GstPadClass parent;
};
-static void gst_selector_pad_class_init (GstSelectorPadClass * klass);
-static void gst_selector_pad_init (GstSelectorPad * pad);
+GType gst_selector_pad_get_type (void);
static void gst_selector_pad_finalize (GObject * object);
static void gst_selector_pad_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_selector_pad_set_property (GObject * object,
guint prop_id, const GValue * value, GParamSpec * pspec);
-static GstPadClass *selector_pad_parent_class = NULL;
-
static gint64 gst_selector_pad_get_running_time (GstSelectorPad * pad);
static void gst_selector_pad_reset (GstSelectorPad * pad);
static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event);
-static GstCaps *gst_selector_pad_getcaps (GstPad * pad);
+static GstCaps *gst_selector_pad_getcaps (GstPad * pad, GstCaps * filter);
static gboolean gst_selector_pad_acceptcaps (GstPad * pad, GstCaps * caps);
static GstIterator *gst_selector_pad_iterate_linked_pads (GstPad * pad);
static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf);
-static GstFlowReturn gst_selector_pad_bufferalloc (GstPad * pad,
- guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf);
-
-static GType
-gst_selector_pad_get_type (void)
-{
- static volatile gsize selector_pad_type = 0;
- static const GTypeInfo selector_pad_info = {
- sizeof (GstSelectorPadClass),
- NULL,
- NULL,
- (GClassInitFunc) gst_selector_pad_class_init,
- NULL,
- NULL,
- sizeof (GstSelectorPad),
- 0,
- (GInstanceInitFunc) gst_selector_pad_init,
- };
-
- if (g_once_init_enter (&selector_pad_type)) {
- GType tmp = g_type_register_static (GST_TYPE_PAD, "GstSelectorPad",
- &selector_pad_info, 0);
- g_once_init_leave (&selector_pad_type, tmp);
- }
- return (GType) selector_pad_type;
-}
+G_DEFINE_TYPE (GstSelectorPad, gst_selector_pad, GST_TYPE_PAD);
static void
gst_selector_pad_class_init (GstSelectorPadClass * klass)
gobject_class = (GObjectClass *) klass;
- selector_pad_parent_class = g_type_class_peek_parent (klass);
-
gobject_class->finalize = gst_selector_pad_finalize;
gobject_class->get_property = gst_selector_pad_get_property;
if (pad->tags)
gst_tag_list_free (pad->tags);
- G_OBJECT_CLASS (selector_pad_parent_class)->finalize (object);
+ G_OBJECT_CLASS (gst_selector_pad_parent_class)->finalize (object);
}
static void
GST_OBJECT_LOCK (pad);
if (pad->active) {
- gint64 last_stop = pad->segment.last_stop;
+ gint64 position = pad->segment.position;
- if (last_stop >= 0)
+ if (position >= 0)
ret = gst_segment_to_running_time (&pad->segment, GST_FORMAT_TIME,
- last_stop);
+ position);
}
GST_OBJECT_UNLOCK (pad);
GstInputSelector *sel;
GstPad *otherpad;
GstIterator *it;
+ GValue val = { 0, };
sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
if (G_UNLIKELY (sel == NULL))
return NULL;
otherpad = gst_input_selector_get_linked_pad (sel, pad, TRUE);
- it = gst_iterator_new_single (GST_TYPE_PAD, otherpad,
- (GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
+ g_value_init (&val, GST_TYPE_PAD);
+ g_value_set_object (&val, otherpad);
+ it = gst_iterator_new_single (GST_TYPE_PAD, &val);
+ g_value_unset (&val);
if (otherpad)
gst_object_unref (otherpad);
sel->pending_close = FALSE;
GST_INPUT_SELECTOR_UNLOCK (sel);
break;
- case GST_EVENT_NEWSEGMENT:
+ case GST_EVENT_SEGMENT:
{
- gboolean update;
- GstFormat format;
- gdouble rate, arate;
- gint64 start, stop, time;
-
- gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
- &start, &stop, &time);
-
- GST_DEBUG_OBJECT (pad,
- "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
- "format %d, "
- "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
- G_GINT64_FORMAT, update, rate, arate, format, start, stop, time);
-
GST_INPUT_SELECTOR_LOCK (sel);
GST_OBJECT_LOCK (selpad);
- gst_segment_set_newsegment_full (&selpad->segment, update,
- rate, arate, format, start, stop, time);
+ gst_event_parse_segment (event, &selpad->segment);
+ GST_DEBUG_OBJECT (pad, "configured SEGMENT %" GST_SEGMENT_FORMAT,
+ &selpad->segment);
GST_OBJECT_UNLOCK (selpad);
/* If we aren't forwarding the event because the pad is not the
}
static GstCaps *
-gst_selector_pad_getcaps (GstPad * pad)
+gst_selector_pad_getcaps (GstPad * pad, GstCaps * filter)
{
GstInputSelector *sel;
GstCaps *caps;
sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
if (G_UNLIKELY (sel == NULL))
- return gst_caps_new_any ();
+ return (filter ? gst_caps_ref (filter) : gst_caps_new_any ());
GST_DEBUG_OBJECT (sel, "Getting caps of srcpad peer");
- caps = gst_pad_peer_get_caps_reffed (sel->srcpad);
+ caps = gst_pad_peer_get_caps (sel->srcpad, filter);
if (caps == NULL)
- caps = gst_caps_new_any ();
+ caps = (filter ? gst_caps_ref (filter) : gst_caps_new_any ());
gst_object_unref (sel);
return res;
}
-static GstFlowReturn
-gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset,
- guint size, GstCaps * caps, GstBuffer ** buf)
-{
- GstInputSelector *sel;
- GstFlowReturn result;
- GstPad *active_sinkpad;
- GstPad *prev_active_sinkpad;
- GstSelectorPad *selpad;
-
- sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
- if (G_UNLIKELY (sel == NULL))
- return GST_FLOW_WRONG_STATE;
-
- selpad = GST_SELECTOR_PAD_CAST (pad);
-
- GST_LOG_OBJECT (pad, "received alloc");
-
- GST_INPUT_SELECTOR_LOCK (sel);
- prev_active_sinkpad = sel->active_sinkpad;
- active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad);
-
- if (pad != active_sinkpad)
- goto not_active;
-
- GST_INPUT_SELECTOR_UNLOCK (sel);
-
- if (prev_active_sinkpad != active_sinkpad && pad == active_sinkpad) {
- NOTIFY_MUTEX_LOCK ();
- g_object_notify (G_OBJECT (sel), "active-pad");
- NOTIFY_MUTEX_UNLOCK ();
- }
-
- result = gst_pad_alloc_buffer (sel->srcpad, offset, size, caps, buf);
-
-done:
- gst_object_unref (sel);
-
- return result;
-
- /* ERRORS */
-not_active:
- {
- gboolean active_pad_pushed = GST_SELECTOR_PAD_CAST (active_sinkpad)->pushed;
-
- GST_INPUT_SELECTOR_UNLOCK (sel);
-
- /* unselected pad, perform fallback alloc or return unlinked when
- * asked */
- GST_OBJECT_LOCK (selpad);
- if (selpad->always_ok || !active_pad_pushed) {
- GST_DEBUG_OBJECT (pad, "Not selected, performing fallback allocation");
- *buf = NULL;
- result = GST_FLOW_OK;
- } else {
- GST_DEBUG_OBJECT (pad, "Not selected, return NOT_LINKED");
- result = GST_FLOW_NOT_LINKED;
- }
- GST_OBJECT_UNLOCK (selpad);
-
- goto done;
- }
-}
-
/* must be called with the SELECTOR_LOCK, will block while the pad is blocked
* or return TRUE when flushing */
static gboolean
if (active_seg->format == GST_FORMAT_TIME)
active_running_time =
gst_segment_to_running_time (active_seg, GST_FORMAT_TIME,
- active_seg->last_stop);
+ active_seg->position);
/* Wait until
* a) this is the active pad
if (active_seg->format == GST_FORMAT_TIME)
active_running_time =
gst_segment_to_running_time (active_seg, GST_FORMAT_TIME,
- active_seg->last_stop);
+ active_seg->position);
else
active_running_time = -1;
GstSelectorPad *selpad;
GstClockTime start_time;
GstSegment *seg;
- GstEvent *close_event = NULL, *start_event = NULL;
+ GstEvent *start_event = NULL;
+#if 0
GstCaps *caps;
+#endif
sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
selpad = GST_SELECTOR_PAD_CAST (pad);
GST_TIME_ARGS (start_time + GST_BUFFER_DURATION (buf)));
GST_OBJECT_LOCK (pad);
- gst_segment_set_last_stop (seg, seg->format, start_time);
+ seg->position = start_time;
GST_OBJECT_UNLOCK (pad);
}
if (sel->sync_streams)
GST_INPUT_SELECTOR_BROADCAST (sel);
- if (G_UNLIKELY (sel->pending_close)) {
- GstSegment *cseg = &sel->segment;
-
- GST_DEBUG_OBJECT (sel,
- "pushing close NEWSEGMENT update %d, rate %lf, applied rate %lf, "
- "format %d, "
- "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
- G_GINT64_FORMAT, TRUE, cseg->rate, cseg->applied_rate, cseg->format,
- cseg->start, cseg->stop, cseg->time);
-
- /* create update segment */
- close_event = gst_event_new_new_segment_full (TRUE, cseg->rate,
- cseg->applied_rate, cseg->format, cseg->start, cseg->stop, cseg->time);
-
- sel->pending_close = FALSE;
- }
/* if we have a pending segment, push it out now */
if (G_UNLIKELY (selpad->segment_pending)) {
GST_DEBUG_OBJECT (pad,
G_GINT64_FORMAT, FALSE, seg->rate, seg->applied_rate, seg->format,
seg->start, seg->stop, seg->time);
- start_event = gst_event_new_new_segment_full (FALSE, seg->rate,
- seg->applied_rate, seg->format, seg->start, seg->stop, seg->time);
+ start_event = gst_event_new_segment (seg);
selpad->segment_pending = FALSE;
}
NOTIFY_MUTEX_UNLOCK ();
}
- if (close_event)
- gst_pad_push_event (sel->srcpad, close_event);
-
if (start_event)
gst_pad_push_event (sel->srcpad, start_event);
if (selpad->discont) {
- buf = gst_buffer_make_metadata_writable (buf);
+ buf = gst_buffer_make_writable (buf);
GST_DEBUG_OBJECT (pad, "Marking discont buffer %p", buf);
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_DISCONT);
/* forward */
GST_LOG_OBJECT (pad, "Forwarding buffer %p", buf);
+#if 0
if ((caps = GST_BUFFER_CAPS (buf))) {
if (GST_PAD_CAPS (sel->srcpad) != caps)
gst_pad_set_caps (sel->srcpad, caps);
}
+#endif
res = gst_pad_push (sel->srcpad, buf);
selpad->pushed = TRUE;
guint prop_id, GValue * value, GParamSpec * pspec);
static GstPad *gst_input_selector_request_new_pad (GstElement * element,
- GstPadTemplate * templ, const gchar * unused);
+ GstPadTemplate * templ, const gchar * unused, const GstCaps * caps);
static void gst_input_selector_release_pad (GstElement * element, GstPad * pad);
static GstStateChangeReturn gst_input_selector_change_state (GstElement *
element, GstStateChange transition);
-static GstCaps *gst_input_selector_getcaps (GstPad * pad);
+static GstCaps *gst_input_selector_getcaps (GstPad * pad, GstCaps * filter);
static gboolean gst_input_selector_event (GstPad * pad, GstEvent * event);
-static gboolean gst_input_selector_query (GstPad * pad, GstQuery * query);
+static gboolean gst_input_selector_query (GstPad * pad, GstQuery ** query);
static gint64 gst_input_selector_block (GstInputSelector * self);
static void gst_input_selector_switch (GstInputSelector * self,
GstPad * pad, gint64 stop_time, gint64 start_time);
g_marshal_value_peek_int64 (param_values + 3), data2);
}
-#define _do_init(bla) \
+#define _do_init \
GST_DEBUG_CATEGORY_INIT (input_selector_debug, \
"input-selector", 0, "An input stream selector element");
-
-GST_BOILERPLATE_FULL (GstInputSelector, gst_input_selector, GstElement,
- GST_TYPE_ELEMENT, _do_init);
-
-static void
-gst_input_selector_base_init (gpointer g_class)
-{
- GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
-
- gst_element_class_set_details_simple (element_class, "Input selector",
- "Generic", "N-to-1 input stream selector",
- "Julien Moutte <julien@moutte.net>, "
- "Jan Schmidt <thaytan@mad.scientist.com>, "
- "Wim Taymans <wim.taymans@gmail.com>");
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&gst_input_selector_sink_factory));
- gst_element_class_add_pad_template (element_class,
- gst_static_pad_template_get (&gst_input_selector_src_factory));
-}
+#define gst_input_selector_parent_class parent_class
+G_DEFINE_TYPE_WITH_CODE (GstInputSelector, gst_input_selector, GST_TYPE_ELEMENT,
+ _do_init);
static void
gst_input_selector_class_init (GstInputSelectorClass * klass)
NULL, NULL, gst_input_selector_marshal_VOID__OBJECT_INT64_INT64,
G_TYPE_NONE, 3, GST_TYPE_PAD, G_TYPE_INT64, G_TYPE_INT64);
+ gst_element_class_set_details_simple (gstelement_class, "Input selector",
+ "Generic", "N-to-1 input stream selector",
+ "Julien Moutte <julien@moutte.net>, "
+ "Jan Schmidt <thaytan@mad.scientist.com>, "
+ "Wim Taymans <wim.taymans@gmail.com>");
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&gst_input_selector_sink_factory));
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&gst_input_selector_src_factory));
+
gstelement_class->request_new_pad = gst_input_selector_request_new_pad;
gstelement_class->release_pad = gst_input_selector_release_pad;
gstelement_class->change_state = gst_input_selector_change_state;
}
static void
-gst_input_selector_init (GstInputSelector * sel,
- GstInputSelectorClass * g_class)
+gst_input_selector_init (GstInputSelector * sel)
{
sel->srcpad = gst_pad_new ("src", GST_PAD_SRC);
gst_pad_set_iterate_internal_links_function (sel->srcpad,
static gint64
gst_segment_get_timestamp (GstSegment * segment, gint64 running_time)
{
- if (running_time <= segment->accum)
+ if (running_time <= segment->base)
return segment->start;
else
- return (running_time - segment->accum) * segment->abs_rate + segment->start;
+ return (running_time - segment->base) * ABS (segment->rate) +
+ segment->start;
}
static void
gst_segment_set_stop (GstSegment * segment, gint64 running_time)
{
segment->stop = gst_segment_get_timestamp (segment, running_time);
- segment->last_stop = -1;
+ segment->position = -1;
}
static void
/* this is the duration we skipped */
duration = new_start - segment->start;
/* add the duration to the accumulated segment time */
- segment->accum += duration;
+ segment->base += duration;
/* move position in the segment */
segment->time += duration;
segment->start += duration;
/* query on the srcpad. We override this function because by default it will
* only forward the query to one random sinkpad */
static gboolean
-gst_input_selector_query (GstPad * pad, GstQuery * query)
+gst_input_selector_query (GstPad * pad, GstQuery ** query)
{
gboolean res = TRUE;
GstInputSelector *sel;
otherpad = gst_input_selector_get_linked_pad (sel, pad, TRUE);
- switch (GST_QUERY_TYPE (query)) {
+ switch (GST_QUERY_TYPE (*query)) {
case GST_QUERY_LATENCY:
{
GList *walk;
/* one query succeeded, we succeed too */
res = TRUE;
- gst_query_parse_latency (query, &live, &min, &max);
+ gst_query_parse_latency (*query, &live, &min, &max);
GST_DEBUG_OBJECT (sinkpad,
"peer latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
}
GST_INPUT_SELECTOR_UNLOCK (sel);
if (res) {
- gst_query_set_latency (query, reslive, resmin, resmax);
+ gst_query_set_latency (*query, reslive, resmin, resmax);
GST_DEBUG_OBJECT (sel,
"total latency min %" GST_TIME_FORMAT ", max %" GST_TIME_FORMAT
}
static GstCaps *
-gst_input_selector_getcaps (GstPad * pad)
+gst_input_selector_getcaps (GstPad * pad, GstCaps * filter)
{
GstPad *otherpad;
GstInputSelector *sel;
sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad));
if (G_UNLIKELY (sel == NULL))
- return gst_caps_new_any ();
+ return (filter ? gst_caps_ref (filter) : gst_caps_new_any ());
otherpad = gst_input_selector_get_linked_pad (sel, pad, FALSE);
if (!otherpad) {
GST_DEBUG_OBJECT (pad, "Pad not linked, returning ANY");
- caps = gst_caps_new_any ();
+ caps = (filter ? gst_caps_ref (filter) : gst_caps_new_any ());
} else {
GST_DEBUG_OBJECT (pad, "Pad is linked (to %s:%s), returning peer caps",
GST_DEBUG_PAD_NAME (otherpad));
/* if the peer has caps, use those. If the pad is not linked, this function
* returns NULL and we return ANY */
- if (!(caps = gst_pad_peer_get_caps_reffed (otherpad)))
- caps = gst_caps_new_any ();
+ if (!(caps = gst_pad_peer_get_caps (otherpad, filter)))
+ caps = (filter ? gst_caps_ref (filter) : gst_caps_new_any ());
gst_object_unref (otherpad);
}
static GstPad *
gst_input_selector_request_new_pad (GstElement * element,
- GstPadTemplate * templ, const gchar * unused)
+ GstPadTemplate * templ, const gchar * unused, const GstCaps * caps)
{
GstInputSelector *sel;
gchar *name = NULL;
GST_DEBUG_FUNCPTR (gst_selector_pad_chain));
gst_pad_set_iterate_internal_links_function (sinkpad,
GST_DEBUG_FUNCPTR (gst_selector_pad_iterate_linked_pads));
- gst_pad_set_bufferalloc_function (sinkpad,
- GST_DEBUG_FUNCPTR (gst_selector_pad_bufferalloc));
gst_pad_set_active (sinkpad, TRUE);
gst_element_add_pad (GST_ELEMENT (sel), sinkpad);