diff -r a4529d0f8ede -r a6ac25bf88a7 gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Thu Jul 05 13:43:24 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Thu Aug 02 14:58:15 2007 +0100 @@ -11,13 +11,13 @@ #include #include #include +#include #include "gmencoder.h" #define G_MENCODER_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate)) -// #define SUPPORT_MULT_INPUT 0 #define USE_MANUAL_SINK typedef struct _GMencoderPrivate GMencoderPrivate; @@ -54,6 +54,13 @@ gint tick_id; gint64 duration; gboolean send_chunked; + + + //V4l info + GstElement *v4lsrc; + gchar *channel; + gchar *norm; + glong frequency; }; enum { @@ -92,7 +99,7 @@ static void _close_output(GMencoder * self); static gboolean _open_output(GMencoder * self, const gchar * uri); -static GstElement *_create_source(const gchar * uri); +static GstElement *_create_source(GMencoder *self, const gchar * uri); static GstElement *_create_pipeline(GMencoder * self, const gchar * video_encode, const gchar * mux_name, @@ -106,7 +113,7 @@ guint audio_rate, gboolean deinterlace); #ifdef USE_MANUAL_SINK -static void _flush_queue (GMencoder *self); +static void _flush_queue (GMencoder *self); static void _buffer_arrive_cb (GstElement* object, GstBuffer* buff, GstPad* pad, @@ -362,7 +369,7 @@ GstElement *vcolorspace = NULL; GstElement *vencode = NULL; GstElement *vrate = NULL; - GstElement *deinterlace = NULL; + GstElement *deinterlace = NULL; GstElement *walk = NULL; GstPad *vpad = NULL; @@ -372,10 +379,10 @@ gst_element_factory_make("ffmpegcolorspace", "colorspace"); if (use_deinterlace) { - deinterlace = gst_element_factory_make ("ffdeinterlace", "deinterlace"); - if (deinterlace == NULL) { - g_warning ("Fail to create deinterlace element: Continue without deinterlace."); - } + deinterlace = gst_element_factory_make ("ffdeinterlace", "deinterlace"); + if (deinterlace == NULL) { + g_warning ("Fail to create deinterlace element: Continue without deinterlace."); + } } @@ -517,8 +524,9 @@ } _close_output(self); - if (_open_output(self, out_uri) == FALSE) + if (_open_output(self, out_uri) == FALSE) { return FALSE; + } priv->sources = 0; priv->send_chunked = chunked; @@ -553,11 +561,7 @@ 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); + src = _create_source(self, uri); if (src == NULL) return FALSE; @@ -565,13 +569,8 @@ 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"); -#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"); @@ -694,7 +693,7 @@ guint video_height, const gchar * audio_encode, gchar ** audio_encode_prop, guint audio_rate, - gboolean deinterlace) + gboolean deinterlace) { GstBus *bus = NULL; GstElement *pipe = NULL; @@ -705,18 +704,9 @@ GstElement *queue = NULL; GstPad *aux_pad = NULL; GstPad *mux_pad = NULL; -#ifdef SUPPORT_MULT_INPUT - GstElement *ap = NULL; - GstElement *vp = NULL; -#endif 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); -#endif mux = gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"), "mux"); @@ -747,17 +737,6 @@ 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(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 = @@ -844,7 +823,30 @@ } static GstElement * -_create_source(const gchar * uri) +_create_v4l_source (GMencoder *self, const gchar * uri) +{ + gchar **info; + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self); + + + info = g_strsplit (uri+6, ":", 3); + if (g_strv_length (info) != 3) { + return NULL; + } + + priv->v4lsrc = gst_element_factory_make ("v4l2src", "src"); + g_debug ("channel %s, norm %s, frequ %s", info[0], info[1], info[2]); + g_object_set (G_OBJECT (priv->v4lsrc), + "channel", info[0], + "norm", info[1], + "frequency", atoi (info[2]), + NULL); + + return priv->v4lsrc; +} + +static GstElement * +_create_source(GMencoder *self, const gchar * uri) { GstElement *bsrc = NULL; @@ -860,7 +862,15 @@ // 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 (strncmp (uri, "v4l://", 6) == 0) { + g_debug ("V4L"); + src = _create_v4l_source (self, uri); + } + else { + g_debug ("SRC"); + src = gst_element_make_from_uri(GST_URI_SRC, uri, "src"); + } + if (src == NULL) goto error; @@ -900,6 +910,7 @@ return bsrc; error: + g_debug ("Fail to create source element"); if (src != NULL) { gst_object_unref(src); } @@ -929,10 +940,15 @@ i = g_strsplit(uri, "://", 0); if (strcmp(i[0], "fd") == 0) { result = gnome_vfs_open_fd (&priv->handle, atoi(i[1])); - } else { - result = gnome_vfs_open (&priv->handle, uri, - GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE); - + } else { + g_debug ("Teste file :%s", i[1]); + if (g_file_test (i[1], G_FILE_TEST_EXISTS) == FALSE) { + result = gnome_vfs_create (&priv->handle, uri, GNOME_VFS_OPEN_WRITE, TRUE, + GNOME_VFS_PERM_USER_WRITE | GNOME_VFS_PERM_USER_READ | GNOME_VFS_PERM_GROUP_READ); + } else { + result = gnome_vfs_open (&priv->handle, uri, + GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE); + } } g_strfreev(i); @@ -1119,15 +1135,15 @@ GnomeVFSFileSize bytes_written; gchar *end_msg; end_msg = g_strdup ("0\r\n\r\n"); - gnome_vfs_write (priv->handle, - (const guint8*) end_msg, + gnome_vfs_write (priv->handle, + (const guint8*) end_msg, strlen(end_msg) * sizeof(gchar), &bytes_written); g_free (end_msg); } } -static void +static void _buffer_arrive_cb (GstElement* object, GstBuffer* buff, GstPad* pad, @@ -1137,14 +1153,14 @@ if (priv->send_chunked) { - if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE) + if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE) goto error; } else { GnomeVFSResult result; GnomeVFSFileSize bytes_written; - result = gnome_vfs_write (priv->handle, - GST_BUFFER_DATA (buff), + result = gnome_vfs_write (priv->handle, + GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff), &bytes_written); @@ -1162,5 +1178,5 @@ g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, "Fail to write on socket"); gst_element_set_state (priv->pipe, GST_STATE_PAUSED); } -#endif +#endif