| 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 "build/build_config.h" | 13 #include "build/build_config.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--; |
| (...skipping 97 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(base::TimeDelta duration, |
| 131 int sample_rate, |
| 132 int hardware_buffer_size) { |
| 133 const double requested_buffer_size = duration.InSecondsF() * sample_rate; |
| 134 |
| 135 DCHECK_NE(0, hardware_buffer_size); |
| 136 |
| 137 // Round the requested size to the nearest multiple of the hardware size |
| 138 const int buffer_size = |
| 139 std::round(std::max(requested_buffer_size, 1.0) / hardware_buffer_size) * |
| 140 hardware_buffer_size; |
| 141 |
| 142 return std::max(buffer_size, hardware_buffer_size); |
| 143 } |
| 144 |
| 129 } // namespace media | 145 } // namespace media |
| OLD | NEW |