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 #if VA_CHECK_VERSION(1, 18, 0)
402 MAP(H264, H264_HIGH_10_INTRA,
404 MAP(H264, H264_HIGH_10, H264High10 ),
406 MAP(H264, H264_CONSTRAINED_BASELINE,
407 H264ConstrainedBaseline),
408 MAP(H264, H264_MAIN, H264Main ),
409 MAP(H264, H264_HIGH, H264High ),
410 #if VA_CHECK_VERSION(0, 37, 0)
411 MAP(HEVC, HEVC_MAIN, HEVCMain ),
412 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
413 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
416 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
417 MAP(HEVC, HEVC_REXT, None,
419 MAP(HEVC, HEVC_SCC, None,
422 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
424 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
425 MAP(WMV3, VC1_MAIN, VC1Main ),
426 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
427 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
428 MAP(VC1, VC1_SIMPLE, VC1Simple ),
429 MAP(VC1, VC1_MAIN, VC1Main ),
430 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
431 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
433 #if VA_CHECK_VERSION(0, 38, 0)
434 MAP(VP9, VP9_0, VP9Profile0 ),
436 #if VA_CHECK_VERSION(0, 39, 0)
437 MAP(VP9, VP9_1, VP9Profile1 ),
438 MAP(VP9, VP9_2, VP9Profile2 ),
439 MAP(VP9, VP9_3, VP9Profile3 ),
441 #if VA_CHECK_VERSION(1, 8, 0)
442 MAP(AV1, AV1_MAIN, AV1Profile0),
443 MAP(AV1, AV1_HIGH, AV1Profile1),
455 VAConfigID *va_config,
464 int profile_count, exact_match, matched_ff_profile,
codec_profile;
475 profile_count = vaMaxNumProfiles(hwctx->display);
483 vas = vaQueryConfigProfiles(hwctx->display,
484 profile_list, &profile_count);
485 if (vas != VA_STATUS_SUCCESS) {
487 "%d (%s).\n", vas, vaErrorStr(vas));
492 matched_va_profile = VAProfileNone;
496 int profile_match = 0;
508 for (j = 0; j < profile_count; j++) {
510 exact_match = profile_match;
514 if (j < profile_count) {
523 if (matched_va_profile == VAProfileNone) {
525 "profile %d.\n", codec_desc->
name, avctx->
profile);
533 "supported for hardware decode.\n",
536 "incompatible profile %d instead.\n",
540 "supported for hardware decode.\n",
547 vas = vaCreateConfig(hwctx->display, matched_va_profile,
548 VAEntrypointVLD,
NULL, 0,
550 if (vas != VA_STATUS_SUCCESS) {
552 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
576 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
586 "usable surface formats.\n");
603 frames->initial_pool_size = 1;
609 frames->initial_pool_size += 16;
612 frames->initial_pool_size += 8;
615 frames->initial_pool_size += 3;
618 frames->initial_pool_size += 2;
630 if (*va_config != VA_INVALID_ID) {
631 vaDestroyConfig(hwctx->display, *va_config);
632 *va_config = VA_INVALID_ID;
644 VAConfigID va_config = VA_INVALID_ID;
649 hwctx = device_ctx->hwctx;
656 if (va_config != VA_INVALID_ID)
657 vaDestroyConfig(hwctx->display, va_config);
668 ctx->va_config = VA_INVALID_ID;
669 ctx->va_context = VA_INVALID_ID;
676 ctx->hwfc =
ctx->frames->hwctx;
677 ctx->device =
ctx->frames->device_ctx;
678 ctx->hwctx =
ctx->device->hwctx;
685 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
688 ctx->hwfc->surface_ids,
689 ctx->hwfc->nb_surfaces,
691 if (vas != VA_STATUS_SUCCESS) {
693 "context: %d (%s).\n", vas, vaErrorStr(vas));
699 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
713 if (
ctx->va_context != VA_INVALID_ID) {
714 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
715 if (vas != VA_STATUS_SUCCESS) {
717 "context %#x: %d (%s).\n",
718 ctx->va_context, vas, vaErrorStr(vas));
721 if (
ctx->va_config != VA_INVALID_ID) {
722 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
723 if (vas != VA_STATUS_SUCCESS) {
725 "configuration %#x: %d (%s).\n",
726 ctx->va_config, vas, vaErrorStr(vas));