Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: media/audio/pulse/pulse_util.cc

Issue 2258143002: Add GetAssociatedOutputDeviceID support to pulse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tommis comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/pulse/pulse_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "media/audio/audio_device_description.h" 13 #include "media/audio/audio_device_description.h"
13 #include "media/base/audio_parameters.h" 14 #include "media/base/audio_parameters.h"
14 15
15 namespace media { 16 namespace media {
16 17
17 namespace pulse { 18 namespace pulse {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 ScopedPropertyList() : property_list_(pa_proplist_new()) {} 62 ScopedPropertyList() : property_list_(pa_proplist_new()) {}
62 ~ScopedPropertyList() { pa_proplist_free(property_list_); } 63 ~ScopedPropertyList() { pa_proplist_free(property_list_); }
63 64
64 pa_proplist* get() const { return property_list_; } 65 pa_proplist* get() const { return property_list_; }
65 66
66 private: 67 private:
67 pa_proplist* property_list_; 68 pa_proplist* property_list_;
68 DISALLOW_COPY_AND_ASSIGN(ScopedPropertyList); 69 DISALLOW_COPY_AND_ASSIGN(ScopedPropertyList);
69 }; 70 };
70 71
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 }
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
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 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
358 #undef RETURN_ON_FAILURE 465 #undef RETURN_ON_FAILURE
359 466
360 } // namespace pulse 467 } // namespace pulse
361 468
362 } // namespace media 469 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698