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

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

Issue 1304973005: Refactor AudioParameters member setting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More cross-platform. Created 5 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_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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 "WebRTC.AudioOutputSampleRate", asr, media::kAudioSampleRateMax + 1); 226 "WebRTC.AudioOutputSampleRate", asr, media::kAudioSampleRateMax + 1);
227 } else { 227 } else {
228 UMA_HISTOGRAM_COUNTS("WebRTC.AudioOutputSampleRateUnexpected", 228 UMA_HISTOGRAM_COUNTS("WebRTC.AudioOutputSampleRateUnexpected",
229 sample_rate); 229 sample_rate);
230 } 230 }
231 231
232 // Set up audio parameters for the source, i.e., the WebRTC client. 232 // Set up audio parameters for the source, i.e., the WebRTC client.
233 233
234 // The WebRTC client only supports multiples of 10ms as buffer size where 234 // The WebRTC client only supports multiples of 10ms as buffer size where
235 // 10ms is preferred for lowest possible delay. 235 // 10ms is preferred for lowest possible delay.
236 media::AudioParameters source_params;
237 const int frames_per_10ms = (sample_rate / 100); 236 const int frames_per_10ms = (sample_rate / 100);
238 DVLOG(1) << "Using WebRTC output buffer size: " << frames_per_10ms; 237 DVLOG(1) << "Using WebRTC output buffer size: " << frames_per_10ms;
239 238 media::AudioParameters source_params(
240 source_params.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 239 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
241 sink_params_.channel_layout(), sink_params_.channels(), 240 sink_params_.channel_layout(), sample_rate, 16, frames_per_10ms);
242 sample_rate, 16, frames_per_10ms); 241 source_params.set_channels_for_discrete(sink_params_.channels());
243 242
244 const int frames_per_buffer = 243 const int frames_per_buffer =
245 GetOptimalBufferSize(sample_rate, sink_params_.frames_per_buffer()); 244 GetOptimalBufferSize(sample_rate, sink_params_.frames_per_buffer());
246 245
247 sink_params_.Reset(sink_params_.format(), sink_params_.channel_layout(), 246 sink_params_.Reset(sink_params_.format(), sink_params_.channel_layout(),
248 sink_params_.channels(), sample_rate, 16, 247 sample_rate, 16, frames_per_buffer);
249 frames_per_buffer);
250 248
251 // Create a FIFO if re-buffering is required to match the source input with 249 // Create a FIFO if re-buffering is required to match the source input with
252 // the sink request. The source acts as provider here and the sink as 250 // the sink request. The source acts as provider here and the sink as
253 // consumer. 251 // consumer.
254 fifo_delay_milliseconds_ = 0; 252 fifo_delay_milliseconds_ = 0;
255 if (source_params.frames_per_buffer() != sink_params_.frames_per_buffer()) { 253 if (source_params.frames_per_buffer() != sink_params_.frames_per_buffer()) {
256 DVLOG(1) << "Rebuffering from " << source_params.frames_per_buffer() 254 DVLOG(1) << "Rebuffering from " << source_params.frames_per_buffer()
257 << " to " << sink_params_.frames_per_buffer(); 255 << " to " << sink_params_.frames_per_buffer();
258 audio_fifo_.reset(new media::AudioPullFifo( 256 audio_fifo_.reset(new media::AudioPullFifo(
259 source_params.channels(), 257 source_params.channels(),
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 431 }
434 432
435 void WebRtcAudioRenderer::OnRenderError() { 433 void WebRtcAudioRenderer::OnRenderError() {
436 NOTIMPLEMENTED(); 434 NOTIMPLEMENTED();
437 LOG(ERROR) << "OnRenderError()"; 435 LOG(ERROR) << "OnRenderError()";
438 } 436 }
439 437
440 // Called by AudioPullFifo when more data is necessary. 438 // Called by AudioPullFifo when more data is necessary.
441 void WebRtcAudioRenderer::SourceCallback( 439 void WebRtcAudioRenderer::SourceCallback(
442 int fifo_frame_delay, media::AudioBus* audio_bus) { 440 int fifo_frame_delay, media::AudioBus* audio_bus) {
443 base::TimeTicks start_time = base::TimeTicks::Now() ; 441 base::TimeTicks start_time = base::TimeTicks::Now();
444 DVLOG(2) << "WebRtcAudioRenderer::SourceCallback(" 442 DVLOG(2) << "WebRtcAudioRenderer::SourceCallback("
445 << fifo_frame_delay << ", " 443 << fifo_frame_delay << ", "
446 << audio_bus->frames() << ")"; 444 << audio_bus->frames() << ")";
447 445
448 int output_delay_milliseconds = audio_delay_milliseconds_; 446 int output_delay_milliseconds = audio_delay_milliseconds_;
449 output_delay_milliseconds += fifo_delay_milliseconds_; 447 output_delay_milliseconds += fifo_delay_milliseconds_;
450 DVLOG(2) << "output_delay_milliseconds: " << output_delay_milliseconds; 448 DVLOG(2) << "output_delay_milliseconds: " << output_delay_milliseconds;
451 449
452 // We need to keep render data for the |source_| regardless of |state_|, 450 // We need to keep render data for the |source_| regardless of |state_|,
453 // otherwise the data will be buffered up inside |source_|. 451 // otherwise the data will be buffered up inside |source_|.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 if (RemovePlayingState(source, state)) 551 if (RemovePlayingState(source, state))
554 EnterPauseState(); 552 EnterPauseState();
555 } else if (AddPlayingState(source, state)) { 553 } else if (AddPlayingState(source, state)) {
556 EnterPlayState(); 554 EnterPlayState();
557 } 555 }
558 UpdateSourceVolume(source); 556 UpdateSourceVolume(source);
559 } 557 }
560 } 558 }
561 559
562 } // namespace content 560 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698