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

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

Issue 23731007: Implicit audio output device selection for getUserMedia. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase Created 7 years, 3 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 "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "content/renderer/media/audio_device_factory.h" 11 #include "content/renderer/media/audio_device_factory.h"
12 #include "content/renderer/media/webrtc_audio_capturer.h" 12 #include "content/renderer/media/webrtc_audio_capturer.h"
13 #include "content/renderer/render_thread_impl.h"
14 #include "media/audio/audio_output_device.h" 13 #include "media/audio/audio_output_device.h"
15 #include "media/base/audio_bus.h" 14 #include "media/base/audio_bus.h"
16 #include "media/base/audio_fifo.h" 15 #include "media/base/audio_fifo.h"
17 #include "media/base/audio_hardware_config.h"
18 16
19 namespace content { 17 namespace content {
20 18
21 // media::AudioRendererSink::RenderCallback implementation 19 // media::AudioRendererSink::RenderCallback implementation
22 int WebRtcLocalAudioRenderer::Render( 20 int WebRtcLocalAudioRenderer::Render(
23 media::AudioBus* audio_bus, int audio_delay_milliseconds) { 21 media::AudioBus* audio_bus, int audio_delay_milliseconds) {
24 base::AutoLock auto_lock(thread_lock_); 22 base::AutoLock auto_lock(thread_lock_);
25 23
26 if (!playing_) { 24 if (!playing_) {
27 audio_bus->Zero(); 25 audio_bus->Zero();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 87 }
90 88
91 void WebRtcLocalAudioRenderer::SetCaptureFormat( 89 void WebRtcLocalAudioRenderer::SetCaptureFormat(
92 const media::AudioParameters& params) { 90 const media::AudioParameters& params) {
93 audio_params_ = params; 91 audio_params_ = params;
94 } 92 }
95 93
96 // WebRtcLocalAudioRenderer::WebRtcLocalAudioRenderer implementation. 94 // WebRtcLocalAudioRenderer::WebRtcLocalAudioRenderer implementation.
97 WebRtcLocalAudioRenderer::WebRtcLocalAudioRenderer( 95 WebRtcLocalAudioRenderer::WebRtcLocalAudioRenderer(
98 WebRtcLocalAudioTrack* audio_track, 96 WebRtcLocalAudioTrack* audio_track,
99 int source_render_view_id) 97 int source_render_view_id,
98 int session_id,
99 int sample_rate,
100 int frames_per_buffer)
100 : audio_track_(audio_track), 101 : audio_track_(audio_track),
101 source_render_view_id_(source_render_view_id), 102 source_render_view_id_(source_render_view_id),
102 playing_(false) { 103 session_id_(session_id),
104 playing_(false),
105 sample_rate_(sample_rate),
106 frames_per_buffer_(frames_per_buffer) {
103 DCHECK(audio_track); 107 DCHECK(audio_track);
104 DVLOG(1) << "WebRtcLocalAudioRenderer::WebRtcLocalAudioRenderer()"; 108 DVLOG(1) << "WebRtcLocalAudioRenderer::WebRtcLocalAudioRenderer()";
105 } 109 }
106 110
107 WebRtcLocalAudioRenderer::~WebRtcLocalAudioRenderer() { 111 WebRtcLocalAudioRenderer::~WebRtcLocalAudioRenderer() {
108 DCHECK(thread_checker_.CalledOnValidThread()); 112 DCHECK(thread_checker_.CalledOnValidThread());
109 DCHECK(!sink_.get()); 113 DCHECK(!sink_.get());
110 DVLOG(1) << "WebRtcLocalAudioRenderer::~WebRtcLocalAudioRenderer()"; 114 DVLOG(1) << "WebRtcLocalAudioRenderer::~WebRtcLocalAudioRenderer()";
111 } 115 }
112 116
(...skipping 13 matching lines...) Expand all
126 // that we start to build up latency and that can be more difficult to 130 // that we start to build up latency and that can be more difficult to
127 // detect. Tests have shown that the FIFO never contains more than 2 or 3 131 // detect. Tests have shown that the FIFO never contains more than 2 or 3
128 // audio frames but I have selected a max size of ten buffers just 132 // audio frames but I have selected a max size of ten buffers just
129 // in case since these tests were performed on a 16 core, 64GB Win 7 133 // in case since these tests were performed on a 16 core, 64GB Win 7
130 // machine. We could also add some sort of error notifier in this area if 134 // machine. We could also add some sort of error notifier in this area if
131 // the FIFO overflows. 135 // the FIFO overflows.
132 DCHECK(!loopback_fifo_); 136 DCHECK(!loopback_fifo_);
133 loopback_fifo_.reset(new media::AudioFifo( 137 loopback_fifo_.reset(new media::AudioFifo(
134 audio_params_.channels(), 10 * audio_params_.frames_per_buffer())); 138 audio_params_.channels(), 10 * audio_params_.frames_per_buffer()));
135 139
136 #if defined(OS_ANDROID)
137 media::AudioHardwareConfig* hardware_config =
138 RenderThreadImpl::current()->GetAudioHardwareConfig();
139 #endif
140
141 media::AudioParameters sink_params(audio_params_.format(), 140 media::AudioParameters sink_params(audio_params_.format(),
142 audio_params_.channel_layout(), 141 audio_params_.channel_layout(),
143 audio_params_.sample_rate(), 142 audio_params_.sample_rate(),
144 audio_params_.bits_per_sample(), 143 audio_params_.bits_per_sample(),
145 #if defined(OS_ANDROID) 144 #if defined(OS_ANDROID)
146 // On Android, input and output are using same sampling rate. In order to 145 // On Android, input and output are using same sampling rate. In order to
147 // achieve low latency mode, we need use buffer size suggested by 146 // achieve low latency mode, we need use buffer size suggested by
148 // AudioManager for the sink paramters which will be used to decide 147 // AudioManager for the sink paramters which will be used to decide
149 // buffer size for shared memory buffer. 148 // buffer size for shared memory buffer.
150 hardware_config->GetOutputBufferSize() 149 frames_per_buffer_
151 #else 150 #else
152 2 * audio_params_.frames_per_buffer() 151 2 * audio_params_.frames_per_buffer()
153 #endif 152 #endif
154 ); 153 );
154
155 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_view_id_); 155 sink_ = AudioDeviceFactory::NewOutputDevice(source_render_view_id_);
156 156
157 // TODO(henrika): we could utilize the unified audio here instead and do 157 // TODO(henrika): we could utilize the unified audio here instead and do
158 // sink_->InitializeIO(sink_params, 2, callback_.get()); 158 // sink_->InitializeIO(sink_params, 2, callback_.get());
159 // It would then be possible to avoid using the WebRtcAudioCapturer. 159 // It would then be possible to avoid using the WebRtcAudioCapturer.
160 sink_->Initialize(sink_params, this); 160 sink_->InitializeUnifiedStream(sink_params, this, session_id_);
161 161
162 // Start the capturer and local rendering. Note that, the capturer is owned 162 // Start the capturer and local rendering. Note that, the capturer is owned
163 // by the WebRTC ADM and might already bee running. 163 // by the WebRTC ADM and might already bee running.
164 sink_->Start(); 164 sink_->Start();
165 165
166 last_render_time_ = base::Time::Now(); 166 last_render_time_ = base::Time::Now();
167 playing_ = false; 167 playing_ = false;
168 } 168 }
169 169
170 void WebRtcLocalAudioRenderer::Stop() { 170 void WebRtcLocalAudioRenderer::Stop() {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (!sink_.get()) 240 if (!sink_.get())
241 return base::TimeDelta(); 241 return base::TimeDelta();
242 return total_render_time(); 242 return total_render_time();
243 } 243 }
244 244
245 bool WebRtcLocalAudioRenderer::IsLocalRenderer() const { 245 bool WebRtcLocalAudioRenderer::IsLocalRenderer() const {
246 return true; 246 return true;
247 } 247 }
248 248
249 } // namespace content 249 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_local_audio_renderer.h ('k') | content/test/webrtc_audio_device_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698