# HG changeset patch # User morphbr # Date 1170806585 0 # Node ID 818deb9ae65d42630da61628711b675d65794459 # Parent 73461d8db7ec9959eea0b3d24010565454016bb9 [svn r331] - Updated gmyth_http (comments, etc..) - Modified gmyth_http test file (test/http.c to test/gmyth_test_http.c) - Created gmyth_vlc (interface for vlc - will be used for live tv and cool stuff) - Created gmyth_vlc test file (test/gmyth_test_vlc.c) diff -r 73461d8db7ec -r 818deb9ae65d gmyth/src/Makefile.am --- a/gmyth/src/Makefile.am Tue Feb 06 15:00:23 2007 +0000 +++ b/gmyth/src/Makefile.am Wed Feb 07 00:03:05 2007 +0000 @@ -6,7 +6,7 @@ gmyth_marshal.c \ gmyth_marshal.h -libgmyth_la_SOURCES = \ +libgmyth_la_SOURCES = \ gmyth_common.c \ gmyth_debug.c \ gmyth_epg.c \ @@ -18,13 +18,14 @@ gmyth_query.c \ gmyth_socket.c \ gmyth_stringlist.c \ - gmyth_monitor_handler.c \ - gmyth_file_transfer.c \ + gmyth_monitor_handler.c \ + gmyth_file_transfer.c \ gmyth_livetv.c \ gmyth_backendinfo.c \ gmyth_programinfo.c \ - gmyth_uri.c \ + gmyth_uri.c \ gmyth_http.c \ + gmyth_vlc.c \ $(BUILT_SOURCES) @@ -40,17 +41,17 @@ glib-genmarshal --body --prefix=gmyth_marshal $(srcdir)/gmyth_marshal.list >> gmyth_marshal.c.tmp mv gmyth_marshal.c.tmp gmyth_marshal.c -libgmyth_la_CFLAGS = \ - -DDATADIR=\"$(pkgdatadir)\" \ +libgmyth_la_CFLAGS = \ + -DDATADIR=\"$(pkgdatadir)\" \ $(GLIB_CFLAGS) \ $(GOBJECT_CFLAGS) \ $(GST_CFLAGS) \ $(GSTBASE_CFLAGS) \ - $(GSTPLUGINSBASE_CFLAGS) \ + $(GSTPLUGINSBASE_CFLAGS) \ $(MYSQL_CFLAGS) \ $(LIBXML_CFLAGS) -libgmyth_la_LDFLAGS = \ +libgmyth_la_LDFLAGS = \ -export-dynamic \ $(MYSQL_LIBS) \ $(GST_LIBS) \ @@ -58,11 +59,11 @@ $(GSTPLUGINS_LIBS) \ $(LIBXML_LIBS) -libgmyth_includedir = \ +libgmyth_includedir = \ $(pkgincludedir) -libgmyth_include_HEADERS = \ - gmyth.h \ +libgmyth_include_HEADERS = \ + gmyth.h \ gmyth_common.h \ gmyth_debug.h \ gmyth_epg.h \ @@ -74,12 +75,13 @@ gmyth_socket.h \ gmyth_remote_util.h \ gmyth_stringlist.h \ - gmyth_monitor_handler.h \ - gmyth_file_transfer.h \ + gmyth_monitor_handler.h \ + gmyth_file_transfer.h \ gmyth_livetv.h \ gmyth_backendinfo.h \ gmyth_programinfo.h \ - gmyth_uri.h \ - gmyth_http.h - + gmyth_uri.h \ + gmyth_http.h \ + gmyth_vlc.h + CLEANFILES = $(BUILT_SOURCES) diff -r 73461d8db7ec -r 818deb9ae65d gmyth/src/gmyth.h --- a/gmyth/src/gmyth.h Tue Feb 06 15:00:23 2007 +0000 +++ b/gmyth/src/gmyth.h Wed Feb 07 00:03:05 2007 +0000 @@ -47,5 +47,6 @@ #include #include #include +#include #endif /* _GMYTH_H_ */ diff -r 73461d8db7ec -r 818deb9ae65d gmyth/src/gmyth_http.c --- a/gmyth/src/gmyth_http.c Tue Feb 06 15:00:23 2007 +0000 +++ b/gmyth/src/gmyth_http.c Wed Feb 07 00:03:05 2007 +0000 @@ -3,14 +3,12 @@ * * @file gmyth/gmyth_http.c * - * @brief

