From c88abb9291cde4b8bca9e72f413a81fe59684d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Manuel=20J=C3=A1quez=20Leal?= Date: Thu, 4 Mar 2021 15:19:25 +0100 Subject: [PATCH] va: filter: add gst_va_filter_enable_cropping () This will toggle the cropping operation in the filter Part-of: --- sys/va/gstvafilter.c | 40 +++++++++++++++++++++++++++++++++++++--- sys/va/gstvafilter.h | 2 ++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/sys/va/gstvafilter.c b/sys/va/gstvafilter.c index 0cec913552..d5cc080b54 100644 --- a/sys/va/gstvafilter.c +++ b/sys/va/gstvafilter.c @@ -59,6 +59,8 @@ struct _GstVaFilter guint rotation; GstVideoOrientationMethod orientation; + gboolean crop_enabled; + VARectangle input_region; VARectangle output_region; @@ -854,6 +856,15 @@ gst_va_filter_get_orientation (GstVaFilter * self) return ret; } +void +gst_va_filter_enable_cropping (GstVaFilter * self, gboolean cropping) +{ + GST_OBJECT_LOCK (self); + if (cropping != self->crop_enabled) + self->crop_enabled = cropping; + GST_OBJECT_UNLOCK (self); +} + static inline GstCaps * _create_base_caps (GstVaFilter * self) { @@ -1238,14 +1249,37 @@ static gboolean _fill_va_sample (GstVaFilter * self, GstVaSample * sample, GstPadDirection direction) { + GstVideoCropMeta *crop; + sample->surface = gst_va_buffer_get_surface (sample->buffer); if (sample->surface == VA_INVALID_ID) return FALSE; - /* TODO: handle GstVideoCropMeta */ + /* XXX: cropping occurs only in input frames */ + if (direction == GST_PAD_SRC) { + GST_OBJECT_LOCK (self); + sample->rect = self->output_region; + GST_OBJECT_UNLOCK (self); + + return TRUE; + } + + /* if buffer has crop meta, its real size is in video meta */ + crop = gst_buffer_get_video_crop_meta (sample->buffer); + GST_OBJECT_LOCK (self); - sample->rect = (direction == GST_PAD_SRC) ? - self->output_region : self->input_region; + if (crop && self->crop_enabled) { + /* *INDENT-OFF* */ + sample->rect = (VARectangle) { + .x = crop->x, + .y = crop->y, + .width = crop->width, + .height = crop->height + }; + /* *INDENT-ON* */ + } else { + sample->rect = self->input_region; + } GST_OBJECT_UNLOCK (self); return TRUE; diff --git a/sys/va/gstvafilter.h b/sys/va/gstvafilter.h index 85886d994e..da5130fdf4 100644 --- a/sys/va/gstvafilter.h +++ b/sys/va/gstvafilter.h @@ -68,6 +68,8 @@ gboolean gst_va_filter_install_properties (GstVaFilter * self, gboolean gst_va_filter_set_orientation (GstVaFilter * self, GstVideoOrientationMethod orientation); GstVideoOrientationMethod gst_va_filter_get_orientation (GstVaFilter * self); +void gst_va_filter_enable_cropping (GstVaFilter * self, + gboolean cropping); const gpointer gst_va_filter_get_filter_caps (GstVaFilter * self, VAProcFilterType type, guint * num_caps);