content/media/webaudio/AudioParamTimeline.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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 AudioParamTimeline_h_
michael@0 8 #define AudioParamTimeline_h_
michael@0 9
michael@0 10 #include "AudioEventTimeline.h"
michael@0 11 #include "mozilla/ErrorResult.h"
michael@0 12 #include "nsAutoPtr.h"
michael@0 13 #include "MediaStreamGraph.h"
michael@0 14 #include "AudioSegment.h"
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17
michael@0 18 namespace dom {
michael@0 19
michael@0 20 // This helper class is used to represent the part of the AudioParam
michael@0 21 // class that gets sent to AudioNodeEngine instances. In addition to
michael@0 22 // AudioEventTimeline methods, it holds a pointer to an optional
michael@0 23 // MediaStream which represents the AudioNode inputs to the AudioParam.
michael@0 24 // This MediaStream is managed by the AudioParam subclass on the main
michael@0 25 // thread, and can only be obtained from the AudioNodeEngine instances
michael@0 26 // consuming this class.
michael@0 27 class AudioParamTimeline : public AudioEventTimeline<ErrorResult>
michael@0 28 {
michael@0 29 typedef AudioEventTimeline<ErrorResult> BaseClass;
michael@0 30
michael@0 31 public:
michael@0 32 explicit AudioParamTimeline(float aDefaultValue)
michael@0 33 : BaseClass(aDefaultValue)
michael@0 34 {
michael@0 35 }
michael@0 36
michael@0 37 MediaStream* Stream() const
michael@0 38 {
michael@0 39 return mStream;
michael@0 40 }
michael@0 41
michael@0 42 bool HasSimpleValue() const
michael@0 43 {
michael@0 44 return BaseClass::HasSimpleValue() && !mStream;
michael@0 45 }
michael@0 46
michael@0 47 // Get the value of the AudioParam at time aTime + aCounter.
michael@0 48 // aCounter here is an offset to aTime if we try to get the value in ticks,
michael@0 49 // otherwise it should always be zero. aCounter is meant to be used when
michael@0 50 // getting the value of an a-rate AudioParam for each tick inside an
michael@0 51 // AudioNodeEngine implementation.
michael@0 52 template<class TimeType>
michael@0 53 float GetValueAtTime(TimeType aTime, size_t aCounter = 0);
michael@0 54
michael@0 55 virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
michael@0 56 {
michael@0 57 return mStream ? mStream->SizeOfIncludingThis(aMallocSizeOf) : 0;
michael@0 58 }
michael@0 59
michael@0 60 virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
michael@0 61 {
michael@0 62 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
michael@0 63 }
michael@0 64
michael@0 65
michael@0 66 private:
michael@0 67 float AudioNodeInputValue(size_t aCounter) const;
michael@0 68
michael@0 69 protected:
michael@0 70 // This is created lazily when needed.
michael@0 71 nsRefPtr<MediaStream> mStream;
michael@0 72 };
michael@0 73
michael@0 74 template<> inline float
michael@0 75 AudioParamTimeline::GetValueAtTime(double aTime, size_t aCounter)
michael@0 76 {
michael@0 77 MOZ_ASSERT(!aCounter);
michael@0 78
michael@0 79 // Getting an AudioParam value on an AudioNode does not consider input from
michael@0 80 // other AudioNodes, which is managed only on the graph thread.
michael@0 81 return BaseClass::GetValueAtTime(aTime);
michael@0 82 }
michael@0 83
michael@0 84
michael@0 85 template<> inline float
michael@0 86 AudioParamTimeline::GetValueAtTime(int64_t aTime, size_t aCounter)
michael@0 87 {
michael@0 88 MOZ_ASSERT(aCounter < WEBAUDIO_BLOCK_SIZE);
michael@0 89 MOZ_ASSERT(!aCounter || !HasSimpleValue());
michael@0 90
michael@0 91 // Mix the value of the AudioParam itself with that of the AudioNode inputs.
michael@0 92 return BaseClass::GetValueAtTime(static_cast<int64_t>(aTime + aCounter)) +
michael@0 93 (mStream ? AudioNodeInputValue(aCounter) : 0.0f);
michael@0 94 }
michael@0 95
michael@0 96 }
michael@0 97 }
michael@0 98
michael@0 99 #endif
michael@0 100

mercurial