mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 19:20:35 +00:00
dvb/parsechannels: implement channels.conf format autodetection
Simple autodetection avoids having to call the parsers one after the other.
This commit is contained in:
parent
d9e0e43ca7
commit
219d4c132c
1 changed files with 64 additions and 12 deletions
|
@ -37,10 +37,18 @@
|
|||
|
||||
#include <linux/dvb/frontend.h>
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CHANNEL_CONF_FORMAT_NONE,
|
||||
CHANNEL_CONF_FORMAT_DVBV5,
|
||||
CHANNEL_CONF_FORMAT_ZAP
|
||||
} GstDvbChannelConfFormat;
|
||||
|
||||
static gboolean parse_and_configure_from_v5_conf_file (GstElement * dvbbasebin,
|
||||
const gchar * filename, const gchar * channel_name, GError ** error);
|
||||
static gboolean parse_and_configure_from_zap_conf_file (GstElement * dvbbasebin,
|
||||
const gchar * filename, const gchar * channel_name, GError ** error);
|
||||
static GstDvbChannelConfFormat detect_file_format (const gchar * filename);
|
||||
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (dvb_base_bin_debug);
|
||||
|
@ -776,6 +784,36 @@ unknown_channel:
|
|||
}
|
||||
}
|
||||
|
||||
static GstDvbChannelConfFormat
|
||||
detect_file_format (const gchar * filename)
|
||||
{
|
||||
gchar *contents;
|
||||
gchar **lines;
|
||||
gchar **line;
|
||||
GstDvbChannelConfFormat ret = CHANNEL_CONF_FORMAT_NONE;
|
||||
|
||||
if (!g_file_get_contents (filename, &contents, NULL, NULL))
|
||||
return ret;
|
||||
|
||||
lines = g_strsplit (contents, "\n", 0);
|
||||
line = lines;
|
||||
|
||||
while (*line) {
|
||||
if (g_str_has_prefix (*line, "[") && g_str_has_suffix (*line, "]")) {
|
||||
ret = CHANNEL_CONF_FORMAT_DVBV5;
|
||||
break;
|
||||
} else if (g_strrstr (*line, ":")) {
|
||||
ret = CHANNEL_CONF_FORMAT_ZAP;
|
||||
break;
|
||||
}
|
||||
line++;
|
||||
}
|
||||
|
||||
g_strfreev (lines);
|
||||
g_free (contents);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
set_properties_for_channel (GstElement * dvbbasebin,
|
||||
const gchar * channel_name, GError ** error)
|
||||
|
@ -790,23 +828,37 @@ set_properties_for_channel (GstElement * dvbbasebin,
|
|||
"gstreamer-" GST_API_VERSION, "dvb-channels.conf", NULL);
|
||||
}
|
||||
|
||||
/* TODO detect channels.conf file format */
|
||||
|
||||
adapter = g_getenv ("GST_DVB_ADAPTER");
|
||||
if (adapter)
|
||||
g_object_set (dvbbasebin, "adapter", atoi (adapter), NULL);
|
||||
|
||||
if (!(ret = parse_and_configure_from_v5_conf_file (dvbbasebin, filename,
|
||||
channel_name, error))) {
|
||||
/* TODO only fallback if it was a parsing error */
|
||||
|
||||
g_clear_error (error);
|
||||
GST_DEBUG_OBJECT (dvbbasebin, "Resorting to old ZAP format file parsing");
|
||||
|
||||
/* fallback to old format */
|
||||
ret = parse_and_configure_from_zap_conf_file (dvbbasebin, filename,
|
||||
channel_name, error);
|
||||
switch (detect_file_format (filename)) {
|
||||
case CHANNEL_CONF_FORMAT_DVBV5:
|
||||
if (!parse_and_configure_from_v5_conf_file (dvbbasebin, filename,
|
||||
channel_name, error)) {
|
||||
GST_WARNING_OBJECT (dvbbasebin, "Could not parse libdvbv5 channel "
|
||||
"configuration file '%s'", filename);
|
||||
} else {
|
||||
GST_INFO_OBJECT (dvbbasebin, "Parsed libdvbv5 channel configuration "
|
||||
"file");
|
||||
ret = TRUE;
|
||||
}
|
||||
break;
|
||||
case CHANNEL_CONF_FORMAT_ZAP:
|
||||
if (!parse_and_configure_from_zap_conf_file (dvbbasebin, filename,
|
||||
channel_name, error)) {
|
||||
GST_WARNING_OBJECT (dvbbasebin, "Could not parse ZAP channel "
|
||||
"configuration file '%s'", filename);
|
||||
} else {
|
||||
GST_INFO_OBJECT (dvbbasebin, "Parsed ZAP channel configuration file");
|
||||
ret = TRUE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
GST_WARNING_OBJECT (dvbbasebin, "Unknown configuration file format. "
|
||||
"Can not get parameters for channel");
|
||||
}
|
||||
|
||||
g_free (filename);
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue