diff options
author | Piotr Srebrny <piotr.srebrny@qt.io> | 2021-06-15 22:21:55 +0200 |
---|---|---|
committer | Piotr Srebrny <piotr.srebrny@qt.io> | 2021-06-16 12:51:27 +0200 |
commit | e1f0c82576325a220a9dd1775c7b28dff60905c9 (patch) | |
tree | 93205265b4c09618c4e984ec135e1fd2785ce7e1 | |
parent | 36fbb6ab08734aff1a73ea4ed255e06bd5aa99f8 (diff) |
Fix media codecs resolver when switching between audio and audio/video
Removing isSupported condition as it is true when audio only format is
selected while flags indicate that video codec is required. The same
occurs when going from audio/video format to audio format.
Reset format if it does not support video while required.
Change-Id: I2c056d935351cfc7a471a7376fa51da320cdb353
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
-rw-r--r-- | src/multimedia/qmediaformat.cpp | 11 | ||||
-rw-r--r-- | tests/auto/unit/multimedia/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/unit/multimedia/qmediaformat/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/auto/unit/multimedia/qmediaformat/tst_qmediaformat.cpp | 68 |
4 files changed, 83 insertions, 4 deletions
diff --git a/src/multimedia/qmediaformat.cpp b/src/multimedia/qmediaformat.cpp index c91b23425..ca9fc0cd3 100644 --- a/src/multimedia/qmediaformat.cpp +++ b/src/multimedia/qmediaformat.cpp @@ -432,8 +432,7 @@ bool QMediaFormat::operator==(const QMediaFormat &other) const */ void QMediaFormat::resolveForEncoding(ResolveFlags flags) { - if (isSupported(Encode)) - return; + const bool requiresVideo = (flags & ResolveFlags::RequiresVideo) != 0; QMediaFormat nullFormat; auto supportedFormats = nullFormat.supportedFileFormats(QMediaFormat::Encode); @@ -456,6 +455,10 @@ void QMediaFormat::resolveForEncoding(ResolveFlags flags) return *list; }; + // reset format if it does not support video when video is required + if (requiresVideo && this->supportedVideoCodecs(QMediaFormat::Encode).isEmpty()) + fmt = QMediaFormat::UnspecifiedFormat; + // reset non supported formats and codecs if (!supportedFormats.contains(fmt)) fmt = QMediaFormat::UnspecifiedFormat; @@ -464,7 +467,7 @@ void QMediaFormat::resolveForEncoding(ResolveFlags flags) if ((flags == NoFlags) || !supportedVideoCodecs.contains(video)) video = QMediaFormat::VideoCodec::Unspecified; - if (!(flags == NoFlags)) { + if (requiresVideo) { // try finding a file format that is supported if (fmt == QMediaFormat::UnspecifiedFormat) fmt = bestSupportedFileFormat(audio, video); @@ -483,7 +486,7 @@ void QMediaFormat::resolveForEncoding(ResolveFlags flags) return; // find a working video codec - if (!(flags == NoFlags)) { + if (requiresVideo) { // reset the audio codec, so that we won't throw away the video codec // if it is supported (choosing the specified video codec has higher // priority than the specified audio codec) diff --git a/tests/auto/unit/multimedia/CMakeLists.txt b/tests/auto/unit/multimedia/CMakeLists.txt index 4ed5121f8..d90d15903 100644 --- a/tests/auto/unit/multimedia/CMakeLists.txt +++ b/tests/auto/unit/multimedia/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(qaudionamespace) add_subdirectory(qcamera) add_subdirectory(qcameradevice) add_subdirectory(qcameraimagecapture) +add_subdirectory(qmediaformat) add_subdirectory(qmediaplayer) add_subdirectory(qmediaplaylist) add_subdirectory(qmediarecorder) diff --git a/tests/auto/unit/multimedia/qmediaformat/CMakeLists.txt b/tests/auto/unit/multimedia/qmediaformat/CMakeLists.txt new file mode 100644 index 000000000..23c4ad18c --- /dev/null +++ b/tests/auto/unit/multimedia/qmediaformat/CMakeLists.txt @@ -0,0 +1,7 @@ +qt_internal_add_test(tst_qmediaformat + SOURCES + tst_qmediaformat.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::MultimediaPrivate +) diff --git a/tests/auto/unit/multimedia/qmediaformat/tst_qmediaformat.cpp b/tests/auto/unit/multimedia/qmediaformat/tst_qmediaformat.cpp new file mode 100644 index 000000000..b7a31d300 --- /dev/null +++ b/tests/auto/unit/multimedia/qmediaformat/tst_qmediaformat.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** 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-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QDebug> +#include <QtMultimedia/qmediaformat.h> + +class tst_QMediaFormat : public QObject +{ + Q_OBJECT + +private slots: + void testResolveForEncoding(); +}; + +void tst_QMediaFormat::testResolveForEncoding() +{ + QMediaFormat format; + + auto hasVideoCodecs = !format.supportedVideoCodecs(QMediaFormat::Encode).isEmpty(); + + // Resolve codecs for audio only stream + format.resolveForEncoding(QMediaFormat::NoFlags); + QVERIFY(format.audioCodec() != QMediaFormat::AudioCodec::Unspecified); + QVERIFY(format.fileFormat() != QMediaFormat::FileFormat::UnspecifiedFormat); + QVERIFY(format.videoCodec() == QMediaFormat::VideoCodec::Unspecified); + + // Resolve codecs for audio/video stream + format.resolveForEncoding(QMediaFormat::RequiresVideo); + QVERIFY(format.audioCodec() != QMediaFormat::AudioCodec::Unspecified); + QVERIFY(format.fileFormat() != QMediaFormat::FileFormat::UnspecifiedFormat); + if (hasVideoCodecs) + QVERIFY(format.videoCodec() != QMediaFormat::VideoCodec::Unspecified); + else + QVERIFY(format.videoCodec() == QMediaFormat::VideoCodec::Unspecified); + + // Resolve again for audio only stream + format.resolveForEncoding(QMediaFormat::NoFlags); + QVERIFY(format.videoCodec() == QMediaFormat::VideoCodec::Unspecified); +} + +QTEST_MAIN(tst_QMediaFormat) +#include "tst_qmediaformat.moc" |