-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_hw_video_acc.c
791 lines (703 loc) · 27.3 KB
/
detect_hw_video_acc.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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
// Copyright 2014 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// hw_video_acc_* detectors
// For each detector, check both V4L2 and VAAPI capabilities.
#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_V4L2_CODEC)
static const char* kJpegDevicePattern = "/dev/jpeg*";
static const char* kVideoDevicePattern = "/dev/video*";
/* Helper function for detect_video_acc_h264.
* A V4L2 device supports H.264 decoding, if it's
* a mem-to-mem V4L2 device, i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*,
* V4L2_CAP_VIDEO_OUTPUT_* and V4L2_CAP_STREAMING capabilities and it supports
* V4L2_PIX_FMT_H264 as it's input, i.e. for its
* V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE queue.
*/
static bool is_v4l2_dec_h264_device(int fd) {
return is_hw_video_acc_device(fd) &&
(is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_H264) ||
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_H264_SLICE));
}
/* Helper function for detect_video_acc_hevc.
* A V4L2 device supports HEVC decoding, if it's a mem-to-mem V4L2 device,
* i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
* V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_HEVC as it's
* input, i.e. for its V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE queue.
*/
static bool is_v4l2_dec_hevc_device(int fd) {
return is_hw_video_acc_device(fd) &&
(is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_HEVC) ||
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_HEVC_SLICE));
}
/* Helper function for detect_video_acc_vp8.
* A V4L2 device supports VP8 decoding, if it's a mem-to-mem V4L2 device,
* i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
* V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_VP8 as it's
* input, i.e. for its V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE queue.
*/
static bool is_v4l2_dec_vp8_device(int fd) {
return is_hw_video_acc_device(fd) &&
(is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_VP8) ||
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_VP8_FRAME));
}
/* Helper function for detect_video_acc_vp9.
* A V4L2 device supports VP9 decoding, if it's a mem-to-mem V4L2 device,
* i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
* V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_VP9 as it's
* input, i.e. for its V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE queue.
*/
static bool is_v4l2_dec_vp9_device(int fd) {
return is_hw_video_acc_device(fd) &&
(is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_VP9) ||
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_VP9_FRAME));
}
/* Helper function for detect_video_acc_av1.
* A V4L2 device supports AV1 decoding, if it's a mem-to-mem V4L2 device,
* i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
* V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_AV1 as it's
* input, i.e. for its V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE queue.
*/
static bool is_v4l2_dec_av1_device(int fd) {
return is_hw_video_acc_device(fd) &&
(is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_AV1) ||
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_AV1_FRAME));
}
/* Helper function for detect_video_acc_enc_h264.
* A V4L2 device supports H.264 encoding, if it's a mem-to-mem V4L2 device,
* i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
* V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_H264 as it's
* output, i.e. for its V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE queue.
*/
static bool is_v4l2_enc_h264_device(int fd) {
return is_hw_video_acc_device(fd) &&
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
V4L2_PIX_FMT_H264);
}
/* Helper function for detect_video_acc_enc_h264_vbr.
* Returns true if the v4l2 device supports h264 encoding (see
* is_v4l2_enc_h264_device comment) and variable bitrate encoding.
*/
static bool is_v4l2_enc_h264_vbr_device(int fd) {
return is_v4l2_enc_h264_device(fd) && is_v4l2_enc_vbr_supported(fd);
}
/* Helper function for detect_video_acc_enc_vp8.
* A V4L2 device supports VP8 encoding, if it's a mem-to-mem V4L2 device,
* i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
* V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_VP8 as it's
* output, i.e. for its V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE queue.
*/
static bool is_v4l2_enc_vp8_device(int fd) {
return is_hw_video_acc_device(fd) &&
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
V4L2_PIX_FMT_VP8);
}
/* Helper function for detect_video_acc_enc_vp8_vbr.
* Returns true if the v4l2 device supports vp8 encoding (see
* is_v4l2_enc_vp8_device comment) and variable bitrate encoding.
*/
static bool is_v4l2_enc_vp8_vbr_device(int fd) {
return is_v4l2_enc_vp8_device(fd) && is_v4l2_enc_vbr_supported(fd);
}
/* Helper function for detect_jpeg_acc_dec.
* A V4L2 device supports JPEG decoding, if it's a mem-to-mem V4L2 device,
* i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
* V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_JPEG as it's
* input, i.e. for its V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE queue.
*/
static bool is_v4l2_dec_jpeg_device(int fd) {
return is_hw_jpeg_acc_device(fd) &&
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE,
V4L2_PIX_FMT_JPEG);
}
/* Helper function for detect_jpeg_acc_enc.
* A V4L2 device supports JPEG encoding, if it's a mem-to-mem V4L2 device,
* i.e. it provides V4L2_CAP_VIDEO_CAPTURE_*, V4L2_CAP_VIDEO_OUTPUT_* and
* V4L2_CAP_STREAMING capabilities and it supports V4L2_PIX_FMT_JPEG as it's
* output, i.e. for its V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE queue.
*/
static bool is_v4l2_enc_jpeg_device(int fd) {
return is_hw_jpeg_acc_device(fd) &&
is_v4l2_support_format(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
V4L2_PIX_FMT_JPEG);
}
#endif // defined(USE_V4L2_CODEC)
#if defined(USE_VAAPI)
static const char* kDRMDevicePattern = "/dev/dri/renderD*";
/* Helper function for detect_video_acc_h264.
* Determine given |fd| is a VAAPI device supports H.264 decoding, i.e.
* it supports one of H.264 profile, has decoding entry point, and output
* YUV420 formats.
*/
static bool is_vaapi_dec_h264_device(int fd) {
VAProfile va_profiles[] = {VAProfileH264Baseline, VAProfileH264Main,
VAProfileH264High,
VAProfileH264ConstrainedBaseline, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420)) {
return true;
}
return false;
}
/* Helper function for detect_video_acc_vp8.
* Dtermine given |fd| is a VAAPI device supports VP8 decoding, i.e. it
* supports VP8 profile, has decoding entry point, and output YUV420
* formats.
*/
static bool is_vaapi_dec_vp8_device(int fd) {
#if VA_CHECK_VERSION(0, 35, 0)
VAProfile va_profiles[] = {VAProfileVP8Version0_3, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_vp9.
* Determine given |fd| is a VAAPI device supports VP9 decoding, i.e. it
* supports VP9 profile 0, has decoding entry point, and can output YUV420
* format.
*/
static bool is_vaapi_dec_vp9_device(int fd) {
#if VA_CHECK_VERSION(0, 37, 1)
VAProfile va_profiles[] = {VAProfileVP9Profile0, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_vp9_2.
* Determine given |fd| is a VAAPI device supports VP9 decoding Profile 2, i.e.
* it supports VP9 profile 2, has decoding entry point, and can output YUV420
* 10BPP format.
*/
static bool is_vaapi_dec_vp9_2_device(int fd) {
#if VA_CHECK_VERSION(0, 38, 1)
VAProfile va_profiles[] = {VAProfileVP9Profile2, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420_10)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_av1.
* Determine if a VAAPI device supports AV1 decoding, i.e. it
* supports AV1 main profile 0, has decoding entry point, and can output
* YUV420 format.
*/
static bool is_vaapi_dec_av1_device(int fd) {
#if VA_CHECK_VERSION(1, 8, 0)
VAProfile va_profiles[] = {VAProfileAV1Profile0, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_av1_10bpp.
* Determine if a VAAPI device supports AV1 decoding main
* profile 0 (10 bit), i.e. it supports AV1 main profile (10 bit),
* has decoding entry point, and can output YUV420 10BPP format.
*/
static bool is_vaapi_dec_av1_10bpp_device(int fd) {
#if VA_CHECK_VERSION(1, 8, 0)
VAProfile va_profiles[] = {VAProfileAV1Profile0, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420_10)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_hevc.
* Determine if a VAAPI device supports HEVC decoding, i.e. it
* supports HEVC main profile, has decoding entry point, and can output
* YUV420 format.
*/
static bool is_vaapi_dec_hevc_device(int fd) {
#if VA_CHECK_VERSION(1, 0, 0)
VAProfile va_profiles[] = {VAProfileHEVCMain, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_hevc_10bpp.
* Determine if a VAAPI device supports HEVC decoding main
* profile 10 (10 bit), i.e. it supports HEVC main profile 10 (10 bit),
* has decoding entry point, and can output YUV420 10BPP format.
*/
static bool is_vaapi_dec_hevc_10bpp_device(int fd) {
#if VA_CHECK_VERSION(1, 0, 0)
VAProfile va_profiles[] = {VAProfileHEVCMain10, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420_10)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_enc_h264.
* Determine given |fd| is a VAAPI device supports H.264 encoding, i.e. it
* support one of H.264 profile, has encoding entry point, and input YUV420
* formats.
*/
static bool is_vaapi_enc_h264_device(int fd) {
VAProfile va_profiles[] = {VAProfileH264Baseline, VAProfileH264Main,
VAProfileH264High,
VAProfileH264ConstrainedBaseline, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSlice,
VA_RT_FORMAT_YUV420) ||
is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSliceLP,
VA_RT_FORMAT_YUV420)) {
return true;
}
return false;
}
/* Helper function for detect_video_acc_enc_h264.
* Returns true if the vaapi driver supports H.264 encoding (see
* is_vaapi_enc_h264_device comment) with variable bitrate encoding.
*/
static bool is_vaapi_enc_h264_vbr_device(int fd) {
VAProfile va_profiles[] = {VAProfileH264Baseline, VAProfileH264Main,
VAProfileH264High,
VAProfileH264ConstrainedBaseline};
for (size_t i = 0; i < 4; i++) {
VAProfile tmp_va_profiles[] = {va_profiles[i], VAProfileNone};
VAEntrypoint va_entrypoints[] = {VAEntrypointEncSlice,
VAEntrypointEncSliceLP};
VAConfigAttrib va_attribs[] = {{VAConfigAttribRateControl, VA_RC_VBR}};
for (size_t j = 0; j < 2; j++) {
if (is_vaapi_support_formats(fd, tmp_va_profiles, va_entrypoints[j],
VA_RT_FORMAT_YUV420) &&
are_vaapi_attribs_supported(fd, va_profiles[i], va_entrypoints[j],
va_attribs, 1)) {
return true;
}
}
}
return false;
}
/* Helper function for detect_video_acc_enc_vp8.
* Determine given |fd| is a VAAPI device supports VP8 encoding, i.e. it
* supports one of VP8 profile, has encoding entry point, and input YUV420
* formats.
*/
static bool is_vaapi_enc_vp8_device(int fd) {
#if VA_CHECK_VERSION(0, 35, 0)
VAProfile va_profiles[] = {VAProfileVP8Version0_3, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSlice,
VA_RT_FORMAT_YUV420) ||
is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSliceLP,
VA_RT_FORMAT_YUV420)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_enc_vp8.
* Returns true if the vaapi driver supports VP8 encoding (see
* is_vaapi_enc_vp8_device comment) with variable bitrate encoding.
*/
static bool is_vaapi_enc_vp8_vbr_device(int fd) {
#if VA_CHECK_VERSION(0, 35, 0)
VAProfile va_profiles[] = {VAProfileVP8Version0_3, VAProfileNone};
VAEntrypoint va_entrypoints[] = {VAEntrypointEncSlice,
VAEntrypointEncSliceLP};
for (int i = 0; i < 2; i++) {
if (!is_vaapi_support_formats(fd, va_profiles, va_entrypoints[i],
VA_RT_FORMAT_YUV420)) {
continue;
}
VAConfigAttrib va_attribs[] = {{VAConfigAttribRateControl, VA_RC_VBR}};
if (are_vaapi_attribs_supported(fd, VAProfileVP8Version0_3,
va_entrypoints[i], va_attribs, 1)) {
return true;
}
}
#endif
return false;
}
/* Helper function for detect_video_acc_enc_vp9.
* Determine given |fd| is a VAAPI device supports VP9 encoding, i.e. it
* supports one of VP9 profile, has encoding entry point, and input YUV420
* formats.
*/
static bool is_vaapi_enc_vp9_device(int fd) {
#if VA_CHECK_VERSION(0, 37, 1)
VAProfile va_profiles[] = {VAProfileVP9Profile0, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSlice,
VA_RT_FORMAT_YUV420) ||
is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSliceLP,
VA_RT_FORMAT_YUV420)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_enc_vp9.
* Returns true if the vaapi driver supports VP9 encoding (see
* is_vaapi_enc_vp9_device comment) with variable bitrate encoding.
*/
static bool is_vaapi_enc_vp9_vbr_device(int fd) {
#if VA_CHECK_VERSION(0, 37, 1)
VAProfile va_profiles[] = {VAProfileVP9Profile0, VAProfileNone};
VAEntrypoint va_entrypoints[] = {VAEntrypointEncSlice,
VAEntrypointEncSliceLP};
for (int i = 0; i < 2; i++) {
if (!is_vaapi_support_formats(fd, va_profiles, va_entrypoints[i],
VA_RT_FORMAT_YUV420)) {
continue;
}
VAConfigAttrib va_attribs[] = {{VAConfigAttribRateControl, VA_RC_VBR}};
if (are_vaapi_attribs_supported(fd, VAProfileVP9Profile0, va_entrypoints[i],
va_attribs, 1)) {
return true;
}
}
#endif
return false;
}
/* Helper function for detect_video_acc_enc_av1.
* Determine if a VAAPI device supports AV1 encoding.
*/
static bool is_vaapi_enc_av1_vbr_device(int fd) {
#if VA_CHECK_VERSION(1, 17, 0)
VAProfile va_profiles[] = {VAProfileAV1Profile0, VAProfileNone};
VAConfigAttrib va_attribs[] = {{VAConfigAttribRateControl, VA_RC_VBR}};
if ((is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSliceLP,
VA_RT_FORMAT_YUV420) ||
is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSlice,
VA_RT_FORMAT_YUV420)) &&
are_vaapi_attribs_supported(fd, VAProfileAV1Profile0,
VAEntrypointEncSliceLP, va_attribs, 1)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_video_acc_enc_av1.
* Determine if a VAAPI device supports AV1 encoding.
*/
static bool is_vaapi_enc_av1_device(int fd) {
#if VA_CHECK_VERSION(1, 17, 0)
VAProfile va_profiles[] = {VAProfileAV1Profile0, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSliceLP,
VA_RT_FORMAT_YUV420) ||
is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncSlice,
VA_RT_FORMAT_YUV420)) {
return true;
}
#endif
return false;
}
/* Helper function for detect_jpeg_acc_dec.
* Determine given |fd| is a VAAPI device supports JPEG decoding, i.e. it
* supports JPEG profile, has decoding entry point, and output YUV420
* formats.
*/
static bool is_vaapi_dec_jpeg_device(int fd) {
VAProfile va_profiles[] = {VAProfileJPEGBaseline, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointVLD,
VA_RT_FORMAT_YUV420)) {
return true;
}
return false;
}
/* Helper function for detect_jpeg_acc_enc.
* Determine given |fd| is a VAAPI device supports JPEG encoding, i.e. it
* supports JPEG profile, has encoding entry point, and accepts YUV420
* as input.
*/
static bool is_vaapi_enc_jpeg_device(int fd) {
VAProfile va_profiles[] = {VAProfileJPEGBaseline, VAProfileNone};
if (is_vaapi_support_formats(fd, va_profiles, VAEntrypointEncPicture,
VA_RT_FORMAT_YUV420)) {
return true;
}
return false;
}
#endif // defined(USE_VAAPI)
/* Determines "hw_video_acc_h264" label. That is, either the VAAPI device
* supports one of H.264 profile, has decoding entry point, and output
* YUV420 formats. Or there is a /dev/video* device supporting H.264
* decoding.
*/
bool detect_video_acc_h264(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_dec_h264_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_dec_h264_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_vp8" label. That is, either the VAAPI device
* supports VP8 profile, has decoding entry point, and output YUV420
* formats. Or there is a /dev/video* device supporting VP8 decoding.
*/
bool detect_video_acc_vp8(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_dec_vp8_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_dec_vp8_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_vp9" label. That is, either the VAAPI device
* supports VP9 profile, has decoding entry point, and output YUV420
* formats. Or there is a /dev/video* device supporting VP9 decoding.
*/
bool detect_video_acc_vp9(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_dec_vp9_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_dec_vp9_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_vp9_2" label. That is, either the VAAPI device
* supports VP9 profile 2, has decoding entry point, and output YUV420 10BPP
* format.
*/
bool detect_video_acc_vp9_2(void) {
#if defined(USE_VAAPI)
return is_any_device(kDRMDevicePattern, is_vaapi_dec_vp9_2_device);
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "hw_video_acc_av1" label. That is, either the VAAPI device
* supports AV1 main profile 0, has decoding entry point, and output YUV420
* formats.
*/
bool detect_video_acc_av1(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_dec_av1_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_dec_av1_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_av1_10bpp" label. That is, either the VAAPI device
* supports AV1 main profile 0 (10bit), has decoding entry point, and output
* YUV420 10BPP formats.
*/
bool detect_video_acc_av1_10bpp(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_dec_av1_10bpp_device))
return true;
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "hw_video_acc_hevc" label. That is, the VAAPI device supports HEVC
* main profile, has decoding entry point, and outputs YUV420 format.
*/
bool detect_video_acc_hevc(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_dec_hevc_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_dec_hevc_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_hevc_10bpp" label. That is, the VAAPI device
* supports HEVC main profile 10 (10bit), has decoding entry point, and outputs
* YUV420 10BPP format.
*/
bool detect_video_acc_hevc_10bpp(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_dec_hevc_10bpp_device))
return true;
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "hw_video_acc_enc_h264" label. That is, either the VAAPI
* device supports one of H.264 profile, has encoding entry point, and
* input YUV420 formats. Or there is a /dev/video* device supporting H.264
* encoding.
*/
bool detect_video_acc_enc_h264(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_h264_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_enc_h264_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_enc_h264_vbr" label. That is, either there is a
* VAAPI device that supports an H.264 profile with an encoding entrypoint for
* YUV420 and variable bitrate encoding, or there is a /dev/video* device that
* supports H.264 encoding and variable bitrate encoding.
*/
bool detect_video_acc_enc_h264_vbr(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_h264_vbr_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_enc_h264_vbr_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_enc_vp8" label. That is, either the VAAPI device
* supports one of VP8 profile, has encoding entry point, and input YUV420
* formats. Or there is a /dev/video* device supporting VP8 encoding.
*/
bool detect_video_acc_enc_vp8(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_vp8_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_enc_vp8_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_enc_vp8_vbr" label. That is, either there is a VAAPI
* device that supports a VP8 profile with an encoding entrypoint for YUV420 and
* variable bitrate encoding, or there is a /dev/video* device that supports VP8
* encoding and variable bitrate encoding.
*/
bool detect_video_acc_enc_vp8_vbr(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_vp8_vbr_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kVideoDevicePattern, is_v4l2_enc_vp8_vbr_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_video_acc_enc_vp9" label. That is, either the VAAPI device
* supports one of VP9 profile, has encoding entry point, and input YUV420
* formats.
*/
bool detect_video_acc_enc_vp9(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_vp9_device))
return true;
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "hw_video_acc_enc_vp9_vbr" label. That is, there is a VAAPI device
* that supports a VP9 profile with an encoding entrypoint for YUV420 and
* variable bitrate encoding.
*/
bool detect_video_acc_enc_vp9_vbr(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_vp9_vbr_device))
return true;
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "hw_video_acc_enc_av1" label. That is, there is a VAAPI device
* that supports a AV1 profile with an encoding entrypoint and input YUV420
* formats.
*/
bool detect_video_acc_enc_av1(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_av1_device))
return true;
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "hw_video_acc_enc_av1_vbr" label. That is, there is a VAAPI device
* that supports a AV1 profile with an encoding entrypoint and input YUV420
* formats.
*/
bool detect_video_acc_enc_av1_vbr(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_av1_vbr_device))
return true;
#endif // defined(USE_VAAPI)
return false;
}
/* Determines "hw_jpeg_acc_dec" label. That is, either the VAAPI device
* supports jpeg profile, has decoding entry point, and output YUV420
* formats. Or there is a /dev/jpeg* device supporting JPEG decoding.
*/
bool detect_jpeg_acc_dec(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_dec_jpeg_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kJpegDevicePattern, is_v4l2_dec_jpeg_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}
/* Determines "hw_jpeg_acc_enc" label. That is, either the VAAPI device
* supports jpeg profile, has encoding entry point, and output JPEG
* formats. Or there is a /dev/jpeg* device supporting JPEG encoding.
*/
bool detect_jpeg_acc_enc(void) {
#if defined(USE_VAAPI)
if (is_any_device(kDRMDevicePattern, is_vaapi_enc_jpeg_device))
return true;
#endif // defined(USE_VAAPI)
#if defined(USE_V4L2_CODEC)
if (is_any_device(kJpegDevicePattern, is_v4l2_enc_jpeg_device))
return true;
#endif // defined(USE_V4L2_CODEC)
return false;
}