collectpads2: Merge clipping API from old collectpads
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 28 Oct 2011 08:17:06 +0000 (10:17 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 28 Oct 2011 08:38:24 +0000 (10:38 +0200)
libs/gst/base/gstcollectpads2.c
libs/gst/base/gstcollectpads2.h

index 60e4663..fed28f0 100644 (file)
@@ -419,6 +419,28 @@ gst_collect_pads2_set_event_function (GstCollectPads2 * pads,
   GST_OBJECT_UNLOCK (pads);
 }
 
+ /**
+ * gst_collect_pads2_set_clip_function:
+ * @pads: the collectspads to use
+ * @clipfunc: clip function to install
+ * @user_data: user data to pass to @clip_func
+ *
+ * Install a clipping function that is called right after a buffer is received
+ * on a pad managed by @pads. See #GstCollectPad2ClipFunction for more info.
+ *
+ * Since: 0.10.36
+ */
+void
+gst_collect_pads2_set_clip_function (GstCollectPads2 * pads,
+    GstCollectPads2ClipFunction clipfunc, gpointer user_data)
+{
+  g_return_if_fail (pads != NULL);
+  g_return_if_fail (GST_IS_COLLECT_PADS2 (pads));
+
+  pads->clip_func = clipfunc;
+  pads->clip_user_data = user_data;
+}
+
 /**
  * gst_collect_pads2_add_pad:
  * @pads: the collectspads to use
@@ -1836,6 +1858,14 @@ gst_collect_pads2_chain (GstPad * pad, GstBuffer * buffer)
               GST_COLLECT_PADS2_STATE_EOS)))
     goto unexpected;
 
+  /* see if we need to clip */
+  if (pads->clip_func) {
+    buffer = pads->clip_func (pads, data, buffer, pads->clip_user_data);
+
+    if (G_UNLIKELY (buffer == NULL))
+      goto clipped;
+  }
+
   GST_DEBUG_OBJECT (pads, "Queuing buffer %p for pad %s:%s", buffer,
       GST_DEBUG_PAD_NAME (pad));
 
@@ -1963,6 +1993,13 @@ unexpected:
     ret = GST_FLOW_UNEXPECTED;
     goto unlock_done;
   }
+clipped:
+  {
+    GST_DEBUG ("clipped buffer on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
+    GST_OBJECT_UNLOCK (pads);
+    unref_data (data);
+    return GST_FLOW_OK;
+  }
 error:
   {
     /* we print the error, the element should post a reasonable error
index bb3b921..f2bb71a 100644 (file)
@@ -217,6 +217,30 @@ typedef gint (*GstCollectPads2CompareFunction) (GstCollectPads2 *pads,
 typedef gboolean (*GstCollectPads2EventFunction)       (GstCollectPads2 *pads, GstCollectData2 * pad,
                                                         GstEvent * event, gpointer user_data);
 
+
+/**
+ * GstCollectPads2ClipFunction:
+ * @pads: a #GstCollectPads2 
+ * @data: a #GstCollectData2
+ * @buffer: a #GstBuffer 
+ * @user_data: user data 
+ *
+ * A function that will be called when @buffer is received on the pad managed
+ * by @data in the collecpad object @pads.
+ *
+ * The function should use the segment of @data and the negotiated media type on
+ * the pad to perform clipping of @buffer. 
+ *
+ * This function takes ownership of @buffer.
+ *
+ * Returns: a #GstBuffer that contains the clipped data of @buffer or NULL when
+ * the buffer has been clipped completely.
+ *
+ * Since: 0.10.36
+ */
+typedef GstBuffer * (*GstCollectPads2ClipFunction) (GstCollectPads2 *pads, GstCollectData2 *data,
+                                                   GstBuffer *buffer, gpointer user_data);
+
 /**
  * GST_COLLECT_PADS2_GET_STREAM_LOCK:
  * @pads: a #GstCollectPads2
@@ -288,6 +312,8 @@ struct _GstCollectPads2 {
   gpointer       compare_user_data;
   GstCollectPads2EventFunction event_func; /* function and data for event callback */
   gpointer       event_user_data;
+  GstCollectPads2ClipFunction clip_func;
+  gpointer       clip_user_data;
 
   /* no other lock needed */
   GMutex        *evt_lock;             /* these make up sort of poor man's event signaling */
@@ -321,6 +347,8 @@ void            gst_collect_pads2_set_event_function (GstCollectPads2 *pads,
                                                 GstCollectPads2EventFunction func, gpointer user_data);
 void           gst_collect_pads2_set_compare_function (GstCollectPads2 *pads,
                                                 GstCollectPads2CompareFunction func, gpointer user_data);
+void            gst_collect_pads2_set_clip_function (GstCollectPads2 *pads, GstCollectPads2ClipFunction clipfunc,
+                                                 gpointer user_data);
 
 /* pad management */
 GstCollectData2* gst_collect_pads2_add_pad     (GstCollectPads2 *pads, GstPad *pad, guint size);