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,
67 const void *slice_data,
89 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
90 VASliceParameterBufferType,
91 params_size, nb_params, (
void*)params_data,
93 if (vas != VA_STATUS_SUCCESS) {
95 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
100 "is %#x.\n", pic->
nb_slices, params_size,
103 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
104 VASliceDataBufferType,
105 slice_size, 1, (
void*)slice_data,
107 if (vas != VA_STATUS_SUCCESS) {
109 "data buffer (size %zu): %d (%s).\n",
110 slice_size, vas, vaErrorStr(vas));
111 vaDestroyBuffer(
ctx->hwctx->display,
132 vas = vaDestroyBuffer(
ctx->hwctx->display,
134 if (vas != VA_STATUS_SUCCESS) {
136 "parameter buffer %#x: %d (%s).\n",
142 vas = vaDestroyBuffer(
ctx->hwctx->display,
144 if (vas != VA_STATUS_SUCCESS) {
146 "slice buffer %#x: %d (%s).\n",
162 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
164 if (vas != VA_STATUS_SUCCESS) {
166 "issue: %d (%s).\n", vas, vaErrorStr(vas));
168 goto fail_with_picture;
171 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
173 if (vas != VA_STATUS_SUCCESS) {
175 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
177 goto fail_with_picture;
180 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
182 if (vas != VA_STATUS_SUCCESS) {
184 "%d (%s).\n", vas, vaErrorStr(vas));
186 goto fail_with_picture;
189 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
190 if (vas != VA_STATUS_SUCCESS) {
192 "issue: %d (%s).\n", vas, vaErrorStr(vas));
194 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
201 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
209 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
210 if (vas != VA_STATUS_SUCCESS) {
212 "after error: %d (%s).\n", vas, vaErrorStr(vas));
239 static const struct {
243 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
250 #ifdef VA_FOURCC_I420
258 #ifdef VA_FOURCC_YV16
262 #ifdef VA_FOURCC_Y210
265 #ifdef VA_FOURCC_Y212
272 #ifdef VA_FOURCC_XYUV
275 #ifdef VA_FOURCC_Y410
278 #ifdef VA_FOURCC_Y412
282 #ifdef VA_FOURCC_P010
285 #ifdef VA_FOURCC_P012
288 #ifdef VA_FOURCC_I010
289 MAP(I010, YUV420P10),
296 VAConfigID config_id,
301 VASurfaceAttrib *attr;
303 uint32_t best_fourcc,
fourcc;
309 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
311 if (vas != VA_STATUS_SUCCESS) {
313 "%d (%s).\n", vas, vaErrorStr(vas));
321 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
323 if (vas != VA_STATUS_SUCCESS) {
325 "%d (%s).\n", vas, vaErrorStr(vas));
332 for (
i = 0;
i < nb_attr;
i++) {
333 if (attr[
i].
type != VASurfaceAttribPixelFormat)
336 fourcc = attr[
i].value.value.i;
351 source_format, 0,
NULL);
352 if (
format == best_format)
367 frames->sw_format = best_format;
372 ctx->pixel_format_attribute = (VASurfaceAttrib) {
373 .type = VASurfaceAttribPixelFormat,
374 .
flags = VA_SURFACE_ATTRIB_SETTABLE,
375 .value.type = VAGenericValueTypeInteger,
376 .value.value.i = best_fourcc,
386 static const struct {
392 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
393 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
394 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
396 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
397 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
398 MPEG4AdvancedSimple),
399 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
400 #if VA_CHECK_VERSION(1, 18, 0)
401 MAP(H264, H264_HIGH_10_INTRA,
403 MAP(H264, H264_HIGH_10, H264High10 ),
405 MAP(H264, H264_CONSTRAINED_BASELINE,
406 H264ConstrainedBaseline),
407 MAP(H264, H264_MAIN, H264Main ),
408 MAP(H264, H264_HIGH, H264High ),
409 #if VA_CHECK_VERSION(0, 37, 0)
410 MAP(HEVC, HEVC_MAIN, HEVCMain ),
411 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
412 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
415 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
416 MAP(HEVC, HEVC_REXT, None,
418 MAP(HEVC, HEVC_SCC, None,
421 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
423 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
424 MAP(WMV3, VC1_MAIN, VC1Main ),
425 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
426 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
427 MAP(VC1, VC1_SIMPLE, VC1Simple ),
428 MAP(VC1, VC1_MAIN, VC1Main ),
429 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
430 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
432 #if VA_CHECK_VERSION(0, 38, 0)
433 MAP(VP9, VP9_0, VP9Profile0 ),
435 #if VA_CHECK_VERSION(0, 39, 0)
436 MAP(VP9, VP9_1, VP9Profile1 ),
437 MAP(VP9, VP9_2, VP9Profile2 ),
438 MAP(VP9, VP9_3, VP9Profile3 ),
440 #if VA_CHECK_VERSION(1, 8, 0)
441 MAP(AV1, AV1_MAIN, AV1Profile0),
442 MAP(AV1, AV1_HIGH, AV1Profile1),
454 VAConfigID *va_config,
463 int profile_count, exact_match, matched_ff_profile,
codec_profile;
474 profile_count = vaMaxNumProfiles(hwctx->display);
482 vas = vaQueryConfigProfiles(hwctx->display,
483 profile_list, &profile_count);
484 if (vas != VA_STATUS_SUCCESS) {
486 "%d (%s).\n", vas, vaErrorStr(vas));
491 matched_va_profile = VAProfileNone;
495 int profile_match = 0;
507 for (j = 0; j < profile_count; j++) {
509 exact_match = profile_match;
513 if (j < profile_count) {
522 if (matched_va_profile == VAProfileNone) {
524 "profile %d.\n", codec_desc->
name, avctx->
profile);
532 "supported for hardware decode.\n",
535 "incompatible profile %d instead.\n",
539 "supported for hardware decode.\n",
546 vas = vaCreateConfig(hwctx->display, matched_va_profile,
547 VAEntrypointVLD,
NULL, 0,
549 if (vas != VA_STATUS_SUCCESS) {
551 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
575 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
585 "usable surface formats.\n");
602 frames->initial_pool_size = 1;
608 frames->initial_pool_size += 16;
611 frames->initial_pool_size += 8;
614 frames->initial_pool_size += 3;
617 frames->initial_pool_size += 2;
629 if (*va_config != VA_INVALID_ID) {
630 vaDestroyConfig(hwctx->display, *va_config);
631 *va_config = VA_INVALID_ID;
643 VAConfigID va_config = VA_INVALID_ID;
648 hwctx = device_ctx->hwctx;
655 if (va_config != VA_INVALID_ID)
656 vaDestroyConfig(hwctx->display, va_config);
667 ctx->va_config = VA_INVALID_ID;
668 ctx->va_context = VA_INVALID_ID;
675 ctx->hwfc =
ctx->frames->hwctx;
676 ctx->device =
ctx->frames->device_ctx;
677 ctx->hwctx =
ctx->device->hwctx;
684 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
687 ctx->hwfc->surface_ids,
688 ctx->hwfc->nb_surfaces,
690 if (vas != VA_STATUS_SUCCESS) {
692 "context: %d (%s).\n", vas, vaErrorStr(vas));
698 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
712 if (
ctx->va_context != VA_INVALID_ID) {
713 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
714 if (vas != VA_STATUS_SUCCESS) {
716 "context %#x: %d (%s).\n",
717 ctx->va_context, vas, vaErrorStr(vas));
720 if (
ctx->va_config != VA_INVALID_ID) {
721 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
722 if (vas != VA_STATUS_SUCCESS) {
724 "configuration %#x: %d (%s).\n",
725 ctx->va_config, vas, vaErrorStr(vas));