| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/process/process.h" | 16 #include "base/process/process.h" |
| 17 #include "content/browser/bad_message.h" | 17 #include "content/browser/bad_message.h" |
| 18 #include "content/browser/browser_main_loop.h" | 18 #include "content/browser/browser_main_loop.h" |
| 19 #include "content/browser/media/audio_output_impl.h" |
| 19 #include "content/browser/media/audio_stream_monitor.h" | 20 #include "content/browser/media/audio_stream_monitor.h" |
| 20 #include "content/browser/media/capture/audio_mirroring_manager.h" | 21 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 21 #include "content/browser/media/media_internals.h" | 22 #include "content/browser/media/media_internals.h" |
| 22 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 23 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 24 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
| 24 #include "content/browser/renderer_host/media/media_stream_manager.h" | 25 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 26 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 26 #include "content/browser/renderer_host/render_widget_host_impl.h" | 27 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 27 #include "content/common/media/audio_messages.h" | 28 #include "content/common/media/audio_messages.h" |
| 28 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 114 |
| 114 class AudioRendererHost::AudioEntry | 115 class AudioRendererHost::AudioEntry |
| 115 : public media::AudioOutputController::EventHandler { | 116 : public media::AudioOutputController::EventHandler { |
| 116 public: | 117 public: |
| 117 AudioEntry(AudioRendererHost* host, | 118 AudioEntry(AudioRendererHost* host, |
| 118 int stream_id, | 119 int stream_id, |
| 119 int render_frame_id, | 120 int render_frame_id, |
| 120 const media::AudioParameters& params, | 121 const media::AudioParameters& params, |
| 121 const std::string& output_device_id, | 122 const std::string& output_device_id, |
| 122 std::unique_ptr<base::SharedMemory> shared_memory, | 123 std::unique_ptr<base::SharedMemory> shared_memory, |
| 123 std::unique_ptr<media::AudioOutputController::SyncReader> reader); | 124 std::unique_ptr<media::AudioOutputController::SyncReader> reader, |
| 125 AudioOutputImpl* audio_output_impl); |
| 124 ~AudioEntry() override; | 126 ~AudioEntry() override; |
| 125 | 127 |
| 126 int stream_id() const { | 128 int stream_id() const { |
| 127 return stream_id_; | 129 return stream_id_; |
| 128 } | 130 } |
| 129 | 131 |
| 130 int render_frame_id() const { return render_frame_id_; } | 132 int render_frame_id() const { return render_frame_id_; } |
| 131 | 133 |
| 132 media::AudioOutputController* controller() const { return controller_.get(); } | 134 media::AudioOutputController* controller() const { return controller_.get(); } |
| 133 | 135 |
| 134 base::SharedMemory* shared_memory() { | 136 base::SharedMemory* shared_memory() { |
| 135 return shared_memory_.get(); | 137 return shared_memory_.get(); |
| 136 } | 138 } |
| 137 | 139 |
| 138 media::AudioOutputController::SyncReader* reader() const { | 140 media::AudioOutputController::SyncReader* reader() const { |
| 139 return reader_.get(); | 141 return reader_.get(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 bool playing() const { return playing_; } | 144 bool playing() const { return playing_; } |
| 143 void set_playing(bool playing) { playing_ = playing; } | 145 void set_playing(bool playing) { playing_ = playing; } |
| 144 | 146 |
| 147 AudioOutputImpl* get_audio_output_impl() { return audio_output_impl_; } |
| 148 |
| 145 private: | 149 private: |
| 146 // media::AudioOutputController::EventHandler implementation. | 150 // media::AudioOutputController::EventHandler implementation. |
| 147 void OnCreated() override; | 151 void OnCreated() override; |
| 148 void OnPlaying() override; | 152 void OnPlaying() override; |
| 149 void OnPaused() override; | 153 void OnPaused() override; |
| 150 void OnError() override; | 154 void OnError() override; |
| 151 | 155 |
| 152 AudioRendererHost* const host_; | 156 AudioRendererHost* const host_; |
| 153 const int stream_id_; | 157 const int stream_id_; |
| 154 | 158 |
| 155 // The routing ID of the source RenderFrame. | 159 // The routing ID of the source RenderFrame. |
| 156 const int render_frame_id_; | 160 const int render_frame_id_; |
| 157 | 161 |
| 158 // Shared memory for transmission of the audio data. Used by |reader_|. | 162 // Shared memory for transmission of the audio data. Used by |reader_|. |
| 159 const std::unique_ptr<base::SharedMemory> shared_memory_; | 163 const std::unique_ptr<base::SharedMemory> shared_memory_; |
| 160 | 164 |
| 161 // The synchronous reader to be used by |controller_|. | 165 // The synchronous reader to be used by |controller_|. |
| 162 const std::unique_ptr<media::AudioOutputController::SyncReader> reader_; | 166 const std::unique_ptr<media::AudioOutputController::SyncReader> reader_; |
| 163 | 167 |
| 164 // The AudioOutputController that manages the audio stream. | 168 // The AudioOutputController that manages the audio stream. |
| 165 const scoped_refptr<media::AudioOutputController> controller_; | 169 const scoped_refptr<media::AudioOutputController> controller_; |
| 166 | 170 |
| 171 AudioOutputImpl* audio_output_impl_; |
| 172 |
| 167 bool playing_; | 173 bool playing_; |
| 168 }; | 174 }; |
| 169 | 175 |
| 170 AudioRendererHost::AudioEntry::AudioEntry( | 176 AudioRendererHost::AudioEntry::AudioEntry( |
| 171 AudioRendererHost* host, | 177 AudioRendererHost* host, |
| 172 int stream_id, | 178 int stream_id, |
| 173 int render_frame_id, | 179 int render_frame_id, |
| 174 const media::AudioParameters& params, | 180 const media::AudioParameters& params, |
| 175 const std::string& output_device_id, | 181 const std::string& output_device_id, |
| 176 std::unique_ptr<base::SharedMemory> shared_memory, | 182 std::unique_ptr<base::SharedMemory> shared_memory, |
| 177 std::unique_ptr<media::AudioOutputController::SyncReader> reader) | 183 std::unique_ptr<media::AudioOutputController::SyncReader> reader, |
| 184 AudioOutputImpl* audio_output_impl) |
| 178 : host_(host), | 185 : host_(host), |
| 179 stream_id_(stream_id), | 186 stream_id_(stream_id), |
| 180 render_frame_id_(render_frame_id), | 187 render_frame_id_(render_frame_id), |
| 181 shared_memory_(std::move(shared_memory)), | 188 shared_memory_(std::move(shared_memory)), |
| 182 reader_(std::move(reader)), | 189 reader_(std::move(reader)), |
| 183 controller_(media::AudioOutputController::Create(host->audio_manager_, | 190 controller_(media::AudioOutputController::Create(host->audio_manager_, |
| 184 this, | 191 this, |
| 185 params, | 192 params, |
| 186 output_device_id, | 193 output_device_id, |
| 187 reader_.get())), | 194 reader_.get())), |
| 195 audio_output_impl_(audio_output_impl), |
| 188 playing_(false) { | 196 playing_(false) { |
| 189 DCHECK(controller_.get()); | 197 DCHECK(controller_.get()); |
| 190 } | 198 } |
| 191 | 199 |
| 192 AudioRendererHost::AudioEntry::~AudioEntry() {} | 200 AudioRendererHost::AudioEntry::~AudioEntry() {} |
| 193 | 201 |
| 194 /////////////////////////////////////////////////////////////////////////////// | 202 /////////////////////////////////////////////////////////////////////////////// |
| 195 // AudioRendererHost implementations. | 203 // AudioRendererHost implementations. |
| 196 | 204 |
| 197 AudioRendererHost::AudioRendererHost( | 205 AudioRendererHost::AudioRendererHost( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 209 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER)), | 217 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER)), |
| 210 media_stream_manager_(media_stream_manager), | 218 media_stream_manager_(media_stream_manager), |
| 211 num_playing_streams_(0), | 219 num_playing_streams_(0), |
| 212 salt_callback_(salt_callback), | 220 salt_callback_(salt_callback), |
| 213 max_simultaneous_streams_(0) { | 221 max_simultaneous_streams_(0) { |
| 214 DCHECK(audio_manager_); | 222 DCHECK(audio_manager_); |
| 215 DCHECK(media_stream_manager_); | 223 DCHECK(media_stream_manager_); |
| 216 } | 224 } |
| 217 | 225 |
| 218 AudioRendererHost::~AudioRendererHost() { | 226 AudioRendererHost::~AudioRendererHost() { |
| 227 LOG(ERROR) << "~AudioRendererHost"; |
| 219 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 228 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 220 CHECK(audio_entries_.empty()); | 229 CHECK(audio_entries_.empty()); |
| 221 | 230 |
| 222 // If we had any streams, report UMA stats for the maximum number of | 231 // If we had any streams, report UMA stats for the maximum number of |
| 223 // simultaneous streams for this render process and for the whole browser | 232 // simultaneous streams for this render process and for the whole browser |
| 224 // process since last reported. | 233 // process since last reported. |
| 225 if (max_simultaneous_streams_ > 0) { | 234 if (max_simultaneous_streams_ > 0) { |
| 226 UMA_HISTOGRAM_CUSTOM_COUNTS("Media.AudioRendererIpcStreams", | 235 UMA_HISTOGRAM_CUSTOM_COUNTS("Media.AudioRendererIpcStreams", |
| 227 max_simultaneous_streams_, 1, 50, 51); | 236 max_simultaneous_streams_, 1, 50, 51); |
| 228 UMA_HISTOGRAM_CUSTOM_COUNTS( | 237 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 229 "Media.AudioRendererIpcStreamsTotal", | 238 "Media.AudioRendererIpcStreamsTotal", |
| 230 g_audio_streams_tracker.Get().max_stream_count(), | 239 g_audio_streams_tracker.Get().max_stream_count(), |
| 231 1, 100, 101); | 240 1, 100, 101); |
| 232 g_audio_streams_tracker.Get().ResetMaxStreamCount(); | 241 g_audio_streams_tracker.Get().ResetMaxStreamCount(); |
| 233 } | 242 } |
| 234 } | 243 } |
| 235 | 244 |
| 236 void AudioRendererHost::GetOutputControllers( | 245 void AudioRendererHost::GetOutputControllers( |
| 237 const RenderProcessHost::GetAudioOutputControllersCallback& | 246 const RenderProcessHost::GetAudioOutputControllersCallback& |
| 238 callback) const { | 247 callback) const { |
| 239 BrowserThread::PostTaskAndReplyWithResult( | 248 BrowserThread::PostTaskAndReplyWithResult( |
| 240 BrowserThread::IO, FROM_HERE, | 249 BrowserThread::IO, FROM_HERE, |
| 241 base::Bind(&AudioRendererHost::DoGetOutputControllers, this), callback); | 250 base::Bind(&AudioRendererHost::DoGetOutputControllers, this), callback); |
| 242 } | 251 } |
| 243 | 252 |
| 244 void AudioRendererHost::OnChannelClosing() { | 253 void AudioRendererHost::OnChannelClosing() { |
| 245 // Since the IPC sender is gone, close all requested audio streams. | 254 // Since the IPC sender is gone, close all requested audio streams. |
| 246 while (!audio_entries_.empty()) { | 255 while (!audio_entries_.empty()) { |
| 247 // Note: OnCloseStream() removes the entries from audio_entries_. | 256 // Note: CloseStream() removes the entries from audio_entries_. |
| 248 OnCloseStream(audio_entries_.begin()->first); | 257 CloseStream(audio_entries_.begin()->first); |
| 249 } | 258 } |
| 250 | 259 |
| 251 // Remove any authorizations for streams that were not yet created | 260 // Remove any authorizations for streams that were not yet created |
| 252 authorizations_.clear(); | 261 authorizations_.clear(); |
| 253 } | 262 } |
| 254 | 263 |
| 255 void AudioRendererHost::OnDestruct() const { | 264 void AudioRendererHost::OnDestruct() const { |
| 256 BrowserThread::DeleteOnIOThread::Destruct(this); | 265 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 257 } | 266 } |
| 258 | 267 |
| 259 void AudioRendererHost::AudioEntry::OnCreated() { | 268 void AudioRendererHost::AudioEntry::OnCreated() { |
| 260 BrowserThread::PostTask( | 269 BrowserThread::PostTask( |
| 261 BrowserThread::IO, | 270 BrowserThread::IO, FROM_HERE, |
| 262 FROM_HERE, | |
| 263 base::Bind(&AudioRendererHost::DoCompleteCreation, host_, stream_id_)); | 271 base::Bind(&AudioRendererHost::DoCompleteCreation, host_, stream_id_)); |
| 264 } | 272 } |
| 265 | 273 |
| 266 void AudioRendererHost::AudioEntry::OnPlaying() { | 274 void AudioRendererHost::AudioEntry::OnPlaying() { |
| 267 BrowserThread::PostTask( | 275 BrowserThread::PostTask( |
| 268 BrowserThread::IO, | 276 BrowserThread::IO, |
| 269 FROM_HERE, | 277 FROM_HERE, |
| 270 base::Bind(&AudioRendererHost::DoNotifyStreamStateChanged, | 278 base::Bind(&AudioRendererHost::DoNotifyStreamStateChanged, |
| 271 host_, | 279 host_, |
| 272 stream_id_, | 280 stream_id_, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 285 | 293 |
| 286 void AudioRendererHost::AudioEntry::OnError() { | 294 void AudioRendererHost::AudioEntry::OnError() { |
| 287 BrowserThread::PostTask( | 295 BrowserThread::PostTask( |
| 288 BrowserThread::IO, | 296 BrowserThread::IO, |
| 289 FROM_HERE, | 297 FROM_HERE, |
| 290 base::Bind(&AudioRendererHost::ReportErrorAndClose, host_, stream_id_)); | 298 base::Bind(&AudioRendererHost::ReportErrorAndClose, host_, stream_id_)); |
| 291 } | 299 } |
| 292 | 300 |
| 293 void AudioRendererHost::DoCompleteCreation(int stream_id) { | 301 void AudioRendererHost::DoCompleteCreation(int stream_id) { |
| 294 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 302 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 303 AudioEntry* entry = LookupById(stream_id); |
| 295 | 304 |
| 296 if (!PeerHandle()) { | 305 if (!PeerHandle()) { |
| 297 DLOG(WARNING) << "Renderer process handle is invalid."; | 306 DLOG(WARNING) << "Renderer process handle is invalid."; |
| 298 ReportErrorAndClose(stream_id); | 307 audio_log_->OnError(stream_id); |
| 308 CloseStream(stream_id); |
| 299 return; | 309 return; |
| 300 } | 310 } |
| 301 | 311 |
| 302 AudioEntry* const entry = LookupById(stream_id); | |
| 303 if (!entry) { | 312 if (!entry) { |
| 304 ReportErrorAndClose(stream_id); | 313 audio_log_->OnError(stream_id); |
| 314 CloseStream(stream_id); |
| 305 return; | 315 return; |
| 306 } | 316 } |
| 307 | 317 |
| 308 // Once the audio stream is created then complete the creation process by | |
| 309 // mapping shared memory and sharing with the renderer process. | |
| 310 base::SharedMemoryHandle foreign_memory_handle; | |
| 311 if (!entry->shared_memory()->ShareToProcess(PeerHandle(), | |
| 312 &foreign_memory_handle)) { | |
| 313 // If we failed to map and share the shared memory then close the audio | |
| 314 // stream and send an error message. | |
| 315 ReportErrorAndClose(entry->stream_id()); | |
| 316 return; | |
| 317 } | |
| 318 | |
| 319 AudioSyncReader* reader = static_cast<AudioSyncReader*>(entry->reader()); | 318 AudioSyncReader* reader = static_cast<AudioSyncReader*>(entry->reader()); |
| 320 | 319 |
| 321 base::SyncSocket::TransitDescriptor socket_descriptor; | 320 base::SyncSocket::TransitDescriptor socket_descriptor; |
| 322 | 321 |
| 323 // If we failed to prepare the sync socket for the renderer then we fail | 322 // If we failed to prepare the sync socket for the renderer then we fail |
| 324 // the construction of audio stream. | 323 // the construction of audio stream. |
| 325 if (!reader->PrepareForeignSocket(PeerHandle(), &socket_descriptor)) { | 324 if (!reader->PrepareForeignSocket(PeerHandle(), &socket_descriptor)) { |
| 326 ReportErrorAndClose(entry->stream_id()); | 325 entry->get_audio_output_impl()->ReportErrorAndCloseStream( |
| 326 entry->stream_id()); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 Send(new AudioMsg_NotifyStreamCreated( | 330 entry->get_audio_output_impl()->StreamFactory( |
| 331 entry->stream_id(), foreign_memory_handle, socket_descriptor, | 331 stream_id, entry->shared_memory(), socket_descriptor); |
| 332 entry->shared_memory()->requested_size())); | |
| 333 } | 332 } |
| 334 | 333 |
| 335 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, | 334 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, |
| 336 bool is_playing) { | 335 bool is_playing) { |
| 337 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 336 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 338 | 337 |
| 339 AudioEntry* const entry = LookupById(stream_id); | 338 AudioEntry* const entry = LookupById(stream_id); |
| 340 if (!entry) | 339 if (!entry) |
| 341 return; | 340 return; |
| 342 | 341 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 373 return controllers; | 372 return controllers; |
| 374 } | 373 } |
| 375 | 374 |
| 376 /////////////////////////////////////////////////////////////////////////////// | 375 /////////////////////////////////////////////////////////////////////////////// |
| 377 // IPC Messages handler | 376 // IPC Messages handler |
| 378 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) { | 377 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) { |
| 379 bool handled = true; | 378 bool handled = true; |
| 380 IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message) | 379 IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message) |
| 381 IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization, | 380 IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization, |
| 382 OnRequestDeviceAuthorization) | 381 OnRequestDeviceAuthorization) |
| 383 IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream) | |
| 384 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) | 382 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) |
| 385 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) | 383 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) |
| 386 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) | 384 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, CloseStream) |
| 387 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) | 385 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) |
| 388 IPC_MESSAGE_UNHANDLED(handled = false) | 386 IPC_MESSAGE_UNHANDLED(handled = false) |
| 389 IPC_END_MESSAGE_MAP() | 387 IPC_END_MESSAGE_MAP() |
| 390 | 388 |
| 391 return handled; | 389 return handled; |
| 392 } | 390 } |
| 393 | 391 |
| 394 void AudioRendererHost::OnRequestDeviceAuthorization( | 392 void AudioRendererHost::OnRequestDeviceAuthorization( |
| 395 int stream_id, | 393 int stream_id, |
| 396 int render_frame_id, | 394 int render_frame_id, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 508 |
| 511 auth_data->second.first = true; | 509 auth_data->second.first = true; |
| 512 auth_data->second.second = device_info.unique_id; | 510 auth_data->second.second = device_info.unique_id; |
| 513 | 511 |
| 514 media::AudioParameters output_params = device_info.output_params; | 512 media::AudioParameters output_params = device_info.output_params; |
| 515 MaybeFixAudioParameters(&output_params); | 513 MaybeFixAudioParameters(&output_params); |
| 516 Send(new AudioMsg_NotifyDeviceAuthorized( | 514 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 517 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string())); | 515 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string())); |
| 518 } | 516 } |
| 519 | 517 |
| 520 void AudioRendererHost::OnCreateStream(int stream_id, | 518 void AudioRendererHost::CreateStream(int stream_id, |
| 521 int render_frame_id, | 519 int render_frame_id, |
| 522 const media::AudioParameters& params) { | 520 const media::AudioParameters& params, |
| 521 AudioOutputImpl* audio_output_impl) { |
| 523 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 522 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 524 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" | 523 DVLOG(1) << "AudioRendererHost@" << this << "::CreateStream" |
| 525 << "(stream_id=" << stream_id << ")"; | 524 << "(stream_id=" << stream_id << ")"; |
| 526 | 525 |
| 527 const auto& auth_data = authorizations_.find(stream_id); | 526 const auto& auth_data = authorizations_.find(stream_id); |
| 528 | 527 |
| 529 // If no previous authorization requested, assume default device | 528 // If no previous authorization requested, assume default device |
| 530 if (auth_data == authorizations_.end()) { | 529 if (auth_data == authorizations_.end()) { |
| 531 DoCreateStream(stream_id, render_frame_id, params, std::string()); | 530 DoCreateStream(stream_id, render_frame_id, params, std::string(), |
| 531 audio_output_impl); |
| 532 return; | 532 return; |
| 533 } | 533 } |
| 534 | 534 |
| 535 CHECK(auth_data->second.first); | 535 CHECK(auth_data->second.first); |
| 536 DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second); | 536 DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second, |
| 537 audio_output_impl); |
| 537 authorizations_.erase(auth_data); | 538 authorizations_.erase(auth_data); |
| 538 } | 539 } |
| 539 | 540 |
| 540 void AudioRendererHost::DoCreateStream(int stream_id, | 541 void AudioRendererHost::DoCreateStream(int stream_id, |
| 541 int render_frame_id, | 542 int render_frame_id, |
| 542 const media::AudioParameters& params, | 543 const media::AudioParameters& params, |
| 543 const std::string& device_unique_id) { | 544 const std::string& device_unique_id, |
| 545 AudioOutputImpl* audio_output_impl) { |
| 544 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 546 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 545 | 547 |
| 546 // media::AudioParameters is validated in the deserializer. | 548 // media::AudioParameters is validated in the deserializer. |
| 547 if (LookupById(stream_id) != NULL) { | 549 if (LookupById(stream_id) != NULL) { |
| 548 SendErrorMessage(stream_id); | 550 SendErrorMessage(stream_id); |
| 549 return; | 551 return; |
| 550 } | 552 } |
| 551 | 553 |
| 552 // Create the shared memory and share with the renderer process. | 554 // Create the shared memory and share with the renderer process. |
| 553 uint32_t shared_memory_size = sizeof(media::AudioOutputBufferParameters) + | 555 uint32_t shared_memory_size = sizeof(media::AudioOutputBufferParameters) + |
| 554 AudioBus::CalculateMemorySize(params); | 556 AudioBus::CalculateMemorySize(params); |
| 555 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 557 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
| 556 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) { | 558 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) { |
| 557 SendErrorMessage(stream_id); | 559 SendErrorMessage(stream_id); |
| 558 return; | 560 return; |
| 559 } | 561 } |
| 560 | 562 |
| 561 std::unique_ptr<AudioSyncReader> reader( | 563 std::unique_ptr<AudioSyncReader> reader( |
| 562 new AudioSyncReader(shared_memory.get(), params)); | 564 new AudioSyncReader(shared_memory.get(), params)); |
| 563 if (!reader->Init()) { | 565 if (!reader->Init()) { |
| 564 SendErrorMessage(stream_id); | 566 SendErrorMessage(stream_id); |
| 565 return; | 567 return; |
| 566 } | 568 } |
| 567 | 569 |
| 568 MediaObserver* const media_observer = | 570 MediaObserver* const media_observer = |
| 569 GetContentClient()->browser()->GetMediaObserver(); | 571 GetContentClient()->browser()->GetMediaObserver(); |
| 570 if (media_observer) | 572 if (media_observer) |
| 571 media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id); | 573 media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id); |
| 572 | 574 |
| 573 std::unique_ptr<AudioEntry> entry( | 575 std::unique_ptr<AudioEntry> entry(new AudioEntry( |
| 574 new AudioEntry(this, stream_id, render_frame_id, params, device_unique_id, | 576 this, stream_id, render_frame_id, params, device_unique_id, |
| 575 std::move(shared_memory), std::move(reader))); | 577 std::move(shared_memory), std::move(reader), audio_output_impl)); |
| 576 if (mirroring_manager_) { | 578 if (mirroring_manager_) { |
| 577 mirroring_manager_->AddDiverter( | 579 mirroring_manager_->AddDiverter( |
| 578 render_process_id_, entry->render_frame_id(), entry->controller()); | 580 render_process_id_, entry->render_frame_id(), entry->controller()); |
| 579 } | 581 } |
| 580 audio_entries_.insert(std::make_pair(stream_id, entry.release())); | 582 audio_entries_.insert(std::make_pair(stream_id, entry.release())); |
| 581 g_audio_streams_tracker.Get().IncreaseStreamCount(); | 583 g_audio_streams_tracker.Get().IncreaseStreamCount(); |
| 582 | 584 |
| 583 audio_log_->OnCreated(stream_id, params, device_unique_id); | 585 audio_log_->OnCreated(stream_id, params, device_unique_id); |
| 584 MediaInternals::GetInstance()->SetWebContentsTitleForAudioLogEntry( | 586 MediaInternals::GetInstance()->SetWebContentsTitleForAudioLogEntry( |
| 585 stream_id, render_process_id_, render_frame_id, audio_log_.get()); | 587 stream_id, render_process_id_, render_frame_id, audio_log_.get()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 return; | 630 return; |
| 629 entry->controller()->SetVolume(volume); | 631 entry->controller()->SetVolume(volume); |
| 630 audio_log_->OnSetVolume(stream_id, volume); | 632 audio_log_->OnSetVolume(stream_id, volume); |
| 631 } | 633 } |
| 632 | 634 |
| 633 void AudioRendererHost::SendErrorMessage(int stream_id) { | 635 void AudioRendererHost::SendErrorMessage(int stream_id) { |
| 634 Send(new AudioMsg_NotifyStreamStateChanged( | 636 Send(new AudioMsg_NotifyStreamStateChanged( |
| 635 stream_id, media::AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR)); | 637 stream_id, media::AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR)); |
| 636 } | 638 } |
| 637 | 639 |
| 638 void AudioRendererHost::OnCloseStream(int stream_id) { | 640 void AudioRendererHost::CloseStream(int stream_id) { |
| 639 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 641 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 640 authorizations_.erase(stream_id); | 642 authorizations_.erase(stream_id); |
| 641 | 643 |
| 642 // Prevent oustanding callbacks from attempting to close/delete the same | 644 // Prevent oustanding callbacks from attempting to close/delete the same |
| 643 // AudioEntry twice. | 645 // AudioEntry twice. |
| 644 AudioEntryMap::iterator i = audio_entries_.find(stream_id); | 646 AudioEntryMap::iterator i = audio_entries_.find(stream_id); |
| 645 if (i == audio_entries_.end()) | 647 if (i == audio_entries_.end()) |
| 646 return; | 648 return; |
| 647 std::unique_ptr<AudioEntry> entry(i->second); | 649 std::unique_ptr<AudioEntry> entry(i->second); |
| 648 audio_entries_.erase(i); | 650 audio_entries_.erase(i); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 675 | 677 |
| 676 // Make sure this isn't a stray callback executing after the stream has been | 678 // Make sure this isn't a stray callback executing after the stream has been |
| 677 // closed, so error notifications aren't sent after clients believe the stream | 679 // closed, so error notifications aren't sent after clients believe the stream |
| 678 // is closed. | 680 // is closed. |
| 679 if (!LookupById(stream_id)) | 681 if (!LookupById(stream_id)) |
| 680 return; | 682 return; |
| 681 | 683 |
| 682 SendErrorMessage(stream_id); | 684 SendErrorMessage(stream_id); |
| 683 | 685 |
| 684 audio_log_->OnError(stream_id); | 686 audio_log_->OnError(stream_id); |
| 685 OnCloseStream(stream_id); | 687 CloseStream(stream_id); |
| 686 } | 688 } |
| 687 | 689 |
| 688 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 690 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
| 689 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 691 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 690 | 692 |
| 691 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); | 693 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); |
| 692 return i != audio_entries_.end() ? i->second : NULL; | 694 return i != audio_entries_.end() ? i->second : NULL; |
| 693 } | 695 } |
| 694 | 696 |
| 695 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry, | 697 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 callback.Run(false, device_info); | 810 callback.Run(false, device_info); |
| 809 } | 811 } |
| 810 | 812 |
| 811 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 813 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
| 812 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 814 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 813 const auto& i = authorizations_.find(stream_id); | 815 const auto& i = authorizations_.find(stream_id); |
| 814 return i != authorizations_.end(); | 816 return i != authorizations_.end(); |
| 815 } | 817 } |
| 816 | 818 |
| 817 } // namespace content | 819 } // namespace content |
| OLD | NEW |