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

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: Remove unneeded pulse signatures. Created 4 years, 4 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
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 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
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 }
71 } // namespace 127 } // namespace
72 128
73 // static, pa_stream_success_cb_t 129 // static, pa_stream_success_cb_t
74 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop) { 130 void StreamSuccessCallback(pa_stream* s, int error, void* mainloop) {
75 pa_threaded_mainloop* pa_mainloop = 131 pa_threaded_mainloop* pa_mainloop =
76 static_cast<pa_threaded_mainloop*>(mainloop); 132 static_cast<pa_threaded_mainloop*>(mainloop);
77 pa_threaded_mainloop_signal(pa_mainloop, 0); 133 pa_threaded_mainloop_signal(pa_mainloop, 0);
78 } 134 }
79 135
80 // |pa_context| and |pa_stream| state changed cb. 136 // |pa_context| and |pa_stream| state changed cb.
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 RETURN_ON_FAILURE( 404 RETURN_ON_FAILURE(
349 PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state"); 405 PA_STREAM_IS_GOOD(stream_state), "Invalid PulseAudio stream state");
350 if (stream_state == PA_STREAM_READY) 406 if (stream_state == PA_STREAM_READY)
351 break; 407 break;
352 pa_threaded_mainloop_wait(*mainloop); 408 pa_threaded_mainloop_wait(*mainloop);
353 } 409 }
354 410
355 return true; 411 return true;
356 } 412 }
357 413
414 std::string GetBusOfInput(const std::string& name,
415 pa_threaded_mainloop* input_mainloop,
416 pa_context* input_context) {
417 DCHECK(input_mainloop);
418 DCHECK(input_context);
419 AutoPulseLock auto_lock(input_mainloop);
420 InputBusData data(input_mainloop, name);
421 pa_operation* operation =
422 pa_context_get_source_info_list(input_context, InputBusCallback, &data);
423 WaitForOperationCompletion(input_mainloop, operation);
424 return data.bus_;
425 }
426
427 std::string GetOutputCorrespondingTo(const std::string& input_bus,
428 pa_threaded_mainloop* input_mainloop,
429 pa_context* input_context) {
430 DCHECK(input_mainloop);
431 DCHECK(input_context);
432 AutoPulseLock auto_lock(input_mainloop);
433 OutputBusData data(input_mainloop, input_bus);
434 pa_operation* operation =
435 pa_context_get_sink_info_list(input_context, OutputBusCallback, &data);
436 WaitForOperationCompletion(input_mainloop, operation);
437 return data.name_;
438 }
439
358 #undef RETURN_ON_FAILURE 440 #undef RETURN_ON_FAILURE
359 441
360 } // namespace pulse 442 } // namespace pulse
361 443
362 } // namespace media 444 } // namespace media
OLDNEW
« media/audio/pulse/audio_manager_pulse.cc ('K') | « media/audio/pulse/pulse_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698