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/qglobal.h>
19#include <QtCore/qdebug.h>
20
21#include <memory>
22#include <pipewire/extensions/metadata.h>
23#include <system_error>
24
25#include <pipewire/pipewire.h>
26
27#if !PW_CHECK_VERSION(0, 3, 75)
28extern "C" {
29bool pw_check_library_version(int major, int minor, int micro);
30}
31#endif
32
33QT_BEGIN_NAMESPACE
34
35namespace QtPipeWire {
36
37// errno helper
38inline std::error_code make_error_code(int errnoValue = errno)
39{
40 return std::error_code(errnoValue, std::generic_category());
41}
42
43// unique_ptr utilities
44template <typename BaseType, void(Deleter)(BaseType *), typename Type = BaseType>
46{
47 void operator()(Type *handle) const
48 {
49 BaseType *base = reinterpret_cast<BaseType *>(handle);
50 (Deleter)(base);
51 }
52};
53
54template <typename BaseType, void(Deleter)(BaseType *), typename Type = BaseType>
59
60// unique_ptr for pipewire types
61
70
72{
73 void operator()(pw_core *handle) const
74 {
75 int status = pw_core_disconnect(handle);
76 if (status < 0)
77 qWarning() << "Failed to disconnect pw_core:" << make_error_code(status).message();
78 }
79};
80
82
83// strong id types
84
85template <typename T, typename Tag>
87{
88 explicit StrongIdType(T arg) : value{ arg } { }
89
91 friend QDebug operator<<(QDebug dbg, const StrongIdType &self) { return dbg << self.value; }
92
93#ifdef __cpp_impl_three_way_comparison
94 auto operator<=>(const StrongIdType &) const = default;
95#else
96 friend bool comparesEqual(const StrongIdType &lhs, const StrongIdType &rhs) noexcept
97 {
98 return lhs.value == rhs.value;
99 }
100
102 const StrongIdType &rhs) noexcept
103 {
104 return qCompareThreeWay(lhs.value, rhs.value);
105 }
106
108#endif
109};
110
112{
113};
114
115// PW_KEY_OBJECT_ID
116// global object ID, can be reused
118
120{
121};
122
123// PW_KEY_OBJECT_SERIAL
124// unique serial for each object
126
127} // namespace QtPipeWire
128
129// debug support
130QDebug operator<<(QDebug dbg, const spa_dict &dict);
131QDebug operator<<(QDebug dbg, const spa_pod &pod);
132QDebug operator<<(QDebug dbg, enum pw_stream_state);
133QDebug operator<<(QDebug dbg, const pw_time &state);
134
135// Address sanitizer helper
136// for now these annotations only function as documentation
137#define QT_MM_GUARDED_BY(Mutex)
138
139QT_END_NAMESPACE
140
141#endif // QPIPEWIRE_SUPPORT_P_H
static std::atomic_int s_sequenceNumberAllocator
std::unique_ptr< pw_core, PwCoreConnectionDeleter > PwCoreConnectionHandle
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)
QDebug operator<<(QDebug dbg, const spa_dict &dict)
QDebug operator<<(QDebug dbg, enum pw_stream_state)
QDebug operator<<(QDebug dbg, const spa_pod &pod)
q23::expected< void, int > asyncWait(pw_core *coreConnection, std::function< void()> handler)
q23::expected< bool, int > sync(pw_core *coreConnection, std::optional< std::chrono::nanoseconds > timeout={})
void operator()(Type *handle) const
NodeEventListener(PwNodeHandle, NodeHandler)
std::function< void(const struct pw_node_info *)> InfoHandler
std::function< void(int, uint32_t, uint32_t, uint32_t, const struct spa_pod *)> ParamHandler
void operator()(pw_core *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