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 "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "media/base/audio_parameters.h" | |
13 | 14 |
14 namespace media { | 15 namespace media { |
15 | 16 |
16 namespace { | 17 namespace { |
17 #if !defined(OS_WIN) | 18 #if !defined(OS_WIN) |
18 // Taken from "Bit Twiddling Hacks" | 19 // Taken from "Bit Twiddling Hacks" |
19 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 | 20 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 |
20 uint32_t RoundUpToPowerOfTwo(uint32_t v) { | 21 uint32_t RoundUpToPowerOfTwo(uint32_t v) { |
21 v--; | 22 v--; |
22 v |= v >> 1; | 23 v |= v >> 1; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 // the jitter. | 120 // the jitter. |
120 const int kSmallBufferSize = 1024; | 121 const int kSmallBufferSize = 1024; |
121 const int kDefaultCallbackBufferSize = 2048; | 122 const int kDefaultCallbackBufferSize = 2048; |
122 if (hardware_buffer_size <= kSmallBufferSize) | 123 if (hardware_buffer_size <= kSmallBufferSize) |
123 return kDefaultCallbackBufferSize; | 124 return kDefaultCallbackBufferSize; |
124 #endif | 125 #endif |
125 | 126 |
126 return hardware_buffer_size; | 127 return hardware_buffer_size; |
127 } | 128 } |
128 | 129 |
130 int AudioLatency::GetExactBufferSize(double duration_in_seconds, | |
DaleCurtis
2017/03/28 17:34:07
This should take TimeDelta since it's a chromium c
Andrew MacPherson
2017/03/29 08:34:09
Done.
| |
131 const AudioParameters& hardware_params) { | |
132 const double requested_buffer_size = | |
133 duration_in_seconds * hardware_params.sample_rate(); | |
134 | |
135 // Round up the requested size to the nearest multiple of the hardware size | |
136 const int buffer_size = std::ceil(std::max(requested_buffer_size, 1.0) / | |
137 hardware_params.frames_per_buffer()) * | |
138 hardware_params.frames_per_buffer(); | |
139 | |
140 return std::max(std::min(buffer_size, GetHighLatencyBufferSize( | |
DaleCurtis
2017/03/28 17:34:07
Hmm, I don't think these methods should call each
Andrew MacPherson
2017/03/29 08:34:09
Ok, I've modified this as you suggest to just use
| |
141 hardware_params.sample_rate(), 0)), | |
142 static_cast<int>(hardware_params.frames_per_buffer())); | |
143 } | |
144 | |
129 } // namespace media | 145 } // namespace media |
OLD | NEW |