1.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c Thu Jul 05 13:43:24 2007 +0100
1.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Fri Aug 03 21:43:42 2007 +0100
1.3 @@ -11,13 +11,13 @@
1.4 #include <sys/types.h>
1.5 #include <sys/socket.h>
1.6 #include <libgnomevfs/gnome-vfs.h>
1.7 +#include <gst/interfaces/tuner.h>
1.8
1.9 #include "gmencoder.h"
1.10
1.11 #define G_MENCODER_GET_PRIVATE(obj) \
1.12 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate))
1.13
1.14 -// #define SUPPORT_MULT_INPUT 0
1.15 #define USE_MANUAL_SINK
1.16
1.17 typedef struct _GMencoderPrivate GMencoderPrivate;
1.18 @@ -54,6 +54,13 @@
1.19 gint tick_id;
1.20 gint64 duration;
1.21 gboolean send_chunked;
1.22 +
1.23 +
1.24 + //V4l info
1.25 + GstElement *v4lsrc;
1.26 + gchar *channel;
1.27 + gchar *norm;
1.28 + glong frequency;
1.29 };
1.30
1.31 enum {
1.32 @@ -92,7 +99,7 @@
1.33 static void _close_output(GMencoder * self);
1.34 static gboolean _open_output(GMencoder * self, const gchar * uri);
1.35
1.36 -static GstElement *_create_source(const gchar * uri);
1.37 +static GstElement *_create_source(GMencoder *self, const gchar * uri);
1.38 static GstElement *_create_pipeline(GMencoder * self,
1.39 const gchar * video_encode,
1.40 const gchar * mux_name,
1.41 @@ -106,7 +113,7 @@
1.42 guint audio_rate,
1.43 gboolean deinterlace);
1.44 #ifdef USE_MANUAL_SINK
1.45 -static void _flush_queue (GMencoder *self);
1.46 +static void _flush_queue (GMencoder *self);
1.47 static void _buffer_arrive_cb (GstElement* object,
1.48 GstBuffer* buff,
1.49 GstPad* pad,
1.50 @@ -362,7 +369,7 @@
1.51 GstElement *vcolorspace = NULL;
1.52 GstElement *vencode = NULL;
1.53 GstElement *vrate = NULL;
1.54 - GstElement *deinterlace = NULL;
1.55 + GstElement *deinterlace = NULL;
1.56 GstElement *walk = NULL;
1.57 GstPad *vpad = NULL;
1.58
1.59 @@ -372,10 +379,10 @@
1.60 gst_element_factory_make("ffmpegcolorspace", "colorspace");
1.61
1.62 if (use_deinterlace) {
1.63 - deinterlace = gst_element_factory_make ("ffdeinterlace", "deinterlace");
1.64 - if (deinterlace == NULL) {
1.65 - g_warning ("Fail to create deinterlace element: Continue without deinterlace.");
1.66 - }
1.67 + deinterlace = gst_element_factory_make ("ffdeinterlace", "deinterlace");
1.68 + if (deinterlace == NULL) {
1.69 + g_warning ("Fail to create deinterlace element: Continue without deinterlace.");
1.70 + }
1.71 }
1.72
1.73
1.74 @@ -517,8 +524,9 @@
1.75 }
1.76
1.77 _close_output(self);
1.78 - if (_open_output(self, out_uri) == FALSE)
1.79 + if (_open_output(self, out_uri) == FALSE) {
1.80 return FALSE;
1.81 + }
1.82
1.83 priv->sources = 0;
1.84 priv->send_chunked = chunked;
1.85 @@ -553,11 +561,7 @@
1.86 g_return_val_if_fail(priv->pipe != NULL, FALSE);
1.87 g_return_val_if_fail(priv->ready == FALSE, FALSE);
1.88
1.89 -#ifndef SUPPORT_MULT_INPUT
1.90 - g_return_val_if_fail(priv->sources < 1, FALSE);
1.91 -#endif
1.92 -
1.93 - src = _create_source(uri);
1.94 + src = _create_source(self, uri);
1.95 if (src == NULL)
1.96 return FALSE;
1.97
1.98 @@ -565,13 +569,8 @@
1.99
1.100 gst_bin_add(GST_BIN(priv->pipe), src);
1.101
1.102 -#ifdef SUPPORT_MULT_INPUT
1.103 - ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "ap");
1.104 - vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vp");
1.105 -#else
1.106 ap = gst_bin_get_by_name(GST_BIN(priv->pipe), "abin");
1.107 vp = gst_bin_get_by_name(GST_BIN(priv->pipe), "vbin");
1.108 -#endif
1.109
1.110 if ((vp == NULL) || (ap == NULL)) {
1.111 g_warning("Fail to get output bin");
1.112 @@ -694,7 +693,7 @@
1.113 guint video_height,
1.114 const gchar * audio_encode,
1.115 gchar ** audio_encode_prop, guint audio_rate,
1.116 - gboolean deinterlace)
1.117 + gboolean deinterlace)
1.118 {
1.119 GstBus *bus = NULL;
1.120 GstElement *pipe = NULL;
1.121 @@ -705,18 +704,9 @@
1.122 GstElement *queue = NULL;
1.123 GstPad *aux_pad = NULL;
1.124 GstPad *mux_pad = NULL;
1.125 -#ifdef SUPPORT_MULT_INPUT
1.126 - GstElement *ap = NULL;
1.127 - GstElement *vp = NULL;
1.128 -#endif
1.129
1.130 pipe = gst_pipeline_new("pipe");
1.131
1.132 -#ifdef SUPPORT_MULT_INPUT
1.133 - ap = gst_element_factory_make("concatmux", "ap");
1.134 - vp = gst_element_factory_make("concatmux", "vp");
1.135 - gst_bin_add_many(GST_BIN(pipe), ap, vp, NULL);
1.136 -#endif
1.137 mux =
1.138 gst_element_factory_make((mux_name ? mux_name : "ffmux_mpeg"),
1.139 "mux");
1.140 @@ -747,17 +737,6 @@
1.141 gst_bin_add_many(GST_BIN(pipe), abin, vbin, mux, queue, sink, NULL);
1.142
1.143
1.144 -#ifdef SUPPORT_MULT_INPUT
1.145 - if (gst_element_link(ap, abin) == FALSE) {
1.146 - g_warning("Fail to link concat and abin");
1.147 - goto error;
1.148 - }
1.149 -
1.150 - if (gst_element_link(vp, vbin) == FALSE) {
1.151 - g_warning("Fail to link concat and vbin");
1.152 - }
1.153 -#endif
1.154 -
1.155 // Link bins with mux
1.156 aux_pad = gst_element_get_pad(abin, "src");
1.157 mux_pad =
1.158 @@ -844,7 +823,30 @@
1.159 }
1.160
1.161 static GstElement *
1.162 -_create_source(const gchar * uri)
1.163 +_create_v4l_source (GMencoder *self, const gchar * uri)
1.164 +{
1.165 + gchar **info;
1.166 + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE(self);
1.167 +
1.168 +
1.169 + info = g_strsplit (uri+6, ":", 3);
1.170 + if (g_strv_length (info) != 3) {
1.171 + return NULL;
1.172 + }
1.173 +
1.174 + priv->v4lsrc = gst_element_factory_make ("v4l2src", "src");
1.175 + g_debug ("channel %s, norm %s, frequ %s", info[0], info[1], info[2]);
1.176 + g_object_set (G_OBJECT (priv->v4lsrc),
1.177 + "channel", info[0],
1.178 + "norm", info[1],
1.179 + "frequency", atoi (info[2]),
1.180 + NULL);
1.181 +
1.182 + return priv->v4lsrc;
1.183 +}
1.184 +
1.185 +static GstElement *
1.186 +_create_source(GMencoder *self, const gchar * uri)
1.187 {
1.188
1.189 GstElement *bsrc = NULL;
1.190 @@ -860,7 +862,15 @@
1.191
1.192 // src = gst_element_factory_make ("gnomevfssrc", "src");
1.193 // g_object_set (G_OBJECT (src), "location", uri, NULL);
1.194 - src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
1.195 + if (strncmp (uri, "v4l://", 6) == 0) {
1.196 + g_debug ("V4L");
1.197 + src = _create_v4l_source (self, uri);
1.198 + }
1.199 + else {
1.200 + g_debug ("SRC");
1.201 + src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
1.202 + }
1.203 +
1.204 if (src == NULL)
1.205 goto error;
1.206
1.207 @@ -900,6 +910,7 @@
1.208 return bsrc;
1.209
1.210 error:
1.211 + g_debug ("Fail to create source element");
1.212 if (src != NULL) {
1.213 gst_object_unref(src);
1.214 }
1.215 @@ -929,10 +940,15 @@
1.216 i = g_strsplit(uri, "://", 0);
1.217 if (strcmp(i[0], "fd") == 0) {
1.218 result = gnome_vfs_open_fd (&priv->handle, atoi(i[1]));
1.219 - } else {
1.220 - result = gnome_vfs_open (&priv->handle, uri,
1.221 - GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE);
1.222 -
1.223 + } else {
1.224 + g_debug ("Teste file :%s", i[1]);
1.225 + if (g_file_test (i[1], G_FILE_TEST_EXISTS) == FALSE) {
1.226 + result = gnome_vfs_create (&priv->handle, uri, GNOME_VFS_OPEN_WRITE, TRUE,
1.227 + GNOME_VFS_PERM_USER_WRITE | GNOME_VFS_PERM_USER_READ | GNOME_VFS_PERM_GROUP_READ);
1.228 + } else {
1.229 + result = gnome_vfs_open (&priv->handle, uri,
1.230 + GNOME_VFS_OPEN_WRITE | GNOME_VFS_OPEN_TRUNCATE);
1.231 + }
1.232 }
1.233
1.234 g_strfreev(i);
1.235 @@ -1119,15 +1135,15 @@
1.236 GnomeVFSFileSize bytes_written;
1.237 gchar *end_msg;
1.238 end_msg = g_strdup ("0\r\n\r\n");
1.239 - gnome_vfs_write (priv->handle,
1.240 - (const guint8*) end_msg,
1.241 + gnome_vfs_write (priv->handle,
1.242 + (const guint8*) end_msg,
1.243 strlen(end_msg) * sizeof(gchar),
1.244 &bytes_written);
1.245 g_free (end_msg);
1.246 }
1.247 }
1.248
1.249 -static void
1.250 +static void
1.251 _buffer_arrive_cb (GstElement* object,
1.252 GstBuffer* buff,
1.253 GstPad* pad,
1.254 @@ -1137,14 +1153,14 @@
1.255
1.256
1.257 if (priv->send_chunked) {
1.258 - if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE)
1.259 + if (_send_buffer (priv->handle, GST_BUFFER_DATA (buff), GST_BUFFER_SIZE (buff)) == FALSE)
1.260 goto error;
1.261 } else {
1.262 GnomeVFSResult result;
1.263 GnomeVFSFileSize bytes_written;
1.264
1.265 - result = gnome_vfs_write (priv->handle,
1.266 - GST_BUFFER_DATA (buff),
1.267 + result = gnome_vfs_write (priv->handle,
1.268 + GST_BUFFER_DATA (buff),
1.269 GST_BUFFER_SIZE (buff),
1.270 &bytes_written);
1.271
1.272 @@ -1162,5 +1178,5 @@
1.273 g_signal_emit(user_data, g_mencoder_signals[ERROR], 0, "Fail to write on socket");
1.274 gst_element_set_state (priv->pipe, GST_STATE_PAUSED);
1.275 }
1.276 -#endif
1.277
1.278 +#endif