source: smplayer/trunk/src/deviceinfo_pulse.cpp@ 188

Last change on this file since 188 was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

File size: 1.8 KB
Line 
1#if USE_PULSEAUDIO_DEVICES
2#include <pulse/context.h>
3#include <pulse/glib-mainloop.h>
4#include <pulse/introspect.h>
5#include <pulse/operation.h>
6#include <QApplication>
7
8QMap<int, QString> pulse_device_list;
9bool pulse_list_done = false;
10
11void sink_cb(pa_context *, const pa_sink_info *i, int eol, void *) {
12 if (eol == 0) {
13 qDebug() << "DeviceInfo::sink_cb: sink #" << i->index << ":" << i->name;
14 pulse_device_list[i->index] = i->name;
15 } else {
16 pulse_list_done = true;
17 }
18}
19
20void context_state_cb(pa_context *c, void *) {
21 qDebug() << "DeviceInfo::context_state_cb";
22
23 pa_context_state_t state = pa_context_get_state(c);
24
25 if (state == PA_CONTEXT_READY) {
26 pa_operation *o;
27
28 if (!(o = pa_context_get_sink_info_list(c, sink_cb, NULL))) {
29 qWarning() << "DeviceInfo::context_state_cb: pa_context_get_sink_info_list failed";
30 return;
31 }
32 pa_operation_unref(o);
33 }
34}
35
36DeviceList DeviceInfo::paDevices() {
37 qDebug("DeviceInfo::paDevices");
38 DeviceList l;
39
40 if (!pulse_list_done) {
41 pa_glib_mainloop *mainloop = pa_glib_mainloop_new(NULL);
42 pa_mainloop_api *api = pa_glib_mainloop_get_api(mainloop);
43 pa_context *context = pa_context_new(api, "smplayer");
44
45 if (pa_context_connect(context, NULL, PA_CONTEXT_NOFAIL, 0) < 0) {
46 pa_context_unref(context);
47 return l;
48 }
49 pa_context_set_state_callback(context, context_state_cb, NULL);
50
51 // Wait for a while until the list is complete
52 for (int n = 0; n < 1000; n++) {
53 QApplication::processEvents();
54 if (pulse_list_done) {
55 qDebug("DeviceInfo::paDevices: list done (%d)", n);
56 break;
57 }
58 }
59 }
60
61 if (!pulse_list_done) {
62 qWarning("DeviceInfo::paDevices: list is not done yet!");
63 }
64
65 QMapIterator<int, QString> i(pulse_device_list);
66 while (i.hasNext()) {
67 i.next();
68 l.append(DeviceData(i.key(), i.value()));
69 }
70
71 return l;
72}
73#endif // USE_PULSEAUDIO_DEVICES
Note: See TracBrowser for help on using the repository browser.