Chromium Code Reviews| Index: content/browser/renderer_host/media/audio_renderer_host.cc |
| diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc |
| index 83b5f2510baaa405905af5e07c561e76283b9ade..812b0bf8f996025e7ce84807dfc23066e8e7aa49 100644 |
| --- a/content/browser/renderer_host/media/audio_renderer_host.cc |
| +++ b/content/browser/renderer_host/media/audio_renderer_host.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/shared_memory.h" |
| #include "content/browser/browser_main_loop.h" |
| #include "content/browser/renderer_host/media/audio_sync_reader.h" |
| +#include "content/browser/renderer_host/media/audio_mirroring_manager.h" |
| #include "content/common/media/audio_messages.h" |
| #include "content/public/browser/media_observer.h" |
| #include "media/audio/shared_memory_util.h" |
| @@ -20,16 +21,55 @@ using media::AudioBus; |
| namespace content { |
| +namespace { |
| + |
| +// Simple wrapper around a media::AudioOutputController to implement the |
| +// AudioMirroringManager::Diverter interface. |
| +class ControllerDiverter : public AudioMirroringManager::Diverter { |
| + public: |
| + void SetController(media::AudioOutputController* controller); |
| + |
| + // AudioMirroringManager::Diverter implementation. |
| + virtual const media::AudioParameters& GetAudioParameters() OVERRIDE; |
| + virtual void StartDiverting(media::AudioOutputStream* stream) OVERRIDE; |
| + virtual void StopDiverting() OVERRIDE; |
| + |
| + private: |
| + media::AudioOutputController* controller_; // Not owned. |
| +}; |
| + |
| +void ControllerDiverter::SetController(media::AudioOutputController* ctlr) { |
| + controller_ = ctlr; |
| +} |
| + |
| +const media::AudioParameters& ControllerDiverter::GetAudioParameters() { |
| + return controller_->params(); |
| +} |
| + |
| +void ControllerDiverter::StartDiverting(media::AudioOutputStream* stream) { |
| + controller_->StartDiverting(stream); |
| +} |
| + |
| +void ControllerDiverter::StopDiverting() { |
| + controller_->StopDiverting(); |
| +} |
| + |
| +} // namespace |
| + |
| struct AudioRendererHost::AudioEntry { |
| AudioEntry(); |
| ~AudioEntry(); |
| // The AudioOutputController that manages the audio stream. |
| scoped_refptr<media::AudioOutputController> controller; |
| + ControllerDiverter diverter; |
| // The audio stream ID. |
| int stream_id; |
| + // The routing ID of the source render view. |
| + int render_view_id; |
| + |
| // Shared memory for transmission of the audio data. |
| base::SharedMemory shared_memory; |
| @@ -43,6 +83,7 @@ struct AudioRendererHost::AudioEntry { |
| AudioRendererHost::AudioEntry::AudioEntry() |
| : stream_id(0), |
| + render_view_id(MSG_ROUTING_NONE), |
| pending_close(false) { |
| } |
| @@ -51,8 +92,10 @@ AudioRendererHost::AudioEntry::~AudioEntry() {} |
| /////////////////////////////////////////////////////////////////////////////// |
| // AudioRendererHost implementations. |
| AudioRendererHost::AudioRendererHost( |
| + int render_process_id, |
| media::AudioManager* audio_manager, MediaObserver* media_observer) |
| - : audio_manager_(audio_manager), |
| + : render_process_id_(render_process_id), |
| + audio_manager_(audio_manager), |
| media_observer_(media_observer) { |
| } |
| @@ -269,11 +312,11 @@ void AudioRendererHost::OnCreateStream( |
| entry->reader.reset(reader.release()); |
| entry->controller = media::AudioOutputController::Create( |
| audio_manager_, this, audio_params, entry->reader.get()); |
| - |
| if (!entry->controller) { |
| SendErrorMessage(stream_id); |
| return; |
| } |
| + entry->diverter.SetController(entry->controller); |
|
tommi (sloooow) - chröme
2012/12/19 12:27:54
nit: keep an empty line after end of scope
miu
2012/12/28 23:03:49
Done.
|
| // If we have created the controller successfully, create an entry and add it |
| // to the map. |
| @@ -285,10 +328,27 @@ void AudioRendererHost::OnCreateStream( |
| void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id, |
| int render_view_id) { |
| - // TODO(miu): Will use render_view_id in upcoming change. |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + |
| DVLOG(1) << "AudioRendererHost@" << this |
| << "::OnAssociateStreamWithProducer(stream_id=" << stream_id |
| << ", render_view_id=" << render_view_id << ")"; |
| + |
| + AudioEntry* const entry = LookupById(stream_id); |
| + if (!entry) { |
| + SendErrorMessage(stream_id); |
| + return; |
| + } |
| + |
| + if (entry->render_view_id == render_view_id) |
| + return; // No change. |
| + |
| + AudioMirroringManager* const amm = AudioMirroringManager::GetInstance(); |
| + amm->RemoveDiverter( |
| + render_process_id_, entry->render_view_id, &entry->diverter); |
| + entry->render_view_id = render_view_id; |
| + amm->AddDiverter( |
| + render_process_id_, entry->render_view_id, &entry->diverter); |
| } |
| void AudioRendererHost::OnPlayStream(int stream_id) { |
| @@ -380,6 +440,8 @@ void AudioRendererHost::CloseAndDeleteStream(AudioEntry* entry) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| if (!entry->pending_close) { |
| + AudioMirroringManager::GetInstance()->RemoveDiverter( |
| + render_process_id_, entry->render_view_id, &entry->diverter); |
| entry->controller->Close( |
| base::Bind(&AudioRendererHost::DeleteEntry, this, entry)); |
| entry->pending_close = true; |