summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
authorTim Blechmann <tim@klingt.org>2024-04-02 13:31:37 +0800
committerTim Blechmann <tim@klingt.org>2024-04-17 08:05:34 +0800
commitd928939dc603d5819f960245b860e749b1f4e3a7 (patch)
tree82dd9c24403de42fa0f43caaa4dbdd6f0ff98ad9 /src/multimedia/audio
parent30eb2b2417c2658fb324452d1fc76043157ada23 (diff)
QAudioDecoder: fix unit tests for GStreamer
When setting a QUrl with an empty scheme, we need to set the file:// pattern for uridecodebin. This has been done for QMediaPlayer in the past, but not for QAudioDecoder. Compare: 8a3806f6263f56b5be5b557e321b9b13d1913d5f To keep consistency with QMediaPlayer, we introduce a QAudioDecoderPrivate class. Pick-to: 6.5 6.7 Task-number: QTBUG-96985 Change-Id: If954a04a003aecb0f862a7e5041ead43e4c9d259 Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/qaudiodecoder.cpp97
-rw-r--r--src/multimedia/audio/qaudiodecoder.h8
-rw-r--r--src/multimedia/audio/qaudiodecoder_p.h40
3 files changed, 107 insertions, 38 deletions
diff --git a/src/multimedia/audio/qaudiodecoder.cpp b/src/multimedia/audio/qaudiodecoder.cpp
index 0542c3459..f555f46ed 100644
--- a/src/multimedia/audio/qaudiodecoder.cpp
+++ b/src/multimedia/audio/qaudiodecoder.cpp
@@ -1,20 +1,19 @@
// 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
-#include "qtmultimediaglobal_p.h"
#include "qaudiodecoder.h"
-#include "private/qplatformaudiodecoder_p.h"
-
+#include <private/qaudiodecoder_p.h>
+#include <private/qmultimediautils_p.h>
+#include <private/qplatformaudiodecoder_p.h>
#include <private/qplatformmediaintegration_p.h>
-#include <private/qobject_p.h>
#include <QtCore/qcoreevent.h>
+#include <QtCore/qdebug.h>
#include <QtCore/qmetaobject.h>
+#include <QtCore/qpointer.h>
#include <QtCore/qtimer.h>
#include <QtCore/qurl.h>
-#include <QtCore/qdebug.h>
-#include <QtCore/qpointer.h>
QT_BEGIN_NAMESPACE
@@ -38,18 +37,20 @@ QT_BEGIN_NAMESPACE
/*!
Construct an QAudioDecoder instance with \a parent.
*/
-QAudioDecoder::QAudioDecoder(QObject *parent)
- : QObject(parent)
+QAudioDecoder::QAudioDecoder(QObject *parent) : QObject{ *new QAudioDecoderPrivate, parent }
{
+ QT6_ONLY(Q_UNUSED(unused))
+
+ Q_D(QAudioDecoder);
+
auto maybeDecoder = QPlatformMediaIntegration::instance()->createAudioDecoder(this);
if (maybeDecoder) {
- decoder = maybeDecoder.value();
+ d->decoder.reset(maybeDecoder.value());
} else {
qWarning() << "Failed to initialize QAudioDecoder" << maybeDecoder.error();
}
}
-
/*!
Destroys the audio decoder object.
*/
@@ -60,7 +61,9 @@ QAudioDecoder::~QAudioDecoder() = default;
*/
bool QAudioDecoder::isSupported() const
{
- return bool(decoder);
+ Q_D(const QAudioDecoder);
+
+ return bool(d->decoder);
}
/*!
@@ -69,7 +72,9 @@ bool QAudioDecoder::isSupported() const
*/
bool QAudioDecoder::isDecoding() const
{
- return decoder && decoder->isDecoding();
+ Q_D(const QAudioDecoder);
+
+ return d->decoder && d->decoder->isDecoding();
}
/*!
@@ -78,7 +83,8 @@ bool QAudioDecoder::isDecoding() const
*/
QAudioDecoder::Error QAudioDecoder::error() const
{
- return decoder ? decoder->error() : NotSupportedError;
+ Q_D(const QAudioDecoder);
+ return d->decoder ? d->decoder->error() : NotSupportedError;
}
/*!
@@ -89,9 +95,10 @@ QAudioDecoder::Error QAudioDecoder::error() const
*/
QString QAudioDecoder::errorString() const
{
- if (!decoder)
+ Q_D(const QAudioDecoder);
+ if (!d->decoder)
return tr("QAudioDecoder not supported.");
- return decoder->errorString();
+ return d->decoder->errorString();
}
/*!
@@ -108,12 +115,14 @@ QString QAudioDecoder::errorString() const
*/
void QAudioDecoder::start()
{
- if (!decoder)
+ Q_D(QAudioDecoder);
+
+ if (!d->decoder)
return;
// Reset error conditions
- decoder->clearError();
- decoder->start();
+ d->decoder->clearError();
+ d->decoder->start();
}
/*!
@@ -121,8 +130,10 @@ void QAudioDecoder::start()
*/
void QAudioDecoder::stop()
{
- if (decoder)
- decoder->stop();
+ Q_D(QAudioDecoder);
+
+ if (d->decoder)
+ d->decoder->stop();
}
/*!
@@ -132,7 +143,8 @@ void QAudioDecoder::stop()
*/
QUrl QAudioDecoder::source() const
{
- return decoder ? decoder->source() : QString{};
+ Q_D(const QAudioDecoder);
+ return d->unresolvedUrl;
}
/*!
@@ -146,11 +158,16 @@ QUrl QAudioDecoder::source() const
*/
void QAudioDecoder::setSource(const QUrl &fileName)
{
- if (!decoder)
+ Q_D(QAudioDecoder);
+
+ if (!d->decoder)
return;
- decoder->clearError();
- decoder->setSource(fileName);
+ d->decoder->clearError();
+ d->unresolvedUrl = fileName;
+ d->decoder->setSourceDevice(nullptr);
+ QUrl url = qMediaFromUserInput(fileName);
+ d->decoder->setSource(url);
}
/*!
@@ -159,7 +176,8 @@ void QAudioDecoder::setSource(const QUrl &fileName)
*/
QIODevice *QAudioDecoder::sourceDevice() const
{
- return decoder ? decoder->sourceDevice() : nullptr;
+ Q_D(const QAudioDecoder);
+ return d->decoder ? d->decoder->sourceDevice() : nullptr;
}
/*!
@@ -173,8 +191,11 @@ QIODevice *QAudioDecoder::sourceDevice() const
*/
void QAudioDecoder::setSourceDevice(QIODevice *device)
{
- if (decoder)
- decoder->setSourceDevice(device);
+ Q_D(QAudioDecoder);
+ if (d->decoder) {
+ d->unresolvedUrl = QUrl{};
+ d->decoder->setSourceDevice(device);
+ }
}
/*!
@@ -187,7 +208,8 @@ void QAudioDecoder::setSourceDevice(QIODevice *device)
*/
QAudioFormat QAudioDecoder::audioFormat() const
{
- return decoder ? decoder->audioFormat() : QAudioFormat{};
+ Q_D(const QAudioDecoder);
+ return d->decoder ? d->decoder->audioFormat() : QAudioFormat{};
}
/*!
@@ -215,8 +237,10 @@ void QAudioDecoder::setAudioFormat(const QAudioFormat &format)
if (isDecoding())
return;
- if (decoder)
- decoder->setAudioFormat(format);
+ Q_D(QAudioDecoder);
+
+ if (d->decoder)
+ d->decoder->setAudioFormat(format);
}
/*!
@@ -226,7 +250,8 @@ void QAudioDecoder::setAudioFormat(const QAudioFormat &format)
*/
bool QAudioDecoder::bufferAvailable() const
{
- return decoder && decoder->bufferAvailable();
+ Q_D(const QAudioDecoder);
+ return d->decoder && d->decoder->bufferAvailable();
}
/*!
@@ -236,7 +261,8 @@ bool QAudioDecoder::bufferAvailable() const
qint64 QAudioDecoder::position() const
{
- return decoder ? decoder->position() : -1;
+ Q_D(const QAudioDecoder);
+ return d->decoder ? d->decoder->position() : -1;
}
/*!
@@ -246,7 +272,8 @@ qint64 QAudioDecoder::position() const
qint64 QAudioDecoder::duration() const
{
- return decoder ? decoder->duration() : -1;
+ Q_D(const QAudioDecoder);
+ return d->decoder ? d->decoder->duration() : -1;
}
/*!
@@ -261,7 +288,8 @@ qint64 QAudioDecoder::duration() const
QAudioBuffer QAudioDecoder::read() const
{
- return decoder ? decoder->read() : QAudioBuffer{};
+ Q_D(const QAudioDecoder);
+ return d->decoder ? d->decoder->read() : QAudioBuffer{};
}
// Enums
@@ -345,7 +373,6 @@ QAudioBuffer QAudioDecoder::read() const
\sa positionChanged()
*/
-
// Properties
/*!
\property QAudioDecoder::source
diff --git a/src/multimedia/audio/qaudiodecoder.h b/src/multimedia/audio/qaudiodecoder.h
index 4a7d6f00a..9044b6617 100644
--- a/src/multimedia/audio/qaudiodecoder.h
+++ b/src/multimedia/audio/qaudiodecoder.h
@@ -6,12 +6,11 @@
#include <QtCore/qobject.h>
#include <QtMultimedia/qmediaenumdebug.h>
-
#include <QtMultimedia/qaudiobuffer.h>
QT_BEGIN_NAMESPACE
-class QPlatformAudioDecoder;
+class QAudioDecoderPrivate;
class Q_MULTIMEDIA_EXPORT QAudioDecoder : public QObject
{
Q_OBJECT
@@ -76,7 +75,10 @@ Q_SIGNALS:
private:
Q_DISABLE_COPY(QAudioDecoder)
- QPlatformAudioDecoder *decoder = nullptr;
+ Q_DECLARE_PRIVATE(QAudioDecoder)
+
+ // ### Qt7: remove unused member
+ QT6_ONLY(void *unused = nullptr;) // for ABI compatibility
};
QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiodecoder_p.h b/src/multimedia/audio/qaudiodecoder_p.h
new file mode 100644
index 000000000..fa7311457
--- /dev/null
+++ b/src/multimedia/audio/qaudiodecoder_p.h
@@ -0,0 +1,40 @@
+// Copyright (C) 2024 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 QAUDIODECODER_P_H
+#define QAUDIODECODER_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtCore/private/qobject_p.h>
+#include <QtMultimedia/private/qplatformaudiodecoder_p.h>
+
+#include <memory.h>
+
+QT_BEGIN_NAMESPACE
+
+class QAudioDecoder;
+
+class QAudioDecoderPrivate : public QObjectPrivate
+{
+ Q_DECLARE_PUBLIC(QAudioDecoder)
+
+public:
+ QAudioDecoderPrivate() = default;
+
+ QUrl unresolvedUrl;
+ std::unique_ptr<QPlatformAudioDecoder> decoder;
+};
+
+QT_END_NAMESPACE
+
+#endif // QAUDIODECODER_P_H