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

Side by Side Diff: media/audio/linux/audio_manager_linux.cc

Issue 12316131: Moved AudioUtil static functions to AudioManager interfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: made the GetPreferredOutputStreamParameters protected Created 7 years, 9 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/linux/audio_manager_linux.h ('k') | media/audio/mac/audio_device_listener_mac.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/linux/audio_manager_linux.h" 5 #include "media/audio/linux/audio_manager_linux.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/logging.h" 9 #include "base/logging.h"
10 #include "base/nix/xdg_util.h" 10 #include "base/nix/xdg_util.h"
11 #include "base/process_util.h" 11 #include "base/process_util.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "media/audio/audio_output_dispatcher.h" 13 #include "media/audio/audio_output_dispatcher.h"
14 #include "media/audio/audio_util.h" 14 #include "media/audio/audio_parameters.h"
15 #if defined(USE_CRAS) 15 #if defined(USE_CRAS)
16 #include "media/audio/cras/audio_manager_cras.h" 16 #include "media/audio/cras/audio_manager_cras.h"
17 #endif 17 #endif
18 #include "media/audio/linux/alsa_input.h" 18 #include "media/audio/linux/alsa_input.h"
19 #include "media/audio/linux/alsa_output.h" 19 #include "media/audio/linux/alsa_output.h"
20 #include "media/audio/linux/alsa_wrapper.h" 20 #include "media/audio/linux/alsa_wrapper.h"
21 #if defined(USE_PULSEAUDIO) 21 #if defined(USE_PULSEAUDIO)
22 #include "media/audio/pulse/audio_manager_pulse.h" 22 #include "media/audio/pulse/audio_manager_pulse.h"
23 #endif 23 #endif
24 #include "media/base/channel_layout.h"
24 #include "media/base/limits.h" 25 #include "media/base/limits.h"
25 #include "media/base/media_switches.h" 26 #include "media/base/media_switches.h"
26 27
27 namespace media { 28 namespace media {
28 29
29 // Maximum number of output streams that can be open simultaneously. 30 // Maximum number of output streams that can be open simultaneously.
30 static const int kMaxOutputStreams = 50; 31 static const int kMaxOutputStreams = 50;
31 32
33 // Default sample rate for input and output streams.
34 static const int kDefaultSampleRate = 48000;
35
32 // Since "default", "pulse" and "dmix" devices are virtual devices mapped to 36 // Since "default", "pulse" and "dmix" devices are virtual devices mapped to
33 // real devices, we remove them from the list to avoiding duplicate counting. 37 // real devices, we remove them from the list to avoiding duplicate counting.
34 // In addition, note that we support no more than 2 channels for recording, 38 // In addition, note that we support no more than 2 channels for recording,
35 // hence surround devices are not stored in the list. 39 // hence surround devices are not stored in the list.
36 static const char* kInvalidAudioInputDevices[] = { 40 static const char* kInvalidAudioInputDevices[] = {
37 "default", 41 "default",
38 "null", 42 "null",
39 "pulse", 43 "pulse",
40 "dmix", 44 "dmix",
41 "surround", 45 "surround",
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 void AudioManagerLinux::ShowAudioInputSettings() { 91 void AudioManagerLinux::ShowAudioInputSettings() {
88 ShowLinuxAudioInputSettings(); 92 ShowLinuxAudioInputSettings();
89 } 93 }
90 94
91 void AudioManagerLinux::GetAudioInputDeviceNames( 95 void AudioManagerLinux::GetAudioInputDeviceNames(
92 media::AudioDeviceNames* device_names) { 96 media::AudioDeviceNames* device_names) {
93 DCHECK(device_names->empty()); 97 DCHECK(device_names->empty());
94 GetAlsaAudioInputDevices(device_names); 98 GetAlsaAudioInputDevices(device_names);
95 } 99 }
96 100
101 AudioParameters AudioManagerLinux::GetInputStreamParameters(
102 const std::string& device_id) {
103 static const int kDefaultInputBufferSize = 1024;
104
105 return AudioParameters(
106 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
107 kDefaultSampleRate, 16, kDefaultInputBufferSize);
108 }
109
97 void AudioManagerLinux::GetAlsaAudioInputDevices( 110 void AudioManagerLinux::GetAlsaAudioInputDevices(
98 media::AudioDeviceNames* device_names) { 111 media::AudioDeviceNames* device_names) {
99 // Constants specified by the ALSA API for device hints. 112 // Constants specified by the ALSA API for device hints.
100 static const char kPcmInterfaceName[] = "pcm"; 113 static const char kPcmInterfaceName[] = "pcm";
101 int card = -1; 114 int card = -1;
102 115
103 // Loop through the sound cards to get ALSA device hints. 116 // Loop through the sound cards to get ALSA device hints.
104 while (!wrapper_->CardNext(&card) && card >= 0) { 117 while (!wrapper_->CardNext(&card) && card >= 0) {
105 void** hints = NULL; 118 void** hints = NULL;
106 int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints); 119 int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); 257 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format());
245 return MakeInputStream(params, device_id); 258 return MakeInputStream(params, device_id);
246 } 259 }
247 260
248 AudioInputStream* AudioManagerLinux::MakeLowLatencyInputStream( 261 AudioInputStream* AudioManagerLinux::MakeLowLatencyInputStream(
249 const AudioParameters& params, const std::string& device_id) { 262 const AudioParameters& params, const std::string& device_id) {
250 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); 263 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format());
251 return MakeInputStream(params, device_id); 264 return MakeInputStream(params, device_id);
252 } 265 }
253 266
267 AudioParameters AudioManagerLinux::GetPreferredOutputStreamParameters(
268 const AudioParameters& input_params) {
269 static const int kDefaultOutputBufferSize = 512;
270 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
271 int sample_rate = kDefaultSampleRate;
272 int buffer_size = kDefaultOutputBufferSize;
273 int bits_per_sample = 16;
274 int input_channels = 0;
275 if (input_params.IsValid()) {
276 // Some clients, such as WebRTC, have a more limited use case and work
277 // acceptably with a smaller buffer size. The check below allows clients
278 // which want to try a smaller buffer size on Linux to do so.
279 // TODO(dalecurtis): This should include bits per channel and channel layout
280 // eventually.
281 sample_rate = input_params.sample_rate();
282 bits_per_sample = input_params.bits_per_sample();
283 channel_layout = input_params.channel_layout();
284 input_channels = input_params.input_channels();
285 buffer_size = std::min(input_params.frames_per_buffer(), buffer_size);
286 }
287
288 return AudioParameters(
289 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels,
290 sample_rate, bits_per_sample, buffer_size);
291 }
292
254 AudioOutputStream* AudioManagerLinux::MakeOutputStream( 293 AudioOutputStream* AudioManagerLinux::MakeOutputStream(
255 const AudioParameters& params) { 294 const AudioParameters& params) {
256 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; 295 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice;
257 if (CommandLine::ForCurrentProcess()->HasSwitch( 296 if (CommandLine::ForCurrentProcess()->HasSwitch(
258 switches::kAlsaOutputDevice)) { 297 switches::kAlsaOutputDevice)) {
259 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 298 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
260 switches::kAlsaOutputDevice); 299 switches::kAlsaOutputDevice);
261 } 300 }
262 return new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this); 301 return new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this);
263 } 302 }
(...skipping 21 matching lines...) Expand all
285 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { 324 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) {
286 AudioManager* manager = AudioManagerPulse::Create(); 325 AudioManager* manager = AudioManagerPulse::Create();
287 if (manager) 326 if (manager)
288 return manager; 327 return manager;
289 } 328 }
290 #endif 329 #endif
291 330
292 return new AudioManagerLinux(); 331 return new AudioManagerLinux();
293 } 332 }
294 333
295 AudioParameters AudioManagerLinux::GetPreferredLowLatencyOutputStreamParameters(
296 const AudioParameters& input_params) {
297 // Since Linux doesn't actually have a low latency path the hardware buffer
298 // size is quite large in order to prevent glitches with general usage. Some
299 // clients, such as WebRTC, have a more limited use case and work acceptably
300 // with a smaller buffer size. The check below allows clients which want to
301 // try a smaller buffer size on Linux to do so.
302 int buffer_size = GetAudioHardwareBufferSize();
303 if (input_params.frames_per_buffer() < buffer_size)
304 buffer_size = input_params.frames_per_buffer();
305
306 // TODO(dalecurtis): This should include bits per channel and channel layout
307 // eventually.
308 return AudioParameters(
309 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(),
310 input_params.sample_rate(), 16, buffer_size);
311 }
312
313 } // namespace media 334 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/linux/audio_manager_linux.h ('k') | media/audio/mac/audio_device_listener_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698