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,
88 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
89 VASliceParameterBufferType,
90 params_size, 1, (
void*)params_data,
92 if (vas != VA_STATUS_SUCCESS) {
94 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
102 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
103 VASliceDataBufferType,
104 slice_size, 1, (
void*)slice_data,
106 if (vas != VA_STATUS_SUCCESS) {
108 "data buffer (size %zu): %d (%s).\n",
109 slice_size, vas, vaErrorStr(vas));
110 vaDestroyBuffer(
ctx->hwctx->display,
131 vas = vaDestroyBuffer(
ctx->hwctx->display,
133 if (vas != VA_STATUS_SUCCESS) {
135 "parameter buffer %#x: %d (%s).\n",
141 vas = vaDestroyBuffer(
ctx->hwctx->display,
143 if (vas != VA_STATUS_SUCCESS) {
145 "slice buffer %#x: %d (%s).\n",
161 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
163 if (vas != VA_STATUS_SUCCESS) {
165 "issue: %d (%s).\n", vas, vaErrorStr(vas));
167 goto fail_with_picture;
170 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
172 if (vas != VA_STATUS_SUCCESS) {
174 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
176 goto fail_with_picture;
179 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
181 if (vas != VA_STATUS_SUCCESS) {
183 "%d (%s).\n", vas, vaErrorStr(vas));
185 goto fail_with_picture;
188 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
189 if (vas != VA_STATUS_SUCCESS) {
191 "issue: %d (%s).\n", vas, vaErrorStr(vas));
193 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
200 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
208 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
209 if (vas != VA_STATUS_SUCCESS) {
211 "after error: %d (%s).\n", vas, vaErrorStr(vas));
238 static const struct {
242 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
249 #ifdef VA_FOURCC_I420
257 #ifdef VA_FOURCC_YV16
261 #ifdef VA_FOURCC_Y210
264 #ifdef VA_FOURCC_Y212
271 #ifdef VA_FOURCC_XYUV
274 #ifdef VA_FOURCC_Y410
277 #ifdef VA_FOURCC_Y412
281 #ifdef VA_FOURCC_P010
284 #ifdef VA_FOURCC_P012
287 #ifdef VA_FOURCC_I010
288 MAP(I010, YUV420P10),
295 VAConfigID config_id,
300 VASurfaceAttrib *attr;
302 uint32_t best_fourcc,
fourcc;
308 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
310 if (vas != VA_STATUS_SUCCESS) {
312 "%d (%s).\n", vas, vaErrorStr(vas));
320 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
322 if (vas != VA_STATUS_SUCCESS) {
324 "%d (%s).\n", vas, vaErrorStr(vas));
331 for (
i = 0;
i < nb_attr;
i++) {
332 if (attr[
i].
type != VASurfaceAttribPixelFormat)
335 fourcc = attr[
i].value.value.i;
350 source_format, 0,
NULL);
351 if (
format == best_format)
366 frames->sw_format = best_format;
371 ctx->pixel_format_attribute = (VASurfaceAttrib) {
372 .type = VASurfaceAttribPixelFormat,
373 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
374 .value.type = VAGenericValueTypeInteger,
375 .value.value.i = best_fourcc,
385 static const struct {
391 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
392 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
393 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
395 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
396 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
397 MPEG4AdvancedSimple),
398 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
399 #if VA_CHECK_VERSION(1, 18, 0)
400 MAP(H264, H264_HIGH_10_INTRA,
402 MAP(H264, H264_HIGH_10, H264High10 ),
404 MAP(H264, H264_CONSTRAINED_BASELINE,
405 H264ConstrainedBaseline),
406 MAP(H264, H264_MAIN, H264Main ),
407 MAP(H264, H264_HIGH, H264High ),
408 #if VA_CHECK_VERSION(0, 37, 0)
409 MAP(HEVC, HEVC_MAIN, HEVCMain ),
410 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
411 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
414 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
415 MAP(HEVC, HEVC_REXT, None,
417 MAP(HEVC, HEVC_SCC, None,
420 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
422 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
423 MAP(WMV3, VC1_MAIN, VC1Main ),
424 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
425 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
426 MAP(VC1, VC1_SIMPLE, VC1Simple ),
427 MAP(VC1, VC1_MAIN, VC1Main ),
428 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
429 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
431 #if VA_CHECK_VERSION(0, 38, 0)
432 MAP(VP9, VP9_0, VP9Profile0 ),
434 #if VA_CHECK_VERSION(0, 39, 0)
435 MAP(VP9, VP9_1, VP9Profile1 ),
436 MAP(VP9, VP9_2, VP9Profile2 ),
437 MAP(VP9, VP9_3, VP9Profile3 ),
439 #if VA_CHECK_VERSION(1, 8, 0)
440 MAP(AV1, AV1_MAIN, AV1Profile0),
441 MAP(AV1, AV1_HIGH, AV1Profile1),
453 VAConfigID *va_config,
462 int profile_count, exact_match, matched_ff_profile,
codec_profile;
473 profile_count = vaMaxNumProfiles(hwctx->display);
481 vas = vaQueryConfigProfiles(hwctx->display,
482 profile_list, &profile_count);
483 if (vas != VA_STATUS_SUCCESS) {
485 "%d (%s).\n", vas, vaErrorStr(vas));
490 matched_va_profile = VAProfileNone;
494 int profile_match = 0;
506 for (j = 0; j < profile_count; j++) {
508 exact_match = profile_match;
512 if (j < profile_count) {
521 if (matched_va_profile == VAProfileNone) {
523 "profile %d.\n", codec_desc->
name, avctx->
profile);
531 "supported for hardware decode.\n",
534 "incompatible profile %d instead.\n",
538 "supported for hardware decode.\n",
545 vas = vaCreateConfig(hwctx->display, matched_va_profile,
546 VAEntrypointVLD,
NULL, 0,
548 if (vas != VA_STATUS_SUCCESS) {
550 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
574 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
584 "usable surface formats.\n");
601 frames->initial_pool_size = 1;
607 frames->initial_pool_size += 16;
610 frames->initial_pool_size += 8;
613 frames->initial_pool_size += 3;
616 frames->initial_pool_size += 2;
628 if (*va_config != VA_INVALID_ID) {
629 vaDestroyConfig(hwctx->display, *va_config);
630 *va_config = VA_INVALID_ID;
642 VAConfigID va_config = VA_INVALID_ID;
647 hwctx = device_ctx->hwctx;
654 if (va_config != VA_INVALID_ID)
655 vaDestroyConfig(hwctx->display, va_config);
666 ctx->va_config = VA_INVALID_ID;
667 ctx->va_context = VA_INVALID_ID;
674 ctx->hwfc =
ctx->frames->hwctx;
675 ctx->device =
ctx->frames->device_ctx;
676 ctx->hwctx =
ctx->device->hwctx;
683 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
686 ctx->hwfc->surface_ids,
687 ctx->hwfc->nb_surfaces,
689 if (vas != VA_STATUS_SUCCESS) {
691 "context: %d (%s).\n", vas, vaErrorStr(vas));
697 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
711 if (
ctx->va_context != VA_INVALID_ID) {
712 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
713 if (vas != VA_STATUS_SUCCESS) {
715 "context %#x: %d (%s).\n",
716 ctx->va_context, vas, vaErrorStr(vas));
719 if (
ctx->va_config != VA_INVALID_ID) {
720 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
721 if (vas != VA_STATUS_SUCCESS) {
723 "configuration %#x: %d (%s).\n",
724 ctx->va_config, vas, vaErrorStr(vas));