41 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
43 if (vas != VA_STATUS_SUCCESS) {
45 "buffer (type %d): %d (%s).\n",
46 type, vas, vaErrorStr(vas));
60 const void *params_data,
62 const void *slice_data,
87 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
88 VASliceParameterBufferType,
89 params_size, 1, (
void*)params_data,
91 if (vas != VA_STATUS_SUCCESS) {
93 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
101 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
102 VASliceDataBufferType,
103 slice_size, 1, (
void*)slice_data,
105 if (vas != VA_STATUS_SUCCESS) {
107 "data buffer (size %zu): %d (%s).\n",
108 slice_size, vas, vaErrorStr(vas));
109 vaDestroyBuffer(
ctx->hwctx->display,
130 vas = vaDestroyBuffer(
ctx->hwctx->display,
132 if (vas != VA_STATUS_SUCCESS) {
134 "parameter buffer %#x: %d (%s).\n",
140 vas = vaDestroyBuffer(
ctx->hwctx->display,
142 if (vas != VA_STATUS_SUCCESS) {
144 "slice buffer %#x: %d (%s).\n",
160 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
162 if (vas != VA_STATUS_SUCCESS) {
164 "issue: %d (%s).\n", vas, vaErrorStr(vas));
166 goto fail_with_picture;
169 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
171 if (vas != VA_STATUS_SUCCESS) {
173 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
175 goto fail_with_picture;
178 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
180 if (vas != VA_STATUS_SUCCESS) {
182 "%d (%s).\n", vas, vaErrorStr(vas));
184 goto fail_with_picture;
187 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
188 if (vas != VA_STATUS_SUCCESS) {
190 "issue: %d (%s).\n", vas, vaErrorStr(vas));
192 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
199 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
207 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
208 if (vas != VA_STATUS_SUCCESS) {
210 "after error: %d (%s).\n", vas, vaErrorStr(vas));
237 static const struct {
241 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
248 #ifdef VA_FOURCC_I420
256 #ifdef VA_FOURCC_YV16
264 #ifdef VA_FOURCC_P010
267 #ifdef VA_FOURCC_I010
268 MAP(I010, YUV420P10),
275 VAConfigID config_id,
280 VASurfaceAttrib *attr;
282 uint32_t best_fourcc,
fourcc;
288 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
290 if (vas != VA_STATUS_SUCCESS) {
292 "%d (%s).\n", vas, vaErrorStr(vas));
300 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
302 if (vas != VA_STATUS_SUCCESS) {
304 "%d (%s).\n", vas, vaErrorStr(vas));
311 for (
i = 0;
i < nb_attr;
i++) {
312 if (attr[
i].
type != VASurfaceAttribPixelFormat)
315 fourcc = attr[
i].value.value.i;
330 source_format, 0,
NULL);
331 if (
format == best_format)
346 frames->sw_format = best_format;
351 ctx->pixel_format_attribute = (VASurfaceAttrib) {
352 .type = VASurfaceAttribPixelFormat,
353 .value.value.i = best_fourcc,
363 static const struct {
368 #define MAP(c, p, v) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v }
369 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
370 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
372 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
373 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
374 MPEG4AdvancedSimple),
375 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
376 MAP(H264, H264_CONSTRAINED_BASELINE,
377 H264ConstrainedBaseline),
378 MAP(H264, H264_MAIN, H264Main ),
379 MAP(H264, H264_HIGH, H264High ),
380 #if VA_CHECK_VERSION(0, 37, 0)
381 MAP(HEVC, HEVC_MAIN, HEVCMain ),
382 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
384 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
386 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
387 MAP(WMV3, VC1_MAIN, VC1Main ),
388 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
389 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
390 MAP(VC1, VC1_SIMPLE, VC1Simple ),
391 MAP(VC1, VC1_MAIN, VC1Main ),
392 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
393 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
395 #if VA_CHECK_VERSION(0, 38, 0)
396 MAP(VP9, VP9_0, VP9Profile0 ),
398 #if VA_CHECK_VERSION(0, 39, 0)
399 MAP(VP9, VP9_2, VP9Profile2 ),
410 VAConfigID *va_config,
418 VAProfile *profile_list =
NULL, matched_va_profile;
419 int profile_count, exact_match, matched_ff_profile;
430 profile_count = vaMaxNumProfiles(hwctx->display);
438 vas = vaQueryConfigProfiles(hwctx->display,
439 profile_list, &profile_count);
440 if (vas != VA_STATUS_SUCCESS) {
442 "%d (%s).\n", vas, vaErrorStr(vas));
447 matched_va_profile = VAProfileNone;
451 int profile_match = 0;
457 for (j = 0; j < profile_count; j++) {
459 exact_match = profile_match;
463 if (j < profile_count) {
472 if (matched_va_profile == VAProfileNone) {
474 "profile %d.\n", codec_desc->
name, avctx->
profile);
482 "supported for hardware decode.\n",
485 "incompatible profile %d instead.\n",
489 "supported for hardware decode.\n",
496 vas = vaCreateConfig(hwctx->display, matched_va_profile,
497 VAEntrypointVLD,
NULL, 0,
499 if (vas != VA_STATUS_SUCCESS) {
501 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
525 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
535 "usable surface formats.\n");
552 frames->initial_pool_size = 1;
557 frames->initial_pool_size += 16;
560 frames->initial_pool_size += 8;
563 frames->initial_pool_size += 3;
566 frames->initial_pool_size += 2;
578 if (*va_config != VA_INVALID_ID) {
579 vaDestroyConfig(hwctx->display, *va_config);
580 *va_config = VA_INVALID_ID;
592 VAConfigID va_config = VA_INVALID_ID;
597 hwctx = device_ctx->hwctx;
604 if (va_config != VA_INVALID_ID)
605 vaDestroyConfig(hwctx->display, va_config);
616 ctx->va_config = VA_INVALID_ID;
617 ctx->va_context = VA_INVALID_ID;
619 #if FF_API_STRUCT_VAAPI_CONTEXT
622 "vaapi_context in decode.\n");
624 ctx->have_old_context = 1;
632 if (!
ctx->device_ref) {
637 ctx->hwctx =
ctx->device->hwctx;
639 ctx->hwctx->display =
ctx->old_context->display;
643 ctx->hwctx->driver_quirks =
649 #if FF_API_STRUCT_VAAPI_CONTEXT
650 if (
ctx->have_old_context) {
651 ctx->va_config =
ctx->old_context->config_id;
652 ctx->va_context =
ctx->old_context->context_id;
655 "context: %#x/%#x.\n",
ctx->va_config,
ctx->va_context);
664 ctx->hwfc =
ctx->frames->hwctx;
665 ctx->device =
ctx->frames->device_ctx;
666 ctx->hwctx =
ctx->device->hwctx;
673 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
676 ctx->hwfc->surface_ids,
677 ctx->hwfc->nb_surfaces,
679 if (vas != VA_STATUS_SUCCESS) {
681 "context: %d (%s).\n", vas, vaErrorStr(vas));
687 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
688 #if FF_API_STRUCT_VAAPI_CONTEXT
704 #if FF_API_STRUCT_VAAPI_CONTEXT
705 if (
ctx->have_old_context) {
710 if (
ctx->va_context != VA_INVALID_ID) {
711 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
712 if (vas != VA_STATUS_SUCCESS) {
714 "context %#x: %d (%s).\n",
715 ctx->va_context, vas, vaErrorStr(vas));
718 if (
ctx->va_config != VA_INVALID_ID) {
719 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
720 if (vas != VA_STATUS_SUCCESS) {
722 "configuration %#x: %d (%s).\n",
723 ctx->va_config, vas, vaErrorStr(vas));
727 #if FF_API_STRUCT_VAAPI_CONTEXT