Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: media/base/audio_latency.cc

Issue 2973763002: Revert of Make OS audio buffer size limits visible. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/pulse/audio_manager_pulse.cc ('k') | media/base/limits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_latency_mac.h"
18 #endif
19 14
20 namespace media { 15 namespace media {
21 16
22 namespace { 17 namespace {
23 #if !defined(OS_WIN) 18 #if !defined(OS_WIN)
24 // Taken from "Bit Twiddling Hacks" 19 // Taken from "Bit Twiddling Hacks"
25 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 20 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
26 uint32_t RoundUpToPowerOfTwo(uint32_t v) { 21 uint32_t RoundUpToPowerOfTwo(uint32_t v) {
27 v--; 22 v--;
28 v |= v >> 1; 23 v |= v >> 1;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (hardware_buffer_size <= kSmallBufferSize) 123 if (hardware_buffer_size <= kSmallBufferSize)
129 return kDefaultCallbackBufferSize; 124 return kDefaultCallbackBufferSize;
130 #endif 125 #endif
131 126
132 return hardware_buffer_size; 127 return hardware_buffer_size;
133 } 128 }
134 129
135 int AudioLatency::GetExactBufferSize(base::TimeDelta duration, 130 int AudioLatency::GetExactBufferSize(base::TimeDelta duration,
136 int sample_rate, 131 int sample_rate,
137 int hardware_buffer_size) { 132 int hardware_buffer_size) {
133 const double requested_buffer_size = duration.InSecondsF() * sample_rate;
134
138 DCHECK_NE(0, hardware_buffer_size); 135 DCHECK_NE(0, hardware_buffer_size);
139 136
140 // Other platforms do not currently support custom buffer sizes.
141 #if !defined(OS_MACOSX) && !defined(USE_CRAS) && !defined(USE_PULSE)
142 return hardware_buffer_size;
143 #else
144 const double requested_buffer_size = duration.InSecondsF() * sample_rate;
145 int minimum_buffer_size = hardware_buffer_size;
146
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 =
151 GetMinAudioBufferSizeMacOS(limits::kMinAudioBufferSize, sample_rate);
152 #elif defined(USE_CRAS)
153 minimum_buffer_size = limits::kMinAudioBufferSize;
154 #endif
155
156 // Round the requested size to the nearest multiple of the hardware size 137 // Round the requested size to the nearest multiple of the hardware size
157 const int buffer_size = 138 const int buffer_size =
158 std::round(std::max(requested_buffer_size, 1.0) / hardware_buffer_size) * 139 std::round(std::max(requested_buffer_size, 1.0) / hardware_buffer_size) *
159 hardware_buffer_size; 140 hardware_buffer_size;
160 141
161 return std::min(static_cast<int>(limits::kMaxAudioBufferSize), 142 return std::max(buffer_size, hardware_buffer_size);
162 std::max(buffer_size, minimum_buffer_size));
163 #endif
164 } 143 }
165 144
166 } // namespace media 145 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/audio_manager_pulse.cc ('k') | media/base/limits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698