Chromium Code Reviews| Index: media/audio/pulse/pulse_util.cc |
| diff --git a/media/audio/pulse/pulse_util.cc b/media/audio/pulse/pulse_util.cc |
| index 5044fa4d26eb4ab76dce0811433a8fb11d298299..7363f06b349d263d6fafff5fdec7d80a0b61cbb3 100644 |
| --- a/media/audio/pulse/pulse_util.cc |
| +++ b/media/audio/pulse/pulse_util.cc |
| @@ -161,6 +161,31 @@ int GetHardwareLatencyInBytes(pa_stream* stream, |
| } \ |
| } while (0) |
| +static std::string system_default_input_device; |
| +static std::string system_default_output_device; |
| + |
| +void SystemDefaultDeviceCallback(pa_context* context, |
|
Henrik Grunell
2016/02/23 11:13:24
Put these functions in the anonymous namespace abo
Henrik Grunell
2016/02/23 11:13:24
Add comments with brief description for these two
rchtara
2016/02/23 14:58:51
Done.
rchtara
2016/02/23 14:58:51
I changed the cl architecture to use stream object
|
| + const pa_server_info* info, |
| + void* mainloop) { |
| + |
| + system_default_input_device = info->default_source_name; |
|
Henrik Grunell
2016/02/23 11:13:24
Store the system default device names in the strea
rchtara
2016/02/23 14:58:51
Done
|
| + system_default_output_device = info->default_sink_name; |
| + pa_threaded_mainloop* pa_mainloop = |
| + static_cast<pa_threaded_mainloop*>(mainloop); |
| + pa_threaded_mainloop_signal(pa_mainloop, 0); |
| +} |
| + |
| +void GetSystemDefaultDevice(pa_threaded_mainloop* mainloop, |
| + pa_context* context) { |
| + DCHECK(mainloop); |
| + DCHECK(context); |
| + |
| + pa_operation* operation = pa_context_get_server_info( |
| + context, SystemDefaultDeviceCallback, mainloop); |
| + |
| + WaitForOperationCompletion(mainloop, operation); |
| +} |
| + |
| bool CreateInputStream(pa_threaded_mainloop* mainloop, |
| pa_context* context, |
| pa_stream** stream, |
| @@ -206,15 +231,19 @@ bool CreateInputStream(pa_threaded_mainloop* mainloop, |
| buffer_attributes.minreq = buffer_size; |
| buffer_attributes.prebuf = static_cast<uint32_t>(-1); |
| buffer_attributes.fragsize = buffer_size; |
| + |
| int flags = PA_STREAM_AUTO_TIMING_UPDATE | |
| PA_STREAM_INTERPOLATE_TIMING | |
| PA_STREAM_ADJUST_LATENCY | |
| PA_STREAM_START_CORKED; |
| + |
| + GetSystemDefaultDevice(mainloop, context); |
| + |
| RETURN_ON_FAILURE( |
| pa_stream_connect_record( |
| *stream, |
| device_id == AudioManagerBase::kDefaultDeviceId ? |
| - NULL : device_id.c_str(), |
| + system_default_input_device.c_str() : device_id.c_str(), |
| &buffer_attributes, |
| static_cast<pa_stream_flags_t>(flags)) == 0, |
| "pa_stream_connect_record FAILED "); |
| @@ -327,6 +356,8 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop, |
| pa_buffer_attributes.tlength = params.GetBytesPerBuffer() * 3; |
| pa_buffer_attributes.fragsize = static_cast<uint32_t>(-1); |
| + GetSystemDefaultDevice(*mainloop, *context); |
| + |
| // Connect playback stream. Like pa_buffer_attr, the pa_stream_flags have a |
| // huge impact on the performance of the stream and were chosen through trial |
| // and error. |
| @@ -334,7 +365,7 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop, |
| pa_stream_connect_playback( |
| *stream, |
| device_id == AudioManagerBase::kDefaultDeviceId ? |
| - NULL : device_id.c_str(), |
| + system_default_output_device.c_str() : device_id.c_str(), |
| &pa_buffer_attributes, |
| static_cast<pa_stream_flags_t>( |
| PA_STREAM_INTERPOLATE_TIMING | PA_STREAM_ADJUST_LATENCY | |