Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 bool m_endSound = false;
95 QAtomicInt m_availableBuffers = BufferCount;
96 SLuint32 m_eventMask = SL_PLAYEVENT_HEADATEND;
97 bool m_startRequiresInit = true;
98
99 qint32 m_streamType;
100 QAudioFormat m_format;
101};
102
104{
106
107public:
108 inline SLIODevicePrivate(QAndroidAudioSink *audio) : m_audioDevice(audio) {}
109 inline ~SLIODevicePrivate() override {}
110
111protected:
112 inline qint64 readData(char *, qint64) override { return 0; }
113 inline qint64 writeData(const char *data, qint64 len) override;
114
115private:
116 QAndroidAudioSink *m_audioDevice;
117};
118
120{
121 Q_ASSERT(m_audioDevice);
122 return m_audioDevice->writeData(data, len);
123}
124
126
127#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
QAndroidAudioSink(const QByteArray &device, QObject *parent)
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:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
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
Definition qaudio.h:29
@ StoppedState
Definition qaudio.h:29
@ SuspendedState
Definition qaudio.h:29
Error
Definition qaudio.h:28
@ NoError
Definition qaudio.h:28
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:49
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
void writeData(const QByteArray &data)