morphbr@379
|
1 |
/**
|
morphbr@379
|
2 |
* GMyth Library
|
morphbr@379
|
3 |
*
|
morphbr@379
|
4 |
* @file gmyth/gmyth_transcode.c
|
morphbr@379
|
5 |
*
|
morphbr@379
|
6 |
* @brief <p> This file contains the transcode class.
|
morphbr@379
|
7 |
*
|
morphbr@379
|
8 |
* Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
|
morphbr@379
|
9 |
* @author Artur Duque de Souza <artur.souza@indt.org.br>
|
morphbr@379
|
10 |
*
|
morphbr@379
|
11 |
*/
|
morphbr@379
|
12 |
/*
|
morphbr@379
|
13 |
*
|
morphbr@379
|
14 |
* This program is free software; you can redistribute it and/or modify
|
morphbr@379
|
15 |
* it under the terms of the GNU Lesser General Public License as published by
|
morphbr@379
|
16 |
* the Free Software Foundation; either version 2 of the License, or
|
morphbr@379
|
17 |
* (at your option) any later version.
|
morphbr@379
|
18 |
*
|
morphbr@379
|
19 |
* This program is distributed in the hope that it will be useful,
|
morphbr@379
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
morphbr@379
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
morphbr@379
|
22 |
* GNU General Public License for more details.
|
morphbr@379
|
23 |
*
|
morphbr@379
|
24 |
* You should have received a copy of the GNU Lesser General Public License
|
morphbr@379
|
25 |
* along with this program; if not, write to the Free Software
|
morphbr@379
|
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
morphbr@379
|
27 |
*/
|
morphbr@379
|
28 |
|
morphbr@379
|
29 |
|
morphbr@379
|
30 |
#ifdef HAVE_CONFIG_H
|
morphbr@379
|
31 |
#include "config.h"
|
morphbr@379
|
32 |
#endif
|
morphbr@379
|
33 |
|
morphbr@379
|
34 |
#include <stdlib.h>
|
morphbr@379
|
35 |
#include <string.h>
|
morphbr@379
|
36 |
#include <assert.h>
|
morphbr@379
|
37 |
|
morphbr@379
|
38 |
#include "gmyth_transcode.h"
|
morphbr@379
|
39 |
#include "gmyth_util.h"
|
morphbr@379
|
40 |
#include "gmyth_debug.h"
|
morphbr@379
|
41 |
|
morphbr@379
|
42 |
static void gmyth_transcode_class_init (GMythTranscodeClass *klass);
|
morphbr@379
|
43 |
static void gmyth_transcode_init (GMythTranscode *object);
|
morphbr@379
|
44 |
|
morphbr@379
|
45 |
static void gmyth_transcode_dispose (GObject *object);
|
morphbr@379
|
46 |
static void gmyth_transcode_finalize (GObject *object);
|
morphbr@379
|
47 |
|
morphbr@379
|
48 |
G_DEFINE_TYPE(GMythTranscode, gmyth_transcode, G_TYPE_OBJECT)
|
morphbr@379
|
49 |
|
morphbr@379
|
50 |
static void
|
morphbr@379
|
51 |
gmyth_transcode_class_init (GMythTranscodeClass *klass)
|
morphbr@379
|
52 |
{
|
morphbr@379
|
53 |
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
morphbr@379
|
54 |
gobject_class->dispose = gmyth_transcode_dispose;
|
morphbr@380
|
55 |
gobject_class->finalize = gmyth_transcode_finalize;
|
morphbr@379
|
56 |
}
|
morphbr@379
|
57 |
|
morphbr@379
|
58 |
static void
|
morphbr@380
|
59 |
gmyth_transcode_init (GMythTranscode *transcode)
|
morphbr@379
|
60 |
{
|
morphbr@379
|
61 |
}
|
morphbr@379
|
62 |
|
morphbr@379
|
63 |
static void
|
morphbr@379
|
64 |
gmyth_transcode_dispose (GObject *object)
|
morphbr@379
|
65 |
{
|
morphbr@379
|
66 |
GMythTranscode *transcode = GMYTH_TRANSCODE(object);
|
morphbr@379
|
67 |
|
morphbr@379
|
68 |
if (transcode->output_filename)
|
morphbr@379
|
69 |
g_free(transcode->output_filename);
|
morphbr@379
|
70 |
|
morphbr@379
|
71 |
if (transcode->filename)
|
morphbr@379
|
72 |
g_free(transcode->filename);
|
morphbr@379
|
73 |
|
morphbr@379
|
74 |
if (transcode->profile)
|
morphbr@379
|
75 |
g_free(transcode->profile);
|
morphbr@379
|
76 |
|
morphbr@379
|
77 |
if (transcode->starttime)
|
morphbr@379
|
78 |
g_free(transcode->starttime);
|
morphbr@379
|
79 |
|
morphbr@379
|
80 |
G_OBJECT_CLASS (gmyth_transcode_parent_class)->dispose (object);
|
morphbr@379
|
81 |
}
|
morphbr@379
|
82 |
|
morphbr@379
|
83 |
static void
|
morphbr@379
|
84 |
gmyth_transcode_finalize (GObject *object)
|
morphbr@379
|
85 |
{
|
morphbr@379
|
86 |
g_signal_handlers_destroy (object);
|
morphbr@379
|
87 |
G_OBJECT_CLASS (gmyth_transcode_parent_class)->finalize (object);
|
morphbr@379
|
88 |
}
|
morphbr@379
|
89 |
|
morphbr@379
|
90 |
/**
|
morphbr@379
|
91 |
* Creates a new instance of GMythTranscode.
|
morphbr@379
|
92 |
*
|
morphbr@379
|
93 |
* @return a new instance of GMythTranscode.
|
morphbr@379
|
94 |
**/
|
morphbr@379
|
95 |
GMythTranscode*
|
morphbr@379
|
96 |
gmyth_transcode_new (void)
|
morphbr@379
|
97 |
{
|
morphbr@379
|
98 |
GMythTranscode *transcode = GMYTH_TRANSCODE\
|
morphbr@379
|
99 |
(g_object_new(GMYTH_TRANSCODE_TYPE, NULL));
|
morphbr@383
|
100 |
|
morphbr@379
|
101 |
return transcode;
|
morphbr@379
|
102 |
}
|
morphbr@379
|
103 |
|
morphbr@379
|
104 |
/**
|
morphbr@379
|
105 |
*
|
morphbr@379
|
106 |
* gmyth_transcode_date_change_format
|
morphbr@379
|
107 |
* @brief converts a string like YYYY-MM-DDTHH:MM:SS into YYYYMMDDHHMMSS (vice versa)
|
morphbr@379
|
108 |
* @param date_s gchar*
|
morphbr@379
|
109 |
* @return gchar* with file or iso format
|
morphbr@379
|
110 |
*
|
morphbr@379
|
111 |
**/
|
morphbr@380
|
112 |
GString* gmyth_transcode_date_change_format (gchar* date_s, int format)
|
morphbr@379
|
113 |
{
|
morphbr@380
|
114 |
if (date_s != NULL)
|
morphbr@379
|
115 |
{
|
morphbr@380
|
116 |
gint length = strlen(date_s);
|
morphbr@379
|
117 |
|
morphbr@379
|
118 |
//create the right date format
|
morphbr@379
|
119 |
gchar* src = (gchar*)g_malloc0(sizeof(gchar) * length);
|
morphbr@380
|
120 |
strncpy(src, date_s, length);
|
morphbr@379
|
121 |
|
morphbr@379
|
122 |
gchar* dst;
|
morphbr@379
|
123 |
|
morphbr@379
|
124 |
if (format == DATE_FILE)
|
morphbr@379
|
125 |
{
|
morphbr@379
|
126 |
dst = (gchar*)g_malloc0(sizeof(gchar) * 16);
|
morphbr@380
|
127 |
snprintf(dst, 16, "%.4s%.2s%.2s%.2s%.2s%.2s", src, src+5,\
|
morphbr@379
|
128 |
src+7, src+9, src+11, src+13);
|
morphbr@380
|
129 |
dst[15] = '\0';
|
morphbr@379
|
130 |
}
|
morphbr@379
|
131 |
else
|
morphbr@379
|
132 |
if (format == DATE_ISO)
|
morphbr@379
|
133 |
{
|
morphbr@380
|
134 |
dst = (gchar*)g_malloc0(sizeof(gchar) * 20);
|
morphbr@380
|
135 |
snprintf(dst, 20, "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", src, src+4,\
|
morphbr@379
|
136 |
src+6, src+8, src+10, src+12);
|
morphbr@379
|
137 |
dst[19] = '\0';
|
morphbr@379
|
138 |
}
|
morphbr@379
|
139 |
|
morphbr@379
|
140 |
GString* ret = g_string_new(dst);
|
morphbr@379
|
141 |
|
morphbr@379
|
142 |
g_free(src);
|
morphbr@379
|
143 |
g_free(dst);
|
morphbr@379
|
144 |
|
morphbr@379
|
145 |
return ret;
|
morphbr@379
|
146 |
}
|
morphbr@379
|
147 |
else return NULL;
|
morphbr@379
|
148 |
}
|
morphbr@379
|
149 |
|
morphbr@379
|
150 |
/**
|
morphbr@379
|
151 |
*
|
morphbr@379
|
152 |
* gmyth_transcode_set_output
|
morphbr@379
|
153 |
* @brief set transcode to use output
|
morphbr@379
|
154 |
* @param value gboolean
|
morphbr@379
|
155 |
* @param outfile filename of output
|
morphbr@379
|
156 |
* @return void set's up the var to value
|
morphbr@379
|
157 |
*
|
morphbr@379
|
158 |
**/
|
morphbr@379
|
159 |
void gmyth_transcode_set_output (GMythTranscode* transcode,
|
morphbr@380
|
160 |
gboolean value, gchar* outputfile)
|
morphbr@379
|
161 |
{
|
morphbr@379
|
162 |
transcode->output = value;
|
morphbr@380
|
163 |
transcode->output_filename = g_string_new(outputfile);
|
morphbr@379
|
164 |
}
|
morphbr@379
|
165 |
|
morphbr@379
|
166 |
/**
|
morphbr@379
|
167 |
*
|
morphbr@379
|
168 |
* gmyth_transcode_set_file
|
morphbr@379
|
169 |
* @brief set the file to transcode
|
morphbr@379
|
170 |
* @param file filename
|
morphbr@379
|
171 |
* @return void set's up the var to value
|
morphbr@379
|
172 |
*
|
morphbr@379
|
173 |
**/
|
morphbr@380
|
174 |
void gmyth_transcode_set_filename (GMythTranscode* transcode, gchar* file)
|
morphbr@379
|
175 |
{
|
morphbr@380
|
176 |
if (file != NULL)
|
morphbr@380
|
177 |
{
|
morphbr@380
|
178 |
gchar** splited = g_strsplit(file, "_", 2);
|
morphbr@380
|
179 |
|
morphbr@380
|
180 |
// Get chanid
|
morphbr@380
|
181 |
sscanf (splited[0],"%d", &(transcode->chanid));
|
morphbr@380
|
182 |
|
morphbr@380
|
183 |
// Get starttime
|
morphbr@380
|
184 |
gchar** date = g_strsplit(splited[1], ".", 2);
|
morphbr@380
|
185 |
transcode->starttime = gmyth_transcode_date_change_format(date[0], DATE_ISO);
|
morphbr@380
|
186 |
|
morphbr@380
|
187 |
transcode->filename = g_string_new(file);
|
morphbr@380
|
188 |
}
|
morphbr@379
|
189 |
}
|