diff options
author | 2017-04-02 12:49:28 -0400 | |
---|---|---|
committer | 2017-04-10 22:26:07 +0000 | |
commit | 5d01b91533af2ba8ffd7afce48b8296e14d60e55 (patch) | |
tree | ef427cbebb92d873d9a2903445c32320ab20c8eb /OutputBuffer.h | |
parent | a30670cd12e03dc874d2f22c48f497817c78ecdc (diff) |
Switch to using Qt's QAudioOutput for outputchinook_3.0.4chinook_3.0.3chinook/3.0.4chinook/3.0.33.0.43.0.3chinook
The underlying issue in the hang reported in SPEC-455 is that due to
the synchronous nature of the pa_simple_* PulseAudio API, the
pa_simple_write call used blocks when a stream is corked . That
prevents the tuner plugin's output thread from exiting when playback is
stopped, resulting in the observed hang. After examining the available
options, it seemed like switching to Qt's QAudioOutput class made sense
since it allows using the asynchronous PulseAudio API easily, and like
the QRadio class the tuner plugin implements, it is part of QtMultimedia
itself.
Note that the radio_output.* files have been removed as the code is no
longer used, and a new pair of OutputBuffer source files have been added
to contain the small class that is used to connect the RTL-SDR output to
QAudioOutput.
Bug-AGL: SPEC-455
Change-Id: I0d690143b9c70fdca24f9fbf3b016feef8ae627b
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
(cherry picked from commit aeb67506173a7b8cef089fa725c3abe1f629dc67)
Diffstat (limited to 'OutputBuffer.h')
-rw-r--r-- | OutputBuffer.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/OutputBuffer.h b/OutputBuffer.h new file mode 100644 index 0000000..d1773ae --- /dev/null +++ b/OutputBuffer.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2017 Konsulko Group + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +/* + * Simple buffer device to act as input device for QAudioInput. + * + * It basically wraps QByteArray with some additional locking that + * the QBuffer class does not provide. It also ensures that reads + * return in units of the given format's sample size. This is + * required to handle the RTL-SDR library output sometimes arriving + * with half a sample at the end. QAudioOutput will blindly pass + * that half sample along and trigger a PulseAudio error if we do + * not handle it here. + */ + +#ifndef OUTPUTBUFFER_H +#define OUTPUTBUFFER_H + +#include <QtCore/QIODevice> +#include <QtCore/QMutex> +#include <QtMultimedia/QAudioFormat> + +class OutputBuffer : public QIODevice +{ + Q_OBJECT + +public: + OutputBuffer(const QAudioFormat &format, QObject *parent); + ~OutputBuffer(); + + void start(); + void stop(); + + qint64 readData(char *data, qint64 maxlen); + qint64 writeData(const char *data, qint64 len); + qint64 bytesAvailable(); + +private: + QMutex m_mutex; + QByteArray m_buffer; + unsigned int m_sample_size; +}; + +#endif // OUTPUTBUFFER_H |