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_; |
41 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 : delegate_(std::move(delegate)), stream_id_(delegate_->stream_id_) {} |
43 | 47 |
44 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerCreated() { | 48 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerCreated() { |
45 BrowserThread::PostTask( | 49 BrowserThread::PostTask( |
46 BrowserThread::IO, FROM_HERE, | 50 BrowserThread::IO, FROM_HERE, |
47 base::BindOnce(&AudioOutputDelegateImpl::SendCreatedNotification, | 51 base::BindOnce(&AudioOutputDelegateImpl::SendCreatedNotification, |
48 delegate_)); | 52 delegate_)); |
49 } | 53 } |
50 | 54 |
51 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPlaying() { | 55 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPlaying() { |
52 BrowserThread::PostTask( | 56 BrowserThread::PostTask( |
53 BrowserThread::IO, FROM_HERE, | 57 BrowserThread::IO, FROM_HERE, |
54 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, | 58 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, |
55 true)); | 59 true)); |
56 } | 60 } |
57 | 61 |
58 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPaused() { | 62 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerPaused() { |
59 BrowserThread::PostTask( | 63 BrowserThread::PostTask( |
60 BrowserThread::IO, FROM_HERE, | 64 BrowserThread::IO, FROM_HERE, |
61 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, | 65 base::BindOnce(&AudioOutputDelegateImpl::UpdatePlayingState, delegate_, |
62 false)); | 66 false)); |
63 } | 67 } |
64 | 68 |
65 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerError() { | 69 void AudioOutputDelegateImpl::ControllerEventHandler::OnControllerError() { |
66 BrowserThread::PostTask( | 70 BrowserThread::PostTask( |
67 BrowserThread::IO, FROM_HERE, | 71 BrowserThread::IO, FROM_HERE, |
68 base::BindOnce(&AudioOutputDelegateImpl::OnError, delegate_)); | 72 base::BindOnce(&AudioOutputDelegateImpl::OnError, delegate_)); |
69 } | 73 } |
70 | 74 |
75 void AudioOutputDelegateImpl::ControllerEventHandler::OnLog( | |
76 const std::string& message) { | |
77 BrowserThread::PostTask( | |
78 BrowserThread::IO, FROM_HERE, | |
79 base::Bind(&AudioOutputDelegateImpl::DoLog, stream_id_, message)); | |
Max Morin
2017/05/29 14:25:44
I just realized this should be BindOnce, like in a
ossu-chromium
2017/05/29 14:35:48
I think I've been a bit hazy on the significance o
Max Morin
2017/05/29 14:44:44
Yes, it's a sort of documentation (with added effi
| |
80 } | |
81 | |
71 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( | 82 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( |
72 EventHandler* handler, | 83 EventHandler* handler, |
73 media::AudioManager* audio_manager, | 84 media::AudioManager* audio_manager, |
74 std::unique_ptr<media::AudioLog> audio_log, | 85 std::unique_ptr<media::AudioLog> audio_log, |
75 AudioMirroringManager* mirroring_manager, | 86 AudioMirroringManager* mirroring_manager, |
76 MediaObserver* media_observer, | 87 MediaObserver* media_observer, |
77 int stream_id, | 88 int stream_id, |
78 int render_frame_id, | 89 int render_frame_id, |
79 int render_process_id, | 90 int render_process_id, |
80 const media::AudioParameters& params, | 91 const media::AudioParameters& params, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 render_frame_id_, stream_id_); | 224 render_frame_id_, stream_id_); |
214 } | 225 } |
215 } | 226 } |
216 | 227 |
217 void AudioOutputDelegateImpl::OnError() { | 228 void AudioOutputDelegateImpl::OnError() { |
218 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 229 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
219 | 230 |
220 audio_log_->OnError(stream_id_); | 231 audio_log_->OnError(stream_id_); |
221 subscriber_->OnStreamError(stream_id_); | 232 subscriber_->OnStreamError(stream_id_); |
222 } | 233 } |
223 | 234 |
liberato (no reviews please)
2017/05/30 16:53:34
please add "// static".
ossu-chromium
2017/05/31 11:16:27
See comment in audio_output_delegate_impl.h.
| |
235 void AudioOutputDelegateImpl::DoLog(int stream_id, const std::string& msg) { | |
236 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
237 std::ostringstream oss; | |
238 oss << "[stream_id=" << stream_id << "] " << msg; | |
239 const std::string message = oss.str(); | |
240 content::MediaStreamManager::SendMessageToNativeLog(message); | |
241 DVLOG(1) << message; | |
242 } | |
243 | |
224 media::AudioOutputController* AudioOutputDelegateImpl::GetControllerForTesting() | 244 media::AudioOutputController* AudioOutputDelegateImpl::GetControllerForTesting() |
225 const { | 245 const { |
226 return controller_.get(); | 246 return controller_.get(); |
227 } | 247 } |
228 | 248 |
229 } // namespace content | 249 } // namespace content |
OLD | NEW |