Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
30
struct
IAudioRenderClient;
31
32
QT_BEGIN_NAMESPACE
33
34
class
QWindowsResampler;
35
36
namespace
QtWASAPI
{
37
38
class
QWindowsAudioSink;
39
using
namespace
QtMultimediaPrivate
;
40
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43
struct
QWASAPIAudioSinkStream
final
:
std
::
enable_shared_from_this
<
QWASAPIAudioSinkStream
>,
44
QPlatformAudioSinkStream
45
{
46
using
SampleFormat
=
QAudioFormat
::
SampleFormat
;
47
using
SinkType
= QWindowsAudioSink;
48
49
enum
class
StreamType
:
uint8_t
{
50
Ringbuffer
,
51
Callback
,
52
};
53
54
QWASAPIAudioSinkStream
(
QAudioDevice
,
const
QAudioFormat &,
55
std::optional<qsizetype> ringbufferSize, QWindowsAudioSink *parent,
56
float
volume, std::optional<NativePeriodFrames> nativePeriodFrames,
57
AudioEndpointRole
);
58
Q_DISABLE_COPY_MOVE
(
QWASAPIAudioSinkStream
)
59
~
QWASAPIAudioSinkStream
() =
default
;
60
61
bool
open
();
62
63
using
QPlatformAudioSinkStream
::
bytesFree
;
64
using
QPlatformAudioSinkStream
::
processedDuration
;
65
using
QPlatformAudioSinkStream
::
ringbufferSizeInBytes
;
66
using
QPlatformAudioSinkStream
::
setVolume
;
67
68
bool
start
(QIODevice *);
69
QIODevice
*
start
();
70
bool
start
(
AudioCallback
);
71
72
void
suspend
();
73
void
resume
();
74
void
stop
(
ShutdownPolicy
);
75
76
void
updateStreamIdle
(
bool
)
override
;
77
78
private
:
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
Q_DECL_NONBLOCKING_FUNCTION
;
89
bool
processCallback()
noexcept
Q_DECL_NONBLOCKING_FUNCTION
;
90
91
void
handleAudioClientError();
92
void
joinWorkerThread();
93
94
ComPtr<IAudioClient3> m_audioClient;
95
ComPtr<IAudioRenderClient> m_renderClient;
96
97
QWMF::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_audioClientEventHandle;
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
121
class
QWindowsAudioSink
final
122
:
public
QPlatformAudioSinkImplementation<QWASAPIAudioSinkStream, QWindowsAudioSink>
123
{
124
using
BaseClass = QPlatformAudioSinkImplementation<QWASAPIAudioSinkStream, QWindowsAudioSink>;
125
126
public
:
127
QWindowsAudioSink
(
QAudioDevice
,
const
QAudioFormat &, QObject *parent);
128
~
QWindowsAudioSink
()
override
;
129
};
130
131
}
// namespace QtWASAPI
132
133
QT_END_NAMESPACE
134
135
#
endif
// QWINDOWSAUDIOSINK_H
QtWASAPI::QWindowsAudioSink::QWindowsAudioSink
QWindowsAudioSink(QAudioDevice, const QAudioFormat &, QObject *parent)
Definition
qwindowsaudiosink.cpp:426
QtWASAPI::QWindowsAudioSink::~QWindowsAudioSink
~QWindowsAudioSink() override
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtWASAPI
Definition
qwindowsaudiodevice_p.h:34
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
QtWASAPI::QWASAPIAudioSinkStream::start
QIODevice * start()
Definition
qwindowsaudiosink.cpp:101
QtWASAPI::QWASAPIAudioSinkStream::updateStreamIdle
void updateStreamIdle(bool) override
Definition
qwindowsaudiosink.cpp:177
QtWASAPI::QWASAPIAudioSinkStream::QWASAPIAudioSinkStream
QWASAPIAudioSinkStream(QAudioDevice, const QAudioFormat &, std::optional< qsizetype > ringbufferSize, QWindowsAudioSink *parent, float volume, std::optional< NativePeriodFrames > nativePeriodFrames, AudioEndpointRole)
Definition
qwindowsaudiosink.cpp:58
QtWASAPI::QWASAPIAudioSinkStream::SampleFormat
QAudioFormat::SampleFormat SampleFormat
Definition
qwindowsaudiosink_p.h:46
QtWASAPI::QWASAPIAudioSinkStream::StreamType
StreamType
Definition
qwindowsaudiosink_p.h:49
QtWASAPI::QWASAPIAudioSinkStream::StreamType::Callback
@ Callback
Definition
qwindowsaudiosink_p.h:51
QtWASAPI::QWASAPIAudioSinkStream::StreamType::Ringbuffer
@ Ringbuffer
Definition
qwindowsaudiosink_p.h:50
QtWASAPI::QWASAPIAudioSinkStream::suspend
void suspend()
Definition
qwindowsaudiosink.cpp:137
QtWASAPI::QWASAPIAudioSinkStream::start
bool start(QIODevice *)
Definition
qwindowsaudiosink.cpp:84
QtWASAPI::QWASAPIAudioSinkStream::start
bool start(AudioCallback)
Definition
qwindowsaudiosink.cpp:122
QtWASAPI::QWASAPIAudioSinkStream::open
bool open()
Definition
qwindowsaudiosink.cpp:79
QtWASAPI::QWASAPIAudioSinkStream::resume
void resume()
Definition
qwindowsaudiosink.cpp:143
QtWASAPI::QWASAPIAudioSinkStream::SinkType
QWindowsAudioSink SinkType
Definition
qwindowsaudiosink_p.h:47
QtWASAPI::QWASAPIAudioSinkStream::stop
void stop(ShutdownPolicy)
Definition
qwindowsaudiosink.cpp:149
qtmultimedia
src
multimedia
windows
qwindowsaudiosink_p.h
Generated on
for Qt by
1.18.0