OLD | NEW |
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { | 51 size_t GetHighLatencyOutputBufferSize(int sample_rate) { |
52 // The minimum number of samples in a hardware packet. | 52 // kNominalBufferSize has been tested on Windows, Mac OS X, and Linux |
53 // This value is selected so that we can handle down to 5khz sample rate. | 53 // with the AUDIO_PCM_LINEAR flag. |
54 static const size_t kMinSamplesPerHardwarePacket = 1024; | 54 const size_t kNominalBufferSize = 2048; |
55 | 55 |
56 // The maximum number of samples in a hardware packet. | 56 if (sample_rate <= 48000) |
57 // This value is selected so that we can handle up to 192khz sample rate. | 57 return kNominalBufferSize; |
58 static const size_t kMaxSamplesPerHardwarePacket = 64 * 1024; | 58 else if (sample_rate <= 96000) |
| 59 return kNominalBufferSize * 2; |
59 | 60 |
60 // This constant governs the hardware audio buffer size, this value should be | 61 return kNominalBufferSize * 4; |
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 } | 62 } |
75 | 63 |
76 uint32 GetInputChannelCount() { | 64 uint32 GetInputChannelCount() { |
77 DCHECK(RenderThreadImpl::current() != NULL); | 65 DCHECK(RenderThreadImpl::current() != NULL); |
78 | 66 |
79 if (!input_channel_count) { | 67 if (!input_channel_count) { |
80 uint32 channels = 0; | 68 uint32 channels = 0; |
81 RenderThreadImpl::current()->Send( | 69 RenderThreadImpl::current()->Send( |
82 new ViewHostMsg_GetHardwareInputChannelCount(&channels)); | 70 new ViewHostMsg_GetHardwareInputChannelCount(&channels)); |
83 input_channel_count = channels; | 71 input_channel_count = channels; |
84 } | 72 } |
85 | 73 |
86 return input_channel_count; | 74 return input_channel_count; |
87 } | 75 } |
88 | 76 |
89 void ResetCache() { | 77 void ResetCache() { |
90 DCHECK(RenderThreadImpl::current() != NULL); | 78 DCHECK(RenderThreadImpl::current() != NULL); |
91 | 79 |
92 output_sample_rate = 0.0; | 80 output_sample_rate = 0.0; |
93 input_sample_rate = 0.0; | 81 input_sample_rate = 0.0; |
94 output_buffer_size = 0; | 82 output_buffer_size = 0; |
95 input_channel_count = 0; | 83 input_channel_count = 0; |
96 } | 84 } |
97 | 85 |
98 } // namespace audio_hardware | 86 } // namespace audio_hardware |
OLD | NEW |