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"
|
#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 */
|
/* this will do zap style channels.conf only for the moment */
|
||||||
static GHashTable *
|
static GHashTable *
|
||||||
parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
|
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",
|
const gchar *cable[] = { "inversion", "symbol-rate", "code-rate-hp",
|
||||||
"modulation"
|
"modulation"
|
||||||
};
|
};
|
||||||
int i;
|
int i, parsedchannels = 0;
|
||||||
GHashTable *res;
|
GHashTable *res;
|
||||||
GError *err = NULL;
|
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_hash_table_insert (params, g_strdup ("sid"),
|
||||||
g_strdup (fields[numfields - 1]));
|
g_strdup (fields[numfields - 1]));
|
||||||
g_hash_table_insert (res, g_strdup (fields[0]), params);
|
g_hash_table_insert (res, g_strdup (fields[0]), params);
|
||||||
|
parsedchannels++;
|
||||||
}
|
}
|
||||||
g_strfreev (fields);
|
g_strfreev (fields);
|
||||||
}
|
}
|
||||||
@ -127,6 +133,9 @@ parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
|
|||||||
g_strfreev (lines);
|
g_strfreev (lines);
|
||||||
g_free (contents);
|
g_free (contents);
|
||||||
|
|
||||||
|
if (parsedchannels == 0)
|
||||||
|
goto no_channels;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
open_fail:
|
open_fail:
|
||||||
@ -137,6 +146,14 @@ open_fail:
|
|||||||
g_clear_error (&err);
|
g_clear_error (&err);
|
||||||
return NULL;
|
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
|
static gboolean
|
||||||
@ -159,8 +176,10 @@ gboolean
|
|||||||
set_properties_for_channel (GstElement * 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, *params;
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
|
gchar *type;
|
||||||
|
const gchar *adapter;
|
||||||
|
|
||||||
filename = g_strdup (g_getenv ("GST_DVB_CHANNELS_CONF"));
|
filename = g_strdup (g_getenv ("GST_DVB_CHANNELS_CONF"));
|
||||||
if (filename == NULL) {
|
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);
|
channels = parse_channels_conf_from_file (dvbbasebin, filename);
|
||||||
g_free (filename);
|
g_free (filename);
|
||||||
|
|
||||||
if (channels) {
|
if (!channels)
|
||||||
GHashTable *params = g_hash_table_lookup (channels,
|
goto beach;
|
||||||
channel_name);
|
|
||||||
|
|
||||||
if (params) {
|
params = g_hash_table_lookup (channels, channel_name);
|
||||||
gchar *type;
|
|
||||||
const gchar *adapter;
|
if (!params)
|
||||||
|
goto unknown_channel;
|
||||||
|
|
||||||
g_object_set (dvbbasebin, "program-numbers",
|
g_object_set (dvbbasebin, "program-numbers",
|
||||||
g_hash_table_lookup (params, "sid"), NULL);
|
g_hash_table_lookup (params, "sid"), NULL);
|
||||||
@ -391,9 +410,18 @@ set_properties_for_channel (GstElement * dvbbasebin, const gchar * channel_name)
|
|||||||
else
|
else
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
destroy_channels_hash (channels);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
destroy_channels_hash (channels);
|
||||||
|
|
||||||
|
beach:
|
||||||
return ret;
|
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