This source file includes following definitions.
- m_renderingParamFanOutCount
- setNumberOfChannels
- updateInternalBus
- updateRenderingState
- updateNumberOfChannels
- propagateChannelCount
- pull
- bus
- fanOutCount
- paramFanOutCount
- renderingFanOutCount
- addInput
- removeInput
- disconnectAllInputs
- addParam
- removeParam
- disconnectAllParams
- disconnectAll
- disable
- enable
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "modules/webaudio/AudioNodeOutput.h"
#include "modules/webaudio/AudioContext.h"
#include "modules/webaudio/AudioNodeInput.h"
#include "wtf/Threading.h"
namespace WebCore {
AudioNodeOutput::AudioNodeOutput(AudioNode* node, unsigned numberOfChannels)
: m_node(node)
, m_numberOfChannels(numberOfChannels)
, m_desiredNumberOfChannels(numberOfChannels)
, m_isInPlace(false)
, m_isEnabled(true)
, m_renderingFanOutCount(0)
, m_renderingParamFanOutCount(0)
{
ASSERT(numberOfChannels <= AudioContext::maxNumberOfChannels());
m_internalBus = AudioBus::create(numberOfChannels, AudioNode::ProcessingSizeInFrames);
}
void AudioNodeOutput::setNumberOfChannels(unsigned numberOfChannels)
{
ASSERT(numberOfChannels <= AudioContext::maxNumberOfChannels());
ASSERT(context()->isGraphOwner());
m_desiredNumberOfChannels = numberOfChannels;
if (context()->isAudioThread()) {
updateNumberOfChannels();
} else {
context()->markAudioNodeOutputDirty(this);
}
}
void AudioNodeOutput::updateInternalBus()
{
if (numberOfChannels() == m_internalBus->numberOfChannels())
return;
m_internalBus = AudioBus::create(numberOfChannels(), AudioNode::ProcessingSizeInFrames);
}
void AudioNodeOutput::updateRenderingState()
{
updateNumberOfChannels();
m_renderingFanOutCount = fanOutCount();
m_renderingParamFanOutCount = paramFanOutCount();
}
void AudioNodeOutput::updateNumberOfChannels()
{
ASSERT(context()->isAudioThread() && context()->isGraphOwner());
if (m_numberOfChannels != m_desiredNumberOfChannels) {
m_numberOfChannels = m_desiredNumberOfChannels;
updateInternalBus();
propagateChannelCount();
}
}
void AudioNodeOutput::propagateChannelCount()
{
ASSERT(context()->isAudioThread() && context()->isGraphOwner());
if (isChannelCountKnown()) {
for (InputsIterator i = m_inputs.begin(); i != m_inputs.end(); ++i) {
AudioNodeInput* input = *i;
AudioNode* connectionNode = input->node();
connectionNode->checkNumberOfChannelsForInput(input);
}
}
}
AudioBus* AudioNodeOutput::pull(AudioBus* inPlaceBus, size_t framesToProcess)
{
ASSERT(context()->isAudioThread());
ASSERT(m_renderingFanOutCount > 0 || m_renderingParamFanOutCount > 0);
m_isInPlace = inPlaceBus && inPlaceBus->numberOfChannels() == numberOfChannels() && (m_renderingFanOutCount + m_renderingParamFanOutCount) == 1;
m_inPlaceBus = m_isInPlace ? inPlaceBus : 0;
node()->processIfNecessary(framesToProcess);
return bus();
}
AudioBus* AudioNodeOutput::bus() const
{
ASSERT(const_cast<AudioNodeOutput*>(this)->context()->isAudioThread());
return m_isInPlace ? m_inPlaceBus.get() : m_internalBus.get();
}
unsigned AudioNodeOutput::fanOutCount()
{
ASSERT(context()->isGraphOwner());
return m_inputs.size();
}
unsigned AudioNodeOutput::paramFanOutCount()
{
ASSERT(context()->isGraphOwner());
return m_params.size();
}
unsigned AudioNodeOutput::renderingFanOutCount() const
{
return m_renderingFanOutCount;
}
void AudioNodeOutput::addInput(AudioNodeInput* input)
{
ASSERT(context()->isGraphOwner());
ASSERT(input);
if (!input)
return;
m_inputs.add(input);
}
void AudioNodeOutput::removeInput(AudioNodeInput* input)
{
ASSERT(context()->isGraphOwner());
ASSERT(input);
if (!input)
return;
m_inputs.remove(input);
}
void AudioNodeOutput::disconnectAllInputs()
{
ASSERT(context()->isGraphOwner());
while (!m_inputs.isEmpty()) {
AudioNodeInput* input = *m_inputs.begin();
input->disconnect(this);
}
}
void AudioNodeOutput::addParam(AudioParam* param)
{
ASSERT(context()->isGraphOwner());
ASSERT(param);
if (!param)
return;
m_params.add(param);
}
void AudioNodeOutput::removeParam(AudioParam* param)
{
ASSERT(context()->isGraphOwner());
ASSERT(param);
if (!param)
return;
m_params.remove(param);
}
void AudioNodeOutput::disconnectAllParams()
{
ASSERT(context()->isGraphOwner());
while (!m_params.isEmpty()) {
AudioParam* param = m_params.begin()->get();
param->disconnect(this);
}
}
void AudioNodeOutput::disconnectAll()
{
disconnectAllInputs();
disconnectAllParams();
}
void AudioNodeOutput::disable()
{
ASSERT(context()->isGraphOwner());
if (m_isEnabled) {
for (InputsIterator i = m_inputs.begin(); i != m_inputs.end(); ++i) {
AudioNodeInput* input = *i;
input->disable(this);
}
m_isEnabled = false;
}
}
void AudioNodeOutput::enable()
{
ASSERT(context()->isGraphOwner());
if (!m_isEnabled) {
for (InputsIterator i = m_inputs.begin(); i != m_inputs.end(); ++i) {
AudioNodeInput* input = *i;
input->enable(this);
}
m_isEnabled = true;
}
}
}
#endif