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,
90 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
91 VASliceParameterBufferType,
92 params_size, nb_params, (
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",
168 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
170 if (vas != VA_STATUS_SUCCESS) {
172 "issue: %d (%s).\n", vas, vaErrorStr(vas));
174 goto fail_with_picture;
177 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
179 if (vas != VA_STATUS_SUCCESS) {
181 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
183 goto fail_with_picture;
186 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
188 if (vas != VA_STATUS_SUCCESS) {
190 "%d (%s).\n", vas, vaErrorStr(vas));
192 goto fail_with_picture;
195 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
196 if (vas != VA_STATUS_SUCCESS) {
198 "issue: %d (%s).\n", vas, vaErrorStr(vas));
200 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
207 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
215 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
216 if (vas != VA_STATUS_SUCCESS) {
218 "after error: %d (%s).\n", vas, vaErrorStr(vas));
245 static const struct {
249 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
256 #ifdef VA_FOURCC_I420
264 #ifdef VA_FOURCC_YV16
268 #ifdef VA_FOURCC_Y210
271 #ifdef VA_FOURCC_Y212
278 #ifdef VA_FOURCC_XYUV
281 #ifdef VA_FOURCC_Y410
284 #ifdef VA_FOURCC_Y412
288 #ifdef VA_FOURCC_P010
291 #ifdef VA_FOURCC_P012
294 #ifdef VA_FOURCC_I010
295 MAP(I010, YUV420P10),
302 VAConfigID config_id,
307 VASurfaceAttrib *attr;
309 uint32_t best_fourcc,
fourcc;
315 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
317 if (vas != VA_STATUS_SUCCESS) {
319 "%d (%s).\n", vas, vaErrorStr(vas));
327 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
329 if (vas != VA_STATUS_SUCCESS) {
331 "%d (%s).\n", vas, vaErrorStr(vas));
338 for (
i = 0;
i < nb_attr;
i++) {
339 if (attr[
i].
type != VASurfaceAttribPixelFormat)
342 fourcc = attr[
i].value.value.i;
357 source_format, 0,
NULL);
358 if (
format == best_format)
373 frames->sw_format = best_format;
378 ctx->pixel_format_attribute = (VASurfaceAttrib) {
379 .type = VASurfaceAttribPixelFormat,
380 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
381 .value.type = VAGenericValueTypeInteger,
382 .value.value.i = best_fourcc,
392 static const struct {
398 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
399 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
400 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
402 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
403 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
404 MPEG4AdvancedSimple),
405 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
406 #if VA_CHECK_VERSION(1, 18, 0)
407 MAP(H264, H264_HIGH_10_INTRA,
409 MAP(H264, H264_HIGH_10, H264High10 ),
411 MAP(H264, H264_CONSTRAINED_BASELINE,
412 H264ConstrainedBaseline),
413 MAP(H264, H264_MAIN, H264Main ),
414 MAP(H264, H264_HIGH, H264High ),
415 #if VA_CHECK_VERSION(0, 37, 0)
416 MAP(HEVC, HEVC_MAIN, HEVCMain ),
417 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
418 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
421 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
422 MAP(HEVC, HEVC_REXT, None,
424 MAP(HEVC, HEVC_SCC, None,
427 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
429 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
430 MAP(WMV3, VC1_MAIN, VC1Main ),
431 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
432 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
433 MAP(VC1, VC1_SIMPLE, VC1Simple ),
434 MAP(VC1, VC1_MAIN, VC1Main ),
435 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
436 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
438 #if VA_CHECK_VERSION(0, 38, 0)
439 MAP(VP9, VP9_0, VP9Profile0 ),
441 #if VA_CHECK_VERSION(0, 39, 0)
442 MAP(VP9, VP9_1, VP9Profile1 ),
443 MAP(VP9, VP9_2, VP9Profile2 ),
444 MAP(VP9, VP9_3, VP9Profile3 ),
446 #if VA_CHECK_VERSION(1, 8, 0)
447 MAP(AV1, AV1_MAIN, AV1Profile0),
448 MAP(AV1, AV1_HIGH, AV1Profile1),
460 VAConfigID *va_config,
469 int profile_count, exact_match, matched_ff_profile,
codec_profile;
480 profile_count = vaMaxNumProfiles(hwctx->display);
488 vas = vaQueryConfigProfiles(hwctx->display,
489 profile_list, &profile_count);
490 if (vas != VA_STATUS_SUCCESS) {
492 "%d (%s).\n", vas, vaErrorStr(vas));
497 matched_va_profile = VAProfileNone;
501 int profile_match = 0;
513 for (j = 0; j < profile_count; j++) {
515 exact_match = profile_match;
519 if (j < profile_count) {
528 if (matched_va_profile == VAProfileNone) {
530 "profile %d.\n", codec_desc->
name, avctx->
profile);
538 "supported for hardware decode.\n",
541 "incompatible profile %d instead.\n",
545 "supported for hardware decode.\n",
552 vas = vaCreateConfig(hwctx->display, matched_va_profile,
553 VAEntrypointVLD,
NULL, 0,
555 if (vas != VA_STATUS_SUCCESS) {
557 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
581 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
591 "usable surface formats.\n");
609 frames->initial_pool_size = 0;
611 frames->initial_pool_size = 1;
617 frames->initial_pool_size += 16;
620 frames->initial_pool_size += 8;
623 frames->initial_pool_size += 3;
626 frames->initial_pool_size += 2;
639 if (*va_config != VA_INVALID_ID) {
640 vaDestroyConfig(hwctx->display, *va_config);
641 *va_config = VA_INVALID_ID;
653 VAConfigID va_config = VA_INVALID_ID;
658 hwctx = device_ctx->hwctx;
665 if (va_config != VA_INVALID_ID)
666 vaDestroyConfig(hwctx->display, va_config);
677 ctx->va_config = VA_INVALID_ID;
678 ctx->va_context = VA_INVALID_ID;
685 ctx->hwfc =
ctx->frames->hwctx;
686 ctx->device =
ctx->frames->device_ctx;
687 ctx->hwctx =
ctx->device->hwctx;
694 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
697 ctx->hwfc->surface_ids,
698 ctx->hwfc->nb_surfaces,
700 if (vas != VA_STATUS_SUCCESS) {
702 "context: %d (%s).\n", vas, vaErrorStr(vas));
708 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
722 if (
ctx->va_context != VA_INVALID_ID) {
723 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
724 if (vas != VA_STATUS_SUCCESS) {
726 "context %#x: %d (%s).\n",
727 ctx->va_context, vas, vaErrorStr(vas));
730 if (
ctx->va_config != VA_INVALID_ID) {
731 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
732 if (vas != VA_STATUS_SUCCESS) {
734 "configuration %#x: %d (%s).\n",
735 ctx->va_config, vas, vaErrorStr(vas));