-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_resolution.c
499 lines (418 loc) · 17.1 KB
/
detect_resolution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
// Copyright 2017 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// resolution detectors
#if defined(USE_V4L2_CODEC)
#include <linux/videodev2.h>
#endif // defined(USE_V4L2_CODEC)
#if defined(USE_VAAPI)
#include <va/va.h>
#endif // defined(USE_VAAPI)
#include "label_detect.h"
#if defined(USE_V4L2_CODEC)
// TODO(b/255770680): Remove this once V4L2 header is updated.
#ifndef V4L2_PIX_FMT_AV1
#define V4L2_PIX_FMT_AV1 v4l2_fourcc('A', 'V', '0', '1') /* AV1 */
#endif
#ifndef V4L2_PIX_FMT_AV1_FRAME
#define V4L2_PIX_FMT_AV1_FRAME \
v4l2_fourcc('A', 'V', '1', 'F') /* AV1 parsed frame */
#endif
// TODO(b/278157861): Remove this once ChromeOS V4L2 header is updated
#ifndef V4L2_PIX_FMT_HEVC_SLICE
#define V4L2_PIX_FMT_HEVC_SLICE \
v4l2_fourcc('S', '2', '6', '5') /* HEVC parsed slices */
#endif
#endif // defined(USE_V4L2_CODEC)
#if defined(USE_VAAPI) || defined(USE_V4L2_CODEC)
static const int32_t width_4k = 3840;
static const int32_t height_4k = 2160;
#endif
#if defined(USE_VAAPI)
static const int32_t width_8k = 7680;
static const int32_t height_8k = 4320;
#endif
#if defined(USE_VAAPI)
#if VA_CHECK_VERSION(0, 35, 0)
static const char kDRMDevicePattern[] = "/dev/dri/renderD*";
static const VAProfile va_profiles_h264[] = {
VAProfileH264Baseline, VAProfileH264Main, VAProfileH264High,
VAProfileH264ConstrainedBaseline, VAProfileNone};
static const VAProfile va_profiles_vp8[] = {VAProfileVP8Version0_3,
VAProfileNone};
static const VAProfile va_profiles_vp9[] = {VAProfileVP9Profile0,
VAProfileNone};
static const VAProfile va_profiles_av1[] = {VAProfileAV1Profile0,
VAProfileNone};
static const VAProfile va_profiles_hevc[] = {VAProfileHEVCMain, VAProfileNone};
static const VAProfile va_profiles_hevc_10bpp[] = {VAProfileHEVCMain10,
VAProfileNone};
/* Determines if a VAAPI device associated with given |fd| supports
* |va_profiles| for |va_entrypoint|, and its maximum resolution is larger
* than or equal to |min_width|x|min_height|.
*/
static bool query_support_for(int fd,
const VAProfile* va_profiles,
VAEntrypoint va_entrypoint,
bool is_10bpp,
int32_t min_width,
int32_t min_height) {
int32_t resolution_width = 0;
int32_t resolution_height = 0;
const unsigned int va_format =
is_10bpp ? VA_RT_FORMAT_YUV420_10 : VA_RT_FORMAT_YUV420;
return is_vaapi_support_formats(fd, va_profiles, va_entrypoint, va_format) &&
get_vaapi_max_resolution(fd, va_profiles, va_entrypoint, va_format,
&resolution_width, &resolution_height) &&
resolution_width >= min_width && resolution_height >= min_height;
}
static bool query_support_for_dec_h264(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_h264, VAEntrypointVLD, false,
min_width, min_height);
}
static bool query_support_for_enc_h264(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_h264, VAEntrypointEncSlice, false,
min_width, min_height) ||
query_support_for(fd, va_profiles_h264, VAEntrypointEncSliceLP, false,
min_width, min_height);
}
static bool query_support_for_dec_vp8(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_vp8, VAEntrypointVLD, false,
min_width, min_height);
}
static bool query_support_for_enc_vp8(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_vp8, VAEntrypointEncSlice, false,
min_width, min_height) ||
query_support_for(fd, va_profiles_vp8, VAEntrypointEncSliceLP, false,
min_width, min_height);
}
static bool query_support_for_dec_vp9(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_vp9, VAEntrypointVLD, false,
min_width, min_height);
}
static bool query_support_for_enc_vp9(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_vp9, VAEntrypointEncSlice, false,
min_width, min_height) ||
query_support_for(fd, va_profiles_vp9, VAEntrypointEncSliceLP, false,
min_width, min_height);
}
static bool query_support_for_enc_av1(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_av1, VAEntrypointEncSliceLP, false,
min_width, min_height) ||
query_support_for(fd, va_profiles_av1, VAEntrypointEncSlice, false,
min_width, min_height);
}
static bool query_support_for_dec_av1(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_av1, VAEntrypointVLD, false,
min_width, min_height);
}
static bool query_support_for_dec_av1_10bpp(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_av1, VAEntrypointVLD, true,
min_width, min_height);
}
static bool query_support_for_dec_hevc(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_hevc, VAEntrypointVLD, false,
min_width, min_height);
}
static bool query_support_for_dec_hevc_10bpp(int fd,
int32_t min_width,
int32_t min_height) {
return query_support_for(fd, va_profiles_hevc_10bpp, VAEntrypointVLD, true,
min_width, min_height);
}
#endif // VA_CHECK_VERSION(0, 38, 1)
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
static const char kVideoDevicePattern[] = "/dev/video*";
/* Determined if a V4L2 device associated with given |fd| supports |pix_fmt|
* for |buf_type|, and its maximum resolution is larger than 3840x2160.
*/
static bool is_v4l2_4k_device(int fd,
enum v4l2_buf_type buf_type,
uint32_t pix_fmt) {
int32_t resolution_width;
int32_t resolution_height;
if (!is_hw_video_acc_device(fd)) {
return false;
}
if (is_v4l2_support_format(fd, buf_type, pix_fmt)) {
if (get_v4l2_max_resolution(fd, pix_fmt, &resolution_width,
&resolution_height)) {
return resolution_width >= width_4k && resolution_height >= height_4k;
}
}
return false;
}
// Determines if is_v4l2_4k_device() for H264 decoding.
static bool is_v4l2_4k_device_dec_h264(int fd) {
return is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_H264) ||
is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_H264_SLICE);
}
// Determines if is_v4l2_4k_device() for H264 encoding.
static bool is_v4l2_4k_device_enc_h264(int fd) {
return is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
V4L2_PIX_FMT_H264);
}
// Determines if is_v4l2_4k_device() for VP8 decoding.
static bool is_v4l2_4k_device_dec_vp8(int fd) {
return is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_VP8) ||
is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_VP8_FRAME);
}
// Determines if is_v4l2_4k_device() for VP8 encoding.
static bool is_v4l2_4k_device_enc_vp8(int fd) {
return is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
V4L2_PIX_FMT_VP8);
}
// Determines if is_v4l2_4k_device() for VP9 decoding.
static bool is_v4l2_4k_device_dec_vp9(int fd) {
return is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_VP9) ||
is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_VP9_FRAME);
}
// Determines if is_v4l2_4k_device() for VP9 encoding.
static bool is_v4l2_4k_device_enc_vp9(int fd) {
return is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
V4L2_PIX_FMT_VP9);
}
// Determines if is_v4l2_4k_device() for HEVC decoding.
static bool is_v4l2_4k_device_dec_hevc(int fd) {
return is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_HEVC) ||
is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_HEVC_SLICE);
}
// Determines if is_v4l2_4k_device() for AV1 decoding.
static bool is_v4l2_4k_device_dec_av1(int fd) {
return is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_AV1) ||
is_v4l2_4k_device(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_AV1_FRAME);
}
#endif // defined(USE_V4L2_CODEC)
/* Determines "4k_video_h264". Return true, if either the VAAPI device
* supports 4k resolution H264 decoding, has decoding entry point,
* and input YUV420 formats. Or there is a
* /dev/video* device supporting 4k resolution H264 decoding.
*/
bool detect_4k_device_h264(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_h264, width_4k, height_4k);
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_4k_device_dec_h264))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "4k_video_vp8". Return true, if either the VAAPI device
* supports 4k resolution VP8 decoding, has decoding entry point,
* and input YUV420 formats. Or there is a
* /dev/video* device supporting 4k resolution VP8 decoding.
*/
bool detect_4k_device_vp8(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_vp8, width_4k, height_4k);
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_4k_device_dec_vp8))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "4k_video_vp9". Return true, if either the VAAPI device
* supports 4k resolution VP9 decoding, has decoding entry point,
* and input YUV420 formats. Or there is a
* /dev/video* device supporting 4k resolution VP9 decoding.
*/
bool detect_4k_device_vp9(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_vp9, width_4k, height_4k);
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_4k_device_dec_vp9))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "4k_video_av1". Return true, if either the VAAPI device
* supports 4k resolution AV1 decoding, has decoding entry point,
* and input YUV420 formats.
*/
bool detect_4k_device_av1(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_av1, width_4k, height_4k);
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_4k_device_dec_av1))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "4k_video_av1_10bpp". Return true, if either the VAAPI device
* supports 4k resolution AV1 10BPP decoding, has decoding entry point,
* and input YUV420 formats.
*/
bool detect_4k_device_av1_10bpp(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_av1_10bpp, width_4k, height_4k);
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "4k_video_hevc". Return true, if the VAAPI device supports 4k
* resolution HEVC main decoding, has decoding entry point, and outputs YUV420
* format.
*/
bool detect_4k_device_hevc(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_hevc, width_4k, height_4k);
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_4k_device_dec_hevc))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "4k_video_hevc_10bpp". Return true, if the VAAPI device supports
* 4k resolution HEVC main10 10BPP decoding, has decoding entry point, and
* outputs YUV420 format.
*/
bool detect_4k_device_hevc_10bpp(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_hevc_10bpp, width_4k, height_4k);
#endif // defined(USE_VAAPI)
return false;
}
bool detect_8k_device_h264(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_h264, width_8k, height_8k);
#endif // defined(USE_VAAPI)
return false;
}
bool detect_8k_device_vp9(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_vp9, width_8k, height_8k);
#endif // defined(USE_VAAPI)
return false;
}
bool detect_8k_device_av1(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_av1, width_8k, height_8k);
#endif // defined(USE_VAAPI)
return false;
}
bool detect_8k_device_av1_10bpp(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_av1_10bpp, width_8k, height_8k);
#endif // defined(USE_VAAPI)
return false;
}
bool detect_8k_device_hevc(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_hevc, width_8k, height_8k);
#endif // defined(USE_VAAPI)
return false;
}
bool detect_8k_device_hevc_10bpp(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_dec_hevc_10bpp, width_8k, height_8k);
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "4k_video_enc_h264". Return true, if either the VAAPI device
* supports 4k resolution H264 encoding, has encoding entry point,
* and input YUV420 formats. Or there is a
* /dev/video* device supporting 4k resolution H264 encoding.
*/
bool detect_4k_device_enc_h264(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_enc_h264, width_4k, height_4k);
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_4k_device_enc_h264))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "4k_video_enc_vp8". Return true, if either the VAAPI device
* supports 4k resolution VP8 encoding, has encoding entry point,
* and input YUV420 formats. Or there is a
* /dev/video* device supporting 4k resolution VP8 encoding.
*/
bool detect_4k_device_enc_vp8(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_enc_vp8, width_4k, height_4k);
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_4k_device_enc_vp8))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "4k_video_enc_vp9". Return true, if either the VAAPI device
* supports 4k resolution VP9 encoding, has encoding entry point,
* and input YUV420 formats. Or there is a
* /dev/video* device supporting 4k resolution VP9 encoding.
*/
bool detect_4k_device_enc_vp9(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_enc_vp9, width_4k, height_4k);
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_4k_device_enc_vp9))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "4k_video_enc_av1". Return true, if the VAAPI device
* supports 4k resolution AV1 encoding, has encoding entry point,
* and input YUV420 formats.
*/
bool detect_4k_device_enc_av1(void) {
#if defined(USE_VAAPI)
return does_any_device_support_resolution(
kDRMDevicePattern, query_support_for_enc_av1, width_4k, height_4k);
#endif // defined(USE_VAAPI)
return false;
}