summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorReynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>2016-06-22 16:14:33 -0700
committerReynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>2016-06-24 18:23:17 -0700
commit219d4c132c54d60949969ddfb0830853569faf8d (patch)
tree02ed862d3dc58ffbd7196d2d3c33d5b2c52ac1ce /sys
parentd9e0e43ca722276db79a8a232e1465a87d2b2824 (diff)
downloadgstreamer-plugins-bad-219d4c132c54d60949969ddfb0830853569faf8d.tar.gz
dvb/parsechannels: implement channels.conf format autodetection
Simple autodetection avoids having to call the parsers one after the other.
Diffstat (limited to 'sys')
-rw-r--r--sys/dvb/parsechannels.c76
1 files changed, 64 insertions, 12 deletions
diff --git a/sys/dvb/parsechannels.c b/sys/dvb/parsechannels.c
index 0cb8ad9bf..11de6ed19 100644
--- a/sys/dvb/parsechannels.c
+++ b/sys/dvb/parsechannels.c
@@ -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;
}