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

Side by Side Diff: content/renderer/media/audio_hardware.cc

Issue 9442005: Clean up audio-related utility functions to compute buffer sizes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase ToT Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/audio_hardware.h ('k') | content/renderer/media/audio_renderer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/audio_hardware.h" 5 #include "content/renderer/media/audio_hardware.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/view_messages.h" 8 #include "content/common/view_messages.h"
9 #include "content/renderer/render_thread_impl.h" 9 #include "content/renderer/render_thread_impl.h"
10 10
(...skipping 30 matching lines...) Expand all
41 if (!output_buffer_size) { 41 if (!output_buffer_size) {
42 uint32 buffer_size = 0; 42 uint32 buffer_size = 0;
43 RenderThreadImpl::current()->Send( 43 RenderThreadImpl::current()->Send(
44 new ViewHostMsg_GetHardwareBufferSize(&buffer_size)); 44 new ViewHostMsg_GetHardwareBufferSize(&buffer_size));
45 output_buffer_size = buffer_size; 45 output_buffer_size = buffer_size;
46 } 46 }
47 47
48 return output_buffer_size; 48 return output_buffer_size;
49 } 49 }
50 50
51 size_t GetHighLatencyOutputBufferSize(int sample_rate) {
52 // The minimum number of samples in a hardware packet.
53 // This value is selected so that we can handle down to 5khz sample rate.
54 static const size_t kMinSamplesPerHardwarePacket = 1024;
55
56 // The maximum number of samples in a hardware packet.
57 // This value is selected so that we can handle up to 192khz sample rate.
58 static const size_t kMaxSamplesPerHardwarePacket = 64 * 1024;
59
60 // This constant governs the hardware audio buffer size, this value should be
61 // chosen carefully.
62 // This value is selected so that we have 8192 samples for 48khz streams.
63 static const size_t kMillisecondsPerHardwarePacket = 170;
64
65 // Select the number of samples that can provide at least
66 // |kMillisecondsPerHardwarePacket| worth of audio data.
67 size_t samples = kMinSamplesPerHardwarePacket;
68 while (samples <= kMaxSamplesPerHardwarePacket &&
69 samples * base::Time::kMillisecondsPerSecond <
70 sample_rate * kMillisecondsPerHardwarePacket) {
71 samples *= 2;
72 }
73 return samples;
74 }
75
51 uint32 GetInputChannelCount() { 76 uint32 GetInputChannelCount() {
52 DCHECK(RenderThreadImpl::current() != NULL); 77 DCHECK(RenderThreadImpl::current() != NULL);
53 78
54 if (!input_channel_count) { 79 if (!input_channel_count) {
55 uint32 channels = 0; 80 uint32 channels = 0;
56 RenderThreadImpl::current()->Send( 81 RenderThreadImpl::current()->Send(
57 new ViewHostMsg_GetHardwareInputChannelCount(&channels)); 82 new ViewHostMsg_GetHardwareInputChannelCount(&channels));
58 input_channel_count = channels; 83 input_channel_count = channels;
59 } 84 }
60 85
61 return input_channel_count; 86 return input_channel_count;
62 } 87 }
63 88
64 void ResetCache() { 89 void ResetCache() {
65 DCHECK(RenderThreadImpl::current() != NULL); 90 DCHECK(RenderThreadImpl::current() != NULL);
66 91
67 output_sample_rate = 0.0; 92 output_sample_rate = 0.0;
68 input_sample_rate = 0.0; 93 input_sample_rate = 0.0;
69 output_buffer_size = 0; 94 output_buffer_size = 0;
70 input_channel_count = 0; 95 input_channel_count = 0;
71 } 96 }
72 97
73 } // namespace audio_hardware 98 } // namespace audio_hardware
OLDNEW
« no previous file with comments | « content/renderer/media/audio_hardware.h ('k') | content/renderer/media/audio_renderer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698