зеркало из https://github.com/mozilla/gecko-dev.git
Bug 853721 - Part 1: Refactor the code to convert GainNode's AudioParamTimeline to ticks into WebAudioUtils; r=roc
This commit is contained in:
Родитель
a4a0e75e81
Коммит
8e35c1ebd8
|
@ -7,7 +7,7 @@
|
|||
#ifndef AudioParam_h_
|
||||
#define AudioParam_h_
|
||||
|
||||
#include "AudioEventTimeline.h"
|
||||
#include "AudioParamTimeline.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -16,7 +16,6 @@
|
|||
#include "AudioNode.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "mozilla/Util.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "WebAudioUtils.h"
|
||||
|
||||
struct JSContext;
|
||||
|
@ -26,8 +25,6 @@ namespace mozilla {
|
|||
|
||||
namespace dom {
|
||||
|
||||
typedef AudioEventTimeline<ErrorResult> AudioParamTimeline;
|
||||
|
||||
class AudioParam MOZ_FINAL : public nsWrapperCache,
|
||||
public EnableWebAudioCheck,
|
||||
public AudioParamTimeline
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef AudioParamTimeline_h_
|
||||
#define AudioParamTimeline_h_
|
||||
|
||||
// This header is intended to make it possible to use AudioParamTimeline
|
||||
// from multiple places without dealing with #include hell!
|
||||
|
||||
#include "AudioEventTimeline.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
|
||||
typedef AudioEventTimeline<ErrorResult> AudioParamTimeline;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
#include "AudioNodeEngine.h"
|
||||
#include "AudioNodeStream.h"
|
||||
#include "AudioDestinationNode.h"
|
||||
#include "WebAudioUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -22,24 +23,6 @@ NS_INTERFACE_MAP_END_INHERITING(AudioNode)
|
|||
NS_IMPL_ADDREF_INHERITED(GainNode, AudioNode)
|
||||
NS_IMPL_RELEASE_INHERITED(GainNode, AudioNode)
|
||||
|
||||
struct ConvertTimeToTickHelper
|
||||
{
|
||||
AudioNodeStream* mSourceStream;
|
||||
AudioNodeStream* mDestinationStream;
|
||||
|
||||
static int64_t Convert(double aTime, void* aClosure)
|
||||
{
|
||||
TrackRate sampleRate = IdealAudioRate();
|
||||
|
||||
ConvertTimeToTickHelper* This = static_cast<ConvertTimeToTickHelper*> (aClosure);
|
||||
TrackTicks tick = This->mSourceStream->GetCurrentPosition();
|
||||
StreamTime streamTime = TicksToTimeRoundDown(sampleRate, tick);
|
||||
GraphTime graphTime = This->mSourceStream->StreamTimeToGraphTime(streamTime);
|
||||
StreamTime destinationStreamTime = This->mDestinationStream->GraphTimeToStreamTime(graphTime);
|
||||
return TimeToTicksRoundDown(sampleRate, destinationStreamTime + SecondsToMediaTime(aTime));
|
||||
}
|
||||
};
|
||||
|
||||
class GainNodeEngine : public AudioNodeEngine
|
||||
{
|
||||
public:
|
||||
|
@ -65,10 +48,7 @@ public:
|
|||
case GAIN:
|
||||
MOZ_ASSERT(mSource && mDestination);
|
||||
mGain = aValue;
|
||||
ConvertTimeToTickHelper ctth;
|
||||
ctth.mSourceStream = mSource;
|
||||
ctth.mDestinationStream = mDestination;
|
||||
mGain.ConvertEventTimesToTicks(ConvertTimeToTickHelper::Convert, &ctth);
|
||||
WebAudioUtils::ConvertAudioParamToTicks(mGain, mSource, mDestination);
|
||||
break;
|
||||
default:
|
||||
NS_ERROR("Bad GainNodeEngine TimelineParameter");
|
||||
|
|
|
@ -32,6 +32,7 @@ CPPSRCS := \
|
|||
MediaBufferDecoder.cpp \
|
||||
PannerNode.cpp \
|
||||
ThreeDPoint.cpp \
|
||||
WebAudioUtils.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS_NAMESPACES := mozilla/dom
|
||||
|
@ -53,6 +54,7 @@ EXPORTS_mozilla/dom := \
|
|||
$(NULL)
|
||||
|
||||
EXPORTS := \
|
||||
AudioParamTimeline.h \
|
||||
MediaBufferDecoder.h \
|
||||
ThreeDPoint.h \
|
||||
WebAudioUtils.h \
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "WebAudioUtils.h"
|
||||
#include "AudioNodeStream.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
|
||||
struct ConvertTimeToTickHelper
|
||||
{
|
||||
AudioNodeStream* mSourceStream;
|
||||
AudioNodeStream* mDestinationStream;
|
||||
|
||||
static int64_t Convert(double aTime, void* aClosure)
|
||||
{
|
||||
TrackRate sampleRate = IdealAudioRate();
|
||||
|
||||
ConvertTimeToTickHelper* This = static_cast<ConvertTimeToTickHelper*> (aClosure);
|
||||
TrackTicks tick = This->mSourceStream->GetCurrentPosition();
|
||||
StreamTime streamTime = TicksToTimeRoundDown(sampleRate, tick);
|
||||
GraphTime graphTime = This->mSourceStream->StreamTimeToGraphTime(streamTime);
|
||||
StreamTime destinationStreamTime = This->mDestinationStream->GraphTimeToStreamTime(graphTime);
|
||||
return TimeToTicksRoundDown(sampleRate, destinationStreamTime + SecondsToMediaTime(aTime));
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
WebAudioUtils::ConvertAudioParamToTicks(AudioParamTimeline& aParam,
|
||||
AudioNodeStream* aSource,
|
||||
AudioNodeStream* aDest)
|
||||
{
|
||||
ConvertTimeToTickHelper ctth;
|
||||
ctth.mSourceStream = aSource;
|
||||
ctth.mDestinationStream = aDest;
|
||||
aParam.ConvertEventTimesToTicks(ConvertTimeToTickHelper::Convert, &ctth);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -8,9 +8,12 @@
|
|||
#define WebAudioUtils_h_
|
||||
|
||||
#include <cmath>
|
||||
#include "AudioParamTimeline.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class AudioNodeStream;
|
||||
|
||||
namespace dom {
|
||||
|
||||
struct WebAudioUtils {
|
||||
|
@ -24,6 +27,19 @@ struct WebAudioUtils {
|
|||
using namespace std;
|
||||
return fabs(v1 - v2) < 1e-7;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts AudioParamTimeline floating point time values to tick values
|
||||
* with respect to a source and a destination AudioNodeStream.
|
||||
*
|
||||
* This needs to be called for each AudioParamTimeline that gets sent to an
|
||||
* AudioNodeEngine on the engine side where the AudioParamTimeline is
|
||||
* received. This means that such engines need to be aware of their source
|
||||
* and destination streams as well.
|
||||
*/
|
||||
static void ConvertAudioParamToTicks(AudioParamTimeline& aParam,
|
||||
AudioNodeStream* aSource,
|
||||
AudioNodeStream* aDest);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче