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, |
| 131 const AudioParameters& hardware_params) { |
| 132 return std::max( |
| 133 std::min(static_cast<int>(duration * hardware_params.sample_rate()), |
| 134 GetHighLatencyBufferSize(hardware_params.sample_rate(), 0)), |
| 135 static_cast<int>(hardware_params.frames_per_buffer())); |
| 136 } |
| 137 |
129 } // namespace media | 138 } // namespace media |
OLD | NEW |