summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authordalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-22 22:05:53 +0000
committerdalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-22 22:05:53 +0000
commit938666c23104b52c4df14792923630976cc47c65 (patch)
treed3029d63645d60a17dab6a6dc0953a8957e0b65b /media
parentdd3bf8e2b94fb9fecbab0c2303521c4684cab5d0 (diff)
downloadchromium_src-938666c23104b52c4df14792923630976cc47c65.zip
chromium_src-938666c23104b52c4df14792923630976cc47c65.tar.gz
chromium_src-938666c23104b52c4df14792923630976cc47c65.tar.bz2
Enable renderer side mixing by default for Mac and Windows.
On Windows and Mac we can use the low latency pipeline because they provide accurate and smooth delay information. On other platforms like Linux there are a couple issues: - The low latency audio clock provided by ALSA (or simulated ALSA when pulse is behind the scenes) is not smooth enough and causes jitter. - AudioRendererImpl misuses the latency information currently with the assumption that it's the only audio provider. Which is false when mixing data between renderers and results in jitter. This change also enables the low latency pipeline if audio renderer mixing is disabled but audio output resampling is not. It's useful to have both enabled to help troubleshoot where issues might be in the field (i.e. with the low latency pipeline itself or specifically for renderer side mixing). It was necessary to move the switch from content to media to ensure this check can be made at runtime w/o a layering violation. And really most of the code lives in media, so it makes sense for the switch to live there. BUG=133637 TEST=Audio on mac / windows plays correctly. Review URL: https://chromiumcodereview.appspot.com/11192068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163398 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/media_switches.cc7
-rw-r--r--media/base/media_switches.h6
-rw-r--r--media/filters/audio_renderer_impl.cc45
3 files changed, 52 insertions, 6 deletions
diff --git a/media/base/media_switches.cc b/media/base/media_switches.cc
index 258ec15..62f0c39 100644
--- a/media/base/media_switches.cc
+++ b/media/base/media_switches.cc
@@ -38,6 +38,13 @@ const char kDisableAudioFallback[] = "disable-audio-fallback";
// Disable AudioOutputResampler for automatic audio resampling and rebuffering.
const char kDisableAudioOutputResampler[] = "disable-audio-output-resampler";
+// Controls renderer side mixing and low latency audio path for media elements.
+#if defined(OS_WIN) || defined(OS_MAC)
+const char kDisableRendererSideMixing[] = "disable-renderer-side-mixing";
+#else
+const char kEnableRendererSideMixing[] = "enable-renderer-side-mixing";
+#endif
+
// Enable browser-side audio mixer.
const char kEnableAudioMixer[] = "enable-audio-mixer";
diff --git a/media/base/media_switches.h b/media/base/media_switches.h
index f68c9b3..744e191 100644
--- a/media/base/media_switches.h
+++ b/media/base/media_switches.h
@@ -33,6 +33,12 @@ MEDIA_EXPORT extern const char kDisableAudioFallback[];
MEDIA_EXPORT extern const char kDisableAudioOutputResampler[];
+#if defined(OS_WIN) || defined(OS_MAC)
+MEDIA_EXPORT extern const char kDisableRendererSideMixing[];
+#else
+MEDIA_EXPORT extern const char kEnableRendererSideMixing[];
+#endif
+
MEDIA_EXPORT extern const char kEnableAudioMixer[];
MEDIA_EXPORT extern const char kEnableWebAudioInput[];
diff --git a/media/filters/audio_renderer_impl.cc b/media/filters/audio_renderer_impl.cc
index 51c19df..772af20 100644
--- a/media/filters/audio_renderer_impl.cc
+++ b/media/filters/audio_renderer_impl.cc
@@ -11,9 +11,11 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/callback_helpers.h"
+#include "base/command_line.h"
#include "base/logging.h"
#include "media/audio/audio_util.h"
#include "media/base/demuxer_stream.h"
+#include "media/base/media_switches.h"
namespace media {
@@ -225,13 +227,44 @@ void AudioRendererImpl::OnDecoderInitDone(
channels, sample_rate, bits_per_channel, 0.0f,
base::Bind(&AudioRendererImpl::ScheduleRead_Locked, this));
- // We use the AUDIO_PCM_LINEAR flag because AUDIO_PCM_LOW_LATENCY
- // does not currently support all the sample-rates that we require.
- // Please see: http://code.google.com/p/chromium/issues/detail?id=103627
- // for more details.
+ int buffer_size = GetHighLatencyOutputBufferSize(sample_rate);
+ AudioParameters::Format format = AudioParameters::AUDIO_PCM_LINEAR;
+
+ // On Windows and Mac we can use the low latency pipeline because they provide
+ // accurate and smooth delay information. On other platforms like Linux there
+ // are jitter issues.
+ // TODO(dalecurtis): Fix bugs: http://crbug.com/138098 http://crbug.com/32757
+#if defined(OS_WIN) || defined(OS_MAC)
+ const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
+ // Either AudioOutputResampler or renderer side mixing must be enabled to use
+ // the low latency pipeline.
+ if (!cmd_line->HasSwitch(switches::kDisableRendererSideMixing) ||
+ !cmd_line->HasSwitch(switches::kDisableAudioOutputResampler)) {
+ // There are two cases here:
+ //
+ // 1. Renderer side mixing is enabled and the buffer size is actually
+ // controlled by the size of the AudioBus provided to Render(). In this
+ // case the buffer size below is ignored.
+ //
+ // 2. Renderer side mixing is disabled and AudioOutputResampler on the
+ // browser side is rebuffering to the hardware size on the fly.
+ //
+ // In the second case we need to choose a a buffer size small enough that
+ // the decoder can fulfill the high frequency low latency audio callbacks,
+ // but not so small that it's less than the hardware buffer size (or we'll
+ // run into issues since the shared memory sync is non-blocking).
+ //
+ // The buffer size below is arbitrarily the same size used by Pepper Flash
+ // for consistency. Since renderer side mixing is only disabled for debug
+ // purposes it's okay that this buffer size might lead to jitter since it's
+ // not a multiple of the hardware buffer size.
+ format = AudioParameters::AUDIO_PCM_LOW_LATENCY;
+ buffer_size = 2048;
+ }
+#endif
+
audio_parameters_ = AudioParameters(
- AudioParameters::AUDIO_PCM_LINEAR, channel_layout, sample_rate,
- bits_per_channel, GetHighLatencyOutputBufferSize(sample_rate));
+ format, channel_layout, sample_rate, bits_per_channel, buffer_size);
sink_->Initialize(audio_parameters_, this);
sink_->Start();