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 ControllerEventHandler(base::WeakPtr<AudioOutputDelegateImpl> delegate, |
29 base::WeakPtr<AudioOutputDelegateImpl> delegate); | 30 int stream_id); |
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 const 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 int stream_id) |
| 46 : delegate_(std::move(delegate)), stream_id_(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 std::ostringstream oss; |
| 78 oss << "[stream_id=" << stream_id_ << "] " << message; |
| 79 const std::string out_message = oss.str(); |
| 80 content::MediaStreamManager::SendMessageToNativeLog(out_message); |
| 81 DVLOG(1) << out_message; |
| 82 } |
| 83 |
71 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( | 84 std::unique_ptr<media::AudioOutputDelegate> AudioOutputDelegateImpl::Create( |
72 EventHandler* handler, | 85 EventHandler* handler, |
73 media::AudioManager* audio_manager, | 86 media::AudioManager* audio_manager, |
74 std::unique_ptr<media::AudioLog> audio_log, | 87 std::unique_ptr<media::AudioLog> audio_log, |
75 AudioMirroringManager* mirroring_manager, | 88 AudioMirroringManager* mirroring_manager, |
76 MediaObserver* media_observer, | 89 MediaObserver* media_observer, |
77 int stream_id, | 90 int stream_id, |
78 int render_frame_id, | 91 int render_frame_id, |
79 int render_process_id, | 92 int render_process_id, |
80 const media::AudioParameters& params, | 93 const media::AudioParameters& params, |
(...skipping 30 matching lines...) Expand all Loading... |
111 weak_factory_(this) { | 124 weak_factory_(this) { |
112 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 125 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
113 DCHECK(subscriber_); | 126 DCHECK(subscriber_); |
114 DCHECK(audio_manager); | 127 DCHECK(audio_manager); |
115 DCHECK(audio_log_); | 128 DCHECK(audio_log_); |
116 DCHECK(mirroring_manager_); | 129 DCHECK(mirroring_manager_); |
117 DCHECK(reader_); | 130 DCHECK(reader_); |
118 // Since the event handler never directly calls functions on |this| but rather | 131 // 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 | 132 // posts them to the IO thread, passing a pointer from the constructor is |
120 // safe. | 133 // safe. |
121 controller_event_handler_ = | 134 controller_event_handler_ = base::MakeUnique<ControllerEventHandler>( |
122 base::MakeUnique<ControllerEventHandler>(weak_factory_.GetWeakPtr()); | 135 weak_factory_.GetWeakPtr(), stream_id_); |
123 audio_log_->OnCreated(stream_id, params, output_device_id); | 136 audio_log_->OnCreated(stream_id, params, output_device_id); |
124 controller_ = media::AudioOutputController::Create( | 137 controller_ = media::AudioOutputController::Create( |
125 audio_manager, controller_event_handler_.get(), params, output_device_id, | 138 audio_manager, controller_event_handler_.get(), params, output_device_id, |
126 reader_.get()); | 139 reader_.get()); |
127 DCHECK(controller_); | 140 DCHECK(controller_); |
128 if (media_observer) | 141 if (media_observer) |
129 media_observer->OnCreatingAudioStream(render_process_id, render_frame_id); | 142 media_observer->OnCreatingAudioStream(render_process_id, render_frame_id); |
130 mirroring_manager_->AddDiverter(render_process_id, render_frame_id, | 143 mirroring_manager_->AddDiverter(render_process_id, render_frame_id, |
131 controller_.get()); | 144 controller_.get()); |
132 } | 145 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 audio_log_->OnError(stream_id_); | 233 audio_log_->OnError(stream_id_); |
221 subscriber_->OnStreamError(stream_id_); | 234 subscriber_->OnStreamError(stream_id_); |
222 } | 235 } |
223 | 236 |
224 media::AudioOutputController* AudioOutputDelegateImpl::GetControllerForTesting() | 237 media::AudioOutputController* AudioOutputDelegateImpl::GetControllerForTesting() |
225 const { | 238 const { |
226 return controller_.get(); | 239 return controller_.get(); |
227 } | 240 } |
228 | 241 |
229 } // namespace content | 242 } // namespace content |
OLD | NEW |