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..8703e9478f3f1dd05ea8a138a858f32f4ba3eb05 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,11 @@ class AudioRendererHost::AudioEntry |
bool playing() const { return playing_; } |
void set_playing(bool playing) { playing_ = playing; } |
+ AudioOutputImpl* audio_output_impl() { return audio_output_impl_; } |
+ void set_audio_output_impl(AudioOutputImpl* audio_output_impl) { |
+ audio_output_impl_ = audio_output_impl; |
+ } |
+ |
private: |
// media::AudioOutputController::EventHandler implementation. |
void OnCreated() override; |
@@ -164,6 +171,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 +183,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 +195,7 @@ AudioRendererHost::AudioEntry::AudioEntry( |
params, |
output_device_id, |
reader_.get())), |
+ audio_output_impl_(audio_output_impl), |
playing_(false) { |
DCHECK(controller_.get()); |
} |
@@ -245,8 +256,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 +270,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 +303,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()); |
+ if (!entry && entry->audio_output_impl()) { |
+ audio_log_->OnError(stream_id); |
+ CloseStream(stream_id); |
return; |
} |
@@ -324,13 +325,12 @@ 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->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->audio_output_impl()->CreateStreamFactory( |
+ stream_id, entry->shared_memory(), socket_descriptor); |
} |
void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, |
@@ -381,10 +381,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 +517,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 +574,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 +639,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 +686,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) { |
@@ -815,4 +818,14 @@ bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
return i != authorizations_.end(); |
} |
+void AudioRendererHost::CleanAudioOutputImpl( |
+ AudioOutputImpl* audio_output_impl) { |
+ for (auto it = audio_entries_.begin(); it != audio_entries_.end(); ++it) { |
+ if (it->second->audio_output_impl() == audio_output_impl) { |
+ it->second->set_audio_output_impl(NULL); |
+ } |
+ // it->second->set_audio_output_impl(NULL); |
+ } |
+} |
+ |
} // namespace content |