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 AudioParamTimeline_h_ michael@0: #define AudioParamTimeline_h_ michael@0: michael@0: #include "AudioEventTimeline.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "MediaStreamGraph.h" michael@0: #include "AudioSegment.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace dom { michael@0: michael@0: // This helper class is used to represent the part of the AudioParam michael@0: // class that gets sent to AudioNodeEngine instances. In addition to michael@0: // AudioEventTimeline methods, it holds a pointer to an optional michael@0: // MediaStream which represents the AudioNode inputs to the AudioParam. michael@0: // This MediaStream is managed by the AudioParam subclass on the main michael@0: // thread, and can only be obtained from the AudioNodeEngine instances michael@0: // consuming this class. michael@0: class AudioParamTimeline : public AudioEventTimeline michael@0: { michael@0: typedef AudioEventTimeline BaseClass; michael@0: michael@0: public: michael@0: explicit AudioParamTimeline(float aDefaultValue) michael@0: : BaseClass(aDefaultValue) michael@0: { michael@0: } michael@0: michael@0: MediaStream* Stream() const michael@0: { michael@0: return mStream; michael@0: } michael@0: michael@0: bool HasSimpleValue() const michael@0: { michael@0: return BaseClass::HasSimpleValue() && !mStream; michael@0: } michael@0: michael@0: // Get the value of the AudioParam at time aTime + aCounter. michael@0: // aCounter here is an offset to aTime if we try to get the value in ticks, michael@0: // otherwise it should always be zero. aCounter is meant to be used when michael@0: // getting the value of an a-rate AudioParam for each tick inside an michael@0: // AudioNodeEngine implementation. michael@0: template michael@0: float GetValueAtTime(TimeType aTime, size_t aCounter = 0); michael@0: michael@0: virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const michael@0: { michael@0: return mStream ? mStream->SizeOfIncludingThis(aMallocSizeOf) : 0; michael@0: } michael@0: michael@0: virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const michael@0: { michael@0: return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); michael@0: } michael@0: michael@0: michael@0: private: michael@0: float AudioNodeInputValue(size_t aCounter) const; michael@0: michael@0: protected: michael@0: // This is created lazily when needed. michael@0: nsRefPtr mStream; michael@0: }; michael@0: michael@0: template<> inline float michael@0: AudioParamTimeline::GetValueAtTime(double aTime, size_t aCounter) michael@0: { michael@0: MOZ_ASSERT(!aCounter); michael@0: michael@0: // Getting an AudioParam value on an AudioNode does not consider input from michael@0: // other AudioNodes, which is managed only on the graph thread. michael@0: return BaseClass::GetValueAtTime(aTime); michael@0: } michael@0: michael@0: michael@0: template<> inline float michael@0: AudioParamTimeline::GetValueAtTime(int64_t aTime, size_t aCounter) michael@0: { michael@0: MOZ_ASSERT(aCounter < WEBAUDIO_BLOCK_SIZE); michael@0: MOZ_ASSERT(!aCounter || !HasSimpleValue()); michael@0: michael@0: // Mix the value of the AudioParam itself with that of the AudioNode inputs. michael@0: return BaseClass::GetValueAtTime(static_cast(aTime + aCounter)) + michael@0: (mStream ? AudioNodeInputValue(aCounter) : 0.0f); michael@0: } michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif michael@0: