| 1 | // Copyright (C) 2022 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 | |
| 5 | #ifndef QAUDIODEVICEINFO_P_H |
| 6 | #define QAUDIODEVICEINFO_P_H |
| 7 | |
| 8 | // |
| 9 | // W A R N I N G |
| 10 | // ------------- |
| 11 | // |
| 12 | // This file is not part of the Qt API. It exists purely as an |
| 13 | // implementation detail. This header file may change from version to |
| 14 | // version without notice, or even be removed. |
| 15 | // |
| 16 | // We mean it. |
| 17 | // |
| 18 | |
| 19 | #include <QtMultimedia/qaudiodevice.h> |
| 20 | #include <QtCore/private/qglobal_p.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | // Implementations should not include volatile members, such as values that can change between |
| 25 | // connection sessions. For example, CoreAudio AudioDeviceId on macOS. |
| 26 | class Q_MULTIMEDIA_EXPORT QAudioDevicePrivate : public QSharedData |
| 27 | { |
| 28 | public: |
| 29 | QAudioDevicePrivate(QByteArray id, QAudioDevice::Mode m, QString description) |
| 30 | : id(std::move(id)), mode(m), description(std::move(description)) |
| 31 | {} |
| 32 | virtual ~QAudioDevicePrivate(); |
| 33 | const QByteArray id; |
| 34 | const QAudioDevice::Mode mode = QAudioDevice::Output; |
| 35 | const QString description; |
| 36 | bool isDefault = false; |
| 37 | |
| 38 | QAudioFormat preferredFormat; |
| 39 | int minimumSampleRate = 0; |
| 40 | int maximumSampleRate = 0; |
| 41 | int minimumChannelCount = 0; |
| 42 | int maximumChannelCount = 0; |
| 43 | QList<QAudioFormat::SampleFormat> supportedSampleFormats; |
| 44 | QAudioFormat::ChannelConfig channelConfiguration = QAudioFormat::ChannelConfigUnknown; |
| 45 | |
| 46 | static QAudioDevice createQAudioDevice(std::unique_ptr<QAudioDevicePrivate> devicePrivate); |
| 47 | |
| 48 | static const QAudioDevicePrivate *handle(const QAudioDevice &device) { return device.d.get(); } |
| 49 | |
| 50 | template <typename Derived> |
| 51 | static const Derived *handle(const QAudioDevice &device) |
| 52 | { |
| 53 | // Note: RTTI is required for dispatching in the gstreamer backend |
| 54 | return dynamic_cast<const Derived *>(handle(device)); |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | inline const QList<QAudioFormat::SampleFormat> &qAllSupportedSampleFormats() |
| 59 | { |
| 60 | static const auto singleton = QList<QAudioFormat::SampleFormat>{ |
| 61 | QAudioFormat::UInt8, |
| 62 | QAudioFormat::Int16, |
| 63 | QAudioFormat::Int32, |
| 64 | QAudioFormat::Float, |
| 65 | }; |
| 66 | return singleton; |
| 67 | } |
| 68 | |
| 69 | struct QAudioDevicePrivateAllMembersEqual |
| 70 | { |
| 71 | bool operator()(const QAudioDevicePrivate &lhs, const QAudioDevicePrivate &rhs) |
| 72 | { |
| 73 | auto asTuple = [](const QAudioDevicePrivate &x) { |
| 74 | return std::tie(args: x.id, args: x.mode, args: x.isDefault, args: x.preferredFormat, args: x.description, |
| 75 | args: x.minimumSampleRate, args: x.maximumSampleRate, args: x.minimumChannelCount, |
| 76 | args: x.maximumChannelCount, args: x.supportedSampleFormats, |
| 77 | args: x.channelConfiguration); |
| 78 | }; |
| 79 | |
| 80 | return asTuple(lhs) == asTuple(rhs); |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | QT_END_NAMESPACE |
| 85 | |
| 86 | #endif // QAUDIODEVICEINFO_H |
| 87 | |