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

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

Issue 10823175: Switch AudioRenderSink::Callback to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Gotta catch'em all! Created 8 years, 4 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 | Annotate | Revision Log
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_device_impl.h" 5 #include "content/renderer/media/webrtc_audio_device_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 int32_t WebRtcAudioDeviceImpl::Release() { 168 int32_t WebRtcAudioDeviceImpl::Release() {
169 int ret = base::subtle::Barrier_AtomicIncrement(&ref_count_, -1); 169 int ret = base::subtle::Barrier_AtomicIncrement(&ref_count_, -1);
170 if (ret == 0) { 170 if (ret == 0) {
171 delete this; 171 delete this;
172 } 172 }
173 return ret; 173 return ret;
174 } 174 }
175 175
176 int WebRtcAudioDeviceImpl::Render( 176 int WebRtcAudioDeviceImpl::Render(
177 const std::vector<float*>& audio_data, 177 media::AudioBus* audio_bus,
178 int number_of_frames, 178 int number_of_frames,
179 int audio_delay_milliseconds) { 179 int audio_delay_milliseconds) {
180 DCHECK_LE(number_of_frames, output_buffer_size()); 180 DCHECK_LE(number_of_frames, output_buffer_size());
181 181
182 { 182 {
183 base::AutoLock auto_lock(lock_); 183 base::AutoLock auto_lock(lock_);
184 // Store the reported audio delay locally. 184 // Store the reported audio delay locally.
185 output_delay_ms_ = audio_delay_milliseconds; 185 output_delay_ms_ = audio_delay_milliseconds;
186 } 186 }
187 187
188 const int channels = audio_data.size(); 188 const int channels = audio_bus->channels();
189 DCHECK_LE(channels, output_channels()); 189 DCHECK_LE(channels, output_channels());
190 190
191 int samples_per_sec = output_sample_rate(); 191 int samples_per_sec = output_sample_rate();
192 if (samples_per_sec == 44100) { 192 if (samples_per_sec == 44100) {
193 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. 193 // Even if the hardware runs at 44.1kHz, we use 44.0 internally.
194 samples_per_sec = 44000; 194 samples_per_sec = 44000;
195 } 195 }
196 int samples_per_10_msec = (samples_per_sec / 100); 196 int samples_per_10_msec = (samples_per_sec / 100);
197 const int bytes_per_10_msec = 197 const int bytes_per_10_msec =
198 channels * samples_per_10_msec * bytes_per_sample_; 198 channels * samples_per_10_msec * bytes_per_sample_;
(...skipping 16 matching lines...) Expand all
215 num_audio_samples); 215 num_audio_samples);
216 accumulated_audio_samples += num_audio_samples; 216 accumulated_audio_samples += num_audio_samples;
217 audio_byte_buffer += bytes_per_10_msec; 217 audio_byte_buffer += bytes_per_10_msec;
218 } 218 }
219 219
220 // Deinterleave each channel and convert to 32-bit floating-point 220 // Deinterleave each channel and convert to 32-bit floating-point
221 // with nominal range -1.0 -> +1.0 to match the callback format. 221 // with nominal range -1.0 -> +1.0 to match the callback format.
222 for (int channel_index = 0; channel_index < channels; ++channel_index) { 222 for (int channel_index = 0; channel_index < channels; ++channel_index) {
223 media::DeinterleaveAudioChannel( 223 media::DeinterleaveAudioChannel(
224 output_buffer_.get(), 224 output_buffer_.get(),
225 audio_data[channel_index], 225 audio_bus->channel(channel_index),
226 channels, 226 channels,
227 channel_index, 227 channel_index,
228 bytes_per_sample_, 228 bytes_per_sample_,
229 number_of_frames); 229 number_of_frames);
230 } 230 }
231 return number_of_frames; 231 return number_of_frames;
232 } 232 }
233 233
234 void WebRtcAudioDeviceImpl::OnRenderError() { 234 void WebRtcAudioDeviceImpl::OnRenderError() {
235 DCHECK_EQ(MessageLoop::current(), ChildProcess::current()->io_message_loop()); 235 DCHECK_EQ(MessageLoop::current(), ChildProcess::current()->io_message_loop());
236 // TODO(henrika): Implement error handling. 236 // TODO(henrika): Implement error handling.
237 LOG(ERROR) << "OnRenderError()"; 237 LOG(ERROR) << "OnRenderError()";
238 } 238 }
239 239
240 void WebRtcAudioDeviceImpl::Capture(const std::vector<float*>& audio_data, 240 void WebRtcAudioDeviceImpl::Capture(media::AudioBus* audio_bus,
241 int number_of_frames, 241 int number_of_frames,
242 int audio_delay_milliseconds, 242 int audio_delay_milliseconds,
243 double volume) { 243 double volume) {
244 DCHECK_LE(number_of_frames, input_buffer_size()); 244 DCHECK_LE(number_of_frames, input_buffer_size());
245 #if defined(OS_WIN) || defined(OS_MACOSX) 245 #if defined(OS_WIN) || defined(OS_MACOSX)
246 DCHECK_LE(volume, 1.0); 246 DCHECK_LE(volume, 1.0);
247 #elif defined(OS_LINUX) || defined(OS_OPENBSD) 247 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
248 // We have a special situation on Linux where the microphone volume can be 248 // We have a special situation on Linux where the microphone volume can be
249 // "higher than maximum". The input volume slider in the sound preference 249 // "higher than maximum". The input volume slider in the sound preference
250 // allows the user to set a scaling that is higher than 100%. It means that 250 // allows the user to set a scaling that is higher than 100%. It means that
251 // even if the reported maximum levels is N, the actual microphone level can 251 // even if the reported maximum levels is N, the actual microphone level can
252 // go up to 1.5*N and that corresponds to a normalized |volume| of 1.5. 252 // go up to 1.5*N and that corresponds to a normalized |volume| of 1.5.
253 DCHECK_LE(volume, 1.5); 253 DCHECK_LE(volume, 1.5);
254 #endif 254 #endif
255 255
256 int output_delay_ms = 0; 256 int output_delay_ms = 0;
257 { 257 {
258 base::AutoLock auto_lock(lock_); 258 base::AutoLock auto_lock(lock_);
259 // Store the reported audio delay locally. 259 // Store the reported audio delay locally.
260 input_delay_ms_ = audio_delay_milliseconds; 260 input_delay_ms_ = audio_delay_milliseconds;
261 output_delay_ms = output_delay_ms_; 261 output_delay_ms = output_delay_ms_;
262 } 262 }
263 263
264 const int channels = audio_data.size(); 264 const int channels = audio_bus->channels();
265 DCHECK_LE(channels, input_channels()); 265 DCHECK_LE(channels, input_channels());
266 uint32_t new_mic_level = 0; 266 uint32_t new_mic_level = 0;
267 267
268 // Interleave, scale, and clip input to int and store result in 268 // Interleave, scale, and clip input to int and store result in
269 // a local byte buffer. 269 // a local byte buffer.
270 media::InterleaveFloatToInt(audio_data, 270 media::InterleaveFloatToInt(*audio_bus,
271 input_buffer_.get(), 271 input_buffer_.get(),
272 number_of_frames, 272 number_of_frames,
273 input_audio_parameters_.bits_per_sample() / 8); 273 input_audio_parameters_.bits_per_sample() / 8);
274 274
275 int samples_per_sec = input_sample_rate(); 275 int samples_per_sec = input_sample_rate();
276 if (samples_per_sec == 44100) { 276 if (samples_per_sec == 44100) {
277 // Even if the hardware runs at 44.1kHz, we use 44.0 internally. 277 // Even if the hardware runs at 44.1kHz, we use 44.0 internally.
278 samples_per_sec = 44000; 278 samples_per_sec = 44000;
279 } 279 }
280 const int samples_per_10_msec = (samples_per_sec / 100); 280 const int samples_per_10_msec = (samples_per_sec / 100);
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 } 1168 }
1169 1169
1170 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const { 1170 int32_t WebRtcAudioDeviceImpl::GetLoudspeakerStatus(bool* enabled) const {
1171 NOTIMPLEMENTED(); 1171 NOTIMPLEMENTED();
1172 return -1; 1172 return -1;
1173 } 1173 }
1174 1174
1175 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) { 1175 void WebRtcAudioDeviceImpl::SetSessionId(int session_id) {
1176 session_id_ = session_id; 1176 session_id_ = session_id;
1177 } 1177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698