47typedef std::shared_ptr<pa_glib_mainloop> MainLoopPtr;
48MainLoopPtr make_main_loop()
52 pa_glib_mainloop_new(g_main_context_default()),
53 [](pa_glib_mainloop *ml)
55 pa_glib_mainloop_free(ml);
60typedef std::shared_ptr<pa_context> ContextPtr;
61ContextPtr make_context(MainLoopPtr main_loop)
65 pa_context_new(pa_glib_mainloop_get_api(main_loop.get()),
"MediaHubPulseContext"),
70void set_state_callback(ContextPtr ctxt, pa_context_notify_cb_t cb,
void* cookie)
72 pa_context_set_state_callback(ctxt.get(), cb, cookie);
75void set_subscribe_callback(ContextPtr ctxt, pa_context_subscribe_cb_t cb,
void* cookie)
77 pa_context_set_subscribe_callback(ctxt.get(), cb, cookie);
80void throw_if_not_connected(ContextPtr ctxt)
82 if (pa_context_get_state(ctxt.get()) != PA_CONTEXT_READY )
throw std::logic_error
84 "Attempted to issue a call against pulseaudio via a non-connected context."
88void get_server_info_async(ContextPtr ctxt, pa_server_info_cb_t cb,
void* cookie)
90 throw_if_not_connected(ctxt);
91 pa_operation_unref(pa_context_get_server_info(ctxt.get(), cb, cookie));
94void subscribe_to_events(ContextPtr ctxt, pa_subscription_mask mask)
96 throw_if_not_connected(ctxt);
97 pa_operation_unref(pa_context_subscribe(ctxt.get(), mask,
nullptr,
nullptr));
100void get_index_of_sink_by_name_async(ContextPtr ctxt,
const QString &name, pa_sink_info_cb_t cb,
void* cookie)
102 throw_if_not_connected(ctxt);
103 pa_operation_unref(pa_context_get_sink_info_by_name(ctxt.get(), qUtf8Printable(name), cb, cookie));
106void get_sink_info_by_index_async(ContextPtr ctxt, std::int32_t index, pa_sink_info_cb_t cb,
void* cookie)
108 throw_if_not_connected(ctxt);
109 pa_operation_unref(pa_context_get_sink_info_by_index(ctxt.get(), index, cb, cookie));
112void connect_async(ContextPtr ctxt)
114 pa_context_connect(ctxt.get(),
nullptr,
static_cast<pa_context_flags_t
>(PA_CONTEXT_NOAUTOSPAWN | PA_CONTEXT_NOFAIL),
nullptr);
117bool is_port_available_on_sink(
const pa_sink_info* info,
const QRegularExpression& port_pattern)
122 for (std::uint32_t i = 0; i < info->n_ports; i++)
124 if (info->ports[i]->available == PA_PORT_AVAILABLE_NO ||
125 info->ports[i]->available == PA_PORT_AVAILABLE_UNKNOWN)
128 if (port_pattern.match(QString(info->ports[i]->name)).hasMatch())