|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
|
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 AudioDestinationNode_h_ |
|
8 #define AudioDestinationNode_h_ |
|
9 |
|
10 #include "mozilla/dom/AudioChannelBinding.h" |
|
11 #include "AudioNode.h" |
|
12 #include "nsIDOMEventListener.h" |
|
13 #include "nsIAudioChannelAgent.h" |
|
14 #include "AudioChannelCommon.h" |
|
15 #include "nsWeakReference.h" |
|
16 |
|
17 namespace mozilla { |
|
18 namespace dom { |
|
19 |
|
20 class AudioContext; |
|
21 |
|
22 class AudioDestinationNode : public AudioNode |
|
23 , public nsIDOMEventListener |
|
24 , public nsIAudioChannelAgentCallback |
|
25 , public nsSupportsWeakReference |
|
26 , public MainThreadMediaStreamListener |
|
27 { |
|
28 public: |
|
29 // This node type knows what MediaStreamGraph to use based on |
|
30 // whether it's in offline mode. |
|
31 AudioDestinationNode(AudioContext* aContext, |
|
32 bool aIsOffline, |
|
33 AudioChannel aChannel = AudioChannel::Normal, |
|
34 uint32_t aNumberOfChannels = 0, |
|
35 uint32_t aLength = 0, |
|
36 float aSampleRate = 0.0f); |
|
37 |
|
38 virtual void DestroyMediaStream() MOZ_OVERRIDE; |
|
39 |
|
40 NS_DECL_ISUPPORTS_INHERITED |
|
41 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioDestinationNode, AudioNode) |
|
42 NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK |
|
43 |
|
44 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
45 |
|
46 virtual uint16_t NumberOfOutputs() const MOZ_FINAL MOZ_OVERRIDE |
|
47 { |
|
48 return 0; |
|
49 } |
|
50 |
|
51 uint32_t MaxChannelCount() const; |
|
52 virtual void SetChannelCount(uint32_t aChannelCount, |
|
53 ErrorResult& aRv) MOZ_OVERRIDE; |
|
54 |
|
55 void Mute(); |
|
56 void Unmute(); |
|
57 |
|
58 void StartRendering(); |
|
59 |
|
60 void OfflineShutdown(); |
|
61 |
|
62 // nsIDOMEventListener |
|
63 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); |
|
64 |
|
65 AudioChannel MozAudioChannelType() const; |
|
66 void SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv); |
|
67 |
|
68 virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE; |
|
69 void FireOfflineCompletionEvent(); |
|
70 |
|
71 // An amount that should be added to the MediaStream's current time to |
|
72 // get the AudioContext.currentTime. |
|
73 double ExtraCurrentTime(); |
|
74 |
|
75 // When aIsOnlyNode is true, this is the only node for the AudioContext. |
|
76 void SetIsOnlyNodeForContext(bool aIsOnlyNode); |
|
77 |
|
78 virtual const char* NodeType() const |
|
79 { |
|
80 return "AudioDestinationNode"; |
|
81 } |
|
82 |
|
83 virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE; |
|
84 virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE; |
|
85 |
|
86 private: |
|
87 bool CheckAudioChannelPermissions(AudioChannel aValue); |
|
88 void CreateAudioChannelAgent(); |
|
89 |
|
90 void SetCanPlay(bool aCanPlay); |
|
91 |
|
92 void NotifyStableState(); |
|
93 void ScheduleStableStateNotification(); |
|
94 |
|
95 SelfReference<AudioDestinationNode> mOfflineRenderingRef; |
|
96 uint32_t mFramesToProduce; |
|
97 |
|
98 nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent; |
|
99 |
|
100 // Audio Channel Type. |
|
101 AudioChannel mAudioChannel; |
|
102 bool mIsOffline; |
|
103 bool mHasFinished; |
|
104 |
|
105 TimeStamp mStartedBlockingDueToBeingOnlyNode; |
|
106 double mExtraCurrentTime; |
|
107 double mExtraCurrentTimeSinceLastStartedBlocking; |
|
108 bool mExtraCurrentTimeUpdatedSinceLastStableState; |
|
109 }; |
|
110 |
|
111 } |
|
112 } |
|
113 |
|
114 #endif |
|
115 |