diff options
Diffstat (limited to 'gst')
-rw-r--r-- | gst/selector/.gitignore | 2 | ||||
-rw-r--r-- | gst/selector/Makefile.am | 22 | ||||
-rw-r--r-- | gst/selector/gstinputselector.c (renamed from gst/switch/gstswitch.c) | 251 | ||||
-rw-r--r-- | gst/selector/gstinputselector.h (renamed from gst/switch/gstswitch.h) | 41 | ||||
-rw-r--r-- | gst/selector/gstoutputselector.c | 448 | ||||
-rw-r--r-- | gst/selector/gstoutputselector.h | 66 | ||||
-rw-r--r-- | gst/selector/gstselector-marshal.list (renamed from gst/switch/gstswitch-marshal.list) | 0 | ||||
-rw-r--r-- | gst/selector/gstselector.c | 44 | ||||
-rw-r--r-- | gst/selector/selector.vcproj (renamed from gst/switch/switch.vcproj) | 20 | ||||
-rw-r--r-- | gst/switch/.gitignore | 2 | ||||
-rw-r--r-- | gst/switch/Makefile.am | 22 |
11 files changed, 736 insertions, 182 deletions
diff --git a/gst/selector/.gitignore b/gst/selector/.gitignore new file mode 100644 index 00000000..1cf1f1b3 --- /dev/null +++ b/gst/selector/.gitignore @@ -0,0 +1,2 @@ +gstselector-marshal.c +gstselector-marshal.h diff --git a/gst/selector/Makefile.am b/gst/selector/Makefile.am new file mode 100644 index 00000000..ddeb90fd --- /dev/null +++ b/gst/selector/Makefile.am @@ -0,0 +1,22 @@ +glib_enum_prefix = gst_selector + +include $(top_srcdir)/common/glib-gen.mak + +built_sources = gstselector-marshal.c +built_headers = gstselector-marshal.h + +BUILT_SOURCES = $(built_sources) $(built_headers) + +CLEANFILES = $(BUILT_SOURCES) + +EXTRA_DIST = gstselector-marshal.list + +plugin_LTLIBRARIES = libgstselector.la + +libgstselector_la_SOURCES = gstselector.c gstinputselector.c gstoutputselector.c +nodist_libgstselector_la_SOURCES = $(built_sources) +libgstselector_la_CFLAGS = $(GST_CFLAGS) +libgstselector_la_LIBADD = +libgstselector_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) + +noinst_HEADERS = gstinputselector.h gstoutputselector.h $(built_headers) diff --git a/gst/switch/gstswitch.c b/gst/selector/gstinputselector.c index fd4a4a33..a4d46182 100644 --- a/gst/switch/gstswitch.c +++ b/gst/selector/gstinputselector.c @@ -4,6 +4,7 @@ * Copyright (C) 2005 Jan Schmidt <thaytan@mad.scientist.com> * Copyright (C) 2007 Wim Taymans <wim.taymans@gmail.com> * Copyright (C) 2007 Andy Wingo <wingo@pobox.com> + * Copyright (C) 2008 Nokia Corporation. (contact <stefan.kost@nokia.com>) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,34 +22,42 @@ * Boston, MA 02111-1307, USA. */ +/** + * SECTION:element-input-selector + * @short_description: N-to-1 stream selectoring + * @see_also: #GstOutputSelector + * + * Direct one out of N input streams to the output pad. + */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <string.h> -#include "gstswitch.h" -#include "gstswitch-marshal.h" +#include "gstinputselector.h" +#include "gstselector-marshal.h" -GST_DEBUG_CATEGORY_STATIC (stream_selector_debug); -#define GST_CAT_DEFAULT stream_selector_debug +GST_DEBUG_CATEGORY_STATIC (input_selector_debug); +#define GST_CAT_DEFAULT input_selector_debug -static const GstElementDetails gst_stream_selector_details = -GST_ELEMENT_DETAILS ("StreamSelector", +static const GstElementDetails gst_input_selector_details = +GST_ELEMENT_DETAILS ("Input selector", "Generic", - "N-to-1 input stream_selectoring", + "N-to-1 input stream selectoring", "Julien Moutte <julien@moutte.net>\n" "Ronald S. Bultje <rbultje@ronald.bitfreak.net>\n" "Jan Schmidt <thaytan@mad.scientist.com>\n" "Wim Taymans <wim.taymans@gmail.com>"); -static GstStaticPadTemplate gst_stream_selector_sink_factory = +static GstStaticPadTemplate gst_input_selector_sink_factory = GST_STATIC_PAD_TEMPLATE ("sink%d", GST_PAD_SINK, GST_PAD_REQUEST, GST_STATIC_CAPS_ANY); -static GstStaticPadTemplate gst_stream_selector_src_factory = +static GstStaticPadTemplate gst_input_selector_src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, @@ -71,15 +80,15 @@ enum SIGNAL_SWITCH, LAST_SIGNAL }; -static guint gst_stream_selector_signals[LAST_SIGNAL] = { 0 }; +static guint gst_input_selector_signals[LAST_SIGNAL] = { 0 }; -static gboolean gst_stream_selector_is_active_sinkpad (GstStreamSelector * sel, +static gboolean gst_input_selector_is_active_sinkpad (GstInputSelector * sel, GstPad * pad); -static GstPad *gst_stream_selector_activate_sinkpad (GstStreamSelector * sel, +static GstPad *gst_input_selector_activate_sinkpad (GstInputSelector * sel, GstPad * pad); -static GstPad *gst_stream_selector_get_linked_pad (GstPad * pad, +static GstPad *gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict); -static void gst_stream_selector_push_pending_stop (GstStreamSelector * self); +static void gst_input_selector_push_pending_stop (GstInputSelector * self); #define GST_TYPE_SELECTOR_PAD \ (gst_selector_pad_get_type()) @@ -148,7 +157,7 @@ gst_selector_pad_get_type (void) }; selector_pad_type = - g_type_register_static (GST_TYPE_PAD, "GstSwitchPad", + g_type_register_static (GST_TYPE_PAD, "GstSelectorPad", &selector_pad_info, 0); } return selector_pad_type; @@ -243,7 +252,7 @@ gst_selector_pad_get_linked_pads (GstPad * pad) { GstPad *otherpad; - otherpad = gst_stream_selector_get_linked_pad (pad, TRUE); + otherpad = gst_input_selector_get_linked_pad (pad, TRUE); if (!otherpad) return NULL; @@ -258,14 +267,14 @@ gst_selector_pad_event (GstPad * pad, GstEvent * event) { gboolean res = TRUE; gboolean forward = TRUE; - GstStreamSelector *sel; + GstInputSelector *sel; GstSelectorPad *selpad; - sel = GST_STREAM_SELECTOR (gst_pad_get_parent (pad)); + sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad)); selpad = GST_SELECTOR_PAD_CAST (pad); /* only forward if we are dealing with the active sinkpad */ - forward = gst_stream_selector_is_active_sinkpad (sel, pad); + forward = gst_input_selector_is_active_sinkpad (sel, pad); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_FLUSH_STOP: @@ -312,10 +321,10 @@ gst_selector_pad_event (GstPad * pad, GstEvent * event) static GstCaps * gst_selector_pad_getcaps (GstPad * pad) { - GstStreamSelector *sel; + GstInputSelector *sel; GstCaps *caps; - sel = GST_STREAM_SELECTOR (gst_pad_get_parent (pad)); + sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad)); GST_DEBUG_OBJECT (sel, "Getting caps of srcpad peer"); caps = gst_pad_peer_get_caps (sel->srcpad); @@ -331,13 +340,13 @@ static GstFlowReturn gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf) { - GstStreamSelector *sel; + GstInputSelector *sel; GstFlowReturn result; GstPad *active_sinkpad; - sel = GST_STREAM_SELECTOR (gst_pad_get_parent (pad)); + sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad)); - active_sinkpad = gst_stream_selector_activate_sinkpad (sel, pad); + active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad); /* Fallback allocation for buffers from pads except the selected one */ if (pad != active_sinkpad) { @@ -370,7 +379,7 @@ gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset, } static gboolean -gst_stream_selector_wait (GstStreamSelector * self, GstPad * pad) +gst_input_selector_wait (GstInputSelector * self, GstPad * pad) { gboolean flushing; @@ -391,21 +400,21 @@ gst_stream_selector_wait (GstStreamSelector * self, GstPad * pad) static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf) { - GstStreamSelector *sel; + GstInputSelector *sel; GstFlowReturn res; GstPad *active_sinkpad; GstSelectorPad *selpad; GstClockTime end_time, duration; GstSegment *seg; - sel = GST_STREAM_SELECTOR (gst_pad_get_parent (pad)); + sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad)); selpad = GST_SELECTOR_PAD_CAST (pad); seg = &selpad->segment; - if (gst_stream_selector_wait (sel, pad)) + if (gst_input_selector_wait (sel, pad)) goto ignore; - active_sinkpad = gst_stream_selector_activate_sinkpad (sel, pad); + active_sinkpad = gst_input_selector_activate_sinkpad (sel, pad); end_time = GST_BUFFER_TIMESTAMP (buf); if (GST_CLOCK_TIME_IS_VALID (end_time)) { @@ -421,7 +430,7 @@ gst_selector_pad_chain (GstPad * pad, GstBuffer * buf) if (pad != active_sinkpad) goto ignore; - gst_stream_selector_push_pending_stop (sel); + gst_input_selector_push_pending_stop (sel); /* if we have a pending segment, push it out now */ if (selpad->segment_pending) { @@ -450,101 +459,100 @@ ignore: } } -static void gst_stream_selector_dispose (GObject * object); -static void gst_stream_selector_init (GstStreamSelector * sel); -static void gst_stream_selector_base_init (GstStreamSelectorClass * klass); -static void gst_stream_selector_class_init (GstStreamSelectorClass * klass); -static void gst_stream_selector_set_property (GObject * object, +static void gst_input_selector_dispose (GObject * object); +static void gst_input_selector_init (GstInputSelector * sel); +static void gst_input_selector_base_init (GstInputSelectorClass * klass); +static void gst_input_selector_class_init (GstInputSelectorClass * klass); +static void gst_input_selector_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); -static void gst_stream_selector_get_property (GObject * object, +static void gst_input_selector_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -static GstPad *gst_stream_selector_request_new_pad (GstElement * element, +static GstPad *gst_input_selector_request_new_pad (GstElement * element, GstPadTemplate * templ, const gchar * unused); -static void gst_stream_selector_release_pad (GstElement * element, - GstPad * pad); -static GstStateChangeReturn gst_stream_selector_change_state (GstElement * +static void gst_input_selector_release_pad (GstElement * element, GstPad * pad); +static GstStateChangeReturn gst_input_selector_change_state (GstElement * element, GstStateChange transition); -static GList *gst_stream_selector_get_linked_pads (GstPad * pad); -static GstCaps *gst_stream_selector_getcaps (GstPad * pad); -static gint64 gst_stream_selector_block (GstStreamSelector * self); -static void gst_stream_selector_switch (GstStreamSelector * self, +static GList *gst_input_selector_get_linked_pads (GstPad * pad); +static GstCaps *gst_input_selector_getcaps (GstPad * pad); +static gint64 gst_input_selector_block (GstInputSelector * self); +static void gst_input_selector_switch (GstInputSelector * self, const gchar * pad_name, gint64 stop_time, gint64 start_time); static GstElementClass *parent_class = NULL; GType -gst_stream_selector_get_type (void) +gst_input_selector_get_type (void) { - static GType stream_selector_type = 0; + static GType input_selector_type = 0; - if (!stream_selector_type) { - static const GTypeInfo stream_selector_info = { - sizeof (GstStreamSelectorClass), - (GBaseInitFunc) gst_stream_selector_base_init, + if (!input_selector_type) { + static const GTypeInfo input_selector_info = { + sizeof (GstInputSelectorClass), + (GBaseInitFunc) gst_input_selector_base_init, NULL, - (GClassInitFunc) gst_stream_selector_class_init, + (GClassInitFunc) gst_input_selector_class_init, NULL, NULL, - sizeof (GstStreamSelector), + sizeof (GstInputSelector), 0, - (GInstanceInitFunc) gst_stream_selector_init, + (GInstanceInitFunc) gst_input_selector_init, }; - stream_selector_type = + input_selector_type = g_type_register_static (GST_TYPE_ELEMENT, - "GstSwitch", &stream_selector_info, 0); - GST_DEBUG_CATEGORY_INIT (stream_selector_debug, - "streamselector", 0, "A stream-selector element"); + "GstInputSelector", &input_selector_info, 0); + GST_DEBUG_CATEGORY_INIT (input_selector_debug, + "input-selector", 0, "An input stream selector element"); } - return stream_selector_type; + return input_selector_type; } static void -gst_stream_selector_base_init (GstStreamSelectorClass * klass) +gst_input_selector_base_init (GstInputSelectorClass * klass) { GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - gst_element_class_set_details (element_class, &gst_stream_selector_details); + gst_element_class_set_details (element_class, &gst_input_selector_details); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_stream_selector_sink_factory)); + gst_static_pad_template_get (&gst_input_selector_sink_factory)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_stream_selector_src_factory)); + gst_static_pad_template_get (&gst_input_selector_src_factory)); } static void -gst_stream_selector_class_init (GstStreamSelectorClass * klass) +gst_input_selector_class_init (GstInputSelectorClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); parent_class = g_type_class_peek_parent (klass); gobject_class->set_property = - GST_DEBUG_FUNCPTR (gst_stream_selector_set_property); + GST_DEBUG_FUNCPTR (gst_input_selector_set_property); gobject_class->get_property = - GST_DEBUG_FUNCPTR (gst_stream_selector_get_property); + GST_DEBUG_FUNCPTR (gst_input_selector_get_property); g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD, g_param_spec_string ("active-pad", "Active pad", "Name of the currently" " active sink pad", NULL, G_PARAM_READWRITE)); - gobject_class->dispose = gst_stream_selector_dispose; - gstelement_class->request_new_pad = gst_stream_selector_request_new_pad; - gstelement_class->release_pad = gst_stream_selector_release_pad; - gstelement_class->change_state = gst_stream_selector_change_state; + gobject_class->dispose = gst_input_selector_dispose; + 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; /** - * GstStreamSelector::block: - * @streamselector: the #GstStreamSelector + * GstInputSelector::block: + * @inputselector: the #GstInputSelector * * Block all sink pads in preparation for a switch. Returns the stop time of * the current switch segment, as a running time, or 0 if there is no current * active pad or the current active pad never received data. */ - gst_stream_selector_signals[SIGNAL_BLOCK] = + gst_input_selector_signals[SIGNAL_BLOCK] = g_signal_new ("block", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstStreamSelectorClass, block), - NULL, NULL, gst_switch_marshal_INT64__VOID, G_TYPE_INT64, 0); + G_STRUCT_OFFSET (GstInputSelectorClass, block), + NULL, NULL, gst_selector_marshal_INT64__VOID, G_TYPE_INT64, 0); /** - * GstStreamSelector::switch: - * @streamselector: the #GstStreamSelector + * GstInputSelector::switch: + * @inputselector: the #GstInputSelector * @pad: name of pad to switch to * @stop_time: running time at which to close the previous segment, or -1 * to use the running time of the previously active sink pad @@ -555,7 +563,7 @@ gst_stream_selector_class_init (GstStreamSelectorClass * klass) * any, will be closed, and a new segment opened before data flows again. * * This signal must be emitted when the element has been blocked via the <link - * linkend="GstStreamSelector-block">block</link> signal. + * linkend="GstInputSelector-block">block</link> signal. * * If you have a stream with only one switch element, such as an audio-only * stream, a stream switch should be performed by first emitting the block @@ -569,7 +577,7 @@ gst_stream_selector_class_init (GstStreamSelectorClass * klass) * have one switch element between the audio feeds and one for video. * * A switch over multiple switch elements should be performed as follows: - * First, emit the <link linkend="GstStreamSelector-block">block</link> + * First, emit the <link linkend="GstInputSelector-block">block</link> * signal, collecting the returned values. The maximum running time returned * by block should then be used as the time at which to close the previous * segment. @@ -582,24 +590,24 @@ gst_stream_selector_class_init (GstStreamSelectorClass * klass) * If @pad is the same as the current active pad, the element will cancel any * previous block without adjusting segments. */ - gst_stream_selector_signals[SIGNAL_SWITCH] = + gst_input_selector_signals[SIGNAL_SWITCH] = g_signal_new ("switch", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GstStreamSelectorClass, switch_), - NULL, NULL, gst_switch_marshal_VOID__STRING_INT64_INT64, + G_STRUCT_OFFSET (GstInputSelectorClass, switch_), + NULL, NULL, gst_selector_marshal_VOID__STRING_INT64_INT64, G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_INT64, G_TYPE_INT64); - klass->block = GST_DEBUG_FUNCPTR (gst_stream_selector_block); - klass->switch_ = GST_DEBUG_FUNCPTR (gst_stream_selector_switch); + klass->block = GST_DEBUG_FUNCPTR (gst_input_selector_block); + klass->switch_ = GST_DEBUG_FUNCPTR (gst_input_selector_switch); } static void -gst_stream_selector_init (GstStreamSelector * sel) +gst_input_selector_init (GstInputSelector * sel) { sel->srcpad = gst_pad_new ("src", GST_PAD_SRC); gst_pad_set_internal_link_function (sel->srcpad, - GST_DEBUG_FUNCPTR (gst_stream_selector_get_linked_pads)); + GST_DEBUG_FUNCPTR (gst_input_selector_get_linked_pads)); gst_pad_set_getcaps_function (sel->srcpad, - GST_DEBUG_FUNCPTR (gst_stream_selector_getcaps)); + GST_DEBUG_FUNCPTR (gst_input_selector_getcaps)); gst_element_add_pad (GST_ELEMENT (sel), sel->srcpad); /* sinkpad management */ sel->active_sinkpad = NULL; @@ -611,9 +619,9 @@ gst_stream_selector_init (GstStreamSelector * sel) } static void -gst_stream_selector_dispose (GObject * object) +gst_input_selector_dispose (GObject * object) { - GstStreamSelector *sel = GST_STREAM_SELECTOR (object); + GstInputSelector *sel = GST_INPUT_SELECTOR (object); if (sel->active_sinkpad) { gst_object_unref (sel->active_sinkpad); @@ -652,7 +660,7 @@ gst_segment_set_start (GstSegment * segment, gint64 running_time) } static void -gst_stream_selector_set_active_pad (GstStreamSelector * self, +gst_input_selector_set_active_pad (GstInputSelector * self, const gchar * pad_name, gint64 stop_time, gint64 start_time) { GstPad *pad; @@ -701,14 +709,14 @@ done: static void -gst_stream_selector_set_property (GObject * object, guint prop_id, +gst_input_selector_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - GstStreamSelector *sel = GST_STREAM_SELECTOR (object); + GstInputSelector *sel = GST_INPUT_SELECTOR (object); switch (prop_id) { case PROP_ACTIVE_PAD: - gst_stream_selector_set_active_pad (sel, + gst_input_selector_set_active_pad (sel, g_value_get_string (value), GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE); break; default: @@ -718,10 +726,10 @@ gst_stream_selector_set_property (GObject * object, guint prop_id, } static void -gst_stream_selector_get_property (GObject * object, guint prop_id, +gst_input_selector_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - GstStreamSelector *sel = GST_STREAM_SELECTOR (object); + GstInputSelector *sel = GST_INPUT_SELECTOR (object); switch (prop_id) { case PROP_ACTIVE_PAD:{ @@ -741,12 +749,12 @@ gst_stream_selector_get_property (GObject * object, guint prop_id, } static GstPad * -gst_stream_selector_get_linked_pad (GstPad * pad, gboolean strict) +gst_input_selector_get_linked_pad (GstPad * pad, gboolean strict) { - GstStreamSelector *sel; + GstInputSelector *sel; GstPad *otherpad = NULL; - sel = GST_STREAM_SELECTOR (gst_pad_get_parent (pad)); + sel = GST_INPUT_SELECTOR (gst_pad_get_parent (pad)); GST_OBJECT_LOCK (sel); if (pad == sel->srcpad) otherpad = sel->active_sinkpad; @@ -760,13 +768,13 @@ gst_stream_selector_get_linked_pad (GstPad * pad, gboolean strict) } static GstCaps * -gst_stream_selector_getcaps (GstPad * pad) +gst_input_selector_getcaps (GstPad * pad) { GstPad *otherpad; GstObject *parent; GstCaps *caps; - otherpad = gst_stream_selector_get_linked_pad (pad, FALSE); + otherpad = gst_input_selector_get_linked_pad (pad, FALSE); parent = gst_object_get_parent (GST_OBJECT (pad)); if (!otherpad) { GST_DEBUG_OBJECT (parent, @@ -789,7 +797,7 @@ gst_stream_selector_getcaps (GstPad * pad) /* check if the pad is the active sinkpad */ static gboolean -gst_stream_selector_is_active_sinkpad (GstStreamSelector * sel, GstPad * pad) +gst_input_selector_is_active_sinkpad (GstInputSelector * sel, GstPad * pad) { GstSelectorPad *selpad; gboolean res; @@ -805,7 +813,7 @@ gst_stream_selector_is_active_sinkpad (GstStreamSelector * sel, GstPad * pad) /* Get or create the active sinkpad */ static GstPad * -gst_stream_selector_activate_sinkpad (GstStreamSelector * sel, GstPad * pad) +gst_input_selector_activate_sinkpad (GstInputSelector * sel, GstPad * pad) { GstPad *active_sinkpad; GstSelectorPad *selpad; @@ -826,11 +834,11 @@ gst_stream_selector_activate_sinkpad (GstStreamSelector * sel, GstPad * pad) } static GList * -gst_stream_selector_get_linked_pads (GstPad * pad) +gst_input_selector_get_linked_pads (GstPad * pad) { GstPad *otherpad; - otherpad = gst_stream_selector_get_linked_pad (pad, TRUE); + otherpad = gst_input_selector_get_linked_pad (pad, TRUE); if (!otherpad) return NULL; /* need to drop the ref, internal linked pads is not MT safe */ @@ -839,14 +847,14 @@ gst_stream_selector_get_linked_pads (GstPad * pad) } static GstPad * -gst_stream_selector_request_new_pad (GstElement * element, +gst_input_selector_request_new_pad (GstElement * element, GstPadTemplate * templ, const gchar * unused) { - GstStreamSelector *sel; + GstInputSelector *sel; gchar *name = NULL; GstPad *sinkpad = NULL; - sel = GST_STREAM_SELECTOR (element); + sel = GST_INPUT_SELECTOR (element); g_return_val_if_fail (templ->direction == GST_PAD_SINK, NULL); GST_LOG_OBJECT (sel, "Creating new pad %d", sel->nb_sinkpads); GST_OBJECT_LOCK (sel); @@ -873,11 +881,11 @@ gst_stream_selector_request_new_pad (GstElement * element, } static void -gst_stream_selector_release_pad (GstElement * element, GstPad * pad) +gst_input_selector_release_pad (GstElement * element, GstPad * pad) { - GstStreamSelector *sel; + GstInputSelector *sel; - sel = GST_STREAM_SELECTOR (element); + sel = GST_INPUT_SELECTOR (element); GST_LOG_OBJECT (sel, "Releasing pad %s:%s", GST_DEBUG_PAD_NAME (pad)); GST_OBJECT_LOCK (sel); @@ -893,10 +901,10 @@ gst_stream_selector_release_pad (GstElement * element, GstPad * pad) } static GstStateChangeReturn -gst_stream_selector_change_state (GstElement * element, +gst_input_selector_change_state (GstElement * element, GstStateChange transition) { - GstStreamSelector *self = GST_STREAM_SELECTOR (element); + GstInputSelector *self = GST_INPUT_SELECTOR (element); GstStateChangeReturn result; result = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); @@ -912,7 +920,7 @@ gst_stream_selector_change_state (GstElement * element, } static gint64 -gst_stream_selector_block (GstStreamSelector * self) +gst_input_selector_block (GstInputSelector * self) { gint64 ret = 0; GstSelectorPad *spad; @@ -936,7 +944,7 @@ gst_stream_selector_block (GstStreamSelector * self) } static void -gst_stream_selector_push_pending_stop (GstStreamSelector * self) +gst_input_selector_push_pending_stop (GstInputSelector * self) { GstEvent *event = NULL; @@ -959,28 +967,15 @@ gst_stream_selector_push_pending_stop (GstStreamSelector * self) /* stop_time and start_time are running times */ static void -gst_stream_selector_switch (GstStreamSelector * self, const gchar * pad_name, +gst_input_selector_switch (GstInputSelector * self, const gchar * pad_name, gint64 stop_time, gint64 start_time) { g_return_if_fail (self->blocked == TRUE); - gst_stream_selector_set_active_pad (self, pad_name, stop_time, start_time); + gst_input_selector_set_active_pad (self, pad_name, stop_time, start_time); GST_OBJECT_LOCK (self); self->blocked = FALSE; g_cond_broadcast (self->blocked_cond); GST_OBJECT_UNLOCK (self); } - -static gboolean -plugin_init (GstPlugin * plugin) -{ - return gst_element_register (plugin, "switch", GST_RANK_NONE, - GST_TYPE_STREAM_SELECTOR); -} - -GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "switch", - "N-to-1 input switching", - plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/gst/switch/gstswitch.h b/gst/selector/gstinputselector.h index 75b20ebf..bb1a28db 100644 --- a/gst/switch/gstswitch.h +++ b/gst/selector/gstinputselector.h @@ -1,6 +1,7 @@ /* GStreamer * Copyright (C) 2003 Julien Moutte <julien@moutte.net> * Copyright (C) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net> + * Copyright (C) 2008 Nokia Corporation. (contact <stefan.kost@nokia.com>) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,28 +19,28 @@ * Boston, MA 02111-1307, USA. */ -#ifndef __GST_STREAM_SELECTOR_H__ -#define __GST_STREAM_SELECTOR_H__ +#ifndef __GST_INPUT_SELECTOR_H__ +#define __GST_INPUT_SELECTOR_H__ #include <gst/gst.h> G_BEGIN_DECLS -#define GST_TYPE_STREAM_SELECTOR \ - (gst_stream_selector_get_type()) -#define GST_STREAM_SELECTOR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_STREAM_SELECTOR, GstStreamSelector)) -#define GST_STREAM_SELECTOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_STREAM_SELECTOR, GstStreamSelectorClass)) -#define GST_IS_STREAM_SELECTOR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_STREAM_SELECTOR)) -#define GST_IS_STREAM_SELECTOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_STREAM_SELECTOR)) +#define GST_TYPE_INPUT_SELECTOR \ + (gst_input_selector_get_type()) +#define GST_INPUT_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_INPUT_SELECTOR, GstInputSelector)) +#define GST_INPUT_SELECTOR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_INPUT_SELECTOR, GstInputSelectorClass)) +#define GST_IS_INPUT_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_INPUT_SELECTOR)) +#define GST_IS_INPUT_SELECTOR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_INPUT_SELECTOR)) -typedef struct _GstStreamSelector GstStreamSelector; -typedef struct _GstStreamSelectorClass GstStreamSelectorClass; +typedef struct _GstInputSelector GstInputSelector; +typedef struct _GstInputSelectorClass GstInputSelectorClass; -struct _GstStreamSelector { +struct _GstInputSelector { GstElement element; GstPad *srcpad; @@ -55,16 +56,16 @@ struct _GstStreamSelector { GstSegment pending_stop_segment; }; -struct _GstStreamSelectorClass { +struct _GstInputSelectorClass { GstElementClass parent_class; - gint64 (*block) (GstStreamSelector *self); - void (*switch_) (GstStreamSelector *self, const gchar *pad_name, + gint64 (*block) (GstInputSelector *self); + void (*switch_) (GstInputSelector *self, const gchar *pad_name, gint64 stop_time, gint64 start_time); }; -GType gst_stream_selector_get_type (void); +GType gst_input_selector_get_type (void); G_END_DECLS -#endif /* __GST_STREAM_SELECTOR_H__ */ +#endif /* __GST_INPUT_SELECTOR_H__ */ diff --git a/gst/selector/gstoutputselector.c b/gst/selector/gstoutputselector.c new file mode 100644 index 00000000..1d1dc05a --- /dev/null +++ b/gst/selector/gstoutputselector.c @@ -0,0 +1,448 @@ +/* GStreamer + * Copyright (C) 2008 Nokia Corporation. (contact <stefan.kost@nokia.com>) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:element-output-selector + * @short_description: 1-to-N stream selectoring + * @see_also: #GstTee, #GstInputSelector + * + * Direct input stream to one out of N output pads. + */ + +/* FIXME: By default basesinks require some prerolled data before changing + to playing state. Also pipeline with output-selector connected to multiple + sink elements won't change to playing until all sink elements have received + the preroll data. Currently this can be worked around using live source element + and and exporting GST_COMPAT="no-live-preroll". +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <string.h> + +#include "gstoutputselector.h" + +GST_DEBUG_CATEGORY_STATIC (output_selector_debug); +#define GST_CAT_DEFAULT output_selector_debug + +static const GstElementDetails gst_output_selector_details = +GST_ELEMENT_DETAILS ("Output selector", + "Generic", + "1-to-N output stream selectoring", + "Stefan Kost <stefan.kost@nokia.com>"); + +static GstStaticPadTemplate gst_output_selector_sink_factory = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS_ANY); + +static GstStaticPadTemplate gst_output_selector_src_factory = +GST_STATIC_PAD_TEMPLATE ("src%d", + GST_PAD_SRC, + GST_PAD_REQUEST, + GST_STATIC_CAPS_ANY); + +enum +{ + PROP_ACTIVE_PAD = 1, + PROP_RESEND_LATEST +}; + +static void gst_output_selector_dispose (GObject * object); +static void gst_output_selector_init (GstOutputSelector * sel); +static void gst_output_selector_base_init (GstOutputSelectorClass * klass); +static void gst_output_selector_class_init (GstOutputSelectorClass * klass); +static void gst_output_selector_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec); +static void gst_output_selector_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); +static GstPad *gst_output_selector_request_new_pad (GstElement * element, + GstPadTemplate * templ, const gchar * unused); +static void gst_output_selector_release_pad (GstElement * element, + GstPad * pad); +static GstFlowReturn gst_output_selector_chain (GstPad * pad, GstBuffer * buf); +static GstStateChangeReturn gst_output_selector_change_state (GstElement * + element, GstStateChange transition); +static gboolean gst_output_selector_handle_sink_event (GstPad * pad, + GstEvent * event); + +static GstElementClass *parent_class = NULL; + +GType +gst_output_selector_get_type (void) +{ + static GType output_selector_type = 0; + + if (!output_selector_type) { + static const GTypeInfo output_selector_info = { + sizeof (GstOutputSelectorClass), + (GBaseInitFunc) gst_output_selector_base_init, + NULL, + (GClassInitFunc) gst_output_selector_class_init, + NULL, + NULL, + sizeof (GstOutputSelector), + 0, + (GInstanceInitFunc) gst_output_selector_init, + }; + output_selector_type = + g_type_register_static (GST_TYPE_ELEMENT, + "GstOutputSelector", &output_selector_info, 0); + GST_DEBUG_CATEGORY_INIT (output_selector_debug, + "output-selector", 0, "An output stream selector element"); + } + + return output_selector_type; +} + +static void +gst_output_selector_base_init (GstOutputSelectorClass * klass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + + gst_element_class_set_details (element_class, &gst_output_selector_details); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_output_selector_sink_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_output_selector_src_factory)); +} + +static void +gst_output_selector_class_init (GstOutputSelectorClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + gobject_class->set_property = + GST_DEBUG_FUNCPTR (gst_output_selector_set_property); + gobject_class->get_property = + GST_DEBUG_FUNCPTR (gst_output_selector_get_property); + g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD, + g_param_spec_string ("active-pad", "Active pad", + "Name of the currently active src pad", NULL, G_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, PROP_RESEND_LATEST, + g_param_spec_boolean ("resend-latest", "Resend latest buffer", + "Resend latest buffer after a switch to a new pad", FALSE, + G_PARAM_READWRITE)); + gobject_class->dispose = gst_output_selector_dispose; + gstelement_class->request_new_pad = + GST_DEBUG_FUNCPTR (gst_output_selector_request_new_pad); + gstelement_class->release_pad = + GST_DEBUG_FUNCPTR (gst_output_selector_release_pad); + gstelement_class->change_state = gst_output_selector_change_state; + +} + +static void +gst_output_selector_init (GstOutputSelector * sel) +{ + sel->sinkpad = + gst_pad_new_from_static_template (&gst_output_selector_sink_factory, + "sink"); + gst_pad_set_chain_function (sel->sinkpad, + GST_DEBUG_FUNCPTR (gst_output_selector_chain)); + gst_pad_set_event_function (sel->sinkpad, + GST_DEBUG_FUNCPTR (gst_output_selector_handle_sink_event)); + + gst_element_add_pad (GST_ELEMENT (sel), sel->sinkpad); + + /* + gst_pad_set_bufferalloc_function (sel->sinkpad, + GST_DEBUG_FUNCPTR (gst_output_selector_bufferalloc)); + gst_pad_set_setcaps_function (sel->sinkpad, + GST_DEBUG_FUNCPTR (gst_pad_proxy_setcaps)); + gst_pad_set_getcaps_function (sel->sinkpad, + GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps)); + */ + /* srcpad management */ + sel->active_srcpad = NULL; + sel->nb_srcpads = 0; + gst_segment_init (&sel->segment, GST_FORMAT_UNDEFINED); + sel->pending_srcpad = NULL; + + sel->resend_latest = FALSE; + sel->latest_buffer = NULL; +} + +static void +gst_output_selector_dispose (GObject * object) +{ + GstOutputSelector *osel = GST_OUTPUT_SELECTOR (object); + + if (osel->pending_srcpad != NULL) { + gst_object_unref (osel->pending_srcpad); + osel->pending_srcpad = NULL; + } + if (osel->latest_buffer != NULL) { + gst_buffer_unref (osel->latest_buffer); + osel->latest_buffer = NULL; + } + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +gst_output_selector_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstOutputSelector *sel = GST_OUTPUT_SELECTOR (object); + + switch (prop_id) { + case PROP_ACTIVE_PAD:{ + GstPad *next_pad = + gst_element_get_static_pad (GST_ELEMENT (sel), + g_value_get_string (value)); + if (next_pad && (next_pad != sel->active_srcpad)) { + /* switch to new srcpad in next chain run */ + if (sel->pending_srcpad != NULL) { + GST_INFO ("replacing pending switch"); + gst_object_unref (sel->pending_srcpad); + } + sel->pending_srcpad = next_pad; + } else { + GST_WARNING ("setting active pad failed"); + } + break; + } + case PROP_RESEND_LATEST:{ + sel->resend_latest = g_value_get_boolean (value); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_output_selector_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstOutputSelector *sel = GST_OUTPUT_SELECTOR (object); + + switch (prop_id) { + case PROP_ACTIVE_PAD:{ + GST_OBJECT_LOCK (object); + if (sel->active_srcpad != NULL) { + g_value_take_string (value, gst_pad_get_name (sel->active_srcpad)); + } else { + g_value_set_string (value, ""); + } + GST_OBJECT_UNLOCK (object); + break; + } + case PROP_RESEND_LATEST:{ + GST_OBJECT_LOCK (object); + g_value_set_boolean (value, sel->resend_latest); + GST_OBJECT_UNLOCK (object); + break; + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GstPad * +gst_output_selector_request_new_pad (GstElement * element, + GstPadTemplate * templ, const gchar * name) +{ + gchar *padname; + GstPad *srcpad; + GstOutputSelector *osel; + + osel = GST_OUTPUT_SELECTOR (element); + + GST_DEBUG_OBJECT (osel, "requesting pad"); + + GST_OBJECT_LOCK (osel); + padname = g_strdup_printf ("src%d", osel->nb_srcpads++); + srcpad = gst_pad_new_from_template (templ, padname); + GST_OBJECT_UNLOCK (osel); + + gst_pad_set_active (srcpad, TRUE); + gst_element_add_pad (GST_ELEMENT (osel), srcpad); + + /* Set the first requested src pad as active by default */ + if (osel->active_srcpad == NULL) { + osel->active_srcpad = srcpad; + } + g_free (padname); + + return srcpad; +} + +static void +gst_output_selector_release_pad (GstElement * element, GstPad * pad) +{ + GstOutputSelector *osel; + + osel = GST_OUTPUT_SELECTOR (element); + + GST_DEBUG_OBJECT (osel, "releasing pad"); + + gst_pad_set_active (pad, FALSE); + + gst_element_remove_pad (GST_ELEMENT_CAST (osel), pad); +} + +static gboolean +gst_output_selector_switch (GstOutputSelector * osel) +{ + gboolean res = TRUE; + GstEvent *ev = NULL; + GstSegment *seg = NULL; + gint64 start = 0, position = 0; + + GST_INFO ("switching to pad %" GST_PTR_FORMAT, osel->pending_srcpad); + + if (gst_pad_is_linked (osel->pending_srcpad)) { + /* Send NEWSEGMENT to the pad we are going to switch to */ + seg = &osel->segment; + /* If resending then mark newsegment start and position accordingly */ + if (osel->resend_latest && osel->latest_buffer && + GST_BUFFER_TIMESTAMP_IS_VALID (osel->latest_buffer)) { + start = position = GST_BUFFER_TIMESTAMP (osel->latest_buffer); + } else { + start = position = seg->last_stop; + } + ev = gst_event_new_new_segment (TRUE, seg->rate, + seg->format, start, seg->stop, position); + if (!gst_pad_push_event (osel->pending_srcpad, ev)) { + GST_WARNING ("newsegment handling failed in %" GST_PTR_FORMAT, + osel->pending_srcpad); + } + + /* Resend latest buffer to newly switched pad */ + if (osel->resend_latest && osel->latest_buffer) { + GST_INFO ("resending latest buffer"); + gst_pad_push (osel->pending_srcpad, osel->latest_buffer); + osel->latest_buffer = NULL; + } + + /* Switch */ + osel->active_srcpad = osel->pending_srcpad; + } else { + GST_WARNING ("switch failed, pad not linked"); + res = FALSE; + } + + gst_object_unref (osel->pending_srcpad); + osel->pending_srcpad = NULL; + + return res; +} + +static GstFlowReturn +gst_output_selector_chain (GstPad * pad, GstBuffer * buf) +{ + GstFlowReturn res; + GstOutputSelector *osel; + GstClockTime last_stop, duration; + + osel = GST_OUTPUT_SELECTOR (gst_pad_get_parent (pad)); + + if (osel->pending_srcpad) { + /* Do the switch */ + gst_output_selector_switch (osel); + } + + /* Keep reference to latest buffer to resend it after switch */ + if (osel->resend_latest) { + if (osel->latest_buffer) + gst_buffer_unref (osel->latest_buffer); + osel->latest_buffer = gst_buffer_ref (buf); + } + + /* Keep track of last stop and use it in NEWSEGMENT start after + switching to a new src pad */ + last_stop = GST_BUFFER_TIMESTAMP (buf); + if (GST_CLOCK_TIME_IS_VALID (last_stop)) { + duration = GST_BUFFER_DURATION (buf); + if (GST_CLOCK_TIME_IS_VALID (duration)) { + last_stop += duration; + } + GST_LOG ("setting last stop %" GST_TIME_FORMAT, GST_TIME_ARGS (last_stop)); + gst_segment_set_last_stop (&osel->segment, osel->segment.format, last_stop); + } + + GST_LOG ("pushing buffer to %" GST_PTR_FORMAT, osel->active_srcpad); + res = gst_pad_push (osel->active_srcpad, buf); + gst_object_unref (osel); + + return res; +} + +static GstStateChangeReturn +gst_output_selector_change_state (GstElement * element, + GstStateChange transition) +{ + return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); +} + +static gboolean +gst_output_selector_handle_sink_event (GstPad * pad, GstEvent * event) +{ + gboolean res = TRUE; + GstOutputSelector *sel; + + sel = GST_OUTPUT_SELECTOR (gst_pad_get_parent (pad)); + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_NEWSEGMENT: + { + 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 ("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_segment_set_newsegment_full (&sel->segment, update, + rate, arate, format, start, stop, time); + + /* Send newsegment to all src pads */ + gst_pad_event_default (pad, event); + + break; + } + case GST_EVENT_EOS: + /* Send eos to all src pads */ + gst_pad_event_default (pad, event); + break; + default: + /* Send other events to active src pad */ + res = gst_pad_push_event (sel->active_srcpad, event); + break; + } + + gst_object_unref (sel); + + return res; +} diff --git a/gst/selector/gstoutputselector.h b/gst/selector/gstoutputselector.h new file mode 100644 index 00000000..5389d473 --- /dev/null +++ b/gst/selector/gstoutputselector.h @@ -0,0 +1,66 @@ +/* GStreamer + * Copyright (C) 2008 Nokia Corporation. (contact <stefan.kost@nokia.com>) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_OUTPUT_SELECTOR_H__ +#define __GST_OUTPUT_SELECTOR_H__ + +#include <gst/gst.h> + +G_BEGIN_DECLS + +#define GST_TYPE_OUTPUT_SELECTOR \ + (gst_output_selector_get_type()) +#define GST_OUTPUT_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_OUTPUT_SELECTOR, GstOutputSelector)) +#define GST_OUTPUT_SELECTOR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_OUTPUT_SELECTOR, GstOutputSelectorClass)) +#define GST_IS_OUTPUT_SELECTOR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_OUTPUT_SELECTOR)) +#define GST_IS_OUTPUT_SELECTOR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_OUTPUT_SELECTOR)) + +typedef struct _GstOutputSelector GstOutputSelector; +typedef struct _GstOutputSelectorClass GstOutputSelectorClass; + +struct _GstOutputSelector { + GstElement element; + + GstPad *sinkpad; + + GstPad *active_srcpad; + GstPad *pending_srcpad; + guint nb_srcpads; + + GstSegment segment; + + /* resend latest buffer after switch */ + gboolean resend_latest; + GstBuffer *latest_buffer; + +}; + +struct _GstOutputSelectorClass { + GstElementClass parent_class; +}; + +GType gst_output_selector_get_type (void); + +G_END_DECLS + +#endif /* __GST_OUTPUT_SELECTOR_H__ */ diff --git a/gst/switch/gstswitch-marshal.list b/gst/selector/gstselector-marshal.list index 97c741cb..97c741cb 100644 --- a/gst/switch/gstswitch-marshal.list +++ b/gst/selector/gstselector-marshal.list diff --git a/gst/selector/gstselector.c b/gst/selector/gstselector.c new file mode 100644 index 00000000..008e4575 --- /dev/null +++ b/gst/selector/gstselector.c @@ -0,0 +1,44 @@ +/* GStreamer + * Copyright (C) 2008 Nokia Corporation. (contact <stefan.kost@nokia.com>) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gst/gst.h> + +#include "gstinputselector.h" +#include "gstoutputselector.h" + + +static gboolean +plugin_init (GstPlugin * plugin) +{ + + return gst_element_register (plugin, "input-selector", + GST_RANK_NONE, GST_TYPE_INPUT_SELECTOR) && + gst_element_register (plugin, "output-selector", + GST_RANK_NONE, GST_TYPE_OUTPUT_SELECTOR); +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "selector", + "input/output stream selector elements", + plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/gst/switch/switch.vcproj b/gst/selector/selector.vcproj index 472d909e..f28880d7 100644 --- a/gst/switch/switch.vcproj +++ b/gst/selector/selector.vcproj @@ -2,7 +2,7 @@ <VisualStudioProject ProjectType="Visual C++" Version="7.10" - Name="switch" + Name="selector" ProjectGUID="{979C216F-0ACF-4956-AE00-055A42D678CF}" Keyword="Win32Proj"> <Platforms> @@ -20,7 +20,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="../../../gstreamer/win32;../../../gstreamer;../../../gstreamer/libs;../../../glib;../../../glib/glib;../../../glib/gmodule;"../../gst-libs";../../../popt/include;../../../libxml2/include/libxml2" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;switch_EXPORTS;HAVE_CONFIG_H;_USE_MATH_DEFINES" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;selector_EXPORTS;HAVE_CONFIG_H;_USE_MATH_DEFINES" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -33,15 +33,15 @@ <Tool Name="VCLinkerTool" AdditionalDependencies="glib-2.0.lib gmodule-2.0.lib gthread-2.0.lib gobject-2.0.lib libgstreamer.lib gstbytestream.lib iconv.lib intl.lib" - OutputFile="$(OutDir)/gstswitch.dll" + OutputFile="$(OutDir)/gstselector.dll" LinkIncremental="2" AdditionalLibraryDirectories="../../../gstreamer/win32/Debug;../../../glib/glib;../../../glib/gmodule;../../../glib/gthread;../../../glib/gobject;../../../gettext/lib;../../../libiconv/lib" ModuleDefinitionFile="" GenerateDebugInformation="TRUE" - ProgramDatabaseFile="$(OutDir)/switch.pdb" + ProgramDatabaseFile="$(OutDir)/selectro.pdb" SubSystem="2" OptimizeReferences="2" - ImportLibrary="$(OutDir)/gstswitch.lib" + ImportLibrary="$(OutDir)/gstselectro.lib" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> @@ -74,7 +74,7 @@ <Tool Name="VCCLCompilerTool" AdditionalIncludeDirectories="../../../gstreamer/win32;../../../gstreamer;../../../gstreamer/libs;../../../glib;../../../glib/glib;../../../glib/gmodule;"../../gst-libs";../../../popt/include;../../../libxml2/include/libxml2" - PreprocessorDefinitions="WIN32;NDEBUG;GST_DISABLE_GST_DEBUG;_WINDOWS;_USRDLL;switch_EXPORTS;HAVE_CONFIG_H;_USE_MATH_DEFINES" + PreprocessorDefinitions="WIN32;NDEBUG;GST_DISABLE_GST_DEBUG;_WINDOWS;_USRDLL;selector_EXPORTS;HAVE_CONFIG_H;_USE_MATH_DEFINES" RuntimeLibrary="2" UsePrecompiledHeader="0" WarningLevel="3" @@ -85,7 +85,7 @@ <Tool Name="VCLinkerTool" AdditionalDependencies="glib-2.0.lib gmodule-2.0.lib gthread-2.0.lib gobject-2.0.lib libgstreamer.lib gstbytestream.lib iconv.lib intl.lib" - OutputFile="$(OutDir)/gstswitch.dll" + OutputFile="$(OutDir)/gstselector.dll" LinkIncremental="1" AdditionalLibraryDirectories="../../../gstreamer/win32/Release;../../../glib/glib;../../../glib/gmodule;../../../glib/gthread;../../../glib/gobject;../../../gettext/lib;../../../libiconv/lib" ModuleDefinitionFile="" @@ -93,7 +93,7 @@ SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" - ImportLibrary="$(OutDir)/gstswitch.lib" + ImportLibrary="$(OutDir)/gstselector.lib" TargetMachine="1"/> <Tool Name="VCMIDLTool"/> @@ -126,7 +126,7 @@ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> <File - RelativePath=".\gstswitch.c"> + RelativePath=".\gstselector.c"> </File> </Filter> <Filter @@ -134,7 +134,7 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> <File - RelativePath=".\gstswitch.h"> + RelativePath=".\gstselector.h"> </File> </Filter> <Filter diff --git a/gst/switch/.gitignore b/gst/switch/.gitignore deleted file mode 100644 index 3acdd44e..00000000 --- a/gst/switch/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -gstswitch-marshal.c -gstswitch-marshal.h diff --git a/gst/switch/Makefile.am b/gst/switch/Makefile.am deleted file mode 100644 index b829095d..00000000 --- a/gst/switch/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -glib_enum_prefix = gst_switch - -include $(top_srcdir)/common/glib-gen.mak - -built_sources = gstswitch-marshal.c -built_headers = gstswitch-marshal.h - -BUILT_SOURCES = $(built_sources) $(built_headers) - -CLEANFILES = $(BUILT_SOURCES) - -EXTRA_DIST = gstswitch-marshal.list - -plugin_LTLIBRARIES = libgstswitch.la - -libgstswitch_la_SOURCES = gstswitch.c -nodist_libgstswitch_la_SOURCES = $(built_sources) -libgstswitch_la_CFLAGS = $(GST_CFLAGS) -libgstswitch_la_LIBADD = -libgstswitch_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) - -noinst_HEADERS = gstswitch.h $(built_headers) |