content/media/webaudio/AudioParamTimeline.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/AudioParamTimeline.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef AudioParamTimeline_h_
    1.11 +#define AudioParamTimeline_h_
    1.12 +
    1.13 +#include "AudioEventTimeline.h"
    1.14 +#include "mozilla/ErrorResult.h"
    1.15 +#include "nsAutoPtr.h"
    1.16 +#include "MediaStreamGraph.h"
    1.17 +#include "AudioSegment.h"
    1.18 +
    1.19 +namespace mozilla {
    1.20 +
    1.21 +namespace dom {
    1.22 +
    1.23 +// This helper class is used to represent the part of the AudioParam
    1.24 +// class that gets sent to AudioNodeEngine instances.  In addition to
    1.25 +// AudioEventTimeline methods, it holds a pointer to an optional
    1.26 +// MediaStream which represents the AudioNode inputs to the AudioParam.
    1.27 +// This MediaStream is managed by the AudioParam subclass on the main
    1.28 +// thread, and can only be obtained from the AudioNodeEngine instances
    1.29 +// consuming this class.
    1.30 +class AudioParamTimeline : public AudioEventTimeline<ErrorResult>
    1.31 +{
    1.32 +  typedef AudioEventTimeline<ErrorResult> BaseClass;
    1.33 +
    1.34 +public:
    1.35 +  explicit AudioParamTimeline(float aDefaultValue)
    1.36 +    : BaseClass(aDefaultValue)
    1.37 +  {
    1.38 +  }
    1.39 +
    1.40 +  MediaStream* Stream() const
    1.41 +  {
    1.42 +    return mStream;
    1.43 +  }
    1.44 +
    1.45 +  bool HasSimpleValue() const
    1.46 +  {
    1.47 +    return BaseClass::HasSimpleValue() && !mStream;
    1.48 +  }
    1.49 +
    1.50 +  // Get the value of the AudioParam at time aTime + aCounter.
    1.51 +  // aCounter here is an offset to aTime if we try to get the value in ticks,
    1.52 +  // otherwise it should always be zero.  aCounter is meant to be used when
    1.53 +  // getting the value of an a-rate AudioParam for each tick inside an
    1.54 +  // AudioNodeEngine implementation.
    1.55 +  template<class TimeType>
    1.56 +  float GetValueAtTime(TimeType aTime, size_t aCounter = 0);
    1.57 +
    1.58 +  virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
    1.59 +  {
    1.60 +    return mStream ? mStream->SizeOfIncludingThis(aMallocSizeOf) : 0;
    1.61 +  }
    1.62 +
    1.63 +  virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
    1.64 +  {
    1.65 +    return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
    1.66 +  }
    1.67 +
    1.68 +
    1.69 +private:
    1.70 +  float AudioNodeInputValue(size_t aCounter) const;
    1.71 +
    1.72 +protected:
    1.73 +  // This is created lazily when needed.
    1.74 +  nsRefPtr<MediaStream> mStream;
    1.75 +};
    1.76 +
    1.77 +template<> inline float
    1.78 +AudioParamTimeline::GetValueAtTime(double aTime, size_t aCounter)
    1.79 +{
    1.80 +  MOZ_ASSERT(!aCounter);
    1.81 +
    1.82 +  // Getting an AudioParam value on an AudioNode does not consider input from
    1.83 +  // other AudioNodes, which is managed only on the graph thread.
    1.84 +  return BaseClass::GetValueAtTime(aTime);
    1.85 +}
    1.86 +
    1.87 +
    1.88 +template<> inline float
    1.89 +AudioParamTimeline::GetValueAtTime(int64_t aTime, size_t aCounter)
    1.90 +{
    1.91 +  MOZ_ASSERT(aCounter < WEBAUDIO_BLOCK_SIZE);
    1.92 +  MOZ_ASSERT(!aCounter || !HasSimpleValue());
    1.93 +
    1.94 +  // Mix the value of the AudioParam itself with that of the AudioNode inputs.
    1.95 +  return BaseClass::GetValueAtTime(static_cast<int64_t>(aTime + aCounter)) +
    1.96 +    (mStream ? AudioNodeInputValue(aCounter) : 0.0f);
    1.97 +}
    1.98 +
    1.99 +}
   1.100 +}
   1.101 +
   1.102 +#endif
   1.103 +

mercurial