| Index: content/renderer/media/render_audiosourceprovider.cc
|
| diff --git a/content/renderer/media/render_audiosourceprovider.cc b/content/renderer/media/render_audiosourceprovider.cc
|
| index 81f99ce7429738facccf38d05f4b52523983d2f0..10803f8a57e834bbbad92a443b36fa5a76ab5363 100644
|
| --- a/content/renderer/media/render_audiosourceprovider.cc
|
| +++ b/content/renderer/media/render_audiosourceprovider.cc
|
| @@ -27,7 +27,53 @@ RenderAudioSourceProvider::RenderAudioSourceProvider()
|
| default_sink_ = new AudioDevice();
|
| }
|
|
|
| -RenderAudioSourceProvider::~RenderAudioSourceProvider() {}
|
| +void RenderAudioSourceProvider::setClient(
|
| + WebKit::WebAudioSourceProviderClient* client) {
|
| + // Synchronize with other uses of client_ and default_sink_.
|
| + base::AutoLock auto_lock(sink_lock_);
|
| +
|
| + if (client && client != client_) {
|
| + // Detach the audio renderer from normal playback.
|
| + default_sink_->Stop();
|
| +
|
| + // The client will now take control by calling provideInput() periodically.
|
| + client_ = client;
|
| +
|
| + if (is_initialized_) {
|
| + // The client needs to be notified of the audio format, if available.
|
| + // If the format is not yet available, we'll be notified later
|
| + // when Initialize() is called.
|
| +
|
| + // Inform WebKit about the audio stream format.
|
| + client->setFormat(channels_, sample_rate_);
|
| + }
|
| + } else if (!client && client_) {
|
| + // Restore normal playback.
|
| + client_ = NULL;
|
| + // TODO(crogers): We should call default_sink_->Play() if we're
|
| + // in the playing state.
|
| + }
|
| +}
|
| +
|
| +void RenderAudioSourceProvider::provideInput(
|
| + const WebVector<float*>& audio_data, size_t number_of_frames) {
|
| + DCHECK(client_);
|
| +
|
| + if (renderer_ && is_initialized_ && is_running_) {
|
| + // Wrap WebVector as std::vector.
|
| + vector<float*> v(audio_data.size());
|
| + for (size_t i = 0; i < audio_data.size(); ++i)
|
| + v[i] = audio_data[i];
|
| +
|
| + // TODO(crogers): figure out if we should volume scale here or in common
|
| + // WebAudio code. In any case we need to take care of volume.
|
| + renderer_->Render(v, number_of_frames, 0);
|
| + } else {
|
| + // Provide silence if the source is not running.
|
| + for (size_t i = 0; i < audio_data.size(); ++i)
|
| + memset(audio_data[i], 0, sizeof(float) * number_of_frames);
|
| + }
|
| +}
|
|
|
| void RenderAudioSourceProvider::Start() {
|
| base::AutoLock auto_lock(sink_lock_);
|
| @@ -79,7 +125,8 @@ void RenderAudioSourceProvider::GetVolume(double* volume) {
|
| }
|
|
|
| void RenderAudioSourceProvider::Initialize(
|
| - const media::AudioParameters& params, RenderCallback* renderer) {
|
| + const media::AudioParameters& params,
|
| + RenderCallback* renderer) {
|
| base::AutoLock auto_lock(sink_lock_);
|
| CHECK(!is_initialized_);
|
| renderer_ = renderer;
|
| @@ -98,50 +145,4 @@ void RenderAudioSourceProvider::Initialize(
|
| is_initialized_ = true;
|
| }
|
|
|
| -void RenderAudioSourceProvider::setClient(
|
| - WebKit::WebAudioSourceProviderClient* client) {
|
| - // Synchronize with other uses of client_ and default_sink_.
|
| - base::AutoLock auto_lock(sink_lock_);
|
| -
|
| - if (client && client != client_) {
|
| - // Detach the audio renderer from normal playback.
|
| - default_sink_->Stop();
|
| -
|
| - // The client will now take control by calling provideInput() periodically.
|
| - client_ = client;
|
| -
|
| - if (is_initialized_) {
|
| - // The client needs to be notified of the audio format, if available.
|
| - // If the format is not yet available, we'll be notified later
|
| - // when Initialize() is called.
|
| -
|
| - // Inform WebKit about the audio stream format.
|
| - client->setFormat(channels_, sample_rate_);
|
| - }
|
| - } else if (!client && client_) {
|
| - // Restore normal playback.
|
| - client_ = NULL;
|
| - // TODO(crogers): We should call default_sink_->Play() if we're
|
| - // in the playing state.
|
| - }
|
| -}
|
| -
|
| -void RenderAudioSourceProvider::provideInput(
|
| - const WebVector<float*>& audio_data, size_t number_of_frames) {
|
| - DCHECK(client_);
|
| -
|
| - if (renderer_ && is_initialized_ && is_running_) {
|
| - // Wrap WebVector as std::vector.
|
| - vector<float*> v(audio_data.size());
|
| - for (size_t i = 0; i < audio_data.size(); ++i)
|
| - v[i] = audio_data[i];
|
| -
|
| - // TODO(crogers): figure out if we should volume scale here or in common
|
| - // WebAudio code. In any case we need to take care of volume.
|
| - renderer_->Render(v, number_of_frames, 0);
|
| - } else {
|
| - // Provide silence if the source is not running.
|
| - for (size_t i = 0; i < audio_data.size(); ++i)
|
| - memset(audio_data[i], 0, sizeof(float) * number_of_frames);
|
| - }
|
| -}
|
| +RenderAudioSourceProvider::~RenderAudioSourceProvider() {}
|
|
|