mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 14:26:43 +00:00
adder: port to GstCollectPads2
This commit is contained in:
parent
60d5d08fbb
commit
a3c5abf97f
2 changed files with 30 additions and 28 deletions
|
@ -136,9 +136,10 @@ static void gst_adder_release_pad (GstElement * element, GstPad * pad);
|
||||||
static GstStateChangeReturn gst_adder_change_state (GstElement * element,
|
static GstStateChangeReturn gst_adder_change_state (GstElement * element,
|
||||||
GstStateChange transition);
|
GstStateChange transition);
|
||||||
|
|
||||||
static GstBuffer *gst_adder_do_clip (GstCollectPads * pads,
|
static GstFlowReturn gst_adder_do_clip (GstCollectPads2 * pads,
|
||||||
GstCollectData * data, GstBuffer * buffer, gpointer user_data);
|
GstCollectData2 * data, GstBuffer * buffer, GstBuffer ** out,
|
||||||
static GstFlowReturn gst_adder_collected (GstCollectPads * pads,
|
gpointer user_data);
|
||||||
|
static GstFlowReturn gst_adder_collected (GstCollectPads2 * pads,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
/* non-clipping versions (for float) */
|
/* non-clipping versions (for float) */
|
||||||
|
@ -660,7 +661,7 @@ gst_adder_src_event (GstPad * pad, GstEvent * event)
|
||||||
/* check if we are flushing */
|
/* check if we are flushing */
|
||||||
if (flush) {
|
if (flush) {
|
||||||
/* make sure we accept nothing anymore and return WRONG_STATE */
|
/* make sure we accept nothing anymore and return WRONG_STATE */
|
||||||
gst_collect_pads_set_flushing (adder->collect, TRUE);
|
gst_collect_pads2_set_flushing (adder->collect, TRUE);
|
||||||
|
|
||||||
/* flushing seek, start flush downstream, the flush will be done
|
/* flushing seek, start flush downstream, the flush will be done
|
||||||
* when all pads received a FLUSH_STOP. */
|
* when all pads received a FLUSH_STOP. */
|
||||||
|
@ -691,7 +692,7 @@ gst_adder_src_event (GstPad * pad, GstEvent * event)
|
||||||
if (flush) {
|
if (flush) {
|
||||||
/* Yes, we need to call _set_flushing again *WHEN* the streaming threads
|
/* Yes, we need to call _set_flushing again *WHEN* the streaming threads
|
||||||
* have stopped so that the cookie gets properly updated. */
|
* have stopped so that the cookie gets properly updated. */
|
||||||
gst_collect_pads_set_flushing (adder->collect, TRUE);
|
gst_collect_pads2_set_flushing (adder->collect, TRUE);
|
||||||
}
|
}
|
||||||
GST_OBJECT_UNLOCK (adder->collect);
|
GST_OBJECT_UNLOCK (adder->collect);
|
||||||
GST_DEBUG_OBJECT (adder, "forwarding seek event: %" GST_PTR_FORMAT,
|
GST_DEBUG_OBJECT (adder, "forwarding seek event: %" GST_PTR_FORMAT,
|
||||||
|
@ -749,7 +750,7 @@ gst_adder_sink_event (GstPad * pad, GstEvent * event)
|
||||||
case GST_EVENT_FLUSH_STOP:
|
case GST_EVENT_FLUSH_STOP:
|
||||||
/* we received a flush-stop. The collect_event function will push the
|
/* we received a flush-stop. The collect_event function will push the
|
||||||
* event past our element. We simply forward all flush-stop events, even
|
* event past our element. We simply forward all flush-stop events, even
|
||||||
* when no flush-stop was pending, this is required because collectpads
|
* when no flush-stop was pending, this is required because collectpads2
|
||||||
* does not provide an API to handle-but-not-forward the flush-stop.
|
* does not provide an API to handle-but-not-forward the flush-stop.
|
||||||
* We unset the pending flush-stop flag so that we don't send anymore
|
* We unset the pending flush-stop flag so that we don't send anymore
|
||||||
* flush-stop from the collect function later.
|
* flush-stop from the collect function later.
|
||||||
|
@ -783,7 +784,7 @@ gst_adder_sink_event (GstPad * pad, GstEvent * event)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now GstCollectPads can take care of the rest, e.g. EOS */
|
/* now GstCollectPads2 can take care of the rest, e.g. EOS */
|
||||||
ret = adder->collect_event (pad, event);
|
ret = adder->collect_event (pad, event);
|
||||||
|
|
||||||
beach:
|
beach:
|
||||||
|
@ -860,10 +861,10 @@ gst_adder_init (GstAdder * adder, GstAdderClass * klass)
|
||||||
adder->filter_caps = NULL;
|
adder->filter_caps = NULL;
|
||||||
|
|
||||||
/* keep track of the sinkpads requested */
|
/* keep track of the sinkpads requested */
|
||||||
adder->collect = gst_collect_pads_new ();
|
adder->collect = gst_collect_pads2_new ();
|
||||||
gst_collect_pads_set_function (adder->collect,
|
gst_collect_pads2_set_function (adder->collect,
|
||||||
GST_DEBUG_FUNCPTR (gst_adder_collected), adder);
|
GST_DEBUG_FUNCPTR (gst_adder_collected), adder);
|
||||||
gst_collect_pads_set_clip_function (adder->collect,
|
gst_collect_pads2_set_clip_function (adder->collect,
|
||||||
GST_DEBUG_FUNCPTR (gst_adder_do_clip), adder);
|
GST_DEBUG_FUNCPTR (gst_adder_do_clip), adder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -968,10 +969,10 @@ gst_adder_request_new_pad (GstElement * element, GstPadTemplate * templ,
|
||||||
gst_pad_set_getcaps_function (newpad,
|
gst_pad_set_getcaps_function (newpad,
|
||||||
GST_DEBUG_FUNCPTR (gst_adder_sink_getcaps));
|
GST_DEBUG_FUNCPTR (gst_adder_sink_getcaps));
|
||||||
gst_pad_set_setcaps_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_setcaps));
|
gst_pad_set_setcaps_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_setcaps));
|
||||||
gst_collect_pads_add_pad (adder->collect, newpad, sizeof (GstCollectData));
|
gst_collect_pads2_add_pad (adder->collect, newpad, sizeof (GstCollectData2));
|
||||||
|
|
||||||
/* FIXME: hacked way to override/extend the event function of
|
/* FIXME: hacked way to override/extend the event function of
|
||||||
* GstCollectPads; because it sets its own event function giving the
|
* GstCollectPads2; because it sets its own event function giving the
|
||||||
* element no access to events */
|
* element no access to events */
|
||||||
adder->collect_event = (GstPadEventFunction) GST_PAD_EVENTFUNC (newpad);
|
adder->collect_event = (GstPadEventFunction) GST_PAD_EVENTFUNC (newpad);
|
||||||
gst_pad_set_event_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_sink_event));
|
gst_pad_set_event_function (newpad, GST_DEBUG_FUNCPTR (gst_adder_sink_event));
|
||||||
|
@ -991,7 +992,7 @@ not_sink:
|
||||||
could_not_add:
|
could_not_add:
|
||||||
{
|
{
|
||||||
GST_DEBUG_OBJECT (adder, "could not add pad");
|
GST_DEBUG_OBJECT (adder, "could not add pad");
|
||||||
gst_collect_pads_remove_pad (adder->collect, newpad);
|
gst_collect_pads2_remove_pad (adder->collect, newpad);
|
||||||
gst_object_unref (newpad);
|
gst_object_unref (newpad);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1006,13 +1007,13 @@ gst_adder_release_pad (GstElement * element, GstPad * pad)
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (adder, "release pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
GST_DEBUG_OBJECT (adder, "release pad %s:%s", GST_DEBUG_PAD_NAME (pad));
|
||||||
|
|
||||||
gst_collect_pads_remove_pad (adder->collect, pad);
|
gst_collect_pads2_remove_pad (adder->collect, pad);
|
||||||
gst_element_remove_pad (element, pad);
|
gst_element_remove_pad (element, pad);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstBuffer *
|
static GstFlowReturn
|
||||||
gst_adder_do_clip (GstCollectPads * pads, GstCollectData * data,
|
gst_adder_do_clip (GstCollectPads2 * pads, GstCollectData2 * data,
|
||||||
GstBuffer * buffer, gpointer user_data)
|
GstBuffer * buffer, GstBuffer ** out, gpointer user_data)
|
||||||
{
|
{
|
||||||
GstAdder *adder = GST_ADDER (user_data);
|
GstAdder *adder = GST_ADDER (user_data);
|
||||||
|
|
||||||
|
@ -1025,11 +1026,12 @@ gst_adder_do_clip (GstCollectPads * pads, GstCollectData * data,
|
||||||
adder->bps);
|
adder->bps);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
*out = buffer;
|
||||||
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_adder_collected (GstCollectPads * pads, gpointer user_data)
|
gst_adder_collected (GstCollectPads2 * pads, gpointer user_data)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* combine streams by adding data values
|
* combine streams by adding data values
|
||||||
|
@ -1070,7 +1072,7 @@ gst_adder_collected (GstCollectPads * pads, gpointer user_data)
|
||||||
|
|
||||||
/* get available bytes for reading, this can be 0 which could mean empty
|
/* get available bytes for reading, this can be 0 which could mean empty
|
||||||
* buffers or EOS, which we will catch when we loop over the pads. */
|
* buffers or EOS, which we will catch when we loop over the pads. */
|
||||||
outsize = gst_collect_pads_available (pads);
|
outsize = gst_collect_pads2_available (pads);
|
||||||
/* can only happen when no pads to collect or all EOS */
|
/* can only happen when no pads to collect or all EOS */
|
||||||
if (outsize == 0)
|
if (outsize == 0)
|
||||||
goto eos;
|
goto eos;
|
||||||
|
@ -1080,18 +1082,18 @@ gst_adder_collected (GstCollectPads * pads, gpointer user_data)
|
||||||
outsize, adder->bps);
|
outsize, adder->bps);
|
||||||
|
|
||||||
for (collected = pads->data; collected; collected = next) {
|
for (collected = pads->data; collected; collected = next) {
|
||||||
GstCollectData *collect_data;
|
GstCollectData2 *collect_data;
|
||||||
GstBuffer *inbuf;
|
GstBuffer *inbuf;
|
||||||
gboolean is_gap;
|
gboolean is_gap;
|
||||||
|
|
||||||
/* take next to see if this is the last collectdata */
|
/* take next to see if this is the last collectdata */
|
||||||
next = g_slist_next (collected);
|
next = g_slist_next (collected);
|
||||||
|
|
||||||
collect_data = (GstCollectData *) collected->data;
|
collect_data = (GstCollectData2 *) collected->data;
|
||||||
|
|
||||||
/* get a buffer of size bytes, if we get a buffer, it is at least outsize
|
/* get a buffer of size bytes, if we get a buffer, it is at least outsize
|
||||||
* bytes big. */
|
* bytes big. */
|
||||||
inbuf = gst_collect_pads_take_buffer (pads, collect_data, outsize);
|
inbuf = gst_collect_pads2_take_buffer (pads, collect_data, outsize);
|
||||||
/* NULL means EOS or an empty buffer so we still need to flush in
|
/* NULL means EOS or an empty buffer so we still need to flush in
|
||||||
* case of an empty buffer. */
|
* case of an empty buffer. */
|
||||||
if (inbuf == NULL) {
|
if (inbuf == NULL) {
|
||||||
|
@ -1287,14 +1289,14 @@ gst_adder_change_state (GstElement * element, GstStateChange transition)
|
||||||
adder->segment_end = GST_CLOCK_TIME_NONE;
|
adder->segment_end = GST_CLOCK_TIME_NONE;
|
||||||
adder->segment_rate = 1.0;
|
adder->segment_rate = 1.0;
|
||||||
gst_segment_init (&adder->segment, GST_FORMAT_UNDEFINED);
|
gst_segment_init (&adder->segment, GST_FORMAT_UNDEFINED);
|
||||||
gst_collect_pads_start (adder->collect);
|
gst_collect_pads2_start (adder->collect);
|
||||||
break;
|
break;
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
||||||
break;
|
break;
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||||
/* need to unblock the collectpads before calling the
|
/* need to unblock the collectpads2 before calling the
|
||||||
* parent change_state so that streaming can finish */
|
* parent change_state so that streaming can finish */
|
||||||
gst_collect_pads_stop (adder->collect);
|
gst_collect_pads2_stop (adder->collect);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#define __GST_ADDER_H__
|
#define __GST_ADDER_H__
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/base/gstcollectpads.h>
|
#include <gst/base/gstcollectpads2.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ struct _GstAdder {
|
||||||
GstElement element;
|
GstElement element;
|
||||||
|
|
||||||
GstPad *srcpad;
|
GstPad *srcpad;
|
||||||
GstCollectPads *collect;
|
GstCollectPads2 *collect;
|
||||||
/* pad counter, used for creating unique request pads */
|
/* pad counter, used for creating unique request pads */
|
||||||
gint padcount;
|
gint padcount;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue