# HG changeset patch # User morphbr # Date 1172672545 0 # Node ID 9f82d680cfe1b10caadf01c9a0976f688fcdc9bc # Parent 8ec23602c4ea8f51d2690b441b38f1f6284b9d4a [svn r384] - Added gmyth_jobqueue to handle messages between gmyth and mythbackend regarding the use of mythbackend's jobqueue - Added gmyth_transcode to handle remote video transcoding diff -r 8ec23602c4ea -r 9f82d680cfe1 gmyth/src/Makefile.am --- a/gmyth/src/Makefile.am Mon Feb 26 23:00:35 2007 +0000 +++ b/gmyth/src/Makefile.am Wed Feb 28 14:22:25 2007 +0000 @@ -18,14 +18,16 @@ 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 \ + gmyth_vlc.c \ + gmyth_jobqueue.c \ + gmyth_transcode.c \ $(BUILT_SOURCES) @@ -42,16 +44,16 @@ mv gmyth_marshal.c.tmp gmyth_marshal.c libgmyth_la_CFLAGS = \ - -DDATADIR=\"$(pkgdatadir)\" \ + -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) \ @@ -63,7 +65,7 @@ $(pkgincludedir) libgmyth_include_HEADERS = \ - gmyth.h \ + gmyth.h \ gmyth_common.h \ gmyth_debug.h \ gmyth_epg.h \ @@ -75,13 +77,15 @@ 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_uri.h \ gmyth_http.h \ - gmyth_vlc.h + gmyth_vlc.h \ + gmyth_jobqueue.h \ + gmyth_transcode.h CLEANFILES = $(BUILT_SOURCES) diff -r 8ec23602c4ea -r 9f82d680cfe1 gmyth/src/gmyth.h --- a/gmyth/src/gmyth.h Mon Feb 26 23:00:35 2007 +0000 +++ b/gmyth/src/gmyth.h Wed Feb 28 14:22:25 2007 +0000 @@ -48,5 +48,7 @@ #include #include #include +#include +#include #endif /* _GMYTH_H_ */ diff -r 8ec23602c4ea -r 9f82d680cfe1 gmyth/src/gmyth_jobqueue.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/src/gmyth_jobqueue.c Wed Feb 28 14:22:25 2007 +0000 @@ -0,0 +1,171 @@ +/** + * GMyth Library + * + * @file gmyth/gmyth_jobqueue.c + * + * @brief

Library to use JobQueue from mythbackend + * + * 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 "gmyth_jobqueue.h" +#include "gmyth_http.h" +#include "gmyth_debug.h" +#include "gmyth_socket.h" + +/** Function to connect + * + * @param backend_info the backendinfo + * @return gboolean - result of connection + * + */ +GMythSocket* +backend_connect (GMythBackendInfo *backend_info) +{ + GMythSocket *socket = gmyth_socket_new (); + if (gmyth_socket_connect_to_backend (socket, + gmyth_backend_info_get_hostname (backend_info), + gmyth_backend_info_get_port (backend_info), TRUE) == TRUE) { + g_debug ("Backend socket connection success"); + return socket; + } else { + g_debug ("Connection failed"); + return NULL; + } +} + + +/** Function to send a command to the backend + * + * @param socket pointer to a socket + * @param action the action itself + * @param job the action itself + * @param chanid the action itself + * @param starttime the action itself + * @param options the action itself + * @return the value returned by the backend + * + */ +GString* send_command(GMythSocket *socket, gchar* action, + gchar* job, gint chanid, gchar* starttime, + gchar* options) +{ + GString* command = g_string_new (""); + GMythStringList *retlist = gmyth_string_list_new(); + + g_string_printf(command, "JOBQUEUE %s %s %d %s %s", action, job, + chanid, starttime, options); + + gmyth_string_list_append_string (retlist, command); + gmyth_socket_write_stringlist (socket, retlist); + + // receive answer + gmyth_socket_read_stringlist (socket, retlist); + return gmyth_string_list_get_string(retlist, 0); +} + + +/** Function to analyze the response from the backend + * + * @param ret the msg returned by the backend + * @param value the expected value + * @return 0 if success and -1 if error + * + */ +gint test_result(gchar* ret, gchar* value) +{ + if (g_ascii_strcasecmp(ret, value)) + return 0; + else + { + g_debug("JobQueue Error: %s", ret); + return -1; + } + +} + +/** Function to add a job inside JOBQUEUE + * + * @param transcode object holding all the info about the transcoding + * @param job the job you want to add the action + * @return the value of the key + * + */ +gint gmyth_jobqueue_add_job (GMythTranscode* transcode, GString* job) +{ + GMythSocket *socket = backend_connect(transcode->backend_info); + if (socket != NULL) + { + GString* options = g_string_new (""); + + if (g_ascii_strcasecmp(job->str, "JOB_TRANSCODE")) + { + if (transcode->cutlist) + g_string_append(options, " JOB_USE_CUTLIST"); + + if (transcode->output) + g_string_append_printf(options, " JOB_OUTPUT %s",\ + transcode->output_filename->str); + + if (transcode->profile != NULL) + g_string_append_printf(options, " %s", transcode->profile->str); + } + + GString* ret = send_command(socket, "ADD", job->str, transcode->chanid, + transcode->starttime->str, options->str); + + return test_result(ret->str, "JOBQUEUE_OK"); + } + else + { + g_debug("JobQueue Connection Failed"); + return -1; + } +} + +/** Function to change a job cmd inside JOBQUEUE + * + * @param transcode object holding all the info about the transcoding + * @param action the action (ADD) + * @param job the job you want to add the action + * @return the value of the key + * + */ +gint gmyth_jobqueue_change_cmd (GMythTranscode* transcode, GString* action, + GString* job) +{ + GMythSocket *socket = backend_connect(transcode->backend_info); + if (socket != NULL) + { + GString* ret = send_command(socket, action->str, job->str, + transcode->chanid, + transcode->starttime->str, ""); + + return test_result(ret->str, "JOBQUEUE_CHANGED_CMD_OK"); + } + else + { + g_debug("JobQueue Connection Failed"); + return -1; + } +} diff -r 8ec23602c4ea -r 9f82d680cfe1 gmyth/src/gmyth_jobqueue.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/src/gmyth_jobqueue.h Wed Feb 28 14:22:25 2007 +0000 @@ -0,0 +1,53 @@ +/** + * GMyth Library + * + * @file gmyth/gmyth_jobqueue.h + * + * @brief

Library to use JobQueue from mythbackend + * + * 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_JOBQUEUE_H__ +#define __GMYTH_JOBQUEUE_H__ + +#include + +#include +#include +#include +#include +#include +#include + +#include "gmyth_stringlist.h" +#include "gmyth_backendinfo.h" +#include "gmyth_transcode.h" +#include "gmyth_socket.h" +#include "gmyth_util.h" + +G_BEGIN_DECLS + +gint gmyth_jobqueue_add_job (GMythTranscode* transcode, GString* job); +gint gmyth_jobqueue_change_cmd (GMythTranscode* transcode, GString* action, + GString* job); + +G_END_DECLS + +#endif /* __GMYTH_JOBQUEUE_H__ */ diff -r 8ec23602c4ea -r 9f82d680cfe1 gmyth/src/gmyth_transcode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/src/gmyth_transcode.c Wed Feb 28 14:22:25 2007 +0000 @@ -0,0 +1,236 @@ +/** + * GMyth Library + * + * @file gmyth/gmyth_transcode.c + * + * @brief

This file contains the transcode class. + * + * 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 +#include + +#include "gmyth_transcode.h" +#include "gmyth_util.h" +#include "gmyth_debug.h" + +static void gmyth_transcode_class_init (GMythTranscodeClass *klass); +static void gmyth_transcode_init (GMythTranscode *object); + +static void gmyth_transcode_dispose (GObject *object); +static void gmyth_transcode_finalize (GObject *object); + +G_DEFINE_TYPE(GMythTranscode, gmyth_transcode, G_TYPE_OBJECT) + +static void +gmyth_transcode_class_init (GMythTranscodeClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + gobject_class->dispose = gmyth_transcode_dispose; + gobject_class->finalize = gmyth_transcode_finalize; +} + +static void +gmyth_transcode_init (GMythTranscode *gmyth_transcode) +{ + +} + +static void +gmyth_transcode_dispose (GObject *object) +{ + GMythTranscode *transcode = GMYTH_TRANSCODE(object); + + if (transcode->output_filename) + g_free(transcode->output_filename); + + if (transcode->filename) + g_free(transcode->filename); + + if (transcode->profile) + g_free(transcode->profile); + + if (transcode->starttime) + g_free(transcode->starttime); + + G_OBJECT_CLASS (gmyth_transcode_parent_class)->dispose (object); +} + +static void +gmyth_transcode_finalize (GObject *object) +{ + g_signal_handlers_destroy (object); + G_OBJECT_CLASS (gmyth_transcode_parent_class)->finalize (object); +} + +/** + * Creates a new instance of GMythTranscode. + * + * @return a new instance of GMythTranscode. + **/ +GMythTranscode* +gmyth_transcode_new (void) +{ + GMythTranscode *transcode = GMYTH_TRANSCODE\ + (g_object_new(GMYTH_TRANSCODE_TYPE, NULL)); + return transcode; +} + +/** + * + * gmyth_transcode_date_change_format + * @brief converts a string like YYYY-MM-DDTHH:MM:SS into YYYYMMDDHHMMSS (vice versa) + * @param date_s gchar* + * @return gchar* with file or iso format + * + **/ +GString* gmyth_transcode_date_change_format (GString* date_s, int format) +{ + if (date_s->str != NULL) + { + gint length = date_s->len; + + //create the right date format + gchar* src = (gchar*)g_malloc0(sizeof(gchar) * length); + strncpy(src, date_s->str, length); + + gchar* dst; + + if (format == DATE_FILE) + { + dst = (gchar*)g_malloc0(sizeof(gchar) * 16); + g_snprintf(dst, 20, "%.4s%.2s%.2s%.2s%.2s%.2s\n", src, src+5,\ + src+7, src+9, src+11, src+13); + dst[14] = '\0'; + } + else + if (format == DATE_ISO) + { + gchar* dst = (gchar*)g_malloc0(sizeof(gchar) * 20); + g_snprintf(dst, 20, "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s\n", src, src+4,\ + src+6, src+8, src+10, src+12); + dst[19] = '\0'; + } + + GString* ret = g_string_new(dst); + + g_free(src); + g_free(dst); + + return ret; + } + else return NULL; +} + +/** + * + * gmyth_transcode_set_cutlist + * @brief set transcode to use cutlist + * @param value gboolean + * @return void set's up the var to value + * + **/ +void gmyth_transcode_set_cutlist (GMythTranscode* transcode, + gboolean value) +{ + transcode->cutlist = value; +} + +/** + * + * gmyth_transcode_set_output + * @brief set transcode to use output + * @param value gboolean + * @param outfile filename of output + * @return void set's up the var to value + * + **/ +void gmyth_transcode_set_output (GMythTranscode* transcode, + gboolean value, GString* outputfile) +{ + transcode->output = value; + transcode->output_filename = outputfile; +} + +/** + * + * gmyth_transcode_set_file + * @brief set the file to transcode + * @param file filename + * @return void set's up the var to value + * + **/ +void gmyth_transcode_set_filename (GMythTranscode* transcode, + GString* file) +{ + transcode->filename = file; +} + + +/** + * + * gmyth_transcode_set_backendinfo + * @brief set transcode's backendinfo + * @param backendinfo GMythBackendInfo + * @return void set's up the var to value + * + **/ +void gmyth_transcode_set_backend (GMythTranscode* transcode, + GMythBackendInfo *backend) +{ + transcode->backend_info = backend; +} + + +/** + * + * gmyth_transcode_get_profile_list + * @brief get profile list from the backend + * @param backend_info GMythBackendInfo* + * @return GSList + * + **/ +GSList* gmyth_transcode_get_profile_list (GMythBackendInfo *backend_info) +{ + //TODO: CODE THIS + return NULL; +} + +/** + * + * gmyth_transcode_create_profile + * @brief get profile list from the backend + * @param backend_info GMythBackendInfo* + * @return gint representing the result + * + **/ +gint gmyth_transcode_create_profile (GMythBackendInfo *backend_info) +{ + //TODO: CODE THIS + return 0; +} diff -r 8ec23602c4ea -r 9f82d680cfe1 gmyth/src/gmyth_transcode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth/src/gmyth_transcode.h Wed Feb 28 14:22:25 2007 +0000 @@ -0,0 +1,89 @@ +/** + * GMyth Library + * + * @file gmyth/gmyth_transcode.h + * + * @brief

