OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "media/base/audio_latency.h" | 5 #include "media/base/audio_latency.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "media/base/limits.h" | |
15 | |
16 #if defined(OS_MACOSX) | |
17 #include "media/base/mac/audio_util_mac.h" | |
18 #endif | |
14 | 19 |
15 namespace media { | 20 namespace media { |
16 | 21 |
17 namespace { | 22 namespace { |
18 #if !defined(OS_WIN) | 23 #if !defined(OS_WIN) |
19 // Taken from "Bit Twiddling Hacks" | 24 // Taken from "Bit Twiddling Hacks" |
20 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 | 25 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 |
21 uint32_t RoundUpToPowerOfTwo(uint32_t v) { | 26 uint32_t RoundUpToPowerOfTwo(uint32_t v) { |
22 v--; | 27 v--; |
23 v |= v >> 1; | 28 v |= v >> 1; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 if (hardware_buffer_size <= kSmallBufferSize) | 128 if (hardware_buffer_size <= kSmallBufferSize) |
124 return kDefaultCallbackBufferSize; | 129 return kDefaultCallbackBufferSize; |
125 #endif | 130 #endif |
126 | 131 |
127 return hardware_buffer_size; | 132 return hardware_buffer_size; |
128 } | 133 } |
129 | 134 |
130 int AudioLatency::GetExactBufferSize(base::TimeDelta duration, | 135 int AudioLatency::GetExactBufferSize(base::TimeDelta duration, |
131 int sample_rate, | 136 int sample_rate, |
132 int hardware_buffer_size) { | 137 int hardware_buffer_size) { |
138 DCHECK_NE(0, hardware_buffer_size); | |
139 | |
140 // Windows and Android don't allow custom buffer sizes. | |
141 #if defined(OS_WIN) || defined(OS_ANDROID) | |
142 return hardware_buffer_size; | |
143 #else | |
133 const double requested_buffer_size = duration.InSecondsF() * sample_rate; | 144 const double requested_buffer_size = duration.InSecondsF() * sample_rate; |
145 int minimum_buffer_size = hardware_buffer_size; | |
134 | 146 |
135 DCHECK_NE(0, hardware_buffer_size); | 147 // On OSX and CRAS the preferred buffer size is larger than the minimum, |
148 // however we allow values down to the minimum if requested explicitly. | |
149 #if defined(OS_MACOSX) | |
150 minimum_buffer_size = audio_util_mac::GetMinAudioBufferSizeForSampleRate( | |
151 limits::kMinAudioBufferSize, sample_rate); | |
152 #elif defined(USE_CRAS) | |
153 minimum_buffer_size = limits::kMinimumOutputBufferSize; | |
o1ka
2017/06/15 15:33:37
Hmm, but AudioManagerCras::GetPreferredOutputStrea
Raymond Toy
2017/06/15 17:50:06
I think that's ok. Linux desktop can have really
o1ka
2017/06/27 16:31:19
The point was to return here exactly the buffer si
Andrew MacPherson
2017/06/27 17:03:40
I may not have been clear when I asked about this
o1ka
2017/06/28 17:38:22
I must be missing something: I don't see how Audio
Andrew MacPherson
2017/06/28 18:19:04
You're completely right, my mistake. I've updated
| |
154 #endif | |
136 | 155 |
137 // Round the requested size to the nearest multiple of the hardware size | 156 // Round the requested size to the nearest multiple of the hardware size |
138 const int buffer_size = | 157 const int buffer_size = |
139 std::round(std::max(requested_buffer_size, 1.0) / hardware_buffer_size) * | 158 std::round(std::max(requested_buffer_size, 1.0) / hardware_buffer_size) * |
140 hardware_buffer_size; | 159 hardware_buffer_size; |
141 | 160 |
142 return std::max(buffer_size, hardware_buffer_size); | 161 return std::min(static_cast<int>(limits::kMaxAudioBufferSize), |
162 std::max(buffer_size, minimum_buffer_size)); | |
163 #endif | |
143 } | 164 } |
144 | 165 |
145 } // namespace media | 166 } // namespace media |
OLD | NEW |