From 94ab0bef408c738b18d851c47a5bcd69a6258cc2 Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Sun, 1 Oct 2017 22:50:59 +0100 Subject: [PATCH 1/5] vaapi: Disable deprecation warnings around use of struct vaapi_context --- libavcodec/vaapi_decode.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavcodec/vaapi_decode.h b/libavcodec/vaapi_decode.h index e195e863a0..fda228b5a9 100644 --- a/libavcodec/vaapi_decode.h +++ b/libavcodec/vaapi_decode.h @@ -24,6 +24,7 @@ #include "libavutil/frame.h" #include "libavutil/hwcontext.h" #include "libavutil/hwcontext_vaapi.h" +#include "libavutil/internal.h" #include "avcodec.h" @@ -57,9 +58,11 @@ typedef struct VAAPIDecodeContext { VAContextID va_context; #if FF_API_VAAPI_CONTEXT +FF_DISABLE_DEPRECATION_WARNINGS int have_old_context; struct vaapi_context *old_context; AVBufferRef *device_ref; +FF_ENABLE_DEPRECATION_WARNINGS #endif AVHWDeviceContext *device; From a126b67e1b01d5886afaa6bcad108a85392ce15c Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Sun, 1 Oct 2017 22:51:07 +0100 Subject: [PATCH 2/5] configure: Add config option for libva2 (VAAPI 1) --- configure | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/configure b/configure index 173610a19c..5223236795 100755 --- a/configure +++ b/configure @@ -1650,6 +1650,7 @@ SYSTEM_FUNCS=" SYSTEM_LIBRARIES=" sdl + vaapi_1 vaapi_drm vaapi_x11 vdpau_x11 @@ -4834,6 +4835,10 @@ enabled vaapi && enabled vaapi && check_lib vaapi_x11 "va/va.h va/va_x11.h" vaGetDisplay -lva -lva-x11 -lX11 +enabled vaapi && + check_cpp_condition "va/va.h" "VA_CHECK_VERSION(1, 0, 0)" && + enable vaapi_1 + enabled vdpau && check_cpp_condition vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" || disable vdpau From f0a978a519167e5ad5dd479245a7b5da77488d43 Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Sun, 1 Oct 2017 22:51:13 +0100 Subject: [PATCH 3/5] vaapi: Remove H.264 baseline profile This has been deprecated in libva2 because hardware does not and will not support it. Therefore never consider it for decode, and for encode assume the user meant constrained baseline profile instead. --- libavcodec/vaapi_decode.c | 1 - libavcodec/vaapi_encode_h264.c | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index 5ae98d8fd7..febe22a710 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -247,7 +247,6 @@ static const struct { MAP(MPEG4, MPEG4_MAIN, MPEG4Main ), MAP(H264, H264_CONSTRAINED_BASELINE, H264ConstrainedBaseline), - MAP(H264, H264_BASELINE, H264Baseline), MAP(H264, H264_MAIN, H264Main ), MAP(H264, H264_HIGH, H264High ), #if VA_CHECK_VERSION(0, 37, 0) diff --git a/libavcodec/vaapi_encode_h264.c b/libavcodec/vaapi_encode_h264.c index 1288249be7..3ff19d2c83 100644 --- a/libavcodec/vaapi_encode_h264.c +++ b/libavcodec/vaapi_encode_h264.c @@ -863,12 +863,13 @@ static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx) ctx->codec = &vaapi_encode_type_h264; switch (avctx->profile) { + case FF_PROFILE_H264_BASELINE: + av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile is not " + "supported, using constrained baseline profile instead.\n"); + avctx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE; case FF_PROFILE_H264_CONSTRAINED_BASELINE: ctx->va_profile = VAProfileH264ConstrainedBaseline; break; - case FF_PROFILE_H264_BASELINE: - ctx->va_profile = VAProfileH264Baseline; - break; case FF_PROFILE_H264_MAIN: ctx->va_profile = VAProfileH264Main; break; From bfc83acfd6b33986480d4c6d3c571ba6a59f1d98 Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Sun, 1 Oct 2017 22:51:20 +0100 Subject: [PATCH 4/5] vaapi: Always free parameter buffers after vaEndPicture() with libva2 This is an ABI change in libva2: previously the Intel driver had this behaviour and it was implemented as a driver quirk, but now it is part of the specification so all drivers must do it. --- libavcodec/vaapi_decode.c | 4 ++-- libavcodec/vaapi_encode.c | 4 ++-- libavfilter/vf_deinterlace_vaapi.c | 2 +- libavfilter/vf_scale_vaapi.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c index febe22a710..02304191ff 100644 --- a/libavcodec/vaapi_decode.c +++ b/libavcodec/vaapi_decode.c @@ -189,14 +189,14 @@ int ff_vaapi_decode_issue(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "Failed to end picture decode " "issue: %d (%s).\n", vas, vaErrorStr(vas)); err = AVERROR(EIO); - if (ctx->hwctx->driver_quirks & + if (HAVE_VAAPI_1 || ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) goto fail; else goto fail_at_end; } - if (ctx->hwctx->driver_quirks & + if (HAVE_VAAPI_1 || ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) ff_vaapi_decode_destroy_buffers(avctx, pic); diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 462ec7a8e7..47795ba735 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -392,14 +392,14 @@ static int vaapi_encode_issue(AVCodecContext *avctx, err = AVERROR(EIO); // vaRenderPicture() has been called here, so we should not destroy // the parameter buffers unless separate destruction is required. - if (ctx->hwctx->driver_quirks & + if (HAVE_VAAPI_1 || ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) goto fail; else goto fail_at_end; } - if (ctx->hwctx->driver_quirks & + if (HAVE_VAAPI_1 || ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { for (i = 0; i < pic->nb_param_buffers; i++) { vas = vaDestroyBuffer(ctx->hwctx->display, diff --git a/libavfilter/vf_deinterlace_vaapi.c b/libavfilter/vf_deinterlace_vaapi.c index f3afcc4f75..95a0f40419 100644 --- a/libavfilter/vf_deinterlace_vaapi.c +++ b/libavfilter/vf_deinterlace_vaapi.c @@ -536,7 +536,7 @@ static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) goto fail_after_render; } - if (ctx->hwctx->driver_quirks & + if (HAVE_VAAPI_1 || ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { vas = vaDestroyBuffer(ctx->hwctx->display, params_id); if (vas != VA_STATUS_SUCCESS) { diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c index 50be68eee0..4c8f2cf4ef 100644 --- a/libavfilter/vf_scale_vaapi.c +++ b/libavfilter/vf_scale_vaapi.c @@ -347,7 +347,7 @@ static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame) goto fail_after_render; } - if (ctx->hwctx->driver_quirks & + if (HAVE_VAAPI_1 || ctx->hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { vas = vaDestroyBuffer(ctx->hwctx->display, params_id); if (vas != VA_STATUS_SUCCESS) { From 2708c8e8efefaad337ccab1e3bf59dcde66c6bc5 Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Sun, 1 Oct 2017 22:51:31 +0100 Subject: [PATCH 5/5] hwcontext_vaapi: Set message callbacks on internally-created devices The message callbacks are library-safe in libva2, so we can now use them. --- libavutil/hwcontext_vaapi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 2260518ca6..12f8ac93cd 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -916,6 +916,22 @@ static void vaapi_device_free(AVHWDeviceContext *ctx) av_freep(&priv); } +#if HAVE_VAAPI_1 +static void vaapi_device_log_error(void *context, const char *message) +{ + AVHWDeviceContext *ctx = context; + + av_log(ctx, AV_LOG_ERROR, "libva: %s", message); +} + +static void vaapi_device_log_info(void *context, const char *message) +{ + AVHWDeviceContext *ctx = context; + + av_log(ctx, AV_LOG_VERBOSE, "libva: %s", message); +} +#endif + static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags) { @@ -985,6 +1001,11 @@ static int vaapi_device_create(AVHWDeviceContext *ctx, const char *device, return AVERROR(EINVAL); } +#if HAVE_VAAPI_1 + vaSetErrorCallback(display, &vaapi_device_log_error, ctx); + vaSetInfoCallback (display, &vaapi_device_log_info, ctx); +#endif + hwctx->display = display; vas = vaInitialize(display, &major, &minor);