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
qmediaformat.h
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
4#ifndef QMEDIAFORMAT_H
5#define QMEDIAFORMAT_H
6
7#include <QtCore/qobjectdefs.h>
8#include <QtCore/qshareddata.h>
9#include <QtCore/qtmetamacros.h>
10#include <QtMultimedia/qtmultimediaglobal.h>
11
13
14class QMimeType;
15class QMediaFormat;
17
18QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QMediaFormatPrivate, Q_MULTIMEDIA_EXPORT)
19
20class Q_MULTIMEDIA_EXPORT QMediaFormat
21{
22 Q_GADGET
23 Q_PROPERTY(FileFormat fileFormat READ fileFormat WRITE setFileFormat)
24 Q_PROPERTY(AudioCodec audioCodec READ audioCodec WRITE setAudioCodec)
25 Q_PROPERTY(VideoCodec videoCodec READ videoCodec WRITE setVideoCodec)
26 Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
27public:
28 enum FileFormat {
29 UnspecifiedFormat = -1,
30 // Video Formats
31 WMV,
32 AVI,
33 Matroska,
34 MPEG4,
35 Ogg,
36 QuickTime,
37 WebM,
38 // Audio Only Formats
39 Mpeg4Audio,
40 AAC,
41 WMA,
42 MP3,
43 FLAC,
44 Wave,
45 LastFileFormat = Wave
46 };
47 Q_ENUM(FileFormat)
48
49 enum class AudioCodec {
50 Unspecified = -1,
51 MP3,
52 AAC,
53 AC3,
54 EAC3,
55 FLAC,
56 DolbyTrueHD,
57 Opus,
58 Vorbis,
59 Wave,
60 WMA,
61 ALAC,
62 LastAudioCodec = ALAC
63 };
64 Q_ENUM(AudioCodec)
65
66 enum class VideoCodec {
67 Unspecified = -1,
68 MPEG1,
69 MPEG2,
70 MPEG4,
71 H264,
72 H265,
73 VP8,
74 VP9,
75 AV1,
76 Theora,
77 WMV,
78 MotionJPEG,
79 LastVideoCodec = MotionJPEG
80 };
81 Q_ENUM(VideoCodec)
82
83 enum ConversionMode {
84 Encode,
85 Decode
86 };
87 Q_ENUM(ConversionMode)
88
89 enum ResolveFlags
90 {
91 NoFlags,
92 RequiresVideo
93 };
94
95 QMediaFormat(FileFormat format = UnspecifiedFormat);
96 ~QMediaFormat();
97 QMediaFormat(const QMediaFormat &other) noexcept;
98 QMediaFormat &operator=(const QMediaFormat &other) noexcept;
99
100 QMediaFormat(QMediaFormat &&other) noexcept = default;
101 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QMediaFormat)
102 void swap(QMediaFormat &other) noexcept
103 {
104 std::swap(fmt, other.fmt);
105 std::swap(audio, other.audio);
106 std::swap(video, other.video);
107 d.swap(other.d);
108 }
109
110 FileFormat fileFormat() const { return fmt; }
111 void setFileFormat(FileFormat f) { fmt = f; }
112
113 void setVideoCodec(VideoCodec codec) { video = codec; }
114 VideoCodec videoCodec() const { return video; }
115
116 void setAudioCodec(AudioCodec codec) { audio = codec; }
117 AudioCodec audioCodec() const { return audio; }
118
119 Q_INVOKABLE bool isSupported(ConversionMode mode) const;
120
121#if QT_CONFIG(mimetype)
122 QMimeType mimeType() const;
123#endif
124
125 Q_INVOKABLE QList<FileFormat> supportedFileFormats(ConversionMode m);
126 Q_INVOKABLE QList<VideoCodec> supportedVideoCodecs(ConversionMode m);
127 Q_INVOKABLE QList<AudioCodec> supportedAudioCodecs(ConversionMode m);
128
129 Q_INVOKABLE static QString fileFormatName(FileFormat fileFormat);
130 Q_INVOKABLE static QString audioCodecName(AudioCodec codec);
131 Q_INVOKABLE static QString videoCodecName(VideoCodec codec);
132
133 Q_INVOKABLE static QString fileFormatDescription(QMediaFormat::FileFormat fileFormat);
134 Q_INVOKABLE static QString audioCodecDescription(QMediaFormat::AudioCodec codec);
135 Q_INVOKABLE static QString videoCodecDescription(QMediaFormat::VideoCodec codec);
136
137 bool operator==(const QMediaFormat &other) const;
138 bool operator!=(const QMediaFormat &other) const
139 { return !operator==(other); }
140
141 void resolveForEncoding(ResolveFlags flags);
142
143protected:
144 friend class QMediaFormatPrivate;
145 FileFormat fmt;
146 AudioCodec audio = AudioCodec::Unspecified;
147 VideoCodec video = VideoCodec::Unspecified;
148 QExplicitlySharedDataPointer<QMediaFormatPrivate> d;
149};
150
151QT_END_NAMESPACE
152
153#endif
\inmodule QtMultimedia