OLD | NEW |
---|---|
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 Loading... | |
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::GetDefaultOutputStreamParameters( | |
102 const AudioParameters& input_params) { | |
103 static const int kDefaultOutputBufferSize = 512; | |
104 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | |
105 int sample_rate = kDefaultSampleRate; | |
106 int buffer_size = kDefaultOutputBufferSize; | |
107 int bits_per_sample = 16; | |
108 int input_channels = 0; | |
109 if (input_params.IsValid()) { | |
110 // Since Linux doesn't actually have a low latency path the hardware buffer | |
DaleCurtis
2013/03/02 01:53:56
Comment can be deleted now.
no longer working on chromium
2013/03/04 14:55:04
Delete the first comment, and I think the other is
| |
111 // size is quite large in order to prevent glitches with general usage. | |
112 // Some clients, such as WebRTC, have a more limited use case and work | |
113 // acceptably with a smaller buffer size. The check below allows clients | |
114 // which want to try a smaller buffer size on Linux to do so. | |
115 // TODO(dalecurtis): This should include bits per channel and channel layout | |
116 // eventually. | |
117 sample_rate = input_params.sample_rate(); | |
118 bits_per_sample = input_params.bits_per_sample(); | |
119 channel_layout = input_params.channel_layout(); | |
120 input_channels = input_params.input_channels(); | |
121 buffer_size = std::min(input_params.frames_per_buffer(), buffer_size); | |
122 } | |
123 | |
124 return AudioParameters( | |
125 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, | |
126 sample_rate, bits_per_sample, buffer_size); | |
127 } | |
128 | |
129 AudioParameters AudioManagerLinux::GetInputStreamParameters( | |
130 const std::string& device_id) { | |
131 static const int kDefaultInputBufferSize = 1024; | |
132 | |
133 return AudioParameters( | |
134 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | |
135 kDefaultSampleRate, 16, kDefaultInputBufferSize); | |
136 } | |
137 | |
97 void AudioManagerLinux::GetAlsaAudioInputDevices( | 138 void AudioManagerLinux::GetAlsaAudioInputDevices( |
98 media::AudioDeviceNames* device_names) { | 139 media::AudioDeviceNames* device_names) { |
99 // Constants specified by the ALSA API for device hints. | 140 // Constants specified by the ALSA API for device hints. |
100 static const char kPcmInterfaceName[] = "pcm"; | 141 static const char kPcmInterfaceName[] = "pcm"; |
101 int card = -1; | 142 int card = -1; |
102 | 143 |
103 // Loop through the sound cards to get ALSA device hints. | 144 // Loop through the sound cards to get ALSA device hints. |
104 while (!wrapper_->CardNext(&card) && card >= 0) { | 145 while (!wrapper_->CardNext(&card) && card >= 0) { |
105 void** hints = NULL; | 146 void** hints = NULL; |
106 int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints); | 147 int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { | 326 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { |
286 AudioManager* manager = AudioManagerPulse::Create(); | 327 AudioManager* manager = AudioManagerPulse::Create(); |
287 if (manager) | 328 if (manager) |
288 return manager; | 329 return manager; |
289 } | 330 } |
290 #endif | 331 #endif |
291 | 332 |
292 return new AudioManagerLinux(); | 333 return new AudioManagerLinux(); |
293 } | 334 } |
294 | 335 |
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 | 336 } // namespace media |
OLD | NEW |