Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_output_delegate_impl.h" | 5 #include "content/browser/renderer_host/media/audio_output_delegate_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "content/browser/media/audio_stream_monitor.h" | 11 #include "content/browser/media/audio_stream_monitor.h" |
| 12 #include "content/browser/media/capture/audio_mirroring_manager.h" | 12 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 13 #include "content/browser/media/media_internals.h" | 13 #include "content/browser/media/media_internals.h" |
| 14 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 14 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_manager.h" | |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/media_observer.h" | 17 #include "content/public/browser/media_observer.h" |
| 17 #include "media/audio/audio_output_controller.h" | 18 #include "media/audio/audio_output_controller.h" |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| 20 | 21 |
| 21 // This class trampolines callbacks from the controller to the delegate. Since | 22 // This class trampolines callbacks from the controller to the delegate. Since |
| 22 // callbacks from the controller are stopped asynchronously, this class holds | 23 // callbacks from the controller are stopped asynchronously, this class holds |
| 23 // a weak pointer to the delegate, allowing the delegate to stop callbacks | 24 // a weak pointer to the delegate, allowing the delegate to stop callbacks |
| 24 // synchronously. | 25 // synchronously. |
| 25 class AudioOutputDelegateImpl::ControllerEventHandler | 26 class AudioOutputDelegateImpl::ControllerEventHandler |
| 26 : public media::AudioOutputController::EventHandler { | 27 : public media::AudioOutputController::EventHandler { |
| 27 public: | 28 public: |
| 28 explicit ControllerEventHandler( | 29 explicit ControllerEventHandler( |
|
Max Morin
2017/05/31 13:51:59
Remove explicit since it has two parameters now.
| |
| 29 base::WeakPtr<AudioOutputDelegateImpl> delegate); | 30 base::WeakPtr<AudioOutputDelegateImpl> delegate, |
| 31 int stream_id); | |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 void OnControllerCreated() override; | 34 void OnControllerCreated() override; |
| 33 void OnControllerPlaying() override; | 35 void OnControllerPlaying() override; |
| 34 void OnControllerPaused() override; | 36 void OnControllerPaused() override; |
| 35 void OnControllerError() override; | 37 void OnControllerError() override; |
| 38 void OnLog(const std::string& message) override; | |
| 36 | 39 |
| 37 base::WeakPtr<AudioOutputDelegateImpl> delegate_; | 40 base::WeakPtr<AudioOutputDelegateImpl> delegate_; |
| 41 const int stream_id_; // Retained separately for logging. | |
| 38 }; | 42 }; |
| 39 | 43 |
| 40 AudioOutputDelegateImpl::ControllerEventHandler::ControllerEventHandler( | 44 AudioOutputDelegateImpl::ControllerEventHandler::ControllerEventHandler( |
| 41 base::WeakPtr<AudioOutputDelegateImpl> delegate) | 45 base::WeakPtr<AudioOutputDelegateImpl> delegate, |
| 42 : delegate_(std::move(delegate)) {} | 46 int stream_id) |
| 47 : delegate_(std::move(delegate)), stream_id_(stream_id) {} | |
| 43 | 48 |
| 44 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerCreated() { | 49 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerCreated() { |
| 45 BrowserThread::PostTask( | 50 BrowserThread::PostTask( |
| 46 BrowserThread::IO, FROM_HERE, | 51 BrowserThread::IO, FROM_HERE, |
| 47 base::BindOnce(&AudioOutputDelegateImpl::SendCreatedNotification, | 52 base::BindOnce(&AudioOutputDelegateImpl::SendCreatedNotification, |
| 48 delegate_)); | 53 delegate_)); |
| 49 } | 54 } |
| 50 | 55 |
| 51 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPlaying() { | 56 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPlaying() { |
| 52 BrowserThread::PostTask( | 57 BrowserThread::PostTask( |
| 53 BrowserThread::IO, FROM_HERE, | 58 BrowserThread::IO, FROM_HERE, |
| 54 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, | 59 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, |
| 55 true)); | 60 true)); |
| 56 } | 61 } |
| 57 | 62 |
| 58 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPaused() { | 63 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPaused() { |
| 59 BrowserThread::PostTask( | 64 BrowserThread::PostTask( |
| 60 BrowserThread::IO, FROM_HERE, | 65 BrowserThread::IO, FROM_HERE, |
| 61 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, | 66 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, |
| 62 false)); | 67 false)); |
| 63 } | 68 } |
| 64 | 69 |
| 65 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerError() { | 70 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerError() { |
| 66 BrowserThread::PostTask( | 71 BrowserThread::PostTask( |
| 67 BrowserThread::IO, FROM_HERE, | 72 BrowserThread::IO, FROM_HERE, |
| 68 base::BindOnce(&AudioOutputDelegateImpl::OnError, delegate_)); | 73 base::BindOnce(&AudioOutputDelegateImpl::OnError, delegate_)); |
| 69 } | 74 } |
| 70 | 75 |
| 76 void AudioOutputDelegateImpl::ControllerEventHandler::OnLog( | |
| 77 const std::string& message) { | |
| 78 std::ostringstream oss; | |
| 79 oss << "[stream_id=" << stream_id_ << "] " << message; | |
| 80 const std::string out_message = oss.str(); | |
| 81 content::MediaStreamManager::SendMessageToNativeLog(out_message); | |
| 82 DVLOG(1) << out_message; | |
| 83 } | |
| 84 | |
| 71 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( | 85 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( |
| 72 EventHandler* handler, | 86 EventHandler* handler, |
| 73 media::AudioManager* audio_manager, | 87 media::AudioManager* audio_manager, |
| 74 std::unique_ptr<media::AudioLog> audio_log, | 88 std::unique_ptr<media::AudioLog> audio_log, |
| 75 AudioMirroringManager* mirroring_manager, | 89 AudioMirroringManager* mirroring_manager, |
| 76 MediaObserver* media_observer, | 90 MediaObserver* media_observer, |
| 77 int stream_id, | 91 int stream_id, |
| 78 int render_frame_id, | 92 int render_frame_id, |
| 79 int render_process_id, | 93 int render_process_id, |
| 80 const media::AudioParameters& params, | 94 const media::AudioParameters& params, |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 111 weak_factory_(this) { | 125 weak_factory_(this) { |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 126 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 113 DCHECK(subscriber_); | 127 DCHECK(subscriber_); |
| 114 DCHECK(audio_manager); | 128 DCHECK(audio_manager); |
| 115 DCHECK(audio_log_); | 129 DCHECK(audio_log_); |
| 116 DCHECK(mirroring_manager_); | 130 DCHECK(mirroring_manager_); |
| 117 DCHECK(reader_); | 131 DCHECK(reader_); |
| 118 // Since the event handler never directly calls functions on |this| but rather | 132 // Since the event handler never directly calls functions on |this| but rather |
| 119 // posts them to the IO thread, passing a pointer from the constructor is | 133 // posts them to the IO thread, passing a pointer from the constructor is |
| 120 // safe. | 134 // safe. |
| 121 controller_event_handler_ = | 135 controller_event_handler_ = base::MakeUnique<ControllerEventHandler>( |
| 122 base::MakeUnique<ControllerEventHandler>(weak_factory_.GetWeakPtr()); | 136 weak_factory_.GetWeakPtr(), stream_id_); |
| 123 audio_log_->OnCreated(stream_id, params, output_device_id); | 137 audio_log_->OnCreated(stream_id, params, output_device_id); |
| 124 controller_ = media::AudioOutputController::Create( | 138 controller_ = media::AudioOutputController::Create( |
| 125 audio_manager, controller_event_handler_.get(), params, output_device_id, | 139 audio_manager, controller_event_handler_.get(), params, output_device_id, |
| 126 reader_.get()); | 140 reader_.get()); |
| 127 DCHECK(controller_); | 141 DCHECK(controller_); |
| 128 if (media_observer) | 142 if (media_observer) |
| 129 media_observer->OnCreatingAudioStream(render_process_id, render_frame_id); | 143 media_observer->OnCreatingAudioStream(render_process_id, render_frame_id); |
| 130 mirroring_manager_->AddDiverter(render_process_id, render_frame_id, | 144 mirroring_manager_->AddDiverter(render_process_id, render_frame_id, |
| 131 controller_.get()); | 145 controller_.get()); |
| 132 } | 146 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 audio_log_->OnError(stream_id_); | 234 audio_log_->OnError(stream_id_); |
| 221 subscriber_->OnStreamError(stream_id_); | 235 subscriber_->OnStreamError(stream_id_); |
| 222 } | 236 } |
| 223 | 237 |
| 224 media::AudioOutputController* AudioOutputDelegateImpl::GetControllerForTesting() | 238 media::AudioOutputController* AudioOutputDelegateImpl::GetControllerForTesting() |
| 225 const { | 239 const { |
| 226 return controller_.get(); | 240 return controller_.get(); |
| 227 } | 241 } |
| 228 | 242 |
| 229 } // namespace content | 243 } // namespace content |
| OLD | NEW |