michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef AudioDestinationNode_h_ michael@0: #define AudioDestinationNode_h_ michael@0: michael@0: #include "mozilla/dom/AudioChannelBinding.h" michael@0: #include "AudioNode.h" michael@0: #include "nsIDOMEventListener.h" michael@0: #include "nsIAudioChannelAgent.h" michael@0: #include "AudioChannelCommon.h" michael@0: #include "nsWeakReference.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class AudioContext; michael@0: michael@0: class AudioDestinationNode : public AudioNode michael@0: , public nsIDOMEventListener michael@0: , public nsIAudioChannelAgentCallback michael@0: , public nsSupportsWeakReference michael@0: , public MainThreadMediaStreamListener michael@0: { michael@0: public: michael@0: // This node type knows what MediaStreamGraph to use based on michael@0: // whether it's in offline mode. michael@0: AudioDestinationNode(AudioContext* aContext, michael@0: bool aIsOffline, michael@0: AudioChannel aChannel = AudioChannel::Normal, michael@0: uint32_t aNumberOfChannels = 0, michael@0: uint32_t aLength = 0, michael@0: float aSampleRate = 0.0f); michael@0: michael@0: virtual void DestroyMediaStream() MOZ_OVERRIDE; michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioDestinationNode, AudioNode) michael@0: NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: virtual uint16_t NumberOfOutputs() const MOZ_FINAL MOZ_OVERRIDE michael@0: { michael@0: return 0; michael@0: } michael@0: michael@0: uint32_t MaxChannelCount() const; michael@0: virtual void SetChannelCount(uint32_t aChannelCount, michael@0: ErrorResult& aRv) MOZ_OVERRIDE; michael@0: michael@0: void Mute(); michael@0: void Unmute(); michael@0: michael@0: void StartRendering(); michael@0: michael@0: void OfflineShutdown(); michael@0: michael@0: // nsIDOMEventListener michael@0: NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); michael@0: michael@0: AudioChannel MozAudioChannelType() const; michael@0: void SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv); michael@0: michael@0: virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE; michael@0: void FireOfflineCompletionEvent(); michael@0: michael@0: // An amount that should be added to the MediaStream's current time to michael@0: // get the AudioContext.currentTime. michael@0: double ExtraCurrentTime(); michael@0: michael@0: // When aIsOnlyNode is true, this is the only node for the AudioContext. michael@0: void SetIsOnlyNodeForContext(bool aIsOnlyNode); michael@0: michael@0: virtual const char* NodeType() const michael@0: { michael@0: return "AudioDestinationNode"; michael@0: } michael@0: michael@0: virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE; michael@0: virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: bool CheckAudioChannelPermissions(AudioChannel aValue); michael@0: void CreateAudioChannelAgent(); michael@0: michael@0: void SetCanPlay(bool aCanPlay); michael@0: michael@0: void NotifyStableState(); michael@0: void ScheduleStableStateNotification(); michael@0: michael@0: SelfReference mOfflineRenderingRef; michael@0: uint32_t mFramesToProduce; michael@0: michael@0: nsCOMPtr mAudioChannelAgent; michael@0: michael@0: // Audio Channel Type. michael@0: AudioChannel mAudioChannel; michael@0: bool mIsOffline; michael@0: bool mHasFinished; michael@0: michael@0: TimeStamp mStartedBlockingDueToBeingOnlyNode; michael@0: double mExtraCurrentTime; michael@0: double mExtraCurrentTimeSinceLastStartedBlocking; michael@0: bool mExtraCurrentTimeUpdatedSinceLastStableState; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif michael@0: