Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qpulseaudiosink_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 QAUDIOOUTPUTPULSE_H
5#define QAUDIOOUTPUTPULSE_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 <QtCore/qfile.h>
19#include <QtCore/qtimer.h>
20#include <QtCore/qstring.h>
21#include <QtCore/qstringlist.h>
22#include <QtCore/qelapsedtimer.h>
23#include <QtCore/qiodevice.h>
24
25#include "qaudio.h"
26#include "qaudiodevice.h"
28
29#include <private/qaudiosystem_p.h>
30
31#include <pulse/pulseaudio.h>
32#include <atomic>
33
35
37{
38 friend class PulseOutputPrivate;
40
41public:
44
45 void start(QIODevice *device) override;
46 QIODevice *start() override;
47 void stop() override;
48 void reset() override;
49 void suspend() override;
50 void resume() override;
51 qsizetype bytesFree() const override;
52 void setBufferSize(qsizetype value) override;
53 qsizetype bufferSize() const override;
54 qint64 processedUSecs() const override;
55 QAudio::Error error() const override;
56 QAudio::State state() const override;
57 void setFormat(const QAudioFormat &format) override;
58 QAudioFormat format() const override;
59
60 void setVolume(qreal volume) override;
61 qreal volume() const override;
62
65
66protected:
67 void timerEvent(QTimerEvent *event) override;
68
69private:
70 void setStateAndError(QAudio::State state, QAudio::Error error, bool forceEmitState = false);
71 void startReading();
72
73 bool open();
74 void close();
75 qint64 write(const char *data, qint64 len);
76
77private Q_SLOTS:
78 void userFeed();
79 void onPulseContextFailed();
80
81 PAOperationUPtr exchangeDrainOperation(pa_operation *newOperation);
82
83private:
84 pa_sample_spec m_spec = {};
85 // calculate timing manually, as pulseaudio doesn't give us good enough data
86 mutable timeval lastTimingInfo = {};
87
88 mutable QList<qint64> latencyList; // last latency values
89
90 QByteArray m_device;
91 QByteArray m_streamName;
92 QAudioFormat m_format;
93 QBasicTimer m_tickTimer;
94
95 QIODevice *m_audioSource = nullptr;
96 pa_stream *m_stream = nullptr;
97 std::vector<char> m_audioBuffer;
98
99 qint64 m_totalTimeValue = 0;
100 qint64 m_elapsedTimeOffset = 0;
101 mutable qint64 averageLatency = 0; // average latency
102 mutable qint64 lastProcessedUSecs = 0;
103 qreal m_volume = 1.0;
104
105 std::atomic<QAudio::Error> m_errorState = QAudio::NoError;
106 std::atomic<QAudio::State> m_deviceState = QAudio::StoppedState;
107 QAudio::State m_suspendedInState = QAudio::SuspendedState;
108 std::atomic<pa_operation *> m_drainOperation = nullptr;
109 int m_periodSize = 0;
110 int m_bufferSize = 0;
111 int m_periodTime = 0;
112 bool m_pullMode = true;
113 bool m_opened = false;
114 bool m_resuming = false;
115};
116
118{
119 friend class QPulseAudioSink;
121
122public:
125
126protected:
127 qint64 readData(char *data, qint64 len) override;
128 qint64 writeData(const char *data, qint64 len) override;
129
130private:
131 QPulseAudioSink *m_audioDevice;
132};
133
135
136#endif
IOBluetoothDevice * device
qint64 writeData(const char *data, qint64 len) override
Writes up to maxSize bytes from data to the device.
The QAudioFormat class stores audio stream parameter information.
\inmodule QtCore
Definition qbasictimer.h:18
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore \reentrant
Definition qiodevice.h:34
Definition qlist.h:74
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
QAudio::Error error() const override
qreal volume() const override
QIODevice * start() override
void setVolume(qreal volume) override
qint64 processedUSecs() const override
void suspend() override
void resume() override
void setBufferSize(qsizetype value) override
void reset() override
QAudio::State state() const override
void setFormat(const QAudioFormat &format) override
void timerEvent(QTimerEvent *event) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
QAudioFormat format() const override
qsizetype bytesFree() const override
void stop() override
qsizetype bufferSize() const override
\inmodule QtCore
Definition qcoreevent.h:359
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
std::unique_ptr< pa_operation, PAOperationDeleter > PAOperationUPtr
#define Q_OBJECT
#define Q_SLOTS
ptrdiff_t qsizetype
Definition qtypes.h:70
long long qint64
Definition qtypes.h:55
double qreal
Definition qtypes.h:92
QByteArray readData()