OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 Loading... |
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 // TODO(vrk/crogers): The buffer sizes that this function computes is probably | |
53 // overly conservative. However, reducing the buffer size to 2048-8192 bytes | |
54 // caused crbug.com/108396. This computation should be revisited while making | |
55 // sure crbug.com/108396 doesn't happen again. | |
56 | |
57 // The minimum number of samples in a hardware packet. | |
58 // This value is selected so that we can handle down to 5khz sample rate. | |
59 static const size_t kMinSamplesPerHardwarePacket = 1024; | |
60 | |
61 // The maximum number of samples in a hardware packet. | |
62 // This value is selected so that we can handle up to 192khz sample rate. | |
63 static const size_t kMaxSamplesPerHardwarePacket = 64 * 1024; | |
64 | |
65 // This constant governs the hardware audio buffer size, this value should be | |
66 // chosen carefully. | |
67 // This value is selected so that we have 8192 samples for 48khz streams. | |
68 static const size_t kMillisecondsPerHardwarePacket = 170; | |
69 | |
70 // Select the number of samples that can provide at least | |
71 // |kMillisecondsPerHardwarePacket| worth of audio data. | |
72 size_t samples = kMinSamplesPerHardwarePacket; | |
73 while (samples <= kMaxSamplesPerHardwarePacket && | |
74 samples * base::Time::kMillisecondsPerSecond < | |
75 sample_rate * kMillisecondsPerHardwarePacket) { | |
76 samples *= 2; | |
77 } | |
78 return samples; | |
79 } | |
80 | |
81 ChannelLayout GetInputChannelLayout() { | 51 ChannelLayout GetInputChannelLayout() { |
82 DCHECK(RenderThreadImpl::current() != NULL); | 52 DCHECK(RenderThreadImpl::current() != NULL); |
83 | 53 |
84 if (input_channel_layout == CHANNEL_LAYOUT_NONE) { | 54 if (input_channel_layout == CHANNEL_LAYOUT_NONE) { |
85 ChannelLayout layout = CHANNEL_LAYOUT_NONE; | 55 ChannelLayout layout = CHANNEL_LAYOUT_NONE; |
86 RenderThreadImpl::current()->Send( | 56 RenderThreadImpl::current()->Send( |
87 new ViewHostMsg_GetHardwareInputChannelLayout(&layout)); | 57 new ViewHostMsg_GetHardwareInputChannelLayout(&layout)); |
88 input_channel_layout = layout; | 58 input_channel_layout = layout; |
89 } | 59 } |
90 | 60 |
91 return input_channel_layout; | 61 return input_channel_layout; |
92 } | 62 } |
93 | 63 |
94 void ResetCache() { | 64 void ResetCache() { |
95 DCHECK(RenderThreadImpl::current() != NULL); | 65 DCHECK(RenderThreadImpl::current() != NULL); |
96 | 66 |
97 output_sample_rate = 0.0; | 67 output_sample_rate = 0.0; |
98 input_sample_rate = 0.0; | 68 input_sample_rate = 0.0; |
99 output_buffer_size = 0; | 69 output_buffer_size = 0; |
100 input_channel_layout = CHANNEL_LAYOUT_NONE; | 70 input_channel_layout = CHANNEL_LAYOUT_NONE; |
101 } | 71 } |
102 | 72 |
103 } // namespace audio_hardware | 73 } // namespace audio_hardware |
OLD | NEW |