summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/qaudiobuffer.cpp24
-rw-r--r--src/multimedia/audio/qaudiodecoder.cpp18
-rw-r--r--src/multimedia/audio/qaudiodevicefactory.cpp8
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo.cpp6
-rw-r--r--src/multimedia/audio/qaudioprobe.cpp6
-rw-r--r--src/multimedia/audio/qsamplecache_p.cpp10
-rw-r--r--src/multimedia/audio/qsamplecache_p.h2
-rw-r--r--src/multimedia/audio/qsoundeffect.cpp34
-rw-r--r--src/multimedia/audio/qsoundeffect.h2
-rw-r--r--src/multimedia/audio/qsoundeffect_pulse_p.cpp13
-rw-r--r--src/multimedia/audio/qsoundeffect_pulse_p.h2
-rw-r--r--src/multimedia/audio/qsoundeffect_qaudio_p.cpp16
-rw-r--r--src/multimedia/audio/qsoundeffect_qaudio_p.h5
-rw-r--r--src/multimedia/audio/qwavedecoder_p.h2
14 files changed, 92 insertions, 56 deletions
diff --git a/src/multimedia/audio/qaudiobuffer.cpp b/src/multimedia/audio/qaudiobuffer.cpp
index 849d79ab3..f3e7ae670 100644
--- a/src/multimedia/audio/qaudiobuffer.cpp
+++ b/src/multimedia/audio/qaudiobuffer.cpp
@@ -85,7 +85,7 @@ public:
static QAudioBufferPrivate *acquire(QAudioBufferPrivate *other)
{
if (!other)
- return 0;
+ return nullptr;
// Ref the other (if there are extant data() pointers, they will
// also point here - it's a feature, not a bug, like QByteArray)
@@ -131,7 +131,7 @@ public:
}
}
} else
- mBuffer = 0;
+ mBuffer = nullptr;
}
~QMemoryAudioBufferProvider()
@@ -178,7 +178,7 @@ QAudioBufferPrivate *QAudioBufferPrivate::clone()
}
}
- return 0;
+ return nullptr;
}
/*!
@@ -199,7 +199,7 @@ QAudioBufferPrivate *QAudioBufferPrivate::clone()
Create a new, empty, invalid buffer.
*/
QAudioBuffer::QAudioBuffer()
- : d(0)
+ : d(nullptr)
{
}
@@ -244,7 +244,7 @@ QAudioBuffer::QAudioBuffer(const QByteArray &data, const QAudioFormat &format, q
int frameCount = format.framesForBytes(data.size());
d = new QAudioBufferPrivate(new QMemoryAudioBufferProvider(data.constData(), frameCount, format, startTime));
} else
- d = 0;
+ d = nullptr;
}
/*!
@@ -259,9 +259,9 @@ QAudioBuffer::QAudioBuffer(const QByteArray &data, const QAudioFormat &format, q
QAudioBuffer::QAudioBuffer(int numFrames, const QAudioFormat &format, qint64 startTime)
{
if (format.isValid())
- d = new QAudioBufferPrivate(new QMemoryAudioBufferProvider(0, numFrames, format, startTime));
+ d = new QAudioBufferPrivate(new QMemoryAudioBufferProvider(nullptr, numFrames, format, startTime));
else
- d = 0;
+ d = nullptr;
}
/*!
@@ -394,7 +394,7 @@ qint64 QAudioBuffer::startTime() const
const void* QAudioBuffer::constData() const
{
if (!isValid())
- return 0;
+ return nullptr;
return d->mProvider->constData();
}
@@ -417,7 +417,7 @@ const void* QAudioBuffer::constData() const
const void* QAudioBuffer::data() const
{
if (!isValid())
- return 0;
+ return nullptr;
return d->mProvider->constData();
}
@@ -456,7 +456,7 @@ const void* QAudioBuffer::data() const
void *QAudioBuffer::data()
{
if (!isValid())
- return 0;
+ return nullptr;
if (d->mCount.load() != 1) {
// Can't share a writable buffer
@@ -465,7 +465,7 @@ void *QAudioBuffer::data()
// This shouldn't happen
if (!newd)
- return 0;
+ return nullptr;
d->deref();
d = newd;
@@ -489,7 +489,7 @@ void *QAudioBuffer::data()
return memBuffer->writableData();
}
- return 0;
+ return nullptr;
}
// Template helper classes worth documenting
diff --git a/src/multimedia/audio/qaudiodecoder.cpp b/src/multimedia/audio/qaudiodecoder.cpp
index ea1d0e56d..b4ba854e1 100644
--- a/src/multimedia/audio/qaudiodecoder.cpp
+++ b/src/multimedia/audio/qaudiodecoder.cpp
@@ -84,8 +84,8 @@ class QAudioDecoderPrivate : public QMediaObjectPrivate
public:
QAudioDecoderPrivate()
- : provider(0)
- , control(0)
+ : provider(nullptr)
+ , control(nullptr)
, state(QAudioDecoder::StoppedState)
, error(QAudioDecoder::NoError)
{}
@@ -135,7 +135,7 @@ QAudioDecoder::QAudioDecoder(QObject *parent)
d->provider = QMediaServiceProvider::defaultServiceProvider();
if (d->service) {
d->control = qobject_cast<QAudioDecoderControl*>(d->service->requestControl(QAudioDecoderControl_iid));
- if (d->control != 0) {
+ if (d->control != nullptr) {
connect(d->control, SIGNAL(stateChanged(QAudioDecoder::State)), SLOT(_q_stateChanged(QAudioDecoder::State)));
connect(d->control, SIGNAL(error(int,QString)), SLOT(_q_error(int,QString)));
@@ -205,7 +205,7 @@ void QAudioDecoder::start()
{
Q_D(QAudioDecoder);
- if (d->control == 0) {
+ if (d->control == nullptr) {
QMetaObject::invokeMethod(this, "_q_error", Qt::QueuedConnection,
Q_ARG(int, QAudioDecoder::ServiceMissingError),
Q_ARG(QString, tr("The QAudioDecoder object does not have a valid service")));
@@ -226,7 +226,7 @@ void QAudioDecoder::stop()
{
Q_D(QAudioDecoder);
- if (d->control != 0)
+ if (d->control != nullptr)
d->control->stop();
}
@@ -256,7 +256,7 @@ void QAudioDecoder::setSourceFilename(const QString &fileName)
{
Q_D(QAudioDecoder);
- if (d->control != 0)
+ if (d->control != nullptr)
d_func()->control->setSourceFilename(fileName);
}
@@ -269,7 +269,7 @@ QIODevice *QAudioDecoder::sourceDevice() const
Q_D(const QAudioDecoder);
if (d->control)
return d->control->sourceDevice();
- return 0;
+ return nullptr;
}
/*!
@@ -285,7 +285,7 @@ void QAudioDecoder::setSourceDevice(QIODevice *device)
{
Q_D(QAudioDecoder);
- if (d->control != 0)
+ if (d->control != nullptr)
d_func()->control->setSourceDevice(device);
}
@@ -327,7 +327,7 @@ void QAudioDecoder::setAudioFormat(const QAudioFormat &format)
if (state() != QAudioDecoder::StoppedState)
return;
- if (d->control != 0)
+ if (d->control != nullptr)
d_func()->control->setAudioFormat(format);
}
diff --git a/src/multimedia/audio/qaudiodevicefactory.cpp b/src/multimedia/audio/qaudiodevicefactory.cpp
index b1788f28a..cf770c468 100644
--- a/src/multimedia/audio/qaudiodevicefactory.cpp
+++ b/src/multimedia/audio/qaudiodevicefactory.cpp
@@ -77,7 +77,7 @@ class QNullInputDevice : public QAbstractAudioInput
{
public:
void start(QIODevice*) override { qWarning()<<"using null input device, none available";}
- QIODevice* start() override { qWarning()<<"using null input device, none available"; return 0; }
+ QIODevice *start() override { qWarning()<<"using null input device, none available"; return nullptr; }
void stop() override {}
void reset() override {}
void suspend() override {}
@@ -102,7 +102,7 @@ class QNullOutputDevice : public QAbstractAudioOutput
{
public:
void start(QIODevice*) override {qWarning()<<"using null output device, none available";}
- QIODevice* start() override { qWarning()<<"using null output device, none available"; return 0; }
+ QIODevice *start() override { qWarning()<<"using null output device, none available"; return nullptr; }
void stop() override {}
void reset() override {}
void suspend() override {}
@@ -194,7 +194,7 @@ QAudioDeviceInfo QAudioDeviceFactory::defaultDevice(QAudio::Mode mode)
QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode)
{
- QAbstractAudioDeviceInfo *rc = 0;
+ QAbstractAudioDeviceInfo *rc = nullptr;
#if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
QAudioSystemFactoryInterface* plugin =
@@ -204,7 +204,7 @@ QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &re
rc = plugin->createDeviceInfo(handle, mode);
#endif
- return rc == 0 ? new QNullDeviceInfo() : rc;
+ return rc == nullptr ? new QNullDeviceInfo() : rc;
}
QAbstractAudioInput* QAudioDeviceFactory::createDefaultInputDevice(QAudioFormat const &format)
diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp
index f4f548017..b8cac18eb 100644
--- a/src/multimedia/audio/qaudiodeviceinfo.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo.cpp
@@ -57,7 +57,7 @@ class QAudioDeviceInfoPrivate : public QSharedData
public:
QAudioDeviceInfoPrivate()
: mode(QAudio::AudioOutput)
- , info(0)
+ , info(nullptr)
{
}
@@ -67,7 +67,7 @@ public:
if (!handle.isEmpty())
info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode);
else
- info = NULL;
+ info = nullptr;
}
QAudioDeviceInfoPrivate(const QAudioDeviceInfoPrivate &other):
@@ -213,7 +213,7 @@ bool QAudioDeviceInfo::operator !=(const QAudioDeviceInfo &other) const
*/
bool QAudioDeviceInfo::isNull() const
{
- return d->info == 0;
+ return d->info == nullptr;
}
/*!
diff --git a/src/multimedia/audio/qaudioprobe.cpp b/src/multimedia/audio/qaudioprobe.cpp
index 23687c3cb..b6fe86b11 100644
--- a/src/multimedia/audio/qaudioprobe.cpp
+++ b/src/multimedia/audio/qaudioprobe.cpp
@@ -156,7 +156,7 @@ bool QAudioProbe::setSource(QMediaObject *source)
}
}
- return (!source || d->probee != 0);
+ return (!source || d->probee != nullptr);
}
/*!
@@ -176,7 +176,7 @@ bool QAudioProbe::setSource(QMediaObject *source)
*/
bool QAudioProbe::setSource(QMediaRecorder *mediaRecorder)
{
- QMediaObject *source = mediaRecorder ? mediaRecorder->mediaObject() : 0;
+ QMediaObject *source = mediaRecorder ? mediaRecorder->mediaObject() : nullptr;
bool result = setSource(source);
if (!mediaRecorder)
@@ -195,7 +195,7 @@ bool QAudioProbe::setSource(QMediaRecorder *mediaRecorder)
*/
bool QAudioProbe::isActive() const
{
- return d->probee != 0;
+ return d->probee != nullptr;
}
/*!
diff --git a/src/multimedia/audio/qsamplecache_p.cpp b/src/multimedia/audio/qsamplecache_p.cpp
index c956d764b..945fabe52 100644
--- a/src/multimedia/audio/qsamplecache_p.cpp
+++ b/src/multimedia/audio/qsamplecache_p.cpp
@@ -97,7 +97,7 @@ QT_BEGIN_NAMESPACE
QSampleCache::QSampleCache(QObject *parent)
: QObject(parent)
- , m_networkAccessManager(0)
+ , m_networkAccessManager(nullptr)
, m_mutex(QMutex::Recursive)
, m_capacity(0)
, m_usage(0)
@@ -327,8 +327,8 @@ void QSample::cleanup()
if (m_stream)
m_stream->deleteLater();
- m_waveDecoder = 0;
- m_stream = 0;
+ m_waveDecoder = nullptr;
+ m_stream = nullptr;
}
// Called in application thread
@@ -429,8 +429,8 @@ void QSample::onReady()
// Called in application thread, then moved to loader thread
QSample::QSample(const QUrl& url, QSampleCache *parent)
: m_parent(parent)
- , m_stream(0)
- , m_waveDecoder(0)
+ , m_stream(nullptr)
+ , m_waveDecoder(nullptr)
, m_url(url)
, m_sampleReadLength(0)
, m_state(Creating)
diff --git a/src/multimedia/audio/qsamplecache_p.h b/src/multimedia/audio/qsamplecache_p.h
index d3a348528..094e3281e 100644
--- a/src/multimedia/audio/qsamplecache_p.h
+++ b/src/multimedia/audio/qsamplecache_p.h
@@ -127,7 +127,7 @@ class Q_MULTIMEDIA_EXPORT QSampleCache : public QObject
public:
friend class QSample;
- QSampleCache(QObject *parent = 0);
+ QSampleCache(QObject *parent = nullptr);
~QSampleCache();
QSample* requestSample(const QUrl& url);
diff --git a/src/multimedia/audio/qsoundeffect.cpp b/src/multimedia/audio/qsoundeffect.cpp
index f093373ce..09085dca9 100644
--- a/src/multimedia/audio/qsoundeffect.cpp
+++ b/src/multimedia/audio/qsoundeffect.cpp
@@ -111,20 +111,34 @@ QT_BEGIN_NAMESPACE
sound effects.
*/
+static QSoundEffectPrivate *initPrivate(QSoundEffect *self, QSoundEffectPrivate *d)
+{
+ QObject::connect(d, &QSoundEffectPrivate::loopsRemainingChanged, self, &QSoundEffect::loopsRemainingChanged);
+ QObject::connect(d, &QSoundEffectPrivate::volumeChanged, self, &QSoundEffect::volumeChanged);
+ QObject::connect(d, &QSoundEffectPrivate::mutedChanged, self, &QSoundEffect::mutedChanged);
+ QObject::connect(d, &QSoundEffectPrivate::loadedChanged, self, &QSoundEffect::loadedChanged);
+ QObject::connect(d, &QSoundEffectPrivate::playingChanged, self, &QSoundEffect::playingChanged);
+ QObject::connect(d, &QSoundEffectPrivate::statusChanged, self, &QSoundEffect::statusChanged);
+ QObject::connect(d, &QSoundEffectPrivate::categoryChanged, self, &QSoundEffect::categoryChanged);
+
+ return d;
+}
/*!
Creates a QSoundEffect with the given \a parent.
*/
-QSoundEffect::QSoundEffect(QObject *parent) :
- QObject(parent)
+QSoundEffect::QSoundEffect(QObject *parent)
+ : QObject(parent)
+ , d(initPrivate(this, new QSoundEffectPrivate(this)))
+{
+}
+
+/*!
+ Creates a QSoundEffect with the given \a audioDevice and \a parent.
+*/
+QSoundEffect::QSoundEffect(const QAudioDeviceInfo &audioDevice, QObject *parent)
+ : QObject(parent)
+ , d(initPrivate(this, new QSoundEffectPrivate(audioDevice, this)))
{
- d = new QSoundEffectPrivate(this);
- connect(d, &QSoundEffectPrivate::loopsRemainingChanged, this, &QSoundEffect::loopsRemainingChanged);
- connect(d, &QSoundEffectPrivate::volumeChanged, this, &QSoundEffect::volumeChanged);
- connect(d, &QSoundEffectPrivate::mutedChanged, this, &QSoundEffect::mutedChanged);
- connect(d, &QSoundEffectPrivate::loadedChanged, this, &QSoundEffect::loadedChanged);
- connect(d, &QSoundEffectPrivate::playingChanged, this, &QSoundEffect::playingChanged);
- connect(d, &QSoundEffectPrivate::statusChanged, this, &QSoundEffect::statusChanged);
- connect(d, &QSoundEffectPrivate::categoryChanged, this, &QSoundEffect::categoryChanged);
}
/*!
diff --git a/src/multimedia/audio/qsoundeffect.h b/src/multimedia/audio/qsoundeffect.h
index b1c5fd22b..1185afe07 100644
--- a/src/multimedia/audio/qsoundeffect.h
+++ b/src/multimedia/audio/qsoundeffect.h
@@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE
class QSoundEffectPrivate;
+class QAudioDeviceInfo;
class Q_MULTIMEDIA_EXPORT QSoundEffect : public QObject
{
@@ -81,6 +82,7 @@ public:
};
explicit QSoundEffect(QObject *parent = nullptr);
+ explicit QSoundEffect(const QAudioDeviceInfo &audioDevice, QObject *parent = nullptr);
~QSoundEffect();
static QStringList supportedMimeTypes();
diff --git a/src/multimedia/audio/qsoundeffect_pulse_p.cpp b/src/multimedia/audio/qsoundeffect_pulse_p.cpp
index bbaf405b6..075e639a8 100644
--- a/src/multimedia/audio/qsoundeffect_pulse_p.cpp
+++ b/src/multimedia/audio/qsoundeffect_pulse_p.cpp
@@ -58,7 +58,7 @@
#include <private/qaudiohelpers_p.h>
#include <private/qmediaresourcepolicy_p.h>
#include <private/qmediaresourceset_p.h>
-
+#include <QAudioDeviceInfo>
#include <unistd.h>
//#define QT_PA_DEBUG
@@ -360,6 +360,12 @@ QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent):
this, &QSoundEffectPrivate::handleAvailabilityChanged);
}
+QSoundEffectPrivate::QSoundEffectPrivate(const QAudioDeviceInfo &audioDevice, QObject *parent)
+ : QSoundEffectPrivate(parent)
+{
+ m_sinkName = audioDevice.deviceName();
+}
+
void QSoundEffectPrivate::handleAvailabilityChanged(bool available)
{
m_resourcesAvailable = available;
@@ -1005,8 +1011,9 @@ void QSoundEffectPrivate::createPulseStream()
}
m_pulseStream = stream;
- if (pa_stream_connect_playback(m_pulseStream, nullptr, nullptr,
- PA_STREAM_START_CORKED, nullptr, nullptr) < 0) {
+ if (pa_stream_connect_playback(m_pulseStream,
+ m_sinkName.isEmpty() ? nullptr : m_sinkName.toLatin1().constData(),
+ nullptr, PA_STREAM_START_CORKED, nullptr, nullptr) < 0) {
qWarning("QSoundEffect(pulseaudio): Failed to connect stream, error = %s",
pa_strerror(pa_context_errno(pulseDaemon()->context())));
}
diff --git a/src/multimedia/audio/qsoundeffect_pulse_p.h b/src/multimedia/audio/qsoundeffect_pulse_p.h
index 8f74d67e7..e0073f0d5 100644
--- a/src/multimedia/audio/qsoundeffect_pulse_p.h
+++ b/src/multimedia/audio/qsoundeffect_pulse_p.h
@@ -73,6 +73,7 @@ class QSoundEffectPrivate : public QObject
Q_OBJECT
public:
explicit QSoundEffectPrivate(QObject* parent);
+ explicit QSoundEffectPrivate(const QAudioDeviceInfo &audioDevice, QObject *parent);
~QSoundEffectPrivate();
static QStringList supportedMimeTypes();
@@ -150,6 +151,7 @@ private:
static void stream_adjust_prebuffer_callback(pa_stream *s, int success, void *userdata);
pa_stream *m_pulseStream = nullptr;
+ QString m_sinkName;
int m_sinkInputId = -1;
pa_sample_spec m_pulseSpec;
int m_pulseBufferSize = 0;
diff --git a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp
index d7a19eeec..ac4dd9cf9 100644
--- a/src/multimedia/audio/qsoundeffect_qaudio_p.cpp
+++ b/src/multimedia/audio/qsoundeffect_qaudio_p.cpp
@@ -66,6 +66,12 @@ QSoundEffectPrivate::QSoundEffectPrivate(QObject *parent):
{
}
+QSoundEffectPrivate::QSoundEffectPrivate(const QAudioDeviceInfo &audioDevice, QObject *parent)
+ : QObject(parent)
+ , d(new PrivateSoundSource(this, audioDevice))
+{
+}
+
QSoundEffectPrivate::~QSoundEffectPrivate()
{
}
@@ -309,8 +315,9 @@ void QSoundEffectPrivate::setCategory(const QString &category)
}
}
-PrivateSoundSource::PrivateSoundSource(QSoundEffectPrivate *s):
- QIODevice(s)
+PrivateSoundSource::PrivateSoundSource(QSoundEffectPrivate *s, const QAudioDeviceInfo &audioDevice)
+ : QIODevice(s)
+ , m_audioDevice(audioDevice)
{
soundeffect = s;
m_category = QLatin1String("game");
@@ -328,7 +335,10 @@ void PrivateSoundSource::sampleReady()
disconnect(m_sample, &QSample::error, this, &PrivateSoundSource::decoderError);
disconnect(m_sample, &QSample::ready, this, &PrivateSoundSource::sampleReady);
if (!m_audioOutput) {
- m_audioOutput = new QAudioOutput(m_sample->format());
+ if (m_audioDevice.isNull())
+ m_audioOutput = new QAudioOutput(m_sample->format());
+ else
+ m_audioOutput = new QAudioOutput(m_audioDevice, m_sample->format());
connect(m_audioOutput, &QAudioOutput::stateChanged, this, &PrivateSoundSource::stateChanged);
if (!m_muted)
m_audioOutput->setVolume(m_volume);
diff --git a/src/multimedia/audio/qsoundeffect_qaudio_p.h b/src/multimedia/audio/qsoundeffect_qaudio_p.h
index c02a85969..a3a48f60d 100644
--- a/src/multimedia/audio/qsoundeffect_qaudio_p.h
+++ b/src/multimedia/audio/qsoundeffect_qaudio_p.h
@@ -66,7 +66,7 @@ class PrivateSoundSource : public QIODevice
friend class QSoundEffectPrivate;
Q_OBJECT
public:
- PrivateSoundSource(QSoundEffectPrivate *s);
+ PrivateSoundSource(QSoundEffectPrivate *s, const QAudioDeviceInfo &audioDevice = QAudioDeviceInfo());
~PrivateSoundSource() {}
qint64 readData(char *data, qint64 len) override;
@@ -90,7 +90,7 @@ private:
bool m_sampleReady = false;
qint64 m_offset = 0;
QString m_category;
-
+ QAudioDeviceInfo m_audioDevice;
QSoundEffectPrivate *soundeffect = nullptr;
};
@@ -102,6 +102,7 @@ class QSoundEffectPrivate : public QObject
public:
explicit QSoundEffectPrivate(QObject *parent);
+ explicit QSoundEffectPrivate(const QAudioDeviceInfo &audioDevice, QObject *parent);
~QSoundEffectPrivate();
static QStringList supportedMimeTypes();
diff --git a/src/multimedia/audio/qwavedecoder_p.h b/src/multimedia/audio/qwavedecoder_p.h
index 0f1cef599..3be0dbaa6 100644
--- a/src/multimedia/audio/qwavedecoder_p.h
+++ b/src/multimedia/audio/qwavedecoder_p.h
@@ -64,7 +64,7 @@ class QWaveDecoder : public QIODevice
Q_OBJECT
public:
- explicit QWaveDecoder(QIODevice *source, QObject *parent = 0);
+ explicit QWaveDecoder(QIODevice *source, QObject *parent = nullptr);
~QWaveDecoder();
QAudioFormat audioFormat() const;