19 #include "config_components.h"
46 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
48 if (vas != VA_STATUS_SUCCESS) {
50 "buffer (type %d): %d (%s).\n",
51 type, vas, vaErrorStr(vas));
65 const void *params_data,
68 const void *slice_data,
91 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
92 VASliceParameterBufferType,
93 params_size, nb_params, (
void*)params_data,
95 if (vas != VA_STATUS_SUCCESS) {
97 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
102 "is %#x.\n", pic->
nb_slices, params_size,
105 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
106 VASliceDataBufferType,
107 slice_size, 1, (
void*)slice_data,
109 if (vas != VA_STATUS_SUCCESS) {
111 "data buffer (size %zu): %d (%s).\n",
112 slice_size, vas, vaErrorStr(vas));
113 vaDestroyBuffer(
ctx->hwctx->display,
134 vas = vaDestroyBuffer(
ctx->hwctx->display,
136 if (vas != VA_STATUS_SUCCESS) {
138 "parameter buffer %#x: %d (%s).\n",
144 vas = vaDestroyBuffer(
ctx->hwctx->display,
146 if (vas != VA_STATUS_SUCCESS) {
148 "slice buffer %#x: %d (%s).\n",
169 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
171 if (vas != VA_STATUS_SUCCESS) {
173 "issue: %d (%s).\n", vas, vaErrorStr(vas));
175 goto fail_with_picture;
178 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
180 if (vas != VA_STATUS_SUCCESS) {
182 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
184 goto fail_with_picture;
187 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
189 if (vas != VA_STATUS_SUCCESS) {
191 "%d (%s).\n", vas, vaErrorStr(vas));
193 goto fail_with_picture;
196 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
197 if (vas != VA_STATUS_SUCCESS) {
199 "issue: %d (%s).\n", vas, vaErrorStr(vas));
201 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
208 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
216 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
217 if (vas != VA_STATUS_SUCCESS) {
219 "after error: %d (%s).\n", vas, vaErrorStr(vas));
246 static const struct {
250 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
257 #ifdef VA_FOURCC_I420
265 #ifdef VA_FOURCC_YV16
269 #ifdef VA_FOURCC_Y210
272 #ifdef VA_FOURCC_Y212
279 #ifdef VA_FOURCC_XYUV
282 #ifdef VA_FOURCC_Y410
285 #ifdef VA_FOURCC_Y412
289 #ifdef VA_FOURCC_P010
292 #ifdef VA_FOURCC_P012
295 #ifdef VA_FOURCC_I010
296 MAP(I010, YUV420P10),
303 VAConfigID config_id,
308 VASurfaceAttrib *attr;
310 uint32_t best_fourcc,
fourcc;
316 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
318 if (vas != VA_STATUS_SUCCESS) {
320 "%d (%s).\n", vas, vaErrorStr(vas));
328 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
330 if (vas != VA_STATUS_SUCCESS) {
332 "%d (%s).\n", vas, vaErrorStr(vas));
339 for (
i = 0;
i < nb_attr;
i++) {
340 if (attr[
i].
type != VASurfaceAttribPixelFormat)
343 fourcc = attr[
i].value.value.i;
358 source_format, 0,
NULL);
359 if (
format == best_format)
374 frames->sw_format = best_format;
379 ctx->pixel_format_attribute = (VASurfaceAttrib) {
380 .type = VASurfaceAttribPixelFormat,
381 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
382 .value.type = VAGenericValueTypeInteger,
383 .value.value.i = best_fourcc,
393 static const struct {
399 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
400 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
401 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
403 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
404 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
405 MPEG4AdvancedSimple),
406 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
407 #if VA_CHECK_VERSION(1, 18, 0)
408 MAP(H264, H264_HIGH_10_INTRA,
410 MAP(H264, H264_HIGH_10, H264High10 ),
412 MAP(H264, H264_CONSTRAINED_BASELINE,
413 H264ConstrainedBaseline),
414 MAP(H264, H264_MAIN, H264Main ),
415 MAP(H264, H264_HIGH, H264High ),
416 #if VA_CHECK_VERSION(0, 37, 0)
417 MAP(HEVC, HEVC_MAIN, HEVCMain ),
418 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
419 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
422 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
423 MAP(HEVC, HEVC_REXT, None,
425 MAP(HEVC, HEVC_SCC, None,
428 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
430 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
431 MAP(WMV3, VC1_MAIN, VC1Main ),
432 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
433 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
434 MAP(VC1, VC1_SIMPLE, VC1Simple ),
435 MAP(VC1, VC1_MAIN, VC1Main ),
436 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
437 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
439 #if VA_CHECK_VERSION(0, 38, 0)
440 MAP(VP9, VP9_0, VP9Profile0 ),
442 #if VA_CHECK_VERSION(0, 39, 0)
443 MAP(VP9, VP9_1, VP9Profile1 ),
444 MAP(VP9, VP9_2, VP9Profile2 ),
445 MAP(VP9, VP9_3, VP9Profile3 ),
447 #if VA_CHECK_VERSION(1, 8, 0)
448 MAP(AV1, AV1_MAIN, AV1Profile0),
449 MAP(AV1, AV1_HIGH, AV1Profile1),
461 VAConfigID *va_config,
470 int profile_count, exact_match, matched_ff_profile,
codec_profile;
481 profile_count = vaMaxNumProfiles(hwctx->display);
489 vas = vaQueryConfigProfiles(hwctx->display,
490 profile_list, &profile_count);
491 if (vas != VA_STATUS_SUCCESS) {
493 "%d (%s).\n", vas, vaErrorStr(vas));
498 matched_va_profile = VAProfileNone;
502 int profile_match = 0;
514 for (j = 0; j < profile_count; j++) {
516 exact_match = profile_match;
520 if (j < profile_count) {
529 if (matched_va_profile == VAProfileNone) {
531 "profile %d.\n", codec_desc->
name, avctx->
profile);
539 "supported for hardware decode.\n",
542 "incompatible profile %d instead.\n",
546 "supported for hardware decode.\n",
553 vas = vaCreateConfig(hwctx->display, matched_va_profile,
554 VAEntrypointVLD,
NULL, 0,
556 if (vas != VA_STATUS_SUCCESS) {
558 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
582 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
592 "usable surface formats.\n");
610 frames->initial_pool_size = 0;
612 frames->initial_pool_size = 1;
618 frames->initial_pool_size += 16;
621 frames->initial_pool_size += 8;
624 frames->initial_pool_size += 3;
627 frames->initial_pool_size += 2;
640 if (*va_config != VA_INVALID_ID) {
641 vaDestroyConfig(hwctx->display, *va_config);
642 *va_config = VA_INVALID_ID;
654 VAConfigID va_config = VA_INVALID_ID;
659 hwctx = device_ctx->hwctx;
666 if (va_config != VA_INVALID_ID)
667 vaDestroyConfig(hwctx->display, va_config);
678 ctx->va_config = VA_INVALID_ID;
679 ctx->va_context = VA_INVALID_ID;
686 ctx->hwfc =
ctx->frames->hwctx;
687 ctx->device =
ctx->frames->device_ctx;
688 ctx->hwctx =
ctx->device->hwctx;
695 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
698 ctx->hwfc->surface_ids,
699 ctx->hwfc->nb_surfaces,
701 if (vas != VA_STATUS_SUCCESS) {
703 "context: %d (%s).\n", vas, vaErrorStr(vas));
709 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
723 if (
ctx->va_context != VA_INVALID_ID) {
724 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
725 if (vas != VA_STATUS_SUCCESS) {
727 "context %#x: %d (%s).\n",
728 ctx->va_context, vas, vaErrorStr(vas));
731 if (
ctx->va_config != VA_INVALID_ID) {
732 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
733 if (vas != VA_STATUS_SUCCESS) {
735 "configuration %#x: %d (%s).\n",
736 ctx->va_config, vas, vaErrorStr(vas));