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
qandroidformatsinfo.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 <QtCore/qjnienvironment.h>
7#include <QtCore/qjniobject.h>
8#include <qcoreapplication.h>
9
10static const char encoderFilter[] = ".encoder";
11static const char decoderFilter[] = ".decoder";
12
14
16{
17 // Audio/Video/Image formats with their decoder/encoder information is documented at
18 // https://developer.android.com/guide/topics/media/media-formats
19
20 const QJniObject codecsArrayObject = QJniObject::callStaticObjectMethod(
21 "org/qtproject/qt/android/multimedia/QtMultimediaUtils",
22 "getMediaCodecs",
23 "()[Ljava/lang/String;");
24 QStringList codecs;
26 const jobjectArray devsArray = codecsArrayObject.object<jobjectArray>();
27 for (int i = 0; i < env->GetArrayLength(devsArray); ++i) {
28 const QString codec = QJniObject(env->GetObjectArrayElement(devsArray, i)).toString();
29 if (codec.contains(QStringLiteral("encoder")))
30 m_supportedEncoders.append(codec);
31 else
32 m_supportedDecoders.append(codec);
33 }
34
35 auto removeUnspecifiedValues = [](QList<CodecMap> &map) {
36 for (CodecMap &codec : map) {
39 }
40 erase_if(map, [](const CodecMap &codec) {
41 return codec.audio.isEmpty() && codec.video.isEmpty();
42 });
43 };
44
45 {
51
57
58 decoders = {
59 { QMediaFormat::AAC, {aac}, {} },
60 { QMediaFormat::MP3, {mp3}, {} },
61 { QMediaFormat::FLAC, {flac}, {} },
62 { QMediaFormat::Mpeg4Audio, {mp3, aac, flac, vorbis}, {} },
63 { QMediaFormat::MPEG4, {mp3, aac, flac, vorbis}, {h264, h265, av1} },
64 { QMediaFormat::Ogg, {opus, vorbis, flac}, {} },
65 { QMediaFormat::Matroska, {mp3, opus, vorbis}, {vp8, vp9, h264, h265, av1} },
66 { QMediaFormat::WebM, {opus, vorbis}, {vp8, vp9} }
67 };
68
69 removeUnspecifiedValues(decoders);
70 }
71
72 {
77
83
84 // MP3 and Vorbis encoders are not supported by the default Android SDK
85 // Opus encoder available only for Android 10+
86 encoders = {
87 { QMediaFormat::AAC, {aac}, {} },
88 { QMediaFormat::MP3, {mp3}, {} },
89 // FLAC encoder is not supported by the MediaRecorder used for recording
90 // { QMediaFormat::FLAC, {flac}, {} },
91 { QMediaFormat::Mpeg4Audio, {mp3, aac, vorbis}, {} },
92 { QMediaFormat::MPEG4, {mp3, aac, vorbis}, {h264, h265, av1} },
93 { QMediaFormat::Ogg, {opus, vorbis}, {} },
94 { QMediaFormat::Matroska, {mp3, opus}, {vp8, vp9, h264, h265, av1} },
95 // NOTE: WebM seems to be documented to supported with VP8 encoder,
96 // but the Camera API doesn't work with it, keep it commented for now.
97 // { QMediaFormat::WebM, {vorbis, opus}, {vp8, vp9} }
98 };
99
100 removeUnspecifiedValues(encoders);
101 }
102
104 // NOTE: Add later if needed, the Camera API doens't seem to work with it.
105 // imageFormats << QImageCapture::PNG << QImageCapture::WebP;
106}
107
111
113{
116 codecString = QLatin1String("HEVC");
117 return codecString;
118}
119
120QMediaFormat::AudioCodec QAndroidFormatInfo::hasEncoder(QMediaFormat::AudioCodec codec) const
121{
122 const QString codecString = QMediaFormat::audioCodecName(codec);
123 for (auto str : m_supportedEncoders) {
125 return codec;
126 }
128}
129
130QMediaFormat::VideoCodec QAndroidFormatInfo::hasEncoder(QMediaFormat::VideoCodec codec) const
131{
132 const QString codecString = getVideoCodecName(codec);
133 for (auto str : m_supportedEncoders) {
135 return codec;
136 }
138}
139
140QMediaFormat::AudioCodec QAndroidFormatInfo::hasDecoder(QMediaFormat::AudioCodec codec) const
141{
142 const QString codecString = QMediaFormat::audioCodecName(codec);
143 for (auto str : m_supportedDecoders) {
145 return codec;
146 }
148}
149
150QMediaFormat::VideoCodec QAndroidFormatInfo::hasDecoder(QMediaFormat::VideoCodec codec) const
151{
152 const QString codecString = getVideoCodecName(codec);
153 for (auto str : m_supportedDecoders) {
155 return codec;
156 }
158}
159
\inmodule QtCore
\inmodule QtCore
bool isEmpty() const
Definition qmap.h:269
static Q_INVOKABLE QString videoCodecName(VideoCodec codec)
\qmlmethod string QtMultimedia::mediaFormat::videoCodecName(codec) Returns a string based name for co...
AudioCodec
\qmlproperty enumeration QtMultimedia::mediaFormat::fileFormat
static Q_INVOKABLE QString audioCodecName(AudioCodec codec)
\qmlmethod string QtMultimedia::mediaFormat::audioCodecName(codec) Returns a string based name for co...
VideoCodec
\qmlproperty enumeration QtMultimedia::mediaFormat::audioCodec
QList< QImageCapture::FileFormat > imageFormats
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.h:1369
QString str
[2]
QMap< QString, QString > map
[6]
Combined button and popup list for selecting options.
@ CaseInsensitive
static const char decoderFilter[]
static const char encoderFilter[]
static QString getVideoCodecName(QMediaFormat::VideoCodec codec)
qsizetype erase_if(QByteArray &ba, Predicate pred)
Definition qbytearray.h:788
QMediaFormat::AudioCodec codec
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)