Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsaudiosink_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of other Qt classes. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QWINDOWSAUDIOSINK_H
16#define QWINDOWSAUDIOSINK_H
17
18#include <QtCore/qthread.h>
19#include <QtCore/qtclasshelpermacros.h>
20#include <QtCore/private/qcomptr_p.h>
21#include <QtMultimedia/private/qaudiosystem_p.h>
22#include <QtMultimedia/private/qaudiosystem_platform_stream_support_p.h>
23#include <QtMultimedia/private/qaudio_platform_implementation_support_p.h>
24#include <QtMultimedia/private/qwindowsaudioutils_p.h>
25
26#include <atomic>
27#include <memory>
28#include <memory_resource>
29
30struct IAudioRenderClient;
31
32QT_BEGIN_NAMESPACE
33
34class QWindowsResampler;
35
36namespace QtWASAPI {
37
38class QWindowsAudioSink;
39using namespace QtMultimediaPrivate;
40
41///////////////////////////////////////////////////////////////////////////////////////////////////
42
45{
47 using SinkType = QWindowsAudioSink;
48
53
54 QWASAPIAudioSinkStream(QAudioDevice, const QAudioFormat &,
55 std::optional<qsizetype> ringbufferSize, QWindowsAudioSink *parent,
56 float volume, std::optional<int32_t> hardwareBufferSize,
60
61 bool open();
62
67
68 bool start(QIODevice *);
70 bool start(AudioCallback);
71
72 void suspend();
73 void resume();
74 void stop(ShutdownPolicy);
75
76 void updateStreamIdle(bool) override;
77
78private:
79 bool openAudioClient(ComPtr<IMMDevice>, AudioEndpointRole);
80 bool startAudioClient(StreamType);
81
82 template <typename Functor>
83 bool visitAudioClientBuffer(Functor &&f);
84
85 void fillInitialHostBuffer(StreamType);
86 void runProcessRingbufferLoop();
87 void runProcessCallbackLoop();
88 bool processRingbuffer() noexcept QT_MM_NONBLOCKING;
89 bool processCallback() noexcept QT_MM_NONBLOCKING;
90
91 void handleAudioClientError();
92 void joinWorkerThread();
93
94 ComPtr<IAudioClient3> m_audioClient;
95 ComPtr<IAudioRenderClient> m_renderClient;
96
97 QWindowsAudioUtils::reference_time m_periodSize;
98 qsizetype m_audioClientFrames;
99
100 std::atomic_bool m_suspended{};
101 std::atomic<ShutdownPolicy> m_shutdownPolicy{ ShutdownPolicy::DiscardRingbuffer };
102 QAutoResetEvent m_ringbufferDrained;
103
104 const AudioEndpointRole m_role;
105
106 const QUniqueWin32NullHandle m_wasapiHandle;
107 std::unique_ptr<QThread> m_workerThread;
108
109 AudioCallback m_audioCallback;
110
111 QWindowsAudioSink *m_parent;
112
113 QAudioFormat m_hostFormat;
114 std::unique_ptr<char[]> m_preallocatedBuffer;
115 std::unique_ptr<std::pmr::memory_resource> m_memoryResource;
116 std::unique_ptr<QWindowsResampler> m_resampler;
117};
118
119///////////////////////////////////////////////////////////////////////////////////////////////////
120
121class QWindowsAudioSink final
122 : public QPlatformAudioSinkImplementation<QWASAPIAudioSinkStream, QWindowsAudioSink>
123{
124 using BaseClass = QPlatformAudioSinkImplementation<QWASAPIAudioSinkStream, QWindowsAudioSink>;
125
126public:
127 QWindowsAudioSink(QAudioDevice, const QAudioFormat &, QObject *parent);
129};
130
131} // namespace QtWASAPI
132
133QT_END_NAMESPACE
134
135#endif // QWINDOWSAUDIOSINK_H
QWindowsAudioSink(QAudioDevice, const QAudioFormat &, QObject *parent)
Combined button and popup list for selecting options.
QWASAPIAudioSinkStream(QAudioDevice, const QAudioFormat &, std::optional< qsizetype > ringbufferSize, QWindowsAudioSink *parent, float volume, std::optional< int32_t > hardwareBufferSize, AudioEndpointRole)
QAudioFormat::SampleFormat SampleFormat