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
qwindowsaudiosource_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 QWINDOWSAUDIOSOURCE_H
16#define QWINDOWSAUDIOSOURCE_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#include <QtMultimedia/private/qwindowsresampler_p.h>
26
27#include <atomic>
28#include <memory>
29#include <memory_resource>
30
31struct IMMDevice;
32struct IAudioCaptureClient;
33
34QT_BEGIN_NAMESPACE
35
36namespace QtWASAPI {
37
38class QWindowsAudioSource;
39using namespace QtMultimediaPrivate;
40
43{
45 using SourceType = QWindowsAudioSource;
46
47 QWASAPIAudioSourceStream(QAudioDevice, const QAudioFormat &,
48 std::optional<qsizetype> ringbufferSize, QWindowsAudioSource *parent,
49 float volume, std::optional<int32_t> hardwareBufferFrames);
52
58
59 bool open() { return true; }
60 bool start(QIODevice *);
62 bool start(AudioCallback &&);
63
64 void suspend();
65 void resume();
66 void stop(ShutdownPolicy);
67
68 void updateStreamIdle(bool) override;
69
70private:
71 bool openAudioClient(ComPtr<IMMDevice> device);
72 bool startAudioClient();
73
74 template <typename Functor>
75 bool visitAudioClientBuffer(Functor &&);
76
77 void runProcessLoop();
78 bool processRingbuffer() noexcept QT_MM_NONBLOCKING;
79 bool processCallback() noexcept QT_MM_NONBLOCKING;
80 void handleAudioClientError();
81
82 ComPtr<IAudioClient3> m_audioClient;
83 ComPtr<IAudioCaptureClient> m_captureClient;
84
85 QWindowsAudioUtils::reference_time m_periodSize;
86 qsizetype m_audioClientFrames;
87
88 std::atomic_bool m_suspended{};
89 std::atomic<ShutdownPolicy> m_shutdownPolicy{ ShutdownPolicy::DiscardRingbuffer };
90 QAutoResetEvent m_ringbufferDrained;
91
92 const QUniqueWin32NullHandle m_wasapiHandle;
93 std::unique_ptr<QThread> m_workerThread;
94
95 std::optional<AudioCallback> m_audioCallback;
96 QWindowsAudioSource *m_parent;
97
98 QAudioFormat m_hostFormat;
99 std::unique_ptr<std::pmr::memory_resource> m_memoryResource;
100 std::unique_ptr<QWindowsResampler> m_resampler;
101};
102
103///////////////////////////////////////////////////////////////////////////////////////////////////
104
105class QWindowsAudioSource final
106 : public QPlatformAudioSourceImplementationWithCallback<QWASAPIAudioSourceStream,
107 QWindowsAudioSource>
108{
109 using BaseClass = QPlatformAudioSourceImplementationWithCallback<QWASAPIAudioSourceStream,
110 QWindowsAudioSource>;
111
112public:
113 QWindowsAudioSource(QAudioDevice, const QAudioFormat &, QObject *parent);
114};
115
116} // namespace QtWASAPI
117
118QT_END_NAMESPACE
119
120#endif
QWindowsAudioSource(QAudioDevice, const QAudioFormat &, QObject *parent)
QAudioFormat::SampleFormat SampleFormat
QWASAPIAudioSourceStream(QAudioDevice, const QAudioFormat &, std::optional< qsizetype > ringbufferSize, QWindowsAudioSource *parent, float volume, std::optional< int32_t > hardwareBufferFrames)