From 1642c3fc96f8084846371175afd1a24d2dbb3bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Tue, 5 Oct 2021 17:41:57 +0200 Subject: [PATCH] va: filter, deinterlace, vpp: Add gst_va_buffer_get_surface_flags(). Add a helper function to get, from GstVideoInfo and GstBuffers flags, the VA interlace surface flags. This is used currently by vainterlace element, but it will be used in vapostproc too if it can process interlaced frames. Part-of: --- .../gst-plugins-bad/sys/va/gstvadeinterlace.c | 27 +------------ .../gst-plugins-bad/sys/va/gstvafilter.c | 40 +++++++++++++++++++ .../gst-plugins-bad/sys/va/gstvafilter.h | 3 ++ subprojects/gst-plugins-bad/sys/va/gstvavpp.c | 2 + 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/va/gstvadeinterlace.c b/subprojects/gst-plugins-bad/sys/va/gstvadeinterlace.c index 454551c2f6..2698088fc1 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvadeinterlace.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvadeinterlace.c @@ -396,32 +396,7 @@ gst_va_deinterlace_transform (GstBaseTransform * trans, GstBuffer * inbuf, g_assert (self->curr_field == FIRST_FIELD || self->curr_field == SECOND_FIELD); - surface_flags = 0; - if (GST_VIDEO_INFO_INTERLACE_MODE (info) == GST_VIDEO_INTERLACE_MODE_MIXED - || (GST_VIDEO_INFO_INTERLACE_MODE (info) == - GST_VIDEO_INTERLACE_MODE_INTERLEAVED - && GST_VIDEO_INFO_FIELD_ORDER (info) == - GST_VIDEO_FIELD_ORDER_UNKNOWN)) { - if (GST_BUFFER_FLAG_IS_SET (inbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED)) { - if (GST_BUFFER_FLAG_IS_SET (inbuf, GST_VIDEO_BUFFER_FLAG_TFF)) { - surface_flags = VA_TOP_FIELD_FIRST; - } else { - surface_flags = VA_BOTTOM_FIELD_FIRST; - } - } else { - /* complete frame? do it twice */ - surface_flags = VA_FRAME_PICTURE; - } - } else if (GST_VIDEO_INFO_FIELD_ORDER (info) == - GST_VIDEO_FIELD_ORDER_BOTTOM_FIELD_FIRST) { - surface_flags = VA_BOTTOM_FIELD_FIRST; - } else if (GST_VIDEO_INFO_FIELD_ORDER (info) == - GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST) { - surface_flags = VA_TOP_FIELD_FIRST; - } else { - g_assert_not_reached (); - } - + surface_flags = gst_va_buffer_get_surface_flags (inbuf, info); if (surface_flags != VA_FRAME_PICTURE) _set_field (self, &surface_flags); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvafilter.c b/subprojects/gst-plugins-bad/sys/va/gstvafilter.c index 58a4b2ff70..e8b63126bf 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvafilter.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvafilter.c @@ -1695,3 +1695,43 @@ fail_end_pic: goto bail; } } + +/** + * gst_va_buffer_get_surface_flags: + * @buffer: the #GstBuffer to check. + * @info: the #GstVideoInfo with info. + * + * Gets the surface flags, related with interlace given @buffer and + * @info. + * + * Returns: VA surface flags. + */ +guint32 +gst_va_buffer_get_surface_flags (GstBuffer * buffer, GstVideoInfo * info) +{ + guint32 surface_flags = 0; + + if (GST_VIDEO_INFO_INTERLACE_MODE (info) == GST_VIDEO_INTERLACE_MODE_MIXED + || (GST_VIDEO_INFO_INTERLACE_MODE (info) == + GST_VIDEO_INTERLACE_MODE_INTERLEAVED + && GST_VIDEO_INFO_FIELD_ORDER (info) == + GST_VIDEO_FIELD_ORDER_UNKNOWN)) { + if (GST_BUFFER_FLAG_IS_SET (buffer, GST_VIDEO_BUFFER_FLAG_INTERLACED)) { + if (GST_BUFFER_FLAG_IS_SET (buffer, GST_VIDEO_BUFFER_FLAG_TFF)) { + surface_flags = VA_TOP_FIELD_FIRST; + } else { + surface_flags = VA_BOTTOM_FIELD_FIRST; + } + } else { + surface_flags = VA_FRAME_PICTURE; + } + } else if (GST_VIDEO_INFO_FIELD_ORDER (info) == + GST_VIDEO_FIELD_ORDER_BOTTOM_FIELD_FIRST) { + surface_flags = VA_BOTTOM_FIELD_FIRST; + } else if (GST_VIDEO_INFO_FIELD_ORDER (info) == + GST_VIDEO_FIELD_ORDER_TOP_FIELD_FIRST) { + surface_flags = VA_TOP_FIELD_FIRST; + } + + return surface_flags; +} diff --git a/subprojects/gst-plugins-bad/sys/va/gstvafilter.h b/subprojects/gst-plugins-bad/sys/va/gstvafilter.h index 4330b9bdaa..e7f720f670 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvafilter.h +++ b/subprojects/gst-plugins-bad/sys/va/gstvafilter.h @@ -110,4 +110,7 @@ gboolean gst_va_filter_process (GstVaFilter * self, GstVaSample * src, GstVaSample * dest); +guint32 gst_va_buffer_get_surface_flags (GstBuffer * buffer, + GstVideoInfo * info); + G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/va/gstvavpp.c b/subprojects/gst-plugins-bad/sys/va/gstvavpp.c index 596b9c72af..50d749db73 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvavpp.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvavpp.c @@ -651,10 +651,12 @@ gst_va_vpp_transform (GstBaseTransform * trans, GstBuffer * inbuf, /* *INDENT-OFF* */ src = (GstVaSample) { .buffer = buf, + .flags = gst_va_buffer_get_surface_flags (buf, &btrans->in_info), }; dst = (GstVaSample) { .buffer = outbuf, + .flags = gst_va_buffer_get_surface_flags (outbuf, &btrans->out_info), }; /* *INDENT-ON* */