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
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#include <private/qaudiostatemachine_p.h>
31#include <pulse/pulseaudio.h>
32
34
36{
37 friend class PulseOutputPrivate;
39
40public:
43
44 void start(QIODevice *device) override;
45 QIODevice *start() override;
46 void stop() override;
47 void reset() override;
48 void suspend() override;
49 void resume() override;
50 qsizetype bytesFree() const override;
51 void setBufferSize(qsizetype value) override;
52 qsizetype bufferSize() const override;
53 qint64 processedUSecs() const override;
54 QAudio::Error error() const override;
55 QAudio::State state() const override;
56 void setFormat(const QAudioFormat &format) override;
57 QAudioFormat format() const override;
58
59 void setVolume(qreal volume) override;
60 qreal volume() const override;
61
64
65protected:
66 void timerEvent(QTimerEvent *event) override;
67
68private:
69 void startPulling();
70 void stopTimer();
71
72 bool open();
73 void close();
74 qint64 write(const char *data, qint64 len);
75
76private Q_SLOTS:
77 void userFeed();
78 void onPulseContextFailed();
79
80 PAOperationUPtr exchangeDrainOperation(pa_operation *newOperation);
81
82private:
83 qsizetype defaultBufferSize() const;
84
85 pa_sample_spec m_spec = {};
86 // calculate timing manually, as pulseaudio doesn't give us good enough data
87 mutable timeval lastTimingInfo = {};
88
89 mutable QList<qint64> latencyList; // last latency values
90
91 QByteArray m_device;
92 QByteArray m_streamName;
93 QAudioFormat m_format;
94 QBasicTimer m_tickTimer;
95
96 QIODevice *m_audioSource = nullptr;
97 pa_stream *m_stream = nullptr;
98 std::vector<char> m_audioBuffer;
99
100 qint64 m_totalTimeValue = 0;
101 qint64 m_elapsedTimeOffset = 0;
102 mutable qint64 averageLatency = 0; // average latency
103 mutable qint64 lastProcessedUSecs = 0;
104 qreal m_volume = 1.0;
105
106 std::atomic<pa_operation *> m_drainOperation = nullptr;
107 qsizetype m_bufferSize = 0;
108 std::optional<qsizetype> m_userBufferSize = std::nullopt;
109 int m_pullingPeriodSize = 0;
110 int m_pullingPeriodTime = 0;
111 bool m_pullMode = true;
112 bool m_opened = false;
113
114 QAudioStateMachine m_stateMachine;
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
PulseOutputPrivate(QPulseAudioSink *audio)
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
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
QAudio::Error error() const override
qreal volume() const override
QIODevice * start() override
QPulseAudioSink(const QByteArray &device, QObject *parent)
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:366
State
Definition qaudio.h:29
Error
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
std::unique_ptr< pa_operation, PAOperationDeleter > PAOperationUPtr
#define Q_OBJECT
#define Q_SLOTS
ptrdiff_t qsizetype
Definition qtypes.h:165
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
QByteArray readData()