diff options
author | Piotr Srebrny <piotr.srebrny@qt.io> | 2022-09-09 15:55:48 +0200 |
---|---|---|
committer | Piotr Srebrny <piotr.srebrny@qt.io> | 2022-09-26 14:35:28 +0200 |
commit | f1aa625049a08519d52ba87958e25cb80e47fd1e (patch) | |
tree | 32ec669d0c9f93e481173b37e3dc78c3ce1c4da8 /src/multimedia/audio/qaudiodecoder.cpp | |
parent | 953468d895413c738e7c8784c271f394e6c53a8d (diff) | |
download | qtmultimedia-f1aa625049a08519d52ba87958e25cb80e47fd1e.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.
Pick-to: 6.4
Change-Id: Id39865cc8f1e9b52804bf5b9d9b15e738508f860
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
Diffstat (limited to 'src/multimedia/audio/qaudiodecoder.cpp')
-rw-r--r-- | src/multimedia/audio/qaudiodecoder.cpp | 58 |
1 files changed, 21 insertions, 37 deletions
diff --git a/src/multimedia/audio/qaudiodecoder.cpp b/src/multimedia/audio/qaudiodecoder.cpp index c35f7b64f..015ecb2de 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; } /*! @@ -103,12 +106,11 @@ QString QAudioDecoder::errorString() const */ void QAudioDecoder::start() { - if (decoder == nullptr) + if (!decoder) return; // Reset error conditions decoder->clearError(); - decoder->start(); } @@ -117,10 +119,8 @@ void QAudioDecoder::start() */ void QAudioDecoder::stop() { - if (!decoder) - return; - - decoder->stop(); + if (decoder) + decoder->stop(); } /*! @@ -130,9 +130,7 @@ void QAudioDecoder::stop() */ QUrl QAudioDecoder::source() const { - if (decoder) - return decoder->source(); - return QString(); + return decoder ? decoder->source() : QString{}; } /*! @@ -159,9 +157,7 @@ void QAudioDecoder::setSource(const QUrl &fileName) */ QIODevice *QAudioDecoder::sourceDevice() const { - if (decoder) - return decoder->sourceDevice(); - return nullptr; + return decoder ? decoder->sourceDevice() : nullptr; } /*! @@ -175,9 +171,8 @@ QIODevice *QAudioDecoder::sourceDevice() const */ void QAudioDecoder::setSourceDevice(QIODevice *device) { - if (!decoder) - return; - decoder->setSourceDevice(device); + if (decoder) + decoder->setSourceDevice(device); } /*! @@ -190,9 +185,7 @@ void QAudioDecoder::setSourceDevice(QIODevice *device) */ QAudioFormat QAudioDecoder::audioFormat() const { - if (decoder) - return decoder->audioFormat(); - return QAudioFormat(); + return decoder ? decoder->audioFormat() : QAudioFormat{}; } /*! @@ -219,7 +212,7 @@ void QAudioDecoder::setAudioFormat(const QAudioFormat &format) if (isDecoding()) return; - if (decoder != nullptr) + if (decoder) decoder->setAudioFormat(format); } @@ -230,9 +223,7 @@ void QAudioDecoder::setAudioFormat(const QAudioFormat &format) */ bool QAudioDecoder::bufferAvailable() const { - if (decoder) - return decoder->bufferAvailable(); - return false; + return decoder && decoder->bufferAvailable(); } /*! @@ -242,9 +233,7 @@ bool QAudioDecoder::bufferAvailable() const qint64 QAudioDecoder::position() const { - if (decoder) - return decoder->position(); - return -1; + return decoder ? decoder->position() : -1; } /*! @@ -254,9 +243,7 @@ qint64 QAudioDecoder::position() const qint64 QAudioDecoder::duration() const { - if (decoder) - return decoder->duration(); - return -1; + return decoder ? decoder->duration() : -1; } /*! @@ -271,10 +258,7 @@ qint64 QAudioDecoder::duration() const QAudioBuffer QAudioDecoder::read() const { - if (decoder) - return decoder->read(); - - return QAudioBuffer(); + return decoder ? decoder->read() : QAudioBuffer{}; } // Enums |