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_audiocontextmanager_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_AUDIOCONTEXTMANAGER_P_H
5#define QPIPEWIRE_AUDIOCONTEXTMANAGER_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
23
24#include <pipewire/pipewire.h>
25
27
28namespace QtPipeWire {
29
32
34{
35public:
38
39 static bool minimumRequirementMet();
40
42 bool isConnected() const;
43
44 template <typename Closure>
45 static auto withEventLoopLock(Closure &&c)
46 {
48
49 pw_thread_loop_lock(self->m_eventLoop.get());
50 auto unlock = qScopeGuard([&] {
51 pw_thread_loop_unlock(self->m_eventLoop.get());
52 });
53
54 return c();
55 }
56
58
59 static bool isInPwThreadLoop();
60 static pw_loop *getEventLoop();
61
64
65 void syncRegistry();
66
68 void unregisterStreamReference(const std::shared_ptr<QPipewireAudioStream> &);
69
71
72private:
73 std::shared_ptr<QPipeWireInstance> m_libraryInstance;
74
75 // event loop
76 PwThreadLoopHandle m_eventLoop;
77 void prepareEventLoop();
78 void startEventLoop();
79 void stopEventLoop();
80
81 // pipewire context
82 PwContextHandle m_context;
83 void prepareContext();
84
85 // pw_core connection
86 PwCoreConnectionHandle m_coreConnection;
87 void connectToPipewireInstance();
88
89 // device monitor
90 PwRegistryHandle m_registry;
91 struct spa_hook m_registryListener{};
92 std::unique_ptr<QAudioDeviceMonitor> m_deviceMonitor;
93
94 void startDeviceMonitor();
95 static void objectAddedCb(void *data, uint32_t id, uint32_t permissions, const char *type,
96 uint32_t version, const struct spa_dict *props);
97 static void objectRemovedCb(void *data, uint32_t id);
98 void objectAdded(ObjectId id, uint32_t permissions, PipewireRegistryType, uint32_t version,
99 const spa_dict &props);
100 void objectRemoved(ObjectId id);
101
102 // default metadata object
103 void startListenDefaultMetadataObject(ObjectId, uint32_t version);
104 struct MetadataRecord
105 {
106 const char *key;
107 const char *type;
108 const char *value;
109 };
110
111 int handleDefaultMetadataObjectEvent(const MetadataRecord &record);
112
113 PwMetadataHandle m_defaultMetadataObject;
114 struct spa_hook m_defaultMetadataObjectListener{};
115
116 QMutex m_activeStreamMutex;
117 std::set<std::shared_ptr<QPipewireAudioStream>> m_activeStreams;
118 void stopActiveStreams();
119};
120
121} // namespace QtPipeWire
122
123QT_END_NAMESPACE
124
125#endif // QPIPEWIRE_AUDIOCONTEXTMANAGER_P_H
void registerStreamReference(std::shared_ptr< QPipewireAudioStream >)
void unregisterStreamReference(const std::shared_ptr< QPipewireAudioStream > &)
const PwCoreConnectionHandle & coreConnection() const
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