Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsformatinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <mfapi.h>
7#include <mftransform.h>
8#include <private/qcomptr_p.h>
9#include <private/qwindowsmultimediautils_p.h>
10#include <private/qcomtaskresource_p.h>
11
12#include <QtCore/qlist.h>
13#include <QtCore/qset.h>
14#include <QtCore/qhash.h>
15#include <QtGui/qimagewriter.h>
16
18
19namespace {
20
21template<typename T>
22using CheckedCodecs = QHash<QPair<T, QMediaFormat::ConversionMode>, bool>;
23
24bool isSupportedMFT(const GUID &category, const MFT_REGISTER_TYPE_INFO &type, QMediaFormat::ConversionMode mode)
25{
26 UINT32 count = 0;
27 IMFActivate **activateArrayRaw = nullptr;
28 HRESULT hr = MFTEnumEx(
30 MFT_ENUM_FLAG_ALL,
31 (mode == QMediaFormat::Encode) ? nullptr : &type, // Input type
32 (mode == QMediaFormat::Encode) ? &type : nullptr, // Output type
33 &activateArrayRaw,
34 &count
35 );
36
37 if (FAILED(hr))
38 return false;
39
40 QComTaskResource<IMFActivate *[], QComDeleter> activateArray(activateArrayRaw, count);
41 for (UINT32 i = 0; i < count; ++i) {
42 ComPtr<IMFTransform> transform;
43 hr = activateArray[i]->ActivateObject(IID_PPV_ARGS(transform.GetAddressOf()));
44 if (SUCCEEDED(hr))
45 return true;
46 }
47
48 return false;
49}
50
52{
53 return isSupportedMFT((mode == QMediaFormat::Encode) ? MFT_CATEGORY_AUDIO_ENCODER : MFT_CATEGORY_AUDIO_DECODER,
55 mode);
56}
57
59{
60 return isSupportedMFT((mode == QMediaFormat::Encode) ? MFT_CATEGORY_VIDEO_ENCODER : MFT_CATEGORY_VIDEO_DECODER,
62 mode);
63}
64
65template <typename T>
66bool isSupportedCodec(T codec, QMediaFormat::ConversionMode m, CheckedCodecs<T> &checkedCodecs)
67{
68 if (auto it = checkedCodecs.constFind(qMakePair(codec, m)); it != checkedCodecs.constEnd())
69 return it.value();
70
71 const bool supported = isSupportedCodec(codec, m);
72
73 checkedCodecs.insert(qMakePair(codec, m), supported);
74 return supported;
75}
76
77}
78
79static QList<QImageCapture::FileFormat> getImageFormatList()
80{
81 QList<QImageCapture::FileFormat> list;
83
84 for (const auto &f : formats) {
86 if (format.compare(QLatin1String("jpg"), Qt::CaseInsensitive) == 0)
88 else if (format.compare(QLatin1String("png"), Qt::CaseInsensitive) == 0)
90 else if (format.compare(QLatin1String("webp"), Qt::CaseInsensitive) == 0)
92 else if (format.compare(QLatin1String("tiff"), Qt::CaseInsensitive) == 0)
94 }
95
96 return list;
97}
98
100{
101 const QList<CodecMap> containerTable = {
116 {} },
119 {} },
122 {} },
125 {} },
128 {} },
132 };
133
134 const QSet<QMediaFormat::FileFormat> decoderFormats = {
145 };
146
147 const QSet<QMediaFormat::FileFormat> encoderFormats = {
155 };
156
157 CheckedCodecs<QMediaFormat::AudioCodec> checkedAudioCodecs;
158 CheckedCodecs<QMediaFormat::VideoCodec> checkedVideoCodecs;
159
160 auto ensureCodecs = [&] (CodecMap &codecs, QMediaFormat::ConversionMode mode) {
161 codecs.audio.removeIf([&] (auto codec) { return !isSupportedCodec(codec, mode, checkedAudioCodecs); });
162 codecs.video.removeIf([&] (auto codec) { return !isSupportedCodec(codec, mode, checkedVideoCodecs); });
163 return !codecs.video.empty() || !codecs.audio.empty();
164 };
165
166 for (const auto &codecMap : containerTable) {
167 if (decoderFormats.contains(codecMap.format)) {
168 auto m = codecMap;
169 if (ensureCodecs(m, QMediaFormat::Decode))
170 decoders.append(m);
171 }
172
173 if (encoderFormats.contains(codecMap.format)) {
174 auto m = codecMap;
175 if (ensureCodecs(m, QMediaFormat::Encode))
176 encoders.append(m);
177 }
178 }
179
181}
182
186
static QList< QByteArray > supportedImageFormats()
Returns the list of image formats supported by QImageWriter.
qsizetype removeIf(Predicate pred)
Definition qlist.h:604
void append(parameter_type t)
Definition qlist.h:458
AudioCodec
\qmlproperty enumeration QtMultimedia::mediaFormat::fileFormat
ConversionMode
In many cases, systems have asymmetric capabilities and can often decode more formats or codecs than ...
VideoCodec
\qmlproperty enumeration QtMultimedia::mediaFormat::audioCodec
QList< QImageCapture::FileFormat > imageFormats
const_iterator constEnd() const noexcept
Definition qset.h:143
const_iterator constFind(const T &value) const
Definition qset.h:161
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
const QLoggingCategory & category()
[1]
QSet< QString >::iterator it
EGLint EGLint * formats
Combined button and popup list for selecting options.
bool isSupportedMFT(const GUID &category, const MFT_REGISTER_TYPE_INFO &type, QMediaFormat::ConversionMode mode)
bool isSupportedCodec(QMediaFormat::AudioCodec codec, QMediaFormat::ConversionMode mode)
QHash< QPair< T, QMediaFormat::ConversionMode >, bool > CheckedCodecs
Q_MULTIMEDIA_EXPORT GUID audioFormatForCodec(QMediaFormat::AudioCodec codec)
Q_MULTIMEDIA_EXPORT GUID videoFormatForCodec(QMediaFormat::VideoCodec codec)
@ CaseInsensitive
QMediaFormat::AudioCodec codec
static QList< QImageCapture::FileFormat > getImageFormatList()
GLenum mode
const GLfloat * m
GLenum GLenum GLsizei count
GLfloat GLfloat f
GLenum type
GLint GLsizei GLsizei GLenum format
GLuint GLenum GLenum transform
QT_BEGIN_NAMESPACE constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
Definition qpair.h:19
long HRESULT
static QList< QImageCapture::FileFormat > getImageFormatList()
QList< int > list
[14]