Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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(
29 category,
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
51bool isSupportedCodec(QMediaFormat::AudioCodec codec, QMediaFormat::ConversionMode mode)
52{
53 return isSupportedMFT((mode == QMediaFormat::Encode) ? MFT_CATEGORY_AUDIO_ENCODER : MFT_CATEGORY_AUDIO_DECODER,
54 { MFMediaType_Audio, QWindowsMultimediaUtils::audioFormatForCodec(codec) },
55 mode);
56}
57
58bool isSupportedCodec(QMediaFormat::VideoCodec codec, QMediaFormat::ConversionMode mode)
59{
60 return isSupportedMFT((mode == QMediaFormat::Encode) ? MFT_CATEGORY_VIDEO_ENCODER : MFT_CATEGORY_VIDEO_DECODER,
61 { MFMediaType_Video, QWindowsMultimediaUtils::videoFormatForCodec(codec) },
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
80{
81 QList<QImageCapture::FileFormat> list;
82 const auto formats = QImageWriter::supportedImageFormats();
83
84 for (const auto &f : formats) {
85 auto format = QString::fromUtf8(f);
86 if (format.compare(QLatin1String("jpg"), Qt::CaseInsensitive) == 0)
87 list.append(QImageCapture::FileFormat::JPEG);
88 else if (format.compare(QLatin1String("png"), Qt::CaseInsensitive) == 0)
89 list.append(QImageCapture::FileFormat::PNG);
90 else if (format.compare(QLatin1String("webp"), Qt::CaseInsensitive) == 0)
91 list.append(QImageCapture::FileFormat::WebP);
92 else if (format.compare(QLatin1String("tiff"), Qt::CaseInsensitive) == 0)
93 list.append(QImageCapture::FileFormat::Tiff);
94 }
95
96 return list;
97}
98
99QWindowsFormatInfo::QWindowsFormatInfo()
100{
101 const QList<CodecMap> containerTable = {
102 { QMediaFormat::MPEG4,
103 { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::ALAC, QMediaFormat::AudioCodec::AC3, QMediaFormat::AudioCodec::EAC3 },
104 { QMediaFormat::VideoCodec::H264, QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::MotionJPEG } },
105 { QMediaFormat::Matroska,
106 { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::ALAC, QMediaFormat::AudioCodec::AC3, QMediaFormat::AudioCodec::EAC3, QMediaFormat::AudioCodec::FLAC, QMediaFormat::AudioCodec::Vorbis, QMediaFormat::AudioCodec::Opus },
107 { QMediaFormat::VideoCodec::H264, QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::VP8, QMediaFormat::VideoCodec::VP9, QMediaFormat::VideoCodec::MotionJPEG } },
108 { QMediaFormat::WebM,
109 { QMediaFormat::AudioCodec::Vorbis, QMediaFormat::AudioCodec::Opus },
110 { QMediaFormat::VideoCodec::VP8, QMediaFormat::VideoCodec::VP9 } },
111 { QMediaFormat::QuickTime,
112 { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::ALAC, QMediaFormat::AudioCodec::AC3, QMediaFormat::AudioCodec::EAC3 },
113 { QMediaFormat::VideoCodec::H264, QMediaFormat::VideoCodec::H265, QMediaFormat::VideoCodec::MotionJPEG } },
114 { QMediaFormat::AAC,
115 { QMediaFormat::AudioCodec::AAC },
116 {} },
117 { QMediaFormat::MP3,
118 { QMediaFormat::AudioCodec::MP3 },
119 {} },
120 { QMediaFormat::FLAC,
121 { QMediaFormat::AudioCodec::FLAC },
122 {} },
123 { QMediaFormat::Mpeg4Audio,
124 { QMediaFormat::AudioCodec::AAC, QMediaFormat::AudioCodec::MP3, QMediaFormat::AudioCodec::ALAC, QMediaFormat::AudioCodec::AC3, QMediaFormat::AudioCodec::EAC3 },
125 {} },
126 { QMediaFormat::WMA,
127 { QMediaFormat::AudioCodec::WMA },
128 {} },
129 { QMediaFormat::WMV,
130 { QMediaFormat::AudioCodec::WMA },
131 { QMediaFormat::VideoCodec::WMV } }
132 };
133
134 const QSet<QMediaFormat::FileFormat> decoderFormats = {
135 QMediaFormat::MPEG4,
136 QMediaFormat::Matroska,
137 QMediaFormat::WebM,
138 QMediaFormat::QuickTime,
139 QMediaFormat::AAC,
140 QMediaFormat::MP3,
141 QMediaFormat::FLAC,
142 QMediaFormat::Mpeg4Audio,
143 QMediaFormat::WMA,
144 QMediaFormat::WMV,
145 };
146
147 const QSet<QMediaFormat::FileFormat> encoderFormats = {
148 QMediaFormat::MPEG4,
149 QMediaFormat::AAC,
150 QMediaFormat::MP3,
151 QMediaFormat::FLAC,
152 QMediaFormat::Mpeg4Audio,
153 QMediaFormat::WMA,
154 QMediaFormat::WMV,
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
180 imageFormats = getImageFormatList();
181}
182
183QWindowsFormatInfo::~QWindowsFormatInfo()
184{
185}
186
187QT_END_NAMESPACE
Combined button and popup list for selecting options.
bool isSupportedCodec(T codec, QMediaFormat::ConversionMode m, CheckedCodecs< T > &checkedCodecs)
bool isSupportedMFT(const GUID &category, const MFT_REGISTER_TYPE_INFO &type, QMediaFormat::ConversionMode mode)
bool isSupportedCodec(QMediaFormat::AudioCodec codec, QMediaFormat::ConversionMode mode)
static QList< QImageCapture::FileFormat > getImageFormatList()