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
qaudio_platform_implementation_support_p.h
Go to the documentation of this file.
1
// Copyright (C) 2025 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
#
ifndef
QAUDIO_PLATFORM_IMPLEMENTATION_SUPPORT_P_H
5
#
define
QAUDIO_PLATFORM_IMPLEMENTATION_SUPPORT_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QtMultimedia
/
private
/
qaudiosystem_p
.
h
>
19
#
include
<
QtMultimedia
/
private
/
qaudiosystem_platform_stream_support_p
.
h
>
20
#
include
<
QtMultimedia
/
qtmultimediaglobal
.
h
>
21
22
QT_BEGIN_NAMESPACE
23
24
namespace
QtMultimediaPrivate
{
25
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27
28
#
ifdef
__cpp_concepts
29
// clang-format off
30
template
<
typename
T
>
31
concept
QPlatformSinkStream
=
requires
(
T
t
,
QIODevice
*
device
,
32
QPlatformAudioIOStream
::
ShutdownPolicy
shutdownPolicy
,
33
AudioSinkCallback
callback
)
34
{
35
requires
std
::
constructible_from
<
36
T
,
37
QAudioDevice
,
38
const
QAudioFormat
&,
39
std
::
optional
<
qsizetype
>,
40
typename
T
::
SinkType
*,
41
float
,
42
std
::
optional
<
NativePeriodFrames
>,
43
AudioEndpointRole
44
>;
45
46
{
t
.
open
() } ->
std
::
same_as
<
bool
>;
47
48
{
t
.
start
() } ->
std
::
same_as
<
QIODevice
*>;
49
{
t
.
start
(
device
) } ->
std
::
same_as
<
bool
>;
50
{
t
.
start
(
std
::
move
(
callback
)) } ->
std
::
same_as
<
bool
>;
51
52
{
t
.
suspend
() } ->
std
::
same_as
<
void
>;
53
{
t
.
resume
() };
54
{
t
.
stop
(
shutdownPolicy
) } ->
std
::
same_as
<
void
>;
55
56
{
t
.
setVolume
(0.0f) } ->
std
::
same_as
<
void
>;
57
{
t
.
bytesFree
() } ->
std
::
same_as
<
quint64
>;
58
59
{
t
.
processedDuration
() } ->
std
::
same_as
<
std
::
chrono
::
microseconds
>;
60
};
61
62
// clang-format on
63
#
define
STREAM_TYPE_ARG
QPlatformSinkStream
StreamType
64
#
else
65
#
define
STREAM_TYPE_ARG
typename
StreamType
66
#
endif
67
68
template
<
STREAM_TYPE_ARG
,
typename
DerivedType =
void
>
69
class
QPlatformAudioSinkImplementation
:
public
QPlatformAudioSink
70
{
71
public
:
72
QPlatformAudioSinkImplementation
(QAudioDevice device,
const
QAudioFormat &format,
73
QObject *parent);
74
~
QPlatformAudioSinkImplementation
()
override
;
75
76
void
start
(QIODevice *device)
override
;
77
void
start
(AudioCallback &&)
override
;
78
QIODevice
*
start
()
override
;
79
80
void
stop
()
override
final
;
81
void
reset
()
override
;
82
83
void
suspend
()
override
;
84
void
resume
()
override
;
85
86
qsizetype
bytesFree
()
const
override
;
87
void
setBufferSize
(qsizetype value)
override
;
88
qsizetype
bufferSize
()
const
override
;
89
void
setNativePeriodFrames
(
std
::
optional
<
NativePeriodFrames
>)
override
;
90
std
::
optional
<
NativePeriodFrames
>
nativePeriodFrames
()
override
;
91
qint64
processedUSecs
()
const
override
;
92
93
void
setVolume
(
float
volume)
override
;
94
bool
hasCallbackAPI
()
override
;
95
void
setRole
(AudioEndpointRole role)
override
;
96
97
protected
:
98
void
handleStreamOpenError
();
99
100
friend
class
QtMultimediaPrivate
::
QPlatformAudioSinkStream
;
101
friend
StreamType;
102
using
ShutdownPolicy
=
QPlatformAudioIOStream
::
ShutdownPolicy
;
103
104
std
::
optional
<
int
>
m_internalBufferSize
;
105
std
::
optional
<
NativePeriodFrames
>
m_nativePeriodFrames
;
106
AudioEndpointRole
m_role
=
AudioEndpointRole
::
Other
;
107
108
std
::
shared_ptr
<
StreamType
>
m_stream
;
109
110
using
ConcreteSinkType
=
std
::
conditional_t
<
std
::
is_same_v
<
DerivedType
,
void
>,
111
QPlatformAudioSinkImplementation
,
DerivedType
>;
112
};
113
114
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
115
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
QPlatformAudioSinkImplementation
(
116
QAudioDevice device,
const
QAudioFormat &format, QObject *parent)
117
:
QPlatformAudioSink
(
std
::
move
(
device
),
format
,
parent
)
118
{
119
}
120
121
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
122
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::~
QPlatformAudioSinkImplementation
()
123
{
124
stop
(
)
;
125
}
126
127
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
128
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
start
(QIODevice *device)
129
{
130
if
(!device) {
131
setError(QAudio::IOError);
132
return
;
133
}
134
135
if
(m_stream) {
136
qWarning(
"QAudioSink::start() called while already started"
);
137
return
;
138
}
139
140
m_stream = std::make_shared<StreamType>(m_audioDevice, m_format, m_internalBufferSize,
141
static_cast
<ConcreteSinkType *>(
this
), volume(),
142
m_nativePeriodFrames, m_role);
143
144
if
(!m_stream->open())
145
return
handleStreamOpenError
(
)
;
146
147
bool
started = m_stream->start(device);
148
if
(!started)
149
return
handleStreamOpenError
(
)
;
150
151
updateStreamState(QAudio::ActiveState);
152
}
153
154
155
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
156
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
handleStreamOpenError
()
157
{
158
m_stream->requestStop();
159
setError(QAudio::OpenError);
160
m_stream = {};
161
}
162
163
164
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
165
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
start
(AudioCallback &&audioCallback)
166
{
167
using
namespace
QtMultimediaPrivate
;
168
if
(m_stream) {
169
qWarning(
"QAudioSink::start() called while already started"
);
170
return
;
171
}
172
173
m_stream = std::make_shared<StreamType>(m_audioDevice, m_format, m_internalBufferSize,
174
static_cast
<ConcreteSinkType *>(
this
), volume(),
175
m_nativePeriodFrames, m_role);
176
177
if
(!m_stream->open())
178
return
handleStreamOpenError
(
)
;
179
180
bool
started = m_stream->start(std::move(audioCallback));
181
if
(!started)
182
return
handleStreamOpenError
(
)
;
183
184
updateStreamState(QAudio::ActiveState);
185
}
186
187
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
188
QIODevice
*
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
start
()
189
{
190
if
(m_stream) {
191
qWarning(
"QAudioSink::start() called while already started"
);
192
return
nullptr
;
193
}
194
195
m_stream = std::make_shared<StreamType>(m_audioDevice, m_format, m_internalBufferSize,
196
static_cast
<ConcreteSinkType *>(
this
), volume(),
197
m_nativePeriodFrames, m_role);
198
199
if
(!m_stream->open()) {
200
handleStreamOpenError
(
)
;
201
return
nullptr
;
202
}
203
204
QIODevice *device = m_stream->start();
205
if
(!device) {
206
handleStreamOpenError
(
)
;
207
return
nullptr
;
208
}
209
210
QObject::connect(device, &QIODevice::readyRead,
this
, [
this
] {
211
updateStreamIdle(
false
);
212
});
213
updateStreamIdle(
true
);
214
updateStreamState(QAudio::ActiveState);
215
return
device;
216
}
217
218
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
219
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
stop
()
220
{
221
if
(m_stream) {
222
m_stream->stop(ShutdownPolicy::DrainRingbuffer);
223
m_stream = {};
224
updateStreamState(QAudio::StoppedState);
225
}
226
setError(QtAudio::NoError);
227
}
228
229
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
230
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
reset
()
231
{
232
if
(m_stream) {
233
m_stream->stop(ShutdownPolicy::DiscardRingbuffer);
234
m_stream = {};
235
updateStreamState(QAudio::StoppedState);
236
}
237
setError(QtAudio::NoError);
238
}
239
240
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
241
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
suspend
()
242
{
243
if
(m_stream) {
244
if
(state() == QAudio::SuspendedState)
245
return
;
246
247
m_stream->suspend();
248
updateStreamState(QAudio::SuspendedState);
249
}
250
}
251
252
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
253
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
resume
()
254
{
255
if
(m_stream) {
256
if
(state() != QAudio::SuspendedState)
257
return
;
258
259
updateStreamState(QAudio::ActiveState);
260
m_stream->resume();
261
}
262
}
263
264
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
265
qsizetype
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
bytesFree
()
const
266
{
267
if
(m_stream)
268
return
m_stream->bytesFree();
269
return
0;
270
}
271
272
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
273
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
setBufferSize
(qsizetype value)
274
{
275
m_internalBufferSize = value;
276
}
277
278
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
279
qsizetype
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
bufferSize
()
const
280
{
281
if
(m_stream)
282
return
m_stream->ringbufferSizeInBytes();
283
284
return
QPlatformAudioIOStream::inferRingbufferBytes(m_internalBufferSize,
285
m_nativePeriodFrames, m_format);
286
}
287
288
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
289
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::setNativePeriodFrames(
290
std
::
optional
<
NativePeriodFrames
>
arg
)
291
{
292
m_nativePeriodFrames
=
arg
;
293
}
294
295
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
296
std
::
optional
<
NativePeriodFrames
>
297
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
nativePeriodFrames
()
298
{
299
return
m_nativePeriodFrames;
300
}
301
302
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
303
qint64
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
processedUSecs
()
const
304
{
305
if
(m_stream)
306
return
m_stream->processedDuration().count();
307
308
return
0;
309
}
310
311
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
312
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
setVolume
(
float
volume)
313
{
314
QPlatformAudioEndpointBase::setVolume(volume);
315
if
(m_stream)
316
m_stream->setVolume(volume);
317
}
318
319
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
320
bool
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
hasCallbackAPI
()
321
{
322
return
true
;
323
}
324
325
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
326
void
QPlatformAudioSinkImplementation
<StreamType, DerivedType>::
setRole
(AudioEndpointRole role)
327
{
328
m_role = role;
329
}
330
331
#
undef
STREAM_TYPE_ARG
332
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334
335
#
ifdef
__cpp_concepts
336
// clang-format off
337
template
<
typename
T
>
338
concept
QPlatformSourceStream
=
requires
(
T
t
,
QIODevice
*
device
,
339
QPlatformAudioIOStream
::
ShutdownPolicy
shutdownPolicy
)
340
{
341
requires
std
::
constructible_from
<
342
T
,
343
QAudioDevice
,
344
const
QAudioFormat
&,
345
std
::
optional
<
qsizetype
>,
346
typename
T
::
SourceType
*,
347
float
,
348
std
::
optional
<
NativePeriodFrames
>
349
>;
350
351
{
t
.
open
() } ->
std
::
same_as
<
bool
>;
352
353
{
t
.
start
() } ->
std
::
same_as
<
QIODevice
*>;
354
{
t
.
start
(
device
) } ->
std
::
same_as
<
bool
>;
355
356
{
t
.
suspend
() } ->
std
::
same_as
<
void
>;
357
{
t
.
resume
() };
358
{
t
.
stop
(
shutdownPolicy
) } ->
std
::
same_as
<
void
>;
359
360
{
t
.
setVolume
(0.0f) } ->
std
::
same_as
<
void
>;
361
{
t
.
bytesReady
() } ->
std
::
same_as
<
qsizetype
>;
362
{
t
.
deviceIsRingbufferReader
() } ->
std
::
same_as
<
bool
>;
363
364
{
t
.
processedDuration
() } ->
std
::
same_as
<
std
::
chrono
::
microseconds
>;
365
};
366
367
// clang-format on
368
#
define
STREAM_TYPE_ARG
QPlatformSourceStream
StreamType
369
#
else
370
#
define
STREAM_TYPE_ARG
typename
StreamType
371
#
endif
372
373
template
<
STREAM_TYPE_ARG
,
typename
DerivedType =
void
>
374
class
QPlatformAudioSourceImplementation
:
public
QPlatformAudioSource
375
{
376
public
:
377
QPlatformAudioSourceImplementation
(QAudioDevice device,
const
QAudioFormat &format,
378
QObject *parent);
379
~
QPlatformAudioSourceImplementation
()
override
;
380
381
void
start
(QIODevice *device)
override
;
382
QIODevice
*
start
()
override
;
383
384
void
stop
()
override
final
;
385
void
reset
()
override
;
386
387
void
suspend
()
override
;
388
void
resume
()
override
;
389
390
qsizetype
bytesReady
()
const
override
;
391
void
setBufferSize
(qsizetype value)
override
;
392
qsizetype
bufferSize
()
const
override
;
393
void
setNativePeriodFrames
(
std
::
optional
<
NativePeriodFrames
>)
override
;
394
std
::
optional
<
NativePeriodFrames
>
nativePeriodFrames
()
override
;
395
qint64
processedUSecs
()
const
override
;
396
397
void
setVolume
(
float
volume)
override
;
398
399
protected
:
400
void
handleStreamOpenError
();
401
402
friend
class
QtMultimediaPrivate
::
QPlatformAudioSourceStream
;
403
friend
StreamType;
404
using
ShutdownPolicy
=
QPlatformAudioIOStream
::
ShutdownPolicy
;
405
406
std
::
optional
<
int
>
m_internalBufferSize
;
407
std
::
optional
<
NativePeriodFrames
>
m_nativePeriodFrames
;
408
409
std
::
shared_ptr
<
StreamType
>
m_stream
;
410
std
::
shared_ptr
<
StreamType
>
m_retiredStream
;
411
412
using
ConcreteSourceType
=
std
::
conditional_t
<
std
::
is_same_v
<
DerivedType
,
void
>,
413
QPlatformAudioSourceImplementation
,
DerivedType
>;
414
};
415
416
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
417
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
QPlatformAudioSourceImplementation
(
418
QAudioDevice device,
const
QAudioFormat &format, QObject *parent)
419
:
QPlatformAudioSource
(
std
::
move
(
device
),
format
,
parent
)
420
{
421
}
422
423
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
424
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::~
QPlatformAudioSourceImplementation
()
425
{
426
stop
(
)
;
427
}
428
429
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
430
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
handleStreamOpenError
()
431
{
432
m_stream->requestStop();
433
setError(QAudio::OpenError);
434
m_stream = {};
435
}
436
437
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
438
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
start
(QIODevice *device)
439
{
440
if
(!device) {
441
setError(QAudio::IOError);
442
return
;
443
}
444
445
if
(m_stream) {
446
qWarning(
"QAudioSource::start() called while already started"
);
447
return
;
448
}
449
450
m_stream = std::make_shared<StreamType>(m_audioDevice, m_format, m_internalBufferSize,
451
static_cast
<ConcreteSourceType *>(
this
), volume(),
452
m_nativePeriodFrames);
453
454
if
(!m_stream->open())
455
return
handleStreamOpenError
(
)
;
456
457
bool
started = m_stream->start(device);
458
if
(!started)
459
return
handleStreamOpenError
(
)
;
460
461
updateStreamState(QAudio::ActiveState);
462
}
463
464
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
465
QIODevice
*
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
start
()
466
{
467
if
(m_stream) {
468
qWarning(
"QAudioSource::start() called while already started"
);
469
return
nullptr
;
470
}
471
472
m_stream = std::make_shared<StreamType>(m_audioDevice, m_format, m_internalBufferSize,
473
static_cast
<ConcreteSourceType *>(
this
), volume(),
474
m_nativePeriodFrames);
475
476
if
(!m_stream->open()) {
477
handleStreamOpenError
(
)
;
478
return
nullptr
;
479
}
480
481
QIODevice *device = m_stream->start();
482
if
(!device) {
483
handleStreamOpenError
(
)
;
484
return
nullptr
;
485
}
486
487
QObject::connect(device, &QIODevice::readyRead,
this
, [
this
] {
488
updateStreamIdle(
false
);
489
});
490
updateStreamIdle(
true
, EmitStateSignal::False);
491
updateStreamState(QAudio::ActiveState);
492
return
device;
493
}
494
495
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
496
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
stop
()
497
{
498
if
(!m_stream)
499
return
;
500
501
if
(m_stream->deviceIsRingbufferReader())
502
// we own the qiodevice, so let's keep it alive to allow users to drain the ringbuffer
503
m_retiredStream = m_stream;
504
505
m_stream->stop(ShutdownPolicy::DrainRingbuffer);
506
m_stream = {};
507
setError(QtAudio::NoError);
508
updateStreamState(QAudio::StoppedState);
509
}
510
511
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
512
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
reset
()
513
{
514
m_retiredStream = {};
515
516
if
(!m_stream)
517
return
;
518
519
m_stream->stop(ShutdownPolicy::DiscardRingbuffer);
520
m_stream = {};
521
setError(QtAudio::NoError);
522
updateStreamState(QAudio::StoppedState);
523
}
524
525
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
526
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
suspend
()
527
{
528
if
(m_stream) {
529
m_stream->suspend();
530
updateStreamState(QAudio::SuspendedState);
531
}
532
}
533
534
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
535
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
resume
()
536
{
537
if
(m_stream) {
538
updateStreamState(QAudio::ActiveState);
539
m_stream->resume();
540
}
541
}
542
543
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
544
qsizetype
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
bytesReady
()
const
545
{
546
return
m_stream ? m_stream->bytesReady() : 0;
547
}
548
549
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
550
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
setBufferSize
(qsizetype value)
551
{
552
m_internalBufferSize = value;
553
}
554
555
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
556
qsizetype
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
bufferSize
()
const
557
{
558
if
(m_stream)
559
return
m_stream->ringbufferSizeInBytes();
560
561
return
QPlatformAudioIOStream::inferRingbufferBytes(m_internalBufferSize,
562
m_nativePeriodFrames, m_format);
563
}
564
565
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
566
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::setNativePeriodFrames(
567
std
::
optional
<
NativePeriodFrames
>
arg
)
568
{
569
m_nativePeriodFrames
=
arg
;
570
}
571
572
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
573
std
::
optional
<
NativePeriodFrames
>
574
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
nativePeriodFrames
()
575
{
576
return
m_nativePeriodFrames;
577
}
578
579
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
580
qint64
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
processedUSecs
()
const
581
{
582
return
m_stream ? m_stream->processedDuration().count() : 0;
583
}
584
585
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
586
void
QPlatformAudioSourceImplementation
<StreamType, DerivedType>::
setVolume
(
float
volume)
587
{
588
QPlatformAudioEndpointBase::setVolume(volume);
589
if
(m_stream)
590
m_stream->setVolume(volume);
591
}
592
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594
595
template
<
STREAM_TYPE_ARG
,
typename
DerivedType =
void
>
596
class
QPlatformAudioSourceImplementationWithCallback
597
:
public
QPlatformAudioSourceImplementation
<StreamType, DerivedType>
598
{
599
protected
:
600
using
BaseClass
=
QPlatformAudioSourceImplementation
<StreamType, DerivedType>;
601
using
BaseClass
::
BaseClass
;
602
using
BaseClass
::start;
603
604
QT_WARNING_PUSH
605
QT_WARNING_DISABLE_CLANG(
"-Woverloaded-virtual"
)
606
void
start
(QPlatformAudioSource::AudioCallback &&)
override
;
607
QT_WARNING_POP
608
bool
hasCallbackAPI
()
override
{
return
true
; }
609
};
610
611
template
<
STREAM_TYPE_ARG
,
typename
DerivedType>
612
void
QPlatformAudioSourceImplementationWithCallback
<StreamType, DerivedType>::
start
(
613
QPlatformAudioSource::AudioCallback &&audioCallback)
614
{
615
using
namespace
QtMultimediaPrivate
;
616
617
BaseClass
::m_stream = std::make_shared<StreamType>(
618
BaseClass::m_audioDevice, BaseClass::m_format, BaseClass::m_internalBufferSize,
619
static_cast
<
typename
BaseClass::ConcreteSourceType *>(
this
), BaseClass::volume(),
620
BaseClass::m_nativePeriodFrames);
621
622
if
(!
BaseClass
::m_stream->open())
623
return
BaseClass
::handleStreamOpenError();
624
625
bool
started =
BaseClass
::m_stream->start(std::move(audioCallback));
626
if
(!started)
627
return
BaseClass
::handleStreamOpenError();
628
629
BaseClass
::updateStreamState(QAudio::ActiveState);
630
}
631
632
#
undef
STREAM_TYPE_ARG
633
634
}
// namespace QtMultimediaPrivate
635
636
QT_END_NAMESPACE
637
638
#
endif
// QAUDIO_PLATFORM_IMPLEMENTATION_SUPPORT_P_H
QtMultimediaPrivate::QPlatformAudioSinkImplementation
Definition
qaudio_platform_implementation_support_p.h:70
QtMultimediaPrivate::QPlatformAudioSinkImplementation::bufferSize
qsizetype bufferSize() const override
Definition
qaudio_platform_implementation_support_p.h:279
QtMultimediaPrivate::QPlatformAudioSinkImplementation::m_nativePeriodFrames
std::optional< NativePeriodFrames > m_nativePeriodFrames
Definition
qaudio_platform_implementation_support_p.h:105
QtMultimediaPrivate::QPlatformAudioSinkImplementation::m_stream
std::shared_ptr< StreamType > m_stream
Definition
qaudio_platform_implementation_support_p.h:108
QtMultimediaPrivate::QPlatformAudioSinkImplementation::setRole
void setRole(AudioEndpointRole role) override
Definition
qaudio_platform_implementation_support_p.h:326
QtMultimediaPrivate::QPlatformAudioSinkImplementation::nativePeriodFrames
std::optional< NativePeriodFrames > nativePeriodFrames() override
Definition
qaudio_platform_implementation_support_p.h:297
QtMultimediaPrivate::QPlatformAudioSinkImplementation::setNativePeriodFrames
void setNativePeriodFrames(std::optional< NativePeriodFrames >) override
Definition
qaudio_platform_implementation_support_p.h:289
QtMultimediaPrivate::QPlatformAudioSinkImplementation::stop
void stop() override final
Definition
qaudio_platform_implementation_support_p.h:219
QtMultimediaPrivate::QPlatformAudioSinkImplementation::m_role
AudioEndpointRole m_role
Definition
qaudio_platform_implementation_support_p.h:106
QtMultimediaPrivate::QPlatformAudioSinkImplementation::bytesFree
qsizetype bytesFree() const override
Definition
qaudio_platform_implementation_support_p.h:265
QtMultimediaPrivate::QPlatformAudioSinkImplementation::processedUSecs
qint64 processedUSecs() const override
Definition
qaudio_platform_implementation_support_p.h:303
QtMultimediaPrivate::QPlatformAudioSinkImplementation::start
void start(AudioCallback &&) override
Definition
qaudio_platform_implementation_support_p.h:165
QtMultimediaPrivate::QPlatformAudioSinkImplementation::setBufferSize
void setBufferSize(qsizetype value) override
Definition
qaudio_platform_implementation_support_p.h:273
QtMultimediaPrivate::QPlatformAudioSinkImplementation::QPlatformAudioSinkImplementation
QPlatformAudioSinkImplementation(QAudioDevice device, const QAudioFormat &format, QObject *parent)
Definition
qaudio_platform_implementation_support_p.h:115
QtMultimediaPrivate::QPlatformAudioSinkImplementation::setVolume
void setVolume(float volume) override
Definition
qaudio_platform_implementation_support_p.h:312
QtMultimediaPrivate::QPlatformAudioSinkImplementation::resume
void resume() override
Definition
qaudio_platform_implementation_support_p.h:253
QtMultimediaPrivate::QPlatformAudioSinkImplementation::start
void start(QIODevice *device) override
Definition
qaudio_platform_implementation_support_p.h:128
QtMultimediaPrivate::QPlatformAudioSinkImplementation::reset
void reset() override
Definition
qaudio_platform_implementation_support_p.h:230
QtMultimediaPrivate::QPlatformAudioSinkImplementation::handleStreamOpenError
void handleStreamOpenError()
Definition
qaudio_platform_implementation_support_p.h:156
QtMultimediaPrivate::QPlatformAudioSinkImplementation::m_internalBufferSize
std::optional< int > m_internalBufferSize
Definition
qaudio_platform_implementation_support_p.h:104
QtMultimediaPrivate::QPlatformAudioSinkImplementation::~QPlatformAudioSinkImplementation
~QPlatformAudioSinkImplementation() override
Definition
qaudio_platform_implementation_support_p.h:122
QtMultimediaPrivate::QPlatformAudioSinkImplementation::hasCallbackAPI
bool hasCallbackAPI() override
Definition
qaudio_platform_implementation_support_p.h:320
QtMultimediaPrivate::QPlatformAudioSinkImplementation::suspend
void suspend() override
Definition
qaudio_platform_implementation_support_p.h:241
QtMultimediaPrivate::QPlatformAudioSinkImplementation::start
QIODevice * start() override
Definition
qaudio_platform_implementation_support_p.h:188
QtMultimediaPrivate::QPlatformAudioSourceImplementationWithCallback
Definition
qaudio_platform_implementation_support_p.h:598
QtMultimediaPrivate::QPlatformAudioSourceImplementationWithCallback::start
QT_WARNING_PUSH void start(QPlatformAudioSource::AudioCallback &&) override
Definition
qaudio_platform_implementation_support_p.h:612
QtMultimediaPrivate::QPlatformAudioSourceImplementationWithCallback::BaseClass
QPlatformAudioSourceImplementation< StreamType, DerivedType > BaseClass
Definition
qaudio_platform_implementation_support_p.h:600
QtMultimediaPrivate::QPlatformAudioSourceImplementationWithCallback::hasCallbackAPI
QT_WARNING_POP bool hasCallbackAPI() override
Definition
qaudio_platform_implementation_support_p.h:608
QtMultimediaPrivate::QPlatformAudioSourceImplementation
Definition
qaudio_platform_implementation_support_p.h:375
QtMultimediaPrivate::QPlatformAudioSourceImplementation::handleStreamOpenError
void handleStreamOpenError()
Definition
qaudio_platform_implementation_support_p.h:430
QtMultimediaPrivate::QPlatformAudioSourceImplementation::setBufferSize
void setBufferSize(qsizetype value) override
Definition
qaudio_platform_implementation_support_p.h:550
QtMultimediaPrivate::QPlatformAudioSourceImplementation::suspend
void suspend() override
Definition
qaudio_platform_implementation_support_p.h:526
QtMultimediaPrivate::QPlatformAudioSourceImplementation::reset
void reset() override
Definition
qaudio_platform_implementation_support_p.h:512
QtMultimediaPrivate::QPlatformAudioSourceImplementation::nativePeriodFrames
std::optional< NativePeriodFrames > nativePeriodFrames() override
Definition
qaudio_platform_implementation_support_p.h:574
QtMultimediaPrivate::QPlatformAudioSourceImplementation::resume
void resume() override
Definition
qaudio_platform_implementation_support_p.h:535
QtMultimediaPrivate::QPlatformAudioSourceImplementation::QPlatformAudioSourceImplementation
QPlatformAudioSourceImplementation(QAudioDevice device, const QAudioFormat &format, QObject *parent)
Definition
qaudio_platform_implementation_support_p.h:417
QtMultimediaPrivate::QPlatformAudioSourceImplementation::setNativePeriodFrames
void setNativePeriodFrames(std::optional< NativePeriodFrames >) override
Definition
qaudio_platform_implementation_support_p.h:566
QtMultimediaPrivate::QPlatformAudioSourceImplementation::start
QIODevice * start() override
Definition
qaudio_platform_implementation_support_p.h:465
QtMultimediaPrivate::QPlatformAudioSourceImplementation::m_stream
std::shared_ptr< StreamType > m_stream
Definition
qaudio_platform_implementation_support_p.h:409
QtMultimediaPrivate::QPlatformAudioSourceImplementation::bytesReady
qsizetype bytesReady() const override
Definition
qaudio_platform_implementation_support_p.h:544
QtMultimediaPrivate::QPlatformAudioSourceImplementation::m_internalBufferSize
std::optional< int > m_internalBufferSize
Definition
qaudio_platform_implementation_support_p.h:406
QtMultimediaPrivate::QPlatformAudioSourceImplementation::setVolume
void setVolume(float volume) override
Definition
qaudio_platform_implementation_support_p.h:586
QtMultimediaPrivate::QPlatformAudioSourceImplementation::~QPlatformAudioSourceImplementation
~QPlatformAudioSourceImplementation() override
Definition
qaudio_platform_implementation_support_p.h:424
QtMultimediaPrivate::QPlatformAudioSourceImplementation::m_nativePeriodFrames
std::optional< NativePeriodFrames > m_nativePeriodFrames
Definition
qaudio_platform_implementation_support_p.h:407
QtMultimediaPrivate::QPlatformAudioSourceImplementation::stop
void stop() override final
Definition
qaudio_platform_implementation_support_p.h:496
QtMultimediaPrivate::QPlatformAudioSourceImplementation::m_retiredStream
std::shared_ptr< StreamType > m_retiredStream
Definition
qaudio_platform_implementation_support_p.h:410
QtMultimediaPrivate::QPlatformAudioSourceImplementation::bufferSize
qsizetype bufferSize() const override
Definition
qaudio_platform_implementation_support_p.h:556
QtMultimediaPrivate::QPlatformAudioSourceImplementation::start
void start(QIODevice *device) override
Definition
qaudio_platform_implementation_support_p.h:438
QtMultimediaPrivate::QPlatformAudioSourceImplementation::processedUSecs
qint64 processedUSecs() const override
Definition
qaudio_platform_implementation_support_p.h:580
QtMultimediaPrivate::impl
Definition
qaudiosystem_p.h:257
STREAM_TYPE_ARG
#define STREAM_TYPE_ARG
Definition
qaudio_platform_implementation_support_p.h:65
qtmultimedia
src
multimedia
audio
qaudio_platform_implementation_support_p.h
Generated on
for Qt by
1.18.0