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
qandroidaudiosource_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 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 QANDROIDAUDIOINPUT_H
5#define QANDROIDAUDIOINPUT_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 <private/qaudio_platform_implementation_support_p.h>
19
20#include <private/qaaudiostream_p.h>
21
22#include <aaudio/AAudio.h>
23
24QT_BEGIN_NAMESPACE
25
26namespace QtAAudio {
27
28class QAndroidAudioSource;
29
30class QAndroidAudioSourceStream final : public QtMultimediaPrivate::QPlatformAudioSourceStream
31{
32 using QPlatformAudiosourceStream = QtMultimediaPrivate::QPlatformAudioSourceStream;
33
34public:
35 explicit QAndroidAudioSourceStream(QAudioDevice device, const QAudioFormat &format,
36 std::optional<int> ringbufferSize,
37 QAndroidAudioSource *parent, float volume,
38 std::optional<int32_t> hardwareBufferFrames);
39 Q_DISABLE_COPY_MOVE(QAndroidAudioSourceStream)
40 ~QAndroidAudioSourceStream();
41
42 bool open();
43
44 bool start(QIODevice *);
46 bool start(AudioCallback &&);
47
48 void suspend();
49 void resume();
50 void stop(ShutdownPolicy);
51
52 using QPlatformAudioSourceStream::bytesReady;
53 using QPlatformAudioSourceStream::deviceIsRingbufferReader;
54 using QPlatformAudioSourceStream::processedDuration;
55 using QPlatformAudioSourceStream::ringbufferSizeInBytes;
56 using QPlatformAudioSourceStream::setVolume;
57
58private:
59 // QPlatformAudioSourceStream overrides
60 void updateStreamIdle(bool idle) override;
61
62 QSpan<const std::byte> getHostSpan(void *audioData, int numFrames) const noexcept QT_MM_NONBLOCKING;
63 aaudio_data_callback_result_t processRingbuffer(QSpan<const std::byte> audioSpan,
64 int numFrames) noexcept QT_MM_NONBLOCKING;
65 aaudio_data_callback_result_t
66 processCallback(QSpan<const std::byte> audioSpan) noexcept QT_MM_NONBLOCKING;
67 void handleError(aaudio_result_t error);
68
69 QAndroidAudioSource *m_parent;
70
71 std::optional<AudioCallback> m_audioCallback;
72
73 std::unique_ptr<QtAAudio::Stream> m_stream;
74
75 std::optional<QAudioFormat> m_hostFormat;
76};
77
78class QAndroidAudioSource final
79 : public QtMultimediaPrivate::QPlatformAudioSourceImplementationWithCallback<
80 QAndroidAudioSourceStream, QAndroidAudioSource>
81{
82 using BaseClass = QtMultimediaPrivate::QPlatformAudioSourceImplementationWithCallback<
83 QAndroidAudioSourceStream, QAndroidAudioSource>;
84
85public:
86 QAndroidAudioSource(QAudioDevice device, const QAudioFormat &format, QObject *parent);
88};
89
90}
91
92QT_END_NAMESPACE
93
94#endif // QANDROIDAUDIOINPUT_H
QAndroidAudioSourceStream(QAudioDevice device, const QAudioFormat &format, std::optional< int > ringbufferSize, QAndroidAudioSource *parent, float volume, std::optional< int32_t > hardwareBufferFrames)
QAndroidAudioSource(QAudioDevice device, const QAudioFormat &format, QObject *parent)