Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 1 | /* |
| 2 | * parsechannels.c - |
| 3 | * Copyright (C) 2008 Zaheer Abbas Merali |
| 4 | * |
| 5 | * Authors: |
| 6 | * Zaheer Abbas Merali <zaheerabbas at merali dot org> |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Library General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Library General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Library General Public |
| 19 | * License along with this library; if not, write to the |
Tim-Philipp Müller | 9e1b75f | 2012-11-03 20:38:00 +0000 | [diff] [blame] | 20 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 21 | * Boston, MA 02110-1301, USA. |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 22 | */ |
| 23 | |
Tim-Philipp Müller | 3bacb63 | 2013-04-21 14:04:11 +0100 | [diff] [blame] | 24 | #ifdef HAVE_CONFIG_H |
| 25 | #include "config.h" |
| 26 | #endif |
| 27 | |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 28 | #include <glib.h> |
| 29 | #include <glib-object.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | #include <gst/gst.h> |
| 33 | |
Tim-Philipp Müller | bd504e3 | 2013-04-21 18:28:52 +0100 | [diff] [blame] | 34 | #include <gst/gst-i18n-plugin.h> |
| 35 | |
Benjamin Otte | f96e4f1 | 2010-03-21 21:39:18 +0100 | [diff] [blame] | 36 | #include "parsechannels.h" |
| 37 | |
Tim-Philipp Müller | fc2b559 | 2013-04-21 14:13:45 +0100 | [diff] [blame] | 38 | GST_DEBUG_CATEGORY_EXTERN (dvb_base_bin_debug); |
| 39 | #define GST_CAT_DEFAULT dvb_base_bin_debug |
| 40 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 41 | /* TODO: |
| 42 | * Store the channels hash table around instead of constantly parsing it |
| 43 | * Detect when the file changed on disk |
| 44 | */ |
| 45 | |
| 46 | /* this will do zap style channels.conf only for the moment */ |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 47 | static GHashTable * |
Tim-Philipp Müller | bd504e3 | 2013-04-21 18:28:52 +0100 | [diff] [blame] | 48 | parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename, |
| 49 | GError ** error) |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 50 | { |
| 51 | gchar *contents; |
| 52 | gchar **lines; |
| 53 | gchar *line; |
| 54 | gchar **fields; |
Benjamin Otte | 33c2f5f | 2010-03-22 13:16:33 +0100 | [diff] [blame] | 55 | const gchar *terrestrial[] = { "inversion", "bandwidth", |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 56 | "code-rate-hp", "code-rate-lp", "modulation", "transmission-mode", |
| 57 | "guard", "hierarchy" |
| 58 | }; |
Benjamin Otte | 33c2f5f | 2010-03-22 13:16:33 +0100 | [diff] [blame] | 59 | const gchar *satellite[] = { "polarity", "diseqc-source", |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 60 | "symbol-rate" |
| 61 | }; |
Benjamin Otte | 33c2f5f | 2010-03-22 13:16:33 +0100 | [diff] [blame] | 62 | const gchar *cable[] = { "inversion", "symbol-rate", "code-rate-hp", |
Zaheer Abbas Merali | 8be7f45 | 2008-03-01 12:49:13 +0000 | [diff] [blame] | 63 | "modulation" |
| 64 | }; |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 65 | int i, parsedchannels = 0; |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 66 | GHashTable *res; |
| 67 | GError *err = NULL; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 68 | |
Tim-Philipp Müller | 3bacb63 | 2013-04-21 14:04:11 +0100 | [diff] [blame] | 69 | GST_INFO_OBJECT (dvbbasebin, "parsing '%s'", filename); |
| 70 | |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 71 | if (!g_file_get_contents (filename, &contents, NULL, &err)) |
| 72 | goto open_fail; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 73 | |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 74 | lines = g_strsplit (contents, "\n", 0); |
| 75 | res = g_hash_table_new (g_str_hash, g_str_equal); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 76 | |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 77 | i = 0; |
| 78 | line = lines[0]; |
| 79 | while (line != NULL) { |
| 80 | if (line[0] != '#') { |
| 81 | int numfields; |
| 82 | gboolean parsed = FALSE; |
| 83 | GHashTable *params = g_hash_table_new_full (g_str_hash, g_str_equal, |
| 84 | g_free, g_free); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 85 | |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 86 | fields = g_strsplit (line, ":", 0); |
| 87 | numfields = g_strv_length (fields); |
| 88 | if (numfields == 8) { |
| 89 | /* satellite */ |
| 90 | int j; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 91 | |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 92 | g_hash_table_insert (params, g_strdup ("type"), g_strdup ("satellite")); |
| 93 | for (j = 2; j <= 4; j++) { |
| 94 | g_hash_table_insert (params, g_strdup (satellite[j - 2]), |
| 95 | g_strdup (fields[j])); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 96 | } |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 97 | g_hash_table_insert (params, g_strdup ("frequency"), |
| 98 | g_strdup_printf ("%d", atoi (fields[1]) * 1000)); |
| 99 | parsed = TRUE; |
| 100 | } else if (numfields == 13) { |
| 101 | /* terrestrial */ |
| 102 | int j; |
| 103 | |
| 104 | g_hash_table_insert (params, g_strdup ("type"), |
| 105 | g_strdup ("terrestrial")); |
| 106 | for (j = 2; j <= 9; j++) { |
| 107 | g_hash_table_insert (params, g_strdup (terrestrial[j - 2]), |
| 108 | g_strdup (fields[j])); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 109 | } |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 110 | g_hash_table_insert (params, g_strdup ("frequency"), |
| 111 | g_strdup (fields[1])); |
| 112 | parsed = TRUE; |
| 113 | } else if (numfields == 9) { |
| 114 | /* cable */ |
| 115 | int j; |
| 116 | |
| 117 | g_hash_table_insert (params, g_strdup ("type"), g_strdup ("cable")); |
| 118 | for (j = 2; j <= 5; j++) { |
| 119 | g_hash_table_insert (params, g_strdup (cable[j - 2]), |
| 120 | g_strdup (fields[j])); |
| 121 | } |
| 122 | g_hash_table_insert (params, g_strdup ("frequency"), |
| 123 | g_strdup (fields[1])); |
| 124 | parsed = TRUE; |
| 125 | } else if (numfields == 6) { |
| 126 | /* atsc (vsb/qam) */ |
| 127 | g_hash_table_insert (params, g_strdup ("type"), g_strdup ("atsc")); |
| 128 | g_hash_table_insert (params, g_strdup ("modulation"), |
| 129 | g_strdup (fields[2])); |
| 130 | |
| 131 | g_hash_table_insert (params, g_strdup ("frequency"), |
| 132 | g_strdup (fields[1])); |
| 133 | parsed = TRUE; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 134 | } |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 135 | if (parsed) { |
| 136 | g_hash_table_insert (params, g_strdup ("sid"), |
| 137 | g_strdup (fields[numfields - 1])); |
| 138 | g_hash_table_insert (res, g_strdup (fields[0]), params); |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 139 | parsedchannels++; |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 140 | } |
| 141 | g_strfreev (fields); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 142 | } |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 143 | line = lines[++i]; |
| 144 | } |
| 145 | g_strfreev (lines); |
| 146 | g_free (contents); |
| 147 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 148 | if (parsedchannels == 0) |
| 149 | goto no_channels; |
| 150 | |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 151 | return res; |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 152 | |
| 153 | open_fail: |
| 154 | { |
Tim-Philipp Müller | bd504e3 | 2013-04-21 18:28:52 +0100 | [diff] [blame] | 155 | if (err->code == G_FILE_ERROR_NOENT) { |
| 156 | g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_NOT_FOUND, |
| 157 | _("Couldn't find DVB channel configuration file")); |
| 158 | } else { |
| 159 | g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_READ, |
| 160 | _("Couldn't load DVB channel configuration file: %s"), err->message); |
| 161 | } |
Edward Hervey | 068598e | 2012-06-19 10:22:50 +0200 | [diff] [blame] | 162 | g_clear_error (&err); |
| 163 | return NULL; |
| 164 | } |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 165 | |
| 166 | no_channels: |
| 167 | { |
Tim-Philipp Müller | bd504e3 | 2013-04-21 18:28:52 +0100 | [diff] [blame] | 168 | g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_FAILED, |
| 169 | _("DVB channel configuration file doesn't contain any channels")); |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 170 | g_hash_table_unref (res); |
| 171 | return NULL; |
| 172 | } |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static gboolean |
| 176 | remove_channel_from_hash (gpointer key, gpointer value, gpointer user_data) |
| 177 | { |
| 178 | if (key) |
| 179 | g_free (key); |
| 180 | if (value) |
| 181 | g_hash_table_destroy ((GHashTable *) value); |
| 182 | return TRUE; |
| 183 | } |
| 184 | |
| 185 | static void |
| 186 | destroy_channels_hash (GHashTable * channels) |
| 187 | { |
| 188 | g_hash_table_foreach_remove (channels, remove_channel_from_hash, NULL); |
| 189 | } |
| 190 | |
| 191 | gboolean |
Tim-Philipp Müller | bd504e3 | 2013-04-21 18:28:52 +0100 | [diff] [blame] | 192 | set_properties_for_channel (GstElement * dvbbasebin, |
| 193 | const gchar * channel_name, GError ** error) |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 194 | { |
| 195 | gboolean ret = FALSE; |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 196 | GHashTable *channels, *params; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 197 | gchar *filename; |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 198 | gchar *type; |
| 199 | const gchar *adapter; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 200 | |
| 201 | filename = g_strdup (g_getenv ("GST_DVB_CHANNELS_CONF")); |
| 202 | if (filename == NULL) { |
Tim-Philipp Müller | 3bacb63 | 2013-04-21 14:04:11 +0100 | [diff] [blame] | 203 | filename = g_build_filename (g_get_user_config_dir (), |
| 204 | "gstreamer-" GST_API_VERSION, "dvb-channels.conf", NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 205 | } |
Tim-Philipp Müller | bd504e3 | 2013-04-21 18:28:52 +0100 | [diff] [blame] | 206 | channels = parse_channels_conf_from_file (dvbbasebin, filename, error); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 207 | g_free (filename); |
| 208 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 209 | if (!channels) |
| 210 | goto beach; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 211 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 212 | params = g_hash_table_lookup (channels, channel_name); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 213 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 214 | if (!params) |
| 215 | goto unknown_channel; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 216 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 217 | g_object_set (dvbbasebin, "program-numbers", |
| 218 | g_hash_table_lookup (params, "sid"), NULL); |
| 219 | /* check if it is terrestrial or satellite */ |
| 220 | adapter = g_getenv ("GST_DVB_ADAPTER"); |
| 221 | if (adapter) |
| 222 | g_object_set (dvbbasebin, "adapter", atoi (adapter), NULL); |
| 223 | g_object_set (dvbbasebin, "frequency", |
| 224 | atoi (g_hash_table_lookup (params, "frequency")), NULL); |
| 225 | type = g_hash_table_lookup (params, "type"); |
| 226 | if (strcmp (type, "terrestrial") == 0) { |
| 227 | gchar *val; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 228 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 229 | val = g_hash_table_lookup (params, "inversion"); |
| 230 | if (strcmp (val, "INVERSION_OFF") == 0) |
| 231 | g_object_set (dvbbasebin, "inversion", 0, NULL); |
| 232 | else if (strcmp (val, "INVERSION_ON") == 0) |
| 233 | g_object_set (dvbbasebin, "inversion", 1, NULL); |
| 234 | else |
| 235 | g_object_set (dvbbasebin, "inversion", 2, NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 236 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 237 | val = g_hash_table_lookup (params, "bandwidth"); |
| 238 | if (strcmp (val, "BANDWIDTH_8_MHZ") == 0) |
| 239 | g_object_set (dvbbasebin, "bandwidth", 0, NULL); |
| 240 | else if (strcmp (val, "BANDWIDTH_7_MHZ") == 0) |
| 241 | g_object_set (dvbbasebin, "bandwidth", 1, NULL); |
| 242 | else if (strcmp (val, "BANDWIDTH_6_MHZ") == 0) |
| 243 | g_object_set (dvbbasebin, "bandwidth", 2, NULL); |
| 244 | else |
| 245 | g_object_set (dvbbasebin, "bandwidth", 3, NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 246 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 247 | val = g_hash_table_lookup (params, "code-rate-hp"); |
| 248 | if (strcmp (val, "FEC_NONE") == 0) |
| 249 | g_object_set (dvbbasebin, "code-rate-hp", 0, NULL); |
| 250 | else if (strcmp (val, "FEC_1_2") == 0) |
| 251 | g_object_set (dvbbasebin, "code-rate-hp", 1, NULL); |
| 252 | else if (strcmp (val, "FEC_2_3") == 0) |
| 253 | g_object_set (dvbbasebin, "code-rate-hp", 2, NULL); |
| 254 | else if (strcmp (val, "FEC_3_4") == 0) |
| 255 | g_object_set (dvbbasebin, "code-rate-hp", 3, NULL); |
| 256 | else if (strcmp (val, "FEC_4_5") == 0) |
| 257 | g_object_set (dvbbasebin, "code-rate-hp", 4, NULL); |
| 258 | else if (strcmp (val, "FEC_5_6") == 0) |
| 259 | g_object_set (dvbbasebin, "code-rate-hp", 5, NULL); |
| 260 | else if (strcmp (val, "FEC_6_7") == 0) |
| 261 | g_object_set (dvbbasebin, "code-rate-hp", 6, NULL); |
| 262 | else if (strcmp (val, "FEC_7_8") == 0) |
| 263 | g_object_set (dvbbasebin, "code-rate-hp", 7, NULL); |
| 264 | else if (strcmp (val, "FEC_8_9") == 0) |
| 265 | g_object_set (dvbbasebin, "code-rate-hp", 8, NULL); |
| 266 | else |
| 267 | g_object_set (dvbbasebin, "code-rate-hp", 9, NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 268 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 269 | val = g_hash_table_lookup (params, "code-rate-lp"); |
| 270 | if (strcmp (val, "FEC_NONE") == 0) |
| 271 | g_object_set (dvbbasebin, "code-rate-lp", 0, NULL); |
| 272 | else if (strcmp (val, "FEC_1_2") == 0) |
| 273 | g_object_set (dvbbasebin, "code-rate-lp", 1, NULL); |
| 274 | else if (strcmp (val, "FEC_2_3") == 0) |
| 275 | g_object_set (dvbbasebin, "code-rate-lp", 2, NULL); |
| 276 | else if (strcmp (val, "FEC_3_4") == 0) |
| 277 | g_object_set (dvbbasebin, "code-rate-lp", 3, NULL); |
| 278 | else if (strcmp (val, "FEC_4_5") == 0) |
| 279 | g_object_set (dvbbasebin, "code-rate-lp", 4, NULL); |
| 280 | else if (strcmp (val, "FEC_5_6") == 0) |
| 281 | g_object_set (dvbbasebin, "code-rate-lp", 5, NULL); |
| 282 | else if (strcmp (val, "FEC_6_7") == 0) |
| 283 | g_object_set (dvbbasebin, "code-rate-lp", 6, NULL); |
| 284 | else if (strcmp (val, "FEC_7_8") == 0) |
| 285 | g_object_set (dvbbasebin, "code-rate-lp", 7, NULL); |
| 286 | else if (strcmp (val, "FEC_8_9") == 0) |
| 287 | g_object_set (dvbbasebin, "code-rate-lp", 8, NULL); |
| 288 | else |
| 289 | g_object_set (dvbbasebin, "code-rate-lp", 9, NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 290 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 291 | val = g_hash_table_lookup (params, "modulation"); |
| 292 | if (strcmp (val, "QPSK") == 0) |
| 293 | g_object_set (dvbbasebin, "modulation", 0, NULL); |
| 294 | else if (strcmp (val, "QAM_16") == 0) |
| 295 | g_object_set (dvbbasebin, "modulation", 1, NULL); |
| 296 | else if (strcmp (val, "QAM_32") == 0) |
| 297 | g_object_set (dvbbasebin, "modulation", 2, NULL); |
| 298 | else if (strcmp (val, "QAM_64") == 0) |
| 299 | g_object_set (dvbbasebin, "modulation", 3, NULL); |
| 300 | else if (strcmp (val, "QAM_128") == 0) |
| 301 | g_object_set (dvbbasebin, "modulation", 4, NULL); |
| 302 | else if (strcmp (val, "QAM_256") == 0) |
| 303 | g_object_set (dvbbasebin, "modulation", 5, NULL); |
| 304 | else |
| 305 | g_object_set (dvbbasebin, "modulation", 6, NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 306 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 307 | val = g_hash_table_lookup (params, "transmission-mode"); |
| 308 | if (strcmp (val, "TRANSMISSION_MODE_2K") == 0) |
| 309 | g_object_set (dvbbasebin, "trans-mode", 0, NULL); |
| 310 | else if (strcmp (val, "TRANSMISSION_MODE_8K") == 0) |
| 311 | g_object_set (dvbbasebin, "trans-mode", 1, NULL); |
| 312 | else |
| 313 | g_object_set (dvbbasebin, "trans-mode", 2, NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 314 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 315 | val = g_hash_table_lookup (params, "guard"); |
| 316 | if (strcmp (val, "GUARD_INTERVAL_1_32") == 0) |
| 317 | g_object_set (dvbbasebin, "guard", 0, NULL); |
| 318 | else if (strcmp (val, "GUARD_INTERVAL_1_16") == 0) |
| 319 | g_object_set (dvbbasebin, "guard", 1, NULL); |
| 320 | else if (strcmp (val, "GUARD_INTERVAL_1_8") == 0) |
| 321 | g_object_set (dvbbasebin, "guard", 2, NULL); |
| 322 | else if (strcmp (val, "GUARD_INTERVAL_1_4") == 0) |
| 323 | g_object_set (dvbbasebin, "guard", 3, NULL); |
| 324 | else |
| 325 | g_object_set (dvbbasebin, "guard", 4, NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 326 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 327 | val = g_hash_table_lookup (params, "hierarchy"); |
| 328 | if (strcmp (val, "HIERARCHY_NONE") == 0) |
| 329 | g_object_set (dvbbasebin, "hierarchy", 0, NULL); |
| 330 | else if (strcmp (val, "HIERARCHY_1") == 0) |
| 331 | g_object_set (dvbbasebin, "hierarchy", 1, NULL); |
| 332 | else if (strcmp (val, "HIERARCHY_2") == 0) |
| 333 | g_object_set (dvbbasebin, "hierarchy", 2, NULL); |
| 334 | else if (strcmp (val, "HIERARCHY_4") == 0) |
| 335 | g_object_set (dvbbasebin, "hierarchy", 3, NULL); |
| 336 | else |
| 337 | g_object_set (dvbbasebin, "hierarchy", 4, NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 338 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 339 | ret = TRUE; |
| 340 | } else if (strcmp (type, "satellite") == 0) { |
| 341 | gchar *val; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 342 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 343 | ret = TRUE; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 344 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 345 | val = g_hash_table_lookup (params, "polarity"); |
| 346 | if (val) |
| 347 | g_object_set (dvbbasebin, "polarity", val, NULL); |
| 348 | else |
| 349 | ret = FALSE; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 350 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 351 | val = g_hash_table_lookup (params, "diseqc-source"); |
| 352 | if (val) |
| 353 | g_object_set (dvbbasebin, "diseqc-source", atoi (val), NULL); |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 354 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 355 | val = g_hash_table_lookup (params, "symbol-rate"); |
| 356 | if (val) |
| 357 | g_object_set (dvbbasebin, "symbol-rate", atoi (val), NULL); |
| 358 | else |
| 359 | ret = FALSE; |
| 360 | } else if (strcmp (type, "cable") == 0) { |
| 361 | gchar *val; |
Michael Krufky | e2c08fe | 2008-08-18 11:13:07 +0000 | [diff] [blame] | 362 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 363 | ret = TRUE; |
| 364 | val = g_hash_table_lookup (params, "symbol-rate"); |
| 365 | if (val) |
| 366 | g_object_set (dvbbasebin, "symbol-rate", atoi (val) / 1000, NULL); |
| 367 | val = g_hash_table_lookup (params, "modulation"); |
| 368 | if (strcmp (val, "QPSK") == 0) |
| 369 | g_object_set (dvbbasebin, "modulation", 0, NULL); |
| 370 | else if (strcmp (val, "QAM_16") == 0) |
| 371 | g_object_set (dvbbasebin, "modulation", 1, NULL); |
| 372 | else if (strcmp (val, "QAM_32") == 0) |
| 373 | g_object_set (dvbbasebin, "modulation", 2, NULL); |
| 374 | else if (strcmp (val, "QAM_64") == 0) |
| 375 | g_object_set (dvbbasebin, "modulation", 3, NULL); |
| 376 | else if (strcmp (val, "QAM_128") == 0) |
| 377 | g_object_set (dvbbasebin, "modulation", 4, NULL); |
| 378 | else if (strcmp (val, "QAM_256") == 0) |
| 379 | g_object_set (dvbbasebin, "modulation", 5, NULL); |
| 380 | else |
| 381 | g_object_set (dvbbasebin, "modulation", 6, NULL); |
| 382 | val = g_hash_table_lookup (params, "code-rate-hp"); |
| 383 | if (strcmp (val, "FEC_NONE") == 0) |
| 384 | g_object_set (dvbbasebin, "code-rate-hp", 0, NULL); |
| 385 | else if (strcmp (val, "FEC_1_2") == 0) |
| 386 | g_object_set (dvbbasebin, "code-rate-hp", 1, NULL); |
| 387 | else if (strcmp (val, "FEC_2_3") == 0) |
| 388 | g_object_set (dvbbasebin, "code-rate-hp", 2, NULL); |
| 389 | else if (strcmp (val, "FEC_3_4") == 0) |
| 390 | g_object_set (dvbbasebin, "code-rate-hp", 3, NULL); |
| 391 | else if (strcmp (val, "FEC_4_5") == 0) |
| 392 | g_object_set (dvbbasebin, "code-rate-hp", 4, NULL); |
| 393 | else if (strcmp (val, "FEC_5_6") == 0) |
| 394 | g_object_set (dvbbasebin, "code-rate-hp", 5, NULL); |
| 395 | else if (strcmp (val, "FEC_6_7") == 0) |
| 396 | g_object_set (dvbbasebin, "code-rate-hp", 6, NULL); |
| 397 | else if (strcmp (val, "FEC_7_8") == 0) |
| 398 | g_object_set (dvbbasebin, "code-rate-hp", 7, NULL); |
| 399 | else if (strcmp (val, "FEC_8_9") == 0) |
| 400 | g_object_set (dvbbasebin, "code-rate-hp", 8, NULL); |
| 401 | else |
| 402 | g_object_set (dvbbasebin, "code-rate-hp", 9, NULL); |
| 403 | val = g_hash_table_lookup (params, "inversion"); |
| 404 | if (strcmp (val, "INVERSION_OFF") == 0) |
| 405 | g_object_set (dvbbasebin, "inversion", 0, NULL); |
| 406 | else if (strcmp (val, "INVERSION_ON") == 0) |
| 407 | g_object_set (dvbbasebin, "inversion", 1, NULL); |
| 408 | else |
| 409 | g_object_set (dvbbasebin, "inversion", 2, NULL); |
| 410 | } else if (strcmp (type, "atsc") == 0) { |
| 411 | gchar *val; |
Michael Krufky | e2c08fe | 2008-08-18 11:13:07 +0000 | [diff] [blame] | 412 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 413 | ret = TRUE; |
| 414 | |
| 415 | val = g_hash_table_lookup (params, "modulation"); |
| 416 | if (strcmp (val, "QAM_64") == 0) |
| 417 | g_object_set (dvbbasebin, "modulation", 3, NULL); |
| 418 | else if (strcmp (val, "QAM_256") == 0) |
| 419 | g_object_set (dvbbasebin, "modulation", 5, NULL); |
| 420 | else if (strcmp (val, "8VSB") == 0) |
| 421 | g_object_set (dvbbasebin, "modulation", 7, NULL); |
| 422 | else if (strcmp (val, "16VSB") == 0) |
| 423 | g_object_set (dvbbasebin, "modulation", 8, NULL); |
| 424 | else |
| 425 | ret = FALSE; |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 428 | destroy_channels_hash (channels); |
| 429 | |
| 430 | beach: |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 431 | return ret; |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 432 | |
| 433 | unknown_channel: |
| 434 | { |
Tim-Philipp Müller | bd504e3 | 2013-04-21 18:28:52 +0100 | [diff] [blame] | 435 | /* FIXME: is channel name guaranteed to be ASCII or UTF-8? */ |
| 436 | g_set_error (error, GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_NOT_FOUND, |
| 437 | _("Couldn't find details for DVB channel %s"), channel_name); |
Edward Hervey | d7ad4ce | 2012-06-19 10:35:48 +0200 | [diff] [blame] | 438 | destroy_channels_hash (channels); |
| 439 | return FALSE; |
| 440 | } |
Zaheer Abbas Merali | 1316ad4 | 2008-02-08 18:22:08 +0000 | [diff] [blame] | 441 | } |