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.cpp
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
5
6#include <QtMultimedia/private/qmultimedia_enum_to_string_converter_p.h>
7#include <QtCore/qspan.h>
8
9#include <pipewire/version.h>
10#include <spa/debug/pod.h>
11
12#include <cstdarg>
13
14QT_BEGIN_NAMESPACE
15
16namespace QtPipeWire {
17
19 : m_loop{
20 pw_thread_loop_new(name, /*props=*/nullptr),
21 }
22{
23}
24
26
27PWThreadedEventLoop::operator bool() const
28{
29 return bool(m_loop);
30}
31
33{
34 return pw_thread_loop_start(m_loop.get());
35}
36
38{
39 pw_thread_loop_stop(m_loop.get());
40}
41
42pw_thread_loop *PWThreadedEventLoop::get() const
43{
44 return m_loop.get();
45}
46
47pw_loop *PWThreadedEventLoop::loop() const
48{
49 return pw_thread_loop_get_loop(m_loop.get());
50}
51
53{
54 return pw_thread_loop_in_thread(m_loop.get());
55}
56
58{
59 pw_thread_loop_lock(m_loop.get());
60}
61
63{
64 pw_thread_loop_unlock(m_loop.get());
65}
66
67int PWThreadedEventLoop::wait_for(std::chrono::seconds waitMax)
68{
69 return pw_thread_loop_timed_wait(m_loop.get(), int(waitMax.count()));
70}
71
72void PWThreadedEventLoop::signal(bool waitForAccept)
73{
74 pw_thread_loop_signal(m_loop.get(), waitForAccept);
75}
76
77} // namespace QtPipeWire
78
79// debug support
80QDebug operator<<(QDebug dbg, const spa_dict &dict)
81{
82 QSpan<const spa_dict_item> items{ dict.items, dict.n_items };
83
84 QDebugStateSaver saver(dbg);
85 dbg.nospace();
86
87 for (const spa_dict_item &item : items)
88 dbg << item.key << "=" << item.value << ", ";
89 return dbg;
90}
91
92#if PW_CHECK_VERSION(0, 3, 65)
93
94namespace {
95
96struct QtSpaDebugContext : ::spa_debug_context
97{
98 explicit QtSpaDebugContext(QDebug dbg)
99 : ::spa_debug_context{},
100 dbg{
101 std::move(dbg),
102 }
103 {
104 ::spa_debug_context::log = &doLog;
105 }
106
107 static void doLog(::spa_debug_context *ctx, const char *fmt, ...)
108 {
109 std::va_list args;
110 va_start(args, fmt);
111 QString logString = QString::vasprintf(fmt, args);
112 va_end(args);
113
114 auto *self = static_cast<QtSpaDebugContext *>(ctx);
115 self->dbg << logString;
116 }
117
118 QDebug dbg;
119};
120
121} // namespace
122
123QDebug operator<<(QDebug dbg, const spa_pod &pod)
124{
125 QtSpaDebugContext context{ std::move(dbg) };
126
127 spa_debugc_pod(&context, 0, nullptr, &pod);
128 return std::move(context.dbg);
129}
130
131#else
132
133QDebug operator<<(QDebug dbg, const spa_pod &)
134{
135 dbg << "QDebug operator<<(QDebug, const spa_pod &) not implemented: minimum requirement: "
136 "pipewire-0.3.65";
137 return dbg;
138}
139
140#endif
141
142// clang-format off
144 (PW_STREAM_STATE_ERROR, "error")
145 (PW_STREAM_STATE_UNCONNECTED, "unconnected")
146 (PW_STREAM_STATE_CONNECTING, "connecting")
147 (PW_STREAM_STATE_PAUSED, "paused")
148 (PW_STREAM_STATE_STREAMING, "streaming")
149 );
150// clang-format on
151
153
154QDebug operator<<(QDebug dbg, const pw_time &state)
155{
156 // pw_time may have more members, but those are only required to exist in 0.3.55 and later
157 dbg << QStringLiteral(u"pw_time{now: %1ns, rate: %2/%3, ticks: %4, delay: %5, queued: %6}")
158 .arg(state.now)
159 .arg(state.rate.num)
160 .arg(state.rate.denom)
161 .arg(state.ticks)
162 .arg(state.delay)
163 .arg(state.queued);
164 return dbg;
165}
166
167QT_END_NAMESPACE
int wait_for(std::chrono::seconds waitMax)
void signal(bool waitForAccept)
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)