19 #include "config_components.h"
57 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
60 if (vas != VA_STATUS_SUCCESS) {
62 "buffer (type %d): %d (%s).\n",
63 type, vas, vaErrorStr(vas));
77 const void *params_data,
80 const void *slice_data,
103 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
104 VASliceParameterBufferType,
105 params_size, nb_params, (
void*)params_data,
107 if (vas != VA_STATUS_SUCCESS) {
109 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
114 "is %#x.\n", pic->
nb_slices, params_size,
117 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
118 VASliceDataBufferType,
119 slice_size, 1, (
void*)slice_data,
121 if (vas != VA_STATUS_SUCCESS) {
123 "data buffer (size %zu): %d (%s).\n",
124 slice_size, vas, vaErrorStr(vas));
125 vaDestroyBuffer(
ctx->hwctx->display,
146 vas = vaDestroyBuffer(
ctx->hwctx->display,
148 if (vas != VA_STATUS_SUCCESS) {
150 "parameter buffer %#x: %d (%s).\n",
156 vas = vaDestroyBuffer(
ctx->hwctx->display,
158 if (vas != VA_STATUS_SUCCESS) {
160 "slice buffer %#x: %d (%s).\n",
181 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
183 if (vas != VA_STATUS_SUCCESS) {
185 "issue: %d (%s).\n", vas, vaErrorStr(vas));
187 goto fail_with_picture;
190 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
192 if (vas != VA_STATUS_SUCCESS) {
194 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
196 goto fail_with_picture;
199 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
201 if (vas != VA_STATUS_SUCCESS) {
203 "%d (%s).\n", vas, vaErrorStr(vas));
205 goto fail_with_picture;
208 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
209 if (vas != VA_STATUS_SUCCESS) {
211 "issue: %d (%s).\n", vas, vaErrorStr(vas));
213 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
220 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
228 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
229 if (vas != VA_STATUS_SUCCESS) {
231 "after error: %d (%s).\n", vas, vaErrorStr(vas));
262 static const struct {
266 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
273 #ifdef VA_FOURCC_I420
281 #ifdef VA_FOURCC_YV16
285 #ifdef VA_FOURCC_Y210
288 #ifdef VA_FOURCC_Y212
295 #ifdef VA_FOURCC_XYUV
298 #ifdef VA_FOURCC_Y410
301 #ifdef VA_FOURCC_Y412
305 #ifdef VA_FOURCC_P010
308 #ifdef VA_FOURCC_P012
311 #ifdef VA_FOURCC_I010
312 MAP(I010, YUV420P10),
319 VAConfigID config_id,
324 VASurfaceAttrib *attr;
326 uint32_t best_fourcc,
fourcc;
332 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
334 if (vas != VA_STATUS_SUCCESS) {
336 "%d (%s).\n", vas, vaErrorStr(vas));
344 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
346 if (vas != VA_STATUS_SUCCESS) {
348 "%d (%s).\n", vas, vaErrorStr(vas));
355 for (
i = 0;
i < nb_attr;
i++) {
356 if (attr[
i].
type != VASurfaceAttribPixelFormat)
359 fourcc = attr[
i].value.value.i;
374 source_format, 0,
NULL);
375 if (
format == best_format)
390 frames->sw_format = best_format;
395 ctx->pixel_format_attribute = (VASurfaceAttrib) {
396 .type = VASurfaceAttribPixelFormat,
397 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
398 .value.type = VAGenericValueTypeInteger,
399 .value.value.i = best_fourcc,
409 static const struct {
415 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
416 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
417 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
419 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
420 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
421 MPEG4AdvancedSimple),
422 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
423 #if VA_CHECK_VERSION(1, 18, 0)
424 MAP(H264, H264_HIGH_10_INTRA,
426 MAP(H264, H264_HIGH_10, H264High10 ),
428 MAP(H264, H264_CONSTRAINED_BASELINE,
429 H264ConstrainedBaseline),
430 MAP(H264, H264_MAIN, H264Main ),
431 MAP(H264, H264_HIGH, H264High ),
432 #if VA_CHECK_VERSION(0, 37, 0)
433 MAP(HEVC, HEVC_MAIN, HEVCMain ),
434 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
435 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
438 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
439 MAP(HEVC, HEVC_REXT, None,
441 MAP(HEVC, HEVC_SCC, None,
444 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
446 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
447 MAP(WMV3, VC1_MAIN, VC1Main ),
448 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
449 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
450 MAP(VC1, VC1_SIMPLE, VC1Simple ),
451 MAP(VC1, VC1_MAIN, VC1Main ),
452 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
453 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
455 #if VA_CHECK_VERSION(0, 38, 0)
456 MAP(VP9, VP9_0, VP9Profile0 ),
458 #if VA_CHECK_VERSION(0, 39, 0)
459 MAP(VP9, VP9_1, VP9Profile1 ),
460 MAP(VP9, VP9_2, VP9Profile2 ),
461 MAP(VP9, VP9_3, VP9Profile3 ),
463 #if VA_CHECK_VERSION(1, 8, 0)
464 MAP(AV1, AV1_MAIN, AV1Profile0),
465 MAP(AV1, AV1_HIGH, AV1Profile1),
467 #if VA_CHECK_VERSION(1, 22, 0)
468 MAP(H266, VVC_MAIN_10, VVCMain10),
480 VAConfigID *va_config,
489 int profile_count, exact_match, matched_ff_profile,
codec_profile;
500 profile_count = vaMaxNumProfiles(hwctx->display);
508 vas = vaQueryConfigProfiles(hwctx->display,
509 profile_list, &profile_count);
510 if (vas != VA_STATUS_SUCCESS) {
512 "%d (%s).\n", vas, vaErrorStr(vas));
517 matched_va_profile = VAProfileNone;
521 int profile_match = 0;
533 for (j = 0; j < profile_count; j++) {
535 exact_match = profile_match;
539 if (j < profile_count) {
548 if (matched_va_profile == VAProfileNone) {
550 "profile %d.\n", codec_desc->
name, avctx->
profile);
558 "supported for hardware decode.\n",
561 "incompatible profile %d instead.\n",
565 "supported for hardware decode.\n",
572 vas = vaCreateConfig(hwctx->display, matched_va_profile,
573 VAEntrypointVLD,
NULL, 0,
575 if (vas != VA_STATUS_SUCCESS) {
577 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
601 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
611 "usable surface formats.\n");
629 frames->initial_pool_size = 0;
631 frames->initial_pool_size = 1;
638 frames->initial_pool_size += 16;
641 frames->initial_pool_size += 8;
644 frames->initial_pool_size += 3;
647 frames->initial_pool_size += 2;
660 if (*va_config != VA_INVALID_ID) {
661 vaDestroyConfig(hwctx->display, *va_config);
662 *va_config = VA_INVALID_ID;
674 VAConfigID va_config = VA_INVALID_ID;
679 hwctx = device_ctx->hwctx;
686 if (va_config != VA_INVALID_ID)
687 vaDestroyConfig(hwctx->display, va_config);
698 ctx->va_config = VA_INVALID_ID;
699 ctx->va_context = VA_INVALID_ID;
706 ctx->hwfc =
ctx->frames->hwctx;
707 ctx->device =
ctx->frames->device_ctx;
708 ctx->hwctx =
ctx->device->hwctx;
715 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
718 ctx->hwfc->surface_ids,
719 ctx->hwfc->nb_surfaces,
721 if (vas != VA_STATUS_SUCCESS) {
723 "context: %d (%s).\n", vas, vaErrorStr(vas));
729 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
743 if (
ctx->va_context != VA_INVALID_ID) {
744 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
745 if (vas != VA_STATUS_SUCCESS) {
747 "context %#x: %d (%s).\n",
748 ctx->va_context, vas, vaErrorStr(vas));
751 if (
ctx->va_config != VA_INVALID_ID) {
752 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
753 if (vas != VA_STATUS_SUCCESS) {
755 "configuration %#x: %d (%s).\n",
756 ctx->va_config, vas, vaErrorStr(vas));