1.1 --- a/gmyth-stream/libgnomevfs2/modules/gmythstream-method.c Tue Apr 17 14:42:18 2007 +0100
1.2 +++ b/gmyth-stream/libgnomevfs2/modules/gmythstream-method.c Tue Jun 26 15:00:45 2007 +0100
1.3 @@ -20,11 +20,12 @@
1.4 #include <config.h>
1.5 #endif
1.6
1.7 -#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
1.8 -#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
1.9 -#include <stdlib.h> /* for atoi() and exit() */
1.10 -#include <string.h> /* for memset() */
1.11 -#include <unistd.h> /* for close() */
1.12 +#include <sys/socket.h> /* for socket(), connect(), send(), and
1.13 + * recv() */
1.14 +#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
1.15 +#include <stdlib.h> /* for atoi() and exit() */
1.16 +#include <string.h> /* for memset() */
1.17 +#include <unistd.h> /* for close() */
1.18 #include <errno.h>
1.19
1.20 #include <glib.h>
1.21 @@ -38,130 +39,129 @@
1.22 #define BUFFER_SIZE 4096
1.23
1.24 typedef struct {
1.25 - gint port;
1.26 - gchar* hostname;
1.27 + gint port;
1.28 + gchar *hostname;
1.29
1.30 GMythStreamClient *stream;
1.31 - gint fd;
1.32 + gint fd;
1.33 } gmsHandle;
1.34
1.35 typedef struct {
1.36 - gchar *file_name;
1.37 - gchar *mux;
1.38 - gchar *vcodec;
1.39 - guint vbitrate;
1.40 - gdouble fps;
1.41 - gchar *acodec;
1.42 - guint abitrate;
1.43 - guint width;
1.44 - guint height;
1.45 - guint port;
1.46 - gchar *opt;
1.47 + gchar *file_name;
1.48 + gchar *mux;
1.49 + gchar *vcodec;
1.50 + guint vbitrate;
1.51 + gdouble fps;
1.52 + gchar *acodec;
1.53 + guint abitrate;
1.54 + guint width;
1.55 + guint height;
1.56 + guint port;
1.57 + gchar *opt;
1.58 } UriArgs;
1.59
1.60
1.61 -static gmsHandle* gmsHandle_new(GnomeVFSURI *uri);
1.62 +static gmsHandle *gmsHandle_new(GnomeVFSURI * uri);
1.63
1.64 -static GnomeVFSResult
1.65 -do_open (GnomeVFSMethod *method,
1.66 - GnomeVFSMethodHandle **method_handle,
1.67 - GnomeVFSURI *uri,
1.68 - GnomeVFSOpenMode mode,
1.69 - GnomeVFSContext *context);
1.70 +static GnomeVFSResult
1.71 +do_open(GnomeVFSMethod * method,
1.72 + GnomeVFSMethodHandle ** method_handle,
1.73 + GnomeVFSURI * uri,
1.74 + GnomeVFSOpenMode mode, GnomeVFSContext * context);
1.75
1.76 -static GnomeVFSResult
1.77 -do_read (GnomeVFSMethod *method,
1.78 - GnomeVFSMethodHandle *method_handle,
1.79 - gpointer buffer,
1.80 - GnomeVFSFileSize bytes,
1.81 - GnomeVFSFileSize *bytes_read,
1.82 - GnomeVFSContext *context);
1.83 +static GnomeVFSResult
1.84 +do_read(GnomeVFSMethod * method,
1.85 + GnomeVFSMethodHandle * method_handle,
1.86 + gpointer buffer,
1.87 + GnomeVFSFileSize bytes,
1.88 + GnomeVFSFileSize * bytes_read, GnomeVFSContext * context);
1.89
1.90 -static GnomeVFSResult
1.91 -do_close (GnomeVFSMethod * method,
1.92 - GnomeVFSMethodHandle * method_handle,
1.93 - GnomeVFSContext * context);
1.94 +static GnomeVFSResult
1.95 +do_close(GnomeVFSMethod * method,
1.96 + GnomeVFSMethodHandle * method_handle, GnomeVFSContext * context);
1.97
1.98 -static GnomeVFSResult
1.99 -do_get_file_info (GnomeVFSMethod * method,
1.100 - GnomeVFSURI * uri,
1.101 - GnomeVFSFileInfo * file_info,
1.102 - GnomeVFSFileInfoOptions options,
1.103 - GnomeVFSContext * context);
1.104 +static GnomeVFSResult
1.105 +do_get_file_info(GnomeVFSMethod * method,
1.106 + GnomeVFSURI * uri,
1.107 + GnomeVFSFileInfo * file_info,
1.108 + GnomeVFSFileInfoOptions options,
1.109 + GnomeVFSContext * context);
1.110
1.111
1.112 -static GnomeVFSResult
1.113 -do_get_file_info_from_handle (GnomeVFSMethod *method,
1.114 - GnomeVFSMethodHandle *method_handle,
1.115 - GnomeVFSFileInfo *file_info,
1.116 - GnomeVFSFileInfoOptions options,
1.117 - GnomeVFSContext *context);
1.118 +static GnomeVFSResult
1.119 +do_get_file_info_from_handle(GnomeVFSMethod * method,
1.120 + GnomeVFSMethodHandle * method_handle,
1.121 + GnomeVFSFileInfo * file_info,
1.122 + GnomeVFSFileInfoOptions options,
1.123 + GnomeVFSContext * context);
1.124
1.125
1.126 -static gboolean
1.127 -do_is_local (GnomeVFSMethod * method, const GnomeVFSURI * uri);
1.128 +static gboolean
1.129 +do_is_local(GnomeVFSMethod * method, const GnomeVFSURI * uri);
1.130
1.131
1.132 -static gmsHandle* gmsHandle_new(GnomeVFSURI *uri)
1.133 +static gmsHandle *
1.134 +gmsHandle_new(GnomeVFSURI * uri)
1.135 {
1.136 - gmsHandle* handler = (gmsHandle*)g_malloc0(sizeof(gmsHandle));
1.137 + gmsHandle *handler = (gmsHandle *) g_malloc0(sizeof(gmsHandle));
1.138
1.139 - handler->hostname = (gchar*)gnome_vfs_uri_get_host_name(uri);
1.140 + handler->hostname = (gchar *) gnome_vfs_uri_get_host_name(uri);
1.141 handler->port = gnome_vfs_uri_get_host_port(uri);
1.142 - handler->stream = gmyth_stream_client_new ();
1.143 + handler->stream = gmyth_stream_client_new();
1.144
1.145 return handler;
1.146 }
1.147
1.148 static GnomeVFSMethod method = {
1.149 - sizeof (GnomeVFSMethod),
1.150 - do_open, /* open */
1.151 - NULL, /* create */
1.152 - do_close, /* close */
1.153 - do_read, /* read */
1.154 - NULL, /* write */
1.155 - NULL, /* seek */
1.156 - NULL, /* tell */
1.157 - NULL, /* truncate_handle */
1.158 - NULL, /* open_directory */
1.159 - NULL, /* close_directory */
1.160 - NULL, /* read_directory */
1.161 - do_get_file_info, /* get_file_info */
1.162 - do_get_file_info_from_handle, /* get_file_info_from_handle */
1.163 - do_is_local, /* is_local */
1.164 - NULL, /* make_directory */
1.165 - NULL, /* remove_directory */
1.166 - NULL, /* move */
1.167 - NULL, /* unlink */
1.168 - NULL, /* check_same_fs */
1.169 - NULL, /* set_file_info */
1.170 - NULL, /* truncate */
1.171 - NULL, /* find_directory */
1.172 - NULL, /* create_symbolic_link */
1.173 - NULL, /* monitor_add */
1.174 - NULL, /* monitor_cancel */
1.175 - NULL /* file_control */
1.176 + sizeof(GnomeVFSMethod),
1.177 + do_open, /* open */
1.178 + NULL, /* create */
1.179 + do_close, /* close */
1.180 + do_read, /* read */
1.181 + NULL, /* write */
1.182 + NULL, /* seek */
1.183 + NULL, /* tell */
1.184 + NULL, /* truncate_handle */
1.185 + NULL, /* open_directory */
1.186 + NULL, /* close_directory */
1.187 + NULL, /* read_directory */
1.188 + do_get_file_info, /* get_file_info */
1.189 + do_get_file_info_from_handle, /* get_file_info_from_handle */
1.190 + do_is_local, /* is_local */
1.191 + NULL, /* make_directory */
1.192 + NULL, /* remove_directory */
1.193 + NULL, /* move */
1.194 + NULL, /* unlink */
1.195 + NULL, /* check_same_fs */
1.196 + NULL, /* set_file_info */
1.197 + NULL, /* truncate */
1.198 + NULL, /* find_directory */
1.199 + NULL, /* create_symbolic_link */
1.200 + NULL, /* monitor_add */
1.201 + NULL, /* monitor_cancel */
1.202 + NULL /* file_control */
1.203 };
1.204
1.205 GnomeVFSMethod *
1.206 -vfs_module_init (const char *method_name, const char *args)
1.207 +vfs_module_init(const char *method_name, const char *args)
1.208 {
1.209 return &method;
1.210 }
1.211
1.212 void
1.213 -vfs_module_shutdown (GnomeVFSMethod* method)
1.214 +vfs_module_shutdown(GnomeVFSMethod * method)
1.215 {
1.216 return;
1.217 }
1.218
1.219 -char* _parse_opt(char* opt)
1.220 +char *
1.221 +_parse_opt(char *opt)
1.222 {
1.223 - char** list = g_strsplit(opt, "opt=", 2);
1.224 - char** opts = g_strsplit(list[1], "+", 32);
1.225 - char* value = "";
1.226 - char* aux;
1.227 - gint i = 0;
1.228 + char **list = g_strsplit(opt, "opt=", 2);
1.229 + char **opts = g_strsplit(list[1], "+", 32);
1.230 + char *value = "";
1.231 + char *aux;
1.232 + gint i = 0;
1.233
1.234 for (aux = opts[0]; aux != NULL; aux = opts[++i])
1.235 value = g_strdup_printf("%s %s", value, aux);
1.236 @@ -173,105 +173,102 @@
1.237 }
1.238
1.239 static UriArgs *
1.240 -_uri_parse_args (const GnomeVFSURI *uri)
1.241 +_uri_parse_args(const GnomeVFSURI * uri)
1.242 {
1.243 - gchar *file = gnome_vfs_unescape_string (uri->text, NULL);
1.244 + gchar *file = gnome_vfs_unescape_string(uri->text, NULL);
1.245
1.246 - gchar **list = g_strsplit(file, "\'", 3);
1.247 - gchar **prefix = g_strsplit_set(list[0], "/=", 3);
1.248 - gchar **lst = g_strsplit (list[2], "?", 0);
1.249 + gchar **list = g_strsplit(file, "\'", 3);
1.250 + gchar **prefix = g_strsplit_set(list[0], "/=", 3);
1.251 + gchar **lst = g_strsplit(list[2], "?", 0);
1.252
1.253 - UriArgs *info = g_new0 (UriArgs, 1);
1.254 - gint i = 1;
1.255 + UriArgs *info = g_new0(UriArgs, 1);
1.256 + gint i = 1;
1.257
1.258 - gchar** prop = NULL;
1.259 + gchar **prop = NULL;
1.260 prop = g_strsplit_set(lst[0], "/=", 3);
1.261
1.262 - info->file_name = g_strdup_printf ("%s://%s",\
1.263 - prefix[1],list[1]);
1.264 + info->file_name = g_strdup_printf("%s://%s", prefix[1], list[1]);
1.265
1.266 - //g_debug("FILENAME: [%s]", info->file_name);
1.267 + // g_debug("FILENAME: [%s]", info->file_name);
1.268
1.269 g_strfreev(prop);
1.270
1.271 - gchar* walk;
1.272 - for (walk = lst[1]; walk != NULL; walk = lst[++i])
1.273 - {
1.274 + gchar *walk;
1.275 + for (walk = lst[1]; walk != NULL; walk = lst[++i]) {
1.276 prop = g_strsplit(walk, "=", 2);
1.277
1.278 - if (g_strv_length (prop) == 2) {
1.279 - if (strcmp (prop[0], "mux") == 0) {
1.280 - info->mux = g_strdup (prop[1]);
1.281 - } else if (strcmp (prop[0], "vcodec") == 0) {
1.282 - info->vcodec = g_strdup (prop[1]);
1.283 - } else if (strcmp (prop[0], "vbitrate") == 0) {
1.284 - info->vbitrate = atoi (prop[1]);
1.285 - } else if (strcmp (prop[0], "fps") == 0) {
1.286 - info->fps = g_strtod (prop[1], NULL);
1.287 - } else if (strcmp (prop[0], "acodec") == 0) {
1.288 - info->acodec = g_strdup (prop[1]);
1.289 - } else if (strcmp (prop[0], "abitrate") == 0) {
1.290 - info->abitrate = atoi (prop[1]);
1.291 - } else if (strcmp (prop[0], "width") == 0) {
1.292 - info->width = atoi (prop[1]);
1.293 - } else if (strcmp (prop[0], "height") == 0) {
1.294 - info->height = atoi (prop[1]);
1.295 - } else if (strcmp (prop[0], "opt") == 0) {
1.296 - info->opt = g_strdup (_parse_opt(walk));
1.297 + if (g_strv_length(prop) == 2) {
1.298 + if (strcmp(prop[0], "mux") == 0) {
1.299 + info->mux = g_strdup(prop[1]);
1.300 + } else if (strcmp(prop[0], "vcodec") == 0) {
1.301 + info->vcodec = g_strdup(prop[1]);
1.302 + } else if (strcmp(prop[0], "vbitrate") == 0) {
1.303 + info->vbitrate = atoi(prop[1]);
1.304 + } else if (strcmp(prop[0], "fps") == 0) {
1.305 + info->fps = g_strtod(prop[1], NULL);
1.306 + } else if (strcmp(prop[0], "acodec") == 0) {
1.307 + info->acodec = g_strdup(prop[1]);
1.308 + } else if (strcmp(prop[0], "abitrate") == 0) {
1.309 + info->abitrate = atoi(prop[1]);
1.310 + } else if (strcmp(prop[0], "width") == 0) {
1.311 + info->width = atoi(prop[1]);
1.312 + } else if (strcmp(prop[0], "height") == 0) {
1.313 + info->height = atoi(prop[1]);
1.314 + } else if (strcmp(prop[0], "opt") == 0) {
1.315 + info->opt = g_strdup(_parse_opt(walk));
1.316 }
1.317 }
1.318 - g_strfreev (prop);
1.319 + g_strfreev(prop);
1.320 }
1.321
1.322 - g_free (file);
1.323 - g_strfreev (list);
1.324 - g_strfreev (prefix);
1.325 - g_strfreev (lst);
1.326 + g_free(file);
1.327 + g_strfreev(list);
1.328 + g_strfreev(prefix);
1.329 + g_strfreev(lst);
1.330 return info;
1.331 }
1.332
1.333 -static GnomeVFSResult
1.334 -do_open (GnomeVFSMethod *method,
1.335 - GnomeVFSMethodHandle **method_handle,
1.336 - GnomeVFSURI *uri,
1.337 - GnomeVFSOpenMode mode,
1.338 - GnomeVFSContext *context)
1.339 +static GnomeVFSResult
1.340 +do_open(GnomeVFSMethod * method,
1.341 + GnomeVFSMethodHandle ** method_handle,
1.342 + GnomeVFSURI * uri,
1.343 + GnomeVFSOpenMode mode, GnomeVFSContext * context)
1.344 {
1.345 - gmsHandle *handle = gmsHandle_new(uri);
1.346 - UriArgs *args;
1.347 + gmsHandle *handle = gmsHandle_new(uri);
1.348 + UriArgs *args;
1.349
1.350 - if (!gmyth_stream_client_connect (handle->stream,
1.351 - gnome_vfs_uri_get_host_name (uri),
1.352 - gnome_vfs_uri_get_host_port (uri))) {
1.353 + if (!gmyth_stream_client_connect(handle->stream,
1.354 + gnome_vfs_uri_get_host_name(uri),
1.355 + gnome_vfs_uri_get_host_port(uri))) {
1.356
1.357 return GNOME_VFS_ERROR_HOST_NOT_FOUND;
1.358 }
1.359
1.360 - args = _uri_parse_args (uri);
1.361 + args = _uri_parse_args(uri);
1.362
1.363 - gint ret = gmyth_stream_client_open_stream (handle->stream,
1.364 - args->file_name,
1.365 - args->mux,
1.366 - args->vcodec,
1.367 - args->vbitrate,
1.368 - args->fps,
1.369 - args->acodec,
1.370 - args->abitrate,
1.371 - args->width,
1.372 - args->height,
1.373 - args->opt);
1.374 + gint ret = gmyth_stream_client_open_stream(handle->stream,
1.375 + args->file_name,
1.376 + args->mux,
1.377 + args->vcodec,
1.378 + args->vbitrate,
1.379 + args->fps,
1.380 + args->acodec,
1.381 + args->abitrate,
1.382 + args->width,
1.383 + args->height,
1.384 + args->opt);
1.385
1.386 - g_free (args);
1.387 + g_free(args);
1.388
1.389 if (ret == -1) {
1.390 - gmyth_stream_client_disconnect (handle->stream);
1.391 + gmyth_stream_client_disconnect(handle->stream);
1.392 return GNOME_VFS_ERROR_HOST_NOT_FOUND;
1.393 }
1.394
1.395 - handle->fd = gmyth_stream_client_play_stream (handle->stream);
1.396 + handle->fd = gmyth_stream_client_play_stream(handle->stream);
1.397
1.398 if (handle->fd == -1) {
1.399 - gmyth_stream_client_disconnect (handle->stream);
1.400 + gmyth_stream_client_disconnect(handle->stream);
1.401 return GNOME_VFS_ERROR_HOST_NOT_FOUND;
1.402 }
1.403
1.404 @@ -279,54 +276,54 @@
1.405 return GNOME_VFS_OK;
1.406 }
1.407
1.408 -static GnomeVFSResult
1.409 -do_read (GnomeVFSMethod *method,
1.410 - GnomeVFSMethodHandle *method_handle,
1.411 - gpointer buffer,
1.412 - GnomeVFSFileSize bytes,
1.413 - GnomeVFSFileSize *bytes_read,
1.414 - GnomeVFSContext *context)
1.415 +static GnomeVFSResult
1.416 +do_read(GnomeVFSMethod * method,
1.417 + GnomeVFSMethodHandle * method_handle,
1.418 + gpointer buffer,
1.419 + GnomeVFSFileSize bytes,
1.420 + GnomeVFSFileSize * bytes_read, GnomeVFSContext * context)
1.421 {
1.422
1.423 - gint64 total_read = 0;
1.424 - gmsHandle *handle = (gmsHandle *) method_handle;
1.425 + gint64 total_read = 0;
1.426 + gmsHandle *handle = (gmsHandle *) method_handle;
1.427
1.428 - //g_debug("waiting something");
1.429 + // g_debug("waiting something");
1.430
1.431 total_read = recv(handle->fd, buffer, BUFFER_SIZE, 0);
1.432 - //g_debug("COULD READ: %d bytes", total_read);
1.433 + // g_debug("COULD READ: %d bytes", total_read);
1.434 *bytes_read = (GnomeVFSFileSize) total_read;
1.435
1.436 - //if (total_read < 0) g_debug("ERROR!!!!!!!!!!!!!!!!");
1.437 + // if (total_read < 0) g_debug("ERROR!!!!!!!!!!!!!!!!");
1.438
1.439 - if (total_read < 0) return GNOME_VFS_ERROR_INTERNAL;
1.440 - else return GNOME_VFS_OK;
1.441 + if (total_read < 0)
1.442 + return GNOME_VFS_ERROR_INTERNAL;
1.443 + else
1.444 + return GNOME_VFS_OK;
1.445
1.446 }
1.447
1.448 -static GnomeVFSResult
1.449 -do_close (GnomeVFSMethod * method,
1.450 - GnomeVFSMethodHandle * method_handle,
1.451 - GnomeVFSContext * context)
1.452 +static GnomeVFSResult
1.453 +do_close(GnomeVFSMethod * method,
1.454 + GnomeVFSMethodHandle * method_handle, GnomeVFSContext * context)
1.455 {
1.456 - gmsHandle *handle = (gmsHandle *) method_handle;
1.457 + gmsHandle *handle = (gmsHandle *) method_handle;
1.458
1.459 g_debug("close close close");
1.460
1.461 - gmyth_stream_client_close_stream (handle->stream);
1.462 - gmyth_stream_client_disconnect (handle->stream);
1.463 + gmyth_stream_client_close_stream(handle->stream);
1.464 + gmyth_stream_client_disconnect(handle->stream);
1.465
1.466 g_free(handle);
1.467 return GNOME_VFS_OK;
1.468 }
1.469
1.470
1.471 -static GnomeVFSResult
1.472 -do_get_file_info (GnomeVFSMethod * method,
1.473 - GnomeVFSURI * uri,
1.474 - GnomeVFSFileInfo * file_info,
1.475 - GnomeVFSFileInfoOptions options,
1.476 - GnomeVFSContext * context)
1.477 +static GnomeVFSResult
1.478 +do_get_file_info(GnomeVFSMethod * method,
1.479 + GnomeVFSURI * uri,
1.480 + GnomeVFSFileInfo * file_info,
1.481 + GnomeVFSFileInfoOptions options,
1.482 + GnomeVFSContext * context)
1.483 {
1.484 file_info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE |
1.485 GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS;
1.486 @@ -334,19 +331,18 @@
1.487 file_info->type = GNOME_VFS_FILE_TYPE_SOCKET;
1.488
1.489 file_info->permissions = GNOME_VFS_PERM_USER_READ |
1.490 - GNOME_VFS_PERM_OTHER_READ |
1.491 - GNOME_VFS_PERM_GROUP_READ;
1.492 + GNOME_VFS_PERM_OTHER_READ | GNOME_VFS_PERM_GROUP_READ;
1.493
1.494 return GNOME_VFS_OK;
1.495 }
1.496
1.497
1.498 -static GnomeVFSResult
1.499 -do_get_file_info_from_handle (GnomeVFSMethod *method,
1.500 - GnomeVFSMethodHandle *method_handle,
1.501 - GnomeVFSFileInfo *file_info,
1.502 - GnomeVFSFileInfoOptions options,
1.503 - GnomeVFSContext *context)
1.504 +static GnomeVFSResult
1.505 +do_get_file_info_from_handle(GnomeVFSMethod * method,
1.506 + GnomeVFSMethodHandle * method_handle,
1.507 + GnomeVFSFileInfo * file_info,
1.508 + GnomeVFSFileInfoOptions options,
1.509 + GnomeVFSContext * context)
1.510 {
1.511 file_info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE |
1.512 GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS;
1.513 @@ -354,15 +350,14 @@
1.514 file_info->type = GNOME_VFS_FILE_TYPE_SOCKET;
1.515
1.516 file_info->permissions = GNOME_VFS_PERM_USER_READ |
1.517 - GNOME_VFS_PERM_OTHER_READ |
1.518 - GNOME_VFS_PERM_GROUP_READ;
1.519 + GNOME_VFS_PERM_OTHER_READ | GNOME_VFS_PERM_GROUP_READ;
1.520
1.521 return GNOME_VFS_OK;
1.522 }
1.523
1.524
1.525 -static gboolean
1.526 -do_is_local (GnomeVFSMethod * method, const GnomeVFSURI * uri)
1.527 +static gboolean
1.528 +do_is_local(GnomeVFSMethod * method, const GnomeVFSURI * uri)
1.529 {
1.530 return FALSE;
1.531 }