19 #include "config_components.h"
45 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
47 if (vas != VA_STATUS_SUCCESS) {
49 "buffer (type %d): %d (%s).\n",
50 type, vas, vaErrorStr(vas));
64 const void *params_data,
66 const void *slice_data,
91 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
92 VASliceParameterBufferType,
93 params_size, 1, (
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",
164 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
166 if (vas != VA_STATUS_SUCCESS) {
168 "issue: %d (%s).\n", vas, vaErrorStr(vas));
170 goto fail_with_picture;
173 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
175 if (vas != VA_STATUS_SUCCESS) {
177 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
179 goto fail_with_picture;
182 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
184 if (vas != VA_STATUS_SUCCESS) {
186 "%d (%s).\n", vas, vaErrorStr(vas));
188 goto fail_with_picture;
191 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
192 if (vas != VA_STATUS_SUCCESS) {
194 "issue: %d (%s).\n", vas, vaErrorStr(vas));
196 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
203 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
211 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
212 if (vas != VA_STATUS_SUCCESS) {
214 "after error: %d (%s).\n", vas, vaErrorStr(vas));
241 static const struct {
245 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
252 #ifdef VA_FOURCC_I420
260 #ifdef VA_FOURCC_YV16
264 #ifdef VA_FOURCC_Y210
267 #ifdef VA_FOURCC_Y212
274 #ifdef VA_FOURCC_XYUV
277 #ifdef VA_FOURCC_Y410
280 #ifdef VA_FOURCC_Y412
284 #ifdef VA_FOURCC_P010
287 #ifdef VA_FOURCC_P012
290 #ifdef VA_FOURCC_I010
291 MAP(I010, YUV420P10),
298 VAConfigID config_id,
303 VASurfaceAttrib *attr;
305 uint32_t best_fourcc,
fourcc;
311 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
313 if (vas != VA_STATUS_SUCCESS) {
315 "%d (%s).\n", vas, vaErrorStr(vas));
323 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
325 if (vas != VA_STATUS_SUCCESS) {
327 "%d (%s).\n", vas, vaErrorStr(vas));
334 for (
i = 0;
i < nb_attr;
i++) {
335 if (attr[
i].
type != VASurfaceAttribPixelFormat)
338 fourcc = attr[
i].value.value.i;
353 source_format, 0,
NULL);
354 if (
format == best_format)
369 frames->sw_format = best_format;
374 ctx->pixel_format_attribute = (VASurfaceAttrib) {
375 .type = VASurfaceAttribPixelFormat,
376 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
377 .value.type = VAGenericValueTypeInteger,
378 .value.value.i = best_fourcc,
388 static const struct {
394 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
395 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
396 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
398 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
399 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
400 MPEG4AdvancedSimple),
401 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
402 #if VA_CHECK_VERSION(1, 18, 0)
403 MAP(H264, H264_HIGH_10_INTRA,
405 MAP(H264, H264_HIGH_10, H264High10 ),
407 MAP(H264, H264_CONSTRAINED_BASELINE,
408 H264ConstrainedBaseline),
409 MAP(H264, H264_MAIN, H264Main ),
410 MAP(H264, H264_HIGH, H264High ),
411 #if VA_CHECK_VERSION(0, 37, 0)
412 MAP(HEVC, HEVC_MAIN, HEVCMain ),
413 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
414 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
417 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
418 MAP(HEVC, HEVC_REXT, None,
420 MAP(HEVC, HEVC_SCC, None,
423 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
425 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
426 MAP(WMV3, VC1_MAIN, VC1Main ),
427 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
428 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
429 MAP(VC1, VC1_SIMPLE, VC1Simple ),
430 MAP(VC1, VC1_MAIN, VC1Main ),
431 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
432 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
434 #if VA_CHECK_VERSION(0, 38, 0)
435 MAP(VP9, VP9_0, VP9Profile0 ),
437 #if VA_CHECK_VERSION(0, 39, 0)
438 MAP(VP9, VP9_1, VP9Profile1 ),
439 MAP(VP9, VP9_2, VP9Profile2 ),
440 MAP(VP9, VP9_3, VP9Profile3 ),
442 #if VA_CHECK_VERSION(1, 8, 0)
443 MAP(AV1, AV1_MAIN, AV1Profile0),
444 MAP(AV1, AV1_HIGH, AV1Profile1),
456 VAConfigID *va_config,
465 int profile_count, exact_match, matched_ff_profile,
codec_profile;
476 profile_count = vaMaxNumProfiles(hwctx->display);
484 vas = vaQueryConfigProfiles(hwctx->display,
485 profile_list, &profile_count);
486 if (vas != VA_STATUS_SUCCESS) {
488 "%d (%s).\n", vas, vaErrorStr(vas));
493 matched_va_profile = VAProfileNone;
497 int profile_match = 0;
509 for (j = 0; j < profile_count; j++) {
511 exact_match = profile_match;
515 if (j < profile_count) {
524 if (matched_va_profile == VAProfileNone) {
526 "profile %d.\n", codec_desc->
name, avctx->
profile);
534 "supported for hardware decode.\n",
537 "incompatible profile %d instead.\n",
541 "supported for hardware decode.\n",
548 vas = vaCreateConfig(hwctx->display, matched_va_profile,
549 VAEntrypointVLD,
NULL, 0,
551 if (vas != VA_STATUS_SUCCESS) {
553 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
577 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
587 "usable surface formats.\n");
604 frames->initial_pool_size = 1;
610 frames->initial_pool_size += 16;
613 frames->initial_pool_size += 8;
616 frames->initial_pool_size += 3;
619 frames->initial_pool_size += 2;
631 if (*va_config != VA_INVALID_ID) {
632 vaDestroyConfig(hwctx->display, *va_config);
633 *va_config = VA_INVALID_ID;
645 VAConfigID va_config = VA_INVALID_ID;
650 hwctx = device_ctx->hwctx;
657 if (va_config != VA_INVALID_ID)
658 vaDestroyConfig(hwctx->display, va_config);
669 ctx->va_config = VA_INVALID_ID;
670 ctx->va_context = VA_INVALID_ID;
677 ctx->hwfc =
ctx->frames->hwctx;
678 ctx->device =
ctx->frames->device_ctx;
679 ctx->hwctx =
ctx->device->hwctx;
686 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
689 ctx->hwfc->surface_ids,
690 ctx->hwfc->nb_surfaces,
692 if (vas != VA_STATUS_SUCCESS) {
694 "context: %d (%s).\n", vas, vaErrorStr(vas));
700 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
714 if (
ctx->va_context != VA_INVALID_ID) {
715 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
716 if (vas != VA_STATUS_SUCCESS) {
718 "context %#x: %d (%s).\n",
719 ctx->va_context, vas, vaErrorStr(vas));
722 if (
ctx->va_config != VA_INVALID_ID) {
723 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
724 if (vas != VA_STATUS_SUCCESS) {
726 "configuration %#x: %d (%s).\n",
727 ctx->va_config, vas, vaErrorStr(vas));