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 <QtMultimedia/private/qpipewire_audiodevicemonitor_p.h>
19#include <QtMultimedia/private/qpipewire_registry_support_p.h>
20#include <QtMultimedia/private/qpipewire_support_p.h>
21#include <QtCore/qglobal.h>
22
23#include <pipewire/pipewire.h>
24
25QT_BEGIN_NAMESPACE
26
27namespace QtPipeWire {
28
31
33{
34public:
37
38 static bool minimumRequirementMet();
39
41 bool isConnected() const;
42
43 template <typename Closure>
44 static auto withEventLoopLock(Closure &&c)
45 {
47
48 pw_thread_loop_lock(self->m_eventLoop.get());
49 auto unlock = qScopeGuard([&] {
50 pw_thread_loop_unlock(self->m_eventLoop.get());
51 });
52
53 return c();
54 }
55
57
58 static bool isInPwThreadLoop();
59 static pw_loop *getEventLoop();
60
63
64 void syncRegistry();
65
67 void unregisterStreamReference(const std::shared_ptr<QPipewireAudioStream> &);
68
70
71private:
72 std::shared_ptr<QPipeWireInstance> m_libraryInstance;
73
74 // event loop
75 PwThreadLoopHandle m_eventLoop;
76 void prepareEventLoop();
77 void startEventLoop();
78 void stopEventLoop();
79
80 // pipewire context
81 PwContextHandle m_context;
82 void prepareContext();
83
84 // pw_core connection
85 PwCoreConnectionHandle m_coreConnection;
86 void connectToPipewireInstance();
87
88 // device monitor
89 PwRegistryHandle m_registry;
90 spa_hook m_registryListener{};
91 std::unique_ptr<QAudioDeviceMonitor> m_deviceMonitor;
92
93 void startDeviceMonitor();
94 void stopDeviceMonitor();
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 void stopListenDefaultMetadataObject();
105 struct MetadataRecord
106 {
107 const char *key;
108 const char *type;
109 const char *value;
110 };
111
112 int handleDefaultMetadataObjectEvent(ObjectId subject, const MetadataRecord &);
113
114 PwMetadataHandle m_defaultMetadataObject;
115 spa_hook m_defaultMetadataObjectListener{};
116
117 QMutex m_activeStreamMutex;
119 void stopActiveStreams();
120};
121
122} // namespace QtPipeWire
123
124QT_END_NAMESPACE
125
126#endif // QPIPEWIRE_AUDIOCONTEXTMANAGER_P_H
void registerStreamReference(std::shared_ptr< QPipewireAudioStream >)
void unregisterStreamReference(const std::shared_ptr< QPipewireAudioStream > &)
const PwCoreConnectionHandle & coreConnection() const
#define __has_include(x)
bool pw_check_library_version(int major, int minor, int micro)