dvb: simplify ZAP file format parser

Simplify state handing, drop unneeded local vars, etc.
This commit is contained in:
Reynaldo H. Verdejo Pinochet 2015-10-08 14:46:10 -07:00
parent 1d1094b71b
commit 0ac769194f

View file

@ -54,6 +54,9 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename,
gchar **lines; gchar **lines;
gchar *line; gchar *line;
gchar **fields; gchar **fields;
int i, parsedchannels = 0;
GHashTable *res;
GError *err = NULL;
const gchar *terrestrial[] = { "inversion", "bandwidth", const gchar *terrestrial[] = { "inversion", "bandwidth",
"code-rate-hp", "code-rate-lp", "modulation", "transmission-mode", "code-rate-hp", "code-rate-lp", "modulation", "transmission-mode",
"guard", "hierarchy" "guard", "hierarchy"
@ -64,9 +67,6 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename,
const gchar *cable[] = { "inversion", "symbol-rate", "code-rate-hp", const gchar *cable[] = { "inversion", "symbol-rate", "code-rate-hp",
"modulation" "modulation"
}; };
int i, parsedchannels = 0;
GHashTable *res;
GError *err = NULL;
GST_INFO_OBJECT (dvbbasebin, "parsing '%s'", filename); GST_INFO_OBJECT (dvbbasebin, "parsing '%s'", filename);
@ -79,18 +79,37 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename,
i = 0; i = 0;
line = lines[0]; line = lines[0];
while (line != NULL) { while (line != NULL) {
if (line[0] != '#') { GHashTable *params;
int numfields; int j, numfields;
gboolean parsed = FALSE;
GHashTable *params = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
fields = g_strsplit (line, ":", 0); if (line[0] == '#')
numfields = g_strv_length (fields); goto next_line;
if (numfields == 8) {
/* satellite */
int j;
params = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
fields = g_strsplit (line, ":", 0);
numfields = g_strv_length (fields);
switch (numfields) {
case 13: /* terrestrial */
g_hash_table_insert (params, g_strdup ("type"),
g_strdup ("terrestrial"));
for (j = 2; j <= 9; j++) {
g_hash_table_insert (params, g_strdup (terrestrial[j - 2]),
g_strdup (fields[j]));
}
g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup (fields[1]));
break;
case 9: /* cable */
g_hash_table_insert (params, g_strdup ("type"), g_strdup ("cable"));
for (j = 2; j <= 5; j++) {
g_hash_table_insert (params, g_strdup (cable[j - 2]),
g_strdup (fields[j]));
}
g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup (fields[1]));
break;
case 8: /* satellite */
g_hash_table_insert (params, g_strdup ("type"), g_strdup ("satellite")); g_hash_table_insert (params, g_strdup ("type"), g_strdup ("satellite"));
for (j = 2; j <= 4; j++) { for (j = 2; j <= 4; j++) {
g_hash_table_insert (params, g_strdup (satellite[j - 2]), g_hash_table_insert (params, g_strdup (satellite[j - 2]),
@ -107,52 +126,31 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename,
g_hash_table_insert (params, g_strdup ("frequency"), g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup_printf ("%d", atoi (fields[1]))); g_strdup_printf ("%d", atoi (fields[1])));
} }
parsed = TRUE; break;
} else if (numfields == 13) { case 6: /* atsc (vsb/qam) */
/* terrestrial */
int j;
g_hash_table_insert (params, g_strdup ("type"),
g_strdup ("terrestrial"));
for (j = 2; j <= 9; j++) {
g_hash_table_insert (params, g_strdup (terrestrial[j - 2]),
g_strdup (fields[j]));
}
g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup (fields[1]));
parsed = TRUE;
} else if (numfields == 9) {
/* cable */
int j;
g_hash_table_insert (params, g_strdup ("type"), g_strdup ("cable"));
for (j = 2; j <= 5; j++) {
g_hash_table_insert (params, g_strdup (cable[j - 2]),
g_strdup (fields[j]));
}
g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup (fields[1]));
parsed = TRUE;
} else if (numfields == 6) {
/* atsc (vsb/qam) */
g_hash_table_insert (params, g_strdup ("type"), g_strdup ("atsc")); g_hash_table_insert (params, g_strdup ("type"), g_strdup ("atsc"));
g_hash_table_insert (params, g_strdup ("modulation"), g_hash_table_insert (params, g_strdup ("modulation"),
g_strdup (fields[2])); g_strdup (fields[2]));
g_hash_table_insert (params, g_strdup ("frequency"), g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup (fields[1])); g_strdup (fields[1]));
parsed = TRUE; break;
} default:
if (parsed) { goto not_parsed;
g_hash_table_insert (params, g_strdup ("sid"),
g_strdup (fields[numfields - 1]));
g_hash_table_insert (res, g_strdup (fields[0]), params);
parsedchannels++;
}
g_strfreev (fields);
} }
/* parsed */
g_hash_table_insert (params, g_strdup ("sid"),
g_strdup (fields[numfields - 1]));
g_hash_table_insert (res, g_strdup (fields[0]), params);
parsedchannels++;
not_parsed:
g_strfreev (fields);
next_line:
line = lines[++i]; line = lines[++i];
} }
g_strfreev (lines); g_strfreev (lines);
g_free (contents); g_free (contents);
@ -162,25 +160,21 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename,
return res; return res;
open_fail: open_fail:
{ if (err->code == G_FILE_ERROR_NOENT) {
if (err->code == G_FILE_ERROR_NOENT) { g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_NOT_FOUND,
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_NOT_FOUND, _("Couldn't find DVB channel configuration file"));
_("Couldn't find DVB channel configuration file")); } else {
} else { g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_READ,
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_READ, _("Couldn't load DVB channel configuration file: %s"), err->message);
_("Couldn't load DVB channel configuration file: %s"), err->message);
}
g_clear_error (&err);
return NULL;
} }
g_clear_error (&err);
return NULL;
no_channels: no_channels:
{ g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED,
g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, _("DVB channel configuration file doesn't contain any channels"));
_("DVB channel configuration file doesn't contain any channels")); g_hash_table_unref (res);
g_hash_table_unref (res); return NULL;
return NULL;
}
} }
static gboolean static gboolean