PROP_LAST
};
+GST_BOILERPLATE (GstOutputSelector, gst_output_selector, GstElement,
+ GST_TYPE_ELEMENT);
+
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,
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)
+gst_output_selector_base_init (gpointer g_class)
{
- GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+ GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details (element_class, &gst_output_selector_details);
gst_element_class_add_pad_template (element_class,
g_object_class_install_property (gobject_class, PROP_ACTIVE_PAD,
g_param_spec_object ("active-pad", "Active pad",
- "Name of the currently active src pad", GST_TYPE_PAD,
- G_PARAM_READWRITE));
+ "Currently active src pad", GST_TYPE_PAD, 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,
GST_DEBUG_FUNCPTR (gst_output_selector_release_pad);
gstelement_class->change_state = gst_output_selector_change_state;
+
+ GST_DEBUG_CATEGORY_INIT (output_selector_debug,
+ "output-selector", 0, "An output stream selector element");
}
static void
-gst_output_selector_init (GstOutputSelector * sel)
+gst_output_selector_init (GstOutputSelector * sel,
+ GstOutputSelectorClass * g_class)
{
sel->sinkpad =
gst_pad_new_from_static_template (&gst_output_selector_sink_factory,
next_pad = g_value_get_object (value);
- GST_LOG ("Activating pad %s:%s", GST_DEBUG_PAD_NAME (next_pad));
+ GST_LOG_OBJECT (sel, "Activating pad %s:%s",
+ GST_DEBUG_PAD_NAME (next_pad));
GST_OBJECT_LOCK (object);
if (next_pad != sel->active_srcpad) {
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,
+ GST_WARNING_OBJECT (osel,
+ "newsegment handling failed in %" GST_PTR_FORMAT,
osel->pending_srcpad);
}
/* Switch */
osel->active_srcpad = osel->pending_srcpad;
} else {
- GST_WARNING ("switch failed, pad not linked");
+ GST_WARNING_OBJECT (osel, "switch failed, pad not linked");
res = FALSE;
}
if (GST_CLOCK_TIME_IS_VALID (duration)) {
last_stop += duration;
}
- GST_LOG ("setting last stop %" GST_TIME_FORMAT, GST_TIME_ARGS (last_stop));
+ GST_LOG_OBJECT (osel, "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);
+ GST_LOG_OBJECT (osel, "pushing buffer to %" GST_PTR_FORMAT,
+ osel->active_srcpad);
res = gst_pad_push (osel->active_srcpad, buf);
gst_object_unref (osel);
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 %"
+ GST_DEBUG_OBJECT (sel,
+ "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,
#include <gst/gst.h>
-//[.. my_bus_callback goes here ..]
+#define SWITCH_TIMEOUT 1000
+#define NUM_VIDEO_BUFFERS 500
static GMainLoop *loop;
+/* Output selector src pads */
+static GstPad *osel_src1 = NULL;
+static GstPad *osel_src2 = NULL;
+
static gboolean
my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
{
static gboolean
switch_cb (gpointer user_data)
{
-
GstElement *sel = GST_ELEMENT (user_data);
- gchar *old_pad_name, *new_pad_name;
+ GstPad *old_pad, *new_pad = NULL;
- g_object_get (G_OBJECT (sel), "active-pad", &old_pad_name, NULL);
+ g_object_get (G_OBJECT (sel), "active-pad", &old_pad, NULL);
- if (g_str_equal (old_pad_name, "src0"))
- new_pad_name = "src1";
+ if (old_pad == osel_src1)
+ new_pad = osel_src2;
else
- new_pad_name = "src0";
+ new_pad = osel_src1;
+
+ g_object_set (G_OBJECT (sel), "active-pad", new_pad, NULL);
- g_object_set (G_OBJECT (sel), "active-pad", new_pad_name, NULL);
+ g_print ("switched from %s:%s to %s:%s\n", GST_DEBUG_PAD_NAME (old_pad),
+ GST_DEBUG_PAD_NAME (new_pad));
- g_print ("switched from %s to %s\n", old_pad_name, new_pad_name);
- g_free (old_pad_name);
+ gst_object_unref (old_pad);
return TRUE;
main (gint argc, gchar * argv[])
{
GstElement *pipeline, *src, *toverlay, *osel, *sink1, *sink2, *convert;
- GstPad *osel_src1, *osel_src2, *sinkpad;
+ GstPad *sinkpad;
GstBus *bus;
/* init GStreamer */
/* set properties */
g_object_set (G_OBJECT (src), "is-live", TRUE, NULL);
g_object_set (G_OBJECT (src), "do-timestamp", TRUE, NULL);
- g_object_set (G_OBJECT (src), "num-buffers", 500, NULL);
+ g_object_set (G_OBJECT (src), "num-buffers", NUM_VIDEO_BUFFERS, NULL);
g_object_set (G_OBJECT (sink1), "sync", FALSE, "async", FALSE, NULL);
g_object_set (G_OBJECT (sink2), "sync", FALSE, "async", FALSE, NULL);
g_object_set (G_OBJECT (osel), "resend-latest", TRUE, NULL);
}
/* add switch callback */
- g_timeout_add (1000, switch_cb, osel);
+ g_timeout_add (SWITCH_TIMEOUT, switch_cb, osel);
/* change to playing */
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));