[svn r795] - fixed bug on transcode operation; trunk
authorrenatofilho
Wed Aug 01 14:22:14 2007 +0100 (2007-08-01)
branchtrunk
changeset 789f9cd59844f78
parent 788 357b301e2d23
child 790 7a914b3fafc1
[svn r795] - fixed bug on transcode operation;
- some code clean;
gmyth-stream/gmemcoder/src/Makefile.am
gmyth-stream/gmemcoder/src/gmencoder.c
gmyth-stream/gmemcoder/src/main.c
     1.1 --- a/gmyth-stream/gmemcoder/src/Makefile.am	Tue Jul 17 23:17:09 2007 +0100
     1.2 +++ b/gmyth-stream/gmemcoder/src/Makefile.am	Wed Aug 01 14:22:14 2007 +0100
     1.3 @@ -9,7 +9,8 @@
     1.4  gmencoder_LDADD = \
     1.5  	$(GLIB_LIBS) \
     1.6  	$(GST_LIBS) \
     1.7 -	$(GVFS_LIBS)
     1.8 +	$(GVFS_LIBS) \
     1.9 +	-lgstinterfaces-0.10
    1.10  
    1.11  AM_CPPFLAGS = \
    1.12  	$(GLIB_CFLAGS) \
     2.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c	Tue Jul 17 23:17:09 2007 +0100
     2.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c	Wed Aug 01 14:22:14 2007 +0100
     2.3 @@ -11,13 +11,13 @@
     2.4  #include <sys/types.h>
     2.5  #include <sys/socket.h>
     2.6  #include <libgnomevfs/gnome-vfs.h>
     2.7 +#include <gst/interfaces/tuner.h>
     2.8  
     2.9  #include "gmencoder.h"
    2.10  
    2.11  #define G_MENCODER_GET_PRIVATE(obj) \
    2.12      (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate))
    2.13  
    2.14 -// #define SUPPORT_MULT_INPUT 0
    2.15  #define USE_MANUAL_SINK
    2.16  
    2.17  typedef struct _GMencoderPrivate GMencoderPrivate;
    2.18 @@ -54,6 +54,13 @@
    2.19      gint            tick_id;
    2.20      gint64          duration;
    2.21      gboolean        send_chunked;
    2.22 +
    2.23 +
    2.24 +    //V4l info
    2.25 +    GstElement *v4lsrc;
    2.26 +    gchar *channel;
    2.27 +    gchar *norm;
    2.28 +    glong frequency;
    2.29  };
    2.30  
    2.31  enum {
    2.32 @@ -92,7 +99,7 @@
    2.33  static void     _close_output(GMencoder * self);
    2.34  static gboolean _open_output(GMencoder * self, const gchar * uri);
    2.35  
    2.36 -static GstElement *_create_source(const gchar * uri);
    2.37 +static GstElement *_create_source(GMencoder *self, const gchar * uri);
    2.38  static GstElement *_create_pipeline(GMencoder * self,
    2.39                                      const gchar * video_encode,
    2.40                                      const gchar * mux_name,
    2.41 @@ -106,7 +113,7 @@
    2.42                                      guint audio_rate,
    2.43  				    gboolean deinterlace);
    2.44  #ifdef USE_MANUAL_SINK
    2.45 -static void _flush_queue 	    (GMencoder *self);
    2.46 +static void _flush_queue	        (GMencoder *self);
    2.47  static void _buffer_arrive_cb       (GstElement* object,
    2.48                                       GstBuffer* buff,
    2.49                                       GstPad* pad,
    2.50 @@ -362,7 +369,7 @@
    2.51      GstElement     *vcolorspace = NULL;
    2.52      GstElement     *vencode = NULL;
    2.53      GstElement     *vrate = NULL;
    2.54 -    GstElement 	   *deinterlace = NULL;
    2.55 +    GstElement	   *deinterlace = NULL;
    2.56      GstElement     *walk = NULL;
    2.57      GstPad         *vpad = NULL;
    2.58  
    2.59 @@ -372,10 +379,10 @@
    2.60          gst_element_factory_make("ffmpegcolorspace", "colorspace");
    2.61  
    2.62      if (use_deinterlace) {
    2.63 -	deinterlace = gst_element_factory_make ("ffdeinterlace", "deinterlace");
    2.64 -	if (deinterlace == NULL) {
    2.65 -	    g_warning ("Fail to create deinterlace element: Continue without deinterlace.");
    2.66 -	} 
    2.67 +        deinterlace = gst_element_factory_make ("ffdeinterlace", "deinterlace");
    2.68 +	    if (deinterlace == NULL) {
    2.69 +	        g_warning ("Fail to create deinterlace element: Continue without deinterlace.");
    2.70 +        }
    2.71      }
    2.72  
    2.73  
    2.74 @@ -517,8 +524,9 @@
    2.75      }
    2.76  
    2.77      _close_output(self);
    2.78 -    if (_open_output(self, out_uri) == FALSE)
    2.79 +    if (_open_output(self, out_uri) == FALSE) {
    2.80          return FALSE;
    2.81 +    }
    2.82  
    2.83      priv->sources = 0;
    2.84      priv->send_chunked = chunked;
    2.85 @@ -553,11 +561,7 @@
    2.86      g_return_val_if_fail(priv->pipe != NULL, FALSE);
    2.87      g_return_val_if_fail(priv->ready == FALSE, FALSE);
    2.88  
    2.89 -#ifndef SUPPORT_MULT_INPUT
    2.90 -    g_return_val_if_fail(priv->sources < 1, FALSE);
    2.91 -#endif
    2.92 -
    2.93 -    src = _create_source(uri);
    2.94 +    src = _create_source(self, uri);
    2.95      if (src == NULL)
    2.96          return FALSE;
    2.97  
    2.98 @@ -565,13 +569,8 @@
    2.99  
   2.100      gst_bin_add(GST_BIN(priv->pipe), src);
   2.101  
   2.102 -#ifdef SUPPORT_MULT_INPUT
   2.103 -    ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "ap");
   2.104 -    vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vp");
   2.105 -#else
   2.106      ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "abin");
   2.107      vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vbin");
   2.108 -#endif
   2.109  
   2.110      if ((vp == NULL) || (ap == NULL)) {
   2.111          g_warning("Fail to get output bin");
   2.112 @@ -694,7 +693,7 @@
   2.113                   guint video_height,
   2.114                   const gchar * audio_encode,
   2.115                   gchar ** audio_encode_prop, guint audio_rate,
   2.116 -	     	 gboolean deinterlace)
   2.117 +		         gboolean deinterlace)
   2.118  {
   2.119      GstBus         *bus = NULL;
   2.120      GstElement     *pipe = NULL;
   2.121 @@ -705,18 +704,9 @@
   2.122      GstElement     *queue = NULL;
   2.123      GstPad         *aux_pad = NULL;
   2.124      GstPad         *mux_pad = NULL;
   2.125 -#ifdef SUPPORT_MULT_INPUT
   2.126 -    GstElement     *ap = NULL;
   2.127 -    GstElement     *vp = NULL;
   2.128 -#endif
   2.129  
   2.130      pipe = gst_pipeline_new("pipe");
   2.131  
   2.132 -#ifdef SUPPORT_MULT_INPUT
   2.133 -    ap = gst_element_factory_make("concatmux", "ap");
   2.134 -    vp = gst_element_factory_make("concatmux", "vp");
   2.135 -    gst_bin_add_many(GST_BIN(pipe), ap, vp, NULL);
   2.136 -#endif
   2.137      mux =
   2.138          gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"),
   2.139                                   "mux");
   2.140 @@ -747,17 +737,6 @@
   2.141      gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, sink, NULL);
   2.142  
   2.143  
   2.144 -#ifdef SUPPORT_MULT_INPUT
   2.145 -    if (gst_element_link(ap, abin) == FALSE) {
   2.146 -        g_warning("Fail to link concat and abin");
   2.147 -        goto error;
   2.148 -    }
   2.149 -
   2.150 -    if (gst_element_link(vp, vbin) == FALSE) {
   2.151 -        g_warning("Fail to link concat and vbin");
   2.152 -    }
   2.153 -#endif
   2.154 -
   2.155      // Link bins with mux
   2.156      aux_pad = gst_element_get_pad(abin, "src");
   2.157      mux_pad =
   2.158 @@ -844,7 +823,30 @@
   2.159  }
   2.160  
   2.161  static GstElement *
   2.162 -_create_source(const gchar * uri)
   2.163 +_create_v4l_source (GMencoder *self, const gchar * uri)
   2.164 +{
   2.165 +    gchar **info;
   2.166 +    GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
   2.167 +
   2.168 +
   2.169 +    info = g_strsplit (uri+6, ":", 3);
   2.170 +    if (g_strv_length (info) != 3) {
   2.171 +        return NULL;
   2.172 +    }
   2.173 +
   2.174 +    priv->v4lsrc = gst_element_factory_make ("v4l2src", "src");
   2.175 +    g_debug ("channel %s, norm %s, frequ %s", info[0], info[1], info[2]);
   2.176 +    g_object_set (G_OBJECT (priv->v4lsrc),
   2.177 +                  "channel", info[0],
   2.178 +                  "norm", info[1],
   2.179 +                  "frequency", atoi (info[2]),
   2.180 +                  NULL);
   2.181 +
   2.182 +    return priv->v4lsrc;
   2.183 +}
   2.184 +
   2.185 +static GstElement *
   2.186 +_create_source(GMencoder *self, const gchar * uri)
   2.187  {
   2.188  
   2.189      GstElement     *bsrc = NULL;
   2.190 @@ -860,7 +862,15 @@
   2.191  
   2.192      // src = gst_element_factory_make ("gnomevfssrc", "src");
   2.193      // g_object_set (G_OBJECT (src), "location", uri, NULL);
   2.194 -    src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
   2.195 +    if (strncmp (uri, "v4l://", 6) == 0) {
   2.196 +        g_debug ("V4L");
   2.197 +        src = _create_v4l_source (self, uri);
   2.198 +    }
   2.199 +    else {
   2.200 +        g_debug ("SRC");
   2.201 +        src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
   2.202 +    }
   2.203 +
   2.204      if (src == NULL)
   2.205          goto error;
   2.206  
   2.207 @@ -900,6 +910,7 @@
   2.208      return bsrc;
   2.209  
   2.210    error:
   2.211 +    g_debug ("Fail to create source element");
   2.212      if (src != NULL) {
   2.213          gst_object_unref(src);
   2.214      }
   2.215 @@ -929,10 +940,15 @@
   2.216      i = g_strsplit(uri, "://", 0);
   2.217      if (strcmp(i[0], "fd") == 0) {
   2.218          result = gnome_vfs_open_fd (&priv->handle, atoi(i[1]));
   2.219 -    } else { 
   2.220 -        result = gnome_vfs_open (&priv->handle, uri, 
   2.221 -                                 GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE);
   2.222 -
   2.223 +    } else {
   2.224 +        g_debug ("Teste file :%s", i[1]);
   2.225 +        if (g_file_test (i[1], G_FILE_TEST_EXISTS) == FALSE) {
   2.226 +            result = gnome_vfs_create (&priv->handle, uri, GNOME_VFS_OPEN_WRITE, TRUE,
   2.227 +                              GNOME_VFS_PERM_USER_WRITE | GNOME_VFS_PERM_USER_READ | GNOME_VFS_PERM_GROUP_READ);
   2.228 +        } else {
   2.229 +            result = gnome_vfs_open (&priv->handle, uri,
   2.230 +                                     GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE);
   2.231 +        }
   2.232      }
   2.233  
   2.234      g_strfreev(i);
   2.235 @@ -1119,15 +1135,15 @@
   2.236          GnomeVFSFileSize bytes_written;
   2.237          gchar *end_msg;
   2.238          end_msg = g_strdup ("0\r\n\r\n");
   2.239 -        gnome_vfs_write (priv->handle, 
   2.240 -                         (const guint8*) end_msg, 
   2.241 +        gnome_vfs_write (priv->handle,
   2.242 +                         (const guint8*) end_msg,
   2.243                           strlen(end_msg) * sizeof(gchar),
   2.244                           &bytes_written);
   2.245          g_free (end_msg);
   2.246      }
   2.247  }
   2.248  
   2.249 -static void 
   2.250 +static void
   2.251  _buffer_arrive_cb (GstElement* object,
   2.252                     GstBuffer* buff,
   2.253                     GstPad* pad,
   2.254 @@ -1137,14 +1153,14 @@
   2.255  
   2.256  
   2.257      if (priv->send_chunked) {
   2.258 -        if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE) 
   2.259 +        if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE)
   2.260              goto error;
   2.261      } else {
   2.262          GnomeVFSResult result;
   2.263          GnomeVFSFileSize bytes_written;
   2.264  
   2.265 -        result = gnome_vfs_write (priv->handle, 
   2.266 -                                  GST_BUFFER_DATA (buff), 
   2.267 +        result = gnome_vfs_write (priv->handle,
   2.268 +                                  GST_BUFFER_DATA (buff),
   2.269                                    GST_BUFFER_SIZE (buff),
   2.270                                    &bytes_written);
   2.271  
   2.272 @@ -1162,5 +1178,5 @@
   2.273      g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, "Fail to write on socket");
   2.274      gst_element_set_state (priv->pipe, GST_STATE_PAUSED);
   2.275  }
   2.276 -#endif 
   2.277  
   2.278 +#endif
     3.1 --- a/gmyth-stream/gmemcoder/src/main.c	Tue Jul 17 23:17:09 2007 +0100
     3.2 +++ b/gmyth-stream/gmemcoder/src/main.c	Wed Aug 01 14:22:14 2007 +0100
     3.3 @@ -5,6 +5,7 @@
     3.4  
     3.5  #include <gst/gst.h>
     3.6  #include <glib.h>
     3.7 +#include <libgnomevfs/gnome-vfs.h>
     3.8  
     3.9  #include "gmencoder.h"
    3.10  
    3.11 @@ -135,6 +136,7 @@
    3.12  
    3.13      g_type_init();
    3.14      g_thread_init(NULL);
    3.15 +    gnome_vfs_init ();
    3.16      mainloop = g_main_loop_new(NULL, FALSE);
    3.17  
    3.18      g_set_prgname("gmemcoder");
    3.19 @@ -170,7 +172,6 @@
    3.20      else
    3.21          vopts = NULL;
    3.22  
    3.23 -    
    3.24      ret = g_mencoder_setup_stream(coder, chunked, deinterlace, mux_name,
    3.25                                    video_encode, vopts, video_fps,
    3.26                                    video_rate, video_width, video_height,