This source file includes following definitions.
- extraData
- owner
- setOwner
- assign
- reset
- initialize
- id
- type
- name
- setReadyState
- readyState
- extraData
- setExtraData
- constraints
- requiresAudioConsumer
- create
- consumer
- setFormat
- consumeAudio
- addAudioConsumer
- removeAudioConsumer
#include "config.h"
#include "public/platform/WebMediaStreamSource.h"
#include "platform/audio/AudioBus.h"
#include "platform/mediastream/MediaStreamSource.h"
#include "public/platform/WebAudioDestinationConsumer.h"
#include "public/platform/WebMediaConstraints.h"
#include "public/platform/WebString.h"
#include "wtf/MainThread.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/Vector.h"
using namespace WebCore;
namespace blink {
namespace {
class ExtraDataContainer : public MediaStreamSource::ExtraData {
public:
ExtraDataContainer(PassOwnPtr<WebMediaStreamSource::ExtraData> extraData) : m_extraData(extraData) { }
WebMediaStreamSource::ExtraData* extraData() { return m_extraData.get(); }
private:
OwnPtr<WebMediaStreamSource::ExtraData> m_extraData;
};
}
WebMediaStreamSource WebMediaStreamSource::ExtraData::owner()
{
ASSERT(m_owner);
return WebMediaStreamSource(m_owner);
}
void WebMediaStreamSource::ExtraData::setOwner(WebCore::MediaStreamSource* owner)
{
ASSERT(!m_owner);
m_owner = owner;
}
WebMediaStreamSource::WebMediaStreamSource(const PassRefPtr<MediaStreamSource>& mediaStreamSource)
: m_private(mediaStreamSource)
{
}
WebMediaStreamSource& WebMediaStreamSource::operator=(WebCore::MediaStreamSource* mediaStreamSource)
{
m_private = mediaStreamSource;
return *this;
}
void WebMediaStreamSource::assign(const WebMediaStreamSource& other)
{
m_private = other.m_private;
}
void WebMediaStreamSource::reset()
{
m_private.reset();
}
WebMediaStreamSource::operator PassRefPtr<MediaStreamSource>() const
{
return m_private.get();
}
WebMediaStreamSource::operator MediaStreamSource*() const
{
return m_private.get();
}
void WebMediaStreamSource::initialize(const WebString& id, Type type, const WebString& name)
{
m_private = MediaStreamSource::create(id, static_cast<MediaStreamSource::Type>(type), name);
}
WebString WebMediaStreamSource::id() const
{
ASSERT(!m_private.isNull());
return m_private.get()->id();
}
WebMediaStreamSource::Type WebMediaStreamSource::type() const
{
ASSERT(!m_private.isNull());
return static_cast<Type>(m_private.get()->type());
}
WebString WebMediaStreamSource::name() const
{
ASSERT(!m_private.isNull());
return m_private.get()->name();
}
void WebMediaStreamSource::setReadyState(ReadyState state)
{
ASSERT(!m_private.isNull());
m_private->setReadyState(static_cast<MediaStreamSource::ReadyState>(state));
}
WebMediaStreamSource::ReadyState WebMediaStreamSource::readyState() const
{
ASSERT(!m_private.isNull());
return static_cast<ReadyState>(m_private->readyState());
}
WebMediaStreamSource::ExtraData* WebMediaStreamSource::extraData() const
{
ASSERT(!m_private.isNull());
MediaStreamSource::ExtraData* data = m_private->extraData();
if (!data)
return 0;
return static_cast<ExtraDataContainer*>(data)->extraData();
}
void WebMediaStreamSource::setExtraData(ExtraData* extraData)
{
ASSERT(!m_private.isNull());
if (extraData)
extraData->setOwner(m_private.get());
m_private->setExtraData(adoptPtr(new ExtraDataContainer(adoptPtr(extraData))));
}
WebMediaConstraints WebMediaStreamSource::constraints()
{
ASSERT(!m_private.isNull());
return m_private->constraints();
}
bool WebMediaStreamSource::requiresAudioConsumer() const
{
ASSERT(!m_private.isNull());
return m_private->requiresAudioConsumer();
}
class ConsumerWrapper : public WebCore::AudioDestinationConsumer {
public:
static PassRefPtr<ConsumerWrapper> create(WebAudioDestinationConsumer* consumer)
{
return adoptRef(new ConsumerWrapper(consumer));
}
virtual void setFormat(size_t numberOfChannels, float sampleRate) OVERRIDE;
virtual void consumeAudio(AudioBus*, size_t numberOfFrames) OVERRIDE;
WebAudioDestinationConsumer* consumer() { return m_consumer; }
private:
explicit ConsumerWrapper(WebAudioDestinationConsumer* consumer) : m_consumer(consumer) { }
WebAudioDestinationConsumer* m_consumer;
};
void ConsumerWrapper::setFormat(size_t numberOfChannels, float sampleRate)
{
m_consumer->setFormat(numberOfChannels, sampleRate);
}
void ConsumerWrapper::consumeAudio(AudioBus* bus, size_t numberOfFrames)
{
if (!bus)
return;
size_t numberOfChannels = bus->numberOfChannels();
blink::WebVector<const float*> busVector(numberOfChannels);
for (size_t i = 0; i < numberOfChannels; ++i)
busVector[i] = bus->channel(i)->data();
m_consumer->consumeAudio(busVector, numberOfFrames);
}
void WebMediaStreamSource::addAudioConsumer(WebAudioDestinationConsumer* consumer)
{
ASSERT(isMainThread());
ASSERT(!m_private.isNull() && consumer);
m_private->addAudioConsumer(ConsumerWrapper::create(consumer));
}
bool WebMediaStreamSource::removeAudioConsumer(WebAudioDestinationConsumer* consumer)
{
ASSERT(isMainThread());
ASSERT(!m_private.isNull() && consumer);
const Vector<RefPtr<AudioDestinationConsumer> >& consumers = m_private->audioConsumers();
for (Vector<RefPtr<AudioDestinationConsumer> >::const_iterator it = consumers.begin(); it != consumers.end(); ++it) {
ConsumerWrapper* wrapper = static_cast<ConsumerWrapper*>((*it).get());
if (wrapper->consumer() == consumer) {
m_private->removeAudioConsumer(wrapper);
return true;
}
}
return false;
}
}