AudioChannelAgent.h (2415B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_audio_channel_agent_h__ 8 #define mozilla_dom_audio_channel_agent_h__ 9 10 #include "nsCOMPtr.h" 11 #include "nsCycleCollectionParticipant.h" 12 #include "nsIAudioChannelAgent.h" 13 #include "nsIWeakReferenceUtils.h" 14 15 class nsPIDOMWindowInner; 16 class nsPIDOMWindowOuter; 17 18 namespace mozilla::dom { 19 20 class AudioPlaybackConfig; 21 22 /* Header file */ 23 class AudioChannelAgent : public nsIAudioChannelAgent { 24 public: 25 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 26 NS_DECL_NSIAUDIOCHANNELAGENT 27 28 NS_DECL_CYCLE_COLLECTION_CLASS(AudioChannelAgent) 29 30 AudioChannelAgent(); 31 32 // nsIAudioChannelAgentCallback MUST call this function after calling 33 // NotifyStartedPlaying() to require the initial update for 34 // volume/suspend/audio-capturing which might set before starting the agent. 35 // Ex. starting the agent in a tab which has been muted before, so the agent 36 // should apply mute state to its callback. 37 void PullInitialUpdate(); 38 39 uint64_t WindowID() const; 40 41 bool IsWindowAudioCapturingEnabled() const; 42 bool IsPlayingStarted() const; 43 44 private: 45 virtual ~AudioChannelAgent(); 46 47 friend class AudioChannelService; 48 void WindowVolumeChanged(float aVolume, bool aMuted); 49 void WindowSuspendChanged(nsSuspendedTypes aSuspend); 50 void WindowAudioCaptureChanged(uint64_t aInnerWindowID, bool aCapture); 51 52 nsPIDOMWindowOuter* Window() const { return mWindow; } 53 uint64_t InnerWindowID() const; 54 AudioPlaybackConfig GetMediaConfig() const; 55 56 // Returns mCallback if that's non-null, or otherwise tries to get an 57 // nsIAudioChannelAgentCallback out of mWeakCallback. 58 already_AddRefed<nsIAudioChannelAgentCallback> GetCallback(); 59 60 nsresult InitInternal(nsPIDOMWindowInner* aWindow, 61 nsIAudioChannelAgentCallback* aCallback, 62 bool aUseWeakRef); 63 64 void Shutdown(); 65 66 nsresult FindCorrectWindow(nsPIDOMWindowInner* aWindow); 67 68 nsCOMPtr<nsPIDOMWindowOuter> mWindow; 69 nsCOMPtr<nsIAudioChannelAgentCallback> mCallback; 70 71 nsWeakPtr mWeakCallback; 72 73 uint64_t mInnerWindowID; 74 bool mIsRegToService; 75 }; 76 77 } // namespace mozilla::dom 78 79 #endif