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
qalsaaudiosink_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//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of other Qt classes. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QAUDIOOUTPUTALSA_H
16#define QAUDIOOUTPUTALSA_H
17
18#include <alsa/asoundlib.h>
19
20#include <QtCore/qfile.h>
21#include <QtCore/qdebug.h>
22#include <QtCore/qtimer.h>
23#include <QtCore/qstring.h>
24#include <QtCore/qstringlist.h>
25#include <QtCore/qelapsedtimer.h>
26#include <QtCore/qiodevice.h>
27
28#include <QtMultimedia/qaudio.h>
29#include <QtMultimedia/qaudiodevice.h>
30#include <private/qaudiosystem_p.h>
31
32QT_BEGIN_NAMESPACE
33
34class QAlsaAudioSink : public QPlatformAudioSink
35{
36 friend class AlsaOutputPrivate;
37 Q_OBJECT
38public:
39 QAlsaAudioSink(QAudioDevice device, const QAudioFormat &, QObject *parent);
40 ~QAlsaAudioSink();
41
42 qint64 write( const char *data, qint64 len );
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::State state() const override;
55
56 QIODevice* audioSource = nullptr;
57 QAudio::Error errorState = QAudio::NoError;
58 QAudio::State deviceState = QAudio::StoppedState;
59 QAudio::State suspendedInState = QAudio::SuspendedState;
60
61private slots:
62 void userFeed();
63 bool deviceReady();
64
65signals:
66 void processMore();
67
68private:
69 bool opened = false;
70 bool pullMode = true;
71 bool resuming = false;
72 int buffer_size = 0;
73 int period_size = 0;
74 qint64 totalTimeValue = 0;
75 unsigned int buffer_time = 100000;
76 unsigned int period_time = 20000;
77 snd_pcm_uframes_t buffer_frames;
78 snd_pcm_uframes_t period_frames;
79 int xrun_recovery(int err);
80
81 int setFormat();
82 bool open();
83 void close();
84
85 QTimer* timer = nullptr;
86 int bytesAvailable = 0;
87 qint64 elapsedTimeOffset = 0;
88 char* audioBuffer = nullptr;
89 snd_pcm_t* handle = nullptr;
90 snd_pcm_access_t access = SND_PCM_ACCESS_RW_INTERLEAVED;
91 snd_pcm_hw_params_t *hwparams = nullptr;
92};
93
95{
96 friend class QAlsaAudioSink;
98public:
101
102 qint64 readData( char* data, qint64 len) override;
103 qint64 writeData(const char* data, qint64 len) override;
104
105private:
106 QAlsaAudioSink *audioDevice;
107};
108
109QT_END_NAMESPACE
110
111
112#endif
qint64 writeData(const char *data, qint64 len) override
Writes up to maxSize bytes from data to the device.
qint64 readData(char *data, qint64 len) override
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...