Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: content/renderer/media/webrtc_local_audio_renderer.cc

Issue 1666363005: Switching audio clients to using RestartableAudioRendererSink interface as a sink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/media/webrtc_local_audio_renderer.h" 5 #include "content/renderer/media/webrtc_local_audio_renderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/synchronization/lock.h" 12 #include "base/synchronization/lock.h"
13 #include "base/thread_task_runner_handle.h" 13 #include "base/thread_task_runner_handle.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "content/renderer/media/audio_device_factory.h"
16 #include "content/renderer/media/media_stream_dispatcher.h" 15 #include "content/renderer/media/media_stream_dispatcher.h"
16 #include "content/renderer/media/restartable_audio_output_device_factory.h"
17 #include "content/renderer/media/webrtc_audio_capturer.h" 17 #include "content/renderer/media/webrtc_audio_capturer.h"
18 #include "content/renderer/media/webrtc_audio_renderer.h" 18 #include "content/renderer/media/webrtc_audio_renderer.h"
19 #include "content/renderer/render_frame_impl.h" 19 #include "content/renderer/render_frame_impl.h"
20 #include "media/audio/audio_output_device.h"
21 #include "media/base/audio_bus.h" 20 #include "media/base/audio_bus.h"
22 #include "media/base/audio_shifter.h" 21 #include "media/base/audio_shifter.h"
22 #include "media/base/restartable_audio_output_device.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 namespace { 26 namespace {
27 27
28 enum LocalRendererSinkStates { 28 enum LocalRendererSinkStates {
29 kSinkStarted = 0, 29 kSinkStarted = 0,
30 kSinkNeverStarted, 30 kSinkNeverStarted,
31 kSinkStatesMax // Must always be last! 31 kSinkStatesMax // Must always be last!
32 }; 32 };
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 120
121 void WebRtcLocalAudioRenderer::Start() { 121 void WebRtcLocalAudioRenderer::Start() {
122 DVLOG(1) << "WebRtcLocalAudioRenderer::Start()"; 122 DVLOG(1) << "WebRtcLocalAudioRenderer::Start()";
123 DCHECK(task_runner_->BelongsToCurrentThread()); 123 DCHECK(task_runner_->BelongsToCurrentThread());
124 124
125 // We get audio data from |audio_track_|... 125 // We get audio data from |audio_track_|...
126 MediaStreamAudioSink::AddToAudioTrack(this, audio_track_); 126 MediaStreamAudioSink::AddToAudioTrack(this, audio_track_);
127 // ...and |sink_| will get audio data from us. 127 // ...and |sink_| will get audio data from us.
128 DCHECK(!sink_.get()); 128 DCHECK(!sink_.get());
129 sink_ = 129 sink_ = RestartableAudioOutputDeviceFactory::NewOutputDevice(
130 AudioDeviceFactory::NewOutputDevice(source_render_frame_id_, session_id_, 130 RestartableAudioOutputDeviceFactory::kSourceLocalUserMedia,
131 output_device_id_, security_origin_); 131 source_render_frame_id_, session_id_, output_device_id_,
132 security_origin_);
132 133
133 base::AutoLock auto_lock(thread_lock_); 134 base::AutoLock auto_lock(thread_lock_);
134 last_render_time_ = base::TimeTicks::Now(); 135 last_render_time_ = base::TimeTicks::Now();
135 playing_ = false; 136 playing_ = false;
136 } 137 }
137 138
138 void WebRtcLocalAudioRenderer::Stop() { 139 void WebRtcLocalAudioRenderer::Stop() {
139 DVLOG(1) << "WebRtcLocalAudioRenderer::Stop()"; 140 DVLOG(1) << "WebRtcLocalAudioRenderer::Stop()";
140 DCHECK(task_runner_->BelongsToCurrentThread()); 141 DCHECK(task_runner_->BelongsToCurrentThread());
141 142
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return true; 232 return true;
232 } 233 }
233 234
234 void WebRtcLocalAudioRenderer::SwitchOutputDevice( 235 void WebRtcLocalAudioRenderer::SwitchOutputDevice(
235 const std::string& device_id, 236 const std::string& device_id,
236 const url::Origin& security_origin, 237 const url::Origin& security_origin,
237 const media::SwitchOutputDeviceCB& callback) { 238 const media::SwitchOutputDeviceCB& callback) {
238 DVLOG(1) << "WebRtcLocalAudioRenderer::SwitchOutputDevice()"; 239 DVLOG(1) << "WebRtcLocalAudioRenderer::SwitchOutputDevice()";
239 DCHECK(task_runner_->BelongsToCurrentThread()); 240 DCHECK(task_runner_->BelongsToCurrentThread());
240 241
241 scoped_refptr<media::AudioOutputDevice> new_sink = 242 scoped_refptr<media::RestartableAudioOutputDevice> new_sink =
242 AudioDeviceFactory::NewOutputDevice(source_render_frame_id_, session_id_, 243 RestartableAudioOutputDeviceFactory::NewOutputDevice(
243 device_id, security_origin); 244 RestartableAudioOutputDeviceFactory::kSourceLocalUserMedia,
245 source_render_frame_id_, session_id_, device_id, security_origin);
244 if (new_sink->GetDeviceStatus() != media::OUTPUT_DEVICE_STATUS_OK) { 246 if (new_sink->GetDeviceStatus() != media::OUTPUT_DEVICE_STATUS_OK) {
245 callback.Run(new_sink->GetDeviceStatus()); 247 callback.Run(new_sink->GetDeviceStatus());
246 return; 248 return;
247 } 249 }
248 250
249 output_device_id_ = device_id; 251 output_device_id_ = device_id;
250 security_origin_ = security_origin; 252 security_origin_ = security_origin;
251 bool was_sink_started = sink_started_; 253 bool was_sink_started = sink_started_;
252 254
253 if (sink_.get()) 255 if (sink_.get())
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 audio_shifter_->Flush(); 297 audio_shifter_->Flush();
296 } 298 }
297 299
298 if (!sink_params_.IsValid() || !playing_ || !volume_ || sink_started_ || 300 if (!sink_params_.IsValid() || !playing_ || !volume_ || sink_started_ ||
299 sink_->GetDeviceStatus() != media::OUTPUT_DEVICE_STATUS_OK) 301 sink_->GetDeviceStatus() != media::OUTPUT_DEVICE_STATUS_OK)
300 return; 302 return;
301 303
302 DVLOG(1) << "WebRtcLocalAudioRenderer::MaybeStartSink() -- Starting sink_."; 304 DVLOG(1) << "WebRtcLocalAudioRenderer::MaybeStartSink() -- Starting sink_.";
303 sink_->Initialize(sink_params_, this); 305 sink_->Initialize(sink_params_, this);
304 sink_->Start(); 306 sink_->Start();
307 sink_->Play(); // RestartableAudioOutputDevice does not play on start.
305 sink_started_ = true; 308 sink_started_ = true;
306 UMA_HISTOGRAM_ENUMERATION("Media.LocalRendererSinkStates", 309 UMA_HISTOGRAM_ENUMERATION("Media.LocalRendererSinkStates",
307 kSinkStarted, kSinkStatesMax); 310 kSinkStarted, kSinkStatesMax);
308 } 311 }
309 312
310 void WebRtcLocalAudioRenderer::ReconfigureSink( 313 void WebRtcLocalAudioRenderer::ReconfigureSink(
311 const media::AudioParameters& params) { 314 const media::AudioParameters& params) {
312 DCHECK(task_runner_->BelongsToCurrentThread()); 315 DCHECK(task_runner_->BelongsToCurrentThread());
313 316
314 DVLOG(1) << "WebRtcLocalAudioRenderer::ReconfigureSink()"; 317 DVLOG(1) << "WebRtcLocalAudioRenderer::ReconfigureSink()";
(...skipping 21 matching lines...) Expand all
336 audio_shifter_.reset(new_shifter); 339 audio_shifter_.reset(new_shifter);
337 } 340 }
338 341
339 if (!sink_.get()) 342 if (!sink_.get())
340 return; // WebRtcLocalAudioRenderer has not yet been started. 343 return; // WebRtcLocalAudioRenderer has not yet been started.
341 344
342 // Stop |sink_| and re-create a new one to be initialized with different audio 345 // Stop |sink_| and re-create a new one to be initialized with different audio
343 // parameters. Then, invoke MaybeStartSink() to restart everything again. 346 // parameters. Then, invoke MaybeStartSink() to restart everything again.
344 sink_->Stop(); 347 sink_->Stop();
345 sink_started_ = false; 348 sink_started_ = false;
346 sink_ = 349 sink_ = RestartableAudioOutputDeviceFactory::NewOutputDevice(
347 AudioDeviceFactory::NewOutputDevice(source_render_frame_id_, session_id_, 350 RestartableAudioOutputDeviceFactory::kSourceLocalUserMedia,
348 output_device_id_, security_origin_); 351 source_render_frame_id_, session_id_, output_device_id_,
352 security_origin_);
349 int frames_per_buffer = sink_->GetOutputParameters().frames_per_buffer(); 353 int frames_per_buffer = sink_->GetOutputParameters().frames_per_buffer();
350 sink_params_ = source_params_; 354 sink_params_ = source_params_;
351 sink_params_.set_frames_per_buffer(WebRtcAudioRenderer::GetOptimalBufferSize( 355 sink_params_.set_frames_per_buffer(WebRtcAudioRenderer::GetOptimalBufferSize(
352 source_params_.sample_rate(), frames_per_buffer)); 356 source_params_.sample_rate(), frames_per_buffer));
353 MaybeStartSink(); 357 MaybeStartSink();
354 } 358 }
355 359
356 } // namespace content 360 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698