Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qandroidaudiosink_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#ifndef QOPENSLESAUDIOOUTPUT_H
5#define QOPENSLESAUDIOOUTPUT_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/qaudiosystem_p.h>
19#include <SLES/OpenSLES.h>
20#include <qbytearray.h>
21#include <qmap.h>
22#include <QElapsedTimer>
23#include <QIODevice>
24
26
28{
30
31public:
34
35 void start(QIODevice *device) override;
36 QIODevice *start() override;
37 void stop() override;
38 void reset() override;
39 void suspend() override;
40 void resume() override;
41 qsizetype bytesFree() const override;
42 void setBufferSize(qsizetype value) override;
43 qsizetype bufferSize() const override;
44 qint64 processedUSecs() const override;
45 QAudio::Error error() const override;
46 QAudio::State state() const override;
47 void setFormat(const QAudioFormat &format) override;
48 QAudioFormat format() const override;
49
50 void setVolume(qreal volume) override;
51 qreal volume() const override;
52
53private:
54 friend class SLIODevicePrivate;
55
56 Q_INVOKABLE void onEOSEvent();
57 Q_INVOKABLE void onBytesProcessed(qint64 bytes);
58 Q_INVOKABLE void bufferAvailable();
59
60 static void playCallback(SLPlayItf playItf, void *ctx, SLuint32 event);
61 static void bufferQueueCallback(SLBufferQueueItf bufferQueue, void *ctx);
62
63 bool preparePlayer();
64 void destroyPlayer();
65 void stopPlayer();
66 void readyRead();
67 void startPlayer();
68 qint64 writeData(const char *data, qint64 len);
69
70 void setState(QAudio::State state);
72
73 SLmillibel adjustVolume(qreal vol);
74
75 static constexpr int BufferCount = 2;
76
77 QByteArray m_deviceName;
79 QAudio::State m_suspendedInState = QAudio::SuspendedState;
81 SLObjectItf m_outputMixObject = nullptr;
82 SLObjectItf m_playerObject = nullptr;
83 SLPlayItf m_playItf = nullptr;
84 SLVolumeItf m_volumeItf = nullptr;
85 SLBufferQueueItf m_bufferQueueItf = nullptr;
86 QIODevice *m_audioSource = nullptr;
87 char *m_buffers = nullptr;
88 qreal m_volume = 1.0;
89 bool m_pullMode = false;
90 int m_nextBuffer = 0;
91 int m_bufferSize = 0;
92 qint64 m_elapsedTime = 0;
93 qint64 m_processedBytes = 0;
94 QAtomicInt m_availableBuffers = BufferCount;
95 SLuint32 m_eventMask = SL_PLAYEVENT_HEADATEND;
96 bool m_startRequiresInit = true;
97
98 qint32 m_streamType;
99 QAudioFormat m_format;
100};
101
103{
105
106public:
107 inline SLIODevicePrivate(QAndroidAudioSink *audio) : m_audioDevice(audio) {}
108 inline ~SLIODevicePrivate() override {}
109
110protected:
111 inline qint64 readData(char *, qint64) override { return 0; }
112 inline qint64 writeData(const char *data, qint64 len) override;
113
114private:
115 QAndroidAudioSink *m_audioDevice;
116};
117
119{
120 Q_ASSERT(m_audioDevice);
121 return m_audioDevice->writeData(data, len);
122}
123
125
126#endif // QOPENSLESAUDIOOUTPUT_H
IOBluetoothDevice * device
qsizetype bytesFree() const override
void setVolume(qreal volume) override
qsizetype bufferSize() const override
QIODevice * start() override
QAudioFormat format() const override
QAudio::Error error() const override
QAudio::State state() const override
qint64 processedUSecs() const override
qreal volume() const override
void suspend() override
void setFormat(const QAudioFormat &format) override
void setBufferSize(qsizetype value) override
\inmodule QtCore
Definition qatomic.h:112
The QAudioFormat class stores audio stream parameter information.
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore \reentrant
Definition qiodevice.h:34
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
SLIODevicePrivate(QAndroidAudioSink *audio)
qint64 readData(char *, qint64) override
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
qint64 writeData(const char *data, qint64 len) override
Writes up to maxSize bytes from data to the device.
EGLContext ctx
State
\value ActiveState Audio data is being processed, this state is set after start() is called and while...
Definition qaudio.h:25
@ StoppedState
Definition qaudio.h:25
@ SuspendedState
Definition qaudio.h:25
Error
\value NoError No errors have occurred \value OpenError An error occurred opening the audio device \v...
Definition qaudio.h:24
@ NoError
Definition qaudio.h:24
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
struct _cl_event * event
GLenum GLsizei len
static void setError(QJsonObject *response, const QString &msg)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_OBJECT
#define Q_INVOKABLE
int qint32
Definition qtypes.h:44
ptrdiff_t qsizetype
Definition qtypes.h:70
long long qint64
Definition qtypes.h:55
double qreal
Definition qtypes.h:92
void writeData(const QByteArray &data)