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

Unified Diff: media/audio/audio_util.cc

Issue 10993013: Return fixed hardware buffer size for odd sample rates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/audio_util.cc
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc
index 2b4fd1742e1c090e8bc0f57a94f6399d4705a42f..63075630c9eb18b499f310aa570dcb4196fe6d78 100644
--- a/media/audio/audio_util.cc
+++ b/media/audio/audio_util.cc
@@ -32,6 +32,7 @@
#include "media/audio/audio_manager_base.h"
#include "media/audio/win/audio_low_latency_input_win.h"
#include "media/audio/win/audio_low_latency_output_win.h"
+#include "media/base/limits.h"
#include "media/base/media_switches.h"
#endif
@@ -305,10 +306,13 @@ size_t GetAudioHardwareBufferSize() {
#if defined(OS_MACOSX)
return 128;
#elif defined(OS_WIN)
+ // Buffer size to use when a proper size can't be determined from the system.
+ static const int kFallbackBufferSize = 2048;
+
if (!IsWASAPISupported()) {
// Fall back to Windows Wave implementation on Windows XP or lower
// and assume 48kHz as default sample rate.
- return 2048;
+ return kFallbackBufferSize;
}
// TODO(crogers): tune this size to best possible WebAudio performance.
@@ -324,6 +328,12 @@ size_t GetAudioHardwareBufferSize() {
int mixing_sample_rate =
WASAPIAudioOutputStream::HardwareSampleRate(eConsole);
+ // Windows will return a sample rate of 0 when no audio output is available
+ // (i.e. via RemoteDesktop with remote audio disabled), but we should never
+ // return a buffer size of zero.
+ if (mixing_sample_rate == 0)
+ return kFallbackBufferSize;
+
// Use different buffer sizes depening on the sample rate . The existing
// WASAPI implementation is tuned to provide the most stable callback
// sequence using these combinations.
@@ -335,8 +345,11 @@ size_t GetAudioHardwareBufferSize() {
// Use buffer size of 10ms.
return (80 * (mixing_sample_rate / 8000));
+ // Ensure we always return a buffer size which is somewhat appropriate.
LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected.";
- return (mixing_sample_rate / 100);
+ if (mixing_sample_rate > limits::kMinSampleRate)
+ return (mixing_sample_rate / 100);
+ return kFallbackBufferSize;
#else
return 2048;
#endif
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698