# HG changeset patch
# User melunko
# Date 1173229222 0
# Node ID da672300b1ab815030f5ab3202980d9e250f80f3
# Parent  0dd110388c6f5ca583c0a0ee0eadf14bf735c907
[svn r399] Fixed svn file error for gmyth_transcoder.c/h

diff -r 0dd110388c6f -r da672300b1ab gmyth/src/gmyth_transcoder.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth/src/gmyth_transcoder.c	Wed Mar 07 01:00:22 2007 +0000
@@ -0,0 +1,260 @@
+/**
+ * GMyth Library
+ * 
+ * @file gmyth/gmyth_transcoder.c
+ * 
+ * @brief <p> This file contains the transcoder class.
+ *
+ * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
+ * @author Artur Duque de Souza <artur.souza@indt.org.br>
+ *
+ */
+/*
+ * 
+ * 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 <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "gmyth_util.h"
+#include "gmyth_debug.h"
+
+#include "gmyth_jobqueue.h"
+#include "gmyth_transcoder.h"
+
+static void gmyth_transcoder_class_init          (GMythTranscoderClass *klass);
+static void gmyth_transcoder_init                (GMythTranscoder *object);
+
+static void gmyth_transcoder_dispose  (GObject *object);
+static void gmyth_transcoder_finalize (GObject *object);
+
+G_DEFINE_TYPE(GMythTranscoder, gmyth_transcoder, G_TYPE_OBJECT)
+
+static void
+gmyth_transcoder_class_init (GMythTranscoderClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+    gobject_class->dispose  = gmyth_transcoder_dispose;
+    gobject_class->finalize = gmyth_transcoder_finalize;
+}
+
+static void
+gmyth_transcoder_init (GMythTranscoder *transcoder)
+{
+    transcoder->started = FALSE;
+}
+
+static void
+gmyth_transcoder_dispose  (GObject *object)
+{
+    GMythTranscoder *transcoder = GMYTH_TRANSCODER(object);
+
+    g_free (transcoder->output_filename);
+    g_free (transcoder->filename);
+    g_free (transcoder->profile);
+    g_free (transcoder->starttime);
+
+    if (transcoder->backend_info)
+	g_object_unref (transcoder->backend_info);
+
+    G_OBJECT_CLASS (gmyth_transcoder_parent_class)->dispose (object);
+}
+
+static void
+gmyth_transcoder_finalize (GObject *object)
+{
+    g_signal_handlers_destroy (object);
+    G_OBJECT_CLASS (gmyth_transcoder_parent_class)->finalize (object);
+}
+
+/**
+ * Creates a new instance of GMythTranscoder.
+ * 
+ * @return a new instance of GMythTranscoder.
+ **/
+GMythTranscoder*
+gmyth_transcoder_new (GMythBackendInfo *backend_info)
+{
+    GMythTranscoder *transcoder = GMYTH_TRANSCODER\
+                                 (g_object_new(GMYTH_TRANSCODER_TYPE, NULL));
+
+    g_object_ref (backend_info);
+    transcoder->backend_info = backend_info;
+
+    return transcoder;
+}
+
+/**
+ *
+ * gmyth_transcoder_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
+ *
+ **/
+static gchar* gmyth_transcoder_date_change_format (gchar* date_s, int format)
+{
+    if (date_s != NULL)
+    {
+        gint length = strlen(date_s);
+
+        //create the right date format
+        gchar* src = (gchar*)g_malloc0(sizeof(gchar) * length);
+        strncpy(src, date_s, length);
+
+        gchar* dst;
+
+        if (format == DATE_FILE)
+        {
+            dst = (gchar*)g_malloc0(sizeof(gchar) * 16);
+            snprintf(dst, 16, "%.4s%.2s%.2s%.2s%.2s%.2s", src, src+5,\
+                    src+7, src+9, src+11, src+13);
+            dst[15] = '\0';
+        } else if (format == DATE_ISO) {
+            dst = (gchar*)g_malloc0(sizeof(gchar) * 20);
+            snprintf(dst, 20, "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", src, src+4,\
+                    src+6, src+8, src+10, src+12);
+            dst[19] = '\0';
+        }
+
+        gchar* ret = g_strdup(dst);
+
+        g_free(src);
+        g_free(dst);
+
+        return ret;
+    }
+    else return NULL;
+}
+
+/**
+ *
+ * gmyth_transcoder_set_output
+ * @brief set transcoder to use output
+ * @param value gboolean
+ * @param outfile filename of output
+ * @return void set's up the var to value
+ *
+ **/
+void gmyth_transcoder_set_output (GMythTranscoder* transcoder,
+                                 gboolean value, gchar* outputfile)
+{
+    transcoder->output = value;
+    transcoder->output_filename = g_strdup(outputfile);
+}
+
+/**
+ *
+ * gmyth_transcoder_set_file
+ * @brief set the file to transcoder
+ * @param file filename
+ * @return void set's up the var to value
+ *
+ **/
+void gmyth_transcoder_set_filename (GMythTranscoder* transcoder, gchar* file)
+{
+    // fixme: if this method is called twice, memory will not be dealocated
+    // one transcoder can be used only for one file request?
+    if (file != NULL)
+    {
+        gchar** splited = g_strsplit(file, "_", 2);
+
+        // Get chanid
+        sscanf (splited[0],"%d", &(transcoder->chanid));
+
+        // Get starttime
+        gchar** date = g_strsplit(splited[1], ".", 2);
+        transcoder->starttime = gmyth_transcode_date_change_format(date[0], DATE_ISO);
+
+        transcoder->filename = g_strdup(file);
+    }
+}
+
+
+/**
+ *
+ * gmyth_transcoder_set_profile
+ * @brief set transcoder's profile
+ * @param rec GMythTranscoder*
+ * @param value the value
+ * @return gint representing the result
+ *
+ **/
+gint
+gmyth_transcoder_set_profile (GMythTranscoder* trans,
+                                  gchar* value)
+{
+    g_return_val_if_fail (value != NULL, -1);
+
+    trans->profile = g_strndup(value, strlen(value));
+
+    return 0;
+}
+
+gboolean
+gmyth_transcoder_start (GMythTranscoder* trans)
+{
+    g_return_val_if_fail (trans != NULL, FALSE);
+
+    if (trans->started == FALSE) { // not started yet
+        trans->started = gmyth_jobqueue_add_job(trans, "JOB_TRANSCODE");
+	if (trans->started == FALSE)
+	    g_debug ("Error while starting GMythTranscoder to file: %s", trans->output_filename);
+    } else {
+	g_debug ("GMythTransfer already started!");
+    }
+
+    return trans->started;
+}
+
+gboolean
+gmyth_transcoder_pause (GMythTranscoder* trans)
+{
+    g_return_val_if_fail (trans != NULL, FALSE);
+
+    return gmyth_jobqueue_change_cmd (trans, "PAUSE", "JOB_TRANSCODE");
+}
+
+gboolean
+gmyth_transcoder_resume (GMythTranscoder* trans)
+{
+    g_return_val_if_fail (trans != NULL, FALSE);
+
+    return gmyth_jobqueue_change_cmd (trans, "RESUME", "JOB_TRANSCODE");
+}
+
+gboolean
+gmyth_transcoder_cancel (GMythTranscoder* trans)
+{
+    g_return_val_if_fail (trans != NULL, FALSE);
+
+    return gmyth_jobqueue_change_cmd (trans, "STOP", "JOB_TRANSCODE");
+}
+
+//fixme: implement this method
+gint
+gmyth_transcoder_get_progress (GMythTranscoder* trans)
+{
+    static int fixme = 0;
+    
+    return (fixme++)%101;
+}
diff -r 0dd110388c6f -r da672300b1ab gmyth/src/gmyth_transcoder.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth/src/gmyth_transcoder.h	Wed Mar 07 01:00:22 2007 +0000
@@ -0,0 +1,101 @@
+/**
+ * GMyth Library
+ * 
+ * @file gmyth/gmyth_transcoder.h
+ * 
+ * @brief <p> This file contains the transcoder class.
+ *
+ * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
+ * @author Artur Duque de Souza <artur.souza@indt.org.br>
+ *
+ */
+/*
+ * 
+ * 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_TRANSCODER_H
+#define _GMYTH_TRANSCODER_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "gmyth_stringlist.h"
+#include "gmyth_backendinfo.h"
+#include "gmyth_socket.h"
+#include "gmyth_http.h"
+#include "gmyth_recprofile.h"
+
+G_BEGIN_DECLS
+
+#define GMYTH_TRANSCODER_TYPE               (gmyth_transcoder_get_type ())
+#define GMYTH_TRANSCODER(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_TRANSCODER_TYPE, GMythTranscoder))
+#define GMYTH_TRANSCODER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_TRANSCODER_TYPE, GMythTranscoderClass))
+#define IS_GMYTH_TRANSCODER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_TRANSCODER_TYPE))
+#define IS_GMYTH_TRANSCODER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_TRANSCODER_TYPE))
+#define GMYTH_TRANSCODER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_TRANSCODER_TYPE, GMythTranscoderClass))
+
+#define DATE_ISO 0
+#define DATE_FILE 1
+
+typedef struct _GMythTranscoder         GMythTranscoder;
+typedef struct _GMythTranscoderClass    GMythTranscoderClass;
+
+struct _GMythTranscoderClass
+{
+  GObjectClass parent_class;
+
+  /* callbacks */
+};
+
+/**
+ * The GMythTranscoder structure is a class to implement functions
+ * related to transcoding.
+ */
+struct _GMythTranscoder
+{
+    GObject parent;
+
+    gboolean cutlist;
+    gboolean output;
+    gboolean started;
+
+    /* private begin */
+    gchar* output_filename;
+    gchar* filename;
+    gchar* profile;
+    /* private end */
+
+    gchar* starttime;
+
+    gint chanid;
+
+    GMythBackendInfo* backend_info;
+};
+
+GType gmyth_transcoder_type (void);
+
+GMythTranscoder* gmyth_transcoder_new (GMythBackendInfo* backend_info);
+
+void gmyth_transcoder_set_output (GMythTranscoder* transcode,
+                                 gboolean value, gchar* outputfile);
+
+void gmyth_transcoder_set_filename (GMythTranscoder* transcode, gchar* file);
+
+gint gmyth_transcoder_set_profile (GMythTranscoder* trans, gchar* value);
+
+G_END_DECLS
+
+#endif /*_GMYTH_TRANSCODER_H*/