42 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
44 if (vas != VA_STATUS_SUCCESS) {
46 "buffer (type %d): %d (%s).\n",
47 type, vas, vaErrorStr(vas));
61 const void *params_data,
63 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
269 #ifdef VA_FOURCC_P010
272 #ifdef VA_FOURCC_I010
273 MAP(I010, YUV420P10),
280 VAConfigID config_id,
285 VASurfaceAttrib *attr;
287 uint32_t best_fourcc,
fourcc;
293 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
295 if (vas != VA_STATUS_SUCCESS) {
297 "%d (%s).\n", vas, vaErrorStr(vas));
305 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
307 if (vas != VA_STATUS_SUCCESS) {
309 "%d (%s).\n", vas, vaErrorStr(vas));
316 for (
i = 0;
i < nb_attr;
i++) {
317 if (attr[
i].
type != VASurfaceAttribPixelFormat)
320 fourcc = attr[
i].value.value.i;
335 source_format, 0,
NULL);
336 if (
format == best_format)
351 frames->sw_format = best_format;
356 ctx->pixel_format_attribute = (VASurfaceAttrib) {
357 .type = VASurfaceAttribPixelFormat,
358 .value.value.i = best_fourcc,
368 static const struct {
374 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
375 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
376 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
378 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
379 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
380 MPEG4AdvancedSimple),
381 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
382 MAP(H264, H264_CONSTRAINED_BASELINE,
383 H264ConstrainedBaseline),
384 MAP(H264, H264_MAIN, H264Main ),
385 MAP(H264, H264_HIGH, H264High ),
386 #if VA_CHECK_VERSION(0, 37, 0)
387 MAP(HEVC, HEVC_MAIN, HEVCMain ),
388 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
389 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
392 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
393 MAP(HEVC, HEVC_REXT, None,
396 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
398 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
399 MAP(WMV3, VC1_MAIN, VC1Main ),
400 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
401 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
402 MAP(VC1, VC1_SIMPLE, VC1Simple ),
403 MAP(VC1, VC1_MAIN, VC1Main ),
404 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
405 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
407 #if VA_CHECK_VERSION(0, 38, 0)
408 MAP(VP9, VP9_0, VP9Profile0 ),
410 #if VA_CHECK_VERSION(0, 39, 0)
411 MAP(VP9, VP9_2, VP9Profile2 ),
422 VAConfigID *va_config,
431 int profile_count, exact_match, matched_ff_profile,
codec_profile;
442 profile_count = vaMaxNumProfiles(hwctx->display);
450 vas = vaQueryConfigProfiles(hwctx->display,
451 profile_list, &profile_count);
452 if (vas != VA_STATUS_SUCCESS) {
454 "%d (%s).\n", vas, vaErrorStr(vas));
459 matched_va_profile = VAProfileNone;
463 int profile_match = 0;
475 for (j = 0; j < profile_count; j++) {
477 exact_match = profile_match;
481 if (j < profile_count) {
490 if (matched_va_profile == VAProfileNone) {
492 "profile %d.\n", codec_desc->
name, avctx->
profile);
500 "supported for hardware decode.\n",
503 "incompatible profile %d instead.\n",
507 "supported for hardware decode.\n",
514 vas = vaCreateConfig(hwctx->display, matched_va_profile,
515 VAEntrypointVLD,
NULL, 0,
517 if (vas != VA_STATUS_SUCCESS) {
519 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
543 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
553 "usable surface formats.\n");
570 frames->initial_pool_size = 1;
575 frames->initial_pool_size += 16;
578 frames->initial_pool_size += 8;
581 frames->initial_pool_size += 3;
584 frames->initial_pool_size += 2;
596 if (*va_config != VA_INVALID_ID) {
597 vaDestroyConfig(hwctx->display, *va_config);
598 *va_config = VA_INVALID_ID;
610 VAConfigID va_config = VA_INVALID_ID;
615 hwctx = device_ctx->hwctx;
622 if (va_config != VA_INVALID_ID)
623 vaDestroyConfig(hwctx->display, va_config);
634 ctx->va_config = VA_INVALID_ID;
635 ctx->va_context = VA_INVALID_ID;
637 #if FF_API_STRUCT_VAAPI_CONTEXT
640 "vaapi_context in decode.\n");
642 ctx->have_old_context = 1;
650 if (!
ctx->device_ref) {
655 ctx->hwctx =
ctx->device->hwctx;
657 ctx->hwctx->display =
ctx->old_context->display;
661 ctx->hwctx->driver_quirks =
667 #if FF_API_STRUCT_VAAPI_CONTEXT
668 if (
ctx->have_old_context) {
669 ctx->va_config =
ctx->old_context->config_id;
670 ctx->va_context =
ctx->old_context->context_id;
673 "context: %#x/%#x.\n",
ctx->va_config,
ctx->va_context);
682 ctx->hwfc =
ctx->frames->hwctx;
683 ctx->device =
ctx->frames->device_ctx;
684 ctx->hwctx =
ctx->device->hwctx;
691 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
694 ctx->hwfc->surface_ids,
695 ctx->hwfc->nb_surfaces,
697 if (vas != VA_STATUS_SUCCESS) {
699 "context: %d (%s).\n", vas, vaErrorStr(vas));
705 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
706 #if FF_API_STRUCT_VAAPI_CONTEXT
722 #if FF_API_STRUCT_VAAPI_CONTEXT
723 if (
ctx->have_old_context) {
728 if (
ctx->va_context != VA_INVALID_ID) {
729 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
730 if (vas != VA_STATUS_SUCCESS) {
732 "context %#x: %d (%s).\n",
733 ctx->va_context, vas, vaErrorStr(vas));
736 if (
ctx->va_config != VA_INVALID_ID) {
737 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
738 if (vas != VA_STATUS_SUCCESS) {
740 "configuration %#x: %d (%s).\n",
741 ctx->va_config, vas, vaErrorStr(vas));
745 #if FF_API_STRUCT_VAAPI_CONTEXT