From 7a464ba015535854aa345628766f3014b245fca8 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Fri, 22 Nov 2013 10:19:06 +0100 Subject: [PATCH] vaapipostproc: fix and optimize advanced deinterlacing mode. Fix advanced deinterlacing modes with VPP to track only up to 2 past reference buffers. This used to be 3 past reference buffers but this doesn't fit with the existing decode pipeline that only has 4 extra scratch surfaces. Also optimize references tracking to be only enabled when needed, i.e. when advanced deinterlacing mode is used. This means that we don't need to track past references for basic bob or weave deinterlacing. --- gst/vaapi/gstvaapipostproc.c | 42 ++++++++++++++++++++++++++++-------- gst/vaapi/gstvaapipostproc.h | 2 +- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/gst/vaapi/gstvaapipostproc.c b/gst/vaapi/gstvaapipostproc.c index b8a7e12076..27ab992f36 100755 --- a/gst/vaapi/gstvaapipostproc.c +++ b/gst/vaapi/gstvaapipostproc.c @@ -456,6 +456,23 @@ append_output_buffer_metadata(GstBuffer *outbuf, GstBuffer *inbuf, guint flags) 0, -1); } +static gboolean +deint_method_is_advanced(GstVaapiDeinterlaceMethod deint_method) +{ + gboolean is_advanced; + + switch (deint_method) { + case GST_VAAPI_DEINTERLACE_METHOD_MOTION_ADAPTIVE: + case GST_VAAPI_DEINTERLACE_METHOD_MOTION_COMPENSATED: + is_advanced = TRUE; + break; + default: + is_advanced = FALSE; + break; + } + return is_advanced; +} + static GstVaapiDeinterlaceMethod get_next_deint_method(GstVaapiDeinterlaceMethod deint_method) { @@ -503,7 +520,7 @@ gst_vaapipostproc_process_vpp(GstBaseTransform *trans, GstBuffer *inbuf, GstBuffer *fieldbuf; GstVaapiDeinterlaceMethod deint_method; guint flags, deint_flags; - gboolean tff, deint, deint_changed; + gboolean tff, deint, deint_refs, deint_changed; /* Validate filters */ if ((postproc->flags & GST_VAAPI_POSTPROC_FLAG_FORMAT) && @@ -542,6 +559,7 @@ gst_vaapipostproc_process_vpp(GstBaseTransform *trans, GstBuffer *inbuf, /* First field */ deint_method = postproc->deinterlace_method; + deint_refs = deint_method_is_advanced(deint_method); if (postproc->flags & GST_VAAPI_POSTPROC_FLAG_DEINTERLACE) { fieldbuf = create_output_buffer(postproc); if (!fieldbuf) @@ -559,15 +577,19 @@ gst_vaapipostproc_process_vpp(GstBaseTransform *trans, GstBuffer *inbuf, if (!set_best_deint_method(postproc, deint_flags, &deint_method)) goto error_op_deinterlace; - ds_set_surfaces(ds); - if (!gst_vaapi_filter_set_deinterlacing_references(postproc->filter, - ds->surfaces, ds->num_surfaces, NULL, 0)) - goto error_op_deinterlace; - if (deint_method != postproc->deinterlace_method) { GST_DEBUG("unsupported deinterlace-method %u. Using %u instead", postproc->deinterlace_method, deint_method); postproc->deinterlace_method = deint_method; + deint_refs = deint_method_is_advanced(deint_method); + } + + if (deint_refs) { + ds_set_surfaces(ds); + if (!gst_vaapi_filter_set_deinterlacing_references( + postproc->filter, ds->surfaces, ds->num_surfaces, + NULL, 0)) + goto error_op_deinterlace; } } else if (deint_changed) { @@ -608,8 +630,8 @@ gst_vaapipostproc_process_vpp(GstBaseTransform *trans, GstBuffer *inbuf, deint_method, deint_flags)) goto error_op_deinterlace; - if (!gst_vaapi_filter_set_deinterlacing_references(postproc->filter, - ds->surfaces, ds->num_surfaces, NULL, 0)) + if (deint_refs && !gst_vaapi_filter_set_deinterlacing_references( + postproc->filter, ds->surfaces, ds->num_surfaces, NULL, 0)) goto error_op_deinterlace; } else if (deint_changed && !gst_vaapi_filter_set_deinterlacing( @@ -629,7 +651,9 @@ gst_vaapipostproc_process_vpp(GstBaseTransform *trans, GstBuffer *inbuf, } gst_buffer_set_vaapi_video_meta(outbuf, outbuf_meta); gst_vaapi_video_meta_unref(outbuf_meta); - ds_add_buffer(ds, inbuf); + + if (deint && deint_refs) + ds_add_buffer(ds, inbuf); return GST_FLOW_OK; /* ERRORS */ diff --git a/gst/vaapi/gstvaapipostproc.h b/gst/vaapi/gstvaapipostproc.h index c10801d1ae..e15472e848 100755 --- a/gst/vaapi/gstvaapipostproc.h +++ b/gst/vaapi/gstvaapipostproc.h @@ -82,7 +82,7 @@ typedef enum { * number of allowed surfaces used as references shall be less than * the actual number of scratch surfaces used for decoding (4). */ -#define GST_VAAPI_DEINTERLACE_MAX_REFERENCES 3 +#define GST_VAAPI_DEINTERLACE_MAX_REFERENCES 2 /** * GstVaapiPostprocFlags: