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
4#include "qplatformmediaformatinfo_p.h"
5#include <qset.h>
6
7QT_BEGIN_NAMESPACE
8
9QPlatformMediaFormatInfo::QPlatformMediaFormatInfo() = default;
10
11QPlatformMediaFormatInfo::~QPlatformMediaFormatInfo() = default;
12
13QList<QMediaFormat::FileFormat> QPlatformMediaFormatInfo::supportedFileFormats(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const
14{
15 QSet<QMediaFormat::FileFormat> formats;
16
17 const auto &codecMap = (m == QMediaFormat::Encode) ? encoders : decoders;
18 for (const auto &m : codecMap) {
19 if (constraints.audioCodec() != QMediaFormat::AudioCodec::Unspecified && !m.audio.contains(t: constraints.audioCodec()))
20 continue;
21 if (constraints.videoCodec() != QMediaFormat::VideoCodec::Unspecified && !m.video.contains(t: constraints.videoCodec()))
22 continue;
23 formats.insert(value: m.format);
24 }
25 return formats.values();
26}
27
28QList<QMediaFormat::AudioCodec> QPlatformMediaFormatInfo::supportedAudioCodecs(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const
29{
30 QSet<QMediaFormat::AudioCodec> codecs;
31
32 const auto &codecMap = (m == QMediaFormat::Encode) ? encoders : decoders;
33 for (const auto &m : codecMap) {
34 if (constraints.fileFormat() != QMediaFormat::UnspecifiedFormat && m.format != constraints.fileFormat())
35 continue;
36 if (constraints.videoCodec() != QMediaFormat::VideoCodec::Unspecified && !m.video.contains(t: constraints.videoCodec()))
37 continue;
38 for (const auto &c : m.audio)
39 codecs.insert(value: c);
40 }
41 return codecs.values();
42}
43
44QList<QMediaFormat::VideoCodec> QPlatformMediaFormatInfo::supportedVideoCodecs(const QMediaFormat &constraints, QMediaFormat::ConversionMode m) const
45{
46 QSet<QMediaFormat::VideoCodec> codecs;
47
48 const auto &codecMap = (m == QMediaFormat::Encode) ? encoders : decoders;
49 for (const auto &m : codecMap) {
50 if (constraints.fileFormat() != QMediaFormat::UnspecifiedFormat && m.format != constraints.fileFormat())
51 continue;
52 if (constraints.audioCodec() != QMediaFormat::AudioCodec::Unspecified && !m.audio.contains(t: constraints.audioCodec()))
53 continue;
54 for (const auto &c : m.video)
55 codecs.insert(value: c);
56 }
57 return codecs.values();
58}
59
60bool QPlatformMediaFormatInfo::isSupported(const QMediaFormat &format, QMediaFormat::ConversionMode m) const
61{
62 const auto &codecMap = (m == QMediaFormat::Encode) ? encoders : decoders;
63
64 for (const auto &m : codecMap) {
65 if (m.format != format.fileFormat())
66 continue;
67 if (!m.audio.contains(t: format.audioCodec()))
68 continue;
69 if (format.videoCodec() != QMediaFormat::VideoCodec::Unspecified && !m.video.contains(t: format.videoCodec()))
70 continue;
71 return true;
72 }
73 return false;
74}
75
76QT_END_NAMESPACE
77

source code of qtmultimedia/src/multimedia/platform/qplatformmediaformatinfo.cpp