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
qmultimedia_drm_support_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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 QMULTIMEDIA_DRM_SUPPORT_P_H
5#define QMULTIMEDIA_DRM_SUPPORT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtMultimedia/private/qtmultimediaglobal_p.h>
19#include <QtMultimedia/qvideoframeformat.h>
20#include <QtCore/qspan.h>
21#include <QtCore/qstring.h>
22
23#include <cstdint>
24#include <optional>
25
26QT_BEGIN_NAMESPACE
27
28class QDebug;
29
30namespace QtMultimediaPrivate {
31
32// see DRM_FORMAT_MOD_VENDOR_* in drm_fourcc.h
33enum class DRMModifier : std::uint64_t { };
34
35static constexpr DRMModifier DmaBufFormatModifierInvalid = DRMModifier{ (1ULL << 56) - 1 };
37
38Q_MULTIMEDIA_EXPORT QString toString(DRMModifier modifier);
39Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug debug, DRMModifier modifier);
40
41constexpr uint32_t fourcc_code(char a, char b, char c, char d)
42{
43 return ((uint32_t)(a) | ((uint32_t)(b) << 8) | ((uint32_t)(c) << 16) | ((uint32_t)(d) << 24));
44}
45
46// clang-format off
47enum class DRMFormat : std::uint32_t {
48 RGBA8888 = fourcc_code('R', 'A', '2', '4'), /* [31:0] R:G:B:A 8:8:8:8 little endian */
49 RGB888 = fourcc_code('R', 'G', '2', '4'), /* [23:0] R:G:B little endian */
50 RG88 = fourcc_code('R', 'G', '8', '8'), /* [15:0] R:G 8:8 little endian */
51 ARGB8888 = fourcc_code('A', 'R', '2', '4'), /* [31:0] A:R:G:B 8:8:8:8 little endian */
52 ABGR8888 = fourcc_code('A', 'B', '2', '4'), /* [31:0] A:B:G:R 8:8:8:8 little endian */
53 XRGB8888 = fourcc_code('X', 'R', '2', '4'), /* [31:0] x:R:G:B 8:8:8:8 little endian */
54 XBGR8888 = fourcc_code('X', 'B', '2', '4'), /* [31:0] x:B:G:R 8:8:8:8 little endian */
55 BGRA8888 = fourcc_code('B', 'A', '2', '4'), /* [31:0] B:G:R:A 8:8:8:8 little endian */
56 BGR888 = fourcc_code('B', 'G', '2', '4'), /* [23:0] B:G:R little endian */
57 GR88 = fourcc_code('G', 'R', '8', '8'), /* [15:0] G:R 8:8 little endian */
58 R8 = fourcc_code('R', '8', ' ', ' '), /* [7:0] R */
59 R16 = fourcc_code('R', '1', '6', ' '), /* [15:0] R little endian */
60 RGB565 = fourcc_code('R', 'G', '1', '6'), /* [15:0] R:G:B 5:6:5 little endian */
61 RG1616 = fourcc_code('R', 'G', '3', '2'), /* [31:0] R:G 16:16 little endian */
62 GR1616 = fourcc_code('G', 'R', '3', '2'), /* [31:0] G:R 16:16 little endian */
63 BGRA1010102 = fourcc_code('B', 'A', '3', '0'), /* [31:0] B:G:R:A 10:10:10:2 little endian */
64 YUYV = fourcc_code('Y', 'U', 'Y', 'V'), /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
65 UYVY = fourcc_code('U', 'Y', 'V', 'Y'), /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
66 AYUV = fourcc_code('A', 'Y', 'U', 'V'), /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
67 NV12 = fourcc_code('N', 'V', '1', '2'), /* 2x2 subsampled Cr:Cb plane */
68 NV21 = fourcc_code('N', 'V', '2', '1'), /* 2x2 subsampled Cb:Cr plane */
69 P010 = fourcc_code('P', '0', '1', '0'), /* 2x2 subsampled Cr:Cb plane, 10 bits per channel */
70 P016 = fourcc_code('P', '0', '1', '6'), /* 2x2 subsampled Cr:Cb plane, 16 bits per channel */
71 YUV411 = fourcc_code('Y', 'U', '1', '1'), /* 4x1 subsampled Cb (1) and Cr (2) planes */
72 YUV420 = fourcc_code('Y', 'U', '1', '2'), /* 2x2 subsampled Cb (1) and Cr (2) planes */
73 YVU420 = fourcc_code('Y', 'V', '1', '2'), /* 2x2 subsampled Cr (1) and Cb (2) planes */
74 YUV422 = fourcc_code('Y', 'U', '1', '6'), /* 2x1 subsampled Cb (1) and Cr (2) planes */
75 YUV444 = fourcc_code('Y', 'U', '2', '4'), /* non-subsampled Cb (1) and Cr (2) planes */
76 MJPEG = fourcc_code('M', 'J', 'P', 'G'), /* Motion-JPEG */
77};
78// clang-format on
79
80Q_MULTIMEDIA_EXPORT QString toString(DRMFormat format);
81Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug debug, DRMFormat format);
82
83#if __cplusplus >= 202302L
84# define constexpr_cxx23 constexpr
85#else
86# define constexpr_cxx23 inline
87#endif
88
90dmaBufFourccFromPixelFormat(const QVideoFrameFormat::PixelFormat format)
91{
92#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
93 constexpr DRMFormat rgba_fourcc = DRMFormat::ABGR8888;
94 constexpr DRMFormat rg_fourcc = DRMFormat::GR88;
95 constexpr DRMFormat rg16_fourcc = DRMFormat::GR1616;
96#else
97 constexpr DRMFormat rgba_fourcc = DRMFormat::RGBA8888;
98 constexpr DRMFormat rg_fourcc = DRMFormat::RG88;
99 constexpr DRMFormat rg16_fourcc = DRMFormat::RG1616;
100#endif
101
102 switch (format) {
103 case QVideoFrameFormat::Format_Invalid:
104 case QVideoFrameFormat::Format_IMC1:
105 case QVideoFrameFormat::Format_IMC2:
106 case QVideoFrameFormat::Format_IMC3:
107 case QVideoFrameFormat::Format_IMC4:
108 case QVideoFrameFormat::Format_SamplerExternalOES:
109 case QVideoFrameFormat::Format_SamplerRect:
110 return {};
111
112 case QVideoFrameFormat::Format_Jpeg: {
113 static constexpr DRMFormat format[] = { DRMFormat::MJPEG };
114 return format;
115 }
116
117 case QVideoFrameFormat::Format_ARGB8888:
118 case QVideoFrameFormat::Format_ARGB8888_Premultiplied:
119 case QVideoFrameFormat::Format_XRGB8888:
120 case QVideoFrameFormat::Format_BGRA8888:
121 case QVideoFrameFormat::Format_BGRA8888_Premultiplied:
122 case QVideoFrameFormat::Format_BGRX8888:
123 case QVideoFrameFormat::Format_ABGR8888:
124 case QVideoFrameFormat::Format_XBGR8888:
125 case QVideoFrameFormat::Format_RGBA8888:
126 case QVideoFrameFormat::Format_RGBX8888:
127 case QVideoFrameFormat::Format_AYUV:
128 case QVideoFrameFormat::Format_AYUV_Premultiplied:
129 case QVideoFrameFormat::Format_UYVY:
130 case QVideoFrameFormat::Format_YUYV: {
131 static constexpr DRMFormat format[] = { rgba_fourcc };
132 return format;
133 }
134
135 case QVideoFrameFormat::Format_Y8: {
136 static constexpr DRMFormat format[] = { DRMFormat::R8 };
137 return format;
138 }
139 case QVideoFrameFormat::Format_Y16: {
140 static constexpr DRMFormat format[] = { DRMFormat::R16 };
141 return format;
142 }
143
144 case QVideoFrameFormat::Format_YUV420P:
145 case QVideoFrameFormat::Format_YUV422P:
146 case QVideoFrameFormat::Format_YV12: {
147 static constexpr DRMFormat format[] = { DRMFormat::R8, DRMFormat::R8, DRMFormat::R8 };
148 return format;
149 }
150 case QVideoFrameFormat::Format_YUV420P10: {
151 static constexpr DRMFormat format[] = { DRMFormat::R16, DRMFormat::R16, DRMFormat::R16 };
152 return format;
153 }
154
155 case QVideoFrameFormat::Format_NV12:
156 case QVideoFrameFormat::Format_NV21: {
157 static constexpr DRMFormat format[] = { DRMFormat::R8, rg_fourcc };
158 return format;
159 }
160
161 case QVideoFrameFormat::Format_P010:
162 case QVideoFrameFormat::Format_P016: {
163 static constexpr DRMFormat format[] = { DRMFormat::R16, rg16_fourcc };
164 return format;
165 }
166 }
167 return {};
168}
169
171dmaBufSingleImageFourccFromPixelFormat(const QVideoFrameFormat::PixelFormat format)
172{
173 switch (format) {
174 case QVideoFrameFormat::Format_NV12:
175 return DRMFormat::NV12;
176 case QVideoFrameFormat::Format_NV21:
177 return DRMFormat::NV21;
178 case QVideoFrameFormat::Format_P010:
179 return DRMFormat::P010;
180 case QVideoFrameFormat::Format_P016:
181 return DRMFormat::P016;
182 case QVideoFrameFormat::Format_YUV420P:
183 return DRMFormat::YUV420;
184 case QVideoFrameFormat::Format_YV12:
185 return DRMFormat::YVU420;
186 case QVideoFrameFormat::Format_YUV422P:
187 return DRMFormat::YUV422;
188 default:
189 return std::nullopt;
190 }
191}
192
193#undef constexpr_cxx23
194
196{
197 switch (format) {
198 case DRMFormat::NV12:
199 return QVideoFrameFormat::Format_NV12;
200 case DRMFormat::NV21:
201 return QVideoFrameFormat::Format_NV21;
202 case DRMFormat::YUV420:
203 return QVideoFrameFormat::Format_YUV420P;
204 case DRMFormat::YVU420:
205 return QVideoFrameFormat::Format_YV12;
206 case DRMFormat::YUV422:
207 return QVideoFrameFormat::Format_YUV422P;
208 case DRMFormat::YUYV:
209 return QVideoFrameFormat::Format_YUYV;
210 case DRMFormat::UYVY:
211 return QVideoFrameFormat::Format_UYVY;
212 case DRMFormat::XRGB8888:
213 return QVideoFrameFormat::Format_XRGB8888;
214 case DRMFormat::XBGR8888:
215 return QVideoFrameFormat::Format_XBGR8888;
216 case DRMFormat::ARGB8888:
217 return QVideoFrameFormat::Format_ARGB8888;
218 case DRMFormat::ABGR8888:
219 return QVideoFrameFormat::Format_ABGR8888;
220 case DRMFormat::R8:
221 return QVideoFrameFormat::Format_Y8;
222 case DRMFormat::R16:
223 return QVideoFrameFormat::Format_Y16;
224 case DRMFormat::P010:
225 return QVideoFrameFormat::Format_P010;
226 case DRMFormat::P016:
227 return QVideoFrameFormat::Format_P016;
228 case DRMFormat::MJPEG:
229 return QVideoFrameFormat::Format_Jpeg;
230
231 // these formats are ambiguous, because they can be premultiplied:
232 case DRMFormat::RGBA8888:
233 return QVideoFrameFormat::Format_RGBA8888;
234 case DRMFormat::BGRA8888:
235 return QVideoFrameFormat::Format_BGRA8888;
236 case DRMFormat::AYUV:
237 return QVideoFrameFormat::Format_AYUV;
238
239 // No QVideoFrameFormat equivalent at all (e.g. 24bpp RGB/BGR with no alpha channel).
241 case DRMFormat::RG88:
243 case DRMFormat::GR88:
250 return std::nullopt;
251 }
252 return std::nullopt;
253}
254
263
265 PerPlane, // one EGL image per plane, using each plane's own DRM format
266 SingleImage, // all planes packed into a single EGL image described by planes[0].drmFormat
267};
268
269} // namespace QtMultimediaPrivate
270
271QT_END_NAMESPACE
272
273#endif
Combined button and popup list for selecting options.
constexpr uint32_t fourcc_code(char a, char b, char c, char d)
QString toString(DRMModifier modifier)
static constexpr DRMModifier DrmFormatModifierLinear
static constexpr DRMModifier DmaBufFormatModifierInvalid
constexpr std::optional< QVideoFrameFormat::PixelFormat > pixelFormatFromDrmFourcc(DRMFormat format)
constexpr_cxx23 std::optional< DRMFormat > dmaBufSingleImageFourccFromPixelFormat(const QVideoFrameFormat::PixelFormat format)
constexpr_cxx23 QSpan< const DRMFormat > dmaBufFourccFromPixelFormat(const QVideoFrameFormat::PixelFormat format)
QString toString(DRMFormat format)
#define constexpr_cxx23