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 AudioBufferSourceNode_h_ michael@0: #define AudioBufferSourceNode_h_ michael@0: michael@0: #include "AudioNode.h" michael@0: #include "AudioBuffer.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class AudioParam; michael@0: michael@0: class AudioBufferSourceNode : public AudioNode, michael@0: public MainThreadMediaStreamListener michael@0: { michael@0: public: michael@0: explicit AudioBufferSourceNode(AudioContext* aContext); michael@0: virtual ~AudioBufferSourceNode(); michael@0: michael@0: virtual void DestroyMediaStream() MOZ_OVERRIDE michael@0: { michael@0: if (mStream) { michael@0: mStream->RemoveMainThreadListener(this); michael@0: } michael@0: AudioNode::DestroyMediaStream(); michael@0: } michael@0: virtual uint16_t NumberOfInputs() const MOZ_FINAL MOZ_OVERRIDE michael@0: { michael@0: return 0; michael@0: } michael@0: virtual AudioBufferSourceNode* AsAudioBufferSourceNode() MOZ_OVERRIDE michael@0: { michael@0: return this; michael@0: } michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode, AudioNode) michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: void Start(double aWhen, double aOffset, michael@0: const Optional& aDuration, ErrorResult& aRv); michael@0: void Stop(double aWhen, ErrorResult& aRv); michael@0: michael@0: AudioBuffer* GetBuffer(JSContext* aCx) const michael@0: { michael@0: return mBuffer; michael@0: } michael@0: void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer) michael@0: { michael@0: mBuffer = aBuffer; michael@0: SendBufferParameterToStream(aCx); michael@0: SendLoopParametersToStream(); michael@0: } michael@0: AudioParam* PlaybackRate() const michael@0: { michael@0: return mPlaybackRate; michael@0: } michael@0: bool Loop() const michael@0: { michael@0: return mLoop; michael@0: } michael@0: void SetLoop(bool aLoop) michael@0: { michael@0: mLoop = aLoop; michael@0: SendLoopParametersToStream(); michael@0: } michael@0: double LoopStart() const michael@0: { michael@0: return mLoopStart; michael@0: } michael@0: void SetLoopStart(double aStart) michael@0: { michael@0: mLoopStart = aStart; michael@0: SendLoopParametersToStream(); michael@0: } michael@0: double LoopEnd() const michael@0: { michael@0: return mLoopEnd; michael@0: } michael@0: void SetLoopEnd(double aEnd) michael@0: { michael@0: mLoopEnd = aEnd; michael@0: SendLoopParametersToStream(); michael@0: } michael@0: void SendDopplerShiftToStream(double aDopplerShift); michael@0: michael@0: IMPL_EVENT_HANDLER(ended) michael@0: michael@0: virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE; michael@0: michael@0: virtual const char* NodeType() const michael@0: { michael@0: return "AudioBufferSourceNode"; 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: friend class AudioBufferSourceNodeEngine; michael@0: // START is sent during Start(). michael@0: // STOP is sent during Stop(). michael@0: // BUFFERSTART and BUFFEREND are sent when SetBuffer() and Start() have michael@0: // been called (along with sending the buffer). michael@0: enum EngineParameters { michael@0: SAMPLE_RATE, michael@0: START, michael@0: STOP, michael@0: // BUFFERSTART is the "offset" passed to start(), multiplied by michael@0: // buffer.sampleRate. michael@0: BUFFERSTART, michael@0: // BUFFEREND is the sum of "offset" and "duration" passed to start(), michael@0: // multiplied by buffer.sampleRate, or the size of the buffer, if smaller. michael@0: BUFFEREND, michael@0: LOOP, michael@0: LOOPSTART, michael@0: LOOPEND, michael@0: PLAYBACKRATE, michael@0: DOPPLERSHIFT michael@0: }; michael@0: michael@0: void SendLoopParametersToStream(); michael@0: void SendBufferParameterToStream(JSContext* aCx); michael@0: void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream); michael@0: static void SendPlaybackRateToStream(AudioNode* aNode); michael@0: michael@0: private: michael@0: double mLoopStart; michael@0: double mLoopEnd; michael@0: double mOffset; michael@0: double mDuration; michael@0: nsRefPtr mBuffer; michael@0: nsRefPtr mPlaybackRate; michael@0: bool mLoop; michael@0: bool mStartCalled; michael@0: bool mStopped; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif michael@0: