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

Side by Side Diff: media/audio/pulse/audio_manager_pulse.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/audio/cras/audio_manager_cras.cc ('k') | media/base/audio_hardware_config.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/audio/pulse/audio_manager_pulse.h" 5 #include "media/audio/pulse/audio_manager_pulse.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/environment.h" 8 #include "base/environment.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 17 matching lines...) Expand all
28 #endif // defined(DLOPEN_PULSEAUDIO) 28 #endif // defined(DLOPEN_PULSEAUDIO)
29 29
30 namespace media { 30 namespace media {
31 31
32 using pulse::AutoPulseLock; 32 using pulse::AutoPulseLock;
33 using pulse::WaitForOperationCompletion; 33 using pulse::WaitForOperationCompletion;
34 34
35 // Maximum number of output streams that can be open simultaneously. 35 // Maximum number of output streams that can be open simultaneously.
36 static const int kMaxOutputStreams = 50; 36 static const int kMaxOutputStreams = 50;
37 37
38 // Define bounds for the output buffer size.
39 static const int kMinimumOutputBufferSize = 512;
40 static const int kMaximumOutputBufferSize = 8192;
41
38 static const base::FilePath::CharType kPulseLib[] = 42 static const base::FilePath::CharType kPulseLib[] =
39 FILE_PATH_LITERAL("libpulse.so.0"); 43 FILE_PATH_LITERAL("libpulse.so.0");
40 44
41 // static 45 // static
42 AudioManager* AudioManagerPulse::Create(AudioLogFactory* audio_log_factory) { 46 AudioManager* AudioManagerPulse::Create(AudioLogFactory* audio_log_factory) {
43 scoped_ptr<AudioManagerPulse> ret(new AudioManagerPulse(audio_log_factory)); 47 scoped_ptr<AudioManagerPulse> ret(new AudioManagerPulse(audio_log_factory));
44 if (ret->Init()) 48 if (ret->Init())
45 return ret.release(); 49 return ret.release();
46 50
47 DVLOG(1) << "PulseAudio is not available on the OS"; 51 DVLOG(1) << "PulseAudio is not available on the OS";
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const AudioParameters& params, const std::string& device_id) { 158 const AudioParameters& params, const std::string& device_id) {
155 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); 159 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
156 return MakeInputStream(params, device_id); 160 return MakeInputStream(params, device_id);
157 } 161 }
158 162
159 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters( 163 AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters(
160 const std::string& output_device_id, 164 const std::string& output_device_id,
161 const AudioParameters& input_params) { 165 const AudioParameters& input_params) {
162 // TODO(tommi): Support |output_device_id|. 166 // TODO(tommi): Support |output_device_id|.
163 VLOG_IF(0, !output_device_id.empty()) << "Not implemented!"; 167 VLOG_IF(0, !output_device_id.empty()) << "Not implemented!";
164 static const int kDefaultOutputBufferSize = 512;
165 168
166 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; 169 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
167 int buffer_size = kDefaultOutputBufferSize; 170 int buffer_size = kMinimumOutputBufferSize;
168 int bits_per_sample = 16; 171 int bits_per_sample = 16;
169 int input_channels = 0; 172 int input_channels = 0;
170 int sample_rate; 173 int sample_rate;
171 if (input_params.IsValid()) { 174 if (input_params.IsValid()) {
172 bits_per_sample = input_params.bits_per_sample(); 175 bits_per_sample = input_params.bits_per_sample();
173 channel_layout = input_params.channel_layout(); 176 channel_layout = input_params.channel_layout();
174 input_channels = input_params.input_channels(); 177 input_channels = input_params.input_channels();
175 buffer_size = std::min(buffer_size, input_params.frames_per_buffer()); 178 buffer_size =
179 std::min(kMaximumOutputBufferSize,
180 std::max(buffer_size, input_params.frames_per_buffer()));
176 sample_rate = input_params.sample_rate(); 181 sample_rate = input_params.sample_rate();
177 } else { 182 } else {
178 sample_rate = GetNativeSampleRate(); 183 sample_rate = GetNativeSampleRate();
179 } 184 }
180 185
181 int user_buffer_size = GetUserBufferSize(); 186 int user_buffer_size = GetUserBufferSize();
182 if (user_buffer_size) 187 if (user_buffer_size)
183 buffer_size = user_buffer_size; 188 buffer_size = user_buffer_size;
184 189
185 return AudioParameters( 190 return AudioParameters(
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, 331 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context,
327 const pa_server_info* info, 332 const pa_server_info* info,
328 void* user_data) { 333 void* user_data) {
329 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); 334 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data);
330 335
331 manager->native_input_sample_rate_ = info->sample_spec.rate; 336 manager->native_input_sample_rate_ = info->sample_spec.rate;
332 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); 337 pa_threaded_mainloop_signal(manager->input_mainloop_, 0);
333 } 338 }
334 339
335 } // namespace media 340 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/cras/audio_manager_cras.cc ('k') | media/base/audio_hardware_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698