# HG changeset patch # User renatofilho # Date 1181841713 -3600 # Node ID b7f71ba285da1c7504771dfaecc6be414bef0b19 # Parent 3cf3c6019e3b49f41424cbfaa1bd1272c58deae5 [svn r758] fixed indent using GNU Style diff -r 3cf3c6019e3b -r b7f71ba285da gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Thu Jun 14 18:21:08 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Thu Jun 14 18:21:53 2007 +0100 @@ -21,1020 +21,1045 @@ struct _SetupInfo { - gchar* video_encode; - gchar* mux_name; - gchar** video_encode_prop; - gdouble video_fps; - gdouble video_rate; - guint video_width; - guint video_height; - gchar* audio_encode; - gchar** audio_encode_prop; - guint audio_rate; + gchar *video_encode; + gchar *mux_name; + gchar **video_encode_prop; + gdouble video_fps; + gdouble video_rate; + guint video_width; + guint video_height; + gchar *audio_encode; + gchar **audio_encode_prop; + guint audio_rate; }; struct _GMencoderPrivate { - GstElement *pipe; - GstElement *abin; - GstElement *vbin; - GstElement *sink; - GstElement *src; - gboolean ready; - SetupInfo *info; - GstClockTime videot; - GstClockTime audiot; - gint fd; - gint sources; - gint tick_id; - gint64 duration; + GstElement *pipe; + GstElement *abin; + GstElement *vbin; + GstElement *sink; + GstElement *src; + gboolean ready; + SetupInfo *info; + GstClockTime videot; + GstClockTime audiot; + gint fd; + gint sources; + gint tick_id; + gint64 duration; }; -enum { - PAUSED, - PLAYING, - STOPED, - EOS, - ERROR, - LAST_SIGNAL +enum +{ + PAUSED, + PLAYING, + STOPED, + EOS, + ERROR, + LAST_SIGNAL }; -static void g_mencoder_class_init (GMencoderClass *klass); -static void g_mencoder_init (GMencoder *object); -static void g_mencoder_dispose (GObject *object); -static void g_mencoder_finalize (GObject *object); -static GstElement* -_create_audio_bin (const gchar* encode, - gchar** encode_prop, - gint rate); -static GstElement* -_create_video_bin (const gchar* encode, - gchar** encode_prop, - gdouble fps, - gint rate, - guint width, - guint height); +static void g_mencoder_class_init(GMencoderClass * klass); +static void g_mencoder_init(GMencoder * object); +static void g_mencoder_dispose(GObject * object); +static void g_mencoder_finalize(GObject * object); +static GstElement *_create_audio_bin(const gchar * encode, + gchar ** encode_prop, gint rate); +static GstElement *_create_video_bin(const gchar * encode, + gchar ** encode_prop, + gdouble fps, + gint rate, guint width, guint height); static gboolean -_pipeline_bus_cb (GstBus *bus, - GstMessage *msg, - gpointer user_data); +_pipeline_bus_cb(GstBus * bus, GstMessage * msg, gpointer user_data); -static void _decodebin_new_pad_cb (GstElement* object, - GstPad* pad, - gboolean flag, - gpointer user_data); +static void _decodebin_new_pad_cb(GstElement * object, + GstPad * pad, + gboolean flag, gpointer user_data); -static void _decodebin_unknown_type_cb (GstElement* object, - GstPad* pad, - GstCaps* caps, - gpointer user_data); +static void _decodebin_unknown_type_cb(GstElement * object, + GstPad * pad, + GstCaps * caps, gpointer user_data); -static void _close_output (GMencoder *self); -static void _open_output (GMencoder *self, - const gchar* uri); +static void _close_output(GMencoder * self); +static void _open_output(GMencoder * self, const gchar * uri); -static GstElement* _create_source (const gchar* uri); -static GstElement*_create_pipeline (GMencoder *self, - const gchar* video_encode, - const gchar* mux_name, - gchar** video_encode_prop, - gdouble video_fps, - gdouble video_rate, - guint video_width, - guint video_height, - const gchar* audio_encode, - gchar** audio_encode_prop, - guint audio_rate); +static GstElement *_create_source(const gchar * uri); +static GstElement *_create_pipeline(GMencoder * self, + const gchar * video_encode, + const gchar * mux_name, + gchar ** video_encode_prop, + gdouble video_fps, + gdouble video_rate, + guint video_width, + guint video_height, + const gchar * audio_encode, + gchar ** audio_encode_prop, + guint audio_rate); -static gboolean _tick_cb (gpointer data); +static gboolean _tick_cb(gpointer data); static guint g_mencoder_signals[LAST_SIGNAL] = { 0 }; G_DEFINE_TYPE(GMencoder, g_mencoder, G_TYPE_OBJECT) + static void g_mencoder_class_init(GMencoderClass * klass) +{ + GObjectClass *object_class; + object_class = (GObjectClass *) klass; + g_type_class_add_private(klass, sizeof(GMencoderPrivate)); -static void -g_mencoder_class_init (GMencoderClass *klass) -{ - GObjectClass *object_class; - object_class = (GObjectClass *) klass; - g_type_class_add_private (klass, sizeof (GMencoderPrivate)); + object_class->dispose = g_mencoder_dispose; + object_class->finalize = g_mencoder_finalize; - object_class->dispose = g_mencoder_dispose; - object_class->finalize = g_mencoder_finalize; + g_mencoder_signals[PAUSED] = + g_signal_new("paused", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - g_mencoder_signals[PAUSED] = - g_signal_new ("paused", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); + g_mencoder_signals[PLAYING] = + g_signal_new("playing", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - g_mencoder_signals[PLAYING] = - g_signal_new ("playing", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); + g_mencoder_signals[STOPED] = + g_signal_new("stoped", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - g_mencoder_signals[STOPED] = - g_signal_new ("stoped", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); + g_mencoder_signals[EOS] = + g_signal_new("eos", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - g_mencoder_signals[EOS] = - g_signal_new ("eos", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - g_mencoder_signals[ERROR] = - g_signal_new ("error", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); + g_mencoder_signals[ERROR] = + g_signal_new("error", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); } static void -g_mencoder_init (GMencoder *self) +g_mencoder_init(GMencoder * self) { - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); - priv->info = g_new0 (SetupInfo, 1); + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); + priv->info = g_new0(SetupInfo, 1); } static void -g_mencoder_dispose (GObject *object) +g_mencoder_dispose(GObject * object) { } static void -g_mencoder_finalize (GObject *object) +g_mencoder_finalize(GObject * object) { - //TODO: clear vars - g_mencoder_close_stream (G_MENCODER (object)); + //TODO: clear vars + g_mencoder_close_stream(G_MENCODER(object)); } -GMencoder* -g_mencoder_new (void) +GMencoder * +g_mencoder_new(void) { - return g_object_new (G_TYPE_MENCODER, NULL); + return g_object_new(G_TYPE_MENCODER, NULL); } static void -_obj_set_prop (GObject *obj, - const gchar *prop_name, - const gchar *prop_val) +_obj_set_prop(GObject * obj, const gchar * prop_name, const gchar * prop_val) { - GValue p = {0}; - GValue v = {0}; - GParamSpec *s = NULL; - GObjectClass *k = G_OBJECT_GET_CLASS (obj); + GValue p = { 0 }; + GValue v = { 0 }; + GParamSpec *s = NULL; + GObjectClass *k = G_OBJECT_GET_CLASS(obj); - g_value_init (&v, G_TYPE_STRING); - g_value_set_string (&v, prop_val); + g_value_init(&v, G_TYPE_STRING); + g_value_set_string(&v, prop_val); - s = g_object_class_find_property (k, prop_name); - if (s == NULL) { - g_print ("Invalid property name: %s\n", prop_name); - return; - } + s = g_object_class_find_property(k, prop_name); + if (s == NULL) + { + g_print("Invalid property name: %s\n", prop_name); + return; + } - g_value_init (&p, s->value_type); - switch (s->value_type) - { - case G_TYPE_INT: - g_value_set_int (&p, atoi (prop_val)); - break; - case G_TYPE_STRING: - g_value_set_string (&p, prop_val); - break; - default: - return; - } + g_value_init(&p, s->value_type); + switch (s->value_type) + { + case G_TYPE_INT: + g_value_set_int(&p, atoi(prop_val)); + break; + case G_TYPE_STRING: + g_value_set_string(&p, prop_val); + break; + default: + return; + } - g_object_set_property (obj, prop_name, &p); - g_value_unset (&v); - g_value_unset (&p); + g_object_set_property(obj, prop_name, &p); + g_value_unset(&v); + g_value_unset(&p); } -static GstElement* -_create_element_with_prop (const gchar* factory_name, - const gchar* element_name, - gchar** prop) +static GstElement * +_create_element_with_prop(const gchar * factory_name, + const gchar * element_name, gchar ** prop) { - GstElement *ret; - int i; + GstElement *ret; + int i; - ret = gst_element_factory_make (factory_name, element_name); - if (ret == NULL) - return NULL; + ret = gst_element_factory_make(factory_name, element_name); + if (ret == NULL) + return NULL; - if (prop != NULL) { - for (i=0; i < g_strv_length (prop); i++) { - if (prop[i] != NULL) { - char** v = g_strsplit(prop[i], "=", 2); - if (g_strv_length (v) == 2) { - _obj_set_prop (G_OBJECT (ret), v[0], v[1]); - } - g_strfreev (v); - } - } - } + if (prop != NULL) + { + for (i = 0; i < g_strv_length(prop); i++) + { + if (prop[i] != NULL) + { + char **v = g_strsplit(prop[i], "=", 2); + if (g_strv_length(v) == 2) + { + _obj_set_prop(G_OBJECT(ret), v[0], v[1]); + } + g_strfreev(v); + } + } + } - return ret; + return ret; } -static GstElement* -_create_audio_bin (const gchar* encode, - gchar** encode_prop, - gint rate) +static GstElement * +_create_audio_bin(const gchar * encode, gchar ** encode_prop, gint rate) { - GstElement *abin = NULL; - GstElement *aqueue = NULL; - GstElement *aconvert = NULL; - GstElement *aencode = NULL; - GstElement *aqueue_src = NULL; - GstPad *apad = NULL; + GstElement *abin = NULL; + GstElement *aqueue = NULL; + GstElement *aconvert = NULL; + GstElement *aencode = NULL; + GstElement *aqueue_src = NULL; + GstPad *apad = NULL; - //audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=upd_audio host=224.0.0.1 port=5002 - abin = gst_bin_new ("abin"); - aqueue = gst_element_factory_make ("queue", "aqueue"); - aconvert= gst_element_factory_make ("audioconvert", "aconvert"); - aencode = _create_element_with_prop ((encode ? encode : "lame"), "aencode", encode_prop); - aqueue_src= gst_element_factory_make ("queue", "aqueue_src"); + //audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=upd_audio host=224.0.0.1 port=5002 + abin = gst_bin_new("abin"); + aqueue = gst_element_factory_make("queue", "aqueue"); + aconvert = gst_element_factory_make("audioconvert", "aconvert"); + aencode = + _create_element_with_prop((encode ? encode : "lame"), "aencode", + encode_prop); + aqueue_src = gst_element_factory_make("queue", "aqueue_src"); - if ((abin == NULL) || (aqueue == NULL) || (aconvert == NULL) - || (aencode == NULL) || (aqueue_src == NULL)) { - g_warning ("Audio elements not found"); - goto error; + if ((abin == NULL) || (aqueue == NULL) || (aconvert == NULL) + || (aencode == NULL) || (aqueue_src == NULL)) + { + g_warning("Audio elements not found"); + goto error; + } + + g_object_set(G_OBJECT(aencode), "bitrate", 32, NULL); + /* + if (rate > 0) { + g_object_set (G_OBJECT (aencode), "bitrate", 32, NULL); } + */ - g_object_set (G_OBJECT (aencode), "bitrate", 32, NULL); - /* - if (rate > 0) { - g_object_set (G_OBJECT (aencode), "bitrate", 32, NULL); - } - */ + gst_bin_add_many(GST_BIN(abin), aqueue, aconvert, aencode, aqueue_src, + NULL); + if (gst_element_link_many(aqueue, aconvert, aencode, aqueue_src, NULL) == + FALSE) + { + g_warning("Not Link audio elements"); + } - gst_bin_add_many (GST_BIN (abin), aqueue, aconvert, aencode, aqueue_src, NULL); - if (gst_element_link_many (aqueue, aconvert, aencode, aqueue_src, NULL) == FALSE) { - g_warning ("Not Link audio elements"); - } + //TODO: apply audio rate - //TODO: apply audio rate + // ghost pad the audio bin + apad = gst_element_get_pad(aqueue, "sink"); + gst_element_add_pad(abin, gst_ghost_pad_new("sink", apad)); + gst_object_unref(apad); - // ghost pad the audio bin - apad = gst_element_get_pad (aqueue, "sink"); - gst_element_add_pad (abin, gst_ghost_pad_new("sink", apad)); - gst_object_unref (apad); + apad = gst_element_get_pad(aqueue_src, "src"); + gst_element_add_pad(abin, gst_ghost_pad_new("src", apad)); + gst_object_unref(apad); - apad = gst_element_get_pad (aqueue_src, "src"); - gst_element_add_pad (abin, gst_ghost_pad_new("src", apad)); - gst_object_unref (apad); + return abin; +error: + if (abin != NULL) + gst_object_unref(abin); - return abin; - error: - if (abin != NULL) - gst_object_unref (abin); + if (aqueue != NULL) + gst_object_unref(aqueue); - if (aqueue != NULL) - gst_object_unref (aqueue); + if (aconvert != NULL) + gst_object_unref(aconvert); - if (aconvert != NULL) - gst_object_unref (aconvert); + if (aencode != NULL) + gst_object_unref(aencode); - if (aencode != NULL) - gst_object_unref (aencode); + if (aqueue_src != NULL) + gst_object_unref(aqueue_src); - if (aqueue_src != NULL) - gst_object_unref (aqueue_src); + if (apad != NULL) + gst_object_unref(apad); - if (apad != NULL) - gst_object_unref (apad); - - return NULL; + return NULL; } //queue ! videoscale ! video/x-raw-yuv,width=240,height=144 ! colorspace ! rate ! encode ! queue -static GstElement* -_create_video_bin (const gchar* encode, - gchar** encode_prop, - gdouble fps, - gint rate, - guint width, - guint height) +static GstElement * +_create_video_bin(const gchar * encode, + gchar ** encode_prop, + gdouble fps, gint rate, guint width, guint height) { - GstElement *vbin = NULL; - GstElement *vqueue = NULL; - GstElement* vqueue_src = NULL; - GstElement *vcolorspace = NULL; - GstElement *vencode = NULL; - GstElement *vrate = NULL; - GstPad *vpad = NULL; + GstElement *vbin = NULL; + GstElement *vqueue = NULL; + GstElement *vqueue_src = NULL; + GstElement *vcolorspace = NULL; + GstElement *vencode = NULL; + GstElement *vrate = NULL; + GstPad *vpad = NULL; - vbin = gst_bin_new ("vbin"); - vqueue = gst_element_factory_make ("queue", "vqueue"); - vcolorspace = gst_element_factory_make ("ffmpegcolorspace", "colorspace"); + vbin = gst_bin_new("vbin"); + vqueue = gst_element_factory_make("queue", "vqueue"); + vcolorspace = gst_element_factory_make("ffmpegcolorspace", "colorspace"); - vencode = _create_element_with_prop ( - (encode != NULL ? encode : "ffenc_mpeg1video"), - "vencode", encode_prop); - vqueue_src = gst_element_factory_make ("queue", "queue_src"); + vencode = _create_element_with_prop((encode != + NULL ? encode : "ffenc_mpeg1video"), + "vencode", encode_prop); + vqueue_src = gst_element_factory_make("queue", "queue_src"); - if ((vbin == NULL) || (vqueue == NULL) || (vcolorspace == NULL) - || (vencode == NULL) || (vqueue_src == NULL)) { - g_warning ("Video elements not found"); - goto error; - } + if ((vbin == NULL) || (vqueue == NULL) || (vcolorspace == NULL) + || (vencode == NULL) || (vqueue_src == NULL)) + { + g_warning("Video elements not found"); + goto error; + } - gst_bin_add_many (GST_BIN (vbin), vqueue, vcolorspace, vencode, vqueue_src, NULL); + gst_bin_add_many(GST_BIN(vbin), vqueue, vcolorspace, vencode, vqueue_src, + NULL); - if ((width > 0) && (height > 0)) { - //Scalling video - GstCaps *vcaps; - GstElement *vscale = gst_element_factory_make ("videoscale", "vscale"); + if ((width > 0) && (height > 0)) + { + //Scalling video + GstCaps *vcaps; + GstElement *vscale = gst_element_factory_make("videoscale", "vscale"); - gst_bin_add (GST_BIN (vbin), vscale); + gst_bin_add(GST_BIN(vbin), vscale); - vcaps = gst_caps_new_simple ("video/x-raw-yuv", - "width", G_TYPE_INT, width, - "height", G_TYPE_INT, height, - NULL); + vcaps = gst_caps_new_simple("video/x-raw-yuv", + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, NULL); - gst_element_link (vqueue, vscale); + gst_element_link(vqueue, vscale); - if (gst_element_link_filtered (vscale, vcolorspace, vcaps) == FALSE) { - g_warning ("Fail to resize video"); - gst_object_unref (vcaps); - gst_object_unref (vscale); - goto error; - } - gst_caps_unref (vcaps); - } else { - gst_element_link (vqueue, vcolorspace); - } + if (gst_element_link_filtered(vscale, vcolorspace, vcaps) == FALSE) + { + g_warning("Fail to resize video"); + gst_object_unref(vcaps); + gst_object_unref(vscale); + goto error; + } + gst_caps_unref(vcaps); + } + else + { + gst_element_link(vqueue, vcolorspace); + } - if (fps > 0) { - //Changing the video fps - GstCaps *vcaps; - vrate = gst_element_factory_make ("videorate", "vrate"); + if (fps > 0) + { + //Changing the video fps + GstCaps *vcaps; + vrate = gst_element_factory_make("videorate", "vrate"); - gst_bin_add (GST_BIN (vbin), vrate); + gst_bin_add(GST_BIN(vbin), vrate); - if (gst_element_link (vcolorspace, vrate) == FALSE) { - g_warning ("Fail to link video elements"); - goto error; - } + if (gst_element_link(vcolorspace, vrate) == FALSE) + { + g_warning("Fail to link video elements"); + goto error; + } - vcaps = gst_caps_new_simple ("video/x-raw-yuv", - "framerate", GST_TYPE_FRACTION, (int) (fps * 1000), 1000, NULL); + vcaps = gst_caps_new_simple("video/x-raw-yuv", + "framerate", GST_TYPE_FRACTION, + (int) (fps * 1000), 1000, NULL); - if (gst_element_link_filtered (vrate, vencode, vcaps) == FALSE) { - g_warning ("Fail to link vrate with vencode."); - goto error; - } - gst_caps_unref (vcaps); - } else { - if (gst_element_link (vcolorspace, vencode) == FALSE) { - g_warning ("Fail to link colorspace and video encode element."); - goto error; - } - } + if (gst_element_link_filtered(vrate, vencode, vcaps) == FALSE) + { + g_warning("Fail to link vrate with vencode."); + goto error; + } + gst_caps_unref(vcaps); + } + else + { + if (gst_element_link(vcolorspace, vencode) == FALSE) + { + g_warning("Fail to link colorspace and video encode element."); + goto error; + } + } - gst_element_link (vencode, vqueue_src); + gst_element_link(vencode, vqueue_src); - // ghost pad the video bin - vpad = gst_element_get_pad (vqueue, "sink"); - gst_element_add_pad (vbin, gst_ghost_pad_new ("sink", vpad)); - gst_object_unref (vpad); + // ghost pad the video bin + vpad = gst_element_get_pad(vqueue, "sink"); + gst_element_add_pad(vbin, gst_ghost_pad_new("sink", vpad)); + gst_object_unref(vpad); - vpad = gst_element_get_pad (vqueue_src, "src"); - gst_element_add_pad (vbin, gst_ghost_pad_new ("src", vpad)); - gst_object_unref (vpad); + vpad = gst_element_get_pad(vqueue_src, "src"); + gst_element_add_pad(vbin, gst_ghost_pad_new("src", vpad)); + gst_object_unref(vpad); - return vbin; + return vbin; - error: - if (vpad != NULL) - gst_object_unref (vpad); +error: + if (vpad != NULL) + gst_object_unref(vpad); - if (vbin != NULL) - gst_object_unref (vbin); + if (vbin != NULL) + gst_object_unref(vbin); - if (vqueue != NULL) - gst_object_unref (vqueue); + if (vqueue != NULL) + gst_object_unref(vqueue); - if (vencode != NULL) - gst_object_unref (vencode); + if (vencode != NULL) + gst_object_unref(vencode); - if (vqueue_src != NULL) - gst_object_unref (vqueue_src); + if (vqueue_src != NULL) + gst_object_unref(vqueue_src); - if (vcolorspace != NULL) - gst_object_unref (vcolorspace); + if (vcolorspace != NULL) + gst_object_unref(vcolorspace); - return NULL; + return NULL; } void -g_mencoder_setup_stream (GMencoder *self, - const gchar* mux_name, - const gchar* video_encode, - gchar** video_encode_prop, - gdouble video_fps, - gdouble video_rate, - guint video_width, - guint video_height, - const gchar* audio_encode, - gchar** audio_encode_prop, - guint audio_rate, - const gchar* out_uri) +g_mencoder_setup_stream(GMencoder * self, + const gchar * mux_name, + const gchar * video_encode, + gchar ** video_encode_prop, + gdouble video_fps, + gdouble video_rate, + guint video_width, + guint video_height, + const gchar * audio_encode, + gchar ** audio_encode_prop, + guint audio_rate, const gchar * out_uri) { - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); - if (priv->ready == TRUE) { - g_warning ("Stream already configured. You need close stream first."); - return; - } + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); + if (priv->ready == TRUE) + { + g_warning("Stream already configured. You need close stream first."); + return; + } - _close_output (self); - _open_output (self, out_uri); + _close_output(self); + _open_output(self, out_uri); - priv->sources = 0; - priv->pipe = _create_pipeline (self, - video_encode, - mux_name, - video_encode_prop, - video_fps, - video_rate, - video_width, - video_height, - audio_encode, - audio_encode_prop, - audio_rate); + priv->sources = 0; + priv->pipe = _create_pipeline(self, + video_encode, + mux_name, + video_encode_prop, + video_fps, + video_rate, + video_width, + video_height, + audio_encode, audio_encode_prop, audio_rate); } gboolean -g_mencoder_append_uri (GMencoder *self, - const gchar* uri) +g_mencoder_append_uri(GMencoder * self, const gchar * uri) { - GstPad *pad_src; - GstPad *pad_sink; - GstElement *src; - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); - gboolean ret = FALSE; - GstElement *ap = NULL; - GstElement *vp = NULL; + GstPad *pad_src; + GstPad *pad_sink; + GstElement *src; + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); + gboolean ret = FALSE; + GstElement *ap = NULL; + GstElement *vp = NULL; - g_return_val_if_fail (priv->pipe != NULL, FALSE); - g_return_val_if_fail (priv->ready == FALSE, FALSE); + g_return_val_if_fail(priv->pipe != NULL, FALSE); + g_return_val_if_fail(priv->ready == FALSE, FALSE); #ifndef SUPPORT_MULT_INPUT - g_return_val_if_fail (priv->sources < 1, FALSE); + g_return_val_if_fail(priv->sources < 1, FALSE); #endif - src = _create_source (uri); - if (src == NULL) - return FALSE; + src = _create_source(uri); + if (src == NULL) + return FALSE; - priv->src = gst_bin_get_by_name (GST_BIN (src), "src"); + priv->src = gst_bin_get_by_name(GST_BIN(src), "src"); - gst_bin_add (GST_BIN (priv->pipe), src); + gst_bin_add(GST_BIN(priv->pipe), src); #ifdef SUPPORT_MULT_INPUT - ap = gst_bin_get_by_name (GST_BIN (priv->pipe), "ap"); - vp = gst_bin_get_by_name (GST_BIN (priv->pipe), "vp"); + ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "ap"); + vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vp"); #else - ap = gst_bin_get_by_name (GST_BIN (priv->pipe), "abin"); - vp = gst_bin_get_by_name (GST_BIN (priv->pipe), "vbin"); + ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "abin"); + vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vbin"); #endif - if ((vp == NULL) || (ap == NULL)) { - g_warning ("Fail to get output bin"); - goto error; - } + if ((vp == NULL) || (ap == NULL)) + { + g_warning("Fail to get output bin"); + goto error; + } - pad_src = gst_element_get_pad (src, "src_audio"); - pad_sink = gst_element_get_compatible_pad (ap, - pad_src, - gst_pad_get_caps (pad_src)); + pad_src = gst_element_get_pad(src, "src_audio"); + pad_sink = gst_element_get_compatible_pad(ap, + pad_src, + gst_pad_get_caps(pad_src)); - if ((pad_sink == NULL) || (pad_src == NULL)) - goto error; + if ((pad_sink == NULL) || (pad_src == NULL)) + goto error; - GstPadLinkReturn lret = gst_pad_link (pad_src, pad_sink); - if (lret != GST_PAD_LINK_OK) - goto error; + GstPadLinkReturn lret = gst_pad_link(pad_src, pad_sink); + if (lret != GST_PAD_LINK_OK) + goto error; - gst_object_unref (pad_src); - gst_object_unref (pad_sink); + gst_object_unref(pad_src); + gst_object_unref(pad_sink); - pad_src = gst_element_get_pad (src, "src_video"); - pad_sink = gst_element_get_compatible_pad (vp, - pad_src, - gst_pad_get_caps (pad_src)); + pad_src = gst_element_get_pad(src, "src_video"); + pad_sink = gst_element_get_compatible_pad(vp, + pad_src, + gst_pad_get_caps(pad_src)); - if ((pad_src == NULL) || (pad_sink == NULL)) - goto error; + if ((pad_src == NULL) || (pad_sink == NULL)) + goto error; - if (gst_pad_link (pad_src, pad_sink) != GST_PAD_LINK_OK) { - g_warning ("invalid source. video"); - goto error; - } + if (gst_pad_link(pad_src, pad_sink) != GST_PAD_LINK_OK) + { + g_warning("invalid source. video"); + goto error; + } - priv->sources++; - ret = TRUE; - error: + priv->sources++; + ret = TRUE; +error: - if ((src != NULL) && (ret == FALSE)) { - gst_bin_remove (GST_BIN (priv->pipe), src); - gst_object_unref (src); - } + if ((src != NULL) && (ret == FALSE)) + { + gst_bin_remove(GST_BIN(priv->pipe), src); + gst_object_unref(src); + } - if (ap != NULL) - gst_object_unref (ap); + if (ap != NULL) + gst_object_unref(ap); - if (vp != NULL) - gst_object_unref (vp); + if (vp != NULL) + gst_object_unref(vp); - if (pad_src != NULL) - gst_object_unref (pad_src); + if (pad_src != NULL) + gst_object_unref(pad_src); - if (pad_sink != NULL) - gst_object_unref (pad_sink); + if (pad_sink != NULL) + gst_object_unref(pad_sink); - return ret; + return ret; } void -g_mencoder_remove_uri (GMencoder *self, - const gchar* uri) +g_mencoder_remove_uri(GMencoder * self, const gchar * uri) { - // GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); - //TODO: remove src + // GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); + //TODO: remove src } void -g_mencoder_play_stream (GMencoder *self) +g_mencoder_play_stream(GMencoder * self) { - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); - g_return_if_fail (priv->ready == FALSE); - priv->ready = TRUE; - gst_element_set_state (priv->pipe, GST_STATE_PLAYING); - priv->tick_id = g_timeout_add (500, _tick_cb, self); + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); + g_return_if_fail(priv->ready == FALSE); + priv->ready = TRUE; + gst_element_set_state(priv->pipe, GST_STATE_PLAYING); + priv->tick_id = g_timeout_add(500, _tick_cb, self); } void -g_mencoder_pause_stream (GMencoder *self) +g_mencoder_pause_stream(GMencoder * self) { - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); - g_return_if_fail (priv->ready == TRUE); - gst_element_set_state (priv->pipe, GST_STATE_PAUSED); + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); + g_return_if_fail(priv->ready == TRUE); + gst_element_set_state(priv->pipe, GST_STATE_PAUSED); } void -g_mencoder_close_stream (GMencoder *self) +g_mencoder_close_stream(GMencoder * self) { - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); - if (priv->tick_id != 0) { - g_source_remove (priv->tick_id); - priv->tick_id = 0; - } + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); + if (priv->tick_id != 0) + { + g_source_remove(priv->tick_id); + priv->tick_id = 0; + } - if (priv->pipe != NULL) { - //TODO: fixe pipeline dispose - //gst_element_set_state (priv->pipe, GST_STATE_NULL); - //g_debug ("SETING STATE TO NULL: OK"); - //gst_element_set_state (priv->pipe, GST_STATE_NULL); - //gst_object_unref (priv->pipe); - gst_object_unref (priv->src); - priv->src = NULL; - priv->pipe = NULL; - priv->abin = NULL; - priv->vbin = NULL; - priv->sink = NULL; - } - priv->ready = FALSE; + if (priv->pipe != NULL) + { + //TODO: fixe pipeline dispose + //gst_element_set_state (priv->pipe, GST_STATE_NULL); + //g_debug ("SETING STATE TO NULL: OK"); + //gst_element_set_state (priv->pipe, GST_STATE_NULL); + //gst_object_unref (priv->pipe); + gst_object_unref(priv->src); + priv->src = NULL; + priv->pipe = NULL; + priv->abin = NULL; + priv->vbin = NULL; + priv->sink = NULL; + } + priv->ready = FALSE; } -static GstElement* -_create_pipeline (GMencoder *self, - const gchar* video_encode, - const gchar* mux_name, - gchar** video_encode_prop, - gdouble video_fps, - gdouble video_rate, - guint video_width, - guint video_height, - const gchar* audio_encode, - gchar** audio_encode_prop, - guint audio_rate) +static GstElement * +_create_pipeline(GMencoder * self, + const gchar * video_encode, + const gchar * mux_name, + gchar ** video_encode_prop, + gdouble video_fps, + gdouble video_rate, + guint video_width, + guint video_height, + const gchar * audio_encode, + gchar ** audio_encode_prop, guint audio_rate) { - GstBus *bus = NULL; - GstElement *pipe = NULL; - GstElement *sink = NULL; - GstElement *mux = NULL; - GstElement *abin = NULL; - GstElement *vbin = NULL; - GstElement *queue= NULL; - GstPad *aux_pad = NULL; - GstPad *mux_pad = NULL; + GstBus *bus = NULL; + GstElement *pipe = NULL; + GstElement *sink = NULL; + GstElement *mux = NULL; + GstElement *abin = NULL; + GstElement *vbin = NULL; + GstElement *queue = NULL; + GstPad *aux_pad = NULL; + GstPad *mux_pad = NULL; #ifdef SUPPORT_MULT_INPUT - GstElement *ap = NULL; - GstElement *vp = NULL; + GstElement *ap = NULL; + GstElement *vp = NULL; #endif - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); - pipe = gst_pipeline_new ("pipe"); + pipe = gst_pipeline_new("pipe"); #ifdef SUPPORT_MULT_INPUT - ap = gst_element_factory_make ("concatmux", "ap"); - vp = gst_element_factory_make ("concatmux", "vp"); - gst_bin_add_many (GST_BIN (pipe), ap, vp, NULL); + ap = gst_element_factory_make("concatmux", "ap"); + vp = gst_element_factory_make("concatmux", "vp"); + gst_bin_add_many(GST_BIN(pipe), ap, vp, NULL); #endif - mux = gst_element_factory_make ((mux_name ? mux_name : "ffmux_mpeg"), "mux"); - if (mux == NULL) - goto error; + mux = gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"), "mux"); + if (mux == NULL) + goto error; - queue = gst_element_factory_make ("queue", "queueu_sink"); + queue = gst_element_factory_make("queue", "queueu_sink"); - sink = gst_element_factory_make ("fdsink", "sink"); - if (sink == NULL) - goto error; + sink = gst_element_factory_make("fdsink", "sink"); + if (sink == NULL) + goto error; - g_object_set (G_OBJECT(sink), - "fd", priv->fd, - "sync", FALSE, - NULL); + g_object_set(G_OBJECT(sink), "fd", priv->fd, "sync", FALSE, NULL); - abin = _create_audio_bin (audio_encode, audio_encode_prop, audio_rate); - if (abin == NULL) - goto error; + abin = _create_audio_bin(audio_encode, audio_encode_prop, audio_rate); + if (abin == NULL) + goto error; - vbin = _create_video_bin (video_encode, video_encode_prop, video_fps, video_rate, video_width, video_height); - if (vbin == NULL) - goto error; + vbin = + _create_video_bin(video_encode, video_encode_prop, video_fps, video_rate, + video_width, video_height); + if (vbin == NULL) + goto error; - // Finish Pipe - gst_bin_add_many (GST_BIN (pipe), abin, vbin, mux, queue, sink, NULL); + // Finish Pipe + gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, sink, NULL); #ifdef SUPPORT_MULT_INPUT - if (gst_element_link (ap, abin) == FALSE) { - g_warning ("Fail to link concat and abin"); - goto error; - } + if (gst_element_link(ap, abin) == FALSE) + { + g_warning("Fail to link concat and abin"); + goto error; + } - if (gst_element_link (vp, vbin) == FALSE) { - g_warning ("Fail to link concat and vbin"); - } + if (gst_element_link(vp, vbin) == FALSE) + { + g_warning("Fail to link concat and vbin"); + } #endif - //Link bins with mux - aux_pad = gst_element_get_pad (abin, "src"); - mux_pad = gst_element_get_compatible_pad (mux, aux_pad, GST_PAD_CAPS (aux_pad)); - if (mux_pad == NULL) { - g_warning ("Mux element no have audio PAD"); - goto error; - } - GstPadLinkReturn ret = gst_pad_link (aux_pad, mux_pad); - if (ret != GST_PAD_LINK_OK) { - g_warning ("Fail link audio and mux: %d", ret); - goto error; + //Link bins with mux + aux_pad = gst_element_get_pad(abin, "src"); + mux_pad = + gst_element_get_compatible_pad(mux, aux_pad, GST_PAD_CAPS(aux_pad)); + if (mux_pad == NULL) + { + g_warning("Mux element no have audio PAD"); + goto error; + } + GstPadLinkReturn ret = gst_pad_link(aux_pad, mux_pad); + if (ret != GST_PAD_LINK_OK) + { + g_warning("Fail link audio and mux: %d", ret); + goto error; - } - gst_object_unref (aux_pad); - gst_object_unref (mux_pad); + } + gst_object_unref(aux_pad); + gst_object_unref(mux_pad); - aux_pad = gst_element_get_pad (vbin, "src"); - mux_pad = gst_element_get_compatible_pad (mux, aux_pad, GST_PAD_CAPS (aux_pad)); - if (mux_pad == NULL) { - g_warning ("Mux element no have video PAD"); - goto error; - } - ret = gst_pad_link (aux_pad, mux_pad); - if (ret != GST_PAD_LINK_OK) { - g_warning ("Fail link video and mux: %d", ret); - goto error; - } - gst_object_unref (aux_pad); - gst_object_unref (mux_pad); - aux_pad = NULL; - mux_pad = NULL; + aux_pad = gst_element_get_pad(vbin, "src"); + mux_pad = + gst_element_get_compatible_pad(mux, aux_pad, GST_PAD_CAPS(aux_pad)); + if (mux_pad == NULL) + { + g_warning("Mux element no have video PAD"); + goto error; + } + ret = gst_pad_link(aux_pad, mux_pad); + if (ret != GST_PAD_LINK_OK) + { + g_warning("Fail link video and mux: %d", ret); + goto error; + } + gst_object_unref(aux_pad); + gst_object_unref(mux_pad); + aux_pad = NULL; + mux_pad = NULL; - //Link mux with sink - gst_element_link_many (mux, queue, sink, NULL); + //Link mux with sink + gst_element_link_many(mux, queue, sink, NULL); - bus = gst_pipeline_get_bus (GST_PIPELINE (pipe)); - gst_bus_add_watch (bus, _pipeline_bus_cb, self); - gst_object_unref (bus); - return pipe; + bus = gst_pipeline_get_bus(GST_PIPELINE(pipe)); + gst_bus_add_watch(bus, _pipeline_bus_cb, self); + gst_object_unref(bus); + return pipe; - error: - g_warning ("Invalid uri"); +error: + g_warning("Invalid uri"); - if (pipe != NULL) { - gst_object_unref (pipe); - } + if (pipe != NULL) + { + gst_object_unref(pipe); + } - if (mux != NULL) { - gst_object_unref (mux); - } + if (mux != NULL) + { + gst_object_unref(mux); + } - if (mux_pad != NULL) { - gst_object_unref (mux_pad); - } + if (mux_pad != NULL) + { + gst_object_unref(mux_pad); + } - if (aux_pad != NULL) { - gst_object_unref (mux_pad); - } + if (aux_pad != NULL) + { + gst_object_unref(mux_pad); + } - if (sink != NULL) { - gst_object_unref (sink); - } + if (sink != NULL) + { + gst_object_unref(sink); + } - if (abin != NULL) { - gst_object_unref (abin); - } + if (abin != NULL) + { + gst_object_unref(abin); + } - if (vbin != NULL) { - gst_object_unref (vbin); - } + if (vbin != NULL) + { + gst_object_unref(vbin); + } - return FALSE; + return FALSE; } static void -_close_output (GMencoder *self) +_close_output(GMencoder * self) { } -static GstElement* -_create_source (const gchar* uri) +static GstElement * +_create_source(const gchar * uri) { - GstElement *bsrc = NULL; - GstElement *src = NULL; - GstElement *queue = NULL; - GstElement *aqueue = NULL; - GstElement *vqueue = NULL; - GstElement *decode = NULL; - GstPad *src_pad = NULL; + GstElement *bsrc = NULL; + GstElement *src = NULL; + GstElement *queue = NULL; + GstElement *aqueue = NULL; + GstElement *vqueue = NULL; + GstElement *decode = NULL; + GstPad *src_pad = NULL; - bsrc = gst_bin_new (NULL); + bsrc = gst_bin_new(NULL); - //src = gst_element_factory_make ("gnomevfssrc", "src"); - //g_object_set (G_OBJECT (src), "location", uri, NULL); - src = gst_element_make_from_uri (GST_URI_SRC, uri, "src"); - if (src == NULL) - goto error; + //src = gst_element_factory_make ("gnomevfssrc", "src"); + //g_object_set (G_OBJECT (src), "location", uri, NULL); + src = gst_element_make_from_uri(GST_URI_SRC, uri, "src"); + if (src == NULL) + goto error; - decode = gst_element_factory_make ("decodebin", "decode"); - if (decode == NULL) - goto error; + decode = gst_element_factory_make("decodebin", "decode"); + if (decode == NULL) + goto error; - queue = gst_element_factory_make ("queue", "queue_src"); - aqueue = gst_element_factory_make ("queue", "aqueue"); - if (aqueue == NULL) - goto error; + queue = gst_element_factory_make("queue", "queue_src"); + aqueue = gst_element_factory_make("queue", "aqueue"); + if (aqueue == NULL) + goto error; - vqueue = gst_element_factory_make ("queue", "vqueue"); - if (vqueue == NULL) - goto error; + vqueue = gst_element_factory_make("queue", "vqueue"); + if (vqueue == NULL) + goto error; - gst_bin_add_many (GST_BIN (bsrc), src, queue, decode, aqueue, vqueue, NULL); - gst_element_link_many (src, queue, decode, NULL); + gst_bin_add_many(GST_BIN(bsrc), src, queue, decode, aqueue, vqueue, NULL); + gst_element_link_many(src, queue, decode, NULL); - g_signal_connect (G_OBJECT (decode), - "new-decoded-pad", - G_CALLBACK (_decodebin_new_pad_cb), - bsrc); + g_signal_connect(G_OBJECT(decode), + "new-decoded-pad", + G_CALLBACK(_decodebin_new_pad_cb), bsrc); - g_signal_connect (G_OBJECT (decode), - "unknown-type", - G_CALLBACK (_decodebin_unknown_type_cb), - pipe); + g_signal_connect(G_OBJECT(decode), + "unknown-type", + G_CALLBACK(_decodebin_unknown_type_cb), pipe); - src_pad = gst_element_get_pad (aqueue, "src"); - gst_element_add_pad (bsrc, gst_ghost_pad_new("src_audio", src_pad)); - gst_object_unref (src_pad); + src_pad = gst_element_get_pad(aqueue, "src"); + gst_element_add_pad(bsrc, gst_ghost_pad_new("src_audio", src_pad)); + gst_object_unref(src_pad); - src_pad = gst_element_get_pad (vqueue, "src"); - gst_element_add_pad (bsrc, gst_ghost_pad_new("src_video", src_pad)); - gst_object_unref (src_pad); + src_pad = gst_element_get_pad(vqueue, "src"); + gst_element_add_pad(bsrc, gst_ghost_pad_new("src_video", src_pad)); + gst_object_unref(src_pad); - return bsrc; + return bsrc; - error: - if (src != NULL) { - gst_object_unref (src); - } +error: + if (src != NULL) + { + gst_object_unref(src); + } - if (decode != NULL) { - gst_object_unref (decode); - } + if (decode != NULL) + { + gst_object_unref(decode); + } - if (aqueue != NULL) { - gst_object_unref (aqueue); - } + if (aqueue != NULL) + { + gst_object_unref(aqueue); + } - if (vqueue != NULL) { - gst_object_unref (vqueue); - } + if (vqueue != NULL) + { + gst_object_unref(vqueue); + } - return NULL; + return NULL; } static void -_open_output (GMencoder *self, - const gchar* uri) +_open_output(GMencoder * self, const gchar * uri) { - gchar** i; - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); + gchar **i; + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); - i = g_strsplit (uri, "://", 0); - if (strcmp (i[0], "fd") == 0) { - priv->fd = atoi (i[1]); - } else if (strcmp (i[0], "file") == 0) { - priv->fd = open (i[1], O_WRONLY | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - } else { - g_warning ("Output uri not supported"); - } + i = g_strsplit(uri, "://", 0); + if (strcmp(i[0], "fd") == 0) + { + priv->fd = atoi(i[1]); + } + else if (strcmp(i[0], "file") == 0) + { + priv->fd = open(i[1], O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + } + else + { + g_warning("Output uri not supported"); + } - g_strfreev (i); + g_strfreev(i); } static gboolean -_pipeline_bus_cb (GstBus *bus, - GstMessage *msg, - gpointer user_data) +_pipeline_bus_cb(GstBus * bus, GstMessage * msg, gpointer user_data) { - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data); + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data); - switch (GST_MESSAGE_TYPE (msg)) + switch (GST_MESSAGE_TYPE(msg)) { - case GST_MESSAGE_STATE_CHANGED: - { - GstState oldstate; - GstState newstate; - GstState pendingstate; + case GST_MESSAGE_STATE_CHANGED: + { + GstState oldstate; + GstState newstate; + GstState pendingstate; - gst_message_parse_state_changed (msg, &oldstate, - &newstate, &pendingstate); + gst_message_parse_state_changed(msg, &oldstate, + &newstate, &pendingstate); - if (pendingstate != GST_STATE_VOID_PENDING) - break; + if (pendingstate != GST_STATE_VOID_PENDING) + break; - if ((oldstate == GST_STATE_READY) && - (newstate == GST_STATE_PAUSED)) { - if (priv->ready) - g_signal_emit (user_data, g_mencoder_signals[PAUSED], 0); - } else if ((oldstate == GST_STATE_PAUSED) && - (newstate == GST_STATE_PLAYING)) { - g_signal_emit (user_data, g_mencoder_signals[PLAYING], 0); - } else if ((oldstate == GST_STATE_READY) && - (newstate == GST_STATE_NULL)) { - g_signal_emit (user_data, g_mencoder_signals[STOPED], 0); - } - break; - } + if ((oldstate == GST_STATE_READY) && (newstate == GST_STATE_PAUSED)) + { + if (priv->ready) + g_signal_emit(user_data, g_mencoder_signals[PAUSED], 0); + } + else if ((oldstate == GST_STATE_PAUSED) && + (newstate == GST_STATE_PLAYING)) + { + g_signal_emit(user_data, g_mencoder_signals[PLAYING], 0); + } + else if ((oldstate == GST_STATE_READY) && + (newstate == GST_STATE_NULL)) + { + g_signal_emit(user_data, g_mencoder_signals[STOPED], 0); + } + break; + } - case GST_MESSAGE_ERROR: - { - GError *error; - gchar *debug; - gchar *err_str; + case GST_MESSAGE_ERROR: + { + GError *error; + gchar *debug; + gchar *err_str; - if (priv->tick_id != 0) { - g_source_remove (priv->tick_id); - priv->tick_id = 0; - } + if (priv->tick_id != 0) + { + g_source_remove(priv->tick_id); + priv->tick_id = 0; + } - gst_message_parse_error (msg, &error, &debug); - err_str = g_strdup_printf ("Error [%d] %s (%s)", error->code, - error->message, - debug); - priv->ready = FALSE; - g_signal_emit (user_data, g_mencoder_signals[ERROR], 0, err_str); - g_free (err_str); - g_clear_error (&error); - g_free (debug); - break; - } + gst_message_parse_error(msg, &error, &debug); + err_str = g_strdup_printf("Error [%d] %s (%s)", error->code, + error->message, debug); + priv->ready = FALSE; + g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, err_str); + g_free(err_str); + g_clear_error(&error); + g_free(debug); + break; + } - case GST_MESSAGE_EOS: - priv->ready = FALSE; - g_signal_emit (user_data, g_mencoder_signals[EOS], 0); - break; + case GST_MESSAGE_EOS: + priv->ready = FALSE; + g_signal_emit(user_data, g_mencoder_signals[EOS], 0); + break; - case GST_MESSAGE_DURATION: - { - GstFormat format; - gint64 duration; - gst_message_parse_duration (msg, &format, &duration); - if (format == GST_FORMAT_BYTES) - priv->duration = duration; - break; - } - default: - { - break; - } + case GST_MESSAGE_DURATION: + { + GstFormat format; + gint64 duration; + gst_message_parse_duration(msg, &format, &duration); + if (format == GST_FORMAT_BYTES) + priv->duration = duration; + break; + } + default: + { + break; + } } - return TRUE; + return TRUE; } static void -_decodebin_new_pad_cb (GstElement* object, - GstPad* pad, - gboolean flag, - gpointer user_data) +_decodebin_new_pad_cb(GstElement * object, + GstPad * pad, gboolean flag, gpointer user_data) { - GstCaps *caps; - gchar *str_caps = NULL; - GstElement *sink_element; - GstPad *sink_pad; + GstCaps *caps; + gchar *str_caps = NULL; + GstElement *sink_element; + GstPad *sink_pad; - caps = gst_pad_get_caps (pad); - str_caps = gst_caps_to_string (caps); - if (strstr (str_caps, "audio") != NULL) { - sink_element = gst_bin_get_by_name (GST_BIN (user_data), "aqueue"); - } else if (strstr (str_caps, "video") != NULL) { - sink_element = gst_bin_get_by_name (GST_BIN (user_data), "vqueue"); - } else { - g_warning ("invalid caps %s", str_caps); - } + caps = gst_pad_get_caps(pad); + str_caps = gst_caps_to_string(caps); + if (strstr(str_caps, "audio") != NULL) + { + sink_element = gst_bin_get_by_name(GST_BIN(user_data), "aqueue"); + } + else if (strstr(str_caps, "video") != NULL) + { + sink_element = gst_bin_get_by_name(GST_BIN(user_data), "vqueue"); + } + else + { + g_warning("invalid caps %s", str_caps); + } - sink_pad = gst_element_get_pad (sink_element, "sink"); - gst_pad_link (pad, sink_pad); + sink_pad = gst_element_get_pad(sink_element, "sink"); + gst_pad_link(pad, sink_pad); - gst_object_unref (sink_element); - gst_object_unref (sink_pad); - g_free (str_caps); - gst_caps_unref (caps); + gst_object_unref(sink_element); + gst_object_unref(sink_pad); + g_free(str_caps); + gst_caps_unref(caps); } static void -_decodebin_unknown_type_cb (GstElement* object, - GstPad* pad, - GstCaps* caps, - gpointer user_data) +_decodebin_unknown_type_cb(GstElement * object, + GstPad * pad, GstCaps * caps, gpointer user_data) { - g_warning ("Unknown Type"); - //priv->ready = FALSE; + g_warning("Unknown Type"); + //priv->ready = FALSE; } static gboolean -_tick_cb (gpointer user_data) +_tick_cb(gpointer user_data) { - GstFormat format = GST_FORMAT_BYTES; - gint64 cur = 0; + GstFormat format = GST_FORMAT_BYTES; + gint64 cur = 0; - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data); + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(user_data); - if (priv->duration == 0) { - gint64 d = 0; - if (gst_element_query_duration (priv->src, &format, &d)) - priv->duration = d; - } + if (priv->duration == 0) + { + gint64 d = 0; + if (gst_element_query_duration(priv->src, &format, &d)) + priv->duration = d; + } - if (priv->duration != 0) { - gst_element_query_position (priv->src, &format, &cur); - g_print ("PROGRESS:%lli\n", (99 * cur) / priv->duration); - } + if (priv->duration != 0) + { + gst_element_query_position(priv->src, &format, &cur); + g_print("PROGRESS:%lli\n", (99 * cur) / priv->duration); + } - return TRUE; + return TRUE; } diff -r 3cf3c6019e3b -r b7f71ba285da gmyth-stream/gmemcoder/src/gmencoder.h --- a/gmyth-stream/gmemcoder/src/gmencoder.h Thu Jun 14 18:21:08 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.h Thu Jun 14 18:21:53 2007 +0100 @@ -3,17 +3,17 @@ #include -G_BEGIN_DECLS - -typedef struct _GMencoder GMencoder; +G_BEGIN_DECLS typedef struct _GMencoder GMencoder; typedef struct _GMencoderClass GMencoderClass; -struct _GMencoderClass { - GObjectClass parent_class; +struct _GMencoderClass +{ + GObjectClass parent_class; }; -struct _GMencoder { - GObject parent; +struct _GMencoder +{ + GObject parent; }; /* TYPE MACROS */ @@ -31,32 +31,28 @@ (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_MENCODER, GMencoderClass)) -GType g_mencoder_get_type (void); -GMencoder* g_mencoder_new (void); +GType g_mencoder_get_type(void); +GMencoder *g_mencoder_new(void); -void g_mencoder_setup_stream (GMencoder *self, - const gchar* mux_name, - const gchar* video_encode, - gchar** video_encode_prop, - gdouble video_fps, - gdouble video_rate, - guint video_width, - guint video_height, - const gchar* audio_encode, - gchar** audio_encode_prop, - guint audio_rate, - const gchar* output_uri); +void g_mencoder_setup_stream(GMencoder * self, + const gchar * mux_name, + const gchar * video_encode, + gchar ** video_encode_prop, + gdouble video_fps, + gdouble video_rate, + guint video_width, + guint video_height, + const gchar * audio_encode, + gchar ** audio_encode_prop, + guint audio_rate, const gchar * output_uri); -gboolean g_mencoder_append_uri (GMencoder *self, - const gchar* uri); +gboolean g_mencoder_append_uri(GMencoder * self, const gchar * uri); -void g_mencoder_remove_uri (GMencoder *self, - const gchar* uri); +void g_mencoder_remove_uri(GMencoder * self, const gchar * uri); -void g_mencoder_play_stream (GMencoder *self); -void g_mencoder_pause_stream (GMencoder *self); -void g_mencoder_close_stream (GMencoder *self); +void g_mencoder_play_stream(GMencoder * self); +void g_mencoder_pause_stream(GMencoder * self); +void g_mencoder_close_stream(GMencoder * self); G_END_DECLS - #endif diff -r 3cf3c6019e3b -r b7f71ba285da gmyth-stream/gmemcoder/src/main.c --- a/gmyth-stream/gmemcoder/src/main.c Thu Jun 14 18:21:08 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/main.c Thu Jun 14 18:21:53 2007 +0100 @@ -12,183 +12,187 @@ static GMainLoop *mainloop = NULL; /* Options */ -static gchar* input_file = NULL; -static gchar* video_encode = NULL; -static gchar* video_opts = NULL; -static gdouble video_fps = 0.0; -static gint video_rate = 0; -static gint video_width = 0; -static gint video_height = 0; -static gchar* audio_encode = NULL; -static gchar* audio_opts = NULL; -static double audio_rate = 0.0; -static gchar* mux_name = NULL; -static gchar* output_uri = NULL; +static gchar *input_file = NULL; +static gchar *video_encode = NULL; +static gchar *video_opts = NULL; +static gdouble video_fps = 0.0; +static gint video_rate = 0; +static gint video_width = 0; +static gint video_height = 0; +static gchar *audio_encode = NULL; +static gchar *audio_opts = NULL; +static double audio_rate = 0.0; +static gchar *mux_name = NULL; +static gchar *output_uri = NULL; static gboolean -_quit (gpointer data) +_quit(gpointer data) { - g_object_unref (data); - g_main_loop_quit (mainloop); - return FALSE; + g_object_unref(data); + g_main_loop_quit(mainloop); + return FALSE; } static void -_mencoder_eos_cb (GMencoder *mencoder, gpointer data) +_mencoder_eos_cb(GMencoder * mencoder, gpointer data) { - g_print ("EOS\n"); - g_idle_add (_quit, mencoder); + g_print("EOS\n"); + g_idle_add(_quit, mencoder); } static void -_mencoder_error_cb (GMencoder *mencoder, const gchar* msg, gpointer data) +_mencoder_error_cb(GMencoder * mencoder, const gchar * msg, gpointer data) { - g_print ("Error: %s\n", msg); - g_idle_add (_quit, mencoder); + g_print("Error: %s\n", msg); + g_idle_add(_quit, mencoder); } static gboolean -_io_channel_cb (GIOChannel *ch, - GIOCondition condition, - gpointer data) +_io_channel_cb(GIOChannel * ch, GIOCondition condition, gpointer data) { - GString *cmd = g_string_new (""); - g_io_channel_read_line_string (ch, cmd, NULL, NULL); + GString *cmd = g_string_new(""); + g_io_channel_read_line_string(ch, cmd, NULL, NULL); - if (strcmp (cmd->str, "PLAY\n") == 0) { - g_mencoder_play_stream (G_MENCODER (data)); - } else if (strcmp (cmd->str, "PAUSE\n") == 0) { - g_mencoder_pause_stream (G_MENCODER (data)); - } else if (strcmp (cmd->str, "STOP\n") == 0) { - g_mencoder_close_stream (G_MENCODER (data)); - } else if (strcmp (cmd->str, "QUIT\n") == 0) { - g_mencoder_close_stream (G_MENCODER (data)); - g_main_loop_quit (mainloop); - } - g_string_free (cmd, TRUE); - return TRUE; + if (strcmp(cmd->str, "PLAY\n") == 0) + { + g_mencoder_play_stream(G_MENCODER(data)); + } + else if (strcmp(cmd->str, "PAUSE\n") == 0) + { + g_mencoder_pause_stream(G_MENCODER(data)); + } + else if (strcmp(cmd->str, "STOP\n") == 0) + { + g_mencoder_close_stream(G_MENCODER(data)); + } + else if (strcmp(cmd->str, "QUIT\n") == 0) + { + g_mencoder_close_stream(G_MENCODER(data)); + g_main_loop_quit(mainloop); + } + g_string_free(cmd, TRUE); + return TRUE; } int -main (int argc, char** argv) +main(int argc, char **argv) { - GMencoder *coder = NULL; - GIOChannel *ch; - gchar **vopts; - gchar **aopts; - gchar **files; - gint i; + GMencoder *coder = NULL; + GIOChannel *ch; + gchar **vopts; + gchar **aopts; + gchar **files; + gint i; - GOptionContext *context; - static const GOptionEntry options [] = { - {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file, - "Input File", NULL}, + GOptionContext *context; + static const GOptionEntry options[] = { + {"input-files", 'i', 0, G_OPTION_ARG_STRING, &input_file, + "Input File", NULL}, - {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode, - "GstElementName for used to video encode", NULL}, + {"video-encode", 0, 0, G_OPTION_ARG_STRING, &video_encode, + "GstElementName for used to video encode", NULL}, - {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts, - "Properties to set on video element", NULL}, + {"video-opts", 0, 0, G_OPTION_ARG_STRING, &video_opts, + "Properties to set on video element", NULL}, - {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps, - "Video FPS", NULL}, + {"video-fps", 0, 0, G_OPTION_ARG_DOUBLE, &video_fps, + "Video FPS", NULL}, - {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate, - "Video rate", NULL}, + {"video-rate", 0, 0, G_OPTION_ARG_INT, &video_rate, + "Video rate", NULL}, - {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width, - "Video width", NULL}, + {"video-width", 0, 0, G_OPTION_ARG_INT, &video_width, + "Video width", NULL}, - {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height, - "Video height", NULL}, + {"video-height", 0, 0, G_OPTION_ARG_INT, &video_height, + "Video height", NULL}, - {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode, - "GstElementName for use to audio encode", NULL}, + {"audio-encode", 0, 0, G_OPTION_ARG_STRING, &audio_encode, + "GstElementName for use to audio encode", NULL}, - {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts, - "Properties to set on audio element", NULL}, + {"audio-opts", 0, 0, G_OPTION_ARG_STRING, &audio_opts, + "Properties to set on audio element", NULL}, - {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate, - "Audio rate", NULL}, + {"audio-rate", 0, 0, G_OPTION_ARG_INT, &audio_rate, + "Audio rate", NULL}, - {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name, - "GstElementName for use to mux file", NULL}, + {"mux-element", 0, 0, G_OPTION_ARG_STRING, &mux_name, + "GstElementName for use to mux file", NULL}, - {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri, - "Uri to output", NULL}, + {"output-uri", 'o', 0, G_OPTION_ARG_STRING, &output_uri, + "Uri to output", NULL}, - { NULL } - }; + {NULL} + }; - g_type_init (); - g_thread_init (NULL); - mainloop = g_main_loop_new (NULL, FALSE); + g_type_init(); + g_thread_init(NULL); + mainloop = g_main_loop_new(NULL, FALSE); - g_set_prgname ("gmemcoder"); - context = g_option_context_new (NULL); - g_option_context_set_help_enabled (context, TRUE); - g_option_context_add_main_entries (context, options, NULL); - g_option_context_add_group (context, gst_init_get_option_group ()); - g_option_context_parse (context, &argc, &argv, NULL); + g_set_prgname("gmemcoder"); + context = g_option_context_new(NULL); + g_option_context_set_help_enabled(context, TRUE); + g_option_context_add_main_entries(context, options, NULL); + g_option_context_add_group(context, gst_init_get_option_group()); + g_option_context_parse(context, &argc, &argv, NULL); - gst_init (&argc, &argv); + gst_init(&argc, &argv); - if (output_uri == NULL) { - g_print ("You need to specify output-uri.\nTry --help " - "for more information.\n"); - return 1; - } + if (output_uri == NULL) + { + g_print("You need to specify output-uri.\nTry --help " + "for more information.\n"); + return 1; + } - if (input_file == NULL) { - g_print ("You need to specify input file\nTry --help " - "for more information.\n"); - } + if (input_file == NULL) + { + g_print("You need to specify input file\nTry --help " + "for more information.\n"); + } - coder = g_mencoder_new (); - ch = g_io_channel_unix_new (0); + coder = g_mencoder_new(); + ch = g_io_channel_unix_new(0); - aopts = g_strsplit (audio_opts, ",", 0); - vopts = g_strsplit (video_opts, ",", 0); + aopts = g_strsplit(audio_opts, ",", 0); + vopts = g_strsplit(video_opts, ",", 0); - g_mencoder_setup_stream (coder, mux_name, - video_encode, vopts, video_fps, - video_rate, video_width, video_height, - audio_encode, aopts, audio_rate, - output_uri); + g_mencoder_setup_stream(coder, mux_name, + video_encode, vopts, video_fps, + video_rate, video_width, video_height, + audio_encode, aopts, audio_rate, output_uri); - files = g_strsplit (input_file, ",", 0); - for (i=0; i < g_strv_length (files); i++) { - if (!g_mencoder_append_uri (coder, files[i])) { - g_debug ("Invalid uri: %s", files[i]); - } - } + files = g_strsplit(input_file, ",", 0); + for (i = 0; i < g_strv_length(files); i++) + { + if (!g_mencoder_append_uri(coder, files[i])) + { + g_debug("Invalid uri: %s", files[i]); + } + } - g_strfreev (files); - g_strfreev (aopts); - g_strfreev (vopts); + g_strfreev(files); + g_strfreev(aopts); + g_strfreev(vopts); - g_io_add_watch (ch, G_IO_IN, _io_channel_cb, coder); + g_io_add_watch(ch, G_IO_IN, _io_channel_cb, coder); - g_signal_connect (G_OBJECT (coder), - "eos", - G_CALLBACK (_mencoder_eos_cb), - mainloop); + g_signal_connect(G_OBJECT(coder), + "eos", G_CALLBACK(_mencoder_eos_cb), mainloop); - g_signal_connect (G_OBJECT (coder), - "error", - G_CALLBACK (_mencoder_error_cb), - mainloop); + g_signal_connect(G_OBJECT(coder), + "error", G_CALLBACK(_mencoder_error_cb), mainloop); - g_mencoder_play_stream (coder); + g_mencoder_play_stream(coder); - g_debug ("RUNNING.."); - g_main_loop_run (mainloop); - g_debug ("DONE"); - g_object_unref (coder); + g_debug("RUNNING.."); + g_main_loop_run(mainloop); + g_debug("DONE"); + g_object_unref(coder); - return 0; + return 0; } diff -r 3cf3c6019e3b -r b7f71ba285da gmyth-stream/gmemcoder/tests/main.c --- a/gmyth-stream/gmemcoder/tests/main.c Thu Jun 14 18:21:08 2007 +0100 +++ b/gmyth-stream/gmemcoder/tests/main.c Thu Jun 14 18:21:53 2007 +0100 @@ -4,234 +4,228 @@ #include #include -#include +#include static GMainLoop *mainloop = NULL; static gint64 d = 0; static gint64 gap = 10; -typedef enum { - MY_STREAM_TYPE_AUDIO = 0, - MY_STREAM_TYPE_VIDEO = 1 +typedef enum +{ + MY_STREAM_TYPE_AUDIO = 0, + MY_STREAM_TYPE_VIDEO = 1 } MyStreamType; typedef struct _StreamData StreamData; -struct _StreamData { - GstElement *bin; - MyStreamType type; +struct _StreamData +{ + GstElement *bin; + MyStreamType type; }; static void -_stream_decode_pad_added_cb (GstElement *decode, - GstPad *pad, - gboolean arg1, - gpointer user_data) +_stream_decode_pad_added_cb(GstElement * decode, + GstPad * pad, gboolean arg1, gpointer user_data) { - StreamData *data = (StreamData *) user_data; - GstElement *queue; - GstPad* sink_pad; - GstCaps* caps = gst_pad_get_caps (pad); - gchar *str_caps = gst_caps_to_string (caps); + StreamData *data = (StreamData *) user_data; + GstElement *queue; + GstPad *sink_pad; + GstCaps *caps = gst_pad_get_caps(pad); + gchar *str_caps = gst_caps_to_string(caps); - g_debug ("decode caps: [%d] [%s]", data->type, str_caps); + g_debug("decode caps: [%d] [%s]", data->type, str_caps); - switch (data->type) - { - case MY_STREAM_TYPE_AUDIO: - g_debug ("Audio"); - if (strstr (str_caps, "audio") == NULL) - goto done; - break; - case MY_STREAM_TYPE_VIDEO: - g_debug ("Video"); - if (strstr (str_caps, "video") == NULL) - goto done; - break; - } + switch (data->type) + { + case MY_STREAM_TYPE_AUDIO: + g_debug("Audio"); + if (strstr(str_caps, "audio") == NULL) + goto done; + break; + case MY_STREAM_TYPE_VIDEO: + g_debug("Video"); + if (strstr(str_caps, "video") == NULL) + goto done; + break; + } - queue = gst_bin_get_by_name (GST_BIN (data->bin), "queue"); - sink_pad = gst_element_get_pad (queue, "sink"); + queue = gst_bin_get_by_name(GST_BIN(data->bin), "queue"); + sink_pad = gst_element_get_pad(queue, "sink"); - if (gst_pad_link (pad, sink_pad) != GST_PAD_LINK_OK) { - g_warning ("Failed to link decode"); - } + if (gst_pad_link(pad, sink_pad) != GST_PAD_LINK_OK) + { + g_warning("Failed to link decode"); + } - gst_object_unref (queue); - gst_object_unref (sink_pad); - //g_free (data); - g_debug ("Linked"); + gst_object_unref(queue); + gst_object_unref(sink_pad); + //g_free (data); + g_debug("Linked"); done: - gst_caps_unref (caps); - g_free (str_caps); + gst_caps_unref(caps); + g_free(str_caps); } -static GstElement* -_create_src_element (const gchar* name, - const gchar* uri, - MyStreamType type, - guint priority) +static GstElement * +_create_src_element(const gchar * name, + const gchar * uri, MyStreamType type, guint priority) { - StreamData *data; - GstElement *bin; - GstElement *src; - GstElement *decode; - GstElement *queue; - GstPad *src_pad; + StreamData *data; + GstElement *bin; + GstElement *src; + GstElement *decode; + GstElement *queue; + GstPad *src_pad; - GstElement *gnl_src; + GstElement *gnl_src; - g_debug ("element from uri: %s", uri); + g_debug("element from uri: %s", uri); - bin = gst_bin_new ("bin"); - src = gst_element_make_from_uri (GST_URI_SRC, uri, "src"); - g_return_val_if_fail (src != NULL, NULL); + bin = gst_bin_new("bin"); + src = gst_element_make_from_uri(GST_URI_SRC, uri, "src"); + g_return_val_if_fail(src != NULL, NULL); - decode = gst_element_factory_make ("decodebin", NULL); - g_return_val_if_fail (decode != NULL, NULL); + decode = gst_element_factory_make("decodebin", NULL); + g_return_val_if_fail(decode != NULL, NULL); - queue = gst_element_factory_make ("queue", "queue"); - g_return_val_if_fail (queue != NULL, NULL); + queue = gst_element_factory_make("queue", "queue"); + g_return_val_if_fail(queue != NULL, NULL); - gst_bin_add_many (GST_BIN (bin), src, decode, queue, NULL); - gst_element_link (src, decode); + gst_bin_add_many(GST_BIN(bin), src, decode, queue, NULL); + gst_element_link(src, decode); - data = g_new0 (StreamData, 1); - data->bin = bin; - data->type = type; - g_debug ("Type : %d = %d", type, data->type); + data = g_new0(StreamData, 1); + data->bin = bin; + data->type = type; + g_debug("Type : %d = %d", type, data->type); - g_signal_connect (G_OBJECT (decode), "new-decoded-pad", - G_CALLBACK (_stream_decode_pad_added_cb), - data); + g_signal_connect(G_OBJECT(decode), "new-decoded-pad", + G_CALLBACK(_stream_decode_pad_added_cb), data); - - src_pad = gst_element_get_pad (queue, "src"); - g_return_val_if_fail (src_pad != NULL, NULL); - gst_element_add_pad (bin, - gst_ghost_pad_new ("src", src_pad)); + src_pad = gst_element_get_pad(queue, "src"); + g_return_val_if_fail(src_pad != NULL, NULL); - gst_object_unref (src_pad); + gst_element_add_pad(bin, gst_ghost_pad_new("src", src_pad)); - gnl_src = gst_element_factory_make ("gnlsource", name); - g_return_val_if_fail (gnl_src != NULL, NULL); - gst_bin_add (GST_BIN (gnl_src), bin); + gst_object_unref(src_pad); - g_debug ("ADDING WITH: START [%lli] DUR [%lli]", d, gap); - if (d == 0) { - g_object_set (G_OBJECT (gnl_src), - //"start", 0L, - "duration", 10 * GST_SECOND, - //"media-start", 0L, - //"media-duration", 10 * GST_SECOND, - "priority", priority, - NULL); + gnl_src = gst_element_factory_make("gnlsource", name); + g_return_val_if_fail(gnl_src != NULL, NULL); + gst_bin_add(GST_BIN(gnl_src), bin); - } else { - g_object_set (G_OBJECT (gnl_src), - "start", 10 * GST_SECOND, - "duration", 10 * GST_SECOND, - ///"media-start", 10 * GST_SECOND, - //"media-duration", 10 * GST_SECOND, - "priority", priority, - NULL); + g_debug("ADDING WITH: START [%lli] DUR [%lli]", d, gap); + if (d == 0) + { + g_object_set(G_OBJECT(gnl_src), + //"start", 0L, + "duration", 10 * GST_SECOND, + //"media-start", 0L, + //"media-duration", 10 * GST_SECOND, + "priority", priority, NULL); - } - d++; + } + else + { + g_object_set(G_OBJECT(gnl_src), + "start", 10 * GST_SECOND, "duration", 10 * GST_SECOND, + ///"media-start", 10 * GST_SECOND, + //"media-duration", 10 * GST_SECOND, + "priority", priority, NULL); - return gnl_src; + } + d++; + + return gnl_src; } static void -_composition_pad_added_cb (GstElement *composition, - GstPad *pad, - gpointer data) +_composition_pad_added_cb(GstElement * composition, + GstPad * pad, gpointer data) { - GstPad *sink_pad = gst_element_get_pad (GST_ELEMENT (data), "sink"); - g_debug ("compose pad added"); + GstPad *sink_pad = gst_element_get_pad(GST_ELEMENT(data), "sink"); + g_debug("compose pad added"); - if (gst_pad_link (pad, sink_pad) != GST_PAD_LINK_OK) { - g_warning ("Failed to link decode"); - } + if (gst_pad_link(pad, sink_pad) != GST_PAD_LINK_OK) + { + g_warning("Failed to link decode"); + } - g_debug ("Linked ok"); + g_debug("Linked ok"); } static void -_compose_add_file (GstElement *compose, - const gchar* e_name, - const gchar* uri, - MyStreamType type, - guint priority) +_compose_add_file(GstElement * compose, + const gchar * e_name, + const gchar * uri, MyStreamType type, guint priority) { - GstElement *src; + GstElement *src; - src = _create_src_element (e_name, uri, type, priority); - gst_bin_add (GST_BIN (compose), src); + src = _create_src_element(e_name, uri, type, priority); + gst_bin_add(GST_BIN(compose), src); } -int -main (int argc, char** argv) +int +main(int argc, char **argv) { - GstElement* pipe; - GstElement* gnl_compose_a; - GstElement* gnl_compose_v; - GstElement* asink; - GstElement* vsink; - GstElement* aqueue; - GstElement* vqueue; + GstElement *pipe; + GstElement *gnl_compose_a; + GstElement *gnl_compose_v; + GstElement *asink; + GstElement *vsink; + GstElement *aqueue; + GstElement *vqueue; - g_type_init (); - gst_init (&argc, &argv); + g_type_init(); + gst_init(&argc, &argv); - mainloop = g_main_loop_new (NULL, FALSE); + mainloop = g_main_loop_new(NULL, FALSE); - pipe = gst_pipeline_new ("test_pipeline"); + pipe = gst_pipeline_new("test_pipeline"); - gnl_compose_a = gst_element_factory_make ("gnlcomposition", "acompose"); - g_return_val_if_fail (gnl_compose_a != NULL, 1); + gnl_compose_a = gst_element_factory_make("gnlcomposition", "acompose"); + g_return_val_if_fail(gnl_compose_a != NULL, 1); - gnl_compose_v = gst_element_factory_make ("gnlcomposition", "vcompose"); - g_return_val_if_fail (gnl_compose_v != NULL, 1); + gnl_compose_v = gst_element_factory_make("gnlcomposition", "vcompose"); + g_return_val_if_fail(gnl_compose_v != NULL, 1); - //_compose_add_file (gnl_compose_a, "src0", argv[1], MY_STREAM_TYPE_AUDIO, 1); - //_compose_add_file (gnl_compose_a, "src1", argv[2], MY_STREAM_TYPE_AUDIO, 1); + //_compose_add_file (gnl_compose_a, "src0", argv[1], MY_STREAM_TYPE_AUDIO, 1); + //_compose_add_file (gnl_compose_a, "src1", argv[2], MY_STREAM_TYPE_AUDIO, 1); - d = 0; + d = 0; - _compose_add_file (gnl_compose_v, "src2", argv[1], MY_STREAM_TYPE_VIDEO, 1); - _compose_add_file (gnl_compose_v, "src3", argv[2], MY_STREAM_TYPE_VIDEO, 1); + _compose_add_file(gnl_compose_v, "src2", argv[1], MY_STREAM_TYPE_VIDEO, 1); + _compose_add_file(gnl_compose_v, "src3", argv[2], MY_STREAM_TYPE_VIDEO, 1); - //aqueue = gst_element_factory_make ("queue", "aqueue"); - //asink = gst_element_factory_make ("alsasink", "asink"); + //aqueue = gst_element_factory_make ("queue", "aqueue"); + //asink = gst_element_factory_make ("alsasink", "asink"); - vqueue = gst_element_factory_make ("queue", "vqueue"); - vsink = gst_element_factory_make ("xvimagesink", "vsink"); + vqueue = gst_element_factory_make("queue", "vqueue"); + vsink = gst_element_factory_make("xvimagesink", "vsink"); - gst_bin_add_many (GST_BIN (pipe), gnl_compose_a, gnl_compose_v, - vqueue, vsink, - //aqueue, asink, - NULL); + gst_bin_add_many(GST_BIN(pipe), gnl_compose_a, gnl_compose_v, vqueue, vsink, + //aqueue, asink, + NULL); - gst_element_link (vqueue, vsink); - //gst_element_link (aqueue, asink); + gst_element_link(vqueue, vsink); + //gst_element_link (aqueue, asink); - //g_signal_connect (G_OBJECT (gnl_compose_a), "pad-added", - // G_CALLBACK (_composition_pad_added_cb), aqueue); + //g_signal_connect (G_OBJECT (gnl_compose_a), "pad-added", + // G_CALLBACK (_composition_pad_added_cb), aqueue); - g_signal_connect (G_OBJECT (gnl_compose_v), "pad-added", - G_CALLBACK (_composition_pad_added_cb), vqueue); + g_signal_connect(G_OBJECT(gnl_compose_v), "pad-added", + G_CALLBACK(_composition_pad_added_cb), vqueue); - //g_idle_add (_play, pipe); - gst_element_set_state (GST_ELEMENT (pipe), GST_STATE_PLAYING); - g_main_loop_run (mainloop); + //g_idle_add (_play, pipe); + gst_element_set_state(GST_ELEMENT(pipe), GST_STATE_PLAYING); + g_main_loop_run(mainloop); - return 0; + return 0; }