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

Side by Side Diff: content/renderer/media/webrtc_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_audio_renderer.h" 5 #include "content/renderer/media/webrtc_audio_renderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "content/renderer/media/audio_device_factory.h"
15 #include "content/renderer/media/media_stream_audio_track.h" 14 #include "content/renderer/media/media_stream_audio_track.h"
16 #include "content/renderer/media/media_stream_dispatcher.h" 15 #include "content/renderer/media/media_stream_dispatcher.h"
17 #include "content/renderer/media/media_stream_track.h" 16 #include "content/renderer/media/media_stream_track.h"
17 #include "content/renderer/media/restartable_audio_output_device_factory.h"
18 #include "content/renderer/media/webrtc_audio_device_impl.h" 18 #include "content/renderer/media/webrtc_audio_device_impl.h"
19 #include "content/renderer/media/webrtc_logging.h" 19 #include "content/renderer/media/webrtc_logging.h"
20 #include "content/renderer/render_frame_impl.h" 20 #include "content/renderer/render_frame_impl.h"
21 #include "media/audio/audio_output_device.h"
22 #include "media/audio/audio_parameters.h" 21 #include "media/audio/audio_parameters.h"
23 #include "media/audio/sample_rates.h" 22 #include "media/audio/sample_rates.h"
23 #include "media/base/restartable_audio_output_device.h"
24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
25 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" 25 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
26 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h" 26 #include "third_party/libjingle/source/talk/media/base/audiorenderer.h"
27 27
28 #if defined(OS_WIN) 28 #if defined(OS_WIN)
29 #include "base/win/windows_version.h" 29 #include "base/win/windows_version.h"
30 #include "media/audio/win/core_audio_util_win.h" 30 #include "media/audio/win/core_audio_util_win.h"
31 #endif 31 #endif
32 32
33 namespace content { 33 namespace content {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 DCHECK(thread_checker_.CalledOnValidThread()); 214 DCHECK(thread_checker_.CalledOnValidThread());
215 DCHECK(source); 215 DCHECK(source);
216 DCHECK(!sink_.get()); 216 DCHECK(!sink_.get());
217 DCHECK_GE(session_id_, 0); 217 DCHECK_GE(session_id_, 0);
218 { 218 {
219 base::AutoLock auto_lock(lock_); 219 base::AutoLock auto_lock(lock_);
220 DCHECK_EQ(state_, UNINITIALIZED); 220 DCHECK_EQ(state_, UNINITIALIZED);
221 DCHECK(!source_); 221 DCHECK(!source_);
222 } 222 }
223 223
224 sink_ = 224 sink_ = RestartableAudioOutputDeviceFactory::NewOutputDevice(
225 AudioDeviceFactory::NewOutputDevice(source_render_frame_id_, session_id_, 225 RestartableAudioOutputDeviceFactory::kSourceWebRTC,
226 output_device_id_, security_origin_); 226 source_render_frame_id_, session_id_, output_device_id_,
227 security_origin_);
228
227 if (sink_->GetDeviceStatus() != media::OUTPUT_DEVICE_STATUS_OK) 229 if (sink_->GetDeviceStatus() != media::OUTPUT_DEVICE_STATUS_OK)
228 return false; 230 return false;
229 231
230 PrepareSink(); 232 PrepareSink();
231 { 233 {
232 // No need to reassert the preconditions because the other thread accessing 234 // No need to reassert the preconditions because the other thread accessing
233 // the fields (checked by |audio_renderer_thread_checker_|) only reads them. 235 // the fields (checked by |audio_renderer_thread_checker_|) only reads them.
234 base::AutoLock auto_lock(lock_); 236 base::AutoLock auto_lock(lock_);
235 source_ = source; 237 source_ = source;
236 238
237 // User must call Play() before any audio can be heard. 239 // User must call Play() before any audio can be heard.
238 state_ = PAUSED; 240 state_ = PAUSED;
239 } 241 }
240 sink_->Start(); 242 sink_->Start();
243 sink_->Play(); // RestartableAudioOutputDevice does not play on start.
241 244
242 return true; 245 return true;
243 } 246 }
244 247
245 scoped_refptr<MediaStreamAudioRenderer> 248 scoped_refptr<MediaStreamAudioRenderer>
246 WebRtcAudioRenderer::CreateSharedAudioRendererProxy( 249 WebRtcAudioRenderer::CreateSharedAudioRendererProxy(
247 const blink::WebMediaStream& media_stream) { 250 const blink::WebMediaStream& media_stream) {
248 content::SharedAudioRenderer::OnPlayStateChanged on_play_state_changed = 251 content::SharedAudioRenderer::OnPlayStateChanged on_play_state_changed =
249 base::Bind(&WebRtcAudioRenderer::OnPlayStateChanged, this); 252 base::Bind(&WebRtcAudioRenderer::OnPlayStateChanged, this);
250 return new SharedAudioRenderer(this, media_stream, on_play_state_changed); 253 return new SharedAudioRenderer(this, media_stream, on_play_state_changed);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 const media::SwitchOutputDeviceCB& callback) { 376 const media::SwitchOutputDeviceCB& callback) {
374 DVLOG(1) << "WebRtcAudioRenderer::SwitchOutputDevice()"; 377 DVLOG(1) << "WebRtcAudioRenderer::SwitchOutputDevice()";
375 DCHECK(thread_checker_.CalledOnValidThread()); 378 DCHECK(thread_checker_.CalledOnValidThread());
376 DCHECK_GE(session_id_, 0); 379 DCHECK_GE(session_id_, 0);
377 { 380 {
378 base::AutoLock auto_lock(lock_); 381 base::AutoLock auto_lock(lock_);
379 DCHECK(source_); 382 DCHECK(source_);
380 DCHECK_NE(state_, UNINITIALIZED); 383 DCHECK_NE(state_, UNINITIALIZED);
381 } 384 }
382 385
383 scoped_refptr<media::AudioOutputDevice> new_sink = 386 scoped_refptr<media::RestartableAudioOutputDevice> new_sink =
384 AudioDeviceFactory::NewOutputDevice(source_render_frame_id_, session_id_, 387 RestartableAudioOutputDeviceFactory::NewOutputDevice(
385 device_id, security_origin); 388 RestartableAudioOutputDeviceFactory::kSourceWebRTC,
389 source_render_frame_id_, session_id_, device_id, security_origin);
386 if (new_sink->GetDeviceStatus() != media::OUTPUT_DEVICE_STATUS_OK) { 390 if (new_sink->GetDeviceStatus() != media::OUTPUT_DEVICE_STATUS_OK) {
387 callback.Run(new_sink->GetDeviceStatus()); 391 callback.Run(new_sink->GetDeviceStatus());
388 return; 392 return;
389 } 393 }
390 394
391 // Make sure to stop the sink while _not_ holding the lock since the Render() 395 // Make sure to stop the sink while _not_ holding the lock since the Render()
392 // callback may currently be executing and trying to grab the lock while we're 396 // callback may currently be executing and trying to grab the lock while we're
393 // stopping the thread on which it runs. 397 // stopping the thread on which it runs.
394 sink_->Stop(); 398 sink_->Stop();
395 audio_renderer_thread_checker_.DetachFromThread(); 399 audio_renderer_thread_checker_.DetachFromThread();
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 base::Bind(&WebRtcAudioRenderer::SourceCallback, 667 base::Bind(&WebRtcAudioRenderer::SourceCallback,
664 base::Unretained(this)))); 668 base::Unretained(this))));
665 } 669 }
666 sink_params_ = new_sink_params; 670 sink_params_ = new_sink_params;
667 } 671 }
668 672
669 sink_->Initialize(new_sink_params, this); 673 sink_->Initialize(new_sink_params, this);
670 } 674 }
671 675
672 } // namespace content 676 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698