4#ifndef QPIPEWIRE_AUDIODEVICEMONITOR_P_H
5#define QPIPEWIRE_AUDIODEVICEMONITOR_P_H
23#include <QtCore/qfuture.h>
24#include <QtCore/qtimer.h>
25#include <QtCore/qreadwritelock.h>
26#include <QtMultimedia/qaudiodevice.h>
31#include <pipewire/pipewire.h>
58 enum class Direction : uint8_t
67 const spa_dict &props);
103 PwPropertyDict properties;
106 struct PendingNodeRecord
109 PwPropertyDict properties);
113 PwPropertyDict properties;
114 std::unique_ptr<NodeEventListener> enumFormatListener;
115 std::unique_ptr<CoreEventDoneListener> enumFormatDoneListener;
116 QFuture<std::optional<SpaObjectAudioFormat>> formatFuture;
123 PwPropertyDict properties;
128 struct PendingRecords
130 std::list<PendingNodeRecord> m_sources;
131 std::list<PendingNodeRecord> m_sinks;
132 std::vector<ObjectSerial> m_removals;
134 std::optional<std::variant<QByteArray, NoDefaultDeviceType>> m_defaultSource;
135 std::optional<std::variant<QByteArray, NoDefaultDeviceType>> m_defaultSink;
139 QMutex m_pendingRecordsMutex;
143 mutable QReadWriteLock m_mutex;
147 std::optional<QByteArray> m_defaultSourceName;
148 std::optional<QByteArray> m_defaultSinkName;
150 QTimer m_compressionTimer;
151 void startCompressionTimer();
154 void audioDevicesChanged(
bool verifyThreading =
true);
155 void updateSources(std::list<PendingNodeRecord> addedNodes,
156 QSpan<
const ObjectSerial> removedObjects);
157 void updateSinks(std::list<PendingNodeRecord> addedNodes,
158 QSpan<
const ObjectSerial> removedObjects);
160 void updateSourcesOrSinks(std::list<PendingNodeRecord>, QSpan<
const ObjectSerial>);
162 QList<QAudioDevice> m_sourceDeviceList;
163 QList<QAudioDevice> m_sinkDeviceList;
165 std::optional<
ObjectSerial> findDeviceSerial(std::string_view deviceName)
const;
168 std::optional<
ObjectSerial> findNodeSerialForNodeName(std::string_view nodeName)
const;
172 mutable QReadWriteLock m_objectDictMutex;
173 std::map<ObjectId, ObjectSerial> m_objectSerialDict
QT_MM_GUARDED_BY(m_objectDictMutex);
174 std::map<ObjectSerial, ObjectId> m_serialObjectDict
QT_MM_GUARDED_BY(m_objectDictMutex);
176 std::vector<SharedObjectRemoveObserver>
ObjectSerial serial() const
static bool minimumRequirementMet()
PwNodeHandle bindNode(ObjectId)
static QAudioDeviceMonitor & deviceMonitor()
static QAudioContextManager * instance()
void registerStreamReference(std::shared_ptr< QPipewireAudioStream >)
void unregisterStreamReference(const std::shared_ptr< QPipewireAudioStream > &)
PwMetadataHandle bindMetadata(ObjectId)
static auto withEventLoopLock(Closure &&c)
static bool isInPwThreadLoop()
static pw_loop * getEventLoop()
const PwCoreConnectionHandle & coreConnection() const
void audioSourcesChanged(QList< QAudioDevice >)
void unregisterObserver(const SharedObjectRemoveObserver &)
std::optional< ObjectSerial > findSourceNodeSerial(std::string_view nodeName) const
void setDefaultAudioSink(std::variant< QByteArray, NoDefaultDeviceType >)
DeviceLists getDeviceLists(bool verifyThreading=true)
void setDefaultAudioSource(std::variant< QByteArray, NoDefaultDeviceType >)
std::optional< ObjectId > findObjectId(ObjectSerial)
std::optional< ObjectSerial > findSinkNodeSerial(std::string_view nodeName) const
void objectRemoved(ObjectId)
static constexpr NoDefaultDeviceType NoDefaultDevice
void objectAdded(ObjectId, uint32_t permissions, PipewireRegistryType, uint32_t version, const spa_dict &props)
std::optional< ObjectSerial > findObjectSerial(ObjectId)
bool registerObserver(SharedObjectRemoveObserver)
static std::atomic_int s_sequenceNumberAllocator
std::unique_ptr< pw_core, PwCoreConnectionDeleter > PwCoreConnectionHandle
StrongIdType< uint32_t, ObjectIdTag > ObjectId
StrongIdType< uint64_t, ObjectSerialTag > ObjectSerial
std::shared_ptr< ObjectRemoveObserver > SharedObjectRemoveObserver
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)
#define QT_MM_GUARDED_BY(Mutex)
QDebug operator<<(QDebug dbg, const spa_pod &pod)
q23::expected< void, int > asyncWait(pw_core *coreConnection, std::function< void()> handler)
pw_core_events coreEvents
q23::expected< bool, int > sync(pw_core *coreConnection, std::optional< std::chrono::nanoseconds > timeout={})
void operator()(Type *handle) const
ParamHandler paramHandler
NodeEventListener(PwNodeHandle, NodeHandler)
std::function< void(const struct pw_node_info *)> InfoHandler
void enumParams(spa_param_type)
std::function< void(int, uint32_t, uint32_t, uint32_t, const struct spa_pod *)> ParamHandler
void operator()(pw_core *handle) const
QList< QAudioDevice > sources
QList< QAudioDevice > sinks
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