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_hardware_config.cc

Issue 235723003: Use larger buffer sizes for lower power on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test on other platforms. Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « media/base/audio_hardware_config.h ('k') | media/base/audio_hardware_config_unittest.cc » ('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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_hardware_config.h" 5 #include "media/base/audio_hardware_config.h"
6 6
7 #include <algorithm>
8
9 #include "base/logging.h"
10 #include "build/build_config.h"
11
7 using base::AutoLock; 12 using base::AutoLock;
8 using media::AudioParameters; 13 using media::AudioParameters;
9 14
10 namespace media { 15 namespace media {
11 16
17 #if defined(OS_LINUX)
18 #define HIGH_LATENCY_AUDIO_SUPPORT 1
19 #endif
20
21 #if defined(HIGH_LATENCY_AUDIO_SUPPORT)
22 // Taken from "Bit Twiddling Hacks"
23 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
24 static uint32_t RoundUpToPowerOfTwo(uint32_t v) {
25 v--;
26 v |= v >> 1;
27 v |= v >> 2;
28 v |= v >> 4;
29 v |= v >> 8;
30 v |= v >> 16;
31 v++;
32 return v;
33 }
34 #endif
35
12 AudioHardwareConfig::AudioHardwareConfig( 36 AudioHardwareConfig::AudioHardwareConfig(
13 const AudioParameters& input_params, 37 const AudioParameters& input_params,
14 const AudioParameters& output_params) 38 const AudioParameters& output_params)
15 : input_params_(input_params), 39 : input_params_(input_params),
16 output_params_(output_params) { 40 output_params_(output_params) {}
17 }
18 41
19 AudioHardwareConfig::~AudioHardwareConfig() {} 42 AudioHardwareConfig::~AudioHardwareConfig() {}
20 43
21 int AudioHardwareConfig::GetOutputBufferSize() const { 44 int AudioHardwareConfig::GetOutputBufferSize() const {
22 AutoLock auto_lock(config_lock_); 45 AutoLock auto_lock(config_lock_);
23 return output_params_.frames_per_buffer(); 46 return output_params_.frames_per_buffer();
24 } 47 }
25 48
26 int AudioHardwareConfig::GetOutputSampleRate() const { 49 int AudioHardwareConfig::GetOutputSampleRate() const {
27 AutoLock auto_lock(config_lock_); 50 AutoLock auto_lock(config_lock_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 AutoLock auto_lock(config_lock_); 93 AutoLock auto_lock(config_lock_);
71 input_params_ = input_params; 94 input_params_ = input_params;
72 } 95 }
73 96
74 void AudioHardwareConfig::UpdateOutputConfig( 97 void AudioHardwareConfig::UpdateOutputConfig(
75 const AudioParameters& output_params) { 98 const AudioParameters& output_params) {
76 AutoLock auto_lock(config_lock_); 99 AutoLock auto_lock(config_lock_);
77 output_params_ = output_params; 100 output_params_ = output_params;
78 } 101 }
79 102
103 int AudioHardwareConfig::GetHighLatencyBufferSize() const {
104 AutoLock auto_lock(config_lock_);
105 #if defined(HIGH_LATENCY_AUDIO_SUPPORT)
106 // Empirically, use the nearest higher power of two buffer size corresponding
107 // to 20 ms worth of samples. For a given sample rate, this works out to:
108 //
109 // <= 3200 : 64
110 // <= 6400 : 128
111 // <= 12800 : 256
112 // <= 25600 : 512
113 // <= 51200 : 1024
114 // <= 102400 : 2048
115 // <= 204800 : 4096
116 //
117 // On Linux, the minimum hardware buffer size is 512, so the lower calculated
118 // values are unused. OSX may have a value as low as 128. Windows is device
119 // dependent but will generally be sample_rate() / 100.
120 const int high_latency_buffer_size =
121 RoundUpToPowerOfTwo(2 * output_params_.sample_rate() / 100);
122 return std::max(output_params_.frames_per_buffer(), high_latency_buffer_size);
123 #else
124 return output_params_.frames_per_buffer();
125 #endif
126 }
127
80 } // namespace media 128 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_hardware_config.h ('k') | media/base/audio_hardware_config_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698