diff -r a76074f53743 -r b937c837e929 gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Tue May 01 23:02:19 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Fri May 11 14:41:11 2007 +0100 @@ -14,6 +14,7 @@ #define G_MENCODER_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate)) +//#define SUPPORT_MULT_INPUT 0 typedef struct _GMencoderPrivate GMencoderPrivate; typedef struct _SetupInfo SetupInfo; @@ -44,6 +45,7 @@ GstClockTime videot; GstClockTime audiot; gint fd; + gint sources; }; enum { @@ -473,6 +475,10 @@ return; } + _close_output (self); + _open_output (self, out_uri); + + priv->sources = 0; priv->pipe = _create_pipeline (self, video_encode, mux_name, @@ -485,8 +491,6 @@ audio_encode_prop, audio_rate); - _close_output (self); - _open_output (self, out_uri); } @@ -494,27 +498,40 @@ g_mencoder_append_uri (GMencoder *self, const gchar* uri) { - GstElement *ap; - GstElement *vp; 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); +#ifndef SUPPORT_MULT_INPUT + g_return_val_if_fail (priv->sources < 1, FALSE); +#endif + src = _create_source (uri); if (src == NULL) return FALSE; 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"); - if ((vp == NULL) || (ap == NULL)) +#else + 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; + } pad_src = gst_element_get_pad (src, "src_audio"); pad_sink = gst_element_get_compatible_pad (ap, @@ -544,7 +561,9 @@ goto error; } + priv->sources++; ret = TRUE; + g_debug ("Uri: [%s] OK ", uri); error: if ((src != NULL) && (ret == FALSE)) { @@ -602,6 +621,7 @@ GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); + g_debug ("g_mencoder_close_stream"); if (priv->pipe != NULL) { gst_element_set_state (priv->pipe, GST_STATE_NULL); gst_object_unref (priv->pipe); @@ -613,22 +633,6 @@ priv->ready = FALSE; } -static void -_sink_handoff_cb (GstElement* object, - GstBuffer* buf, - GstPad* pad, - gpointer user_data) -{ - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data); - gint size = 0; - - size = write (priv->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf)); - if (size == -1) { - g_signal_emit (user_data, g_mencoder_signals[ERROR], 0, "Fail to write output"); - } -} - - static GstElement* _create_pipeline (GMencoder *self, const gchar* video_encode, @@ -648,27 +652,34 @@ GstElement *mux = NULL; GstElement *abin = NULL; GstElement *vbin = NULL; + GstPad *aux_pad = NULL; + GstPad *mux_pad = NULL; +#ifdef SUPPORT_MULT_INPUT GstElement *ap = NULL; GstElement *vp = NULL; - GstPad *aux_pad = NULL; - GstPad *mux_pad = NULL; +#endif + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); pipe = gst_pipeline_new ("pipe"); - 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); +#endif mux = gst_element_factory_make ((mux_name ? mux_name : "ffmux_mpeg"), "mux"); if (mux == NULL) goto error; - sink = gst_element_factory_make ("fakesink", "sink"); + + sink = gst_element_factory_make ("fdsink", "sink"); if (sink == NULL) goto error; g_object_set (G_OBJECT(sink), - "sync", FALSE, - "signal-handoffs", TRUE, NULL); + "fd", priv->fd, + NULL); abin = _create_audio_bin (audio_encode, audio_encode_prop, audio_rate); if (abin == NULL) @@ -679,16 +690,19 @@ goto error; // Finish Pipe - gst_bin_add_many (GST_BIN (pipe), ap, abin, vp, vbin, mux, sink, NULL); + gst_bin_add_many (GST_BIN (pipe), abin, vbin, mux, sink, NULL); - 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"); - } +#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 //Link bins with mux aux_pad = gst_element_get_pad (abin, "src"); @@ -725,11 +739,6 @@ //Link mux with sink gst_element_link (mux, sink); - g_signal_connect (G_OBJECT (sink), - "handoff", - G_CALLBACK (_sink_handoff_cb), - self); - bus = gst_pipeline_get_bus (GST_PIPELINE (pipe)); gst_bus_add_watch (bus, _pipeline_bus_cb, self); gst_object_unref (bus); @@ -791,8 +800,9 @@ bsrc = gst_bin_new (NULL); - src = gst_element_factory_make ("gnomevfssrc", "src"); - g_object_set (G_OBJECT (src), "location", uri, 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; @@ -948,6 +958,7 @@ caps = gst_pad_get_caps (pad); str_caps = gst_caps_to_string (caps); + g_debug ("New pad : %s", str_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) {