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 0cf02958b073e8ae8218f66ad09a305215a643e7..15ecaca12ff58dd223847e3fc039ddaca450062e 100644 |
| --- a/content/browser/renderer_host/media/audio_renderer_host.cc |
| +++ b/content/browser/renderer_host/media/audio_renderer_host.cc |
| @@ -16,6 +16,7 @@ |
| #include "base/process/process.h" |
| #include "content/browser/bad_message.h" |
| #include "content/browser/browser_main_loop.h" |
| +#include "content/browser/media/audio_output_impl.h" |
| #include "content/browser/media/audio_stream_monitor.h" |
| #include "content/browser/media/capture/audio_mirroring_manager.h" |
| #include "content/browser/media/media_internals.h" |
| @@ -120,7 +121,8 @@ class AudioRendererHost::AudioEntry |
| const media::AudioParameters& params, |
| const std::string& output_device_id, |
| std::unique_ptr<base::SharedMemory> shared_memory, |
| - std::unique_ptr<media::AudioOutputController::SyncReader> reader); |
| + std::unique_ptr<media::AudioOutputController::SyncReader> reader, |
| + AudioOutputImpl* audio_output_impl); |
| ~AudioEntry() override; |
| int stream_id() const { |
| @@ -142,6 +144,8 @@ class AudioRendererHost::AudioEntry |
| bool playing() const { return playing_; } |
| void set_playing(bool playing) { playing_ = playing; } |
| + AudioOutputImpl* get_audio_output_impl() { return audio_output_impl_; } |
|
nasko
2016/05/25 20:50:42
No get_ prefix. The _impl suffix is also optional.
rchtara
2016/05/27 15:24:39
Done.
|
| + |
| private: |
| // media::AudioOutputController::EventHandler implementation. |
| void OnCreated() override; |
| @@ -164,6 +168,8 @@ class AudioRendererHost::AudioEntry |
| // The AudioOutputController that manages the audio stream. |
| const scoped_refptr<media::AudioOutputController> controller_; |
| + AudioOutputImpl* audio_output_impl_; |
| + |
| bool playing_; |
| }; |
| @@ -174,7 +180,8 @@ AudioRendererHost::AudioEntry::AudioEntry( |
| const media::AudioParameters& params, |
| const std::string& output_device_id, |
| std::unique_ptr<base::SharedMemory> shared_memory, |
| - std::unique_ptr<media::AudioOutputController::SyncReader> reader) |
| + std::unique_ptr<media::AudioOutputController::SyncReader> reader, |
| + AudioOutputImpl* audio_output_impl) |
| : host_(host), |
| stream_id_(stream_id), |
| render_frame_id_(render_frame_id), |
| @@ -185,6 +192,7 @@ AudioRendererHost::AudioEntry::AudioEntry( |
| params, |
| output_device_id, |
| reader_.get())), |
| + audio_output_impl_(audio_output_impl), |
| playing_(false) { |
| DCHECK(controller_.get()); |
| } |
| @@ -245,8 +253,8 @@ void AudioRendererHost::OnChannelClosing() { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| // Since the IPC sender is gone, close all requested audio streams. |
| while (!audio_entries_.empty()) { |
| - // Note: OnCloseStream() removes the entries from audio_entries_. |
| - OnCloseStream(audio_entries_.begin()->first); |
| + // Note: CloseStream() removes the entries from audio_entries_. |
| + CloseStream(audio_entries_.begin()->first); |
| } |
| // Remove any authorizations for streams that were not yet created |
| @@ -259,8 +267,7 @@ void AudioRendererHost::OnDestruct() const { |
| void AudioRendererHost::AudioEntry::OnCreated() { |
| BrowserThread::PostTask( |
| - BrowserThread::IO, |
| - FROM_HERE, |
| + BrowserThread::IO, FROM_HERE, |
| base::Bind(&AudioRendererHost::DoCompleteCreation, host_, stream_id_)); |
| } |
| @@ -293,27 +300,18 @@ void AudioRendererHost::AudioEntry::OnError() { |
| void AudioRendererHost::DoCompleteCreation(int stream_id) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + AudioEntry* entry = LookupById(stream_id); |
| if (!PeerHandle()) { |
| DLOG(WARNING) << "Renderer process handle is invalid."; |
| - ReportErrorAndClose(stream_id); |
| + audio_log_->OnError(stream_id); |
| + CloseStream(stream_id); |
| return; |
| } |
| - AudioEntry* const entry = LookupById(stream_id); |
| if (!entry) { |
| - ReportErrorAndClose(stream_id); |
| - return; |
| - } |
| - |
| - // Once the audio stream is created then complete the creation process by |
| - // mapping shared memory and sharing with the renderer process. |
| - base::SharedMemoryHandle foreign_memory_handle; |
| - if (!entry->shared_memory()->ShareToProcess(PeerHandle(), |
| - &foreign_memory_handle)) { |
| - // If we failed to map and share the shared memory then close the audio |
| - // stream and send an error message. |
| - ReportErrorAndClose(entry->stream_id()); |
| + audio_log_->OnError(stream_id); |
| + CloseStream(stream_id); |
| return; |
| } |
| @@ -324,13 +322,13 @@ void AudioRendererHost::DoCompleteCreation(int stream_id) { |
| // If we failed to prepare the sync socket for the renderer then we fail |
| // the construction of audio stream. |
| if (!reader->PrepareForeignSocket(PeerHandle(), &socket_descriptor)) { |
| - ReportErrorAndClose(entry->stream_id()); |
| + entry->get_audio_output_impl()->ReportErrorAndCloseStream( |
| + entry->stream_id()); |
| return; |
| } |
| - Send(new AudioMsg_NotifyStreamCreated( |
| - entry->stream_id(), foreign_memory_handle, socket_descriptor, |
| - entry->shared_memory()->requested_size())); |
| + entry->get_audio_output_impl()->CreateStreamFactory( |
| + stream_id, entry->shared_memory(), socket_descriptor); |
| } |
| void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, |
| @@ -381,10 +379,9 @@ bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) { |
| IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message) |
| IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization, |
| OnRequestDeviceAuthorization) |
| - IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream) |
| IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) |
| IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) |
| - IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) |
| + IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, CloseStream) |
| IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| @@ -518,30 +515,34 @@ void AudioRendererHost::OnDeviceIDTranslated( |
| stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string())); |
| } |
| -void AudioRendererHost::OnCreateStream(int stream_id, |
| - int render_frame_id, |
| - const media::AudioParameters& params) { |
| +void AudioRendererHost::CreateStream(int stream_id, |
| + int render_frame_id, |
| + const media::AudioParameters& params, |
| + AudioOutputImpl* audio_output_impl) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" |
| + DVLOG(1) << "AudioRendererHost@" << this << "::CreateStream" |
| << "(stream_id=" << stream_id << ")"; |
| const auto& auth_data = authorizations_.find(stream_id); |
| // If no previous authorization requested, assume default device |
| if (auth_data == authorizations_.end()) { |
| - DoCreateStream(stream_id, render_frame_id, params, std::string()); |
| + DoCreateStream(stream_id, render_frame_id, params, std::string(), |
| + audio_output_impl); |
| return; |
| } |
| CHECK(auth_data->second.first); |
| - DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second); |
| + DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second, |
| + audio_output_impl); |
| authorizations_.erase(auth_data); |
| } |
| void AudioRendererHost::DoCreateStream(int stream_id, |
| int render_frame_id, |
| const media::AudioParameters& params, |
| - const std::string& device_unique_id) { |
| + const std::string& device_unique_id, |
| + AudioOutputImpl* audio_output_impl) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| // media::AudioParameters is validated in the deserializer. |
| @@ -571,9 +572,9 @@ void AudioRendererHost::DoCreateStream(int stream_id, |
| if (media_observer) |
| media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id); |
| - std::unique_ptr<AudioEntry> entry( |
| - new AudioEntry(this, stream_id, render_frame_id, params, device_unique_id, |
| - std::move(shared_memory), std::move(reader))); |
| + std::unique_ptr<AudioEntry> entry(new AudioEntry( |
| + this, stream_id, render_frame_id, params, device_unique_id, |
| + std::move(shared_memory), std::move(reader), audio_output_impl)); |
| if (mirroring_manager_) { |
| mirroring_manager_->AddDiverter( |
| render_process_id_, entry->render_frame_id(), entry->controller()); |
| @@ -636,7 +637,7 @@ void AudioRendererHost::SendErrorMessage(int stream_id) { |
| stream_id, media::AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR)); |
| } |
| -void AudioRendererHost::OnCloseStream(int stream_id) { |
| +void AudioRendererHost::CloseStream(int stream_id) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| authorizations_.erase(stream_id); |
| @@ -683,7 +684,7 @@ void AudioRendererHost::ReportErrorAndClose(int stream_id) { |
| SendErrorMessage(stream_id); |
| audio_log_->OnError(stream_id); |
| - OnCloseStream(stream_id); |
| + CloseStream(stream_id); |
| } |
| AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |