va: postproc: only drop filters if they change
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Fri, 12 Mar 2021 12:50:59 +0000 (13:50 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 15 Mar 2021 06:10:27 +0000 (06:10 +0000)
Currently, at every frame the filters array is recreated. This is not
optimal, since it should be only rebuilt if the VA filter's related
properties change. This patches does that by using a flag.

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

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

index 83c14773afdebca624127378582c680f4a923392..d79fa2bbb4d47ae1e1596468e68603ecbba46922 100644 (file)
@@ -1220,6 +1220,19 @@ gst_va_filter_add_filter_buffer (GstVaFilter * self, gpointer data, gsize size,
   return TRUE;
 }
 
+gboolean
+gst_va_filter_drop_filter_buffers (GstVaFilter * self)
+{
+  gboolean ret = TRUE;
+
+  GST_OBJECT_LOCK (self);
+  if (self->filters)
+    ret = _destroy_filters_unlocked (self);
+  GST_OBJECT_UNLOCK (self);
+
+  return ret;
+}
+
 static gboolean
 _create_pipeline_buffer (GstVaFilter * self, VASurfaceID surface,
     VARectangle * src_rect, VARectangle * dst_rect, VABufferID * buffer)
@@ -1350,10 +1363,8 @@ gst_va_filter_convert_surface (GstVaFilter * self, VASurfaceID in_surface,
 
 bail:
   GST_OBJECT_LOCK (self);
-  if (self->filters) {
+  if (self->filters)
     g_array_unref (self->filters);
-    _destroy_filters_unlocked (self);
-  }
 
   gst_va_display_lock (self->display);
   status = vaDestroyBuffer (dpy, buffer);
index 274ea5d062ff039b91da1fccf6fd9733c9265b0a..e747cc2dd897bcd4999b5f6d25ce182ab134d6c5 100644 (file)
@@ -70,6 +70,7 @@ gboolean              gst_va_filter_add_filter_buffer     (GstVaFilter * self,
                                                            gpointer data,
                                                            gsize size,
                                                            guint num);
+gboolean              gst_va_filter_drop_filter_buffers   (GstVaFilter * self);
 gboolean              gst_va_filter_convert_surface       (GstVaFilter * self,
                                                            VASurfaceID in_surface,
                                                            VASurfaceID out_surface);
index 76cea8d5422e15272a160e0b5519e0a1e32410b8..ccd2c5e6240b8b4a12169fbad683ca6606a4e489 100644 (file)
@@ -112,6 +112,7 @@ struct _GstVaVpp
   GstBufferPool *other_pool;
   GstVideoInfo srcpad_info;
 
+  gboolean rebuild_filters;
   guint op_flags;
 
   /* filters */
@@ -265,15 +266,18 @@ gst_va_vpp_set_property (GObject * object, guint prop_id,
   switch (prop_id) {
     case GST_VA_FILTER_PROP_DENOISE:
       self->denoise = g_value_get_float (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_SHARPEN:
       self->sharpen = g_value_get_float (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_SKINTONE:
       if (G_VALUE_TYPE (value) == G_TYPE_BOOLEAN)
         self->skintone = (float) g_value_get_boolean (value);
       else
         self->skintone = g_value_get_float (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_VIDEO_DIR:{
       GstVideoOrientationMethod direction = g_value_get_enum (value);
@@ -284,24 +288,31 @@ gst_va_vpp_set_property (GObject * object, guint prop_id,
     }
     case GST_VA_FILTER_PROP_HUE:
       self->hue = g_value_get_float (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_SATURATION:
       self->saturation = g_value_get_float (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_BRIGHTNESS:
       self->brightness = g_value_get_float (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_CONTRAST:
       self->contrast = g_value_get_float (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_AUTO_SATURATION:
       self->auto_saturation = g_value_get_boolean (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_AUTO_BRIGHTNESS:
       self->auto_brightness = g_value_get_boolean (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     case GST_VA_FILTER_PROP_AUTO_CONTRAST:
       self->auto_contrast = g_value_get_boolean (value);
+      g_atomic_int_set (&self->rebuild_filters, TRUE);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -934,9 +945,8 @@ _add_filter_cb_buffer (GstVaVpp * self,
 }
 
 static void
-gst_va_vpp_before_transform (GstBaseTransform * trans, GstBuffer * inbuf)
+_build_filters (GstVaVpp * self)
 {
-  GstVaVpp *self = GST_VA_VPP (trans);
   static const VAProcFilterType filter_types[] = { VAProcFilterNoiseReduction,
     VAProcFilterSharpening, VAProcFilterSkinToneEnhancement,
     VAProcFilterColorBalance,
@@ -974,8 +984,19 @@ gst_va_vpp_before_transform (GstBaseTransform * trans, GstBuffer * inbuf)
   else
     self->op_flags &= ~VPP_CONVERT_FILTERS;
   GST_OBJECT_UNLOCK (self);
+}
 
-  _update_passthrough (self, TRUE);
+static void
+gst_va_vpp_before_transform (GstBaseTransform * trans, GstBuffer * inbuf)
+{
+  GstVaVpp *self = GST_VA_VPP (trans);
+
+  if (g_atomic_int_get (&self->rebuild_filters) == TRUE) {
+    gst_va_filter_drop_filter_buffers (self->filter);
+    _build_filters (self);
+    _update_passthrough (self, TRUE);
+    g_atomic_int_set (&self->rebuild_filters, FALSE);
+  }
 }
 
 static inline gsize
@@ -2562,6 +2583,7 @@ _set_cb_val (GstVaVpp * self, const gchar * name,
   if (changed) {
     GST_INFO_OBJECT (self, "%s: %d / %f", channel->label, value, new_value);
     gst_color_balance_value_changed (GST_COLOR_BALANCE (self), channel, value);
+    g_atomic_int_set (&self->rebuild_filters, TRUE);
   }
 
   return TRUE;