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 #include <string.h> | |
9 | 8 |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "base/time/time.h" | 11 #include "base/time/time.h" |
13 #include "media/audio/audio_device_description.h" | 12 #include "media/audio/audio_device_description.h" |
14 #include "media/base/audio_parameters.h" | 13 #include "media/base/audio_parameters.h" |
15 | 14 |
16 namespace media { | 15 namespace media { |
17 | 16 |
18 namespace pulse { | 17 namespace pulse { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 ScopedPropertyList() : property_list_(pa_proplist_new()) {} | 61 ScopedPropertyList() : property_list_(pa_proplist_new()) {} |
63 ~ScopedPropertyList() { pa_proplist_free(property_list_); } | 62 ~ScopedPropertyList() { pa_proplist_free(property_list_); } |
64 | 63 |
65 pa_proplist* get() const { return property_list_; } | 64 pa_proplist* get() const { return property_list_; } |
66 | 65 |
67 private: | 66 private: |
68 pa_proplist* property_list_; | 67 pa_proplist* property_list_; |
69 DISALLOW_COPY_AND_ASSIGN(ScopedPropertyList); | 68 DISALLOW_COPY_AND_ASSIGN(ScopedPropertyList); |
70 }; | 69 }; |
71 | 70 |
72 struct InputBusData { | |
73 InputBusData(pa_threaded_mainloop* loop, const std::string& name) | |
74 : loop_(loop), name_(name), bus_() {} | |
75 | |
76 pa_threaded_mainloop* const loop_; | |
77 const std::string& name_; | |
78 std::string bus_; | |
79 }; | |
80 | |
81 struct OutputBusData { | |
82 OutputBusData(pa_threaded_mainloop* loop, const std::string& bus) | |
83 : loop_(loop), name_(), bus_(bus) {} | |
84 | |
85 pa_threaded_mainloop* const loop_; | |
86 std::string name_; | |
87 const std::string& bus_; | |
88 }; | |
89 | |
90 void InputBusCallback(pa_context* context, | |
91 const pa_source_info* info, | |
92 int error, | |
93 void* user_data) { | |
94 InputBusData* data = static_cast<InputBusData*>(user_data); | |
95 | |
96 if (error) { | |
97 // We have checked all the devices now. | |
98 pa_threaded_mainloop_signal(data->loop_, 0); | |
99 return; | |
100 } | |
101 | |
102 if (strcmp(info->name, data->name_.c_str()) == 0 && | |
103 pa_proplist_contains(info->proplist, PA_PROP_DEVICE_BUS)) { | |
104 data->bus_ = pa_proplist_gets(info->proplist, PA_PROP_DEVICE_BUS); | |
105 } | |
106 } | |
107 | |
108 void OutputBusCallback(pa_context* context, | |
109 const pa_sink_info* info, | |
110 int error, | |
111 void* user_data) { | |
112 OutputBusData* data = static_cast<OutputBusData*>(user_data); | |
113 | |
114 if (error) { | |
115 // We have checked all the devices now. | |
116 pa_threaded_mainloop_signal(data->loop_, 0); | |
117 return; | |
118 } | |
119 | |
120 if (pa_proplist_contains(info->proplist, PA_PROP_DEVICE_BUS) && | |
121 strcmp(pa_proplist_gets(info->proplist, PA_PROP_DEVICE_BUS), | |
122 data->bus_.c_str()) == 0) { | |
123 data->name_ = info->name; | |
124 } | |
125 } | |
126 | |
127 struct DefaultDevicesData { | |
128 DefaultDevicesData(pa_threaded_mainloop* loop) : loop_(loop) {} | |
129 std::string input_; | |
130 std::string output_; | |
131 pa_threaded_mainloop* const loop_; | |
132 }; | |
133 | |
134 void GetDefaultDeviceIdCallback(pa_context* c, | |
135 const pa_server_info* info, | |
136 void* userdata) { | |
137 DefaultDevicesData* data = static_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 } | |
142 } // namespace | 71 } // namespace |
143 | 72 |
144 // static, pa_stream_success_cb_t | 73 // static, pa_stream_success_cb_t |
145 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop) { | 74 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop) { |
146 pa_threaded_mainloop* pa_mainloop = | 75 pa_threaded_mainloop* pa_mainloop = |
147 static_cast<pa_threaded_mainloop*>(mainloop); | 76 static_cast<pa_threaded_mainloop*>(mainloop); |
148 pa_threaded_mainloop_signal(pa_mainloop, 0); | 77 pa_threaded_mainloop_signal(pa_mainloop, 0); |
149 } | 78 } |
150 | 79 |
151 // |pa_context| and |pa_stream| state changed cb. | 80 // |pa_context| and |pa_stream| state changed cb. |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 RETURN_ON_FAILURE( | 348 RETURN_ON_FAILURE( |
420 PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state"); | 349 PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state"); |
421 if (stream_state == PA_STREAM_READY) | 350 if (stream_state == PA_STREAM_READY) |
422 break; | 351 break; |
423 pa_threaded_mainloop_wait(*mainloop); | 352 pa_threaded_mainloop_wait(*mainloop); |
424 } | 353 } |
425 | 354 |
426 return true; | 355 return true; |
427 } | 356 } |
428 | 357 |
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 RequestType type) { | |
458 DefaultDevicesData data(mainloop); | |
459 pa_operation* op = | |
460 pa_context_get_server_info(context, &GetDefaultDeviceIdCallback, &data); | |
461 WaitForOperationCompletion(mainloop, op); | |
462 return (type == RequestType::INPUT) ? data.input_ : data.output_; | |
463 } | |
464 | |
465 #undef RETURN_ON_FAILURE | 358 #undef RETURN_ON_FAILURE |
466 | 359 |
467 } // namespace pulse | 360 } // namespace pulse |
468 | 361 |
469 } // namespace media | 362 } // namespace media |
OLD | NEW |