 Chromium Code Reviews
 Chromium Code Reviews Issue 2258143002:
  Add GetAssociatedOutputDeviceID support to pulse.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2258143002:
  Add GetAssociatedOutputDeviceID support to pulse.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pulse_util.h" | 5 #include "media/audio/pulse/pulse_util.h" | 
| 6 | 6 | 
| 7 #include <stdint.h> | 7 #include <stdint.h> | 
| 8 | 8 | 
| 9 #include "base/logging.h" | 9 #include "base/logging.h" | 
| 10 #include "base/macros.h" | 10 #include "base/macros.h" | 
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" | 
| 12 #include "media/audio/audio_device_description.h" | 12 #include "media/audio/audio_device_description.h" | 
| 13 #include "media/base/audio_parameters.h" | 13 #include "media/base/audio_parameters.h" | 
| 14 | 14 | 
| 15 int strcmp(const char* s1, const char* s2); | |
| 16 | |
| 15 namespace media { | 17 namespace media { | 
| 16 | 18 | 
| 17 namespace pulse { | 19 namespace pulse { | 
| 18 | 20 | 
| 19 namespace { | 21 namespace { | 
| 20 | 22 | 
| 21 #if defined(GOOGLE_CHROME_BUILD) | 23 #if defined(GOOGLE_CHROME_BUILD) | 
| 22 static const char kBrowserDisplayName[] = "google-chrome"; | 24 static const char kBrowserDisplayName[] = "google-chrome"; | 
| 23 #else | 25 #else | 
| 24 static const char kBrowserDisplayName[] = "chromium-browser"; | 26 static const char kBrowserDisplayName[] = "chromium-browser"; | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 ScopedPropertyList() : property_list_(pa_proplist_new()) {} | 63 ScopedPropertyList() : property_list_(pa_proplist_new()) {} | 
| 62 ~ScopedPropertyList() { pa_proplist_free(property_list_); } | 64 ~ScopedPropertyList() { pa_proplist_free(property_list_); } | 
| 63 | 65 | 
| 64 pa_proplist* get() const { return property_list_; } | 66 pa_proplist* get() const { return property_list_; } | 
| 65 | 67 | 
| 66 private: | 68 private: | 
| 67 pa_proplist* property_list_; | 69 pa_proplist* property_list_; | 
| 68 DISALLOW_COPY_AND_ASSIGN(ScopedPropertyList); | 70 DISALLOW_COPY_AND_ASSIGN(ScopedPropertyList); | 
| 69 }; | 71 }; | 
| 70 | 72 | 
| 73 struct InputBusData { | |
| 74 InputBusData(pa_threaded_mainloop* loop, const std::string& name) | |
| 75 : loop_(loop), name_(name), bus_() {} | |
| 76 | |
| 77 pa_threaded_mainloop* loop_; | |
| 78 const std::string& name_; | |
| 79 std::string bus_; | |
| 80 }; | |
| 81 | |
| 82 struct OutputBusData { | |
| 83 OutputBusData(pa_threaded_mainloop* loop, const std::string& bus) | |
| 84 : loop_(loop), name_(), bus_(bus) {} | |
| 85 | |
| 86 pa_threaded_mainloop* loop_; | |
| 87 std::string name_; | |
| 88 const std::string& bus_; | |
| 89 }; | |
| 90 | |
| 91 void InputBusCallback(pa_context* context, | |
| 92 const pa_source_info* info, | |
| 93 int error, | |
| 94 void* user_data) { | |
| 95 InputBusData* data = reinterpret_cast<InputBusData*>(user_data); | |
| 96 | |
| 97 if (error) { | |
| 98 // We have checked all the devices now. | |
| 99 pa_threaded_mainloop_signal(data->loop_, 0); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 if (strcmp(info->name, data->name_.c_str()) == 0 && | |
| 104 pa_proplist_contains(info->proplist, PA_PROP_DEVICE_BUS)) { | |
| 105 data->bus_ = pa_proplist_gets(info->proplist, PA_PROP_DEVICE_BUS); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 void OutputBusCallback(pa_context* context, | |
| 110 const pa_sink_info* info, | |
| 111 int error, | |
| 112 void* user_data) { | |
| 113 OutputBusData* data = reinterpret_cast<OutputBusData*>(user_data); | |
| 114 | |
| 115 if (error) { | |
| 116 // We have checked all the devices now. | |
| 117 pa_threaded_mainloop_signal(data->loop_, 0); | |
| 118 return; | |
| 119 } | |
| 120 | |
| 121 if (pa_proplist_contains(info->proplist, PA_PROP_DEVICE_BUS) && | |
| 122 strcmp(pa_proplist_gets(info->proplist, PA_PROP_DEVICE_BUS), | |
| 123 data->bus_.c_str()) == 0) { | |
| 124 data->name_ = info->name; | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 struct DefaultDevicesData { | |
| 129 std::string input_; | |
| 130 std::string output_; | |
| 131 pa_threaded_mainloop* loop_; | |
| 132 }; | |
| 133 | |
| 134 void GetDefaultDeviceIdCallback(pa_context* c, | |
| 135 const pa_server_info* info, | |
| 136 void* userdata) { | |
| 137 DefaultDevicesData* data = reinterpret_cast<DefaultDevicesData*>(userdata); | |
| 138 data->input_ = info->default_source_name; | |
| 139 data->output_ = info->default_sink_name; | |
| 140 pa_threaded_mainloop_signal(data->loop_, 0); | |
| 141 } | |
| 71 } // namespace | 142 } // namespace | 
| 72 | 143 | 
| 73 // static, pa_stream_success_cb_t | 144 // static, pa_stream_success_cb_t | 
| 74 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop) { | 145 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop) { | 
| 75 pa_threaded_mainloop* pa_mainloop = | 146 pa_threaded_mainloop* pa_mainloop = | 
| 76 static_cast<pa_threaded_mainloop*>(mainloop); | 147 static_cast<pa_threaded_mainloop*>(mainloop); | 
| 77 pa_threaded_mainloop_signal(pa_mainloop, 0); | 148 pa_threaded_mainloop_signal(pa_mainloop, 0); | 
| 78 } | 149 } | 
| 79 | 150 | 
| 80 // |pa_context| and |pa_stream| state changed cb. | 151 // |pa_context| and |pa_stream| state changed cb. | 
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 RETURN_ON_FAILURE( | 419 RETURN_ON_FAILURE( | 
| 349 PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state"); | 420 PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state"); | 
| 350 if (stream_state == PA_STREAM_READY) | 421 if (stream_state == PA_STREAM_READY) | 
| 351 break; | 422 break; | 
| 352 pa_threaded_mainloop_wait(*mainloop); | 423 pa_threaded_mainloop_wait(*mainloop); | 
| 353 } | 424 } | 
| 354 | 425 | 
| 355 return true; | 426 return true; | 
| 356 } | 427 } | 
| 357 | 428 | 
| 429 std::string GetBusOfInput(pa_threaded_mainloop* mainloop, | |
| 430 pa_context* context, | |
| 431 const std::string& name) { | |
| 432 DCHECK(mainloop); | |
| 433 DCHECK(context); | |
| 434 AutoPulseLock auto_lock(mainloop); | |
| 435 InputBusData data(mainloop, name); | |
| 436 pa_operation* operation = | |
| 437 pa_context_get_source_info_list(context, InputBusCallback, &data); | |
| 438 WaitForOperationCompletion(mainloop, operation); | |
| 439 return data.bus_; | |
| 440 } | |
| 441 | |
| 442 std::string GetOutputCorrespondingTo(pa_threaded_mainloop* mainloop, | |
| 443 pa_context* context, | |
| 444 const std::string& bus) { | |
| 445 DCHECK(mainloop); | |
| 446 DCHECK(context); | |
| 447 AutoPulseLock auto_lock(mainloop); | |
| 448 OutputBusData data(mainloop, bus); | |
| 449 pa_operation* operation = | |
| 450 pa_context_get_sink_info_list(context, OutputBusCallback, &data); | |
| 451 WaitForOperationCompletion(mainloop, operation); | |
| 452 return data.name_; | |
| 453 } | |
| 454 | |
| 455 std::string GetRealDefaultDeviceId(pa_threaded_mainloop* mainloop, | |
| 456 pa_context* context, | |
| 457 bool input) { | |
| 
Guido Urdaneta
2016/08/29 10:31:12
Is it possible to use an enum instead of bool?
 
Max Morin
2016/08/29 11:54:02
Done.
 | |
| 458 DefaultDevicesData data; | |
| 459 data.loop_ = mainloop; | |
| 460 pa_operation* op = | |
| 461 pa_context_get_server_info(context, &GetDefaultDeviceIdCallback, &data); | |
| 462 WaitForOperationCompletion(mainloop, op); | |
| 463 if (input) { | |
| 464 return data.input_; | |
| 465 } | |
| 466 return data.output_; | |
| 467 } | |
| 468 | |
| 358 #undef RETURN_ON_FAILURE | 469 #undef RETURN_ON_FAILURE | 
| 359 | 470 | 
| 360 } // namespace pulse | 471 } // namespace pulse | 
| 361 | 472 | 
| 362 } // namespace media | 473 } // namespace media | 
| OLD | NEW |