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

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

Issue 518433002: Revert of Revert of Remove the last piece of deprecated synchronous IO code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | 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_renderer.h" 5 #include "content/renderer/media/webrtc_audio_renderer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 source_render_view_id_(source_render_view_id), 211 source_render_view_id_(source_render_view_id),
212 source_render_frame_id_(source_render_frame_id), 212 source_render_frame_id_(source_render_frame_id),
213 session_id_(session_id), 213 session_id_(session_id),
214 media_stream_(media_stream), 214 media_stream_(media_stream),
215 source_(NULL), 215 source_(NULL),
216 play_ref_count_(0), 216 play_ref_count_(0),
217 start_ref_count_(0), 217 start_ref_count_(0),
218 audio_delay_milliseconds_(0), 218 audio_delay_milliseconds_(0),
219 fifo_delay_milliseconds_(0), 219 fifo_delay_milliseconds_(0),
220 sink_params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 220 sink_params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
221 media::CHANNEL_LAYOUT_STEREO, 0, sample_rate, 16, 221 media::CHANNEL_LAYOUT_STEREO, sample_rate, 16,
222 frames_per_buffer, 222 frames_per_buffer,
223 GetCurrentDuckingFlag(source_render_frame_id)) { 223 GetCurrentDuckingFlag(source_render_frame_id)) {
224 WebRtcLogMessage(base::StringPrintf( 224 WebRtcLogMessage(base::StringPrintf(
225 "WAR::WAR. source_render_view_id=%d" 225 "WAR::WAR. source_render_view_id=%d"
226 ", session_id=%d, sample_rate=%d, frames_per_buffer=%d, effects=%i", 226 ", session_id=%d, sample_rate=%d, frames_per_buffer=%d, effects=%i",
227 source_render_view_id, 227 source_render_view_id,
228 session_id, 228 session_id,
229 sample_rate, 229 sample_rate,
230 frames_per_buffer, 230 frames_per_buffer,
231 sink_params_.effects())); 231 sink_params_.effects()));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 278
279 // Set up audio parameters for the source, i.e., the WebRTC client. 279 // Set up audio parameters for the source, i.e., the WebRTC client.
280 280
281 // The WebRTC client only supports multiples of 10ms as buffer size where 281 // The WebRTC client only supports multiples of 10ms as buffer size where
282 // 10ms is preferred for lowest possible delay. 282 // 10ms is preferred for lowest possible delay.
283 media::AudioParameters source_params; 283 media::AudioParameters source_params;
284 const int frames_per_10ms = (sample_rate / 100); 284 const int frames_per_10ms = (sample_rate / 100);
285 DVLOG(1) << "Using WebRTC output buffer size: " << frames_per_10ms; 285 DVLOG(1) << "Using WebRTC output buffer size: " << frames_per_10ms;
286 286
287 source_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 287 source_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
288 sink_params_.channel_layout(), sink_params_.channels(), 0, 288 sink_params_.channel_layout(), sink_params_.channels(),
289 sample_rate, 16, frames_per_10ms); 289 sample_rate, 16, frames_per_10ms);
290 290
291 // Update audio parameters for the sink, i.e., the native audio output stream. 291 // Update audio parameters for the sink, i.e., the native audio output stream.
292 // We strive to open up using native parameters to achieve best possible 292 // We strive to open up using native parameters to achieve best possible
293 // performance and to ensure that no FIFO is needed on the browser side to 293 // performance and to ensure that no FIFO is needed on the browser side to
294 // match the client request. Any mismatch between the source and the sink is 294 // match the client request. Any mismatch between the source and the sink is
295 // taken care of in this class instead using a pull FIFO. 295 // taken care of in this class instead using a pull FIFO.
296 296
297 // Use native output size as default. 297 // Use native output size as default.
298 int frames_per_buffer = sink_params_.frames_per_buffer(); 298 int frames_per_buffer = sink_params_.frames_per_buffer();
299 #if defined(OS_ANDROID) 299 #if defined(OS_ANDROID)
300 // TODO(henrika): Keep tuning this scheme and espcicially for low-latency 300 // TODO(henrika): Keep tuning this scheme and espcicially for low-latency
301 // cases. Might not be possible to come up with the perfect solution using 301 // cases. Might not be possible to come up with the perfect solution using
302 // the render side only. 302 // the render side only.
303 if (frames_per_buffer < 2 * frames_per_10ms) { 303 if (frames_per_buffer < 2 * frames_per_10ms) {
304 // Examples of low-latency frame sizes and the resulting |buffer_size|: 304 // Examples of low-latency frame sizes and the resulting |buffer_size|:
305 // Nexus 7 : 240 audio frames => 2*480 = 960 305 // Nexus 7 : 240 audio frames => 2*480 = 960
306 // Nexus 10 : 256 => 2*441 = 882 306 // Nexus 10 : 256 => 2*441 = 882
307 // Galaxy Nexus: 144 => 2*441 = 882 307 // Galaxy Nexus: 144 => 2*441 = 882
308 frames_per_buffer = 2 * frames_per_10ms; 308 frames_per_buffer = 2 * frames_per_10ms;
309 DVLOG(1) << "Low-latency output detected on Android"; 309 DVLOG(1) << "Low-latency output detected on Android";
310 } 310 }
311 #endif 311 #endif
312 DVLOG(1) << "Using sink output buffer size: " << frames_per_buffer; 312 DVLOG(1) << "Using sink output buffer size: " << frames_per_buffer;
313 313
314 sink_params_.Reset(sink_params_.format(), sink_params_.channel_layout(), 314 sink_params_.Reset(sink_params_.format(), sink_params_.channel_layout(),
315 sink_params_.channels(), 0, sample_rate, 16, 315 sink_params_.channels(), sample_rate, 16,
316 frames_per_buffer); 316 frames_per_buffer);
317 317
318 // Create a FIFO if re-buffering is required to match the source input with 318 // Create a FIFO if re-buffering is required to match the source input with
319 // the sink request. The source acts as provider here and the sink as 319 // the sink request. The source acts as provider here and the sink as
320 // consumer. 320 // consumer.
321 fifo_delay_milliseconds_ = 0; 321 fifo_delay_milliseconds_ = 0;
322 if (source_params.frames_per_buffer() != sink_params_.frames_per_buffer()) { 322 if (source_params.frames_per_buffer() != sink_params_.frames_per_buffer()) {
323 DVLOG(1) << "Rebuffering from " << source_params.frames_per_buffer() 323 DVLOG(1) << "Rebuffering from " << source_params.frames_per_buffer()
324 << " to " << sink_params_.frames_per_buffer(); 324 << " to " << sink_params_.frames_per_buffer();
325 audio_fifo_.reset(new media::AudioPullFifo( 325 audio_fifo_.reset(new media::AudioPullFifo(
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 if (RemovePlayingState(source, state)) 603 if (RemovePlayingState(source, state))
604 EnterPauseState(); 604 EnterPauseState();
605 } else if (AddPlayingState(source, state)) { 605 } else if (AddPlayingState(source, state)) {
606 EnterPlayState(); 606 EnterPlayState();
607 } 607 }
608 UpdateSourceVolume(source); 608 UpdateSourceVolume(source);
609 } 609 }
610 } 610 }
611 611
612 } // namespace content 612 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer.cc ('k') | content/renderer/media/webrtc_local_audio_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698