GMythHttp class provides a wrapper to access + * @brief

GMythHttp library provides a wrapper to access * data from the database using http+xml * - * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia. - * @author Artur Duque de Souza <@indt.org.br> + * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia. + * @author Artur Duque de Souza * - */ -/* * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -83,6 +81,7 @@ return result; } + /** Retrieves the Progam List from the Channel * * @param nodeTab A pointer to a node inside the XML diff -r 73461d8db7ec -r 818deb9ae65d gmyth/src/gmyth_http.h --- a/gmyth/src/gmyth_http.h Tue Feb 06 15:00:23 2007 +0000 +++ b/gmyth/src/gmyth_http.h Wed Feb 07 00:03:05 2007 +0000 @@ -1,16 +1,15 @@ /** * GMyth Library * - * @file gmyth/gmyth_http.c + * @file gmyth/gmyth_http.h * - * @brief

GMythHttp class provides a wrapper to access + * @brief

GMythHttp library provides a wrapper to access * data from the database using http+xml * - * Copyright (C) 2006 INdT - Instituto Nokia de Tecnologia. - * @author Artur Duque de Souza <@indt.org.br> + * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia. + * @author Artur Duque de Souza * - *//* - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -49,7 +48,6 @@ #define MYTH_PORT_STATUS 6544 -typedef struct _GMythPacket GMythPacket; typedef struct _GMythProgram GMythProgram; typedef struct _GMythChannel GMythChannel; typedef struct _GMythEpg GMythEpg; @@ -61,11 +59,6 @@ size_t size; }; -struct _GMythPacket -{ - GString *response; - int type; -}; struct _GMythProgram { diff -r 73461d8db7ec -r 818deb9ae65d gmyth/src/gmyth_vlc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/src/gmyth_vlc.c Wed Feb 07 00:03:05 2007 +0000 @@ -0,0 +1,284 @@ +/** + * GMyth Library + * + * @file gmyth/gmyth_vlc.c + * + * @brief

GMythVLC library provides functions that + * interact with a VLC server running telnet interface. + * + * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia. + * @author Artur Duque de Souza + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "gmyth_vlc.h" +#include "gmyth_debug.h" +#include "gmyth_socket.h" + + + +/** Primitive function to send a message through the socket + * + * @param socket + * @param msg the message itself + * @return 0 if success + */ +int socket_send(int socket, gchar* msg) +{ + size_t size = strlen(msg) + 1; + gchar* final = (gchar *)g_malloc0(sizeof(gchar) * size); + g_snprintf(final, size+1, "%s\n", msg); + + if (send(socket, final, strlen(final), 0) == -1) + perror("GMyth_VLC: send error"); + + g_free(final); + return 0; +} + + +/** Primitive function to receive a message through the socket + * + * @param socket + * @param buf Buffer to put the message + * @return 0 if success + */ +int socket_recv(int socket, gchar* buf) +{ + int numbytes = 0; + + if ((numbytes=recv(socket, buf, BUFFER-1, 0)) == -1) + { + perror("GMyth_VLC: recv error"); + return -1; + } + + buf[numbytes-1] = '\0'; + return numbytes; +} + + +/** Function that adds options to the output media + * + * @param vlc structure with options for vlc + * @param output the number of the output media + * @param kind the type of option we'll change + * @param the params for the option + * @return 0 if success + */ +int gmyth_vlc_setup_output(GMythVlc *vlc, int output, \ + gchar* kind, gchar* opts) +{ + int ret; + + size_t size = strlen(opts) + 25; + gchar* msg = g_malloc0(sizeof(gchar) * size); + g_snprintf(msg, size, "setup output%d %s %s", output,\ + kind, opts); + + ret = socket_send(vlc->sockfd, msg); + + g_free(msg); + return ret; +} + + + +/** Function to clean the playlist + * + * @param vlc structure with options for vlc + * @param output the number of the output media + * @param file the file we want to insert in the playlist + * @return 0 if success + */ +int gmyth_vlc_clean_playlist(GMythVlc *vlc) +{ + return socket_send(vlc->sockfd, "del all"); +} + + +/** Function to control the playlist + * + * @param vlc structure with options for vlc + * @param output the number of the output media + * @param command play, stop or pause(just for vod) + * @return 0 if success + */ +int gmyth_vlc_control_input(GMythVlc *vlc, int output, \ + gchar* command) +{ + size_t size = 25; + gchar* msg = g_malloc0(sizeof(gchar) * size); + g_snprintf(msg, size, "control output%d %s", output,\ + command); + + int ret = socket_send(vlc->sockfd, msg); + + g_free(msg); + return ret; +} + + + +/** Function to insert an item in the playlist + * + * @param vlc structure with options for vlc + * @param output the number of the output media + * @param file the file we want to insert in the playlist + * @return 0 if success + */ +int gmyth_vlc_create_input(GMythVlc *vlc, int output,\ + gchar* file) +{ + return gmyth_vlc_setup_output(vlc, output, "input",\ + file); +} + + +/** Function to create a channel in vlc + * + * @param vlc structure with options for vlc + * @param type the type of channel (broadcast, vod...) + * @param port + * @return 0 if success + */ +int gmyth_vlc_create_channel(GMythVlc *vlc, gchar* type,\ + int port) +{ + int ret; + size_t size = 40; + gchar* msg = (gchar *)g_malloc0(sizeof(gchar) * size); + g_snprintf(msg, size, "new output%d %s enabled loop", \ + vlc->n_outputs, type); + + ret = socket_send(vlc->sockfd, msg); + + if (ret > -1) + { + gmyth_vlc_setup_output(vlc, vlc->n_outputs, "option", \ + "sout-keep=1"); + + g_free(msg); + size = 256; + msg = (gchar *)g_malloc0(sizeof(gchar) * size); + + // Best transcode option for N800 + g_snprintf(msg, size, "#transcode{vcodec=mp1v,vb=384," + "fps=25.0,scale=0.5,acodec=mpga," + "ab=64,channels=1}:duplicate{dst=" + "std{access=http,mux=mpeg1,dst=" + ":%d}}", port); + + ret = gmyth_vlc_setup_output(vlc, vlc->n_outputs, "output", \ + msg); + + vlc->n_outputs++; + } + + g_free(msg); + + return ret; +} + + +/** Function to connect to vlc on the backend + * + * @param vlc structure with options for vlc + * @param backend_info infos about the backend + * @param passwd the password for telnet interface + * @return 0 if success + */ +int gmyth_vlc_connect(GMythVlc *vlc, GMythBackendInfo *backend_info,\ + gchar* passwd) +{ + int numbytes; + + if ((vlc->he=gethostbyname(backend_info->hostname)) == NULL) + { + herror("GMyth_VLC: gethostbyname error"); + return -1; + } + + if ((vlc->sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) + { + perror("GMyth_VLC: socket error"); + return -1; + } + + // Socket properties + vlc->their_addr.sin_family = AF_INET; + vlc->their_addr.sin_port = htons(VLC_TELNET_PORT); + vlc->their_addr.sin_addr = *((struct in_addr *)vlc->he->h_addr); + memset(&(vlc->their_addr.sin_zero), '\0', 8); + + if (connect(vlc->sockfd, (struct sockaddr *)&(vlc->their_addr), + sizeof(struct sockaddr)) == -1) + { + perror("GMyth_VLC: connect error. Check VLC's telnet interface"); + return -1; + } + + + // Receive the Password's Prompt + numbytes = socket_recv(vlc->sockfd, vlc->buf); + + // Send the Password. We don't have to + // care about passwords being sent in plain text + // because telnet protocol does it. + socket_send(vlc->sockfd, passwd); + + // Receive the Welcome msg + numbytes = socket_recv(vlc->sockfd, vlc->buf); + if (numbytes > -1) + if (strncmp(vlc->buf,"\r\nWrong password.", 17) == 0) + { + perror("Gmyth_VLC: passwd error. Check your passwd"); + return -2; + } + + + return 0; +} + + +/** Function to disconnect from vlc + * + * @param vlc structure with options for vlc + * @param backend_info infos about the backend + * @return 0 if success + */ +int gmyth_vlc_disconnect(GMythVlc *vlc) +{ + + int ret; + + ret = gmyth_vlc_clean_playlist(vlc); + + if (ret > -1) + { + vlc->n_outputs = 0; + vlc->n_inputs = 0; + } + + return close(vlc->sockfd); +} diff -r 73461d8db7ec -r 818deb9ae65d gmyth/src/gmyth_vlc.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/src/gmyth_vlc.h Wed Feb 07 00:03:05 2007 +0000 @@ -0,0 +1,97 @@ +/** + * GMyth Library + * + * @file gmyth/gmyth_vlc.c + * + * @brief

GMythVLC library provides functions that + * interact with a VLC server running telnet interface. + * + * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia. + * @author Artur Duque de Souza + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __GMYTH_VLC_H__ +#define __GMYTH_VLC_H__ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "gmyth_backendinfo.h" +#include "gmyth_util.h" + +G_BEGIN_DECLS + +#define VLC_TELNET_PORT 4212 +#define BUFFER 512 + +typedef struct _GMythVlc GMythVlc; + +struct _GMythVlc +{ + int sockfd; + + // Number of outputs used + int n_outputs; + + // Number of inputs + int n_inputs; + + // Socket vars + struct hostent *he; + struct sockaddr_in their_addr; + + char buf[BUFFER]; +}; + + + +int gmyth_vlc_setup_output(GMythVlc *vlc, int output, \ + gchar* kind, gchar* opts); + + +int gmyth_vlc_clean_playlist(GMythVlc *vlc); + + +int gmyth_vlc_control_input(GMythVlc *vlc, int output, \ + gchar* command); + +int gmyth_vlc_create_input(GMythVlc *vlc, int output,\ + gchar* file); + +int gmyth_vlc_create_channel(GMythVlc *vlc, gchar* type,\ + int port); + +int gmyth_vlc_connect(GMythVlc *vlc, GMythBackendInfo *backend_info,\ + gchar* passwd); + +int gmyth_vlc_disconnect(GMythVlc *vlc); + +G_END_DECLS + +#endif /* __GMYTH_VLC_H__ */ diff -r 73461d8db7ec -r 818deb9ae65d gmyth/tests/gmyth_test_http.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/gmyth_test_http.c Wed Feb 07 00:03:05 2007 +0000 @@ -0,0 +1,24 @@ +#include +#include "gmyth.h" +#include + +int +main (int args, const char **argv) +{ + GMythBackendInfo *backend_info; + g_type_init(); + //g_thread_init(NULL); + + backend_info = gmyth_backend_info_new (); + + gmyth_backend_info_set_hostname (backend_info, "192.168.3.165"); + gmyth_backend_info_set_port (backend_info, 6543); + + GTimeVal* start = gmyth_util_string_to_time_val("2006-01-01T00:00"); + GTimeVal* end = gmyth_util_string_to_time_val("2007-01-01T00:00"); + GMythEpg epg; + epg = retrieve_epg(backend_info, 6544, start, end, 0, 2, "True"); + + + return 0; +} diff -r 73461d8db7ec -r 818deb9ae65d gmyth/tests/gmyth_test_vlc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/tests/gmyth_test_vlc.c Wed Feb 07 00:03:05 2007 +0000 @@ -0,0 +1,28 @@ +#include +#include "gmyth.h" +#include + +int +main (int args, const char **argv) +{ + GMythBackendInfo *backend_info; + g_type_init(); + //g_thread_init(NULL); + + backend_info = gmyth_backend_info_new (); + + GMythVlc vlc; + vlc.n_inputs = 0; + vlc.n_outputs = 0; + + gmyth_backend_info_set_hostname (backend_info, "192.168.3.137"); + gmyth_backend_info_set_port (backend_info, 6543); + + gmyth_vlc_connect(&vlc, backend_info, "admin"); + gmyth_vlc_create_channel(&vlc, "broadcast", 8080); + gmyth_vlc_create_input(&vlc, 0, "/tmp/grande.nuv"); + gmyth_vlc_control_input(&vlc, 0, "play"); + gmyth_vlc_disconnect(&vlc); + + return 0; +} diff -r 73461d8db7ec -r 818deb9ae65d gmyth/tests/http.c --- a/gmyth/tests/http.c Tue Feb 06 15:00:23 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -#include -#include "gmyth.h" -#include - -int -main (int args, const char **argv) -{ - GMythBackendInfo *backend_info; - g_type_init(); - //g_thread_init(NULL); - - backend_info = gmyth_backend_info_new (); - - gmyth_backend_info_set_hostname (backend_info, "localhost"); - gmyth_backend_info_set_port (backend_info, 6543); - - GTimeVal* start = gmyth_util_string_to_time_val("2006-01-01T00:00"); - GTimeVal* end = gmyth_util_string_to_time_val("2007-01-01T00:00"); - GMythEpg epg; - epg = retrieve_epg(backend_info, 6544, start, end, 0, 2, "True"); - - - return 0; -}