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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef AudioParamTimeline_h_
     8 #define AudioParamTimeline_h_
    10 #include "AudioEventTimeline.h"
    11 #include "mozilla/ErrorResult.h"
    12 #include "nsAutoPtr.h"
    13 #include "MediaStreamGraph.h"
    14 #include "AudioSegment.h"
    16 namespace mozilla {
    18 namespace dom {
    20 // This helper class is used to represent the part of the AudioParam
    21 // class that gets sent to AudioNodeEngine instances.  In addition to
    22 // AudioEventTimeline methods, it holds a pointer to an optional
    23 // MediaStream which represents the AudioNode inputs to the AudioParam.
    24 // This MediaStream is managed by the AudioParam subclass on the main
    25 // thread, and can only be obtained from the AudioNodeEngine instances
    26 // consuming this class.
    27 class AudioParamTimeline : public AudioEventTimeline<ErrorResult>
    28 {
    29   typedef AudioEventTimeline<ErrorResult> BaseClass;
    31 public:
    32   explicit AudioParamTimeline(float aDefaultValue)
    33     : BaseClass(aDefaultValue)
    34   {
    35   }
    37   MediaStream* Stream() const
    38   {
    39     return mStream;
    40   }
    42   bool HasSimpleValue() const
    43   {
    44     return BaseClass::HasSimpleValue() && !mStream;
    45   }
    47   // Get the value of the AudioParam at time aTime + aCounter.
    48   // aCounter here is an offset to aTime if we try to get the value in ticks,
    49   // otherwise it should always be zero.  aCounter is meant to be used when
    50   // getting the value of an a-rate AudioParam for each tick inside an
    51   // AudioNodeEngine implementation.
    52   template<class TimeType>
    53   float GetValueAtTime(TimeType aTime, size_t aCounter = 0);
    55   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
    56   {
    57     return mStream ? mStream->SizeOfIncludingThis(aMallocSizeOf) : 0;
    58   }
    60   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
    61   {
    62     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
    63   }
    66 private:
    67   float AudioNodeInputValue(size_t aCounter) const;
    69 protected:
    70   // This is created lazily when needed.
    71   nsRefPtr<MediaStream> mStream;
    72 };
    74 template<> inline float
    75 AudioParamTimeline::GetValueAtTime(double aTime, size_t aCounter)
    76 {
    77   MOZ_ASSERT(!aCounter);
    79   // Getting an AudioParam value on an AudioNode does not consider input from
    80   // other AudioNodes, which is managed only on the graph thread.
    81   return BaseClass::GetValueAtTime(aTime);
    82 }
    85 template<> inline float
    86 AudioParamTimeline::GetValueAtTime(int64_t aTime, size_t aCounter)
    87 {
    88   MOZ_ASSERT(aCounter < WEBAUDIO_BLOCK_SIZE);
    89   MOZ_ASSERT(!aCounter || !HasSimpleValue());
    91   // Mix the value of the AudioParam itself with that of the AudioNode inputs.
    92   return BaseClass::GetValueAtTime(static_cast<int64_t>(aTime + aCounter)) +
    93     (mStream ? AudioNodeInputValue(aCounter) : 0.0f);
    94 }
    96 }
    97 }
    99 #endif

mercurial