diff options
author | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-27 19:09:21 +0000 |
---|---|---|
committer | vrk@google.com <vrk@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-27 19:09:21 +0000 |
commit | d14ca89275628f1133374fbba2bdbfc91f0732ab (patch) | |
tree | 2764fec71ec947e0ae21a356f5ae79812ec5a95b /media | |
parent | d94604fadd084c1d4b51e972c4bb047962e888cd (diff) | |
download | chromium_src-d14ca89275628f1133374fbba2bdbfc91f0732ab.zip chromium_src-d14ca89275628f1133374fbba2bdbfc91f0732ab.tar.gz chromium_src-d14ca89275628f1133374fbba2bdbfc91f0732ab.tar.bz2 |
Merge 123292 - Increase the buffer size in AudioRendererImpl to fix muted playback rate
This CL temporarily removes GetBufferSizeForSampleRate() and uses
SelectSamplesPerPacket() to determine the size of samples_per_packet in
AudioDevice. This restores the buffer size that AudioRendererImpl
used prior to r113821. SelectSamplesPerPacket() calculates a much larger
samples_per_packet value than GetBufferSizeForSampleRate(), so it fixes
the issue described in 108239.
This CL also does some mild refactoring to move audio_common.cc into
audio_util.cc.
BUG=108239
TEST=media_unittests,content_unittests, manual testing of different playback rates
Review URL: https://chromiumcodereview.appspot.com/9416085
TBR=vrk@google.com
Review URL: https://chromiumcodereview.appspot.com/9479012
git-svn-id: svn://svn.chromium.org/chrome/branches/1025/src@123774 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_util.cc | 27 | ||||
-rw-r--r-- | media/audio/audio_util.h | 5 |
2 files changed, 32 insertions, 0 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc index b4b87518..8caced5 100644 --- a/media/audio/audio_util.cc +++ b/media/audio/audio_util.cc @@ -14,9 +14,11 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/shared_memory.h" +#include "base/time.h" #if defined(OS_WIN) #include "base/win/windows_version.h" #endif +#include "media/audio/audio_parameters.h" #include "media/audio/audio_util.h" #if defined(OS_MACOSX) #include "media/audio/mac/audio_low_latency_input_mac.h" @@ -436,4 +438,29 @@ void Crossfade(int bytes_to_crossfade, int number_of_channels, } } +// The minimum number of samples in a hardware packet. +// This value is selected so that we can handle down to 5khz sample rate. +static const int kMinSamplesPerHardwarePacket = 1024; + +// The maximum number of samples in a hardware packet. +// This value is selected so that we can handle up to 192khz sample rate. +static const int kMaxSamplesPerHardwarePacket = 64 * 1024; + +// This constant governs the hardware audio buffer size, this value should be +// chosen carefully. +// This value is selected so that we have 8192 samples for 48khz streams. +static const int kMillisecondsPerHardwarePacket = 170; + +uint32 SelectSamplesPerPacket(int sample_rate) { + // Select the number of samples that can provide at least + // |kMillisecondsPerHardwarePacket| worth of audio data. + int samples = kMinSamplesPerHardwarePacket; + while (samples <= kMaxSamplesPerHardwarePacket && + samples * base::Time::kMillisecondsPerSecond < + sample_rate * kMillisecondsPerHardwarePacket) { + samples *= 2; + } + return samples; +} + } // namespace media diff --git a/media/audio/audio_util.h b/media/audio/audio_util.h index d8de479..3730c11 100644 --- a/media/audio/audio_util.h +++ b/media/audio/audio_util.h @@ -10,6 +10,8 @@ #include "base/basictypes.h" #include "media/base/media_export.h" +struct AudioParameters; + namespace base { class SharedMemory; } @@ -122,6 +124,9 @@ MEDIA_EXPORT void Crossfade(int bytes_to_crossfade, int number_of_channels, int bytes_per_channel, const uint8* src, uint8* dest); +// Calculates a safe hardware buffer size (in number of samples) given a set +// of audio parameters. +MEDIA_EXPORT uint32 SelectSamplesPerPacket(int sample_rate); } // namespace media |