| 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 static const int kDefaultOutputBufferSize = 512; |
| 103 |
| 104 return AudioParameters( |
| 105 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 106 kDefaultSampleRate, 16, kDefaultOutputBufferSize); |
| 107 } |
| 108 |
| 109 AudioParameters AudioManagerLinux::GetDefaultInputStreamParameters( |
| 110 const std::string& device_id) { |
| 111 static const int kDefaultInputBufferSize = 1024; |
| 112 |
| 113 return AudioParameters( |
| 114 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 115 kDefaultSampleRate, 16, kDefaultInputBufferSize); |
| 116 } |
| 117 |
| 97 void AudioManagerLinux::GetAlsaAudioInputDevices( | 118 void AudioManagerLinux::GetAlsaAudioInputDevices( |
| 98 media::AudioDeviceNames* device_names) { | 119 media::AudioDeviceNames* device_names) { |
| 99 // Constants specified by the ALSA API for device hints. | 120 // Constants specified by the ALSA API for device hints. |
| 100 static const char kPcmInterfaceName[] = "pcm"; | 121 static const char kPcmInterfaceName[] = "pcm"; |
| 101 int card = -1; | 122 int card = -1; |
| 102 | 123 |
| 103 // Loop through the sound cards to get ALSA device hints. | 124 // Loop through the sound cards to get ALSA device hints. |
| 104 while (!wrapper_->CardNext(&card) && card >= 0) { | 125 while (!wrapper_->CardNext(&card) && card >= 0) { |
| 105 void** hints = NULL; | 126 void** hints = NULL; |
| 106 int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints); | 127 int error = wrapper_->DeviceNameHint(card, kPcmInterfaceName, &hints); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 return new AudioManagerLinux(); | 313 return new AudioManagerLinux(); |
| 293 } | 314 } |
| 294 | 315 |
| 295 AudioParameters AudioManagerLinux::GetPreferredLowLatencyOutputStreamParameters( | 316 AudioParameters AudioManagerLinux::GetPreferredLowLatencyOutputStreamParameters( |
| 296 const AudioParameters& input_params) { | 317 const AudioParameters& input_params) { |
| 297 // Since Linux doesn't actually have a low latency path the hardware buffer | 318 // 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 | 319 // 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 | 320 // 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 | 321 // with a smaller buffer size. The check below allows clients which want to |
| 301 // try a smaller buffer size on Linux to do so. | 322 // try a smaller buffer size on Linux to do so. |
| 302 int buffer_size = GetAudioHardwareBufferSize(); | 323 AudioParameters default_params = GetDefaultOutputStreamParameters(); |
| 303 if (input_params.frames_per_buffer() < buffer_size) | 324 int buffer_size = std::min(input_params.frames_per_buffer(), |
| 304 buffer_size = input_params.frames_per_buffer(); | 325 default_params.frames_per_buffer()); |
| 305 | 326 |
| 306 // TODO(dalecurtis): This should include bits per channel and channel layout | 327 // TODO(dalecurtis): This should include bits per channel and channel layout |
| 307 // eventually. | 328 // eventually. |
| 308 return AudioParameters( | 329 return AudioParameters( |
| 309 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), | 330 AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), |
| 310 input_params.sample_rate(), 16, buffer_size); | 331 input_params.sample_rate(), 16, buffer_size); |
| 311 } | 332 } |
| 312 | 333 |
| 313 } // namespace media | 334 } // namespace media |
| OLD | NEW |