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
271 #ifdef VA_FOURCC_P010
274 #ifdef VA_FOURCC_I010
275 MAP(I010, YUV420P10),
282 VAConfigID config_id,
287 VASurfaceAttrib *attr;
289 uint32_t best_fourcc,
fourcc;
295 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
297 if (vas != VA_STATUS_SUCCESS) {
299 "%d (%s).\n", vas, vaErrorStr(vas));
307 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
309 if (vas != VA_STATUS_SUCCESS) {
311 "%d (%s).\n", vas, vaErrorStr(vas));
318 for (
i = 0;
i < nb_attr;
i++) {
319 if (attr[
i].
type != VASurfaceAttribPixelFormat)
322 fourcc = attr[
i].value.value.i;
337 source_format, 0,
NULL);
338 if (
format == best_format)
353 frames->sw_format = best_format;
358 ctx->pixel_format_attribute = (VASurfaceAttrib) {
359 .type = VASurfaceAttribPixelFormat,
360 .value.value.i = best_fourcc,
370 static const struct {
376 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
377 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
378 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
380 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
381 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
382 MPEG4AdvancedSimple),
383 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
384 MAP(H264, H264_CONSTRAINED_BASELINE,
385 H264ConstrainedBaseline),
386 MAP(H264, H264_MAIN, H264Main ),
387 MAP(H264, H264_HIGH, H264High ),
388 #if VA_CHECK_VERSION(0, 37, 0)
389 MAP(HEVC, HEVC_MAIN, HEVCMain ),
390 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
391 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
394 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
395 MAP(HEVC, HEVC_REXT, None,
398 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
400 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
401 MAP(WMV3, VC1_MAIN, VC1Main ),
402 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
403 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
404 MAP(VC1, VC1_SIMPLE, VC1Simple ),
405 MAP(VC1, VC1_MAIN, VC1Main ),
406 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
407 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
409 #if VA_CHECK_VERSION(0, 38, 0)
410 MAP(VP9, VP9_0, VP9Profile0 ),
412 #if VA_CHECK_VERSION(0, 39, 0)
413 MAP(VP9, VP9_2, VP9Profile2 ),
415 #if VA_CHECK_VERSION(1, 8, 0)
416 MAP(AV1, AV1_MAIN, AV1Profile0),
417 MAP(AV1, AV1_HIGH, AV1Profile1),
429 VAConfigID *va_config,
438 int profile_count, exact_match, matched_ff_profile,
codec_profile;
449 profile_count = vaMaxNumProfiles(hwctx->display);
457 vas = vaQueryConfigProfiles(hwctx->display,
458 profile_list, &profile_count);
459 if (vas != VA_STATUS_SUCCESS) {
461 "%d (%s).\n", vas, vaErrorStr(vas));
466 matched_va_profile = VAProfileNone;
470 int profile_match = 0;
482 for (j = 0; j < profile_count; j++) {
484 exact_match = profile_match;
488 if (j < profile_count) {
497 if (matched_va_profile == VAProfileNone) {
499 "profile %d.\n", codec_desc->
name, avctx->
profile);
507 "supported for hardware decode.\n",
510 "incompatible profile %d instead.\n",
514 "supported for hardware decode.\n",
521 vas = vaCreateConfig(hwctx->display, matched_va_profile,
522 VAEntrypointVLD,
NULL, 0,
524 if (vas != VA_STATUS_SUCCESS) {
526 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
550 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
560 "usable surface formats.\n");
577 frames->initial_pool_size = 1;
583 frames->initial_pool_size += 16;
586 frames->initial_pool_size += 8;
589 frames->initial_pool_size += 3;
592 frames->initial_pool_size += 2;
604 if (*va_config != VA_INVALID_ID) {
605 vaDestroyConfig(hwctx->display, *va_config);
606 *va_config = VA_INVALID_ID;
618 VAConfigID va_config = VA_INVALID_ID;
623 hwctx = device_ctx->hwctx;
630 if (va_config != VA_INVALID_ID)
631 vaDestroyConfig(hwctx->display, va_config);
642 ctx->va_config = VA_INVALID_ID;
643 ctx->va_context = VA_INVALID_ID;
650 ctx->hwfc =
ctx->frames->hwctx;
651 ctx->device =
ctx->frames->device_ctx;
652 ctx->hwctx =
ctx->device->hwctx;
659 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
662 ctx->hwfc->surface_ids,
663 ctx->hwfc->nb_surfaces,
665 if (vas != VA_STATUS_SUCCESS) {
667 "context: %d (%s).\n", vas, vaErrorStr(vas));
673 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
687 if (
ctx->va_context != VA_INVALID_ID) {
688 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
689 if (vas != VA_STATUS_SUCCESS) {
691 "context %#x: %d (%s).\n",
692 ctx->va_context, vas, vaErrorStr(vas));
695 if (
ctx->va_config != VA_INVALID_ID) {
696 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
697 if (vas != VA_STATUS_SUCCESS) {
699 "configuration %#x: %d (%s).\n",
700 ctx->va_config, vas, vaErrorStr(vas));