summaryrefslogtreecommitdiff
path: root/src/plugins/wasapi/qwasapiaudiodeviceinfo.cpp
diff options
context:
space:
mode:
authorMaurice Kalinowski <maurice.kalinowski@theqtcompany.com>2016-02-17 11:19:47 +0100
committerMaurice Kalinowski <maurice.kalinowski@theqtcompany.com>2016-03-29 11:26:33 +0000
commit0d8366273dcb9af5dae641c7efbc6db878942422 (patch)
tree7c17ce8274a80409cff05733dd846379d29a0fef /src/plugins/wasapi/qwasapiaudiodeviceinfo.cpp
parente757890f4a5669b396039211902224f31666725a (diff)
downloadqtmultimedia-0d8366273dcb9af5dae641c7efbc6db878942422.tar.gz
Add Wasapi audio backend
WASAPI is a Windows audio backend for low latency audio. This backend works for WinRT as well as classic desktop apps. Task-number: QTBUG-42287 Change-Id: I7a1b7b103b64fadc50a9955a9d59443791f6d026 Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
Diffstat (limited to 'src/plugins/wasapi/qwasapiaudiodeviceinfo.cpp')
-rw-r--r--src/plugins/wasapi/qwasapiaudiodeviceinfo.cpp164
1 files changed, 164 insertions, 0 deletions
diff --git a/src/plugins/wasapi/qwasapiaudiodeviceinfo.cpp b/src/plugins/wasapi/qwasapiaudiodeviceinfo.cpp
new file mode 100644
index 000000000..283e8b740
--- /dev/null
+++ b/src/plugins/wasapi/qwasapiaudiodeviceinfo.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qwasapiaudiodeviceinfo.h"
+#include "qwasapiutils.h"
+
+#include <Audioclient.h>
+
+QT_BEGIN_NAMESPACE
+
+Q_LOGGING_CATEGORY(lcMmDeviceInfo, "qt.multimedia.deviceinfo")
+
+QWasapiAudioDeviceInfo::QWasapiAudioDeviceInfo(QByteArray dev, QAudio::Mode mode)
+ : m_deviceName(dev)
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__ << dev << mode;
+ m_interface = QWasapiUtils::createOrGetInterface(dev, mode);
+
+ QAudioFormat referenceFormat = m_interface->m_mixFormat;
+
+ const int rates[] = {8000, 11025, 160000, 22050, 32000, 44100, 48000, 88200, 96000, 192000};
+ for (int rate : rates) {
+ QAudioFormat f = referenceFormat;
+ f.setSampleRate(rate);
+ if (isFormatSupported(f))
+ m_sampleRates.append(rate);
+ }
+
+ for (int i = 1; i <= 18; ++i) {
+ QAudioFormat f = referenceFormat;
+ f.setChannelCount(i);
+ if (isFormatSupported(f))
+ m_channelCounts.append(i);
+ }
+
+ const int sizes[] = {8, 12, 16, 20, 24, 32, 64};
+ for (int s : sizes) {
+ QAudioFormat f = referenceFormat;
+ f.setSampleSize(s);
+ if (isFormatSupported(f))
+ m_sampleSizes.append(s);
+ }
+
+ referenceFormat.setSampleType(QAudioFormat::SignedInt);
+ if (isFormatSupported(referenceFormat))
+ m_sampleTypes.append(QAudioFormat::SignedInt);
+
+ referenceFormat.setSampleType(QAudioFormat::Float);
+ if (isFormatSupported(referenceFormat))
+ m_sampleTypes.append(QAudioFormat::Float);
+}
+
+QWasapiAudioDeviceInfo::~QWasapiAudioDeviceInfo()
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+}
+
+bool QWasapiAudioDeviceInfo::isFormatSupported(const QAudioFormat& format) const
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__ << format;
+
+ WAVEFORMATEX nfmt;
+ if (!QWasapiUtils::convertToNativeFormat(format, &nfmt))
+ return false;
+
+ WAVEFORMATEX closest;
+ WAVEFORMATEX *pClosest = &closest;
+ HRESULT hr;
+ hr = m_interface->m_client->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, &nfmt, &pClosest);
+
+ if (hr == S_OK) // S_FALSE is inside SUCCEEDED()
+ return true;
+
+ if (lcMmDeviceInfo().isDebugEnabled()) {
+ QAudioFormat f;
+ QWasapiUtils::convertFromNativeFormat(pClosest, &f);
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__ << hr << "Closest match is:" << f;
+ }
+
+ return false;
+}
+
+QAudioFormat QWasapiAudioDeviceInfo::preferredFormat() const
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+ return m_interface->m_mixFormat;
+}
+
+QString QWasapiAudioDeviceInfo::deviceName() const
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+ return m_deviceName;
+}
+
+QStringList QWasapiAudioDeviceInfo::supportedCodecs()
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+ return QStringList() << QStringLiteral("audio/pcm");
+}
+
+QList<int> QWasapiAudioDeviceInfo::supportedSampleRates()
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+ return m_sampleRates;
+}
+
+QList<int> QWasapiAudioDeviceInfo::supportedChannelCounts()
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+ return m_channelCounts;
+}
+
+QList<int> QWasapiAudioDeviceInfo::supportedSampleSizes()
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+ return m_sampleSizes;
+}
+
+QList<QAudioFormat::Endian> QWasapiAudioDeviceInfo::supportedByteOrders()
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+ return QList<QAudioFormat::Endian>() << m_interface->m_mixFormat.byteOrder();
+}
+
+QList<QAudioFormat::SampleType> QWasapiAudioDeviceInfo::supportedSampleTypes()
+{
+ qCDebug(lcMmDeviceInfo) << __FUNCTION__;
+ return m_sampleTypes;
+}
+
+QT_END_NAMESPACE