Chromium Code Reviews| Index: media/audio/pulse/pulse_input.cc |
| diff --git a/media/audio/pulse/pulse_input.cc b/media/audio/pulse/pulse_input.cc |
| index 8d4aeea2079d201a69e52fb48e4344680c467d70..7d1fde9fe515f747f489d5237a7bb40f5143bb50 100644 |
| --- a/media/audio/pulse/pulse_input.cc |
| +++ b/media/audio/pulse/pulse_input.cc |
| @@ -51,8 +51,15 @@ PulseAudioInputStream::~PulseAudioInputStream() { |
| bool PulseAudioInputStream::Open() { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| AutoPulseLock auto_lock(pa_mainloop_); |
| + std::string device_name_to_use = device_name_; |
| + if (device_name_ == AudioManagerBase::kDefaultDeviceId) { |
| + GetSystemDefaultInputDevice(); |
| + device_name_to_use = default_system_device_name_; |
| + } |
| + |
| if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_, |
| - device_name_, &StreamNotifyCallback, this)) { |
| + device_name_to_use, &StreamNotifyCallback, |
| + this)) { |
| return false; |
| } |
| @@ -268,6 +275,26 @@ void PulseAudioInputStream::StreamNotifyCallback(pa_stream* s, |
| pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); |
| } |
| +// static, used by pa_context_get_server_info. |
| +void PulseAudioInputStream::GetSystemDefaultInputDeviceCallback( |
| + pa_context* context, |
| + const pa_server_info* info, |
| + void* user_data) { |
| + media::PulseAudioInputStream* stream = |
| + reinterpret_cast<media::PulseAudioInputStream*>(user_data); |
|
tommi (sloooow) - chröme
2016/03/16 15:21:47
nit: typically we use static_cast<> for upcasting
rchtara
2016/03/19 12:07:30
Done.
|
| + stream->default_system_device_name_ = info->default_source_name; |
| + pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); |
| +} |
| + |
| +void PulseAudioInputStream::GetSystemDefaultInputDevice() { |
| + DCHECK(pa_mainloop_); |
| + DCHECK(pa_context_); |
| + pa_operation* operation = pa_context_get_server_info( |
| + pa_context_, PulseAudioInputStream::GetSystemDefaultInputDeviceCallback, |
| + this); |
| + WaitForOperationCompletion(pa_mainloop_, operation); |
| +} |
| + |
| void PulseAudioInputStream::ReadData() { |
| uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes( |
| handle_, params_.sample_rate(), params_.GetBytesPerFrame()); |