6#include <QtMultimedia/private/qaudio_alignment_support_p.h>
7#include <QtMultimedia/private/qaudiohelpers_p.h>
8#include <QtMultimedia/private/qaudiosystem_p.h>
9#include <QtMultimedia/private/qplatformaudiodevices_p.h>
10#include <QtMultimedia/private/qplatformmediaintegration_p.h>
11#include <QtMultimedia/qaudio.h>
12#include <QtMultimedia/qaudiodevice.h>
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
119
120
121
122
123
125QAudioSource::QAudioSource(
const QAudioFormat &format, QObject *parent)
126 : QAudioSource({}, format, parent)
131
132
133
134
135
137QAudioSource::QAudioSource(
const QAudioDevice &audioDevice,
const QAudioFormat &format, QObject *parent):
140 d = QPlatformMediaIntegration::instance()->audioDevices()->audioInputDevice(format, audioDevice,
143 connect(d, &QPlatformAudioSource::stateChanged,
this, &QAudioSource::stateChanged);
145 qWarning(
"No audio device detected");
149
150
151
152
155
156
158QAudioSource::~QAudioSource()
165 if (!d->format().isValid()) {
166 qWarning() <<
"QAudioSource::start: QAudioFormat not valid";
167 d->setError(QAudio::OpenError);
171 if (!d->isFormatSupported(d->format())) {
172 qWarning() <<
"QAudioSource::start: QAudioFormat not supported by QAudioDevice";
173 d->setError(QAudio::OpenError);
180
181
182
183
184
185
186
187
188
189
190
191
192
194void QAudioSource::start(QIODevice* device)
199 d->setError(QAudio::NoError);
201 if (!device->isWritable()) {
202 qWarning() <<
"QAudioSource::start: QIODevice is not writable";
203 d->setError(QAudio::OpenError);
207 if (!validateFormatAtStart(d))
210 d->elapsedTime.start();
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
232QIODevice* QAudioSource::start()
237 d->setError(QAudio::NoError);
239 if (!validateFormatAtStart(d))
242 d->elapsedTime.start();
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
267void QAudioSource::startImpl(T &&callback)
272 if (!d->hasCallbackAPI()) {
273 qWarning() <<
"QAudioSource::start: Callback API not supported on this platform";
274 d->setError(QAudio::OpenError);
278 using namespace QtMultimediaPrivate;
279 if (!validateAudioCallback(callback, format())) {
280 d->setError(QAudio::OpenError);
284 if (!validateFormatAtStart(d))
287 d->elapsedTime.start();
288 d->start(std::forward<T>(callback));
291void QAudioSource::startABIImpl(QtAudioPrivate::AudioSourceCallback &&callback)
293 return QAudioSource::startImpl(QtMultimediaPrivate::asAudioSourceCallback(std::move(callback)));
297
298
300QAudioFormat QAudioSource::format()
const
302 return d ? d->format() : QAudioFormat();
306
307
308
309
310
312void QAudioSource::stop()
319
320
322void QAudioSource::reset()
329
330
331
332
333
335void QAudioSource::suspend()
342
343
344
345
346
348void QAudioSource::resume()
355
356
357
358
359
360
361
362
363
364
365
366
368void QAudioSource::setBufferSize(qsizetype value)
371 d->setBufferSize(value);
375
376
377
378
379
380
381
382
383
384
386qsizetype QAudioSource::bufferSize()
const
388 return d ? d->bufferSize() : 0;
392
393
394
395
396
397
398
399
400
401
402
403
404
406void QAudioSource::setBufferFrameCount(qsizetype value)
409 setBufferSize(d->format().bytesForFrames(value));
413
414
415
416
417
418
419
420
421
422
423
425qsizetype QAudioSource::bufferFrameCount()
const
427 return d ? d->format().framesForBytes(bufferSize()) : 0;
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451void QAudioSource::setNativePeriodFrameCount(
int frameCount)
456 if (frameCount != -1) {
458 if (state() != QAudio::StoppedState) {
459 qWarning(
"QAudioSource::setNativePeriodFrameCount: can only be set when stopped");
463 if (frameCount < 32 || frameCount > 4096
464 || !QtMultimediaPrivate::isPowerOfTwo(frameCount)) {
465 qWarning(
"QAudioSource::setNativePeriodFrameCount: invalid frame count %d "
466 "(must be -1 or a power of 2 between 32 and 4096)",
472 if (frameCount != -1)
473 d->setNativePeriodFrames(QtMultimediaPrivate::NativePeriodFrames(frameCount));
475 d->setNativePeriodFrames(std::nullopt);
479
480
481
482
483
484
485
486
487int QAudioSource::nativePeriodFrameCount()
const
489 std::optional hwbf = d ? d->nativePeriodFrames() : std::nullopt;
490 return hwbf ? qToUnderlying(*hwbf) : -1;
494
495
496
497
498
499
500
502qsizetype QAudioSource::bytesAvailable()
const
504 return d ? d->bytesReady() : 0;
508
509
510
511
512
513
514
515
517qsizetype QAudioSource::framesAvailable()
const
520 return d ? d->format().framesForBytes(bytesAvailable()) : 0;
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538void QAudioSource::setVolume(qreal volume)
543 std::optional<
float> newVolume = QAudioHelperInternal::sanitizeVolume(volume,
this->volume());
545 d->setVolume(*newVolume);
549
550
551
552
553
554qreal QAudioSource::volume()
const
556 return d ? d->volume() : 1.0;
560
561
562
564qint64 QAudioSource::processedUSecs()
const
566 return d ? d->processedUSecs() : 0;
570
571
572
574qint64 QAudioSource::elapsedUSecs()
const
576 return state() == QAudio::StoppedState ? 0 : d->elapsedTime.nsecsElapsed()/1000;
580
581
583QtAudio::Error QAudioSource::error()
const
585 return d ? d->error() : QAudio::OpenError;
589
590
592QtAudio::State QAudioSource::state()
const
594 return d ? d->state() : QAudio::StoppedState;
598
599
600
601
602
603
604
608#include "moc_qaudiosource.cpp"
Combined button and popup list for selecting options.
static bool validateFormatAtStart(QPlatformAudioSource *d)