/src/mozilla-central/dom/media/webaudio/AudioDestinationNode.h
Line | Count | Source (jump to first uncovered line) |
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 "AudioChannelService.h" |
11 | | #include "AudioNode.h" |
12 | | #include "nsIAudioChannelAgent.h" |
13 | | #include "mozilla/TimeStamp.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | class AudioContext; |
19 | | |
20 | | class AudioDestinationNode final : public AudioNode |
21 | | , public nsIAudioChannelAgentCallback |
22 | | , public MainThreadMediaStreamListener |
23 | | { |
24 | | public: |
25 | | // This node type knows what MediaStreamGraph to use based on |
26 | | // whether it's in offline mode. |
27 | | AudioDestinationNode(AudioContext* aContext, |
28 | | bool aIsOffline, |
29 | | bool aAllowedToStart, |
30 | | uint32_t aNumberOfChannels = 0, |
31 | | uint32_t aLength = 0, |
32 | | float aSampleRate = 0.0f); |
33 | | |
34 | | void DestroyMediaStream() override; |
35 | | |
36 | | NS_DECL_ISUPPORTS_INHERITED |
37 | | NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioDestinationNode, AudioNode) |
38 | | NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK |
39 | | |
40 | | JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; |
41 | | |
42 | | uint16_t NumberOfOutputs() const final |
43 | 0 | { |
44 | 0 | return 0; |
45 | 0 | } |
46 | | |
47 | | uint32_t MaxChannelCount() const; |
48 | | void SetChannelCount(uint32_t aChannelCount, |
49 | | ErrorResult& aRv) override; |
50 | | |
51 | | // Returns the stream or null after unlink. |
52 | 0 | AudioNodeStream* Stream() { return mStream; } |
53 | | |
54 | | void Mute(); |
55 | | void Unmute(); |
56 | | |
57 | | void Suspend(); |
58 | | void Resume(); |
59 | | |
60 | | void StartRendering(Promise* aPromise); |
61 | | |
62 | | void OfflineShutdown(); |
63 | | |
64 | | void NotifyMainThreadStreamFinished() override; |
65 | | void FireOfflineCompletionEvent(); |
66 | | |
67 | | nsresult CreateAudioChannelAgent(); |
68 | | void DestroyAudioChannelAgent(); |
69 | | |
70 | | const char* NodeType() const override |
71 | 0 | { |
72 | 0 | return "AudioDestinationNode"; |
73 | 0 | } |
74 | | |
75 | | size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override; |
76 | | size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; |
77 | | |
78 | | void InputMuted(bool aInputMuted); |
79 | | void ResolvePromise(AudioBuffer* aRenderedBuffer); |
80 | | |
81 | | unsigned long Length() |
82 | 0 | { |
83 | 0 | MOZ_ASSERT(mIsOffline); |
84 | 0 | return mFramesToProduce; |
85 | 0 | } |
86 | | |
87 | | protected: |
88 | | virtual ~AudioDestinationNode(); |
89 | | |
90 | | private: |
91 | | SelfReference<AudioDestinationNode> mOfflineRenderingRef; |
92 | | uint32_t mFramesToProduce; |
93 | | |
94 | | nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent; |
95 | | RefPtr<MediaInputPort> mCaptureStreamPort; |
96 | | |
97 | | RefPtr<Promise> mOfflineRenderingPromise; |
98 | | |
99 | | bool mIsOffline; |
100 | | bool mAudioChannelSuspended; |
101 | | |
102 | | bool mCaptured; |
103 | | AudioChannelService::AudibleState mAudible; |
104 | | |
105 | | // These varaibles are used to know how long AudioContext would become audible |
106 | | // since it was created. |
107 | | TimeStamp mCreatedTime; |
108 | | TimeDuration mDurationBeforeFirstTimeAudible; |
109 | | }; |
110 | | |
111 | | } // namespace dom |
112 | | } // namespace mozilla |
113 | | |
114 | | #endif |
115 | | |