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
170#undef constexpr_cxx23
171
173{
174 switch (format) {
175 case DRMFormat::NV12:
176 return QVideoFrameFormat::Format_NV12;
177 case DRMFormat::NV21:
178 return QVideoFrameFormat::Format_NV21;
179 case DRMFormat::YUV420:
180 return QVideoFrameFormat::Format_YUV420P;
181 case DRMFormat::YVU420:
182 return QVideoFrameFormat::Format_YV12;
183 case DRMFormat::YUV422:
184 return QVideoFrameFormat::Format_YUV422P;
185 case DRMFormat::YUYV:
186 return QVideoFrameFormat::Format_YUYV;
187 case DRMFormat::UYVY:
188 return QVideoFrameFormat::Format_UYVY;
189 case DRMFormat::XRGB8888:
190 return QVideoFrameFormat::Format_XRGB8888;
191 case DRMFormat::XBGR8888:
192 return QVideoFrameFormat::Format_XBGR8888;
193 case DRMFormat::ARGB8888:
194 return QVideoFrameFormat::Format_ARGB8888;
195 case DRMFormat::ABGR8888:
196 return QVideoFrameFormat::Format_ABGR8888;
197 case DRMFormat::R8:
198 return QVideoFrameFormat::Format_Y8;
199 case DRMFormat::R16:
200 return QVideoFrameFormat::Format_Y16;
201 case DRMFormat::P010:
202 return QVideoFrameFormat::Format_P010;
203 case DRMFormat::P016:
204 return QVideoFrameFormat::Format_P016;
205 case DRMFormat::MJPEG:
206 return QVideoFrameFormat::Format_Jpeg;
207
208 // these formats are ambiguous, because they can be premultiplied:
209 case DRMFormat::RGBA8888:
210 return QVideoFrameFormat::Format_RGBA8888;
211 case DRMFormat::BGRA8888:
212 return QVideoFrameFormat::Format_BGRA8888;
213 case DRMFormat::AYUV:
214 return QVideoFrameFormat::Format_AYUV;
215
216 // No QVideoFrameFormat equivalent at all (e.g. 24bpp RGB/BGR with no alpha channel).
218 case DRMFormat::RG88:
220 case DRMFormat::GR88:
227 return std::nullopt;
228 }
229 return std::nullopt;
230}
231
240
241} // namespace QtMultimediaPrivate
242
243QT_END_NAMESPACE
244
245#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 QSpan< const DRMFormat > dmaBufFourccFromPixelFormat(const QVideoFrameFormat::PixelFormat format)
QString toString(DRMFormat format)
#define constexpr_cxx23