| 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; |
| 36 | 37 |
| 38 void OnLog(const std::string& message) override; |
| 39 |
| 37 base::WeakPtr<AudioOutputDelegateImpl> delegate_; | 40 base::WeakPtr<AudioOutputDelegateImpl> delegate_; |
| 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)) {} |
| 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, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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::Bind(&AudioOutputDelegateImpl::DoLog, delegate_, message)); |
| 79 } |
| 80 |
| 71 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( | 81 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( |
| 72 EventHandler* handler, | 82 EventHandler* handler, |
| 73 media::AudioManager* audio_manager, | 83 media::AudioManager* audio_manager, |
| 74 std::unique_ptr<media::AudioLog> audio_log, | 84 std::unique_ptr<media::AudioLog> audio_log, |
| 75 AudioMirroringManager* mirroring_manager, | 85 AudioMirroringManager* mirroring_manager, |
| 76 MediaObserver* media_observer, | 86 MediaObserver* media_observer, |
| 77 int stream_id, | 87 int stream_id, |
| 78 int render_frame_id, | 88 int render_frame_id, |
| 79 int render_process_id, | 89 int render_process_id, |
| 80 const media::AudioParameters& params, | 90 const media::AudioParameters& params, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 224 } |
| 215 } | 225 } |
| 216 | 226 |
| 217 void AudioOutputDelegateImpl::OnError() { | 227 void AudioOutputDelegateImpl::OnError() { |
| 218 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 228 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 219 | 229 |
| 220 audio_log_->OnError(stream_id_); | 230 audio_log_->OnError(stream_id_); |
| 221 subscriber_->OnStreamError(stream_id_); | 231 subscriber_->OnStreamError(stream_id_); |
| 222 } | 232 } |
| 223 | 233 |
| 234 void AudioOutputDelegateImpl::DoLog(const std::string& msg) { |
| 235 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 236 std::ostringstream oss; |
| 237 oss << "[stream_id=" << stream_id_ << "] " << msg; |
| 238 const std::string message = oss.str(); |
| 239 content::MediaStreamManager::SendMessageToNativeLog(message); |
| 240 DVLOG(1) << message; |
| 241 } |
| 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 |