aspectcropratio: Set caps from the streaming thread on property changes
authorThibault Saunier <tsaunier@igalia.com>
Sun, 25 Nov 2018 14:31:11 +0000 (11:31 -0300)
committerThibault Saunier <tsaunier@igalia.com>
Mon, 26 Nov 2018 10:14:09 +0000 (07:14 -0300)
Otherwise it might lead to deadlocks

See https://gitlab.gnome.org/GNOME/pitivi/issues/2259

Closes #518

gst/videocrop/gstaspectratiocrop.c
gst/videocrop/gstaspectratiocrop.h

index 2c1d9d7..0bd4b69 100644 (file)
@@ -205,10 +205,32 @@ gst_aspect_ratio_crop_finalize (GObject * object)
   aspect_ratio_crop = GST_ASPECT_RATIO_CROP (object);
 
   g_mutex_clear (&aspect_ratio_crop->crop_lock);
+  gst_caps_unref (aspect_ratio_crop->renegotiation_caps);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static GstFlowReturn
+gst_aspect_ratio_crop_sink_chain (GstPad * pad, GstObject * parent,
+    GstBuffer * buffer)
+{
+  GstCaps *caps = NULL;
+  GstAspectRatioCrop *aspect_ratio_crop = GST_ASPECT_RATIO_CROP (parent);
+
+  GST_OBJECT_LOCK (parent);
+  caps = aspect_ratio_crop->renegotiation_caps;
+  aspect_ratio_crop->renegotiation_caps = NULL;
+  GST_OBJECT_UNLOCK (parent);
+
+  if (caps) {
+    gst_aspect_ratio_crop_set_caps (GST_ASPECT_RATIO_CROP (parent), caps);
+    gst_caps_unref (caps);
+  }
+
+  return gst_proxy_pad_chain_default (pad, parent, buffer);
+
+}
+
 static void
 gst_aspect_ratio_crop_init (GstAspectRatioCrop * aspect_ratio_crop)
 {
@@ -247,6 +269,8 @@ gst_aspect_ratio_crop_init (GstAspectRatioCrop * aspect_ratio_crop)
 
   gst_pad_set_event_function (aspect_ratio_crop->sink,
       GST_DEBUG_FUNCPTR (gst_aspect_ratio_crop_sink_event));
+  gst_pad_set_chain_function (aspect_ratio_crop->sink,
+      GST_DEBUG_FUNCPTR (gst_aspect_ratio_crop_sink_chain));
 }
 
 static void
@@ -461,11 +485,11 @@ gst_aspect_ratio_crop_set_property (GObject * object, guint prop_id,
   GST_OBJECT_UNLOCK (aspect_ratio_crop);
 
   if (recheck) {
-    GstCaps *caps = gst_pad_get_current_caps (aspect_ratio_crop->sink);
-    if (caps != NULL) {
-      gst_aspect_ratio_crop_set_caps (aspect_ratio_crop, caps);
-      gst_caps_unref (caps);
-    }
+    GST_OBJECT_LOCK (aspect_ratio_crop);
+    gst_clear_caps (&aspect_ratio_crop->renegotiation_caps);
+    aspect_ratio_crop->renegotiation_caps =
+        gst_pad_get_current_caps (aspect_ratio_crop->sink);
+    GST_OBJECT_UNLOCK (aspect_ratio_crop);
   }
 }
 
index 2caeb5c..9cb2ef7 100644 (file)
@@ -51,6 +51,8 @@ struct _GstAspectRatioCrop
   gint ar_num; /* if < 1 then don't change ar */
   gint ar_denom;
 
+  GstCaps *renegotiation_caps;
+
   GMutex crop_lock;
 };