// Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QWINDOWSAUDIOUTILS_H #define QWINDOWSAUDIOUTILS_H // // W A R N I N G // ------------- // // This file is not part of the Qt API. It exists purely as an // implementation detail. This header file may change from version to // version without notice, or even be removed. // // We mean it. // #include #include #include #include #include #include #include #include struct IAudioClient; struct IAudioClient3; struct IMFMediaType; struct IMMDevice; typedef LONGLONG REFERENCE_TIME; QT_BEGIN_NAMESPACE class QWindowsMediaFoundation; namespace QWindowsAudioUtils { using QtMultimediaPrivate::AudioEndpointRole; // REFERENCE_TIME helper using reference_time = std::chrono::duration>; static_assert(reference_time(1) == std::chrono::nanoseconds(100)); // format utilities bool formatToWaveFormatExtensible(const QAudioFormat &format, WAVEFORMATEXTENSIBLE &wfx); std::optional toWaveFormatExtensible(const QAudioFormat &format); QAudioFormat waveFormatExToFormat(const WAVEFORMATEX &in); Q_MULTIMEDIA_EXPORT QAudioFormat mediaTypeToFormat(IMFMediaType *mediaType); ComPtr formatToMediaType(QWindowsMediaFoundation &, const QAudioFormat &format); QAudioFormat::ChannelConfig maskToChannelConfig(UINT32 mask, int count); // IAudioClient helpers struct AudioClientCreationResult { ComPtr client; reference_time periodSize; qsizetype audioClientFrames; }; std::optional createAudioClient(const ComPtr &, const QAudioFormat &, std::optional hardwareBufferFrames, const QUniqueWin32NullHandle &wasapiEventHandle, std::optional = {}); bool audioClientStart(const ComPtr &); bool audioClientStop(const ComPtr &); bool audioClientReset(const ComPtr &); bool audioClientSetRate(const ComPtr &, int rate); bool audioClientSetRole(const ComPtr &client, AudioEndpointRole role); std::optional getBufferSizeInFrames(const ComPtr &client); struct AudioClientDevicePeriod { reference_time defaultDuration; reference_time minimalDuration; }; std::optional getDevicePeriod(const ComPtr &client); // wasapi thread helper void setMCSSForPeriodSize(reference_time); // error stringification QString audioClientErrorString(HRESULT); } // namespace QWindowsAudioUtils QT_END_NAMESPACE #endif // QWINDOWSAUDIOUTILS_H