summaryrefslogtreecommitdiff
path: root/src/multimedia/audio/qaudiodecoder.cpp
diff options
context:
space:
mode:
authorPiotr Srebrny <piotr.srebrny@qt.io>2022-09-09 15:55:48 +0200
committerPiotr Srebrny <piotr.srebrny@qt.io>2022-10-06 09:44:58 +0200
commit5cc60401eef22ebfc9406d85c563db3f395d0c53 (patch)
tree3e84c43e7227d0480d5c5722ba6e1248edf25aa8 /src/multimedia/audio/qaudiodecoder.cpp
parent9dd61fb5f5912444374450278d44e5b320e880c4 (diff)
downloadqtmultimedia-5cc60401eef22ebfc9406d85c563db3f395d0c53.tar.gz
Enable error reporting when failed to initialize backend element
This patch adds an option to report error message when a backend component cannot be instantiated. This error message is then displayed in the console with qWarning and in some cases reported to the app user with error signals. We need further improvements on the error reporting side. Additionally, this patch cleans up the code in the .cpp API classes. Change-Id: Id39865cc8f1e9b52804bf5b9d9b15e738508f860 Reviewed-by: Lars Knoll <lars@knoll.priv.no> (cherry picked from commit f1aa625049a08519d52ba87958e25cb80e47fd1e)
Diffstat (limited to 'src/multimedia/audio/qaudiodecoder.cpp')
-rw-r--r--src/multimedia/audio/qaudiodecoder.cpp58
1 files changed, 21 insertions, 37 deletions
diff --git a/src/multimedia/audio/qaudiodecoder.cpp b/src/multimedia/audio/qaudiodecoder.cpp
index 8be33b07e..088852f5c 100644
--- a/src/multimedia/audio/qaudiodecoder.cpp
+++ b/src/multimedia/audio/qaudiodecoder.cpp
@@ -41,7 +41,12 @@ QT_BEGIN_NAMESPACE
QAudioDecoder::QAudioDecoder(QObject *parent)
: QObject(parent)
{
- decoder = QPlatformMediaIntegration::instance()->createAudioDecoder(this);
+ auto maybeDecoder = QPlatformMediaIntegration::instance()->createAudioDecoder(this);
+ if (maybeDecoder) {
+ decoder = maybeDecoder.value();
+ } else {
+ qWarning() << "Failed to initialize QAudioDecoder" << maybeDecoder.error();
+ }
}
@@ -55,7 +60,7 @@ QAudioDecoder::~QAudioDecoder() = default;
*/
bool QAudioDecoder::isSupported() const
{
- return decoder != nullptr;
+ return bool(decoder);
}
/*!
@@ -73,9 +78,7 @@ bool QAudioDecoder::isDecoding() const
*/
QAudioDecoder::Error QAudioDecoder::error() const
{
- if (!decoder)
- return NotSupportedError;
- return decoder->error();
+ return decoder ? decoder->error() : NotSupportedError;
}
/*!
@@ -105,12 +108,11 @@ QString QAudioDecoder::errorString() const
*/
void QAudioDecoder::start()
{
- if (decoder == nullptr)
+ if (!decoder)
return;
// Reset error conditions
decoder->clearError();
-
decoder->start();
}
@@ -119,10 +121,8 @@ void QAudioDecoder::start()
*/
void QAudioDecoder::stop()
{
- if (!decoder)
- return;
-
- decoder->stop();
+ if (decoder)
+ decoder->stop();
}
/*!
@@ -132,9 +132,7 @@ void QAudioDecoder::stop()
*/
QUrl QAudioDecoder::source() const
{
- if (decoder)
- return decoder->source();
- return QString();
+ return decoder ? decoder->source() : QString{};
}
/*!
@@ -161,9 +159,7 @@ void QAudioDecoder::setSource(const QUrl &fileName)
*/
QIODevice *QAudioDecoder::sourceDevice() const
{
- if (decoder)
- return decoder->sourceDevice();
- return nullptr;
+ return decoder ? decoder->sourceDevice() : nullptr;
}
/*!
@@ -177,9 +173,8 @@ QIODevice *QAudioDecoder::sourceDevice() const
*/
void QAudioDecoder::setSourceDevice(QIODevice *device)
{
- if (!decoder)
- return;
- decoder->setSourceDevice(device);
+ if (decoder)
+ decoder->setSourceDevice(device);
}
/*!
@@ -192,9 +187,7 @@ void QAudioDecoder::setSourceDevice(QIODevice *device)
*/
QAudioFormat QAudioDecoder::audioFormat() const
{
- if (decoder)
- return decoder->audioFormat();
- return QAudioFormat();
+ return decoder ? decoder->audioFormat() : QAudioFormat{};
}
/*!
@@ -221,7 +214,7 @@ void QAudioDecoder::setAudioFormat(const QAudioFormat &format)
if (isDecoding())
return;
- if (decoder != nullptr)
+ if (decoder)
decoder->setAudioFormat(format);
}
@@ -232,9 +225,7 @@ void QAudioDecoder::setAudioFormat(const QAudioFormat &format)
*/
bool QAudioDecoder::bufferAvailable() const
{
- if (decoder)
- return decoder->bufferAvailable();
- return false;
+ return decoder && decoder->bufferAvailable();
}
/*!
@@ -244,9 +235,7 @@ bool QAudioDecoder::bufferAvailable() const
qint64 QAudioDecoder::position() const
{
- if (decoder)
- return decoder->position();
- return -1;
+ return decoder ? decoder->position() : -1;
}
/*!
@@ -256,9 +245,7 @@ qint64 QAudioDecoder::position() const
qint64 QAudioDecoder::duration() const
{
- if (decoder)
- return decoder->duration();
- return -1;
+ return decoder ? decoder->duration() : -1;
}
/*!
@@ -273,10 +260,7 @@ qint64 QAudioDecoder::duration() const
QAudioBuffer QAudioDecoder::read() const
{
- if (decoder)
- return decoder->read();
-
- return QAudioBuffer();
+ return decoder ? decoder->read() : QAudioBuffer{};
}
// Enums