Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 AudioManagerPulse::~AudioManagerPulse() { | 59 AudioManagerPulse::~AudioManagerPulse() { |
| 60 Shutdown(); | 60 Shutdown(); |
| 61 | 61 |
| 62 // The Pulse objects are the last things to be destroyed since Shutdown() | 62 // The Pulse objects are the last things to be destroyed since Shutdown() |
| 63 // needs them. | 63 // needs them. |
| 64 DestroyPulse(); | 64 DestroyPulse(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 // Implementation of AudioManager. | 67 // Implementation of AudioManager. |
| 68 bool AudioManagerPulse::HasAudioOutputDevices() { | 68 bool AudioManagerPulse::HasAudioOutputDevices() { |
| 69 DCHECK(input_mainloop_); | 69 AudioDeviceNames devices; |
| 70 DCHECK(input_context_); | 70 GetAudioOutputDeviceNames(&devices); |
| 71 media::AudioDeviceNames devices; | |
| 72 AutoPulseLock auto_lock(input_mainloop_); | |
| 73 devices_ = &devices; | |
| 74 pa_operation* operation = pa_context_get_sink_info_list( | |
| 75 input_context_, OutputDevicesInfoCallback, this); | |
| 76 WaitForOperationCompletion(input_mainloop_, operation); | |
| 77 return !devices.empty(); | 71 return !devices.empty(); |
| 78 } | 72 } |
| 79 | 73 |
| 80 bool AudioManagerPulse::HasAudioInputDevices() { | 74 bool AudioManagerPulse::HasAudioInputDevices() { |
| 81 media::AudioDeviceNames devices; | 75 AudioDeviceNames devices; |
| 82 GetAudioInputDeviceNames(&devices); | 76 GetAudioInputDeviceNames(&devices); |
| 83 return !devices.empty(); | 77 return !devices.empty(); |
| 84 } | 78 } |
| 85 | 79 |
| 86 void AudioManagerPulse::ShowAudioInputSettings() { | 80 void AudioManagerPulse::ShowAudioInputSettings() { |
| 87 AudioManagerLinux::ShowLinuxAudioInputSettings(); | 81 AudioManagerLinux::ShowLinuxAudioInputSettings(); |
| 88 } | 82 } |
| 89 | 83 |
| 90 void AudioManagerPulse::GetAudioInputDeviceNames( | 84 void AudioManagerPulse::GetAudioInputDeviceNames( |
| 91 media::AudioDeviceNames* device_names) { | 85 AudioDeviceNames* device_names) { |
| 92 DCHECK(device_names->empty()); | 86 DCHECK(device_names->empty()); |
| 93 DCHECK(input_mainloop_); | 87 DCHECK(input_mainloop_); |
| 94 DCHECK(input_context_); | 88 DCHECK(input_context_); |
| 95 AutoPulseLock auto_lock(input_mainloop_); | 89 AutoPulseLock auto_lock(input_mainloop_); |
| 96 devices_ = device_names; | 90 devices_ = device_names; |
| 97 pa_operation* operation = pa_context_get_source_info_list( | 91 pa_operation* operation = pa_context_get_source_info_list( |
| 98 input_context_, InputDevicesInfoCallback, this); | 92 input_context_, InputDevicesInfoCallback, this); |
| 99 WaitForOperationCompletion(input_mainloop_, operation); | 93 WaitForOperationCompletion(input_mainloop_, operation); |
| 100 | 94 |
| 101 // Append the default device on the top of the list if the list is not empty. | 95 // Append the default device on the top of the list if the list is not empty. |
| 102 if (!device_names->empty()) { | 96 if (!device_names->empty()) { |
| 103 device_names->push_front( | 97 device_names->push_front( |
| 104 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, | 98 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, |
| 105 AudioManagerBase::kDefaultDeviceId)); | 99 AudioManagerBase::kDefaultDeviceId)); |
| 106 } | 100 } |
| 107 } | 101 } |
| 108 | 102 |
| 103 void AudioManagerPulse::GetAudioOutputDeviceNames( | |
| 104 AudioDeviceNames* device_names) { | |
| 105 DCHECK(device_names); | |
| 106 DCHECK(input_mainloop_); | |
| 107 DCHECK(input_context_); | |
| 108 AutoPulseLock auto_lock(input_mainloop_); | |
| 109 devices_ = device_names; | |
| 110 pa_operation* operation = pa_context_get_sink_info_list( | |
| 111 input_context_, OutputDevicesInfoCallback, this); | |
| 112 WaitForOperationCompletion(input_mainloop_, operation); | |
|
tommi (sloooow) - chröme
2013/09/03 15:57:15
I think we should also add the default device when
Jói
2013/09/04 09:11:04
Done.
| |
| 113 } | |
| 114 | |
| 109 AudioParameters AudioManagerPulse::GetInputStreamParameters( | 115 AudioParameters AudioManagerPulse::GetInputStreamParameters( |
| 110 const std::string& device_id) { | 116 const std::string& device_id) { |
| 111 static const int kDefaultInputBufferSize = 1024; | 117 static const int kDefaultInputBufferSize = 1024; |
| 112 | 118 |
| 113 // TODO(xians): add support for querying native channel layout for pulse. | 119 // TODO(xians): add support for querying native channel layout for pulse. |
| 114 return AudioParameters( | 120 return AudioParameters( |
| 115 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 121 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 116 GetNativeSampleRate(), 16, kDefaultInputBufferSize); | 122 GetNativeSampleRate(), 16, kDefaultInputBufferSize); |
| 117 } | 123 } |
| 118 | 124 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 285 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
| 280 | 286 |
| 281 if (error) { | 287 if (error) { |
| 282 // Signal the pulse object that it is done. | 288 // Signal the pulse object that it is done. |
| 283 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 289 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
| 284 return; | 290 return; |
| 285 } | 291 } |
| 286 | 292 |
| 287 // Exclude the output devices. | 293 // Exclude the output devices. |
| 288 if (info->monitor_of_sink == PA_INVALID_INDEX) { | 294 if (info->monitor_of_sink == PA_INVALID_INDEX) { |
| 289 manager->devices_->push_back(media::AudioDeviceName(info->description, | 295 manager->devices_->push_back(AudioDeviceName(info->description, |
| 290 info->name)); | 296 info->name)); |
| 291 } | 297 } |
| 292 } | 298 } |
| 293 | 299 |
| 294 void AudioManagerPulse::OutputDevicesInfoCallback(pa_context* context, | 300 void AudioManagerPulse::OutputDevicesInfoCallback(pa_context* context, |
| 295 const pa_sink_info* info, | 301 const pa_sink_info* info, |
| 296 int error, void *user_data) { | 302 int error, void *user_data) { |
| 297 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 303 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
| 298 | 304 |
| 299 if (error) { | 305 if (error) { |
| 300 // Signal the pulse object that it is done. | 306 // Signal the pulse object that it is done. |
| 301 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 307 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
| 302 return; | 308 return; |
| 303 } | 309 } |
| 304 | 310 |
| 305 manager->devices_->push_back(media::AudioDeviceName(info->description, | 311 manager->devices_->push_back(AudioDeviceName(info->description, |
| 306 info->name)); | 312 info->name)); |
| 307 } | 313 } |
| 308 | 314 |
| 309 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, | 315 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, |
| 310 const pa_server_info* info, | 316 const pa_server_info* info, |
| 311 void* user_data) { | 317 void* user_data) { |
| 312 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 318 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
| 313 | 319 |
| 314 manager->native_input_sample_rate_ = info->sample_spec.rate; | 320 manager->native_input_sample_rate_ = info->sample_spec.rate; |
| 315 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 321 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
| 316 } | 322 } |
| 317 | 323 |
| 318 } // namespace media | 324 } // namespace media |
| OLD | NEW |