6#include <QtCore/private/qcore_mac_p.h>
8#include <QtMultimedia/private/qcoreaudioutils_p.h>
9#include <QtMultimedia/private/qaudioformat_p.h>
11#include <QtMultimedia/private/qmacosaudiodatautils_p.h>
21 QAudioDevice::Mode mode,
22 QAudioFormat::ChannelConfig channelConfig)
25 format.setSampleRate(44100);
26 format.setSampleFormat(QAudioFormat::Int16);
27 format.setChannelCount(mode == QAudioDevice::Input ? 1 : 2);
28 format.setChannelConfig(channelConfig);
34 return (mode == QAudioDevice::Input) ? QAudioFormat::ChannelConfigMono : QAudioFormat::ChannelConfigStereo;
39 return QString::fromUtf8(id);
44[[nodiscard]] std::optional<QAudioFormat> qGetPreferredFormatForCoreAudioDevice(
45 QAudioDevice::Mode mode,
46 AudioDeviceID deviceId)
48 using namespace QCoreAudioUtils;
50 const auto audioDevicePropertyStreamsAddress =
51 makePropertyAddress(kAudioDevicePropertyStreams, mode);
53 if (
auto streamIDs = getAudioPropertyList<AudioStreamID>(deviceId, audioDevicePropertyStreamsAddress)) {
54 const auto audioDevicePhysicalFormatPropertyAddress =
55 makePropertyAddress(kAudioStreamPropertyPhysicalFormat, mode);
57 for (
auto streamID : *streamIDs) {
58 if (
auto streamDescription = getAudioProperty<AudioStreamBasicDescription>(
59 streamID, audioDevicePhysicalFormatPropertyAddress)) {
60 return QCoreAudioUtils::toQAudioFormat(*streamDescription);
68[[nodiscard]] std::optional<QAudioFormat::ChannelConfig> qGetChannelLayoutForCoreAudioDevice(
69 QAudioDevice::Mode mode,
70 AudioDeviceID deviceId)
72 using namespace QCoreAudioUtils;
74 const auto propertyAddress =
75 makePropertyAddress(kAudioDevicePropertyPreferredChannelLayout, mode);
77 if (
auto layout = getAudioPropertyWithFlexibleArrayMember<AudioChannelLayout>(deviceId, propertyAddress))
78 return QCoreAudioUtils::fromAudioChannelLayout(layout.get());
83[[nodiscard]] std::optional<QString> qGetDescriptionForCoreAudioDevice(
84 QAudioDevice::Mode mode,
85 AudioDeviceID deviceId)
87 using namespace QCoreAudioUtils;
89 const auto propertyAddress = makePropertyAddress(kAudioObjectPropertyName, mode);
90 if (
auto name = getAudioProperty<QCFString>(deviceId, propertyAddress))
96[[nodiscard]] std::optional<
int> qSupportedNumberOfChannels(
97 QAudioDevice::Mode mode,
98 AudioDeviceID deviceId)
100 using namespace QCoreAudioUtils;
102 const auto audioDevicePropertyStreamsAddress =
103 makePropertyAddress(kAudioDevicePropertyStreams, mode);
105 auto streamIDs = getAudioPropertyList<AudioStreamID>(deviceId, audioDevicePropertyStreamsAddress);
109 const auto propVirtualFormat = makePropertyAddress(kAudioStreamPropertyVirtualFormat, mode);
113 for (
auto streamID : *streamIDs) {
114 auto streamDescription = getAudioProperty<AudioStreamBasicDescription>(streamID, propVirtualFormat);
115 if (!streamDescription)
117 ret += streamDescription->mChannelsPerFrame;
129static QString getDescription(AudioDeviceID id,
const QByteArray &device, QAudioDevice::Mode mode)
131 if (
auto optionalDescription = qGetDescriptionForCoreAudioDevice(mode, id))
132 return *optionalDescription;
133 return qGetDefaultDescription(device);
136QCoreAudioDeviceInfo::QCoreAudioDeviceInfo(AudioDeviceID id,
const QByteArray &device, QAudioDevice::Mode mode):
140 getDescription(id, device, mode),
143 const std::optional<QAudioFormat::ChannelConfig> channelConfigOpt =
144 qGetChannelLayoutForCoreAudioDevice(mode, id);
145 if (channelConfigOpt.has_value())
146 channelConfiguration = channelConfigOpt.value();
148 channelConfiguration = qGetDefaultChannelLayout(mode);
150 const std::optional<QAudioFormat> preferredFormatOpt =
151 qGetPreferredFormatForCoreAudioDevice(mode, id);
152 if (preferredFormatOpt.has_value())
153 preferredFormat = preferredFormatOpt.value();
155 preferredFormat = qDefaultPreferredFormat(mode, channelConfiguration);
157 minimumSampleRate = QtMultimediaPrivate::allSupportedSampleRates.front();
158 maximumSampleRate = QtMultimediaPrivate::allSupportedSampleRates.back();
159 minimumChannelCount = 1;
160 maximumChannelCount = qSupportedNumberOfChannels(mode, id).value_or(16);
162 supportedSampleFormats = qAllSupportedSampleFormats();
167QCoreAudioDeviceInfo::QCoreAudioDeviceInfo(
const QByteArray &device, QAudioDevice::Mode mode)
168 : QAudioDevicePrivate(device, mode, qGetDefaultDescription(device))
170 channelConfiguration = qGetDefaultChannelLayout(mode);
171 preferredFormat = qDefaultPreferredFormat(mode, channelConfiguration);
173 minimumSampleRate = 1;
174 maximumSampleRate = 96000;
175 minimumChannelCount = 1;
176 maximumChannelCount = 16;
177 supportedSampleFormats = qAllSupportedSampleFormats();
QAudioFormat::ChannelConfig qGetDefaultChannelLayout(QAudioDevice::Mode mode)
QAudioFormat qDefaultPreferredFormat(QAudioDevice::Mode mode, QAudioFormat::ChannelConfig channelConfig)
QString qGetDefaultDescription(const QByteArray &id)