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 d5c699a09e28a821fd1e7107ca1cd6be9858d24a..0595c0ab244501a514dabdbd4e5ccdcb23fccdc1 100644 |
| --- a/media/audio/pulse/pulse_util.cc |
| +++ b/media/audio/pulse/pulse_util.cc |
| @@ -12,6 +12,8 @@ |
| #include "media/audio/audio_device_description.h" |
| #include "media/base/audio_parameters.h" |
| +int strcmp(const char* s1, const char* s2); |
|
tommi (sloooow) - chröme
2016/08/29 13:02:26
any reason not to #include this declaration?
Max Morin
2016/08/29 14:04:22
Done.
|
| + |
| namespace media { |
| namespace pulse { |
| @@ -68,6 +70,75 @@ class ScopedPropertyList { |
| DISALLOW_COPY_AND_ASSIGN(ScopedPropertyList); |
| }; |
| +struct InputBusData { |
| + InputBusData(pa_threaded_mainloop* loop, const std::string& name) |
| + : loop_(loop), name_(name), bus_() {} |
| + |
| + pa_threaded_mainloop* loop_; |
|
tommi (sloooow) - chröme
2016/08/29 13:02:26
const? (as in pa_threaded_mainloop* const loop_;)
Max Morin
2016/08/29 14:04:23
Done.
|
| + const std::string& name_; |
| + std::string bus_; |
| +}; |
| + |
| +struct OutputBusData { |
| + OutputBusData(pa_threaded_mainloop* loop, const std::string& bus) |
| + : loop_(loop), name_(), bus_(bus) {} |
| + |
| + pa_threaded_mainloop* loop_; |
| + std::string name_; |
| + const std::string& bus_; |
| +}; |
| + |
| +void InputBusCallback(pa_context* context, |
| + const pa_source_info* info, |
| + int error, |
| + void* user_data) { |
| + InputBusData* data = reinterpret_cast<InputBusData*>(user_data); |
| + |
| + if (error) { |
| + // We have checked all the devices now. |
| + pa_threaded_mainloop_signal(data->loop_, 0); |
| + return; |
| + } |
| + |
| + if (strcmp(info->name, data->name_.c_str()) == 0 && |
| + pa_proplist_contains(info->proplist, PA_PROP_DEVICE_BUS)) { |
| + data->bus_ = pa_proplist_gets(info->proplist, PA_PROP_DEVICE_BUS); |
| + } |
| +} |
| + |
| +void OutputBusCallback(pa_context* context, |
| + const pa_sink_info* info, |
| + int error, |
| + void* user_data) { |
| + OutputBusData* data = reinterpret_cast<OutputBusData*>(user_data); |
| + |
| + if (error) { |
| + // We have checked all the devices now. |
| + pa_threaded_mainloop_signal(data->loop_, 0); |
| + return; |
| + } |
| + |
| + if (pa_proplist_contains(info->proplist, PA_PROP_DEVICE_BUS) && |
| + strcmp(pa_proplist_gets(info->proplist, PA_PROP_DEVICE_BUS), |
| + data->bus_.c_str()) == 0) { |
| + data->name_ = info->name; |
| + } |
| +} |
| + |
| +struct DefaultDevicesData { |
| + std::string input_; |
| + std::string output_; |
| + pa_threaded_mainloop* loop_; |
| +}; |
| + |
| +void GetDefaultDeviceIdCallback(pa_context* c, |
| + const pa_server_info* info, |
| + void* userdata) { |
| + DefaultDevicesData* data = reinterpret_cast<DefaultDevicesData*>(userdata); |
|
tommi (sloooow) - chröme
2016/08/29 13:02:26
nit: these sort of casts (casting from a void* to
Max Morin
2016/08/29 14:04:23
Done.
|
| + data->input_ = info->default_source_name; |
| + data->output_ = info->default_sink_name; |
| + pa_threaded_mainloop_signal(data->loop_, 0); |
| +} |
| } // namespace |
| // static, pa_stream_success_cb_t |
| @@ -355,6 +426,46 @@ bool CreateOutputStream(pa_threaded_mainloop** mainloop, |
| return true; |
| } |
| +std::string GetBusOfInput(pa_threaded_mainloop* mainloop, |
| + pa_context* context, |
| + const std::string& name) { |
| + DCHECK(mainloop); |
| + DCHECK(context); |
| + AutoPulseLock auto_lock(mainloop); |
| + InputBusData data(mainloop, name); |
| + pa_operation* operation = |
| + pa_context_get_source_info_list(context, InputBusCallback, &data); |
| + WaitForOperationCompletion(mainloop, operation); |
| + return data.bus_; |
| +} |
| + |
| +std::string GetOutputCorrespondingTo(pa_threaded_mainloop* mainloop, |
| + pa_context* context, |
| + const std::string& bus) { |
| + DCHECK(mainloop); |
| + DCHECK(context); |
| + AutoPulseLock auto_lock(mainloop); |
| + OutputBusData data(mainloop, bus); |
| + pa_operation* operation = |
| + pa_context_get_sink_info_list(context, OutputBusCallback, &data); |
| + WaitForOperationCompletion(mainloop, operation); |
| + return data.name_; |
| +} |
| + |
| +std::string GetRealDefaultDeviceId(pa_threaded_mainloop* mainloop, |
| + pa_context* context, |
| + RequestType type) { |
| + DefaultDevicesData data; |
| + data.loop_ = mainloop; |
| + pa_operation* op = |
| + pa_context_get_server_info(context, &GetDefaultDeviceIdCallback, &data); |
| + WaitForOperationCompletion(mainloop, op); |
| + if (type == RequestType::INPUT) { |
|
tommi (sloooow) - chröme
2016/08/29 13:02:26
remove {}
could also do
return type == RequestTy
Max Morin
2016/08/29 14:04:22
Done.
|
| + return data.input_; |
| + } |
| + return data.output_; |
| +} |
| + |
| #undef RETURN_ON_FAILURE |
| } // namespace pulse |