diff options
30 files changed, 1567 insertions, 9 deletions
diff --git a/examples/multimediawidgets/camera/camera.cpp b/examples/multimediawidgets/camera/camera.cpp index 385608bbc..533a2d4db 100644 --- a/examples/multimediawidgets/camera/camera.cpp +++ b/examples/multimediawidgets/camera/camera.cpp @@ -64,6 +64,7 @@ #include <QtWidgets> #include <QMediaDeviceManager> +#include <QMediaFormat> Q_DECLARE_METATYPE(QCameraInfo) @@ -82,6 +83,21 @@ Camera::Camera() : ui(new Ui::Camera) connect(ui->captureWidget, &QTabWidget::currentChanged, this, &Camera::updateCaptureMode); setCamera(QMediaDeviceManager::defaultVideoInput()); + + qDebug() << "Supported Containers:"; + auto containers = QMediaEncoderInfo::supportedFileFormats(); + for (const auto c : containers) + qDebug() << " " << QMediaFormat::fileFormatName(c); + + qDebug() << "Supported Audio Codecs:"; + auto audio = QMediaEncoderInfo::supportedAudioCodecs(); + for (const auto c : audio) + qDebug() << " " << QMediaFormat::audioCodecName(c); + + qDebug() << "Supported Video Codecs:"; + auto video = QMediaEncoderInfo::supportedVideoCodecs(); + for (const auto c : video) + qDebug() << " " << QMediaFormat::videoCodecName(c); } void Camera::setCamera(const QCameraInfo &cameraInfo) diff --git a/src/imports/multimedia/qmldir b/src/imports/multimedia/qmldir index e7dcc3dd6..d68049f63 100644 --- a/src/imports/multimedia/qmldir +++ b/src/imports/multimedia/qmldir @@ -4,4 +4,3 @@ classname QMultimediaDeclarativeModule typeinfo plugins.qmltypes typeinfo plugins.qmltypes Video 5.0 Video.qml - diff --git a/src/multimedia/CMakeLists.txt b/src/multimedia/CMakeLists.txt index 78685717f..2e408425c 100644 --- a/src/multimedia/CMakeLists.txt +++ b/src/multimedia/CMakeLists.txt @@ -51,11 +51,13 @@ qt_internal_add_module(Multimedia platform/qmediaplatformdevicemanager.cpp platform/qmediaplatformdevicemanager_p.h platform/qmediaplatformintegration.cpp platform/qmediaplatformintegration_p.h platform/qmediaplatformplayerinterface.cpp platform/qmediaplatformplayerinterface_p.h + platform/qmediaplatformformatinfo.cpp platform/qmediaplatformformatinfo_p.h playback/qmediaplayer.cpp playback/qmediaplayer.h playback/qmediaplaylist.cpp playback/qmediaplaylist.h playback/qmediaplaylist_p.h playback/qplaylistfileparser.cpp playback/qplaylistfileparser_p.h qmediadevicemanager.cpp qmediadevicemanager.h qmediaenumdebug.h + qmediaformat.cpp qmediaformat.h qmediametadata.cpp qmediametadata.h qmediapluginloader.cpp qmediapluginloader_p.h qmediaservice.cpp qmediaservice.h qmediaservice_p.h @@ -222,6 +224,7 @@ qt_internal_extend_target(Multimedia CONDITION QT_FEATURE_gstreamer platform/gstreamer/mediaplayer/qgstreamerplayerservice.cpp platform/gstreamer/mediaplayer/qgstreamerplayerservice_p.h platform/gstreamer/mediaplayer/qgstreamerstreamscontrol.cpp platform/gstreamer/mediaplayer/qgstreamerstreamscontrol_p.h platform/gstreamer/qgstreamerdevicemanager.cpp platform/gstreamer/qgstreamerdevicemanager_p.h + platform/gstreamer/qgstreamerformatsinfo.cpp platform/gstreamer/qgstreamerformatsinfo_p.h platform/gstreamer/qgstreamerintegration.cpp platform/gstreamer/qgstreamerintegration_p.h DEFINES GLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_26 @@ -367,6 +370,7 @@ qt_internal_extend_target(Multimedia CONDITION ANDROID platform/android/mediaplayer/qandroidmediaservice.cpp platform/android/mediaplayer/qandroidmediaservice_p.h platform/android/mediaplayer/qandroidmetadatareadercontrol.cpp platform/android/mediaplayer/qandroidmetadatareadercontrol_p.h platform/android/qandroiddevicemanager.cpp platform/android/qandroiddevicemanager_p.h + platform/android/qandroidformatsinfo.cpp platform/android/qandroidformatsinfo_p.h platform/android/qandroidintegration.cpp platform/android/qandroidintegration_p.h platform/android/wrappers/jni/androidcamera.cpp platform/android/wrappers/jni/androidcamera_p.h platform/android/wrappers/jni/androidmediametadataretriever.cpp platform/android/wrappers/jni/androidmediametadataretriever_p.h @@ -415,6 +419,7 @@ qt_internal_extend_target(Multimedia CONDITION APPLE AND NOT WATCHOS platform/darwin/mediaplayer/avfvideooutput.mm platform/darwin/mediaplayer/avfvideooutput_p.h platform/darwin/mediaplayer/avfvideowindowcontrol.mm platform/darwin/mediaplayer/avfvideowindowcontrol_p.h platform/darwin/qdarwindevicemanager.mm platform/darwin/qdarwindevicemanager_p.h + platform/darwin/qdarwinformatsinfo.mm platform/darwin/qdarwinformatsinfo_p.h platform/darwin/qdarwinintegration.cpp platform/darwin/qdarwinintegration_p.h PUBLIC_LIBRARIES ${FWAudioToolbox} diff --git a/src/multimedia/multimedia.pro b/src/multimedia/multimedia.pro index 16872c739..7657fec00 100644 --- a/src/multimedia/multimedia.pro +++ b/src/multimedia/multimedia.pro @@ -15,7 +15,7 @@ PRIVATE_HEADERS += \ qmediapluginloader_p.h \ qmediaservice_p.h \ qmediastoragelocation_p.h \ - qmultimediautils_p.h + qmultimediautils_p.h \ PUBLIC_HEADERS += \ qtmultimediaglobal.h \ @@ -26,7 +26,8 @@ PUBLIC_HEADERS += \ qmediasource.h \ qmediaservice.h \ qmediatimerange.h \ - qmultimedia.h + qmultimedia.h \ + qmediaformat.h SOURCES += \ qmediasink.cpp \ @@ -38,7 +39,8 @@ SOURCES += \ qmediatimerange.cpp \ qmediastoragelocation.cpp \ qmultimedia.cpp \ - qmultimediautils.cpp + qmultimediautils.cpp \ + qmediaformat.cpp CONFIG += simd optimize_full diff --git a/src/multimedia/platform/android/android.pri b/src/multimedia/platform/android/android.pri index 555d8bec0..4369a1864 100644 --- a/src/multimedia/platform/android/android.pri +++ b/src/multimedia/platform/android/android.pri @@ -2,11 +2,13 @@ QT += opengl core-private network HEADERS += \ $$PWD/qandroidintegration_p.h \ - $$PWD/qandroiddevicemanager_p.h + $$PWD/qandroiddevicemanager_p.h \ + $$PWD/qandroidformatsinfo_p.h SOURCES += \ $$PWD/qandroidintegration.cpp \ - $$PWD/qandroiddevicemanager.cpp + $$PWD/qandroiddevicemanager.cpp \ + $$PWD/qandroidformatsinfo.cpp include(audio/audio.pri) include(wrappers/jni/jni.pri) diff --git a/src/multimedia/platform/android/qandroidformatsinfo.cpp b/src/multimedia/platform/android/qandroidformatsinfo.cpp new file mode 100644 index 000000000..c6860e3c9 --- /dev/null +++ b/src/multimedia/platform/android/qandroidformatsinfo.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 "qandroidformatsinfo_p.h" + +QT_BEGIN_NAMESPACE + +QAndroidFormatInfo::QAndroidFormatInfo() +{ + // ### Properly determine the set of supported codecs, this is a minimal set gathered from the old code base + m_decodableAudioCodecs << Qt::AudioCodec::AAC << Qt::AudioCodec::MP3; + m_encodableAudioCodecs << Qt::AudioCodec::AAC << Qt::AudioCodec::MP3; + m_decodableVideoCodecs << Qt::VideoCodec::MPEG4 << Qt::VideoCodec::H264; + m_encodableVideoCodecs << Qt::VideoCodec::MPEG4 << Qt::VideoCodec::H264; + m_decodableMediaContainers << Qt::MediaContainer::MPEG4 << Qt::MediaContainer::MP3; + m_encodableMediaContainers << Qt::MediaContainer::MPEG4 << Qt::MediaContainer::MP3; +} + +QAndroidFormatInfo::~QAndroidFormatInfo +{ + +} + +QList<Qt::MediaContainer> QAndroidFormatInfo::decodableMediaContainers() const +{ + return m_decodableMediaContainers; +} + +QList<Qt::AudioCodec> QAndroidFormatInfo::decodableAudioCodecs() const +{ + return m_decodableAudioCodecs; +} + +QList<Qt::VideoCodec> QAndroidFormatInfo::decodableVideoCodecs() const +{ + return m_decodableVideoCodecs; +} + +QList<Qt::MediaContainer> QAndroidFormatInfo::encodableMediaContainers() const +{ + return m_encodableMediaContainers; +} + +QList<Qt::AudioCodec> QAndroidFormatInfo::encodableAudioCodecs() const +{ + return m_encodableAudioCodecs; +} + +QList<Qt::VideoCodec> QAndroidFormatInfo::encodableVideoCodecs() const +{ + return m_encodableVideoCodecs; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/platform/android/qandroidformatsinfo_p.h b/src/multimedia/platform/android/qandroidformatsinfo_p.h new file mode 100644 index 000000000..54ce80072 --- /dev/null +++ b/src/multimedia/platform/android/qandroidformatsinfo_p.h @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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$ +** +****************************************************************************/ + +#ifndef QANDROIDFORMATINFO_H +#define QANDROIDFORMATINFO_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 <private/qmediaplatformformatinfo_p.h> + +QT_BEGIN_NAMESPACE + +class QAndroidFormatInfo : public QMediaPlatformFormatInfo +{ +public: + QAndroidFormatInfo(); + ~QAndroidFormatInfo(); + + QList<QMediaFormat::FileFormat> decodableMediaContainers() const override; + QList<QMediaFormat::AudioCodec> decodableAudioCodecs() const override; + QList<QMediaFormat::VideoCodec> decodableVideoCodecs() const override; + + QList<QMediaFormat::FileFormat> encodableMediaContainers() const override; + QList<QMediaFormat::AudioCodec> encodableAudioCodecs() const override; + QList<QMediaFormat::VideoCodec> encodableVideoCodecs() const override; + +private: + QList<QMediaFormat::FileFormat> m_decodableMediaContainers; + QList<QMediaFormat::AudioCodec> m_decodableAudioCodecs; + QList<QMediaFormat::VideoCodec> m_decodableVideoCodecs; + + QList<QMediaFormat::FileFormat> m_encodableMediaContainers; + QList<QMediaFormat::AudioCodec> m_encodableAudioCodecs; + QList<QMediaFormat::VideoCodec> m_encodableVideoCodecs; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/platform/android/qandroidintegration.cpp b/src/multimedia/platform/android/qandroidintegration.cpp index 76102a476..7ee99b74e 100644 --- a/src/multimedia/platform/android/qandroidintegration.cpp +++ b/src/multimedia/platform/android/qandroidintegration.cpp @@ -48,6 +48,7 @@ #include "private/androidsurfaceview_p.h" #include "private/androidcamera_p.h" #include "private/androidmediarecorder_p.h" +#include "private/qandroidformatsinfo_p.h" QT_BEGIN_NAMESPACE @@ -61,6 +62,7 @@ QAndroidIntegration::QAndroidIntegration() QAndroidIntegration::~QAndroidIntegration() { delete m_manager; + delete m_formatInfo; } QMediaPlatformDeviceManager *QAndroidIntegration::deviceManager() @@ -70,6 +72,14 @@ QMediaPlatformDeviceManager *QAndroidIntegration::deviceManager() return m_manager; } +QMediaPlatformFormatInfo *QAndroidIntegration::formatInfo() +{ + if (!m_formatInfo) + m_formatInfo = new QAndroidFormatInfo(); + return m_formatInfo; + +} + QMediaPlatformCaptureInterface *QAndroidIntegration::createCaptureInterface(QMediaRecorder::CaptureMode mode) { return new QAndroidCaptureService(mode); diff --git a/src/multimedia/platform/android/qandroidintegration_p.h b/src/multimedia/platform/android/qandroidintegration_p.h index d4cf5bb6a..ca8f384af 100644 --- a/src/multimedia/platform/android/qandroidintegration_p.h +++ b/src/multimedia/platform/android/qandroidintegration_p.h @@ -65,11 +65,13 @@ public: ~QAndroidIntegration(); QMediaPlatformDeviceManager *deviceManager() override; + QMediaPlatformFormatInfo *formatInfo() override; QMediaPlatformCaptureInterface *createCaptureInterface(QMediaRecorder::CaptureMode mode) override; QMediaPlatformPlayerInterface *createPlayerInterface() override; QAndroidDeviceManager *m_manager = nullptr; + QMediaPlatformFormatInfo *m_formatInfo = nullptr; }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/darwin/darwin.pri b/src/multimedia/platform/darwin/darwin.pri index 0daa36f8c..935a8451b 100644 --- a/src/multimedia/platform/darwin/darwin.pri +++ b/src/multimedia/platform/darwin/darwin.pri @@ -21,8 +21,10 @@ include(mediaplayer/mediaplayer.pri) SOURCES += \ $$PWD/qdarwinintegration.cpp \ - $$PWD/qdarwindevicemanager.mm + $$PWD/qdarwindevicemanager.mm \ + $$PWD/qdarwinformatsinfo.mm HEADERS += \ $$PWD/qdarwinintegration_p.h \ - $$PWD/qdarwindevicemanager_p.h + $$PWD/qdarwindevicemanager_p.h \ + $$PWD/qdarwinformatsinfo_p.h diff --git a/src/multimedia/platform/darwin/qdarwinformatsinfo.mm b/src/multimedia/platform/darwin/qdarwinformatsinfo.mm new file mode 100644 index 000000000..5b953e4a7 --- /dev/null +++ b/src/multimedia/platform/darwin/qdarwinformatsinfo.mm @@ -0,0 +1,163 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 "qdarwinformatsinfo_p.h" +#include <AVFoundation/AVFoundation.h> +#include <qdebug.h> +QT_BEGIN_NAMESPACE + +static struct { + const char *name; + QMediaFormat::FileFormat value; +} mediaContainerMap[] = { + { "video/x-ms-asf", QMediaFormat::ASF }, + { "video/avi", QMediaFormat::AVI }, + { "video/x-matroska", QMediaFormat::Matroska }, + { "video/mp4", QMediaFormat::MPEG4 }, + { "video/quicktime", QMediaFormat::QuickTime }, + { "video/ogg", QMediaFormat::Ogg }, + { "audio/mp3", QMediaFormat::MP3 }, + { nullptr, QMediaFormat::MPEG4 } +}; + +static struct { + const char *name; + QMediaFormat::VideoCodec value; +} videoCodecMap[] = { + // See CMVideoCodecType for the four character code names of codecs + { "video/mp4; codecs=\"mp1v\"", QMediaFormat::VideoCodec::MPEG1 }, + { "video/mp4; codecs=\"mp2v\"", QMediaFormat::VideoCodec::MPEG2 }, + { "video/mp4; codecs=\"mp4v\"", QMediaFormat::VideoCodec::MPEG4 }, + { "video/mp4; codecs=\"avc1\"", QMediaFormat::VideoCodec::H264 }, + { "video/mp4; codecs=\"hvc1\"", QMediaFormat::VideoCodec::H265 }, + { "video/mp4; codecs=\"vp09\"", QMediaFormat::VideoCodec::VP9 }, + { "video/mp4; codecs=\"av01\"", QMediaFormat::VideoCodec::AV1 }, // ### ???? + { "video/mp4; codecs=\"jpeg\"", QMediaFormat::VideoCodec::MotionJPEG }, + { nullptr, QMediaFormat::VideoCodec::Invalid } +}; + +static struct { + const char *name; + QMediaFormat::AudioCodec value; +} audioCodecMap[] = { + // AudioFile.h + { "audio/mp3", QMediaFormat::AudioCodec::MP3 }, + { "audio/aac", QMediaFormat::AudioCodec::AAC }, + { "video/mp4; codecs=\"ac-3\"", QMediaFormat::AudioCodec::AC3 }, + { "video/mp4; codecs=\"ec-3\"", QMediaFormat::AudioCodec::EAC3 }, + { "audio/flac", QMediaFormat::AudioCodec::FLAC }, + { nullptr, QMediaFormat::AudioCodec::Invalid }, +}; + +QDarwinFormatInfo::QDarwinFormatInfo() +{ + auto avtypes = [AVURLAsset audiovisualMIMETypes]; + for (AVFileType filetype in avtypes) { + auto *m = mediaContainerMap; + while (m->name) { + if (!strcmp(filetype.UTF8String, m->name)) { + m_decodableMediaContainers.append(m->value); + break; + } + ++m; + } + } + + { + auto *m = videoCodecMap; + while (m->name) { + if ([AVURLAsset isPlayableExtendedMIMEType:[NSString stringWithUTF8String:m->name]]) + m_decodableVideoCodecs << m->value; + ++m; + } + } + { + auto *m = audioCodecMap; + while (m->name) { + qDebug() << "audio" << m->name << [AVURLAsset isPlayableExtendedMIMEType:[NSString stringWithUTF8String:m->name]]; + if ([AVURLAsset isPlayableExtendedMIMEType:[NSString stringWithUTF8String:m->name]]) + m_decodableAudioCodecs << m->value; + ++m; + } + } + // Audio format seems to be symmetric + m_encodableAudioCodecs = m_decodableAudioCodecs; + + // ### Haven't seen a good way to figure this out. + // seems AVFoundation only supports those for encoding + m_encodableMediaContainers << QMediaFormat::MPEG4 << QMediaFormat::QuickTime; + // AVCaptureVideoDataOutput.availableVideoCodecTypes does not mention H265 even though it is supported + m_encodableVideoCodecs << QMediaFormat::VideoCodec::H264 << QMediaFormat::VideoCodec::H265 << QMediaFormat::VideoCodec::MotionJPEG; +} + +QDarwinFormatInfo::~QDarwinFormatInfo() +{ + +} + +QList<QMediaFormat::FileFormat> QDarwinFormatInfo::decodableMediaContainers() const +{ + return m_decodableMediaContainers; +} + +QList<QMediaFormat::AudioCodec> QDarwinFormatInfo::decodableAudioCodecs() const +{ + return m_decodableAudioCodecs; +} + +QList<QMediaFormat::VideoCodec> QDarwinFormatInfo::decodableVideoCodecs() const +{ + return m_decodableVideoCodecs; +} + +QList<QMediaFormat::FileFormat> QDarwinFormatInfo::encodableMediaContainers() const +{ + return m_encodableMediaContainers; +} + +QList<QMediaFormat::AudioCodec> QDarwinFormatInfo::encodableAudioCodecs() const +{ + return m_encodableAudioCodecs; +} + +QList<QMediaFormat::VideoCodec> QDarwinFormatInfo::encodableVideoCodecs() const +{ + return m_encodableVideoCodecs; +} +QT_END_NAMESPACE diff --git a/src/multimedia/platform/darwin/qdarwinformatsinfo_p.h b/src/multimedia/platform/darwin/qdarwinformatsinfo_p.h new file mode 100644 index 000000000..fc6ee1743 --- /dev/null +++ b/src/multimedia/platform/darwin/qdarwinformatsinfo_p.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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$ +** +****************************************************************************/ + +#ifndef QDARWINFORMATINFO_H +#define QDARWINFORMATINFO_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 <private/qmediaplatformformatinfo_p.h> +#include <qlist.h> + +QT_BEGIN_NAMESPACE + +class QDarwinDeviceManager; + +class QDarwinFormatInfo : public QMediaPlatformFormatInfo +{ +public: + QDarwinFormatInfo(); + ~QDarwinFormatInfo(); + + QList<QMediaFormat::FileFormat> decodableMediaContainers() const override; + QList<QMediaFormat::AudioCodec> decodableAudioCodecs() const override; + QList<QMediaFormat::VideoCodec> decodableVideoCodecs() const override; + + QList<QMediaFormat::FileFormat> encodableMediaContainers() const override; + QList<QMediaFormat::AudioCodec> encodableAudioCodecs() const override; + QList<QMediaFormat::VideoCodec> encodableVideoCodecs() const override; + +private: + QList<QMediaFormat::FileFormat> m_decodableMediaContainers; + QList<QMediaFormat::AudioCodec> m_decodableAudioCodecs; + QList<QMediaFormat::VideoCodec> m_decodableVideoCodecs; + + QList<QMediaFormat::FileFormat> m_encodableMediaContainers; + QList<QMediaFormat::AudioCodec> m_encodableAudioCodecs; + QList<QMediaFormat::VideoCodec> m_encodableVideoCodecs; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/platform/darwin/qdarwinintegration.cpp b/src/multimedia/platform/darwin/qdarwinintegration.cpp index 3f969a43a..0d53feb29 100644 --- a/src/multimedia/platform/darwin/qdarwinintegration.cpp +++ b/src/multimedia/platform/darwin/qdarwinintegration.cpp @@ -41,6 +41,7 @@ #include "qdarwindevicemanager_p.h" #include <private/avfmediaplayerservice_p.h> #include <private/avfcameraservice_p.h> +#include <private/qdarwinformatsinfo_p.h> QT_BEGIN_NAMESPACE @@ -52,6 +53,7 @@ QDarwinIntegration::QDarwinIntegration() QDarwinIntegration::~QDarwinIntegration() { delete m_manager; + delete m_formatInfo; } QMediaPlatformDeviceManager *QDarwinIntegration::deviceManager() @@ -61,6 +63,13 @@ QMediaPlatformDeviceManager *QDarwinIntegration::deviceManager() return m_manager; } +QMediaPlatformFormatInfo *QDarwinIntegration::formatInfo() +{ + if (!m_formatInfo) + m_formatInfo = new QDarwinFormatInfo(); + return m_formatInfo; +} + QMediaPlatformCaptureInterface *QDarwinIntegration::createCaptureInterface(QMediaRecorder::CaptureMode) { return new AVFCameraService; diff --git a/src/multimedia/platform/darwin/qdarwinintegration_p.h b/src/multimedia/platform/darwin/qdarwinintegration_p.h index ec9e33b78..2a82448a7 100644 --- a/src/multimedia/platform/darwin/qdarwinintegration_p.h +++ b/src/multimedia/platform/darwin/qdarwinintegration_p.h @@ -64,11 +64,13 @@ public: ~QDarwinIntegration(); QMediaPlatformDeviceManager *deviceManager() override; + QMediaPlatformFormatInfo *formatInfo() override; QMediaPlatformCaptureInterface *createCaptureInterface(QMediaRecorder::CaptureMode /*mode*/) override; QMediaPlatformPlayerInterface *createPlayerInterface() override; QDarwinDeviceManager *m_manager = nullptr; + QMediaPlatformFormatInfo *m_formatInfo = nullptr; }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/gstreamer/common/qgstcodecsinfo.cpp b/src/multimedia/platform/gstreamer/common/qgstcodecsinfo.cpp index 359c0deba..2f1dc4391 100644 --- a/src/multimedia/platform/gstreamer/common/qgstcodecsinfo.cpp +++ b/src/multimedia/platform/gstreamer/common/qgstcodecsinfo.cpp @@ -228,6 +228,16 @@ GList *QGstCodecsInfo::elementFactories(ElementType elementType) const case Muxer: gstElementType = GST_ELEMENT_FACTORY_TYPE_MUXER; break; + case AudioDecoder: + gstElementType = (GstElementFactoryListType)(GST_ELEMENT_FACTORY_TYPE_DECODER | GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO); + break; + case VideoDecoder: + // GST_ELEMENT_FACTORY_TYPE_VIDEO_ENCODER also lists image encoders. We don't want these here. + gstElementType = (GstElementFactoryListType)(GST_ELEMENT_FACTORY_TYPE_DECODER | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO); + break; + case Demuxer: + gstElementType = GST_ELEMENT_FACTORY_TYPE_DEMUXER; + break; } GList *list = gst_element_factory_list_get_elements(gstElementType, GST_RANK_MARGINAL); diff --git a/src/multimedia/platform/gstreamer/common/qgstcodecsinfo_p.h b/src/multimedia/platform/gstreamer/common/qgstcodecsinfo_p.h index b043aa5d7..fb2fb71d9 100644 --- a/src/multimedia/platform/gstreamer/common/qgstcodecsinfo_p.h +++ b/src/multimedia/platform/gstreamer/common/qgstcodecsinfo_p.h @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE class Q_MULTIMEDIA_EXPORT QGstCodecsInfo { public: - enum ElementType { AudioEncoder, VideoEncoder, Muxer }; + enum ElementType { AudioEncoder, VideoEncoder, Muxer, AudioDecoder, VideoDecoder, Demuxer }; struct CodecInfo { QString description; diff --git a/src/multimedia/platform/gstreamer/gstreamer.pri b/src/multimedia/platform/gstreamer/gstreamer.pri index 8d986aef6..6bc041254 100644 --- a/src/multimedia/platform/gstreamer/gstreamer.pri +++ b/src/multimedia/platform/gstreamer/gstreamer.pri @@ -5,10 +5,12 @@ QMAKE_USE_PRIVATE += gstreamer gstreamer_app SOURCES += \ $$PWD/qgstreamerintegration.cpp \ $$PWD/qgstreamerdevicemanager.cpp \ + $$PWD/qgstreamerformatsinfo.cpp HEADERS += \ $$PWD/qgstreamerintegration_p.h \ $$PWD/qgstreamerdevicemanager_p.h \ + $$PWD/qgstreamerformatsinfo_p.h include(audio/audio.pri) include(common/common.pri) diff --git a/src/multimedia/platform/gstreamer/qgstreamerformatsinfo.cpp b/src/multimedia/platform/gstreamer/qgstreamerformatsinfo.cpp new file mode 100644 index 000000000..6f6b6913c --- /dev/null +++ b/src/multimedia/platform/gstreamer/qgstreamerformatsinfo.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 "qgstreamerformatsinfo_p.h" + +#include "private/qgstutils_p.h" +#include "private/qgstcodecsinfo_p.h" + +QT_BEGIN_NAMESPACE + +static struct { + const char *name; + QMediaFormat::FileFormat value; +} videoFormatsMap[] = { + { "video/x-ms-asf", QMediaFormat::FileFormat::ASF }, + { "video/x-msvideo", QMediaFormat::FileFormat::AVI }, + { "video/x-matroska", QMediaFormat::FileFormat::Matroska }, + { "video/quicktime, variant=(string)iso", QMediaFormat::FileFormat::MPEG4 }, + { "video/quicktime", QMediaFormat::FileFormat::QuickTime }, + { "video/ogg", QMediaFormat::FileFormat::Ogg }, + { "video/webm", QMediaFormat::FileFormat::WebM }, + { nullptr, QMediaFormat::FileFormat::MPEG4 } +}; + +static struct { + const char *name; + QMediaFormat::FileFormat value; +} audioFormatsMap[] = { + { "audio/mpeg, mpegversion=(int)1, layer=(int)3", QMediaFormat::FileFormat::MP3 }, + { "audio/mpeg, mpegversion=(int)4", QMediaFormat::FileFormat::AAC }, + { "audio/x-flac", QMediaFormat::FileFormat::FLAC }, + { "audio/x-wma, wmaversion=(int)1", QMediaFormat::FileFormat::WindowsMediaAudio }, + { "audio/x-wma, wmaversion=(int)2", QMediaFormat::FileFormat::WindowsMediaAudio }, + { nullptr, QMediaFormat::FileFormat::MPEG4 }, +}; + +static struct { + const char *name; + QMediaFormat::VideoCodec value; +} videoCodecMap[] = { + { "video/mpeg, mpegversion=(int)1, systemstream=(boolean)false", QMediaFormat::VideoCodec::MPEG1 }, + { "video/mpeg, mpegversion=(int)2, systemstream=(boolean)false", QMediaFormat::VideoCodec::MPEG2 }, + { "video/mpeg, mpegversion=(int)4, systemstream=(boolean)false", QMediaFormat::VideoCodec::MPEG4 }, + { "video/x-h264", QMediaFormat::VideoCodec::H264 }, + { "video/x-h265", QMediaFormat::VideoCodec::H265 }, + { "video/x-vp8", QMediaFormat::VideoCodec::VP8 }, + { "video/x-vp9", QMediaFormat::VideoCodec::VP9 }, + { "video/x-av1", QMediaFormat::VideoCodec::AV1 }, + { "video/x-theora", QMediaFormat::VideoCodec::Theora }, + { "video/", QMediaFormat::VideoCodec::MotionJPEG }, + { nullptr, QMediaFormat::VideoCodec::Invalid } +}; + +static struct { + const char *name; + QMediaFormat::AudioCodec value; +} audioCodecMap[] = { + { "audio/mpeg, mpegversion=(int)1, layer=(int)3", QMediaFormat::AudioCodec::MP3 }, + { "audio/mpeg, mpegversion=(int)4", QMediaFormat::AudioCodec::AAC }, + { "audio/x-ac3", QMediaFormat::AudioCodec::AC3 }, + { "audio/x-eac3", QMediaFormat::AudioCodec::EAC3 }, + { "audio/x-flac", QMediaFormat::AudioCodec::FLAC }, + { "audio/x-wma, wmaversion=(int)1", QMediaFormat::AudioCodec::WindowsMediaAudio }, + { "audio/x-wma, wmaversion=(int)2", QMediaFormat::AudioCodec::WindowsMediaAudio }, + { "audio/x-true-hd", QMediaFormat::AudioCodec::DolbyTrueHD }, + { "audio/x-vorbis", QMediaFormat::AudioCodec::Vorbis }, + { nullptr, QMediaFormat::AudioCodec::Invalid }, +}; + +template<typename Map> +static auto getList(QGstCodecsInfo::ElementType type, Map *map) +{ + using T = decltype(map->value); + QList<T> list; + QGstCodecsInfo info(type); + auto codecs = info.supportedCodecs(); + for (const auto &c : codecs) { + Map *m = map; + while (m->name) { + if (m->name == c.toLatin1()) { + list.append(m->value); + break; + } + ++m; + } + } + return list; +} + +QGstreamerFormatsInfo::QGstreamerFormatsInfo() +{ + m_decodableMediaContainers = getList(QGstCodecsInfo::Demuxer, videoFormatsMap); + m_decodableMediaContainers.append(getList(QGstCodecsInfo::AudioDecoder, audioFormatsMap)); + m_decodableAudioCodecs = getList(QGstCodecsInfo::AudioDecoder, audioCodecMap); + m_decodableVideoCodecs = getList(QGstCodecsInfo::VideoDecoder, videoCodecMap); + + m_encodableMediaContainers = getList(QGstCodecsInfo::Muxer, videoFormatsMap); + m_encodableMediaContainers.append(getList(QGstCodecsInfo::AudioEncoder, audioFormatsMap)); + m_encodableAudioCodecs = getList(QGstCodecsInfo::AudioEncoder, audioCodecMap); + m_encodableVideoCodecs = getList(QGstCodecsInfo::VideoEncoder, videoCodecMap); +} + +QGstreamerFormatsInfo::~QGstreamerFormatsInfo() +{ + +} + + +QList<QMediaFormat::FileFormat> QGstreamerFormatsInfo::decodableMediaContainers() const +{ + return m_decodableMediaContainers; +} + +QList<QMediaFormat::AudioCodec> QGstreamerFormatsInfo::decodableAudioCodecs() const +{ + return m_decodableAudioCodecs; +} + +QList<QMediaFormat::VideoCodec> QGstreamerFormatsInfo::decodableVideoCodecs() const +{ + return m_decodableVideoCodecs; +} + +QList<QMediaFormat::FileFormat> QGstreamerFormatsInfo::encodableMediaContainers() const +{ + return m_encodableMediaContainers; +} + +QList<QMediaFormat::AudioCodec> QGstreamerFormatsInfo::encodableAudioCodecs() const +{ + return m_encodableAudioCodecs; +} + +QList<QMediaFormat::VideoCodec> QGstreamerFormatsInfo::encodableVideoCodecs() const +{ + return m_encodableVideoCodecs; +} + +QT_END_NAMESPACE diff --git a/src/multimedia/platform/gstreamer/qgstreamerformatsinfo_p.h b/src/multimedia/platform/gstreamer/qgstreamerformatsinfo_p.h new file mode 100644 index 000000000..dff690fd6 --- /dev/null +++ b/src/multimedia/platform/gstreamer/qgstreamerformatsinfo_p.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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$ +** +****************************************************************************/ + +#ifndef QGSTREAMERFORMATSINFO_H +#define QGSTREAMERFORMATSINFO_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 <private/qmediaplatformformatinfo_p.h> +#include <qlist.h> + +QT_BEGIN_NAMESPACE + +class QGstreamerFormatsInfo : public QMediaPlatformFormatInfo +{ +public: + QGstreamerFormatsInfo(); + ~QGstreamerFormatsInfo(); + + QList<QMediaFormat::FileFormat> decodableMediaContainers() const override; + QList<QMediaFormat::AudioCodec> decodableAudioCodecs() const override; + QList<QMediaFormat::VideoCodec> decodableVideoCodecs() const override; + + QList<QMediaFormat::FileFormat> encodableMediaContainers() const override; + QList<QMediaFormat::AudioCodec> encodableAudioCodecs() const override; + QList<QMediaFormat::VideoCodec> encodableVideoCodecs() const override; + +private: + QList<QMediaFormat::FileFormat> m_decodableMediaContainers; + QList<QMediaFormat::AudioCodec> m_decodableAudioCodecs; + QList<QMediaFormat::VideoCodec> m_decodableVideoCodecs; + + QList<QMediaFormat::FileFormat> m_encodableMediaContainers; + QList<QMediaFormat::AudioCodec> m_encodableAudioCodecs; + QList<QMediaFormat::VideoCodec> m_encodableVideoCodecs; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/platform/gstreamer/qgstreamerintegration.cpp b/src/multimedia/platform/gstreamer/qgstreamerintegration.cpp index f31133f21..1140f12e8 100644 --- a/src/multimedia/platform/gstreamer/qgstreamerintegration.cpp +++ b/src/multimedia/platform/gstreamer/qgstreamerintegration.cpp @@ -43,6 +43,7 @@ #include "private/qgstreamerplayerservice_p.h" #include "private/qgstreamercaptureservice_p.h" #include "private/qgstreameraudiodecodercontrol_p.h" +#include "private/qgstreamerformatsinfo_p.h" QT_BEGIN_NAMESPACE @@ -54,6 +55,7 @@ QGstreamerIntegration::QGstreamerIntegration() QGstreamerIntegration::~QGstreamerIntegration() { delete m_manager; + delete m_formatsInfo; } QMediaPlatformDeviceManager *QGstreamerIntegration::deviceManager() @@ -63,6 +65,13 @@ QMediaPlatformDeviceManager *QGstreamerIntegration::deviceManager() return m_manager; } +QMediaPlatformFormatInfo *QGstreamerIntegration::formatInfo() +{ + if (!m_formatsInfo) + m_formatsInfo = new QGstreamerFormatsInfo(); + return m_formatsInfo; +} + QAudioDecoderControl *QGstreamerIntegration::createAudioDecoder() { return new QGstreamerAudioDecoderControl(nullptr); diff --git a/src/multimedia/platform/gstreamer/qgstreamerintegration_p.h b/src/multimedia/platform/gstreamer/qgstreamerintegration_p.h index 54c51748f..8a0106627 100644 --- a/src/multimedia/platform/gstreamer/qgstreamerintegration_p.h +++ b/src/multimedia/platform/gstreamer/qgstreamerintegration_p.h @@ -65,12 +65,14 @@ public: ~QGstreamerIntegration(); QMediaPlatformDeviceManager *deviceManager() override; + QMediaPlatformFormatInfo *formatInfo() override; QAudioDecoderControl *createAudioDecoder() override; QMediaPlatformCaptureInterface *createCaptureInterface(QMediaRecorder::CaptureMode mode) override; QMediaPlatformPlayerInterface *createPlayerInterface() override; QGstreamerDeviceManager *m_manager = nullptr; + QMediaPlatformFormatInfo *m_formatsInfo = nullptr; }; QT_END_NAMESPACE diff --git a/src/multimedia/platform/platform.pri b/src/multimedia/platform/platform.pri index c296963b7..1d3481583 100644 --- a/src/multimedia/platform/platform.pri +++ b/src/multimedia/platform/platform.pri @@ -3,12 +3,14 @@ HEADERS += \ $$PWD/qmediaplatformintegration_p.h \ $$PWD/qmediaplatformdevicemanager_p.h \ $$PWD/qmediaplatformplayerinterface_p.h \ + $$PWD/qmediaplatformformatinfo_p.h SOURCES += \ $$PWD/qmediaplatformcaptureinterface.cpp \ $$PWD/qmediaplatformintegration.cpp \ $$PWD/qmediaplatformdevicemanager.cpp \ $$PWD/qmediaplatformplayerinterface.cpp \ + $$PWD/qmediaplatformformatinfo.cpp qtConfig(gstreamer):include(gstreamer/gstreamer.pri) qtConfig(pulseaudio): include(pulseaudio/pulseaudio.pri) diff --git a/src/multimedia/platform/qmediaplatformformatinfo.cpp b/src/multimedia/platform/qmediaplatformformatinfo.cpp new file mode 100644 index 000000000..e157a2455 --- /dev/null +++ b/src/multimedia/platform/qmediaplatformformatinfo.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 "qmediaplatformformatinfo_p.h" + +QT_BEGIN_NAMESPACE + +QMediaPlatformFormatInfo::QMediaPlatformFormatInfo() = default; + +QMediaPlatformFormatInfo::~QMediaPlatformFormatInfo() = default; + +QT_END_NAMESPACE diff --git a/src/multimedia/platform/qmediaplatformformatinfo_p.h b/src/multimedia/platform/qmediaplatformformatinfo_p.h new file mode 100644 index 000000000..0a3d06cb3 --- /dev/null +++ b/src/multimedia/platform/qmediaplatformformatinfo_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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$ +** +****************************************************************************/ + +#ifndef QMEDIAPLATFORMFORMATINFO_H +#define QMEDIAPLATFORMFORMATINFO_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 <private/qtmultimediaglobal_p.h> +#include <qmediaformat.h> + +QT_BEGIN_NAMESPACE + +class Q_AUTOTEST_EXPORT QMediaPlatformFormatInfo +{ +public: + QMediaPlatformFormatInfo(); + virtual ~QMediaPlatformFormatInfo(); + + virtual QList<QMediaFormat::FileFormat> decodableMediaContainers() const = 0; + virtual QList<QMediaFormat::AudioCodec> decodableAudioCodecs() const = 0; + virtual QList<QMediaFormat::VideoCodec> decodableVideoCodecs() const = 0; + + virtual QList<QMediaFormat::FileFormat> encodableMediaContainers() const = 0; + virtual QList<QMediaFormat::AudioCodec> encodableAudioCodecs() const = 0; + virtual QList<QMediaFormat::VideoCodec> encodableVideoCodecs() const = 0; +}; + +QT_END_NAMESPACE + + +#endif // QMEDIAPLATFORMDEVICEMANAGER_H diff --git a/src/multimedia/platform/qmediaplatformintegration_p.h b/src/multimedia/platform/qmediaplatformintegration_p.h index a049c704b..4d46ac39b 100644 --- a/src/multimedia/platform/qmediaplatformintegration_p.h +++ b/src/multimedia/platform/qmediaplatformintegration_p.h @@ -60,6 +60,7 @@ class QMediaPlatformDeviceManager; class QMediaPlatformCaptureInterface; class QMediaPlatformPlayerInterface; class QAudioDecoderControl; +class QMediaPlatformFormatInfo; class Q_MULTIMEDIA_EXPORT QMediaPlatformIntegration { @@ -71,10 +72,12 @@ public: virtual ~QMediaPlatformIntegration(); virtual QMediaPlatformDeviceManager *deviceManager() = 0; + virtual QMediaPlatformFormatInfo *formatInfo() = 0; virtual QAudioDecoderControl *createAudioDecoder() { return nullptr; } virtual QMediaPlatformCaptureInterface *createCaptureInterface(QMediaRecorder::CaptureMode /*mode*/) { return nullptr; } virtual QMediaPlatformPlayerInterface *createPlayerInterface() { return nullptr; } + }; QT_END_NAMESPACE diff --git a/src/multimedia/qmediaformat.cpp b/src/multimedia/qmediaformat.cpp new file mode 100644 index 000000000..43bd38d4b --- /dev/null +++ b/src/multimedia/qmediaformat.cpp @@ -0,0 +1,479 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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 "qmediaformat.h" +#include "private/qmediaplatformintegration_p.h" +#include "private/qmediaplatformformatinfo_p.h" + +QT_BEGIN_NAMESPACE + +namespace { + +// info from https://en.wikipedia.org/wiki/Comparison_of_video_container_formats +constexpr bool audioSupportMatrix[QMediaFormat::FileFormat::LastFileFormat + 1][(int)QMediaFormat::AudioCodec::LastAudioCodec + 1] = +{ + // MP3, AAC, AC3, EAC3, FLAC, DTHD, Opus,Vorbis, Wave, WMA + // Container formats (Audio and Video) + { true, true, true, true, true, false, true, false, false, true }, // ASF + { true, true, true, false, true, false, true, false, false, true }, // AVI, + { true, true, true, true, true, true, true, true, false, true }, // Matroska, + { true, true, true, true, true, true, true, false, false, true }, // MPEG4, + { false, false, false, false, true, false, true, true, false, false }, // Ogg, + { true, true, true, true, false, false, false, false, false, false }, // QuickTime, + { false, false, false, false, true, false, true, true, false, false }, // WebM, + // Audio Formats + { false, true, false, false, false, false, false, false, false, false }, // AAC, + { false, false, false, false, true, false, false, false, false, false }, // FLAC, + { true, false, false, false, false, false, false, false, false, false }, // Mpeg3, + { true, true, true, true, true, true, true, false, false, true }, // Mpeg4Audio, + { false, false, false, false, false, false, true, false, false, false }, // Opus, + { false, false, false, false, false, false, false, false, true, false }, // Wave, + { false, false, false, false, false, false, false, false, false, true }, // WindowsMediaAudio +}; + +// info from https://en.wikipedia.org/wiki/Comparison_of_video_container_formats +constexpr bool videoSupportMatrix[QMediaFormat::FileFormat::LastFileFormat + 1][(int)QMediaFormat::VideoCodec::LastVideoCodec + 1] = +{ + //MPEG1, MPEG2, MPEG4, H264, H265, VP8, VP9, AV1,Theora, MotionJPEG, + // Container formats (Audio and Video) + { true, true, true, true, true, false, false, false, false,false }, // ASF + { true, true, true, true, true, true, true, false, true, true }, // AVI, + { true, true, true, true, true, true, true, true, true, false }, // Matroska, + { true, true, true, true, true, true, true, true, true, true }, // MPEG4, + { false, true, true, true, true, false, false, false, false, true }, // Ogg, + { false, false, false, false, false, false, false, false, true, false }, // QuickTime, + { false, false, false, false, false, true, true, true, false, false }, // WebM, + // Audio Formats + { false, false, false, false, false, false, false, false, false, false }, // AAC, + { false, false, false, false, false, false, false, false, false, false }, // FLAC, + { false, false, false, false, false, false, false, false, false, false }, // Mpeg3, + { false, false, false, false, false, false, false, false, false, false }, // Mpeg4Audio, + { false, false, false, false, false, false, false, false, false, false }, // Opus, + { false, false, false, false, false, false, false, false, false, false }, // Wave, + { false, false, false, false, false, false, false, false, false, false }, // WindowsMediaAudio +}; + +constexpr QMediaFormat::AudioCodec audioPriorityList[] = +{ + QMediaFormat::AudioCodec::AAC, + QMediaFormat::AudioCodec::MP3, + QMediaFormat::AudioCodec::AC3, + QMediaFormat::AudioCodec::Opus, + QMediaFormat::AudioCodec::EAC3, + QMediaFormat::AudioCodec::DolbyTrueHD, + QMediaFormat::AudioCodec::WindowsMediaAudio, + QMediaFormat::AudioCodec::FLAC, + QMediaFormat::AudioCodec::Vorbis, + QMediaFormat::AudioCodec::Wave, + QMediaFormat::AudioCodec::Invalid +}; + +constexpr QMediaFormat::VideoCodec videoPriorityList[] = +{ + QMediaFormat::VideoCodec::H265, + QMediaFormat::VideoCodec::VP9, + QMediaFormat::VideoCodec::H264, + QMediaFormat::VideoCodec::AV1, + QMediaFormat::VideoCodec::VP8, + QMediaFormat::VideoCodec::Theora, + QMediaFormat::VideoCodec::MPEG4, + QMediaFormat::VideoCodec::MPEG2, + QMediaFormat::VideoCodec::MPEG1, + QMediaFormat::VideoCodec::MotionJPEG, +}; + +} + +/*! \enum QMediaFormat::FileFormat + + Describes the container format used in a multimedia file or stream. +*/ + +/*! \enum QMediaFormat::AudioCodec + + Describes the audio coded used in multimedia file or stream. +*/ + +/*! \enum QMediaFormat::AudioCodec + + Describes the video coded used in multimedia file or stream. +*/ + +/*! \class QMediaFormat + + Describes an encoding format for a multimedia file or stream. + + You can check whether a certain QMediaFormat can be used for encoding + or decoding using QMediaDecoderInfo or QMediaEncoderInfo. +*/ + +// these are non inline to make a possible future addition of a d pointer binary compatible +QMediaFormat::QMediaFormat(FileFormat format) + : fmt(format) +{ + Q_UNUSED(d); + const QMediaFormat::VideoCodec *v = videoPriorityList; + while (*v != QMediaFormat::VideoCodec::Invalid) { + if (videoSupportMatrix[fmt][(int)*v]) + break; + ++v; + } + video = *v; + + const QMediaFormat::AudioCodec *a = audioPriorityList; + while (*a != QMediaFormat::AudioCodec::Invalid) { + if (videoSupportMatrix[fmt][(int)*a]) + break; + ++a; + } + audio = *a; +} + +QMediaFormat::~QMediaFormat() = default; +QMediaFormat::QMediaFormat(const QMediaFormat &other) = default; +QMediaFormat &QMediaFormat::operator=(const QMediaFormat &other) = default; + + +/*! \fn void QMediaFormat::setMediaContainer(QMediaFormat::FileFormat container) + + Sets the container to \a container. + + \sa mediaContainer(), QMediaFormat::FileFormat +*/ + +/*! \fn QMediaFormat::FileFormat QMediaFormat::mediaContainer() const + + Returns the container used in this format. + + \sa setMediaContainer(), QMediaFormat::FileFormat +*/ + +/*! \fn void QMediaFormat::setVideoCodec(VideoCodec codec) + + Sets the video codec to \a codec. + + \sa videoCodec(), QMediaFormat::VideoCodec +*/ +bool QMediaFormat::setVideoCodec(VideoCodec codec) +{ + if (!videoSupportMatrix[fmt][(int)codec]) + return false; + video = codec; + return true; +} + +/*! \fn QMediaFormat::VideoCodec QMediaFormat::videoCodec() const + + Returns the video codec used in this format. + + \sa setVideoCodec(), QMediaFormat::VideoCodec +*/ + +/*! \fn void QMediaFormat::setAudioCodec(AudioCodec codec) + + Sets the audio codec to \a codec. + + \sa audioCodec(), QMediaFormat::AudioCodec +*/ +bool QMediaFormat::setAudioCodec(QMediaFormat::AudioCodec codec) +{ + if (!audioSupportMatrix[fmt][(int)codec]) + return false; + audio = codec; + return true; +} + +/*! \fn QMediaFormat::AudioCodec QMediaFormat::audioCodec() const + + Returns the audio codec used in this format. + + \sa setAudioCodec(), QMediaFormat::AudioCodec +*/ + +/*! \fn bool QMediaFormat::isValid() const + + Returns true if the format is valid. +*/ + +/*! + Returns true if Qt Multimedia can decode this format. + + \sa QMediaDecoderInfo + */ +bool QMediaFormat::canDecode() const +{ + if (!QMediaDecoderInfo::supportedFileFormats().contains(fmt)) + return false; + if (audio == QMediaFormat::AudioCodec::Invalid && video == QMediaFormat::VideoCodec::Invalid) + return false; + if (audio != QMediaFormat::AudioCodec::Invalid) { + if (!QMediaDecoderInfo::supportedAudioCodecs().contains(audio)) + return false; + } + if (video != QMediaFormat::VideoCodec::Invalid) { + if (!QMediaDecoderInfo::supportedVideoCodecs().contains(video)) + return false; + } + return true; +} + +/*! + Returns true if Qt Multimedia can encode this format. + + \sa QMediaEncoderInfo +*/ +bool QMediaFormat::canEncode() const +{ + if (!QMediaEncoderInfo::supportedFileFormats().contains(fmt)) + return false; + if (audio == QMediaFormat::AudioCodec::Invalid && video == QMediaFormat::VideoCodec::Invalid) + return false; + if (audio != QMediaFormat::AudioCodec::Invalid) { + if (!QMediaEncoderInfo::supportedAudioCodecs().contains(audio)) + return false; + } + if (video != QMediaFormat::VideoCodec::Invalid) { + if (!QMediaEncoderInfo::supportedVideoCodecs().contains(video)) + return false; + } + return true; +} + +/*! + Returns true if is is an audio-only file format. + */ +bool QMediaFormat::isAudioFormat() const +{ + return fmt >= AAC; +} + +QString QMediaFormat::fileFormatName(QMediaFormat::FileFormat c) +{ + constexpr const char *descriptions[] = { + "ASF", + "AVI", + "Matroska", + "MPEG-4", + "Ogg", + "QuickTime", + "WebM", + // Audio Formats + "AAC", + "FLAC", + "MP3", + "MPEG-4 Audio", + "Opus", + "Wave", + "Windows Media Audio", + }; + return QString::fromUtf8(descriptions[int(c)]); +} + +QString QMediaFormat::audioCodecName(QMediaFormat::AudioCodec c) +{ + constexpr const char *descriptions[] = { + "Invalid", + "MP3", + "AAC", + "AC3", + "EAC3", + "FLAC", + "DolbyTrueHD", + "Opus", + "Vorbis", + "Wave", + "WindowsMediaAudio", + }; + return QString::fromUtf8(descriptions[int(c) + 1]); +} + +QString QMediaFormat::videoCodecName(QMediaFormat::VideoCodec c) +{ + constexpr const char *descriptions[] = { + "Invalid", + "MPEG1", + "MPEG2", + "MPEG4", + "H264", + "H265", + "VP8", + "VP9", + "AV1", + "Theora", + "MotionJPEG" + }; + return QString::fromUtf8(descriptions[int(c) + 1]); +} + +QString QMediaFormat::fileFormatDescription(QMediaFormat::FileFormat c) +{ + constexpr const char *descriptions[] = { + "Windows Media Format (ASF)", + "Audio Video Interleave (AVI)", + "Matroska Multimedia Container", + "MPEG-4 Video Container", + "Ogg", + "QuickTime Container", + "WebM", + // Audio Formats + "Advanced Audio Codec (AAC)", + "Free Lossless Audio Codec (FLAC)", + "MP3", + "MPEG-4 Audio Container", + "Opus Audio Encoding", + "Wave File", + "Windows Media Audio", + }; + return QString::fromUtf8(descriptions[int(c)]); +} + +QString QMediaFormat::audioCodecDescription(QMediaFormat::AudioCodec c) +{ + constexpr const char *descriptions[] = { + "Invalid Audio Codec", + "MP3", + "Advanced Audio Codec (AAC)", + "Dolby Digital (AC3)", + "Dolby Digital Plus (E-AC3)", + "Free Lossless Audio Codec (FLAC)", + "Dolby True HD", + "Opus", + "Vorbis", + "Wave", + "Windows Media Audio", + }; + return QString::fromUtf8(descriptions[int(c) + 1]); +} + +QString QMediaFormat::videoCodecDescription(QMediaFormat::VideoCodec c) +{ + constexpr const char *descriptions[] = { + "Invalid", + "MPEG-1 Video", + "MPEG-2 Video", + "MPEG-4 Video", + "H.264", + "H.265", + "VP8", + "VP9", + "AV1", + "Theora", + "MotionJPEG" + }; + return QString::fromUtf8(descriptions[int(c) + 1]); +} + +/*! \class QMediaDecoderInfo + + QMediaDecoderInfo describes the media formats supported for decoding + on the current platform. + + Qt Multimedia might be able to decode formats that are not listed + in the QMediaFormat::FileFormat, QMediaFormat::AudioCodec and QMediaFormat::VideoCodec enums. + + \sa QMediaFormat::canDecode() +*/ + +/*! + Returns a list of container formats that are supported for decoding by + Qt Multimedia. + + This does not imply that Qt can successfully decode the media file or + stream, as the audio or video codec used within the container might not + be supported. + */ +QList<QMediaFormat::FileFormat> QMediaDecoderInfo::supportedFileFormats() +{ + return QMediaPlatformIntegration::instance()->formatInfo()->decodableMediaContainers(); +} + +/*! + Returns a list of video codecs that are supported for decoding by + Qt Multimedia. + */ +QList<QMediaFormat::VideoCodec> QMediaDecoderInfo::supportedVideoCodecs() +{ + return QMediaPlatformIntegration::instance()->formatInfo()->decodableVideoCodecs(); +} + +/*! + Returns a list of audio codecs that are supported for decoding by + Qt Multimedia. + */ +QList<QMediaFormat::AudioCodec> QMediaDecoderInfo::supportedAudioCodecs() +{ + return QMediaPlatformIntegration::instance()->formatInfo()->decodableAudioCodecs(); +} + +/*! \class QMediaEncodecInfo + + QMediaEncoderInfo describes the media formats supported for + encoding on the current platform. + + \sa QMediaFormat::canEncode() +*/ + +/*! + Returns a list of container formats that are supported for encoding by + Qt Multimedia. + */ +QList<QMediaFormat::FileFormat> QMediaEncoderInfo::supportedFileFormats() +{ + return QMediaPlatformIntegration::instance()->formatInfo()->encodableMediaContainers(); +} + +/*! + Returns a list of video codecs that are supported for encoding by + Qt Multimedia. + */ +QList<QMediaFormat::VideoCodec> QMediaEncoderInfo::supportedVideoCodecs() +{ + return QMediaPlatformIntegration::instance()->formatInfo()->encodableVideoCodecs(); +} + +/*! + Returns a list of audio codecs that are supported for encoding by + Qt Multimedia. + */ +QList<QMediaFormat::AudioCodec> QMediaEncoderInfo::supportedAudioCodecs() +{ + return QMediaPlatformIntegration::instance()->formatInfo()->encodableAudioCodecs(); +} + +QT_END_NAMESPACE diff --git a/src/multimedia/qmediaformat.h b/src/multimedia/qmediaformat.h new file mode 100644 index 000000000..baf4d90eb --- /dev/null +++ b/src/multimedia/qmediaformat.h @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2021 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$ +** +****************************************************************************/ + +#ifndef QMEDIAFORMAT_H +#define QMEDIAFORMAT_H + +#include <QtCore/qsharedpointer.h> +#include <QtMultimedia/qtmultimediaglobal.h> +#include <QtMultimedia/qmultimedia.h> + +QT_BEGIN_NAMESPACE + +class QMediaFormatPrivate; +class Q_MULTIMEDIA_EXPORT QMediaFormat +{ +public: + enum FileFormat { + // Video Formats + ASF, + AVI, + Matroska, + MPEG4, + Ogg, + QuickTime, + WebM, + // Audio Formats + AAC, + FLAC, + MP3, + Mpeg4Audio, + Opus, + Wave, + WindowsMediaAudio, + LastFileFormat = WindowsMediaAudio + }; + + enum class AudioCodec { + Invalid = -1, + MP3, + AAC, + AC3, + EAC3, + FLAC, + DolbyTrueHD, + Opus, + Vorbis, + Wave, + WindowsMediaAudio, + LastAudioCodec = WindowsMediaAudio + }; + + enum class VideoCodec { + Invalid = -1, + MPEG1, + MPEG2, + MPEG4, + H264, + H265, + VP8, + VP9, + AV1, + Theora, + MotionJPEG, + LastVideoCodec = MotionJPEG + }; + + QMediaFormat(FileFormat format); + ~QMediaFormat(); + QMediaFormat(const QMediaFormat &other); + QMediaFormat &operator=(const QMediaFormat &other); + + FileFormat format() const { return fmt; } + + bool setVideoCodec(VideoCodec codec); + VideoCodec videoCodec() const { return video; } + + bool setAudioCodec(AudioCodec codec); + AudioCodec audioCodec() const { return audio; } + + bool canDecode() const; + bool canEncode() const; + + bool isAudioFormat() const; + + static QString fileFormatName(QMediaFormat::FileFormat c); + static QString audioCodecName(QMediaFormat::AudioCodec c); + static QString videoCodecName(QMediaFormat::VideoCodec c); + + static QString fileFormatDescription(QMediaFormat::FileFormat c); + static QString audioCodecDescription(QMediaFormat::AudioCodec c); + static QString videoCodecDescription(QMediaFormat::VideoCodec c); + +private: + FileFormat fmt; + AudioCodec audio = AudioCodec::Invalid; + VideoCodec video = VideoCodec::Invalid; + QMediaFormatPrivate *d = nullptr; +}; + + +class Q_MULTIMEDIA_EXPORT QMediaDecoderInfo +{ +public: + static QList<QMediaFormat::FileFormat> supportedFileFormats(); + static QList<QMediaFormat::VideoCodec> supportedVideoCodecs(); + static QList<QMediaFormat::AudioCodec> supportedAudioCodecs(); +}; + +class Q_MULTIMEDIA_EXPORT QMediaEncoderInfo +{ +public: + static QList<QMediaFormat::FileFormat> supportedFileFormats(); + static QList<QMediaFormat::VideoCodec> supportedVideoCodecs(); + static QList<QMediaFormat::AudioCodec> supportedAudioCodecs(); +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/multimedia/recording/qmediaencodersettings.cpp b/src/multimedia/recording/qmediaencodersettings.cpp index ef6fecfd6..13b7f0e06 100644 --- a/src/multimedia/recording/qmediaencodersettings.cpp +++ b/src/multimedia/recording/qmediaencodersettings.cpp @@ -880,3 +880,8 @@ void QImageEncoderSettings::setEncodingOptions(const QVariantMap &options) QT_END_NAMESPACE + +QMediaEncoderSettings::QMediaEncoderSettings() +{ + +} diff --git a/src/multimedia/recording/qmediaencodersettings.h b/src/multimedia/recording/qmediaencodersettings.h index 0d6a9eddf..3bf57d70c 100644 --- a/src/multimedia/recording/qmediaencodersettings.h +++ b/src/multimedia/recording/qmediaencodersettings.h @@ -136,6 +136,38 @@ private: QSharedDataPointer<QVideoEncoderSettingsPrivate> d; }; +class QMediaFormat; +class Q_MULTIMEDIA_EXPORT QMediaEncoderSettings +{ + + QMediaEncoderSettings(); + + QMediaFormat format(); + void setMediaFormat(const QMediaFormat &); + + QMultimedia::EncodingMode encodingMode() const; + void setEncodingMode(QMultimedia::EncodingMode); + + QMultimedia::EncodingQuality quality() const; + void setQuality(QMultimedia::EncodingQuality quality); + + QSize videoResolution() const; + void setVideoResolution(const QSize &); + void setVideoResolution(int width, int height); + + qreal videoFrameRate() const; + void setVideoFrameRate(qreal rate); + + int videoBitRate() const; + void setVideoBitRate(int bitrate); + + int audioBitRate() const; + void setAudioBitRate(int bitrate); + + int audioChannelCount() const; + void setAudioChannelCount(int channels); +}; + class QImageEncoderSettingsPrivate; class Q_MULTIMEDIA_EXPORT QImageEncoderSettings { diff --git a/tests/auto/unit/mockbackend/qmockintegration_p.h b/tests/auto/unit/mockbackend/qmockintegration_p.h index fb2ccfd79..2870633b9 100644 --- a/tests/auto/unit/mockbackend/qmockintegration_p.h +++ b/tests/auto/unit/mockbackend/qmockintegration_p.h @@ -67,6 +67,7 @@ public: ~QMockIntegration(); QMediaPlatformDeviceManager *deviceManager() override; + QMediaPlatformFormatInfo *formatInfo() override { return nullptr; } QAudioDecoderControl *createAudioDecoder() override; QMediaPlatformPlayerInterface *createPlayerInterface() override; |