dvb: Detect more issues with configuration file
Report useful errors when: * file is present but empty * requested channel is not present
This commit is contained in:
parent
068598e237
commit
d7ad4ce890
@ -29,6 +29,11 @@
|
||||
|
||||
#include "parsechannels.h"
|
||||
|
||||
/* TODO:
|
||||
* Store the channels hash table around instead of constantly parsing it
|
||||
* Detect when the file changed on disk
|
||||
*/
|
||||
|
||||
/* this will do zap style channels.conf only for the moment */
|
||||
static GHashTable *
|
||||
parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
|
||||
@ -47,7 +52,7 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
|
||||
const gchar *cable[] = { "inversion", "symbol-rate", "code-rate-hp",
|
||||
"modulation"
|
||||
};
|
||||
int i;
|
||||
int i, parsedchannels = 0;
|
||||
GHashTable *res;
|
||||
GError *err = NULL;
|
||||
|
||||
@ -119,6 +124,7 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
|
||||
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);
|
||||
}
|
||||
@ -127,6 +133,9 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
|
||||
g_strfreev (lines);
|
||||
g_free (contents);
|
||||
|
||||
if (parsedchannels == 0)
|
||||
goto no_channels;
|
||||
|
||||
return res;
|
||||
|
||||
open_fail:
|
||||
@ -137,6 +146,14 @@ open_fail:
|
||||
g_clear_error (&err);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
no_channels:
|
||||
{
|
||||
GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
|
||||
("Channels configuration file doesn't contain any channels"));
|
||||
g_hash_table_unref (res);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -159,8 +176,10 @@ gboolean
|
||||
set_properties_for_channel (GstElement * dvbbasebin, const gchar * channel_name)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GHashTable *channels;
|
||||
GHashTable *channels, *params;
|
||||
gchar *filename;
|
||||
gchar *type;
|
||||
const gchar *adapter;
|
||||
|
||||
filename = g_strdup (g_getenv ("GST_DVB_CHANNELS_CONF"));
|
||||
if (filename == NULL) {
|
||||
@ -173,13 +192,13 @@ set_properties_for_channel (GstElement * dvbbasebin, const gchar * channel_name)
|
||||
channels = parse_channels_conf_from_file (dvbbasebin, filename);
|
||||
g_free (filename);
|
||||
|
||||
if (channels) {
|
||||
GHashTable *params = g_hash_table_lookup (channels,
|
||||
channel_name);
|
||||
if (!channels)
|
||||
goto beach;
|
||||
|
||||
if (params) {
|
||||
gchar *type;
|
||||
const gchar *adapter;
|
||||
params = g_hash_table_lookup (channels, channel_name);
|
||||
|
||||
if (!params)
|
||||
goto unknown_channel;
|
||||
|
||||
g_object_set (dvbbasebin, "program-numbers",
|
||||
g_hash_table_lookup (params, "sid"), NULL);
|
||||
@ -391,9 +410,18 @@ set_properties_for_channel (GstElement * dvbbasebin, const gchar * channel_name)
|
||||
else
|
||||
ret = FALSE;
|
||||
}
|
||||
}
|
||||
destroy_channels_hash (channels);
|
||||
}
|
||||
|
||||
destroy_channels_hash (channels);
|
||||
|
||||
beach:
|
||||
return ret;
|
||||
|
||||
unknown_channel:
|
||||
{
|
||||
GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
|
||||
("Couldn't find configuration properties for channel \"%s\"",
|
||||
channel_name));
|
||||
destroy_channels_hash (channels);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user