va: filter: add gst_va_filter_enable_cropping ()
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Thu, 4 Mar 2021 14:19:25 +0000 (15:19 +0100)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Sat, 3 Apr 2021 13:47:18 +0000 (15:47 +0200)
This will toggle the cropping operation in the filter

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2058>

sys/va/gstvafilter.c
sys/va/gstvafilter.h

index 0cec913..d5cc080 100644 (file)
@@ -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;
index 85886d9..da5130f 100644 (file)
@@ -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);