1.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c Tue May 08 14:54:37 2007 +0100
1.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Tue May 08 14:59:15 2007 +0100
1.3 @@ -14,6 +14,7 @@
1.4 #define G_MENCODER_GET_PRIVATE(obj) \
1.5 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate))
1.6
1.7 +//#define SUPPORT_MULT_INPUT 0
1.8
1.9 typedef struct _GMencoderPrivate GMencoderPrivate;
1.10 typedef struct _SetupInfo SetupInfo;
1.11 @@ -44,6 +45,7 @@
1.12 GstClockTime videot;
1.13 GstClockTime audiot;
1.14 gint fd;
1.15 + gint sources;
1.16 };
1.17
1.18 enum {
1.19 @@ -473,6 +475,10 @@
1.20 return;
1.21 }
1.22
1.23 + _close_output (self);
1.24 + _open_output (self, out_uri);
1.25 +
1.26 + priv->sources = 0;
1.27 priv->pipe = _create_pipeline (self,
1.28 video_encode,
1.29 mux_name,
1.30 @@ -485,8 +491,6 @@
1.31 audio_encode_prop,
1.32 audio_rate);
1.33
1.34 - _close_output (self);
1.35 - _open_output (self, out_uri);
1.36 }
1.37
1.38
1.39 @@ -494,27 +498,40 @@
1.40 g_mencoder_append_uri (GMencoder *self,
1.41 const gchar* uri)
1.42 {
1.43 - GstElement *ap;
1.44 - GstElement *vp;
1.45 GstPad *pad_src;
1.46 GstPad *pad_sink;
1.47 GstElement *src;
1.48 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
1.49 gboolean ret = FALSE;
1.50 + GstElement *ap = NULL;
1.51 + GstElement *vp = NULL;
1.52 +
1.53
1.54 g_return_val_if_fail (priv->pipe != NULL, FALSE);
1.55 g_return_val_if_fail (priv->ready == FALSE, FALSE);
1.56
1.57 +#ifndef SUPPORT_MULT_INPUT
1.58 + g_return_val_if_fail (priv->sources < 1, FALSE);
1.59 +#endif
1.60 +
1.61 src = _create_source (uri);
1.62 if (src == NULL)
1.63 return FALSE;
1.64
1.65 gst_bin_add (GST_BIN (priv->pipe), src);
1.66
1.67 +#ifdef SUPPORT_MULT_INPUT
1.68 ap = gst_bin_get_by_name (GST_BIN (priv->pipe), "ap");
1.69 vp = gst_bin_get_by_name (GST_BIN (priv->pipe), "vp");
1.70 - if ((vp == NULL) || (ap == NULL))
1.71 +#else
1.72 + ap = gst_bin_get_by_name (GST_BIN (priv->pipe), "abin");
1.73 + vp = gst_bin_get_by_name (GST_BIN (priv->pipe), "vbin");
1.74 +#endif
1.75 +
1.76 + if ((vp == NULL) || (ap == NULL)) {
1.77 + g_warning ("Fail to get output bin");
1.78 goto error;
1.79 + }
1.80
1.81 pad_src = gst_element_get_pad (src, "src_audio");
1.82 pad_sink = gst_element_get_compatible_pad (ap,
1.83 @@ -544,7 +561,9 @@
1.84 goto error;
1.85 }
1.86
1.87 + priv->sources++;
1.88 ret = TRUE;
1.89 + g_debug ("Uri: [%s] OK ", uri);
1.90 error:
1.91
1.92 if ((src != NULL) && (ret == FALSE)) {
1.93 @@ -602,6 +621,7 @@
1.94
1.95 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
1.96
1.97 + g_debug ("g_mencoder_close_stream");
1.98 if (priv->pipe != NULL) {
1.99 gst_element_set_state (priv->pipe, GST_STATE_NULL);
1.100 gst_object_unref (priv->pipe);
1.101 @@ -613,22 +633,6 @@
1.102 priv->ready = FALSE;
1.103 }
1.104
1.105 -static void
1.106 -_sink_handoff_cb (GstElement* object,
1.107 - GstBuffer* buf,
1.108 - GstPad* pad,
1.109 - gpointer user_data)
1.110 -{
1.111 - GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data);
1.112 - gint size = 0;
1.113 -
1.114 - size = write (priv->fd, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));
1.115 - if (size == -1) {
1.116 - g_signal_emit (user_data, g_mencoder_signals[ERROR], 0, "Fail to write output");
1.117 - }
1.118 -}
1.119 -
1.120 -
1.121 static GstElement*
1.122 _create_pipeline (GMencoder *self,
1.123 const gchar* video_encode,
1.124 @@ -648,27 +652,34 @@
1.125 GstElement *mux = NULL;
1.126 GstElement *abin = NULL;
1.127 GstElement *vbin = NULL;
1.128 + GstPad *aux_pad = NULL;
1.129 + GstPad *mux_pad = NULL;
1.130 +#ifdef SUPPORT_MULT_INPUT
1.131 GstElement *ap = NULL;
1.132 GstElement *vp = NULL;
1.133 - GstPad *aux_pad = NULL;
1.134 - GstPad *mux_pad = NULL;
1.135 +#endif
1.136 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
1.137
1.138 pipe = gst_pipeline_new ("pipe");
1.139
1.140 - ap = gst_element_factory_make ("concatmux", "ap");
1.141 +#ifdef SUPPORT_MULT_INPUT
1.142 + ap = gst_element_factory_make ("concatmux", "ap");
1.143 vp = gst_element_factory_make ("concatmux", "vp");
1.144 + gst_bin_add_many (GST_BIN (pipe), ap, vp, NULL);
1.145 +#endif
1.146
1.147 mux = gst_element_factory_make ((mux_name ? mux_name : "ffmux_mpeg"), "mux");
1.148 if (mux == NULL)
1.149 goto error;
1.150
1.151 - sink = gst_element_factory_make ("fakesink", "sink");
1.152 +
1.153 + sink = gst_element_factory_make ("fdsink", "sink");
1.154 if (sink == NULL)
1.155 goto error;
1.156
1.157 g_object_set (G_OBJECT(sink),
1.158 - "sync", FALSE,
1.159 - "signal-handoffs", TRUE, NULL);
1.160 + "fd", priv->fd,
1.161 + NULL);
1.162
1.163 abin = _create_audio_bin (audio_encode, audio_encode_prop, audio_rate);
1.164 if (abin == NULL)
1.165 @@ -679,16 +690,19 @@
1.166 goto error;
1.167
1.168 // Finish Pipe
1.169 - gst_bin_add_many (GST_BIN (pipe), ap, abin, vp, vbin, mux, sink, NULL);
1.170 + gst_bin_add_many (GST_BIN (pipe), abin, vbin, mux, sink, NULL);
1.171
1.172 - if (gst_element_link (ap, abin) == FALSE) {
1.173 - g_warning ("Fail to link concat and abin");
1.174 - goto error;
1.175 - }
1.176
1.177 - if (gst_element_link (vp, vbin) == FALSE) {
1.178 - g_warning ("Fail to link concat and vbin");
1.179 - }
1.180 +#ifdef SUPPORT_MULT_INPUT
1.181 + if (gst_element_link (ap, abin) == FALSE) {
1.182 + g_warning ("Fail to link concat and abin");
1.183 + goto error;
1.184 + }
1.185 +
1.186 + if (gst_element_link (vp, vbin) == FALSE) {
1.187 + g_warning ("Fail to link concat and vbin");
1.188 + }
1.189 +#endif
1.190
1.191 //Link bins with mux
1.192 aux_pad = gst_element_get_pad (abin, "src");
1.193 @@ -725,11 +739,6 @@
1.194 //Link mux with sink
1.195 gst_element_link (mux, sink);
1.196
1.197 - g_signal_connect (G_OBJECT (sink),
1.198 - "handoff",
1.199 - G_CALLBACK (_sink_handoff_cb),
1.200 - self);
1.201 -
1.202 bus = gst_pipeline_get_bus (GST_PIPELINE (pipe));
1.203 gst_bus_add_watch (bus, _pipeline_bus_cb, self);
1.204 gst_object_unref (bus);
1.205 @@ -791,8 +800,9 @@
1.206
1.207 bsrc = gst_bin_new (NULL);
1.208
1.209 - src = gst_element_factory_make ("gnomevfssrc", "src");
1.210 - g_object_set (G_OBJECT (src), "location", uri, NULL);
1.211 + //src = gst_element_factory_make ("gnomevfssrc", "src");
1.212 + //g_object_set (G_OBJECT (src), "location", uri, NULL);
1.213 + src = gst_element_make_from_uri (GST_URI_SRC, uri, "src");
1.214 if (src == NULL)
1.215 goto error;
1.216
1.217 @@ -948,6 +958,7 @@
1.218
1.219 caps = gst_pad_get_caps (pad);
1.220 str_caps = gst_caps_to_string (caps);
1.221 + g_debug ("New pad : %s", str_caps);
1.222 if (strstr (str_caps, "audio") != NULL) {
1.223 sink_element = gst_bin_get_by_name (GST_BIN (user_data), "aqueue");
1.224 } else if (strstr (str_caps, "video") != NULL) {
2.1 --- a/gmyth-stream/gmemcoder/src/main.c Tue May 08 14:54:37 2007 +0100
2.2 +++ b/gmyth-stream/gmemcoder/src/main.c Tue May 08 14:59:15 2007 +0100
2.3 @@ -37,6 +37,7 @@
2.4 _mencoder_error_cb (GMencoder *mencoder, const gchar* msg, gpointer data)
2.5 {
2.6 g_print ("Error: %s\n", msg);
2.7 + g_mencoder_close_stream (mencoder);
2.8 g_main_loop_quit ((GMainLoop *) data);
2.9 }
2.10
2.11 @@ -151,10 +152,8 @@
2.12
2.13 g_debug ("RUNNING..");
2.14 g_main_loop_run (mainloop);
2.15 -
2.16 - g_mencoder_close_stream (coder);
2.17 + g_debug ("DONE");
2.18 g_object_unref (coder);
2.19
2.20 -
2.21 return 0;
2.22 }