19 #include "config_components.h"
44 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
46 if (vas != VA_STATUS_SUCCESS) {
48 "buffer (type %d): %d (%s).\n",
49 type, vas, vaErrorStr(vas));
63 const void *params_data,
65 const void *slice_data,
90 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
91 VASliceParameterBufferType,
92 params_size, 1, (
void*)params_data,
94 if (vas != VA_STATUS_SUCCESS) {
96 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
101 "is %#x.\n", pic->
nb_slices, params_size,
104 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
105 VASliceDataBufferType,
106 slice_size, 1, (
void*)slice_data,
108 if (vas != VA_STATUS_SUCCESS) {
110 "data buffer (size %zu): %d (%s).\n",
111 slice_size, vas, vaErrorStr(vas));
112 vaDestroyBuffer(
ctx->hwctx->display,
133 vas = vaDestroyBuffer(
ctx->hwctx->display,
135 if (vas != VA_STATUS_SUCCESS) {
137 "parameter buffer %#x: %d (%s).\n",
143 vas = vaDestroyBuffer(
ctx->hwctx->display,
145 if (vas != VA_STATUS_SUCCESS) {
147 "slice buffer %#x: %d (%s).\n",
163 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
165 if (vas != VA_STATUS_SUCCESS) {
167 "issue: %d (%s).\n", vas, vaErrorStr(vas));
169 goto fail_with_picture;
172 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
174 if (vas != VA_STATUS_SUCCESS) {
176 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
178 goto fail_with_picture;
181 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
183 if (vas != VA_STATUS_SUCCESS) {
185 "%d (%s).\n", vas, vaErrorStr(vas));
187 goto fail_with_picture;
190 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
191 if (vas != VA_STATUS_SUCCESS) {
193 "issue: %d (%s).\n", vas, vaErrorStr(vas));
195 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
202 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
210 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
211 if (vas != VA_STATUS_SUCCESS) {
213 "after error: %d (%s).\n", vas, vaErrorStr(vas));
240 static const struct {
244 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
251 #ifdef VA_FOURCC_I420
259 #ifdef VA_FOURCC_YV16
263 #ifdef VA_FOURCC_Y210
266 #ifdef VA_FOURCC_Y212
273 #ifdef VA_FOURCC_XYUV
276 #ifdef VA_FOURCC_Y410
279 #ifdef VA_FOURCC_Y412
283 #ifdef VA_FOURCC_P010
286 #ifdef VA_FOURCC_P012
289 #ifdef VA_FOURCC_I010
290 MAP(I010, YUV420P10),
297 VAConfigID config_id,
302 VASurfaceAttrib *attr;
304 uint32_t best_fourcc,
fourcc;
310 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
312 if (vas != VA_STATUS_SUCCESS) {
314 "%d (%s).\n", vas, vaErrorStr(vas));
322 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
324 if (vas != VA_STATUS_SUCCESS) {
326 "%d (%s).\n", vas, vaErrorStr(vas));
333 for (
i = 0;
i < nb_attr;
i++) {
334 if (attr[
i].
type != VASurfaceAttribPixelFormat)
337 fourcc = attr[
i].value.value.i;
352 source_format, 0,
NULL);
353 if (
format == best_format)
368 frames->sw_format = best_format;
373 ctx->pixel_format_attribute = (VASurfaceAttrib) {
374 .type = VASurfaceAttribPixelFormat,
375 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
376 .value.type = VAGenericValueTypeInteger,
377 .value.value.i = best_fourcc,
387 static const struct {
393 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
394 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
395 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
397 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
398 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
399 MPEG4AdvancedSimple),
400 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
401 MAP(H264, H264_CONSTRAINED_BASELINE,
402 H264ConstrainedBaseline),
403 MAP(H264, H264_MAIN, H264Main ),
404 MAP(H264, H264_HIGH, H264High ),
405 #if VA_CHECK_VERSION(0, 37, 0)
406 MAP(HEVC, HEVC_MAIN, HEVCMain ),
407 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
408 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
411 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
412 MAP(HEVC, HEVC_REXT, None,
414 MAP(HEVC, HEVC_SCC, None,
417 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
419 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
420 MAP(WMV3, VC1_MAIN, VC1Main ),
421 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
422 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
423 MAP(VC1, VC1_SIMPLE, VC1Simple ),
424 MAP(VC1, VC1_MAIN, VC1Main ),
425 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
426 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
428 #if VA_CHECK_VERSION(0, 38, 0)
429 MAP(VP9, VP9_0, VP9Profile0 ),
431 #if VA_CHECK_VERSION(0, 39, 0)
432 MAP(VP9, VP9_1, VP9Profile1 ),
433 MAP(VP9, VP9_2, VP9Profile2 ),
434 MAP(VP9, VP9_3, VP9Profile3 ),
436 #if VA_CHECK_VERSION(1, 8, 0)
437 MAP(AV1, AV1_MAIN, AV1Profile0),
438 MAP(AV1, AV1_HIGH, AV1Profile1),
450 VAConfigID *va_config,
459 int profile_count, exact_match, matched_ff_profile,
codec_profile;
470 profile_count = vaMaxNumProfiles(hwctx->display);
478 vas = vaQueryConfigProfiles(hwctx->display,
479 profile_list, &profile_count);
480 if (vas != VA_STATUS_SUCCESS) {
482 "%d (%s).\n", vas, vaErrorStr(vas));
487 matched_va_profile = VAProfileNone;
491 int profile_match = 0;
503 for (j = 0; j < profile_count; j++) {
505 exact_match = profile_match;
509 if (j < profile_count) {
518 if (matched_va_profile == VAProfileNone) {
520 "profile %d.\n", codec_desc->
name, avctx->
profile);
528 "supported for hardware decode.\n",
531 "incompatible profile %d instead.\n",
535 "supported for hardware decode.\n",
542 vas = vaCreateConfig(hwctx->display, matched_va_profile,
543 VAEntrypointVLD,
NULL, 0,
545 if (vas != VA_STATUS_SUCCESS) {
547 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
571 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
581 "usable surface formats.\n");
598 frames->initial_pool_size = 1;
604 frames->initial_pool_size += 16;
607 frames->initial_pool_size += 8;
610 frames->initial_pool_size += 3;
613 frames->initial_pool_size += 2;
625 if (*va_config != VA_INVALID_ID) {
626 vaDestroyConfig(hwctx->display, *va_config);
627 *va_config = VA_INVALID_ID;
639 VAConfigID va_config = VA_INVALID_ID;
644 hwctx = device_ctx->hwctx;
651 if (va_config != VA_INVALID_ID)
652 vaDestroyConfig(hwctx->display, va_config);
663 ctx->va_config = VA_INVALID_ID;
664 ctx->va_context = VA_INVALID_ID;
671 ctx->hwfc =
ctx->frames->hwctx;
672 ctx->device =
ctx->frames->device_ctx;
673 ctx->hwctx =
ctx->device->hwctx;
680 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
683 ctx->hwfc->surface_ids,
684 ctx->hwfc->nb_surfaces,
686 if (vas != VA_STATUS_SUCCESS) {
688 "context: %d (%s).\n", vas, vaErrorStr(vas));
694 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
708 if (
ctx->va_context != VA_INVALID_ID) {
709 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
710 if (vas != VA_STATUS_SUCCESS) {
712 "context %#x: %d (%s).\n",
713 ctx->va_context, vas, vaErrorStr(vas));
716 if (
ctx->va_config != VA_INVALID_ID) {
717 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
718 if (vas != VA_STATUS_SUCCESS) {
720 "configuration %#x: %d (%s).\n",
721 ctx->va_config, vas, vaErrorStr(vas));