Source code

Revision control

Other Tools

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 "nsIAudioChannelAgent.h"
11
#include "nsCycleCollectionParticipant.h"
12
#include "nsCOMPtr.h"
13
#include "nsIWeakReferenceUtils.h"
14
15
class nsPIDOMWindowInner;
16
class nsPIDOMWindowOuter;
17
18
namespace mozilla {
19
namespace dom {
20
21
class AudioPlaybackConfig;
22
23
/* Header file */
24
class AudioChannelAgent : public nsIAudioChannelAgent {
25
public:
26
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27
NS_DECL_NSIAUDIOCHANNELAGENT
28
29
NS_DECL_CYCLE_COLLECTION_CLASS(AudioChannelAgent)
30
31
AudioChannelAgent();
32
33
// nsIAudioChannelAgentCallback MUST call this function after calling
34
// NotifyStartedPlaying() to require the initial update for
35
// volume/suspend/audio-capturing which might set before starting the agent.
36
// Ex. starting the agent in a tab which has been muted before, so the agent
37
// should apply mute state to its callback.
38
void PullInitialUpdate();
39
40
uint64_t WindowID() const;
41
42
bool IsWindowAudioCapturingEnabled() const;
43
bool IsPlayingStarted() const;
44
45
private:
46
virtual ~AudioChannelAgent();
47
48
friend class AudioChannelService;
49
void WindowVolumeChanged(float aVolume, bool aMuted);
50
void WindowSuspendChanged(nsSuspendedTypes aSuspend);
51
void WindowAudioCaptureChanged(uint64_t aInnerWindowID, bool aCapture);
52
53
nsPIDOMWindowOuter* Window() const { return mWindow; }
54
uint64_t InnerWindowID() const;
55
AudioPlaybackConfig GetMediaConfig() const;
56
57
// Returns mCallback if that's non-null, or otherwise tries to get an
58
// nsIAudioChannelAgentCallback out of mWeakCallback.
59
already_AddRefed<nsIAudioChannelAgentCallback> GetCallback();
60
61
nsresult InitInternal(nsPIDOMWindowInner* aWindow,
62
nsIAudioChannelAgentCallback* aCallback,
63
bool aUseWeakRef);
64
65
void Shutdown();
66
67
nsresult FindCorrectWindow(nsPIDOMWindowInner* aWindow);
68
69
nsCOMPtr<nsPIDOMWindowOuter> mWindow;
70
nsCOMPtr<nsIAudioChannelAgentCallback> mCallback;
71
72
nsWeakPtr mWeakCallback;
73
74
uint64_t mInnerWindowID;
75
bool mIsRegToService;
76
};
77
78
} // namespace dom
79
} // namespace mozilla
80
81
#endif