2013-05-05 15:49:37 +00: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 "mozilla/dom/ChannelMergerNode.h"
|
|
|
|
#include "mozilla/dom/ChannelMergerNodeBinding.h"
|
|
|
|
#include "AudioNodeEngine.h"
|
|
|
|
#include "AudioNodeStream.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED0(ChannelMergerNode, AudioNode)
|
|
|
|
|
|
|
|
class ChannelMergerNodeEngine : public AudioNodeEngine
|
|
|
|
{
|
|
|
|
public:
|
2014-09-01 03:50:59 +00:00
|
|
|
explicit ChannelMergerNodeEngine(ChannelMergerNode* aNode)
|
2013-05-05 15:49:37 +00:00
|
|
|
: AudioNodeEngine(aNode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2014-03-04 21:09:49 +00:00
|
|
|
virtual void ProcessBlocksOnPorts(AudioNodeStream* aStream,
|
|
|
|
const OutputChunks& aInput,
|
|
|
|
OutputChunks& aOutput,
|
|
|
|
bool* aFinished) MOZ_OVERRIDE
|
2013-05-05 15:49:37 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aInput.Length() >= 1, "Should have one or more input ports");
|
|
|
|
|
|
|
|
// Get the number of output channels, and allocate it
|
2014-05-15 21:23:38 +00:00
|
|
|
size_t channelCount = 0;
|
2013-05-05 15:49:37 +00:00
|
|
|
for (uint16_t i = 0; i < InputCount(); ++i) {
|
|
|
|
channelCount += aInput[i].mChannelData.Length();
|
|
|
|
}
|
|
|
|
if (channelCount == 0) {
|
|
|
|
aOutput[0].SetNull(WEBAUDIO_BLOCK_SIZE);
|
|
|
|
return;
|
|
|
|
}
|
2014-05-15 21:23:38 +00:00
|
|
|
channelCount = std::min(channelCount, WebAudioUtils::MaxChannelCount);
|
2013-05-05 15:49:37 +00:00
|
|
|
AllocateAudioBlock(channelCount, &aOutput[0]);
|
|
|
|
|
|
|
|
// Append each channel in each input to the output
|
2014-05-15 21:23:38 +00:00
|
|
|
size_t channelIndex = 0;
|
|
|
|
for (uint16_t i = 0; true; ++i) {
|
|
|
|
MOZ_ASSERT(i < InputCount());
|
|
|
|
for (size_t j = 0; j < aInput[i].mChannelData.Length(); ++j) {
|
2013-05-06 18:30:47 +00:00
|
|
|
AudioBlockCopyChannelWithScale(
|
|
|
|
static_cast<const float*>(aInput[i].mChannelData[j]),
|
|
|
|
aInput[i].mVolume,
|
|
|
|
static_cast<float*>(const_cast<void*>(aOutput[0].mChannelData[channelIndex])));
|
2013-05-05 15:49:37 +00:00
|
|
|
++channelIndex;
|
2014-05-15 21:23:38 +00:00
|
|
|
if (channelIndex >= channelCount) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-05 15:49:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-13 18:08:10 +00:00
|
|
|
|
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
2013-05-05 15:49:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ChannelMergerNode::ChannelMergerNode(AudioContext* aContext,
|
|
|
|
uint16_t aInputCount)
|
|
|
|
: AudioNode(aContext,
|
|
|
|
2,
|
|
|
|
ChannelCountMode::Max,
|
|
|
|
ChannelInterpretation::Speakers)
|
|
|
|
, mInputCount(aInputCount)
|
|
|
|
{
|
|
|
|
mStream = aContext->Graph()->CreateAudioNodeStream(new ChannelMergerNodeEngine(this),
|
|
|
|
MediaStreamGraph::INTERNAL_STREAM);
|
|
|
|
}
|
|
|
|
|
2014-07-08 21:23:17 +00:00
|
|
|
ChannelMergerNode::~ChannelMergerNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-05 15:49:37 +00:00
|
|
|
JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
ChannelMergerNode::WrapObject(JSContext* aCx)
|
2013-05-05 15:49:37 +00:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return ChannelMergerNodeBinding::Wrap(aCx, this);
|
2013-05-05 15:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|