content/media/webaudio/AudioBufferSourceNode.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 AudioBufferSourceNode_h_
michael@0 8 #define AudioBufferSourceNode_h_
michael@0 9
michael@0 10 #include "AudioNode.h"
michael@0 11 #include "AudioBuffer.h"
michael@0 12
michael@0 13 namespace mozilla {
michael@0 14 namespace dom {
michael@0 15
michael@0 16 class AudioParam;
michael@0 17
michael@0 18 class AudioBufferSourceNode : public AudioNode,
michael@0 19 public MainThreadMediaStreamListener
michael@0 20 {
michael@0 21 public:
michael@0 22 explicit AudioBufferSourceNode(AudioContext* aContext);
michael@0 23 virtual ~AudioBufferSourceNode();
michael@0 24
michael@0 25 virtual void DestroyMediaStream() MOZ_OVERRIDE
michael@0 26 {
michael@0 27 if (mStream) {
michael@0 28 mStream->RemoveMainThreadListener(this);
michael@0 29 }
michael@0 30 AudioNode::DestroyMediaStream();
michael@0 31 }
michael@0 32 virtual uint16_t NumberOfInputs() const MOZ_FINAL MOZ_OVERRIDE
michael@0 33 {
michael@0 34 return 0;
michael@0 35 }
michael@0 36 virtual AudioBufferSourceNode* AsAudioBufferSourceNode() MOZ_OVERRIDE
michael@0 37 {
michael@0 38 return this;
michael@0 39 }
michael@0 40 NS_DECL_ISUPPORTS_INHERITED
michael@0 41 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode, AudioNode)
michael@0 42
michael@0 43 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 44
michael@0 45 void Start(double aWhen, double aOffset,
michael@0 46 const Optional<double>& aDuration, ErrorResult& aRv);
michael@0 47 void Stop(double aWhen, ErrorResult& aRv);
michael@0 48
michael@0 49 AudioBuffer* GetBuffer(JSContext* aCx) const
michael@0 50 {
michael@0 51 return mBuffer;
michael@0 52 }
michael@0 53 void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer)
michael@0 54 {
michael@0 55 mBuffer = aBuffer;
michael@0 56 SendBufferParameterToStream(aCx);
michael@0 57 SendLoopParametersToStream();
michael@0 58 }
michael@0 59 AudioParam* PlaybackRate() const
michael@0 60 {
michael@0 61 return mPlaybackRate;
michael@0 62 }
michael@0 63 bool Loop() const
michael@0 64 {
michael@0 65 return mLoop;
michael@0 66 }
michael@0 67 void SetLoop(bool aLoop)
michael@0 68 {
michael@0 69 mLoop = aLoop;
michael@0 70 SendLoopParametersToStream();
michael@0 71 }
michael@0 72 double LoopStart() const
michael@0 73 {
michael@0 74 return mLoopStart;
michael@0 75 }
michael@0 76 void SetLoopStart(double aStart)
michael@0 77 {
michael@0 78 mLoopStart = aStart;
michael@0 79 SendLoopParametersToStream();
michael@0 80 }
michael@0 81 double LoopEnd() const
michael@0 82 {
michael@0 83 return mLoopEnd;
michael@0 84 }
michael@0 85 void SetLoopEnd(double aEnd)
michael@0 86 {
michael@0 87 mLoopEnd = aEnd;
michael@0 88 SendLoopParametersToStream();
michael@0 89 }
michael@0 90 void SendDopplerShiftToStream(double aDopplerShift);
michael@0 91
michael@0 92 IMPL_EVENT_HANDLER(ended)
michael@0 93
michael@0 94 virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE;
michael@0 95
michael@0 96 virtual const char* NodeType() const
michael@0 97 {
michael@0 98 return "AudioBufferSourceNode";
michael@0 99 }
michael@0 100
michael@0 101 virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
michael@0 102 virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
michael@0 103
michael@0 104 private:
michael@0 105 friend class AudioBufferSourceNodeEngine;
michael@0 106 // START is sent during Start().
michael@0 107 // STOP is sent during Stop().
michael@0 108 // BUFFERSTART and BUFFEREND are sent when SetBuffer() and Start() have
michael@0 109 // been called (along with sending the buffer).
michael@0 110 enum EngineParameters {
michael@0 111 SAMPLE_RATE,
michael@0 112 START,
michael@0 113 STOP,
michael@0 114 // BUFFERSTART is the "offset" passed to start(), multiplied by
michael@0 115 // buffer.sampleRate.
michael@0 116 BUFFERSTART,
michael@0 117 // BUFFEREND is the sum of "offset" and "duration" passed to start(),
michael@0 118 // multiplied by buffer.sampleRate, or the size of the buffer, if smaller.
michael@0 119 BUFFEREND,
michael@0 120 LOOP,
michael@0 121 LOOPSTART,
michael@0 122 LOOPEND,
michael@0 123 PLAYBACKRATE,
michael@0 124 DOPPLERSHIFT
michael@0 125 };
michael@0 126
michael@0 127 void SendLoopParametersToStream();
michael@0 128 void SendBufferParameterToStream(JSContext* aCx);
michael@0 129 void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream);
michael@0 130 static void SendPlaybackRateToStream(AudioNode* aNode);
michael@0 131
michael@0 132 private:
michael@0 133 double mLoopStart;
michael@0 134 double mLoopEnd;
michael@0 135 double mOffset;
michael@0 136 double mDuration;
michael@0 137 nsRefPtr<AudioBuffer> mBuffer;
michael@0 138 nsRefPtr<AudioParam> mPlaybackRate;
michael@0 139 bool mLoop;
michael@0 140 bool mStartCalled;
michael@0 141 bool mStopped;
michael@0 142 };
michael@0 143
michael@0 144 }
michael@0 145 }
michael@0 146
michael@0 147 #endif
michael@0 148

mercurial