diff -r 8d28bf09d12f -r bf9dac4bdc5d gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Fri May 25 14:14:18 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Tue Jun 12 22:13:46 2007 +0100 @@ -27,7 +27,7 @@ gdouble video_fps; gdouble video_rate; guint video_width; - guint video_height; + guint video_height; gchar* audio_encode; gchar** audio_encode_prop; guint audio_rate; @@ -35,80 +35,80 @@ struct _GMencoderPrivate -{ - GstElement *pipe; - GstElement *abin; - GstElement *vbin; - GstElement *sink; - GstElement *src; - gboolean ready; +{ + 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; + gint sources; + gint tick_id; + gint64 duration; }; enum { - PAUSED, - PLAYING, - STOPED, - EOS, - ERROR, - LAST_SIGNAL + 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 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); +_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); +_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); -static void _decodebin_new_pad_cb (GstElement* object, - GstPad* pad, - gboolean flag, - gpointer user_data); +static gboolean +_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_unknown_type_cb (GstElement* object, - GstPad* pad, + GstPad* pad, GstCaps* caps, gpointer user_data); + static void _close_output (GMencoder *self); static void _open_output (GMencoder *self, - const gchar* uri); + 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 gboolean _tick_cb (gpointer data); + 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 guint g_mencoder_signals[LAST_SIGNAL] = { 0 }; @@ -116,78 +116,75 @@ static void g_mencoder_class_init (GMencoderClass *klass) -{ - GObjectClass *object_class; +{ + GObjectClass *object_class; + object_class = (GObjectClass *) klass; + g_type_class_add_private (klass, sizeof (GMencoderPrivate)); - object_class = (GObjectClass *) klass; + object_class->dispose = g_mencoder_dispose; + object_class->finalize = g_mencoder_finalize; - g_type_class_add_private (klass, sizeof (GMencoderPrivate)); - - 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_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_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_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_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_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) { - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); priv->info = g_new0 (SetupInfo, 1); } -static void +static void g_mencoder_dispose (GObject *object) { } -static void +static void g_mencoder_finalize (GObject *object) { //TODO: clear vars - g_mencoder_close_stream (G_MENCODER (object)); + g_mencoder_close_stream (G_MENCODER (object)); } -GMencoder* +GMencoder* g_mencoder_new (void) { return g_object_new (G_TYPE_MENCODER, NULL); @@ -195,9 +192,9 @@ 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}; @@ -215,8 +212,8 @@ } g_value_init (&p, s->value_type); - switch (s->value_type) - { + switch (s->value_type) + { case G_TYPE_INT: g_value_set_int (&p, atoi (prop_val)); break; @@ -225,8 +222,8 @@ break; default: return; - } - + } + g_object_set_property (obj, prop_name, &p); g_value_unset (&v); g_value_unset (&p); @@ -234,8 +231,8 @@ static GstElement* _create_element_with_prop (const gchar* factory_name, - const gchar* element_name, - gchar** prop) + const gchar* element_name, + gchar** prop) { GstElement *ret; int i; @@ -246,13 +243,13 @@ if (prop != NULL) { for (i=0; i < g_strv_length (prop); i++) { - if (prop[i] != NULL) { + 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]); - } + _obj_set_prop (G_OBJECT (ret), v[0], v[1]); + } g_strfreev (v); - } + } } } @@ -272,58 +269,58 @@ 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); - } + 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) { + 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); - - apad = gst_element_get_pad (aqueue_src, "src"); - gst_element_add_pad (abin, gst_ghost_pad_new("src", 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); return abin; -error: - if (abin != NULL) - gst_object_unref (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); @@ -337,11 +334,11 @@ //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) + gchar** encode_prop, + gdouble fps, + gint rate, + guint width, + guint height) { GstElement *vbin = NULL; GstElement *vqueue = NULL; @@ -351,38 +348,37 @@ 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; - } - - gst_bin_add_many (GST_BIN (vbin), vqueue, vcolorspace, vencode, vqueue_src, NULL); + if ((vbin == NULL) || (vqueue == NULL) || (vcolorspace == NULL) + || (vencode == NULL) || (vqueue_src == NULL)) { + g_warning ("Video elements not found"); + goto error; + } - - if ((width > 0) && (height > 0)) { + 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"); + GstElement *vscale = gst_element_factory_make ("videoscale", "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); + "width", G_TYPE_INT, width, + "height", G_TYPE_INT, height, + NULL); gst_element_link (vqueue, vscale); - + if (gst_element_link_filtered (vscale, vcolorspace, vcaps) == FALSE) { g_warning ("Fail to resize video"); gst_object_unref (vcaps); @@ -393,7 +389,6 @@ } else { gst_element_link (vqueue, vcolorspace); } - if (fps > 0) { //Changing the video fps @@ -403,16 +398,16 @@ gst_bin_add (GST_BIN (vbin), vrate); if (gst_element_link (vcolorspace, vrate) == FALSE) { - g_warning ("Fail to link video elements"); - goto error; + 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); + "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; + if (gst_element_link_filtered (vrate, vencode, vcaps) == FALSE) { + g_warning ("Fail to link vrate with vencode."); + goto error; } gst_caps_unref (vcaps); } else { @@ -421,35 +416,35 @@ goto error; } } - + 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); - - vpad = gst_element_get_pad (vqueue_src, "src"); - gst_element_add_pad (vbin, gst_ghost_pad_new ("src", 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); return vbin; -error: + 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); @@ -460,14 +455,14 @@ void -g_mencoder_setup_stream (GMencoder *self, +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, + guint video_width, + guint video_height, const gchar* audio_encode, gchar** audio_encode_prop, guint audio_rate, @@ -482,25 +477,25 @@ _close_output (self); _open_output (self, out_uri); - priv->sources = 0; + 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); + 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) + const gchar* uri) { GstPad *pad_src; GstPad *pad_sink; @@ -515,14 +510,14 @@ 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) + 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); @@ -535,14 +530,14 @@ #endif if ((vp == NULL) || (ap == NULL)) { - g_warning ("Fail to get output bin"); + 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_sink = gst_element_get_compatible_pad (ap, + pad_src, + gst_pad_get_caps (pad_src)); if ((pad_sink == NULL) || (pad_src == NULL)) goto error; @@ -555,9 +550,9 @@ 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_sink = gst_element_get_compatible_pad (vp, + pad_src, + gst_pad_get_caps (pad_src)); if ((pad_src == NULL) || (pad_sink == NULL)) goto error; @@ -567,16 +562,16 @@ goto error; } - priv->sources++; + priv->sources++; ret = TRUE; -error: + error: if ((src != NULL) && (ret == FALSE)) { gst_bin_remove (GST_BIN (priv->pipe), src); gst_object_unref (src); } - if (ap != NULL) + if (ap != NULL) gst_object_unref (ap); if (vp != NULL) @@ -593,9 +588,9 @@ -void +void g_mencoder_remove_uri (GMencoder *self, - const gchar* uri) + const gchar* uri) { // GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); //TODO: remove src @@ -605,19 +600,16 @@ 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); + priv->tick_id = g_timeout_add (500, _tick_cb, self); } void 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); } @@ -627,20 +619,19 @@ { GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); + 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; - } - - if (priv->pipe != NULL) { - //TODO: fixe pipeline dispose - g_debug ("SETING STATE TO NULL"); + if (priv->pipe != NULL) { + //TODO: fixe pipeline dispose + g_debug ("SETING STATE TO NULL"); //gst_element_set_state (priv->pipe, GST_STATE_NULL); - g_debug ("SETING STATE TO NULL: OK"); + g_debug ("SETING STATE TO NULL: OK"); //gst_object_unref (priv->pipe); gst_object_unref (priv->src); - priv->src = NULL; + priv->src = NULL; priv->pipe = NULL; priv->abin = NULL; priv->vbin = NULL; @@ -656,8 +647,8 @@ gchar** video_encode_prop, gdouble video_fps, gdouble video_rate, - guint video_width, - guint video_height, + guint video_width, + guint video_height, const gchar* audio_encode, gchar** audio_encode_prop, guint audio_rate) @@ -667,22 +658,22 @@ GstElement *sink = NULL; GstElement *mux = NULL; GstElement *abin = NULL; - GstElement *vbin = 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 *vp = NULL; #endif 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"); +#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); + gst_bin_add_many (GST_BIN (pipe), ap, vp, NULL); #endif mux = gst_element_factory_make ((mux_name ? mux_name : "ffmux_mpeg"), "mux"); @@ -696,10 +687,10 @@ 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) @@ -709,20 +700,20 @@ if (vbin == NULL) goto error; - // Finish Pipe + // 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; - } +#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 (vp, vbin) == FALSE) { - g_warning ("Fail to link concat and vbin"); - } -#endif + 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"); @@ -735,9 +726,9 @@ 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 (aux_pad); gst_object_unref (mux_pad); aux_pad = gst_element_get_pad (vbin, "src"); @@ -759,16 +750,16 @@ //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); + 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"); - if (pipe != NULL) { - gst_object_unref (pipe); + error: + g_warning ("Invalid uri"); + + if (pipe != NULL) { + gst_object_unref (pipe); } @@ -784,8 +775,8 @@ gst_object_unref (mux_pad); } - if (sink != NULL) { - gst_object_unref (sink); + if (sink != NULL) { + gst_object_unref (sink); } if (abin != NULL) { @@ -796,14 +787,13 @@ gst_object_unref (vbin); } - return FALSE; + return FALSE; } static void _close_output (GMencoder *self) { - } static GstElement* @@ -821,15 +811,15 @@ bsrc = gst_bin_new (NULL); - //src = gst_element_factory_make ("gnomevfssrc", "src"); + //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_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"); @@ -843,48 +833,48 @@ 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_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_element_add_pad (bsrc, gst_ghost_pad_new("src_video", src_pad)); gst_object_unref (src_pad); 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; } static void -_open_output (GMencoder *self, +_open_output (GMencoder *self, const gchar* uri) { gchar** i; @@ -907,113 +897,116 @@ 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 ((oldstate == GST_STATE_READY) && + if ((oldstate == GST_STATE_READY) && (newstate == GST_STATE_PAUSED)) { - if (priv->ready) - g_signal_emit (user_data, g_mencoder_signals[PAUSED], 0); + 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); + 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); - } + g_signal_emit (user_data, g_mencoder_signals[STOPED], 0); + } break; - } - 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; - } - - gst_message_parse_error (msg, &error, &debug); - err_str = g_strdup_printf ("Error [%d] %s (%s)", error->code, - error->message, - debug); + 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; + } + + 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: + 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_DURATION: - { - GstFormat format; - gint64 duration; - gst_message_parse_duration (msg, &format, &duration); - if (format == GST_FORMAT_BYTES) - priv->duration = duration; - break; - } - default: - { - break; - } + 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; + } } - return TRUE; + return TRUE; } -static void +static void _decodebin_new_pad_cb (GstElement* object, GstPad* pad, gboolean flag, gpointer user_data) { - GstCaps *caps; - gchar *str_caps = NULL; + 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) { + 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) { + } 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); - } + } else { + g_warning ("invalid caps %s", str_caps); + } sink_pad = gst_element_get_pad (sink_element, "sink"); - gst_pad_link (pad, sink_pad); + 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_pad); + g_free (str_caps); + gst_caps_unref (caps); } -static void +static void _decodebin_unknown_type_cb (GstElement* object, GstPad* pad, GstCaps* caps, @@ -1026,21 +1019,21 @@ static gboolean _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; }