diff options
Diffstat (limited to 'src/multimedia/audio/qaudiodecoder.cpp')
-rw-r--r-- | src/multimedia/audio/qaudiodecoder.cpp | 174 |
1 files changed, 76 insertions, 98 deletions
diff --git a/src/multimedia/audio/qaudiodecoder.cpp b/src/multimedia/audio/qaudiodecoder.cpp index e0587d31a..f555f46ed 100644 --- a/src/multimedia/audio/qaudiodecoder.cpp +++ b/src/multimedia/audio/qaudiodecoder.cpp @@ -1,56 +1,19 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtmultimediaglobal_p.h" -#include "qaudiodecoder.h" +// 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 "private/qplatformaudiodecoder_p.h" +#include "qaudiodecoder.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 @@ -74,12 +37,19 @@ QT_BEGIN_NAMESPACE /*! Construct an QAudioDecoder instance with \a parent. */ -QAudioDecoder::QAudioDecoder(QObject *parent) - : QObject(parent) +QAudioDecoder::QAudioDecoder(QObject *parent) : QObject{ *new QAudioDecoderPrivate, parent } { - decoder = QPlatformMediaIntegration::instance()->createAudioDecoder(this); -} + QT6_ONLY(Q_UNUSED(unused)) + + Q_D(QAudioDecoder); + auto maybeDecoder = QPlatformMediaIntegration::instance()->createAudioDecoder(this); + if (maybeDecoder) { + d->decoder.reset(maybeDecoder.value()); + } else { + qWarning() << "Failed to initialize QAudioDecoder" << maybeDecoder.error(); + } +} /*! Destroys the audio decoder object. @@ -91,7 +61,9 @@ QAudioDecoder::~QAudioDecoder() = default; */ bool QAudioDecoder::isSupported() const { - return decoder != nullptr; + Q_D(const QAudioDecoder); + + return bool(d->decoder); } /*! @@ -100,29 +72,33 @@ bool QAudioDecoder::isSupported() const */ bool QAudioDecoder::isDecoding() const { - return decoder && decoder->isDecoding(); + Q_D(const QAudioDecoder); + + return d->decoder && d->decoder->isDecoding(); } /*! - \property QAudioDecoder::error - \brief The current error state. + + Returns the current error state of the QAudioDecoder. */ QAudioDecoder::Error QAudioDecoder::error() const { - if (!decoder) - return NotSupportedError; - return decoder->error(); + Q_D(const QAudioDecoder); + return d->decoder ? d->decoder->error() : NotSupportedError; } /*! + \property QAudioDecoder::error + Returns a human readable description of the current error, or an empty string is there is no error. */ 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(); } /*! @@ -139,13 +115,14 @@ QString QAudioDecoder::errorString() const */ void QAudioDecoder::start() { - if (decoder == nullptr) + Q_D(QAudioDecoder); + + if (!d->decoder) return; // Reset error conditions - decoder->clearError(); - - decoder->start(); + d->decoder->clearError(); + d->decoder->start(); } /*! @@ -153,10 +130,10 @@ void QAudioDecoder::start() */ void QAudioDecoder::stop() { - if (!decoder) - return; + Q_D(QAudioDecoder); - decoder->stop(); + if (d->decoder) + d->decoder->stop(); } /*! @@ -166,9 +143,8 @@ void QAudioDecoder::stop() */ QUrl QAudioDecoder::source() const { - if (decoder) - return decoder->source(); - return QString(); + Q_D(const QAudioDecoder); + return d->unresolvedUrl; } /*! @@ -182,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); } /*! @@ -195,9 +176,8 @@ void QAudioDecoder::setSource(const QUrl &fileName) */ QIODevice *QAudioDecoder::sourceDevice() const { - if (decoder) - return decoder->sourceDevice(); - return nullptr; + Q_D(const QAudioDecoder); + return d->decoder ? d->decoder->sourceDevice() : nullptr; } /*! @@ -211,9 +191,11 @@ QIODevice *QAudioDecoder::sourceDevice() const */ void QAudioDecoder::setSourceDevice(QIODevice *device) { - if (!decoder) - return; - decoder->setSourceDevice(device); + Q_D(QAudioDecoder); + if (d->decoder) { + d->unresolvedUrl = QUrl{}; + d->decoder->setSourceDevice(device); + } } /*! @@ -226,9 +208,8 @@ void QAudioDecoder::setSourceDevice(QIODevice *device) */ QAudioFormat QAudioDecoder::audioFormat() const { - if (decoder) - return decoder->audioFormat(); - return QAudioFormat(); + Q_D(const QAudioDecoder); + return d->decoder ? d->decoder->audioFormat() : QAudioFormat{}; } /*! @@ -248,15 +229,18 @@ QAudioFormat QAudioDecoder::audioFormat() const audio file, you can specify an invalid \a format. \warning Setting a desired audio format is not yet supported - on Android. + on the Android backend. It does work with the default FFMPEG + backend. */ void QAudioDecoder::setAudioFormat(const QAudioFormat &format) { if (isDecoding()) return; - if (decoder != nullptr) - decoder->setAudioFormat(format); + Q_D(QAudioDecoder); + + if (d->decoder) + d->decoder->setAudioFormat(format); } /*! @@ -266,9 +250,8 @@ void QAudioDecoder::setAudioFormat(const QAudioFormat &format) */ bool QAudioDecoder::bufferAvailable() const { - if (decoder) - return decoder->bufferAvailable(); - return false; + Q_D(const QAudioDecoder); + return d->decoder && d->decoder->bufferAvailable(); } /*! @@ -278,9 +261,8 @@ bool QAudioDecoder::bufferAvailable() const qint64 QAudioDecoder::position() const { - if (decoder) - return decoder->position(); - return -1; + Q_D(const QAudioDecoder); + return d->decoder ? d->decoder->position() : -1; } /*! @@ -290,9 +272,8 @@ qint64 QAudioDecoder::position() const qint64 QAudioDecoder::duration() const { - if (decoder) - return decoder->duration(); - return -1; + Q_D(const QAudioDecoder); + return d->decoder ? d->decoder->duration() : -1; } /*! @@ -307,10 +288,8 @@ qint64 QAudioDecoder::duration() const QAudioBuffer QAudioDecoder::read() const { - if (decoder) - return decoder->read(); - - return QAudioBuffer(); + Q_D(const QAudioDecoder); + return d->decoder ? d->decoder->read() : QAudioBuffer{}; } // Enums @@ -328,7 +307,7 @@ QAudioBuffer QAudioDecoder::read() const // Signals /*! - \fn QAudioDecoder::error(QAudioDecoder::Error error) + \fn void QAudioDecoder::error(QAudioDecoder::Error error) Signals that an \a error condition has occurred. @@ -394,7 +373,6 @@ QAudioBuffer QAudioDecoder::read() const \sa positionChanged() */ - // Properties /*! \property QAudioDecoder::source |