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( |
| 29 base::WeakPtr<AudioOutputDelegateImpl> delegate); | 30 base::WeakPtr<AudioOutputDelegateImpl> delegate); |
| 30 | 31 |
| 31 private: | 32 private: |
| 32 void OnControllerCreated() override; | 33 void OnControllerCreated() override; |
| 33 void OnControllerPlaying() override; | 34 void OnControllerPlaying() override; |
| 34 void OnControllerPaused() override; | 35 void OnControllerPaused() override; |
| 35 void OnControllerError() override; | 36 void OnControllerError() override; |
| 37 void OnLog(const std::string& message) override; | |
| 36 | 38 |
| 37 base::WeakPtr<AudioOutputDelegateImpl> delegate_; | 39 base::WeakPtr<AudioOutputDelegateImpl> delegate_; |
| 40 int stream_id_; // Retained separately for logging. | |
| 38 }; | 41 }; |
| 39 | 42 |
| 40 AudioOutputDelegateImpl::ControllerEventHandler::ControllerEventHandler( | 43 AudioOutputDelegateImpl::ControllerEventHandler::ControllerEventHandler( |
| 41 base::WeakPtr<AudioOutputDelegateImpl> delegate) | 44 base::WeakPtr<AudioOutputDelegateImpl> delegate) |
| 42 : delegate_(std::move(delegate)) {} | 45 : delegate_(std::move(delegate)), stream_id_(delegate_->stream_id_) {} |
|
Max Morin
2017/05/31 11:52:40
Since you're dereferencing |delegate_|, maybe add
ossu-chromium
2017/05/31 13:47:20
I've no reasonable place to put it - in the code b
Max Morin
2017/05/31 13:51:59
Alright, that's fine by me.
| |
| 43 | 46 |
| 44 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerCreated() { | 47 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerCreated() { |
| 45 BrowserThread::PostTask( | 48 BrowserThread::PostTask( |
| 46 BrowserThread::IO, FROM_HERE, | 49 BrowserThread::IO, FROM_HERE, |
| 47 base::BindOnce(&AudioOutputDelegateImpl::SendCreatedNotification, | 50 base::BindOnce(&AudioOutputDelegateImpl::SendCreatedNotification, |
| 48 delegate_)); | 51 delegate_)); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPlaying() { | 54 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPlaying() { |
| 52 BrowserThread::PostTask( | 55 BrowserThread::PostTask( |
| 53 BrowserThread::IO, FROM_HERE, | 56 BrowserThread::IO, FROM_HERE, |
| 54 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, | 57 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, |
| 55 true)); | 58 true)); |
| 56 } | 59 } |
| 57 | 60 |
| 58 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPaused() { | 61 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPaused() { |
| 59 BrowserThread::PostTask( | 62 BrowserThread::PostTask( |
| 60 BrowserThread::IO, FROM_HERE, | 63 BrowserThread::IO, FROM_HERE, |
| 61 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, | 64 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, |
| 62 false)); | 65 false)); |
| 63 } | 66 } |
| 64 | 67 |
| 65 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerError() { | 68 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerError() { |
| 66 BrowserThread::PostTask( | 69 BrowserThread::PostTask( |
| 67 BrowserThread::IO, FROM_HERE, | 70 BrowserThread::IO, FROM_HERE, |
| 68 base::BindOnce(&AudioOutputDelegateImpl::OnError, delegate_)); | 71 base::BindOnce(&AudioOutputDelegateImpl::OnError, delegate_)); |
| 69 } | 72 } |
| 70 | 73 |
| 74 void AudioOutputDelegateImpl::ControllerEventHandler::OnLog( | |
| 75 const std::string& message) { | |
| 76 BrowserThread::PostTask( | |
| 77 BrowserThread::IO, FROM_HERE, | |
| 78 base::BindOnce( | |
| 79 [](int stream_id, const std::string& message) { | |
| 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 81 std::ostringstream oss; | |
| 82 oss << "[stream_id=" << stream_id << "] " << message; | |
| 83 const std::string out_message = oss.str(); | |
| 84 content::MediaStreamManager::SendMessageToNativeLog(out_message); | |
|
Max Morin
2017/05/31 11:52:40
Since I'm nit-picking anyways, remove unnecessary
Max Morin
2017/05/31 11:56:23
Oh, I just noticed SendMessageToNativeLog is safe
ossu-chromium
2017/05/31 11:59:45
Ah, yes, you are right! The task was only posted t
| |
| 85 DVLOG(1) << out_message; | |
| 86 }, | |
| 87 stream_id_, message)); | |
| 88 } | |
| 89 | |
| 71 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( | 90 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( |
| 72 EventHandler* handler, | 91 EventHandler* handler, |
| 73 media::AudioManager* audio_manager, | 92 media::AudioManager* audio_manager, |
| 74 std::unique_ptr<media::AudioLog> audio_log, | 93 std::unique_ptr<media::AudioLog> audio_log, |
| 75 AudioMirroringManager* mirroring_manager, | 94 AudioMirroringManager* mirroring_manager, |
| 76 MediaObserver* media_observer, | 95 MediaObserver* media_observer, |
| 77 int stream_id, | 96 int stream_id, |
| 78 int render_frame_id, | 97 int render_frame_id, |
| 79 int render_process_id, | 98 int render_process_id, |
| 80 const media::AudioParameters& params, | 99 const media::AudioParameters& params, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 audio_log_->OnError(stream_id_); | 239 audio_log_->OnError(stream_id_); |
| 221 subscriber_->OnStreamError(stream_id_); | 240 subscriber_->OnStreamError(stream_id_); |
| 222 } | 241 } |
| 223 | 242 |
| 224 media::AudioOutputController* AudioOutputDelegateImpl::GetControllerForTesting() | 243 media::AudioOutputController* AudioOutputDelegateImpl::GetControllerForTesting() |
| 225 const { | 244 const { |
| 226 return controller_.get(); | 245 return controller_.get(); |
| 227 } | 246 } |
| 228 | 247 |
| 229 } // namespace content | 248 } // namespace content |
| OLD | NEW |