2012-11-07 05:01:11 +04:00
|
|
|
/* -*- 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 "DynamicsCompressorNode.h"
|
|
|
|
#include "mozilla/dom/DynamicsCompressorNodeBinding.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-30 03:18:20 +04:00
|
|
|
#include "AudioNodeEngine.h"
|
|
|
|
#include "AudioNodeStream.h"
|
|
|
|
#include "AudioDestinationNode.h"
|
|
|
|
#include "WebAudioUtils.h"
|
2013-04-22 00:13:59 +04:00
|
|
|
#include "blink/DynamicsCompressor.h"
|
|
|
|
|
|
|
|
using WebCore::DynamicsCompressor;
|
|
|
|
|
2012-11-07 05:01:11 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(DynamicsCompressorNode, AudioNode,
|
|
|
|
mThreshold,
|
|
|
|
mKnee,
|
|
|
|
mRatio,
|
|
|
|
mAttack,
|
|
|
|
mRelease)
|
2012-11-07 05:01:11 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DynamicsCompressorNode)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(AudioNode)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(DynamicsCompressorNode, AudioNode)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DynamicsCompressorNode, AudioNode)
|
|
|
|
|
2015-04-28 09:42:00 +03:00
|
|
|
class DynamicsCompressorNodeEngine final : public AudioNodeEngine
|
2013-03-30 03:18:20 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-04-20 20:16:28 +04:00
|
|
|
explicit DynamicsCompressorNodeEngine(AudioNode* aNode,
|
|
|
|
AudioDestinationNode* aDestination)
|
|
|
|
: AudioNodeEngine(aNode)
|
2015-07-02 08:36:07 +03:00
|
|
|
, mDestination(aDestination->Stream())
|
2013-03-30 03:18:20 +04:00
|
|
|
// Keep the default value in sync with the default value in
|
|
|
|
// DynamicsCompressorNode::DynamicsCompressorNode.
|
|
|
|
, mThreshold(-24.f)
|
|
|
|
, mKnee(30.f)
|
|
|
|
, mRatio(12.f)
|
|
|
|
, mAttack(0.003f)
|
|
|
|
, mRelease(0.25f)
|
2013-05-24 21:10:59 +04:00
|
|
|
, mCompressor(new DynamicsCompressor(mDestination->SampleRate(), 2))
|
2013-03-30 03:18:20 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Parameters {
|
|
|
|
THRESHOLD,
|
|
|
|
KNEE,
|
|
|
|
RATIO,
|
|
|
|
ATTACK,
|
|
|
|
RELEASE
|
|
|
|
};
|
2015-09-25 16:57:55 +03:00
|
|
|
void RecvTimelineEvent(uint32_t aIndex,
|
|
|
|
AudioTimelineEvent& aEvent) override
|
2013-03-30 03:18:20 +04:00
|
|
|
{
|
2015-09-22 08:11:52 +03:00
|
|
|
MOZ_ASSERT(mDestination);
|
2015-09-25 16:57:55 +03:00
|
|
|
|
|
|
|
WebAudioUtils::ConvertAudioTimelineEventToTicks(aEvent,
|
|
|
|
mDestination);
|
|
|
|
|
2013-03-30 03:18:20 +04:00
|
|
|
switch (aIndex) {
|
|
|
|
case THRESHOLD:
|
2015-09-25 16:57:55 +03:00
|
|
|
mThreshold.InsertEvent<int64_t>(aEvent);
|
2013-03-30 03:18:20 +04:00
|
|
|
break;
|
|
|
|
case KNEE:
|
2015-09-25 16:57:55 +03:00
|
|
|
mKnee.InsertEvent<int64_t>(aEvent);
|
2013-03-30 03:18:20 +04:00
|
|
|
break;
|
|
|
|
case RATIO:
|
2015-09-25 16:57:55 +03:00
|
|
|
mRatio.InsertEvent<int64_t>(aEvent);
|
2013-03-30 03:18:20 +04:00
|
|
|
break;
|
|
|
|
case ATTACK:
|
2015-09-25 16:57:55 +03:00
|
|
|
mAttack.InsertEvent<int64_t>(aEvent);
|
2013-03-30 03:18:20 +04:00
|
|
|
break;
|
|
|
|
case RELEASE:
|
2015-09-25 16:57:55 +03:00
|
|
|
mRelease.InsertEvent<int64_t>(aEvent);
|
2013-03-30 03:18:20 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Bad DynamicsCompresssorNodeEngine TimelineParameter");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:22:51 +03:00
|
|
|
void ProcessBlock(AudioNodeStream* aStream,
|
|
|
|
GraphTime aFrom,
|
|
|
|
const AudioBlock& aInput,
|
|
|
|
AudioBlock* aOutput,
|
|
|
|
bool* aFinished) override
|
2013-03-30 03:18:20 +04:00
|
|
|
{
|
2013-04-22 00:13:59 +04:00
|
|
|
if (aInput.IsNull()) {
|
|
|
|
// Just output silence
|
|
|
|
*aOutput = aInput;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-03 08:30:16 +03:00
|
|
|
const uint32_t channelCount = aInput.ChannelCount();
|
2013-05-01 23:40:07 +04:00
|
|
|
if (mCompressor->numberOfChannels() != channelCount) {
|
|
|
|
// Create a new compressor object with a new channel count
|
2013-05-24 21:10:59 +04:00
|
|
|
mCompressor = new WebCore::DynamicsCompressor(aStream->SampleRate(),
|
2015-09-03 08:30:16 +03:00
|
|
|
aInput.ChannelCount());
|
2013-05-01 23:40:07 +04:00
|
|
|
}
|
|
|
|
|
2015-09-22 07:34:45 +03:00
|
|
|
StreamTime pos = mDestination->GraphTimeToStreamTime(aFrom);
|
2013-04-22 00:13:59 +04:00
|
|
|
mCompressor->setParameterValue(DynamicsCompressor::ParamThreshold,
|
|
|
|
mThreshold.GetValueAtTime(pos));
|
|
|
|
mCompressor->setParameterValue(DynamicsCompressor::ParamKnee,
|
|
|
|
mKnee.GetValueAtTime(pos));
|
|
|
|
mCompressor->setParameterValue(DynamicsCompressor::ParamRatio,
|
|
|
|
mRatio.GetValueAtTime(pos));
|
|
|
|
mCompressor->setParameterValue(DynamicsCompressor::ParamAttack,
|
|
|
|
mAttack.GetValueAtTime(pos));
|
|
|
|
mCompressor->setParameterValue(DynamicsCompressor::ParamRelease,
|
|
|
|
mRelease.GetValueAtTime(pos));
|
|
|
|
|
2015-09-03 10:01:50 +03:00
|
|
|
aOutput->AllocateChannels(channelCount);
|
2013-04-22 00:13:59 +04:00
|
|
|
mCompressor->process(&aInput, aOutput, aInput.GetDuration());
|
|
|
|
|
|
|
|
SendReductionParamToMainThread(aStream,
|
|
|
|
mCompressor->parameterValue(DynamicsCompressor::ParamReduction));
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:22:51 +03:00
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
|
2014-04-13 22:08:10 +04:00
|
|
|
{
|
|
|
|
// Not owned:
|
|
|
|
// - mDestination (probably)
|
|
|
|
// - Don't count the AudioParamTimelines, their inner refs are owned by the
|
|
|
|
// AudioNode.
|
|
|
|
size_t amount = AudioNodeEngine::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
amount += mCompressor->sizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:22:51 +03:00
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
|
2014-04-13 22:08:10 +04:00
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-04-22 00:13:59 +04:00
|
|
|
private:
|
|
|
|
void SendReductionParamToMainThread(AudioNodeStream* aStream, float aReduction)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!NS_IsMainThread());
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class Command final : public Runnable
|
2013-04-22 00:13:59 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Command(AudioNodeStream* aStream, float aReduction)
|
|
|
|
: mStream(aStream)
|
|
|
|
, mReduction(aReduction)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-28 09:42:00 +03:00
|
|
|
NS_IMETHOD Run() override
|
2013-04-22 00:13:59 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DynamicsCompressorNode> node =
|
2015-07-14 12:57:01 +03:00
|
|
|
static_cast<DynamicsCompressorNode*>
|
|
|
|
(mStream->Engine()->NodeMainThread());
|
2013-04-22 00:13:59 +04:00
|
|
|
if (node) {
|
2015-03-12 16:36:39 +03:00
|
|
|
node->SetReduction(mReduction);
|
2013-04-22 00:13:59 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AudioNodeStream> mStream;
|
2013-04-22 00:13:59 +04:00
|
|
|
float mReduction;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DispatchToMainThread(new Command(aStream, aReduction));
|
2013-03-30 03:18:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
AudioNodeStream* mDestination;
|
|
|
|
AudioParamTimeline mThreshold;
|
|
|
|
AudioParamTimeline mKnee;
|
|
|
|
AudioParamTimeline mRatio;
|
|
|
|
AudioParamTimeline mAttack;
|
|
|
|
AudioParamTimeline mRelease;
|
2013-04-22 00:13:59 +04:00
|
|
|
nsAutoPtr<DynamicsCompressor> mCompressor;
|
2013-03-30 03:18:20 +04:00
|
|
|
};
|
|
|
|
|
2012-11-07 05:01:11 +04:00
|
|
|
DynamicsCompressorNode::DynamicsCompressorNode(AudioContext* aContext)
|
2013-04-28 02:44:50 +04:00
|
|
|
: AudioNode(aContext,
|
2013-05-01 23:40:07 +04:00
|
|
|
2,
|
2013-04-28 02:44:50 +04:00
|
|
|
ChannelCountMode::Explicit,
|
|
|
|
ChannelInterpretation::Speakers)
|
2015-10-01 05:48:20 +03:00
|
|
|
, mThreshold(new AudioParam(this, DynamicsCompressorNodeEngine::THRESHOLD,
|
|
|
|
-24.f, "threshold"))
|
|
|
|
, mKnee(new AudioParam(this, DynamicsCompressorNodeEngine::KNEE,
|
|
|
|
30.f, "knee"))
|
|
|
|
, mRatio(new AudioParam(this, DynamicsCompressorNodeEngine::RATIO,
|
|
|
|
12.f, "ratio"))
|
2015-03-12 16:36:39 +03:00
|
|
|
, mReduction(0)
|
2015-10-01 05:48:20 +03:00
|
|
|
, mAttack(new AudioParam(this, DynamicsCompressorNodeEngine::ATTACK,
|
|
|
|
0.003f, "attack"))
|
|
|
|
, mRelease(new AudioParam(this, DynamicsCompressorNodeEngine::RELEASE,
|
|
|
|
0.25f, "release"))
|
2013-03-30 03:18:20 +04:00
|
|
|
{
|
2013-04-20 20:16:28 +04:00
|
|
|
DynamicsCompressorNodeEngine* engine = new DynamicsCompressorNodeEngine(this, aContext->Destination());
|
2015-09-08 16:22:16 +03:00
|
|
|
mStream = AudioNodeStream::Create(aContext, engine,
|
2016-09-05 18:25:41 +03:00
|
|
|
AudioNodeStream::NO_STREAM_FLAGS,
|
|
|
|
aContext->Graph());
|
2013-03-30 03:18:20 +04:00
|
|
|
}
|
|
|
|
|
2014-07-09 01:23:17 +04:00
|
|
|
DynamicsCompressorNode::~DynamicsCompressorNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-13 22:08:10 +04:00
|
|
|
size_t
|
|
|
|
DynamicsCompressorNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
amount += mThreshold->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
amount += mKnee->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
amount += mRatio->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
amount += mAttack->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
amount += mRelease->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
DynamicsCompressorNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2012-11-07 05:01:11 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
DynamicsCompressorNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-11-07 05:01:11 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return DynamicsCompressorNodeBinding::Wrap(aCx, this, aGivenProto);
|
2012-11-07 05:01:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|