[svn r399] Fixed svn file error for gmyth_transcoder.c/h trunk
authormelunko
Wed Mar 07 01:00:22 2007 +0000 (2007-03-07)
branchtrunk
changeset 394da672300b1ab
parent 393 0dd110388c6f
child 395 c1ba898fc4ed
[svn r399] Fixed svn file error for gmyth_transcoder.c/h
gmyth/src/gmyth_transcoder.c
gmyth/src/gmyth_transcoder.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth/src/gmyth_transcoder.c	Wed Mar 07 01:00:22 2007 +0000
     1.3 @@ -0,0 +1,260 @@
     1.4 +/**
     1.5 + * GMyth Library
     1.6 + * 
     1.7 + * @file gmyth/gmyth_transcoder.c
     1.8 + * 
     1.9 + * @brief <p> This file contains the transcoder class.
    1.10 + *
    1.11 + * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
    1.12 + * @author Artur Duque de Souza <artur.souza@indt.org.br>
    1.13 + *
    1.14 + */
    1.15 +/*
    1.16 + * 
    1.17 + * This program is free software; you can redistribute it and/or modify
    1.18 + * it under the terms of the GNU Lesser General Public License as published by
    1.19 + * the Free Software Foundation; either version 2 of the License, or
    1.20 + * (at your option) any later version.
    1.21 + *
    1.22 + * This program is distributed in the hope that it will be useful,
    1.23 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.24 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.25 + * GNU General Public License for more details.
    1.26 + *
    1.27 + * You should have received a copy of the GNU Lesser General Public License
    1.28 + * along with this program; if not, write to the Free Software
    1.29 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.30 + */
    1.31 +
    1.32 + 
    1.33 +#ifdef HAVE_CONFIG_H
    1.34 +#include "config.h"
    1.35 +#endif
    1.36 +
    1.37 +#include <stdlib.h>
    1.38 +#include <string.h>
    1.39 +#include <assert.h>
    1.40 +
    1.41 +#include "gmyth_util.h"
    1.42 +#include "gmyth_debug.h"
    1.43 +
    1.44 +#include "gmyth_jobqueue.h"
    1.45 +#include "gmyth_transcoder.h"
    1.46 +
    1.47 +static void gmyth_transcoder_class_init          (GMythTranscoderClass *klass);
    1.48 +static void gmyth_transcoder_init                (GMythTranscoder *object);
    1.49 +
    1.50 +static void gmyth_transcoder_dispose  (GObject *object);
    1.51 +static void gmyth_transcoder_finalize (GObject *object);
    1.52 +
    1.53 +G_DEFINE_TYPE(GMythTranscoder, gmyth_transcoder, G_TYPE_OBJECT)
    1.54 +
    1.55 +static void
    1.56 +gmyth_transcoder_class_init (GMythTranscoderClass *klass)
    1.57 +{
    1.58 +    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
    1.59 +    gobject_class->dispose  = gmyth_transcoder_dispose;
    1.60 +    gobject_class->finalize = gmyth_transcoder_finalize;
    1.61 +}
    1.62 +
    1.63 +static void
    1.64 +gmyth_transcoder_init (GMythTranscoder *transcoder)
    1.65 +{
    1.66 +    transcoder->started = FALSE;
    1.67 +}
    1.68 +
    1.69 +static void
    1.70 +gmyth_transcoder_dispose  (GObject *object)
    1.71 +{
    1.72 +    GMythTranscoder *transcoder = GMYTH_TRANSCODER(object);
    1.73 +
    1.74 +    g_free (transcoder->output_filename);
    1.75 +    g_free (transcoder->filename);
    1.76 +    g_free (transcoder->profile);
    1.77 +    g_free (transcoder->starttime);
    1.78 +
    1.79 +    if (transcoder->backend_info)
    1.80 +	g_object_unref (transcoder->backend_info);
    1.81 +
    1.82 +    G_OBJECT_CLASS (gmyth_transcoder_parent_class)->dispose (object);
    1.83 +}
    1.84 +
    1.85 +static void
    1.86 +gmyth_transcoder_finalize (GObject *object)
    1.87 +{
    1.88 +    g_signal_handlers_destroy (object);
    1.89 +    G_OBJECT_CLASS (gmyth_transcoder_parent_class)->finalize (object);
    1.90 +}
    1.91 +
    1.92 +/**
    1.93 + * Creates a new instance of GMythTranscoder.
    1.94 + * 
    1.95 + * @return a new instance of GMythTranscoder.
    1.96 + **/
    1.97 +GMythTranscoder*
    1.98 +gmyth_transcoder_new (GMythBackendInfo *backend_info)
    1.99 +{
   1.100 +    GMythTranscoder *transcoder = GMYTH_TRANSCODER\
   1.101 +                                 (g_object_new(GMYTH_TRANSCODER_TYPE, NULL));
   1.102 +
   1.103 +    g_object_ref (backend_info);
   1.104 +    transcoder->backend_info = backend_info;
   1.105 +
   1.106 +    return transcoder;
   1.107 +}
   1.108 +
   1.109 +/**
   1.110 + *
   1.111 + * gmyth_transcoder_date_change_format
   1.112 + * @brief converts a string like YYYY-MM-DDTHH:MM:SS into YYYYMMDDHHMMSS (vice versa)
   1.113 + * @param date_s gchar*
   1.114 + * @return gchar* with file or iso format
   1.115 + *
   1.116 + **/
   1.117 +static gchar* gmyth_transcoder_date_change_format (gchar* date_s, int format)
   1.118 +{
   1.119 +    if (date_s != NULL)
   1.120 +    {
   1.121 +        gint length = strlen(date_s);
   1.122 +
   1.123 +        //create the right date format
   1.124 +        gchar* src = (gchar*)g_malloc0(sizeof(gchar) * length);
   1.125 +        strncpy(src, date_s, length);
   1.126 +
   1.127 +        gchar* dst;
   1.128 +
   1.129 +        if (format == DATE_FILE)
   1.130 +        {
   1.131 +            dst = (gchar*)g_malloc0(sizeof(gchar) * 16);
   1.132 +            snprintf(dst, 16, "%.4s%.2s%.2s%.2s%.2s%.2s", src, src+5,\
   1.133 +                    src+7, src+9, src+11, src+13);
   1.134 +            dst[15] = '\0';
   1.135 +        } else if (format == DATE_ISO) {
   1.136 +            dst = (gchar*)g_malloc0(sizeof(gchar) * 20);
   1.137 +            snprintf(dst, 20, "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", src, src+4,\
   1.138 +                    src+6, src+8, src+10, src+12);
   1.139 +            dst[19] = '\0';
   1.140 +        }
   1.141 +
   1.142 +        gchar* ret = g_strdup(dst);
   1.143 +
   1.144 +        g_free(src);
   1.145 +        g_free(dst);
   1.146 +
   1.147 +        return ret;
   1.148 +    }
   1.149 +    else return NULL;
   1.150 +}
   1.151 +
   1.152 +/**
   1.153 + *
   1.154 + * gmyth_transcoder_set_output
   1.155 + * @brief set transcoder to use output
   1.156 + * @param value gboolean
   1.157 + * @param outfile filename of output
   1.158 + * @return void set's up the var to value
   1.159 + *
   1.160 + **/
   1.161 +void gmyth_transcoder_set_output (GMythTranscoder* transcoder,
   1.162 +                                 gboolean value, gchar* outputfile)
   1.163 +{
   1.164 +    transcoder->output = value;
   1.165 +    transcoder->output_filename = g_strdup(outputfile);
   1.166 +}
   1.167 +
   1.168 +/**
   1.169 + *
   1.170 + * gmyth_transcoder_set_file
   1.171 + * @brief set the file to transcoder
   1.172 + * @param file filename
   1.173 + * @return void set's up the var to value
   1.174 + *
   1.175 + **/
   1.176 +void gmyth_transcoder_set_filename (GMythTranscoder* transcoder, gchar* file)
   1.177 +{
   1.178 +    // fixme: if this method is called twice, memory will not be dealocated
   1.179 +    // one transcoder can be used only for one file request?
   1.180 +    if (file != NULL)
   1.181 +    {
   1.182 +        gchar** splited = g_strsplit(file, "_", 2);
   1.183 +
   1.184 +        // Get chanid
   1.185 +        sscanf (splited[0],"%d", &(transcoder->chanid));
   1.186 +
   1.187 +        // Get starttime
   1.188 +        gchar** date = g_strsplit(splited[1], ".", 2);
   1.189 +        transcoder->starttime = gmyth_transcode_date_change_format(date[0], DATE_ISO);
   1.190 +
   1.191 +        transcoder->filename = g_strdup(file);
   1.192 +    }
   1.193 +}
   1.194 +
   1.195 +
   1.196 +/**
   1.197 + *
   1.198 + * gmyth_transcoder_set_profile
   1.199 + * @brief set transcoder's profile
   1.200 + * @param rec GMythTranscoder*
   1.201 + * @param value the value
   1.202 + * @return gint representing the result
   1.203 + *
   1.204 + **/
   1.205 +gint
   1.206 +gmyth_transcoder_set_profile (GMythTranscoder* trans,
   1.207 +                                  gchar* value)
   1.208 +{
   1.209 +    g_return_val_if_fail (value != NULL, -1);
   1.210 +
   1.211 +    trans->profile = g_strndup(value, strlen(value));
   1.212 +
   1.213 +    return 0;
   1.214 +}
   1.215 +
   1.216 +gboolean
   1.217 +gmyth_transcoder_start (GMythTranscoder* trans)
   1.218 +{
   1.219 +    g_return_val_if_fail (trans != NULL, FALSE);
   1.220 +
   1.221 +    if (trans->started == FALSE) { // not started yet
   1.222 +        trans->started = gmyth_jobqueue_add_job(trans, "JOB_TRANSCODE");
   1.223 +	if (trans->started == FALSE)
   1.224 +	    g_debug ("Error while starting GMythTranscoder to file: %s", trans->output_filename);
   1.225 +    } else {
   1.226 +	g_debug ("GMythTransfer already started!");
   1.227 +    }
   1.228 +
   1.229 +    return trans->started;
   1.230 +}
   1.231 +
   1.232 +gboolean
   1.233 +gmyth_transcoder_pause (GMythTranscoder* trans)
   1.234 +{
   1.235 +    g_return_val_if_fail (trans != NULL, FALSE);
   1.236 +
   1.237 +    return gmyth_jobqueue_change_cmd (trans, "PAUSE", "JOB_TRANSCODE");
   1.238 +}
   1.239 +
   1.240 +gboolean
   1.241 +gmyth_transcoder_resume (GMythTranscoder* trans)
   1.242 +{
   1.243 +    g_return_val_if_fail (trans != NULL, FALSE);
   1.244 +
   1.245 +    return gmyth_jobqueue_change_cmd (trans, "RESUME", "JOB_TRANSCODE");
   1.246 +}
   1.247 +
   1.248 +gboolean
   1.249 +gmyth_transcoder_cancel (GMythTranscoder* trans)
   1.250 +{
   1.251 +    g_return_val_if_fail (trans != NULL, FALSE);
   1.252 +
   1.253 +    return gmyth_jobqueue_change_cmd (trans, "STOP", "JOB_TRANSCODE");
   1.254 +}
   1.255 +
   1.256 +//fixme: implement this method
   1.257 +gint
   1.258 +gmyth_transcoder_get_progress (GMythTranscoder* trans)
   1.259 +{
   1.260 +    static int fixme = 0;
   1.261 +    
   1.262 +    return (fixme++)%101;
   1.263 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gmyth/src/gmyth_transcoder.h	Wed Mar 07 01:00:22 2007 +0000
     2.3 @@ -0,0 +1,101 @@
     2.4 +/**
     2.5 + * GMyth Library
     2.6 + * 
     2.7 + * @file gmyth/gmyth_transcoder.h
     2.8 + * 
     2.9 + * @brief <p> This file contains the transcoder class.
    2.10 + *
    2.11 + * Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
    2.12 + * @author Artur Duque de Souza <artur.souza@indt.org.br>
    2.13 + *
    2.14 + */
    2.15 +/*
    2.16 + * 
    2.17 + * This program is free software; you can redistribute it and/or modify
    2.18 + * it under the terms of the GNU Lesser General Public License as published by
    2.19 + * the Free Software Foundation; either version 2 of the License, or
    2.20 + * (at your option) any later version.
    2.21 + *
    2.22 + * This program is distributed in the hope that it will be useful,
    2.23 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.24 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.25 + * GNU General Public License for more details.
    2.26 + *
    2.27 + * You should have received a copy of the GNU Lesser General Public License
    2.28 + * along with this program; if not, write to the Free Software
    2.29 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.30 + */
    2.31 +
    2.32 +#ifndef _GMYTH_TRANSCODER_H
    2.33 +#define _GMYTH_TRANSCODER_H
    2.34 +
    2.35 +#include <glib.h>
    2.36 +#include <glib-object.h>
    2.37 +
    2.38 +#include "gmyth_stringlist.h"
    2.39 +#include "gmyth_backendinfo.h"
    2.40 +#include "gmyth_socket.h"
    2.41 +#include "gmyth_http.h"
    2.42 +#include "gmyth_recprofile.h"
    2.43 +
    2.44 +G_BEGIN_DECLS
    2.45 +
    2.46 +#define GMYTH_TRANSCODER_TYPE               (gmyth_transcoder_get_type ())
    2.47 +#define GMYTH_TRANSCODER(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_TRANSCODER_TYPE, GMythTranscoder))
    2.48 +#define GMYTH_TRANSCODER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_TRANSCODER_TYPE, GMythTranscoderClass))
    2.49 +#define IS_GMYTH_TRANSCODER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMYTH_TRANSCODER_TYPE))
    2.50 +#define IS_GMYTH_TRANSCODER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMYTH_TRANSCODER_TYPE))
    2.51 +#define GMYTH_TRANSCODER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GMYTH_TRANSCODER_TYPE, GMythTranscoderClass))
    2.52 +
    2.53 +#define DATE_ISO 0
    2.54 +#define DATE_FILE 1
    2.55 +
    2.56 +typedef struct _GMythTranscoder         GMythTranscoder;
    2.57 +typedef struct _GMythTranscoderClass    GMythTranscoderClass;
    2.58 +
    2.59 +struct _GMythTranscoderClass
    2.60 +{
    2.61 +  GObjectClass parent_class;
    2.62 +
    2.63 +  /* callbacks */
    2.64 +};
    2.65 +
    2.66 +/**
    2.67 + * The GMythTranscoder structure is a class to implement functions
    2.68 + * related to transcoding.
    2.69 + */
    2.70 +struct _GMythTranscoder
    2.71 +{
    2.72 +    GObject parent;
    2.73 +
    2.74 +    gboolean cutlist;
    2.75 +    gboolean output;
    2.76 +    gboolean started;
    2.77 +
    2.78 +    /* private begin */
    2.79 +    gchar* output_filename;
    2.80 +    gchar* filename;
    2.81 +    gchar* profile;
    2.82 +    /* private end */
    2.83 +
    2.84 +    gchar* starttime;
    2.85 +
    2.86 +    gint chanid;
    2.87 +
    2.88 +    GMythBackendInfo* backend_info;
    2.89 +};
    2.90 +
    2.91 +GType gmyth_transcoder_type (void);
    2.92 +
    2.93 +GMythTranscoder* gmyth_transcoder_new (GMythBackendInfo* backend_info);
    2.94 +
    2.95 +void gmyth_transcoder_set_output (GMythTranscoder* transcode,
    2.96 +                                 gboolean value, gchar* outputfile);
    2.97 +
    2.98 +void gmyth_transcoder_set_filename (GMythTranscoder* transcode, gchar* file);
    2.99 +
   2.100 +gint gmyth_transcoder_set_profile (GMythTranscoder* trans, gchar* value);
   2.101 +
   2.102 +G_END_DECLS
   2.103 +
   2.104 +#endif /*_GMYTH_TRANSCODER_H*/