gmyth/src/gmyth_transcoder.c
branchtrunk
changeset 750 312d6bc514f3
parent 701 2f28edb4d804
child 754 cb885ee44618
     1.1 --- a/gmyth/src/gmyth_transcoder.c	Wed May 23 19:50:41 2007 +0100
     1.2 +++ b/gmyth/src/gmyth_transcoder.c	Thu Jun 14 18:19:52 2007 +0100
     1.3 @@ -39,48 +39,48 @@
     1.4  #include "gmyth_jobqueue.h"
     1.5  #include "gmyth_transcoder.h"
     1.6  
     1.7 -static void gmyth_transcoder_class_init ( GMythTranscoderClass * klass );
     1.8 -static void gmyth_transcoder_init ( GMythTranscoder * object );
     1.9 +static void gmyth_transcoder_class_init(GMythTranscoderClass * klass);
    1.10 +static void gmyth_transcoder_init(GMythTranscoder * object);
    1.11  
    1.12 -static void gmyth_transcoder_dispose ( GObject * object );
    1.13 -static void gmyth_transcoder_finalize ( GObject * object );
    1.14 +static void gmyth_transcoder_dispose(GObject * object);
    1.15 +static void gmyth_transcoder_finalize(GObject * object);
    1.16  
    1.17 -G_DEFINE_TYPE ( GMythTranscoder, gmyth_transcoder, G_TYPE_OBJECT )
    1.18 -     static void gmyth_transcoder_class_init ( GMythTranscoderClass * klass )
    1.19 +G_DEFINE_TYPE(GMythTranscoder, gmyth_transcoder, G_TYPE_OBJECT)
    1.20 +	 static void gmyth_transcoder_class_init(GMythTranscoderClass * klass)
    1.21  {
    1.22 -    GObjectClass *gobject_class = G_OBJECT_CLASS ( klass );
    1.23 +  GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
    1.24  
    1.25 -    gobject_class->dispose = gmyth_transcoder_dispose;
    1.26 -    gobject_class->finalize = gmyth_transcoder_finalize;
    1.27 +  gobject_class->dispose = gmyth_transcoder_dispose;
    1.28 +  gobject_class->finalize = gmyth_transcoder_finalize;
    1.29  }
    1.30  
    1.31  static void
    1.32 -gmyth_transcoder_init ( GMythTranscoder * transcoder )
    1.33 +gmyth_transcoder_init(GMythTranscoder * transcoder)
    1.34  {
    1.35 -    transcoder->started = FALSE;
    1.36 +  transcoder->started = FALSE;
    1.37  }
    1.38  
    1.39  static void
    1.40 -gmyth_transcoder_dispose ( GObject * object )
    1.41 +gmyth_transcoder_dispose(GObject * object)
    1.42  {
    1.43 -    GMythTranscoder *transcoder = GMYTH_TRANSCODER ( object );
    1.44 +  GMythTranscoder *transcoder = GMYTH_TRANSCODER(object);
    1.45  
    1.46 -    g_free ( transcoder->output_filename );
    1.47 -    g_free ( transcoder->filename );
    1.48 -    g_free ( transcoder->profile );
    1.49 -    g_free ( transcoder->starttime );
    1.50 +  g_free(transcoder->output_filename);
    1.51 +  g_free(transcoder->filename);
    1.52 +  g_free(transcoder->profile);
    1.53 +  g_free(transcoder->starttime);
    1.54  
    1.55 -    if ( transcoder->backend_info )
    1.56 -        g_object_unref ( transcoder->backend_info );
    1.57 +  if (transcoder->backend_info)
    1.58 +	g_object_unref(transcoder->backend_info);
    1.59  
    1.60 -    G_OBJECT_CLASS ( gmyth_transcoder_parent_class )->dispose ( object );
    1.61 +  G_OBJECT_CLASS(gmyth_transcoder_parent_class)->dispose(object);
    1.62  }
    1.63  
    1.64  static void
    1.65 -gmyth_transcoder_finalize ( GObject * object )
    1.66 +gmyth_transcoder_finalize(GObject * object)
    1.67  {
    1.68 -    g_signal_handlers_destroy ( object );
    1.69 -    G_OBJECT_CLASS ( gmyth_transcoder_parent_class )->finalize ( object );
    1.70 +  g_signal_handlers_destroy(object);
    1.71 +  G_OBJECT_CLASS(gmyth_transcoder_parent_class)->finalize(object);
    1.72  }
    1.73  
    1.74  /**
    1.75 @@ -89,18 +89,18 @@
    1.76   * @return a new instance of GMythTranscoder.
    1.77   **/
    1.78  GMythTranscoder *
    1.79 -gmyth_transcoder_new ( GMythBackendInfo * backend_info )
    1.80 +gmyth_transcoder_new(GMythBackendInfo * backend_info)
    1.81  {
    1.82 -    GMythTranscoder *transcoder = GMYTH_TRANSCODER
    1.83 -        ( g_object_new ( GMYTH_TRANSCODER_TYPE, NULL ) );
    1.84 +  GMythTranscoder *transcoder = GMYTH_TRANSCODER
    1.85 +	(g_object_new(GMYTH_TRANSCODER_TYPE, NULL));
    1.86  
    1.87 -    if ( backend_info != NULL )
    1.88 -    {
    1.89 -        g_object_ref ( backend_info );
    1.90 -        transcoder->backend_info = backend_info;
    1.91 -    }
    1.92 +  if (backend_info != NULL)
    1.93 +	{
    1.94 +	  g_object_ref(backend_info);
    1.95 +	  transcoder->backend_info = backend_info;
    1.96 +	}
    1.97  
    1.98 -    return transcoder;
    1.99 +  return transcoder;
   1.100  }
   1.101  
   1.102  /**
   1.103 @@ -112,43 +112,43 @@
   1.104   *
   1.105   **/
   1.106  static gchar *
   1.107 -gmyth_transcoder_date_change_format ( gchar * date_s, int format )
   1.108 +gmyth_transcoder_date_change_format(gchar * date_s, int format)
   1.109  {
   1.110 -    if ( date_s != NULL )
   1.111 -    {
   1.112 -        gint length = strlen ( date_s );
   1.113 +  if (date_s != NULL)
   1.114 +	{
   1.115 +	  gint length = strlen(date_s);
   1.116  
   1.117 -        //create the right date format
   1.118 -        gchar *src = ( gchar * ) g_malloc0 ( sizeof ( gchar ) * length );
   1.119 +	 //create the right date format
   1.120 +	  gchar *src = (gchar *) g_malloc0(sizeof(gchar) * length);
   1.121  
   1.122 -        strncpy ( src, date_s, length );
   1.123 +	  strncpy(src, date_s, length);
   1.124  
   1.125 -        gchar *dst;
   1.126 +	  gchar *dst;
   1.127  
   1.128 -        if ( format == DATE_FILE )
   1.129 -        {
   1.130 -            dst = ( gchar * ) g_malloc0 ( sizeof ( gchar ) * 16 );
   1.131 -            snprintf ( dst, 16, "%.4s%.2s%.2s%.2s%.2s%.2s", src, src + 5,
   1.132 -                       src + 7, src + 9, src + 11, src + 13 );
   1.133 -            dst[15] = '\0';
   1.134 -        }
   1.135 -        else if ( format == DATE_ISO )
   1.136 -        {
   1.137 -            dst = ( gchar * ) g_malloc0 ( sizeof ( gchar ) * 20 );
   1.138 -            snprintf ( dst, 20, "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", src, src + 4,
   1.139 -                       src + 6, src + 8, src + 10, src + 12 );
   1.140 -            dst[19] = '\0';
   1.141 -        }
   1.142 +	  if (format == DATE_FILE)
   1.143 +		{
   1.144 +		  dst = (gchar *) g_malloc0(sizeof(gchar) * 16);
   1.145 +		  snprintf(dst, 16, "%.4s%.2s%.2s%.2s%.2s%.2s", src, src + 5,
   1.146 +				   src + 7, src + 9, src + 11, src + 13);
   1.147 +		  dst[15] = '\0';
   1.148 +		}
   1.149 +	  else if (format == DATE_ISO)
   1.150 +		{
   1.151 +		  dst = (gchar *) g_malloc0(sizeof(gchar) * 20);
   1.152 +		  snprintf(dst, 20, "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", src, src + 4,
   1.153 +				   src + 6, src + 8, src + 10, src + 12);
   1.154 +		  dst[19] = '\0';
   1.155 +		}
   1.156  
   1.157 -        gchar *ret = g_strdup ( dst );
   1.158 +	  gchar *ret = g_strdup(dst);
   1.159  
   1.160 -        g_free ( src );
   1.161 -        g_free ( dst );
   1.162 +	  g_free(src);
   1.163 +	  g_free(dst);
   1.164  
   1.165 -        return ret;
   1.166 -    }
   1.167 -    else
   1.168 -        return NULL;
   1.169 +	  return ret;
   1.170 +	}
   1.171 +  else
   1.172 +	return NULL;
   1.173  }
   1.174  
   1.175  /**
   1.176 @@ -160,11 +160,11 @@
   1.177   *
   1.178   **/
   1.179  void
   1.180 -gmyth_transcoder_set_output ( GMythTranscoder * transcoder,
   1.181 -                              gboolean value, const gchar * outputfile )
   1.182 +gmyth_transcoder_set_output(GMythTranscoder * transcoder,
   1.183 +							gboolean value, const gchar * outputfile)
   1.184  {
   1.185 -    transcoder->output = value;
   1.186 -    transcoder->output_filename = g_strdup ( outputfile );
   1.187 +  transcoder->output = value;
   1.188 +  transcoder->output_filename = g_strdup(outputfile);
   1.189  }
   1.190  
   1.191  /**
   1.192 @@ -175,26 +175,26 @@
   1.193   *
   1.194   **/
   1.195  void
   1.196 -gmyth_transcoder_set_filename ( GMythTranscoder * transcoder,
   1.197 -                                const gchar * file )
   1.198 +gmyth_transcoder_set_filename(GMythTranscoder * transcoder,
   1.199 +							  const gchar * file)
   1.200  {
   1.201 -    // fixme: if this method is called twice, memory will not be dealocated
   1.202 -    // one transcoder can be used only for one file request?
   1.203 -    if ( file != NULL )
   1.204 -    {
   1.205 -        gchar **splited = g_strsplit ( file, "_", 2 );
   1.206 + // fixme: if this method is called twice, memory will not be dealocated
   1.207 + // one transcoder can be used only for one file request?
   1.208 +  if (file != NULL)
   1.209 +	{
   1.210 +	  gchar **splited = g_strsplit(file, "_", 2);
   1.211  
   1.212 -        // Get chanid
   1.213 -        sscanf ( splited[0], "%d", &( transcoder->chanid ) );
   1.214 +	 // Get chanid
   1.215 +	  sscanf(splited[0], "%d", &(transcoder->chanid));
   1.216  
   1.217 -        // Get starttime
   1.218 -        gchar **date = g_strsplit ( splited[1], ".", 2 );
   1.219 +	 // Get starttime
   1.220 +	  gchar **date = g_strsplit(splited[1], ".", 2);
   1.221  
   1.222 -        transcoder->starttime =
   1.223 -            gmyth_transcoder_date_change_format ( date[0], DATE_ISO );
   1.224 +	  transcoder->starttime =
   1.225 +		gmyth_transcoder_date_change_format(date[0], DATE_ISO);
   1.226  
   1.227 -        transcoder->filename = g_strdup ( file );
   1.228 -    }
   1.229 +	  transcoder->filename = g_strdup(file);
   1.230 +	}
   1.231  }
   1.232  
   1.233  
   1.234 @@ -208,74 +208,74 @@
   1.235   *
   1.236   **/
   1.237  gint
   1.238 -gmyth_transcoder_set_profile ( GMythTranscoder * trans, const gchar * value )
   1.239 +gmyth_transcoder_set_profile(GMythTranscoder * trans, const gchar * value)
   1.240  {
   1.241 -    g_return_val_if_fail ( value != NULL, -1 );
   1.242 +  g_return_val_if_fail(value != NULL, -1);
   1.243  
   1.244 -    trans->profile = g_strndup ( value, strlen ( value ) );
   1.245 +  trans->profile = g_strndup(value, strlen(value));
   1.246  
   1.247 -    return 0;
   1.248 +  return 0;
   1.249  }
   1.250  
   1.251  gboolean
   1.252 -gmyth_transcoder_start ( GMythTranscoder * trans )
   1.253 +gmyth_transcoder_start(GMythTranscoder * trans)
   1.254  {
   1.255 -    g_return_val_if_fail ( trans != NULL, FALSE );
   1.256 -    g_return_val_if_fail ( trans->backend_info != NULL, FALSE );
   1.257 -    g_return_val_if_fail ( trans->filename != NULL, FALSE );
   1.258 +  g_return_val_if_fail(trans != NULL, FALSE);
   1.259 +  g_return_val_if_fail(trans->backend_info != NULL, FALSE);
   1.260 +  g_return_val_if_fail(trans->filename != NULL, FALSE);
   1.261  
   1.262 -    if ( trans->started == FALSE )
   1.263 -    {                           // not started yet
   1.264 -        if ( !gmyth_util_file_exists ( trans->backend_info, trans->filename ) )
   1.265 -        {
   1.266 -            gmyth_debug ( "File %s does not exist", trans->filename );
   1.267 -        }
   1.268 -        trans->started = gmyth_jobqueue_add_job ( trans, "JOB_TRANSCODE" );
   1.269 -        if ( trans->started == FALSE )
   1.270 -            gmyth_debug ( "Error while starting GMythTranscoder to file: %s",
   1.271 -                          trans->output_filename );
   1.272 -    }
   1.273 -    else
   1.274 -    {
   1.275 -        gmyth_debug ( "GMythTransfer already started!" );
   1.276 -    }
   1.277 +  if (trans->started == FALSE)
   1.278 +	{							// not started yet
   1.279 +	  if (!gmyth_util_file_exists(trans->backend_info, trans->filename))
   1.280 +		{
   1.281 +		  gmyth_debug("File %s does not exist", trans->filename);
   1.282 +		}
   1.283 +	  trans->started = gmyth_jobqueue_add_job(trans, "JOB_TRANSCODE");
   1.284 +	  if (trans->started == FALSE)
   1.285 +		gmyth_debug("Error while starting GMythTranscoder to file: %s",
   1.286 +					trans->output_filename);
   1.287 +	}
   1.288 +  else
   1.289 +	{
   1.290 +	  gmyth_debug("GMythTransfer already started!");
   1.291 +	}
   1.292  
   1.293 -    return trans->started;
   1.294 +  return trans->started;
   1.295  }
   1.296  
   1.297  gboolean
   1.298 -gmyth_transcoder_pause ( GMythTranscoder * trans )
   1.299 +gmyth_transcoder_pause(GMythTranscoder * trans)
   1.300  {
   1.301 -    g_return_val_if_fail ( trans != NULL, FALSE );
   1.302 -    g_return_val_if_fail ( trans->started == TRUE, FALSE );
   1.303 +  g_return_val_if_fail(trans != NULL, FALSE);
   1.304 +  g_return_val_if_fail(trans->started == TRUE, FALSE);
   1.305  
   1.306 -    return gmyth_jobqueue_change_cmd ( trans, "PAUSE", "JOB_TRANSCODE" );
   1.307 +  return gmyth_jobqueue_change_cmd(trans, "PAUSE", "JOB_TRANSCODE");
   1.308  }
   1.309  
   1.310  gboolean
   1.311 -gmyth_transcoder_resume ( GMythTranscoder * trans )
   1.312 +gmyth_transcoder_resume(GMythTranscoder * trans)
   1.313  {
   1.314 -    g_return_val_if_fail ( trans != NULL, FALSE );
   1.315 +  g_return_val_if_fail(trans != NULL, FALSE);
   1.316  
   1.317 -    return gmyth_jobqueue_change_cmd ( trans, "RESUME", "JOB_TRANSCODE" );
   1.318 +  return gmyth_jobqueue_change_cmd(trans, "RESUME", "JOB_TRANSCODE");
   1.319  }
   1.320  
   1.321  gboolean
   1.322 -gmyth_transcoder_cancel ( GMythTranscoder * trans )
   1.323 +gmyth_transcoder_cancel(GMythTranscoder * trans)
   1.324  {
   1.325 -    g_return_val_if_fail ( trans != NULL, FALSE );
   1.326 -    g_return_val_if_fail ( trans->started == TRUE, FALSE );
   1.327 +  g_return_val_if_fail(trans != NULL, FALSE);
   1.328 +  g_return_val_if_fail(trans->started == TRUE, FALSE);
   1.329  
   1.330 -    trans->started = FALSE;
   1.331 +  trans->started = FALSE;
   1.332  
   1.333 -    return gmyth_jobqueue_change_cmd ( trans, "STOP", "JOB_TRANSCODE" );
   1.334 +  return gmyth_jobqueue_change_cmd(trans, "STOP", "JOB_TRANSCODE");
   1.335  }
   1.336  
   1.337  //fixme: implement this method
   1.338  gint
   1.339 -gmyth_transcoder_get_progress ( GMythTranscoder * trans )
   1.340 +gmyth_transcoder_get_progress(GMythTranscoder * trans)
   1.341  {
   1.342 -    static int fixme = 0;
   1.343 +  static int fixme = 0;
   1.344  
   1.345 -    return ( fixme++ ) % 101;
   1.346 +  return (fixme++) % 101;
   1.347  }