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 <QtMultimedia/qtmultimediaglobal.h>
19#include <QtCore/qdebug.h>
20#include <QtCore/qglobal.h>
21
22#include <chrono>
23#include <memory>
24#include <mutex>
25#include <pipewire/extensions/metadata.h>
26#include <system_error>
27
28#include <pipewire/pipewire.h>
29
30#if !PW_CHECK_VERSION(0, 3, 75)
31extern "C" {
32bool pw_check_library_version(int major, int minor, int micro);
33}
34#endif
35
36QT_BEGIN_NAMESPACE
37
38namespace QtPipeWire {
39
40// errno helper
41inline std::error_code make_error_code(int errnoValue = errno)
42{
43 return std::error_code(errnoValue, std::generic_category());
44}
45
46// unique_ptr utilities
47template <typename BaseType, void(Deleter)(BaseType *), typename Type = BaseType>
49{
50 void operator()(Type *handle) const
51 {
52 BaseType *base = reinterpret_cast<BaseType *>(handle);
53 (Deleter)(base);
54 }
55};
56
57template <typename BaseType, void(Deleter)(BaseType *), typename Type = BaseType>
62
63// unique_ptr for pipewire types
64
74
76{
77 void operator()(pw_core *handle) const
78 {
79 int status = pw_core_disconnect(handle);
80 if (status < 0)
81 qWarning() << "Failed to disconnect pw_core:" << make_error_code(status).message();
82 }
83};
84
86
88{
89 void operator()(spa_handle *handle) const
90 {
91 int status = pw_unload_spa_handle(handle);
92 if (status < 0)
93 qWarning() << "Failed to unload spa_handle:" << make_error_code(-status).message();
94 }
95};
96
97using SpaHandleHandle = std::unique_ptr<spa_handle, SpaHandleDeleter>;
98
99class Q_MULTIMEDIA_EXPORT PWThreadedEventLoop
100{
101public:
102 explicit PWThreadedEventLoop(const char *name);
104
106
107 explicit operator bool() const;
108
109 int start();
110 void stop();
111
112 pw_thread_loop *get() const;
113 pw_loop *loop() const;
114
115 bool isInThread() const;
116
117 void lock();
118 void unlock();
119
121 void signal(bool waitForAccept);
122
123 template <typename Closure>
125 {
126 std::lock_guard guard{ *this };
127 return c();
128 }
129
130private:
132};
133
134// strong id types
135
136template <typename T, typename Tag>
138{
139 explicit StrongIdType(T arg) : value{ arg } { }
140
142 friend QDebug operator<<(QDebug dbg, const StrongIdType &self) { return dbg << self.value; }
143
144#ifdef __cpp_impl_three_way_comparison
145 auto operator<=>(const StrongIdType &) const = default;
146#else
147 friend bool comparesEqual(const StrongIdType &lhs, const StrongIdType &rhs) noexcept
148 {
149 return lhs.value == rhs.value;
150 }
151
153 const StrongIdType &rhs) noexcept
154 {
155 return qCompareThreeWay(lhs.value, rhs.value);
156 }
157
159#endif
160};
161
163{
164};
165
166// PW_KEY_OBJECT_ID
167// global object ID, can be reused
169
171{
172};
173
174// PW_KEY_OBJECT_SERIAL
175// unique serial for each object
177
178} // namespace QtPipeWire
179
180// debug support
181QDebug operator<<(QDebug dbg, const spa_dict &dict);
182QDebug operator<<(QDebug dbg, const spa_pod &pod);
183QDebug operator<<(QDebug dbg, enum pw_stream_state);
184QDebug operator<<(QDebug dbg, const pw_time &state);
185
186// Address sanitizer helper
187// for now these annotations only function as documentation
188#define QT_MM_GUARDED_BY(Mutex)
189
190QT_END_NAMESPACE
191
192#endif // QPIPEWIRE_SUPPORT_P_H
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