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,
415 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
417 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
418 MAP(WMV3, VC1_MAIN, VC1Main ),
419 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
420 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
421 MAP(VC1, VC1_SIMPLE, VC1Simple ),
422 MAP(VC1, VC1_MAIN, VC1Main ),
423 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
424 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
426 #if VA_CHECK_VERSION(0, 38, 0)
427 MAP(VP9, VP9_0, VP9Profile0 ),
429 #if VA_CHECK_VERSION(0, 39, 0)
430 MAP(VP9, VP9_1, VP9Profile1 ),
431 MAP(VP9, VP9_2, VP9Profile2 ),
432 MAP(VP9, VP9_3, VP9Profile3 ),
434 #if VA_CHECK_VERSION(1, 8, 0)
435 MAP(AV1, AV1_MAIN, AV1Profile0),
436 MAP(AV1, AV1_HIGH, AV1Profile1),
448 VAConfigID *va_config,
457 int profile_count, exact_match, matched_ff_profile,
codec_profile;
468 profile_count = vaMaxNumProfiles(hwctx->display);
476 vas = vaQueryConfigProfiles(hwctx->display,
477 profile_list, &profile_count);
478 if (vas != VA_STATUS_SUCCESS) {
480 "%d (%s).\n", vas, vaErrorStr(vas));
485 matched_va_profile = VAProfileNone;
489 int profile_match = 0;
501 for (j = 0; j < profile_count; j++) {
503 exact_match = profile_match;
507 if (j < profile_count) {
516 if (matched_va_profile == VAProfileNone) {
518 "profile %d.\n", codec_desc->
name, avctx->
profile);
526 "supported for hardware decode.\n",
529 "incompatible profile %d instead.\n",
533 "supported for hardware decode.\n",
540 vas = vaCreateConfig(hwctx->display, matched_va_profile,
541 VAEntrypointVLD,
NULL, 0,
543 if (vas != VA_STATUS_SUCCESS) {
545 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
569 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
579 "usable surface formats.\n");
596 frames->initial_pool_size = 1;
602 frames->initial_pool_size += 16;
605 frames->initial_pool_size += 8;
608 frames->initial_pool_size += 3;
611 frames->initial_pool_size += 2;
623 if (*va_config != VA_INVALID_ID) {
624 vaDestroyConfig(hwctx->display, *va_config);
625 *va_config = VA_INVALID_ID;
637 VAConfigID va_config = VA_INVALID_ID;
642 hwctx = device_ctx->hwctx;
649 if (va_config != VA_INVALID_ID)
650 vaDestroyConfig(hwctx->display, va_config);
661 ctx->va_config = VA_INVALID_ID;
662 ctx->va_context = VA_INVALID_ID;
669 ctx->hwfc =
ctx->frames->hwctx;
670 ctx->device =
ctx->frames->device_ctx;
671 ctx->hwctx =
ctx->device->hwctx;
678 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
681 ctx->hwfc->surface_ids,
682 ctx->hwfc->nb_surfaces,
684 if (vas != VA_STATUS_SUCCESS) {
686 "context: %d (%s).\n", vas, vaErrorStr(vas));
692 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
706 if (
ctx->va_context != VA_INVALID_ID) {
707 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
708 if (vas != VA_STATUS_SUCCESS) {
710 "context %#x: %d (%s).\n",
711 ctx->va_context, vas, vaErrorStr(vas));
714 if (
ctx->va_config != VA_INVALID_ID) {
715 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
716 if (vas != VA_STATUS_SUCCESS) {
718 "configuration %#x: %d (%s).\n",
719 ctx->va_config, vas, vaErrorStr(vas));