Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
)
31
extern
"C"
{
32
bool
pw_check_library_version
(
int
major,
int
minor,
int
micro);
33
}
34
#
endif
35
36
QT_BEGIN_NAMESPACE
37
38
namespace
QtPipeWire
{
39
40
// errno helper
41
inline
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
47
template
<
typename
BaseType,
void
(Deleter)(BaseType *),
typename
Type = BaseType>
48
struct
HandleDeleter
49
{
50
void
operator
()(Type *handle)
const
51
{
52
BaseType *base =
reinterpret_cast
<BaseType *>(handle);
53
(Deleter)(base);
54
}
55
};
56
57
template
<
typename
BaseType,
void
(Deleter)(BaseType *),
typename
Type = BaseType>
58
struct
MakeUniquePtr
59
{
60
using
type
=
std
::
unique_ptr
<
Type
,
HandleDeleter
<
BaseType
,
Deleter
,
Type
>>;
61
};
62
63
// unique_ptr for pipewire types
64
65
using
PwLoopHandle
=
MakeUniquePtr
<
pw_loop
,
pw_loop_destroy
>::
type
;
66
using
PwContextHandle
=
MakeUniquePtr
<
pw_context
,
pw_context_destroy
>::
type
;
67
using
PwPropertiesHandle
=
MakeUniquePtr
<
pw_properties
,
pw_properties_free
>::
type
;
68
using
PwThreadLoopHandle
=
MakeUniquePtr
<
pw_thread_loop
,
pw_thread_loop_destroy
>::
type
;
69
using
PwStreamHandle
=
MakeUniquePtr
<
pw_stream
,
pw_stream_destroy
>::
type
;
70
using
PwRegistryHandle
=
MakeUniquePtr
<
pw_proxy
,
pw_proxy_destroy
,
pw_registry
>::
type
;
71
using
PwNodeHandle
=
MakeUniquePtr
<
pw_proxy
,
pw_proxy_destroy
,
pw_node
>::
type
;
72
using
PwMetadataHandle
=
MakeUniquePtr
<
pw_proxy
,
pw_proxy_destroy
,
pw_metadata
>::
type
;
73
using
PwProxyHandle
=
MakeUniquePtr
<
pw_proxy
,
pw_proxy_destroy
>::
type
;
74
75
struct
PwCoreConnectionDeleter
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
85
using
PwCoreConnectionHandle
=
std
::unique_ptr<pw_core,
PwCoreConnectionDeleter
>;
86
87
struct
SpaHandleDeleter
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
97
using
SpaHandleHandle
=
std
::unique_ptr<spa_handle,
SpaHandleDeleter
>;
98
99
class
Q_MULTIMEDIA_EXPORT
PWThreadedEventLoop
100
{
101
public
:
102
explicit
PWThreadedEventLoop
(
const
char
*
name
);
103
~
PWThreadedEventLoop
();
104
105
Q_DISABLE_COPY_MOVE
(
PWThreadedEventLoop
)
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
120
int
wait_for
(
std
::
chrono
::
seconds
waitMax
);
121
void
signal
(
bool
waitForAccept
);
122
123
template
<
typename
Closure
>
124
auto
runWithEventLoopLock
(
Closure
&&
c
)
125
{
126
std
::
lock_guard
guard
{ *
this
};
127
return
c
();
128
}
129
130
private
:
131
PwThreadLoopHandle
m_loop
;
132
};
133
134
// strong id types
135
136
template
<
typename
T,
typename
Tag>
137
struct
StrongIdType
138
{
139
explicit
StrongIdType
(T arg) :
value
{ arg } { }
140
141
T
value
;
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
152
friend
Qt
::
strong_ordering
compareThreeWay
(
const
StrongIdType
&lhs,
153
const
StrongIdType
&rhs)
noexcept
154
{
155
return
qCompareThreeWay(lhs
.
value
, rhs
.
value
);
156
}
157
158
Q_DECLARE_STRONGLY_ORDERED
(
StrongIdType
)
159
#
endif
160
};
161
162
struct
ObjectIdTag
163
{
164
};
165
166
// PW_KEY_OBJECT_ID
167
// global object ID, can be reused
168
using
ObjectId
=
StrongIdType
<uint32_t,
ObjectIdTag
>;
169
170
struct
ObjectSerialTag
171
{
172
};
173
174
// PW_KEY_OBJECT_SERIAL
175
// unique serial for each object
176
using
ObjectSerial
=
StrongIdType
<uint64_t,
ObjectSerialTag
>;
177
178
}
// namespace QtPipeWire
179
180
// debug support
181
QDebug
operator
<<(QDebug dbg,
const
spa_dict &dict);
182
QDebug
operator
<<(QDebug dbg,
const
spa_pod &pod);
183
QDebug
operator
<<(QDebug dbg,
enum
pw_stream_state);
184
QDebug
operator
<<(QDebug dbg,
const
pw_time &state);
185
QDebug
operator
<<(QDebug dbg,
spa_data_type
);
186
187
// Address sanitizer helper
188
// for now these annotations only function as documentation
189
#
define
QT_MM_GUARDED_BY
(
Mutex
)
190
191
QT_END_NAMESPACE
192
193
#
endif
// QPIPEWIRE_SUPPORT_P_H
QtPipeWire::PWThreadedEventLoop
Definition
qpipewire_support_p.h:100
QtPipeWire
Definition
qpipewire_async_support.cpp:10
QtPipeWire::PwCoreConnectionHandle
std::unique_ptr< pw_core, PwCoreConnectionDeleter > PwCoreConnectionHandle
Definition
qpipewire_support_p.h:85
QtPipeWire::SpaHandleHandle
std::unique_ptr< spa_handle, SpaHandleDeleter > SpaHandleHandle
Definition
qpipewire_support_p.h:97
QtPipeWire::ObjectId
StrongIdType< uint32_t, ObjectIdTag > ObjectId
Definition
qpipewire_support_p.h:168
QtPipeWire::ObjectSerial
StrongIdType< uint64_t, ObjectSerialTag > ObjectSerial
Definition
qpipewire_support_p.h:176
QtPipeWire::make_error_code
std::error_code make_error_code(int errnoValue=errno)
Definition
qpipewire_support_p.h:41
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
operator<<
QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition
qdir.cpp:2620
pw_check_library_version
bool pw_check_library_version(int major, int minor, int micro)
operator<<
QDebug operator<<(QDebug dbg, const pw_time &state)
Definition
qpipewire_support.cpp:154
QT_MM_MAKE_STRING_RESOLVER
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"))
operator<<
QDebug operator<<(QDebug dbg, const spa_dict &dict)
Definition
qpipewire_support.cpp:80
operator<<
QDebug operator<<(QDebug dbg, const spa_pod &)
Definition
qpipewire_support.cpp:133
QT_MM_DEFINE_QDEBUG_ENUM
QT_MM_DEFINE_QDEBUG_ENUM(pw_stream_state)
operator<<
QDebug operator<<(QDebug dbg, enum pw_stream_state)
QtPipeWire::HandleDeleter
Definition
qpipewire_support_p.h:49
QtPipeWire::HandleDeleter::operator()
void operator()(Type *handle) const
Definition
qpipewire_support_p.h:50
QtPipeWire::MakeUniquePtr
Definition
qpipewire_support_p.h:59
QtPipeWire::ObjectIdTag
Definition
qpipewire_support_p.h:163
QtPipeWire::ObjectSerialTag
Definition
qpipewire_support_p.h:171
QtPipeWire::PwCoreConnectionDeleter
Definition
qpipewire_support_p.h:76
QtPipeWire::PwCoreConnectionDeleter::operator()
void operator()(pw_core *handle) const
Definition
qpipewire_support_p.h:77
QtPipeWire::SpaHandleDeleter
Definition
qpipewire_support_p.h:88
QtPipeWire::SpaHandleDeleter::operator()
void operator()(spa_handle *handle) const
Definition
qpipewire_support_p.h:89
QtPipeWire::StrongIdType
Definition
qpipewire_support_p.h:138
QtPipeWire::StrongIdType::operator<<
friend QDebug operator<<(QDebug dbg, const StrongIdType &self)
Definition
qpipewire_support_p.h:142
QtPipeWire::StrongIdType::comparesEqual
friend bool comparesEqual(const StrongIdType &lhs, const StrongIdType &rhs) noexcept
Definition
qpipewire_support_p.h:147
QtPipeWire::StrongIdType::StrongIdType
StrongIdType(T arg)
Definition
qpipewire_support_p.h:139
QtPipeWire::StrongIdType::value
T value
Definition
qpipewire_support_p.h:141
QtPipeWire::StrongIdType::compareThreeWay
friend Qt::strong_ordering compareThreeWay(const StrongIdType &lhs, const StrongIdType &rhs) noexcept
Definition
qpipewire_support_p.h:152
qtmultimedia
src
multimedia
pipewire
qpipewire_support_p.h
Generated on
for Qt by
1.18.0