Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 // Since "default", "pulse" and "dmix" devices are virtual devices mapped to | 30 // Since "default", "pulse" and "dmix" devices are virtual devices mapped to |
| 31 // real devices, we remove them from the list to avoiding duplicate counting. | 31 // real devices, we remove them from the list to avoiding duplicate counting. |
| 32 // In addition, note that we support no more than 2 channels for recording, | 32 // In addition, note that we support no more than 2 channels for recording, |
| 33 // hence surround devices are not stored in the list. | 33 // hence surround devices are not stored in the list. |
| 34 static const char* kInvalidAudioInputDevices[] = { | 34 static const char* kInvalidAudioInputDevices[] = { |
| 35 "default", | 35 "default", |
| 36 "null", | 36 "null", |
| 37 "pulse", | 37 "pulse", |
| 38 "dmix", | 38 "dmix", |
| 39 "surround", | |
|
scherkus (not reviewing)
2011/11/16 01:20:40
??
no longer working on chromium
2011/11/16 17:45:48
We would like to strip out all the surround device
| |
| 40 }; | 39 }; |
| 41 | 40 |
| 42 // Implementation of AudioManager. | 41 // Implementation of AudioManager. |
| 43 bool AudioManagerLinux::HasAudioOutputDevices() { | 42 bool AudioManagerLinux::HasAudioOutputDevices() { |
| 44 return HasAnyAlsaAudioDevice(kStreamPlayback); | 43 return HasAnyAlsaAudioDevice(kStreamPlayback); |
| 45 } | 44 } |
| 46 | 45 |
| 47 bool AudioManagerLinux::HasAudioInputDevices() { | 46 bool AudioManagerLinux::HasAudioInputDevices() { |
| 48 return HasAnyAlsaAudioDevice(kStreamCapture); | 47 return HasAnyAlsaAudioDevice(kStreamCapture); |
| 49 } | 48 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 80 stream = new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, | 79 stream = new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, |
| 81 GetMessageLoop()); | 80 GetMessageLoop()); |
| 82 #if defined(USE_PULSEAUDIO) | 81 #if defined(USE_PULSEAUDIO) |
| 83 } | 82 } |
| 84 #endif | 83 #endif |
| 85 active_streams_.insert(stream); | 84 active_streams_.insert(stream); |
| 86 return stream; | 85 return stream; |
| 87 } | 86 } |
| 88 | 87 |
| 89 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( | 88 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( |
| 90 const AudioParameters& params) { | 89 const AudioParameters& params, const std::string& device_uid) { |
| 91 if (!params.IsValid() || params.channels > kMaxInputChannels) | 90 if (!params.IsValid() || params.channels > kMaxInputChannels) |
| 92 return NULL; | 91 return NULL; |
| 93 | 92 |
| 94 if (params.format == AudioParameters::AUDIO_MOCK) { | 93 if (params.format == AudioParameters::AUDIO_MOCK) { |
| 95 return FakeAudioInputStream::MakeFakeStream(params); | 94 return FakeAudioInputStream::MakeFakeStream(params); |
| 96 } else if (params.format != AudioParameters::AUDIO_PCM_LINEAR) { | 95 } else if (params.format != AudioParameters::AUDIO_PCM_LINEAR) { |
| 97 return NULL; | 96 return NULL; |
| 98 } | 97 } |
| 99 | 98 |
| 100 if (!initialized()) | 99 if (!initialized()) |
| 101 return NULL; | 100 return NULL; |
| 102 | 101 |
| 103 // TODO(xians): Pass the device name From AudioInputController instead. | 102 std::string device_name; |
| 104 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; | 103 if ((device_uid == AudioManagerBase::kDefaultDeviceId) || device_uid.empty()) |
| 104 device_name = AlsaPcmInputStream::kAutoSelectDevice; | |
| 105 else | |
| 106 device_name = device_uid; | |
| 105 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { | 107 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { |
| 106 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 108 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 107 switches::kAlsaInputDevice); | 109 switches::kAlsaInputDevice); |
| 108 } | 110 } |
| 109 | 111 |
| 110 AlsaPcmInputStream* stream = new AlsaPcmInputStream( | 112 AlsaPcmInputStream* stream = new AlsaPcmInputStream( |
| 111 device_name, params, wrapper_.get()); | 113 device_name, params, wrapper_.get()); |
| 112 | 114 |
| 113 return stream; | 115 return stream; |
| 114 } | 116 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 DCHECK(device_names->empty()); | 178 DCHECK(device_names->empty()); |
| 177 | 179 |
| 178 GetAlsaAudioInputDevices(device_names); | 180 GetAlsaAudioInputDevices(device_names); |
| 179 | 181 |
| 180 if (!device_names->empty()) { | 182 if (!device_names->empty()) { |
| 181 // Prepend the default device to the list since we always want it to be | 183 // Prepend the default device to the list since we always want it to be |
| 182 // on the top of the list for all platforms. There is no duplicate | 184 // on the top of the list for all platforms. There is no duplicate |
| 183 // counting here since the default device has been abstracted out before. | 185 // counting here since the default device has been abstracted out before. |
| 184 // We use index 0 to make up the unique_id to identify the default device. | 186 // We use index 0 to make up the unique_id to identify the default device. |
| 185 device_names->push_front(media::AudioDeviceName( | 187 device_names->push_front(media::AudioDeviceName( |
| 186 AudioManagerBase::kDefaultDeviceName, "0")); | 188 AudioManagerBase::kDefaultDeviceName, |
| 189 AudioManagerBase::kDefaultDeviceId)); | |
| 187 } | 190 } |
| 188 } | 191 } |
| 189 | 192 |
| 190 void AudioManagerLinux::GetAlsaAudioInputDevices( | 193 void AudioManagerLinux::GetAlsaAudioInputDevices( |
| 191 media::AudioDeviceNames* device_names) { | 194 media::AudioDeviceNames* device_names) { |
| 192 // Constants specified by the ALSA API for device hints. | 195 // Constants specified by the ALSA API for device hints. |
| 193 static const char kPcmInterfaceName[] = "pcm"; | 196 static const char kPcmInterfaceName[] = "pcm"; |
| 194 int card = -1; | 197 int card = -1; |
| 195 | 198 |
| 196 // Loop through the sound cards to get ALSA device hints. | 199 // Loop through the sound cards to get ALSA device hints. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 name.device_name = unique_device_name.get(); | 252 name.device_name = unique_device_name.get(); |
| 250 } | 253 } |
| 251 | 254 |
| 252 // Store the device information. | 255 // Store the device information. |
| 253 device_names->push_back(name); | 256 device_names->push_back(name); |
| 254 } | 257 } |
| 255 } | 258 } |
| 256 } | 259 } |
| 257 | 260 |
| 258 bool AudioManagerLinux::IsAlsaDeviceAvailable(const char* device_name) { | 261 bool AudioManagerLinux::IsAlsaDeviceAvailable(const char* device_name) { |
| 262 static const char kNotWantedSurroundDevices[] = "surround"; | |
| 263 | |
| 259 if (!device_name) | 264 if (!device_name) |
| 260 return false; | 265 return false; |
| 261 | 266 |
| 262 // Check if the device is in the list of invalid devices. | 267 // Check if the device is in the list of invalid devices. |
| 263 for (size_t i = 0; i < arraysize(kInvalidAudioInputDevices); ++i) { | 268 for (size_t i = 0; i < arraysize(kInvalidAudioInputDevices); ++i) { |
| 264 if (!strncmp(kInvalidAudioInputDevices[i], device_name, | 269 if (!strcmp(kInvalidAudioInputDevices[i], device_name) || |
| 265 strlen(kInvalidAudioInputDevices[i]))) | 270 !strncmp(kNotWantedSurroundDevices, device_name, |
| 271 arraysize(kNotWantedSurroundDevices) -1)) | |
|
scherkus (not reviewing)
2011/11/16 01:20:40
nit space between -1
no longer working on chromium
2011/11/16 17:45:48
Done.
| |
| 266 return false; | 272 return false; |
| 267 } | 273 } |
| 268 | 274 |
| 269 // The only way to check if the device is available is to open/close the | 275 // The only way to check if the device is available is to open/close the |
| 270 // device. Return false if it fails either of operations. | 276 // device. Return false if it fails either of operations. |
| 271 snd_pcm_t* device_handle = NULL; | 277 snd_pcm_t* device_handle = NULL; |
| 272 if (wrapper_->PcmOpen(&device_handle, | 278 if (wrapper_->PcmOpen(&device_handle, |
| 273 device_name, | 279 device_name, |
| 274 SND_PCM_STREAM_CAPTURE, | 280 SND_PCM_STREAM_CAPTURE, |
| 275 SND_PCM_NONBLOCK)) | 281 SND_PCM_NONBLOCK)) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 } | 323 } |
| 318 } | 324 } |
| 319 | 325 |
| 320 return has_device; | 326 return has_device; |
| 321 } | 327 } |
| 322 | 328 |
| 323 // static | 329 // static |
| 324 AudioManager* AudioManager::CreateAudioManager() { | 330 AudioManager* AudioManager::CreateAudioManager() { |
| 325 return new AudioManagerLinux(); | 331 return new AudioManagerLinux(); |
| 326 } | 332 } |
| OLD | NEW |