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

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: 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
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 // Taken from "Bit Twiddling Hacks"
18 // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
19 static uint32_t RoundUpToPowerOfTwo(uint32_t v) {
20 v--;
21 v |= v >> 1;
22 v |= v >> 2;
23 v |= v >> 4;
24 v |= v >> 8;
25 v |= v >> 16;
26 v++;
27 return v;
28 }
29
12 AudioHardwareConfig::AudioHardwareConfig( 30 AudioHardwareConfig::AudioHardwareConfig(
13 const AudioParameters& input_params, 31 const AudioParameters& input_params,
14 const AudioParameters& output_params) 32 const AudioParameters& output_params)
15 : input_params_(input_params), 33 : input_params_(input_params),
16 output_params_(output_params) { 34 output_params_(output_params) {
35 DCHECK(input_params_.IsValid());
36 DCHECK(output_params_.IsValid());
17 } 37 }
18 38
19 AudioHardwareConfig::~AudioHardwareConfig() {} 39 AudioHardwareConfig::~AudioHardwareConfig() {}
20 40
21 int AudioHardwareConfig::GetOutputBufferSize() const { 41 int AudioHardwareConfig::GetOutputBufferSize() const {
22 AutoLock auto_lock(config_lock_); 42 AutoLock auto_lock(config_lock_);
23 return output_params_.frames_per_buffer(); 43 return output_params_.frames_per_buffer();
24 } 44 }
25 45
26 int AudioHardwareConfig::GetOutputSampleRate() const { 46 int AudioHardwareConfig::GetOutputSampleRate() const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 AutoLock auto_lock(config_lock_); 90 AutoLock auto_lock(config_lock_);
71 input_params_ = input_params; 91 input_params_ = input_params;
72 } 92 }
73 93
74 void AudioHardwareConfig::UpdateOutputConfig( 94 void AudioHardwareConfig::UpdateOutputConfig(
75 const AudioParameters& output_params) { 95 const AudioParameters& output_params) {
76 AutoLock auto_lock(config_lock_); 96 AutoLock auto_lock(config_lock_);
77 output_params_ = output_params; 97 output_params_ = output_params;
78 } 98 }
79 99
100 int AudioHardwareConfig::GetHighLatencyBufferSize() const {
101 AutoLock auto_lock(config_lock_);
102 #if defined(OS_LINUX)
103 // Empirically, use the nearest higher power of two buffer size corresponding
104 // to 20 ms worth of samples. For a given sample rate, this works out to:
no longer working on chromium 2014/04/14 08:51:50 curiously, 20ms does not sound "high" latency, why
DaleCurtis 2014/04/14 18:08:18 As discussed in the meeting this morning, I choose
105 //
106 // <= 3200 : 64
107 // <= 6400 : 128
108 // <= 12800 : 256
109 // <= 25600 : 512
110 // <= 51200 : 1024
111 // <= 102400 : 2048
112 // <= 204800 : 4096
113 //
114 // On Linux, the minimum hardware buffer size is 512, so the lower calculated
115 // values are unused. OSX may have a value as low as 128. Windows is device
henrika (OOO until Aug 14) 2014/04/14 08:03:24 Should comments about OSX and Windows be within de
DaleCurtis 2014/04/14 18:08:18 I hope eventually this section will have all OS, s
116 // dependent but will generally be sample_rate() / 100.
117 const int high_latency_buffer_size =
118 RoundUpToPowerOfTwo(2 * output_params_.sample_rate() / 100);
119 return std::max(output_params_.frames_per_buffer(), high_latency_buffer_size);
120 #else
121 return output_params_.frames_per_buffer();
122 #endif
123 }
124
80 } // namespace media 125 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698