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

Unified Diff: content/renderer/media/webrtc_audio_renderer.cc

Issue 539453003: Used 10ms native buffer size for webrtc audio renderer on Linux and Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/webrtc_audio_renderer.cc
diff --git a/content/renderer/media/webrtc_audio_renderer.cc b/content/renderer/media/webrtc_audio_renderer.cc
index 8976ca66579f3bee523b6545d168f279efb71681..26b22d9dddac9fdb67a60a67e32c581052ec5d40 100644
--- a/content/renderer/media/webrtc_audio_renderer.cc
+++ b/content/renderer/media/webrtc_audio_renderer.cc
@@ -47,51 +47,6 @@ const int kValidOutputRates[] = {48000, 44100, 16000};
const int kValidOutputRates[] = {44100};
#endif
-// TODO(xians): Merge the following code to WebRtcAudioCapturer, or remove.
-enum AudioFramesPerBuffer {
- k160,
- k320,
- k440,
- k480,
- k640,
- k880,
- k960,
- k1440,
- k1920,
- kUnexpectedAudioBufferSize // Must always be last!
-};
-
-// Helper method to convert integral values to their respective enum values
-// above, or kUnexpectedAudioBufferSize if no match exists.
-// We map 441 to k440 to avoid changes in the XML part for histograms.
-// It is still possible to map the histogram result to the actual buffer size.
-// See http://crbug.com/243450 for details.
-AudioFramesPerBuffer AsAudioFramesPerBuffer(int frames_per_buffer) {
- switch (frames_per_buffer) {
- case 160: return k160;
- case 320: return k320;
- case 441: return k440;
- case 480: return k480;
- case 640: return k640;
- case 880: return k880;
- case 960: return k960;
- case 1440: return k1440;
- case 1920: return k1920;
- }
- return kUnexpectedAudioBufferSize;
-}
-
-void AddHistogramFramesPerBuffer(int param) {
- AudioFramesPerBuffer afpb = AsAudioFramesPerBuffer(param);
- if (afpb != kUnexpectedAudioBufferSize) {
- UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputFramesPerBuffer",
- afpb, kUnexpectedAudioBufferSize);
- } else {
- // Report unexpected sample rates using a unique histogram name.
- UMA_HISTOGRAM_COUNTS("WebRTC.AudioOutputFramesPerBufferUnexpected", param);
- }
-}
-
// This is a simple wrapper class that's handed out to users of a shared
// WebRtcAudioRenderer instance. This class maintains the per-user 'playing'
// and 'started' states to avoid problems related to incorrect usage which
@@ -198,6 +153,38 @@ int GetCurrentDuckingFlag(int render_frame_id) {
return media::AudioParameters::NO_EFFECTS;
}
+// Helper method to get platform specific optimal buffer size.
+int GetOptimalBufferSize(int sample_rate, int hardware_buffer_size) {
+ // Use native hardware buffer size as default.
+ int frames_per_buffer = hardware_buffer_size;
+
+ // On Windows, we strive to open up using native parameters to achieve best
tommi (sloooow) - chröme 2014/09/03 13:22:11 this comment is a bit confusing since there's no #
no longer working on chromium 2014/09/03 14:34:50 I moved the comment up and explained by we don't h
+ // possible performance and to ensure that no FIFO is needed on the browser
+ // side to match the client request.
+
+#if defined(OS_LINUX) || defined(OS_MACOSX)
+ // On Linux and MacOS, the low level IO implementations on the browser side
+ // supports all buffer size the clients want. We use the native peer
+ // connection buffer size (10ms) to achieve best possible performance.
+ frames_per_buffer = sample_rate / 100;
+#elif defined(OS_ANDROID)
+ // TODO(henrika): Keep tuning this scheme and espcicially for low-latency
+ // cases. Might not be possible to come up with the perfect solution using
tommi (sloooow) - chröme 2014/09/03 13:22:11 fix indenting here and the next line
no longer working on chromium 2014/09/03 14:34:50 Done.
+ // the render side only.
+ if (frames_per_buffer < 2 * frames_per_10ms) {
+ // Examples of low-latency frame sizes and the resulting |buffer_size|:
+ // Nexus 7 : 240 audio frames => 2*480 = 960
+ // Nexus 10 : 256 => 2*441 = 882
+ // Galaxy Nexus: 144 => 2*441 = 882
+ frames_per_buffer = 2 * frames_per_10ms;
+ DVLOG(1) << "Low-latency output detected on Android";
+ }
+#endif
+
+ DVLOG(1) << "Using sink output buffer size: " << frames_per_buffer;
+ return frames_per_buffer;
+}
+
} // namespace
WebRtcAudioRenderer::WebRtcAudioRenderer(
@@ -288,28 +275,8 @@ bool WebRtcAudioRenderer::Initialize(WebRtcAudioRendererSource* source) {
sink_params_.channel_layout(), sink_params_.channels(),
sample_rate, 16, frames_per_10ms);
- // Update audio parameters for the sink, i.e., the native audio output stream.
- // We strive to open up using native parameters to achieve best possible
- // performance and to ensure that no FIFO is needed on the browser side to
- // match the client request. Any mismatch between the source and the sink is
- // taken care of in this class instead using a pull FIFO.
-
- // Use native output size as default.
- int frames_per_buffer = sink_params_.frames_per_buffer();
-#if defined(OS_ANDROID)
- // TODO(henrika): Keep tuning this scheme and espcicially for low-latency
- // cases. Might not be possible to come up with the perfect solution using
- // the render side only.
- if (frames_per_buffer < 2 * frames_per_10ms) {
- // Examples of low-latency frame sizes and the resulting |buffer_size|:
- // Nexus 7 : 240 audio frames => 2*480 = 960
- // Nexus 10 : 256 => 2*441 = 882
- // Galaxy Nexus: 144 => 2*441 = 882
- frames_per_buffer = 2 * frames_per_10ms;
- DVLOG(1) << "Low-latency output detected on Android";
- }
-#endif
- DVLOG(1) << "Using sink output buffer size: " << frames_per_buffer;
+ const int frames_per_buffer =
henrika (OOO until Aug 14) 2014/09/03 12:43:58 DVLOG could be useful here.
no longer working on chromium 2014/09/03 12:49:26 There has already been one DVLOG in the end of Get
+ GetOptimalBufferSize(sample_rate, sink_params_.frames_per_buffer());
sink_params_.Reset(sink_params_.format(), sink_params_.channel_layout(),
sink_params_.channels(), sample_rate, 16,
@@ -351,11 +318,6 @@ bool WebRtcAudioRenderer::Initialize(WebRtcAudioRendererSource* source) {
// User must call Play() before any audio can be heard.
state_ = PAUSED;
- UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioOutputFramesPerBuffer",
- source_params.frames_per_buffer(),
- kUnexpectedAudioBufferSize);
- AddHistogramFramesPerBuffer(source_params.frames_per_buffer());
-
return true;
}

Powered by Google App Engine
This is Rietveld 408576698