dvbbasebin: Emit an error when we fail reading the channels file

Conflicts:

	sys/dvb/dvbbasebin.c
This commit is contained in:
Edward Hervey 2012-06-19 10:22:50 +02:00 committed by Sebastian Dröge
parent 1ee6a35949
commit 068598e237
3 changed files with 85 additions and 76 deletions

View File

@ -987,7 +987,7 @@ dvb_base_bin_uri_set_uri (GstURIHandler * handler, const gchar * uri,
if (location == NULL) if (location == NULL)
goto no_location; goto no_location;
if (!set_properties_for_channel (G_OBJECT (dvbbasebin), location)) if (!set_properties_for_channel (GST_ELEMENT (dvbbasebin), location))
goto set_properties_failed; goto set_properties_failed;
/* FIXME: here is where we parse channels.conf */ /* FIXME: here is where we parse channels.conf */

View File

@ -30,8 +30,8 @@
#include "parsechannels.h" #include "parsechannels.h"
/* this will do zap style channels.conf only for the moment*/ /* this will do zap style channels.conf only for the moment*/
GHashTable * static GHashTable *
parse_channels_conf_from_file (const gchar * filename) parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
{ {
gchar *contents; gchar *contents;
gchar **lines; gchar **lines;
@ -48,85 +48,95 @@ parse_channels_conf_from_file (const gchar * filename)
"modulation" "modulation"
}; };
int i; int i;
GHashTable *res = NULL; GHashTable *res;
GError *err = NULL;
if (g_file_get_contents (filename, &contents, NULL, NULL)) { if (!g_file_get_contents (filename, &contents, NULL, &err))
lines = g_strsplit (contents, "\n", 0); goto open_fail;
res = g_hash_table_new (g_str_hash, g_str_equal);
i = 0; lines = g_strsplit (contents, "\n", 0);
line = lines[0]; res = g_hash_table_new (g_str_hash, g_str_equal);
while (line != NULL) {
if (line[0] != '#') {
int 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); i = 0;
numfields = g_strv_length (fields); line = lines[0];
if (numfields == 8) { while (line != NULL) {
/* satellite */ if (line[0] != '#') {
int j; int numfields;
gboolean parsed = FALSE;
GHashTable *params = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
g_hash_table_insert (params, g_strdup ("type"), fields = g_strsplit (line, ":", 0);
g_strdup ("satellite")); numfields = g_strv_length (fields);
for (j = 2; j <= 4; j++) { if (numfields == 8) {
g_hash_table_insert (params, g_strdup (satellite[j - 2]), /* satellite */
g_strdup (fields[j])); int j;
}
g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup_printf ("%d", atoi (fields[1]) * 1000));
parsed = TRUE;
} else if (numfields == 13) {
/* terrestrial */
int j;
g_hash_table_insert (params, g_strdup ("type"), g_hash_table_insert (params, g_strdup ("type"), g_strdup ("satellite"));
g_strdup ("terrestrial")); for (j = 2; j <= 4; j++) {
for (j = 2; j <= 9; j++) { g_hash_table_insert (params, g_strdup (satellite[j - 2]),
g_hash_table_insert (params, g_strdup (terrestrial[j - 2]), g_strdup (fields[j]));
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 ("modulation"),
g_strdup (fields[2]));
g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup (fields[1]));
parsed = TRUE;
} }
if (parsed) { g_hash_table_insert (params, g_strdup ("frequency"),
g_hash_table_insert (params, g_strdup ("sid"), g_strdup_printf ("%d", atoi (fields[1]) * 1000));
g_strdup (fields[numfields - 1])); parsed = TRUE;
g_hash_table_insert (res, g_strdup (fields[0]), params); } else if (numfields == 13) {
/* 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_strfreev (fields); 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 ("modulation"),
g_strdup (fields[2]));
g_hash_table_insert (params, g_strdup ("frequency"),
g_strdup (fields[1]));
parsed = TRUE;
} }
line = lines[++i]; if (parsed) {
g_hash_table_insert (params, g_strdup ("sid"),
g_strdup (fields[numfields - 1]));
g_hash_table_insert (res, g_strdup (fields[0]), params);
}
g_strfreev (fields);
} }
g_strfreev (lines); line = lines[++i];
g_free (contents); }
} else g_strfreev (lines);
GST_WARNING ("Couldn't open file"); g_free (contents);
return res; return res;
open_fail:
{
GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
("Opening channels configuration file failed : %s", filename,
err->message));
g_clear_error (&err);
return NULL;
}
} }
static gboolean static gboolean
@ -146,7 +156,7 @@ destroy_channels_hash (GHashTable * channels)
} }
gboolean gboolean
set_properties_for_channel (GObject * dvbbasebin, const gchar * channel_name) set_properties_for_channel (GstElement * dvbbasebin, const gchar * channel_name)
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
GHashTable *channels; GHashTable *channels;
@ -160,7 +170,7 @@ set_properties_for_channel (GObject * dvbbasebin, const gchar * channel_name)
filename = g_strdup_printf ("%s/gstreamer-%d.%d/dvb-channels.conf", filename = g_strdup_printf ("%s/gstreamer-%d.%d/dvb-channels.conf",
g_get_user_config_dir (), major, minor); g_get_user_config_dir (), major, minor);
} }
channels = parse_channels_conf_from_file (filename); channels = parse_channels_conf_from_file (dvbbasebin, filename);
g_free (filename); g_free (filename);
if (channels) { if (channels) {

View File

@ -24,8 +24,7 @@
#ifndef PARSE_CHANNELS_H #ifndef PARSE_CHANNELS_H
#define PARSE_CHANNELS_H #define PARSE_CHANNELS_H
GHashTable* parse_channels_conf_from_file(const gchar* filename); gboolean set_properties_for_channel(GstElement *dvbbasebin,
gboolean set_properties_for_channel(GObject *dvbbasebin,
const gchar* channel_name); const gchar* channel_name);
#endif #endif