Commit 415f3dd8 authored by Sebastian Dröge's avatar Sebastian Dröge
Browse files

collectpads2: Merge clipping API from old collectpads

parent ab2d4528
...@@ -419,6 +419,28 @@ gst_collect_pads2_set_event_function (GstCollectPads2 * pads, ...@@ -419,6 +419,28 @@ gst_collect_pads2_set_event_function (GstCollectPads2 * pads,
GST_OBJECT_UNLOCK (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: * gst_collect_pads2_add_pad:
* @pads: the collectspads to use * @pads: the collectspads to use
...@@ -1836,6 +1858,14 @@ gst_collect_pads2_chain (GstPad * pad, GstBuffer * buffer) ...@@ -1836,6 +1858,14 @@ gst_collect_pads2_chain (GstPad * pad, GstBuffer * buffer)
GST_COLLECT_PADS2_STATE_EOS))) GST_COLLECT_PADS2_STATE_EOS)))
goto unexpected; 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_OBJECT (pads, "Queuing buffer %p for pad %s:%s", buffer,
GST_DEBUG_PAD_NAME (pad)); GST_DEBUG_PAD_NAME (pad));
...@@ -1963,6 +1993,13 @@ unexpected: ...@@ -1963,6 +1993,13 @@ unexpected:
ret = GST_FLOW_UNEXPECTED; ret = GST_FLOW_UNEXPECTED;
goto unlock_done; 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: error:
{ {
/* we print the error, the element should post a reasonable error /* we print the error, the element should post a reasonable error
......
...@@ -217,6 +217,30 @@ typedef gint (*GstCollectPads2CompareFunction) (GstCollectPads2 *pads, ...@@ -217,6 +217,30 @@ typedef gint (*GstCollectPads2CompareFunction) (GstCollectPads2 *pads,
typedef gboolean (*GstCollectPads2EventFunction) (GstCollectPads2 *pads, GstCollectData2 * pad, typedef gboolean (*GstCollectPads2EventFunction) (GstCollectPads2 *pads, GstCollectData2 * pad,
GstEvent * event, gpointer user_data); 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: * GST_COLLECT_PADS2_GET_STREAM_LOCK:
* @pads: a #GstCollectPads2 * @pads: a #GstCollectPads2
...@@ -288,6 +312,8 @@ struct _GstCollectPads2 { ...@@ -288,6 +312,8 @@ struct _GstCollectPads2 {
gpointer compare_user_data; gpointer compare_user_data;
GstCollectPads2EventFunction event_func; /* function and data for event callback */ GstCollectPads2EventFunction event_func; /* function and data for event callback */
gpointer event_user_data; gpointer event_user_data;
GstCollectPads2ClipFunction clip_func;
gpointer clip_user_data;
/* no other lock needed */ /* no other lock needed */
GMutex *evt_lock; /* these make up sort of poor man's event signaling */ 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, ...@@ -321,6 +347,8 @@ void gst_collect_pads2_set_event_function (GstCollectPads2 *pads,
GstCollectPads2EventFunction func, gpointer user_data); GstCollectPads2EventFunction func, gpointer user_data);
void gst_collect_pads2_set_compare_function (GstCollectPads2 *pads, void gst_collect_pads2_set_compare_function (GstCollectPads2 *pads,
GstCollectPads2CompareFunction func, gpointer user_data); GstCollectPads2CompareFunction func, gpointer user_data);
void gst_collect_pads2_set_clip_function (GstCollectPads2 *pads, GstCollectPads2ClipFunction clipfunc,
gpointer user_data);
/* pad management */ /* pad management */
GstCollectData2* gst_collect_pads2_add_pad (GstCollectPads2 *pads, GstPad *pad, guint size); GstCollectData2* gst_collect_pads2_add_pad (GstCollectPads2 *pads, GstPad *pad, guint size);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment