Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdarwinaudiodevice.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "qcoreaudioutils_p.h"
6#include <private/qcore_mac_p.h>
7
8#if defined(Q_OS_IOS)
10#else
12#endif
13
14#include <QtCore/QDataStream>
15#include <QtCore/QDebug>
16#include <QtCore/QSet>
17#include <QIODevice>
18
20
21#if defined(Q_OS_MACOS)
24 m_deviceId(id)
25#else
28#endif
29{
30 description = getDescription();
31 getChannelLayout();
32 preferredFormat = determinePreferredFormat();
33 minimumSampleRate = 1;
34 maximumSampleRate = 96000;
35 minimumChannelCount = 1;
36 maximumChannelCount = 16;
38
39}
40
41QAudioFormat QCoreAudioDeviceInfo::determinePreferredFormat() const
42{
44
45#if defined(Q_OS_MACOS)
46 const auto audioDevicePropertyStreamsAddress =
47 makePropertyAddress(kAudioDevicePropertyStreams, mode);
48
49 if (auto streamIDs = getAudioData<AudioStreamID>(m_deviceId, audioDevicePropertyStreamsAddress,
50 "propertyStreams")) {
51 const auto audioDevicePhysicalFormatPropertyAddress =
52 makePropertyAddress(kAudioStreamPropertyPhysicalFormat, mode);
53
54 for (auto streamID : *streamIDs) {
55 if (auto streamDescription = getAudioObject<AudioStreamBasicDescription>(
56 streamID, audioDevicePhysicalFormatPropertyAddress,
57 "prefferedPhysicalFormat")) {
58 format = CoreAudioUtils::toQAudioFormat(*streamDescription);
59 break;
60 }
61 }
62 }
63
64 if (!format.isValid())
65#endif
66 {
67 format.setSampleRate(44100);
68 format.setSampleFormat(QAudioFormat::Int16);
69 format.setChannelCount(mode == QAudioDevice::Input ? 1 : 2);
70 }
71 format.setChannelConfig(channelConfiguration);
72
73 return format;
74}
75
76
77QString QCoreAudioDeviceInfo::getDescription() const
78{
79#ifdef Q_OS_MACOS
80 const auto propertyAddress = makePropertyAddress(kAudioObjectPropertyName, mode);
81 if (auto name =
82 getAudioObject<CFStringRef>(m_deviceId, propertyAddress, "Device Description")) {
83 auto deleter = qScopeGuard([&name]() { CFRelease(*name); });
84 return QString::fromCFString(*name);
85 }
86
87 return {};
88#else
89 return QString::fromUtf8(id);
90#endif
91}
92
93void QCoreAudioDeviceInfo::getChannelLayout()
94{
95#ifdef Q_OS_MACOS
96 const auto propertyAddress =
97 makePropertyAddress(kAudioDevicePropertyPreferredChannelLayout, mode);
98 if (auto data = getAudioData<char>(m_deviceId, propertyAddress, "prefferedChannelLayout",
99 sizeof(AudioChannelLayout))) {
100 const auto *layout = reinterpret_cast<const AudioChannelLayout *>(data->data());
102 }
103#else
105#endif
106}
107
IOBluetoothDevice * device
static Q_MULTIMEDIA_EXPORT QAudioFormat toQAudioFormat(const AudioStreamBasicDescription &streamFormat)
static QAudioFormat::ChannelConfig fromAudioChannelLayout(const AudioChannelLayout *layout)
QAudioFormat::ChannelConfig channelConfiguration
The QAudioDevice class provides an information about audio devices and their functionality.
Mode
Describes the mode of this device.
The QAudioFormat class stores audio stream parameter information.
\inmodule QtCore
Definition qbytearray.h:57
QCoreAudioDeviceInfo(const QByteArray &device, QAudioDevice::Mode mode)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
Combined button and popup list for selecting options.
static AudioObjectPropertyAddress makePropertyAddress(AudioObjectPropertySelector selector, QAudioDevice::Mode mode, AudioObjectPropertyElement element=kAudioObjectPropertyElementMain)
GLenum mode
GLenum GLuint id
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLint GLsizei GLsizei GLenum format
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
Definition qscopeguard.h:60
QVBoxLayout * layout