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::GetAudioDeviceNames( |
91 media::AudioDeviceNames* device_names) { | 85 bool input, media::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 = NULL; |
| 92 if (input) { |
| 93 operation = pa_context_get_source_info_list( |
98 input_context_, InputDevicesInfoCallback, this); | 94 input_context_, InputDevicesInfoCallback, this); |
| 95 } else { |
| 96 operation = pa_context_get_sink_info_list( |
| 97 input_context_, OutputDevicesInfoCallback, this); |
| 98 } |
99 WaitForOperationCompletion(input_mainloop_, operation); | 99 WaitForOperationCompletion(input_mainloop_, operation); |
100 | 100 |
101 // Append the default device on the top of the list if the list is not empty. | 101 // Prepend the default device if the list is not empty. |
102 if (!device_names->empty()) { | 102 if (!device_names->empty()) { |
103 device_names->push_front( | 103 device_names->push_front( |
104 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, | 104 AudioDeviceName(AudioManagerBase::kDefaultDeviceName, |
105 AudioManagerBase::kDefaultDeviceId)); | 105 AudioManagerBase::kDefaultDeviceId)); |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
| 109 void AudioManagerPulse::GetAudioInputDeviceNames( |
| 110 AudioDeviceNames* device_names) { |
| 111 GetAudioDeviceNames(true, device_names); |
| 112 } |
| 113 |
| 114 void AudioManagerPulse::GetAudioOutputDeviceNames( |
| 115 AudioDeviceNames* device_names) { |
| 116 GetAudioDeviceNames(false, device_names); |
| 117 } |
| 118 |
109 AudioParameters AudioManagerPulse::GetInputStreamParameters( | 119 AudioParameters AudioManagerPulse::GetInputStreamParameters( |
110 const std::string& device_id) { | 120 const std::string& device_id) { |
111 static const int kDefaultInputBufferSize = 1024; | 121 static const int kDefaultInputBufferSize = 1024; |
112 | 122 |
113 // TODO(xians): add support for querying native channel layout for pulse. | 123 // TODO(xians): add support for querying native channel layout for pulse. |
114 return AudioParameters( | 124 return AudioParameters( |
115 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 125 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
116 GetNativeSampleRate(), 16, kDefaultInputBufferSize); | 126 GetNativeSampleRate(), 16, kDefaultInputBufferSize); |
117 } | 127 } |
118 | 128 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 295 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
286 | 296 |
287 if (error) { | 297 if (error) { |
288 // Signal the pulse object that it is done. | 298 // Signal the pulse object that it is done. |
289 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 299 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
290 return; | 300 return; |
291 } | 301 } |
292 | 302 |
293 // Exclude the output devices. | 303 // Exclude the output devices. |
294 if (info->monitor_of_sink == PA_INVALID_INDEX) { | 304 if (info->monitor_of_sink == PA_INVALID_INDEX) { |
295 manager->devices_->push_back(media::AudioDeviceName(info->description, | 305 manager->devices_->push_back(AudioDeviceName(info->description, |
296 info->name)); | 306 info->name)); |
297 } | 307 } |
298 } | 308 } |
299 | 309 |
300 void AudioManagerPulse::OutputDevicesInfoCallback(pa_context* context, | 310 void AudioManagerPulse::OutputDevicesInfoCallback(pa_context* context, |
301 const pa_sink_info* info, | 311 const pa_sink_info* info, |
302 int error, void *user_data) { | 312 int error, void *user_data) { |
303 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 313 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
304 | 314 |
305 if (error) { | 315 if (error) { |
306 // Signal the pulse object that it is done. | 316 // Signal the pulse object that it is done. |
307 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 317 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
308 return; | 318 return; |
309 } | 319 } |
310 | 320 |
311 manager->devices_->push_back(media::AudioDeviceName(info->description, | 321 manager->devices_->push_back(AudioDeviceName(info->description, |
312 info->name)); | 322 info->name)); |
313 } | 323 } |
314 | 324 |
315 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, | 325 void AudioManagerPulse::SampleRateInfoCallback(pa_context* context, |
316 const pa_server_info* info, | 326 const pa_server_info* info, |
317 void* user_data) { | 327 void* user_data) { |
318 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); | 328 AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data); |
319 | 329 |
320 manager->native_input_sample_rate_ = info->sample_spec.rate; | 330 manager->native_input_sample_rate_ = info->sample_spec.rate; |
321 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); | 331 pa_threaded_mainloop_signal(manager->input_mainloop_, 0); |
322 } | 332 } |
323 | 333 |
324 } // namespace media | 334 } // namespace media |
OLD | NEW |