diff options
Diffstat (limited to 'src/multimedia/pulseaudio/qpulseaudiosink_p.h')
-rw-r--r-- | src/multimedia/pulseaudio/qpulseaudiosink_p.h | 71 |
1 files changed, 20 insertions, 51 deletions
diff --git a/src/multimedia/pulseaudio/qpulseaudiosink_p.h b/src/multimedia/pulseaudio/qpulseaudiosink_p.h index 1a7b6d212..cf0b181ec 100644 --- a/src/multimedia/pulseaudio/qpulseaudiosink_p.h +++ b/src/multimedia/pulseaudio/qpulseaudiosink_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QAUDIOOUTPUTPULSE_H #define QAUDIOOUTPUTPULSE_H @@ -60,8 +24,10 @@ #include "qaudio.h" #include "qaudiodevice.h" -#include <private/qaudiosystem_p.h> +#include "pulseaudio/qpulsehelpers_p.h" +#include <private/qaudiosystem_p.h> +#include <private/qaudiostatemachine_p.h> #include <pulse/pulseaudio.h> QT_BEGIN_NAMESPACE @@ -72,7 +38,7 @@ class QPulseAudioSink : public QPlatformAudioSink Q_OBJECT public: - QPulseAudioSink(const QByteArray &device); + QPulseAudioSink(const QByteArray &device, QObject *parent); ~QPulseAudioSink(); void start(QIODevice *device) override; @@ -100,9 +66,8 @@ protected: void timerEvent(QTimerEvent *event) override; private: - void setState(QAudio::State state); - void setError(QAudio::Error error); - void startReading(); + void startPulling(); + void stopTimer(); bool open(); void close(); @@ -112,7 +77,11 @@ private Q_SLOTS: void userFeed(); void onPulseContextFailed(); + PAOperationUPtr exchangeDrainOperation(pa_operation *newOperation); + private: + qsizetype defaultBufferSize() const; + pa_sample_spec m_spec = {}; // calculate timing manually, as pulseaudio doesn't give us good enough data mutable timeval lastTimingInfo = {}; @@ -126,7 +95,7 @@ private: QIODevice *m_audioSource = nullptr; pa_stream *m_stream = nullptr; - char *m_audioBuffer = nullptr; + std::vector<char> m_audioBuffer; qint64 m_totalTimeValue = 0; qint64 m_elapsedTimeOffset = 0; @@ -134,15 +103,15 @@ private: mutable qint64 lastProcessedUSecs = 0; qreal m_volume = 1.0; - QAudio::Error m_errorState = QAudio::NoError; - QAudio::State m_deviceState = QAudio::StoppedState; - int m_periodSize = 0; - int m_bufferSize = 0; - int m_maxBufferSize = 0; - int m_periodTime = 0; + std::atomic<pa_operation *> m_drainOperation = nullptr; + qsizetype m_bufferSize = 0; + std::optional<qsizetype> m_userBufferSize = std::nullopt; + int m_pullingPeriodSize = 0; + int m_pullingPeriodTime = 0; bool m_pullMode = true; bool m_opened = false; - bool m_resuming = false; + + QAudioStateMachine m_stateMachine; }; class PulseOutputPrivate : public QIODevice |