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

Unified Diff: media/audio/audio_util.cc

Issue 9826023: Merge AudioRendererImpl and AudioRendererBase; add NullAudioSink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win build Created 8 years, 8 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 | « media/audio/audio_util.h ('k') | media/audio/null_audio_sink.h » ('j') | 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 c15e845724dde4a0f404ad423cf8d1142c95a1da..01d71eee3dd3ce38a69102282a3d4dec11f0a01d 100644
--- a/media/audio/audio_util.cc
+++ b/media/audio/audio_util.cc
@@ -427,6 +427,38 @@ ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) {
#endif
}
+// Computes a buffer size based on the given |sample_rate|. Must be used in
+// conjunction with AUDIO_PCM_LINEAR.
+size_t GetHighLatencyOutputBufferSize(int sample_rate) {
+ // TODO(vrk/crogers): The buffer sizes that this function computes is probably
+ // overly conservative. However, reducing the buffer size to 2048-8192 bytes
+ // caused crbug.com/108396. This computation should be revisited while making
+ // sure crbug.com/108396 doesn't happen again.
+
+ // 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 size_t 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 size_t 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 size_t kMillisecondsPerHardwarePacket = 170;
+
+ // Select the number of samples that can provide at least
+ // |kMillisecondsPerHardwarePacket| worth of audio data.
+ size_t samples = kMinSamplesPerHardwarePacket;
+ while (samples <= kMaxSamplesPerHardwarePacket &&
+ samples * base::Time::kMillisecondsPerSecond <
+ sample_rate * kMillisecondsPerHardwarePacket) {
+ samples *= 2;
+ }
+ return samples;
+}
+
// When transferring data in the shared memory, first word is size of data
// in bytes. Actual data starts immediately after it.
« no previous file with comments | « media/audio/audio_util.h ('k') | media/audio/null_audio_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698