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
qcoreaudioaggregatedevice_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QCOREAUDIOAGGREGATEDEVICE_P_H
5#define QCOREAUDIOAGGREGATEDEVICE_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/qaudiodevice.h>
19#include <QtCore/qstring.h>
20
21#include <chrono>
22#include <cstdint>
23#include <memory>
24#include <optional>
25
26QT_BEGIN_NAMESPACE
27
28// Test helper: creates a CoreAudio aggregate device wrapping the system default device, and
29// destroys it on request. Destroying the aggregate device looks like an unplugged device to
30// QtMultimedia, without needing any hardware to be unplugged.
31class QCoreAudioAggregateDevice
32{
33public:
34 enum class Direction : uint8_t {
35 Output,
36 Input,
37 };
38
39 // CoreAudio refuses to make a private aggregate device the system default
40 enum class Visibility : uint8_t {
41 Private,
42 Public,
43 };
44
45 // The first call in a process first removes the stale devices of earlier processes
46 static std::unique_ptr<QCoreAudioAggregateDevice> create(Direction,
47 Visibility = Visibility::Private);
48
49 // Same name and UID for every call with the same identity, so a re-created aggregate is
50 // the same QAudioDevice as the one that was destroyed.
51 static std::unique_ptr<QCoreAudioAggregateDevice> create(Direction, const QString &identity,
52 Visibility = Visibility::Private);
53
54 // The UID records the owning process. A device whose owner exited was left behind by a
55 // crashed test run, so it is destroyed. Destroying it makes the default fall back.
56 static void removeStaleDevices();
57
58 // Creates a device as if owned by another process
59 static std::unique_ptr<QCoreAudioAggregateDevice>
60 createOwnedBy(Direction, qint64 ownerPid, const QString &identity,
61 Visibility = Visibility::Private);
62
63 Q_DISABLE_COPY_MOVE(QCoreAudioAggregateDevice)
64 ~QCoreAudioAggregateDevice();
65
66 // Polls QMediaDevices until the aggregate shows up. Nullopt on timeout.
67 std::optional<QAudioDevice> waitForQtDevice(std::chrono::milliseconds timeout) const;
68
69 // Makes the aggregate the system default. Returns false if CoreAudio keeps the previous
70 // default, which is what happens for private devices. The previous default is restored
71 // when this object is destroyed.
72 bool makeSystemDefault();
73
74 bool destroyAndWaitForDisconnectNotification(std::chrono::milliseconds timeout);
75
76private:
77 struct Private;
78 explicit QCoreAudioAggregateDevice(std::unique_ptr<Private>);
79
80 std::unique_ptr<Private> d;
81};
82
83QT_END_NAMESPACE
84
85#endif // QCOREAUDIOAGGREGATEDEVICE_P_H
std::optional< AudioObjectID > previousDefaultId