Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpipewire_support_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QPIPEWIRE_SUPPORT_P_H
5#define QPIPEWIRE_SUPPORT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qdebug.h>
19#include <QtCore/qglobal.h>
20
21#include <chrono>
22#include <memory>
23#include <mutex>
24#include <pipewire/extensions/metadata.h>
25#include <system_error>
26
27#include <pipewire/pipewire.h>
28
29#if !PW_CHECK_VERSION(0, 3, 75)
30extern "C" {
31bool pw_check_library_version(int major, int minor, int micro);
32}
33#endif
34
35QT_BEGIN_NAMESPACE
36
37namespace QtPipeWire {
38
39// errno helper
40inline std::error_code make_error_code(int errnoValue = errno)
41{
42 return std::error_code(errnoValue, std::generic_category());
43}
44
45// unique_ptr utilities
46template <typename BaseType, void(Deleter)(BaseType *), typename Type = BaseType>
48{
49 void operator()(Type *handle) const
50 {
51 BaseType *base = reinterpret_cast<BaseType *>(handle);
52 (Deleter)(base);
53 }
54};
55
56template <typename BaseType, void(Deleter)(BaseType *), typename Type = BaseType>
61
62// unique_ptr for pipewire types
63
72
74{
75 void operator()(pw_core *handle) const
76 {
77 int status = pw_core_disconnect(handle);
78 if (status < 0)
79 qWarning() << "Failed to disconnect pw_core:" << make_error_code(status).message();
80 }
81};
82
84
86{
87 void operator()(spa_handle *handle) const
88 {
89 int status = pw_unload_spa_handle(handle);
90 if (status < 0)
91 qWarning() << "Failed to unload spa_handle:" << make_error_code(-status).message();
92 }
93};
94
95using SpaHandleHandle = std::unique_ptr<spa_handle, SpaHandleDeleter>;
96
98{
99public:
100 explicit PWThreadedEventLoop(const char *name);
102
104
105 explicit operator bool() const;
106
107 int start();
108 void stop();
109
110 pw_thread_loop *get() const;
111 pw_loop *loop() const;
112
113 bool isInThread() const;
114
115 void lock();
116 void unlock();
117
118 int wait_for(std::chrono::seconds waitMax);
119 void signal(bool waitForAccept);
120
121 template <typename Closure>
122 auto runWithEventLoopLock(Closure &&c)
123 {
124 std::lock_guard guard{ *this };
125 return c();
126 }
127
128private:
129 PwThreadLoopHandle m_loop;
130};
131
132// strong id types
133
134template <typename T, typename Tag>
136{
137 explicit StrongIdType(T arg) : value{ arg } { }
138
140 friend QDebug operator<<(QDebug dbg, const StrongIdType &self) { return dbg << self.value; }
141
142#ifdef __cpp_impl_three_way_comparison
143 auto operator<=>(const StrongIdType &) const = default;
144#else
145 friend bool comparesEqual(const StrongIdType &lhs, const StrongIdType &rhs) noexcept
146 {
147 return lhs.value == rhs.value;
148 }
149
151 const StrongIdType &rhs) noexcept
152 {
153 return qCompareThreeWay(lhs.value, rhs.value);
154 }
155
157#endif
158};
159
161{
162};
163
164// PW_KEY_OBJECT_ID
165// global object ID, can be reused
167
169{
170};
171
172// PW_KEY_OBJECT_SERIAL
173// unique serial for each object
175
176} // namespace QtPipeWire
177
178// debug support
179QDebug operator<<(QDebug dbg, const spa_dict &dict);
180QDebug operator<<(QDebug dbg, const spa_pod &pod);
181QDebug operator<<(QDebug dbg, enum pw_stream_state);
182QDebug operator<<(QDebug dbg, const pw_time &state);
183
184// Address sanitizer helper
185// for now these annotations only function as documentation
186#define QT_MM_GUARDED_BY(Mutex)
187
188QT_END_NAMESPACE
189
190#endif // QPIPEWIRE_SUPPORT_P_H
int wait_for(std::chrono::seconds waitMax)
void signal(bool waitForAccept)
std::unique_ptr< pw_core, PwCoreConnectionDeleter > PwCoreConnectionHandle
std::unique_ptr< spa_handle, SpaHandleDeleter > SpaHandleHandle
StrongIdType< uint32_t, ObjectIdTag > ObjectId
StrongIdType< uint64_t, ObjectSerialTag > ObjectSerial
std::error_code make_error_code(int errnoValue=errno)
bool pw_check_library_version(int major, int minor, int micro)
QDebug operator<<(QDebug dbg, const pw_time &state)
QT_MM_MAKE_STRING_RESOLVER(pw_stream_state, QtMultimediaPrivate::EnumName,(PW_STREAM_STATE_ERROR, "error")(PW_STREAM_STATE_UNCONNECTED, "unconnected")(PW_STREAM_STATE_CONNECTING, "connecting")(PW_STREAM_STATE_PAUSED, "paused")(PW_STREAM_STATE_STREAMING, "streaming"))
QDebug operator<<(QDebug dbg, const spa_dict &dict)
QDebug operator<<(QDebug dbg, const spa_pod &)
QT_MM_DEFINE_QDEBUG_ENUM(pw_stream_state)
QDebug operator<<(QDebug dbg, enum pw_stream_state)
void operator()(Type *handle) const
void operator()(pw_core *handle) const
void operator()(spa_handle *handle) const
friend QDebug operator<<(QDebug dbg, const StrongIdType &self)
friend bool comparesEqual(const StrongIdType &lhs, const StrongIdType &rhs) noexcept
friend Qt::strong_ordering compareThreeWay(const StrongIdType &lhs, const StrongIdType &rhs) noexcept