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..ebefe914f19a4f8cbd4c884684d227a957037e59 100644 |
| --- a/media/audio/pulse/pulse_util.cc |
| +++ b/media/audio/pulse/pulse_util.cc |
| @@ -11,6 +11,8 @@ |
| #include "base/time/time.h" |
| #include "media/audio/audio_manager_base.h" |
| #include "media/audio/audio_parameters.h" |
| +#include "media/audio/pulse/pulse_input.h" |
| +#include "media/base/limits.h" |
| namespace media { |
| @@ -161,6 +163,34 @@ int GetHardwareLatencyInBytes(pa_stream* stream, |
| } \ |
| } while (0) |
| +void SystemDefaultInputDeviceCallback(pa_context* context, |
| + const pa_server_info* info, |
| + void* user_data) { |
| + PulseAudioInputStream* stream = |
| + reinterpret_cast<PulseAudioInputStream*>(user_data); |
| + stream->device_name_ = info->default_source_name; |
|
Henrik Grunell
2016/02/24 15:54:53
This will overwrite the device name provided in th
rchtara
2016/02/25 17:17:26
Done.
|
| + pa_threaded_mainloop* pa_mainloop = |
| + static_cast<pa_threaded_mainloop*>(stream->pa_mainloop_); |
| + pa_threaded_mainloop_signal(pa_mainloop, 0); |
| +} |
| + |
| +std::string GetSystemDefaultInputDevice(pa_threaded_mainloop* mainloop, |
| + pa_context* context) { |
| + DCHECK(mainloop); |
| + DCHECK(context); |
| + AudioParameters params(AudioParameters::Format::AUDIO_PCM_LINEAR, |
| + ChannelLayout::CHANNEL_LAYOUT_MONO, |
| + limits::kMinSampleRate, limits::kMaxBitsPerSample, |
| + limits::kMaxSamplesPerPacket); |
| + |
| + PulseAudioInputStream stream(NULL, "", params, mainloop, context); |
| + |
| + pa_operation* operation = pa_context_get_server_info( |
| + context, SystemDefaultInputDeviceCallback, &stream); |
| + WaitForOperationCompletion(mainloop, operation); |
| + return stream.device_name_; |
| +} |
| + |
| bool CreateInputStream(pa_threaded_mainloop* mainloop, |
| pa_context* context, |
| pa_stream** stream, |
| @@ -206,17 +236,21 @@ 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; |
| + |
| + std::string system_default_input_device = |
| + GetSystemDefaultInputDevice(mainloop, context); |
| + |
| RETURN_ON_FAILURE( |
| pa_stream_connect_record( |
| - *stream, |
| - device_id == AudioManagerBase::kDefaultDeviceId ? |
| - NULL : device_id.c_str(), |
| - &buffer_attributes, |
| - static_cast<pa_stream_flags_t>(flags)) == 0, |
| + *stream, device_id == AudioManagerBase::kDefaultDeviceId |
|
Henrik Grunell
2016/02/24 15:54:52
Then here, always use |device_id|.
And below for
rchtara
2016/02/25 17:17:26
Done.
rchtara
2016/02/25 17:17:26
Done.
|
| + ? 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 "); |
| // Wait for the stream to be ready. |
| @@ -232,6 +266,35 @@ bool CreateInputStream(pa_threaded_mainloop* mainloop, |
| return true; |
| } |
| +void SystemDefaultOutputDeviceCallback(pa_context* context, |
| + const pa_server_info* info, |
| + void* user_data) { |
| + PulseAudioInputStream* stream = |
| + reinterpret_cast<PulseAudioInputStream*>(user_data); |
| + stream->device_name_ = info->default_sink_name; |
| + pa_threaded_mainloop* pa_mainloop = |
| + static_cast<pa_threaded_mainloop*>(stream->pa_mainloop_); |
| + pa_threaded_mainloop_signal(pa_mainloop, 0); |
| +} |
| + |
| +std::string GetSystemDefaultOutputDevice(pa_threaded_mainloop* mainloop, |
| + pa_context* context) { |
| + DCHECK(mainloop); |
| + DCHECK(context); |
| + AudioParameters params(AudioParameters::Format::AUDIO_PCM_LINEAR, |
| + ChannelLayout::CHANNEL_LAYOUT_MONO, |
| + limits::kMinSampleRate, limits::kMaxBitsPerSample, |
| + limits::kMaxSamplesPerPacket); |
| + |
| + PulseAudioInputStream stream(NULL, "", params, mainloop, context); |
| + |
| + pa_operation* operation = pa_context_get_server_info( |
| + context, SystemDefaultOutputDeviceCallback, &stream); |
| + WaitForOperationCompletion(mainloop, operation); |
| + DLOG(WARNING) << "Operation is NU" << stream.device_name_; |
| + return stream.device_name_; |
| +} |
| + |
| bool CreateOutputStream(pa_threaded_mainloop** mainloop, |
| pa_context** context, |
| pa_stream** stream, |
| @@ -327,21 +390,23 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop, |
| pa_buffer_attributes.tlength = params.GetBytesPerBuffer() * 3; |
| pa_buffer_attributes.fragsize = static_cast<uint32_t>(-1); |
| + std::string system_default_output_device = |
| + GetSystemDefaultOutputDevice(*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. |
| RETURN_ON_FAILURE( |
| pa_stream_connect_playback( |
| - *stream, |
| - device_id == AudioManagerBase::kDefaultDeviceId ? |
| - NULL : device_id.c_str(), |
| + *stream, device_id == AudioManagerBase::kDefaultDeviceId |
| + ? 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 | |
| PA_STREAM_AUTO_TIMING_UPDATE | PA_STREAM_NOT_MONOTONIC | |
| PA_STREAM_START_CORKED), |
| - NULL, |
| - NULL) == 0, |
| + NULL, NULL) == 0, |
| "pa_stream_connect_playback FAILED "); |
| // Wait for the stream to be ready. |