This file contains the transcode class. + * + * 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_TRANSCODE_H +#define _GMYTH_TRANSCODE_H + +#include +#include + +#include "gmyth_stringlist.h" +#include "gmyth_backendinfo.h" +#include "gmyth_socket.h" + +G_BEGIN_DECLS + +#define GMYTH_TRANSCODE_TYPE (gmyth_transcode_get_type ()) +#define GMYTH_TRANSCODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_TRANSCODE_TYPE, GMythTranscode)) +#define GMYTH_TRANSCODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_TRANSCODE_TYPE, GMythTranscodeClass)) +#define IS_GMYTH_TRANSCODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_TRANSCODE_TYPE)) +#define IS_GMYTH_TRANSCODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_TRANSCODE_TYPE)) +#define GMYTH_TRANSCODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_TRANSCODE_TYPE, GMythTranscodeClass)) + +#define DATE_ISO 0 +#define DATE_FILE 1 + +typedef struct _GMythTranscode GMythTranscode; +typedef struct _GMythTranscodeClass GMythTranscodeClass; + +struct _GMythTranscodeClass +{ + GObjectClass parent_class; + + /* callbacks */ +}; + +/** + * The GMythTranscode structure is a class to implement functions + * related to transcoding. + */ +struct _GMythTranscode +{ + /* all private members */ + GObject parent; + + gboolean cutlist; + gboolean output; + + GString* output_filename; + GString* filename; + GString* profile; + GString* starttime; + + gint chanid; + + GMythBackendInfo* backend_info; +}; + +GType gmyth_transcode_type (void); + +GMythTranscode* gmyth_transcode_new (void); + +G_END_DECLS + +#endif /*_GMYTH_TRANSCODE_H*/