6#include <QtMultimedia/qaudio.h>
7#include <QtMultimedia/qaudiodevice.h>
8#include <QtMultimedia/private/qaudiosystem_p.h>
9#include <QtMultimedia/private/qaudiohelpers_p.h>
10#include <QtMultimedia/private/qplatformaudiodevices_p.h>
11#include <QtMultimedia/private/qplatformmediaintegration_p.h>
16
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
118
119
120
121
122
124QAudioSource::QAudioSource(
const QAudioFormat &format, QObject *parent)
125 : QAudioSource({}, format, parent)
130
131
132
133
134
136QAudioSource::QAudioSource(
const QAudioDevice &audioDevice,
const QAudioFormat &format, QObject *parent):
139 d = QPlatformMediaIntegration::instance()->audioDevices()->audioInputDevice(format, audioDevice,
142 connect(d, &QPlatformAudioSource::stateChanged,
this, &QAudioSource::stateChanged);
144 qWarning(
"No audio device detected");
148
149
150
151
154
155
157QAudioSource::~QAudioSource()
164 if (!d->format().isValid()) {
165 qWarning() <<
"QAudioSource::start: QAudioFormat not valid";
166 d->setError(QAudio::OpenError);
170 if (!d->isFormatSupported(d->format())) {
171 qWarning() <<
"QAudioSource::start: QAudioFormat not supported by QAudioDevice";
172 d->setError(QAudio::OpenError);
179
180
181
182
183
184
185
186
187
188
189
190
191
193void QAudioSource::start(QIODevice* device)
198 d->setError(QAudio::NoError);
200 if (!device->isWritable()) {
201 qWarning() <<
"QAudioSource::start: QIODevice is not writable";
202 d->setError(QAudio::OpenError);
206 if (!validateFormatAtStart(d))
209 d->elapsedTime.start();
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
231QIODevice* QAudioSource::start()
236 d->setError(QAudio::NoError);
238 if (!validateFormatAtStart(d))
241 d->elapsedTime.start();
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
266void QAudioSource::startImpl(T &&callback)
271 if (!d->hasCallbackAPI()) {
272 qWarning() <<
"QAudioSource::start: Callback API not supported on this platform";
273 d->setError(QAudio::OpenError);
277 using namespace QtMultimediaPrivate;
278 if (!validateAudioCallback(callback, format())) {
279 d->setError(QAudio::OpenError);
283 if (!validateFormatAtStart(d))
286 d->elapsedTime.start();
287 d->start(std::forward<T>(callback));
290void QAudioSource::startABIImpl(QtAudioPrivate::AudioSourceCallback &&callback)
292 return QAudioSource::startImpl(QtMultimediaPrivate::asAudioSourceCallback(std::move(callback)));
296
297
299QAudioFormat QAudioSource::format()
const
301 return d ? d->format() : QAudioFormat();
305
306
307
308
309
311void QAudioSource::stop()
318
319
321void QAudioSource::reset()
328
329
330
331
332
334void QAudioSource::suspend()
341
342
343
344
345
346
347
349void QAudioSource::resume()
356
357
358
359
360
361
362
363
364
365
367void QAudioSource::setBufferSize(qsizetype value)
370 d->setBufferSize(value);
374
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
402void QAudioSource::setBufferFrameCount(qsizetype value)
405 setBufferSize(d->format().bytesForFrames(value));
409
410
411
412
413
414
415
416
417
418
420qsizetype QAudioSource::bufferFrameCount()
const
422 return d ? d->format().framesForBytes(bufferSize()) : 0;
426
427
428
429
430
431
432
434qsizetype QAudioSource::bytesAvailable()
const
436 return d ? d->bytesReady() : 0;
440
441
442
443
444
445
446
447
449qsizetype QAudioSource::framesAvailable()
const
452 return d ? d->format().framesForBytes(bytesAvailable()) : 0;
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470void QAudioSource::setVolume(qreal volume)
475 std::optional<
float> newVolume = QAudioHelperInternal::sanitizeVolume(volume,
this->volume());
477 d->setVolume(*newVolume);
481
482
483
484
485
486qreal QAudioSource::volume()
const
488 return d ? d->volume() : 1.0;
492
493
494
496qint64 QAudioSource::processedUSecs()
const
498 return d ? d->processedUSecs() : 0;
502
503
504
506qint64 QAudioSource::elapsedUSecs()
const
508 return state() == QAudio::StoppedState ? 0 : d->elapsedTime.nsecsElapsed()/1000;
512
513
515QtAudio::Error QAudioSource::error()
const
517 return d ? d->error() : QAudio::OpenError;
521
522
524QtAudio::State QAudioSource::state()
const
526 return d ? d->state() : QAudio::StoppedState;
530
531
532
533
534
535
536
540#include "moc_qaudiosource.cpp"
Combined button and popup list for selecting options.
static bool validateFormatAtStart(QPlatformAudioSource *d)