This source file includes following definitions.
- create
- m_sourceSampleRate
- setFormat
- process
- lock
- unlock
#include "config.h"
#if ENABLE(WEB_AUDIO)
#include "modules/webaudio/MediaElementAudioSourceNode.h"
#include "core/html/HTMLMediaElement.h"
#include "modules/webaudio/AudioContext.h"
#include "modules/webaudio/AudioNodeOutput.h"
#include "platform/Logging.h"
#include "platform/graphics/media/MediaPlayer.h"
#include "wtf/Locker.h"
const unsigned minSampleRate = 8000;
const unsigned maxSampleRate = 192000;
namespace WebCore {
PassRefPtr<MediaElementAudioSourceNode> MediaElementAudioSourceNode::create(AudioContext* context, HTMLMediaElement* mediaElement)
{
return adoptRef(new MediaElementAudioSourceNode(context, mediaElement));
}
MediaElementAudioSourceNode::MediaElementAudioSourceNode(AudioContext* context, HTMLMediaElement* mediaElement)
: AudioSourceNode(context, context->sampleRate())
, m_mediaElement(mediaElement)
, m_sourceNumberOfChannels(0)
, m_sourceSampleRate(0)
{
ScriptWrappable::init(this);
addOutput(adoptPtr(new AudioNodeOutput(this, 2)));
setNodeType(NodeTypeMediaElementAudioSource);
initialize();
}
MediaElementAudioSourceNode::~MediaElementAudioSourceNode()
{
m_mediaElement->setAudioSourceNode(0);
uninitialize();
}
void MediaElementAudioSourceNode::setFormat(size_t numberOfChannels, float sourceSampleRate)
{
if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != m_sourceSampleRate) {
if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfChannels() || sourceSampleRate < minSampleRate || sourceSampleRate > maxSampleRate) {
WTF_LOG(Media, "MediaElementAudioSourceNode::setFormat(%u, %f) - unhandled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate);
m_sourceNumberOfChannels = 0;
m_sourceSampleRate = 0;
return;
}
m_sourceNumberOfChannels = numberOfChannels;
m_sourceSampleRate = sourceSampleRate;
Locker<MediaElementAudioSourceNode> locker(*this);
if (sourceSampleRate != sampleRate()) {
double scaleFactor = sourceSampleRate / sampleRate();
m_multiChannelResampler = adoptPtr(new MultiChannelResampler(scaleFactor, numberOfChannels));
} else {
m_multiChannelResampler.clear();
}
{
AudioContext::AutoLocker contextLocker(context());
output(0)->setNumberOfChannels(numberOfChannels);
}
}
}
void MediaElementAudioSourceNode::process(size_t numberOfFrames)
{
AudioBus* outputBus = output(0)->bus();
if (!mediaElement() || !m_sourceNumberOfChannels || !m_sourceSampleRate) {
outputBus->zero();
return;
}
MutexTryLocker tryLocker(m_processLock);
if (tryLocker.locked()) {
if (AudioSourceProvider* provider = mediaElement()->audioSourceProvider()) {
if (m_multiChannelResampler.get()) {
ASSERT(m_sourceSampleRate != sampleRate());
m_multiChannelResampler->process(provider, outputBus, numberOfFrames);
} else {
ASSERT(m_sourceSampleRate == sampleRate());
provider->provideInput(outputBus, numberOfFrames);
}
} else {
outputBus->zero();
}
} else {
outputBus->zero();
}
}
void MediaElementAudioSourceNode::lock()
{
ref();
m_processLock.lock();
}
void MediaElementAudioSourceNode::unlock()
{
m_processLock.unlock();
deref();
}
}
#endif