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