Loading...
Searching...
No Matches
PipewireSharedContext.hpp
1#pragma once
2
3#include <libremidi/backends/linux/pipewire/context.hpp>
4
5#include <QDebug>
6
7#include <memory>
8
9namespace Gfx::PipeWire
10{
11
12using SharedPipewireContext = std::shared_ptr<libremidi::pipewire::context>;
13
26inline SharedPipewireContext acquireSharedContext(const char* who) noexcept
27{
28 using connection_state = libremidi::pipewire::connection_state;
29
30 auto ctx = libremidi::pipewire::shared_context();
31 if(!ctx)
32 return {};
33
34 if(ctx->state() == connection_state::broken)
35 {
36 if(ctx.use_count() == 1)
37 {
38 ctx->reconnect();
39 }
40 else
41 {
42 qWarning() << who
43 << ": shared PipeWire connection is flagged broken but is "
44 "still held by"
45 << (ctx.use_count() - 1)
46 << "other client(s) with live streams on it; reusing it "
47 "instead of tearing it down";
48 }
49 }
50
51 if(!ctx->ok() && !(ctx->pw_core_ptr() && ctx->thread_loop_handle()))
52 return {};
53
54 return ctx;
55}
56
57}