3 * Copyright (C) 2008 Zaheer Abbas Merali
6 * Zaheer Abbas Merali <zaheerabbas at merali dot org>
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.
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.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #include <glib-object.h>
30 #include "parsechannels.h"
33 * Store the channels hash table around instead of constantly parsing it
34 * Detect when the file changed on disk
37 /* this will do zap style channels.conf only for the moment */
39 parse_channels_conf_from_file (GstElement * dvbbasebin, const gchar * filename)
45 const gchar *terrestrial[] = { "inversion", "bandwidth",
46 "code-rate-hp", "code-rate-lp", "modulation", "transmission-mode",
49 const gchar *satellite[] = { "polarity", "diseqc-source",
52 const gchar *cable[] = { "inversion", "symbol-rate", "code-rate-hp",
55 int i, parsedchannels = 0;
59 if (!g_file_get_contents (filename, &contents, NULL, &err))
62 lines = g_strsplit (contents, "\n", 0);
63 res = g_hash_table_new (g_str_hash, g_str_equal);
67 while (line != NULL) {
70 gboolean parsed = FALSE;
71 GHashTable *params = g_hash_table_new_full (g_str_hash, g_str_equal,
74 fields = g_strsplit (line, ":", 0);
75 numfields = g_strv_length (fields);
80 g_hash_table_insert (params, g_strdup ("type"), g_strdup ("satellite"));
81 for (j = 2; j <= 4; j++) {
82 g_hash_table_insert (params, g_strdup (satellite[j - 2]),
83 g_strdup (fields[j]));
85 g_hash_table_insert (params, g_strdup ("frequency"),
86 g_strdup_printf ("%d", atoi (fields[1]) * 1000));
88 } else if (numfields == 13) {
92 g_hash_table_insert (params, g_strdup ("type"),
93 g_strdup ("terrestrial"));
94 for (j = 2; j <= 9; j++) {
95 g_hash_table_insert (params, g_strdup (terrestrial[j - 2]),
96 g_strdup (fields[j]));
98 g_hash_table_insert (params, g_strdup ("frequency"),
99 g_strdup (fields[1]));
101 } else if (numfields == 9) {
105 g_hash_table_insert (params, g_strdup ("type"), g_strdup ("cable"));
106 for (j = 2; j <= 5; j++) {
107 g_hash_table_insert (params, g_strdup (cable[j - 2]),
108 g_strdup (fields[j]));
110 g_hash_table_insert (params, g_strdup ("frequency"),
111 g_strdup (fields[1]));
113 } else if (numfields == 6) {
115 g_hash_table_insert (params, g_strdup ("type"), g_strdup ("atsc"));
116 g_hash_table_insert (params, g_strdup ("modulation"),
117 g_strdup (fields[2]));
119 g_hash_table_insert (params, g_strdup ("frequency"),
120 g_strdup (fields[1]));
124 g_hash_table_insert (params, g_strdup ("sid"),
125 g_strdup (fields[numfields - 1]));
126 g_hash_table_insert (res, g_strdup (fields[0]), params);
136 if (parsedchannels == 0)
143 GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
144 ("Opening channels configuration file '%s' failed : %s", filename,
146 g_clear_error (&err);
152 GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
153 ("Channels configuration file doesn't contain any channels"));
154 g_hash_table_unref (res);
160 remove_channel_from_hash (gpointer key, gpointer value, gpointer user_data)
165 g_hash_table_destroy ((GHashTable *) value);
170 destroy_channels_hash (GHashTable * channels)
172 g_hash_table_foreach_remove (channels, remove_channel_from_hash, NULL);
176 set_properties_for_channel (GstElement * dvbbasebin, const gchar * channel_name)
178 gboolean ret = FALSE;
179 GHashTable *channels, *params;
182 const gchar *adapter;
184 filename = g_strdup (g_getenv ("GST_DVB_CHANNELS_CONF"));
185 if (filename == NULL) {
186 guint major, minor, micro, nano;
188 gst_version (&major, &minor, µ, &nano);
189 filename = g_strdup_printf ("%s/gstreamer-%d.%d/dvb-channels.conf",
190 g_get_user_config_dir (), major, minor);
192 channels = parse_channels_conf_from_file (dvbbasebin, filename);
198 params = g_hash_table_lookup (channels, channel_name);
201 goto unknown_channel;
203 g_object_set (dvbbasebin, "program-numbers",
204 g_hash_table_lookup (params, "sid"), NULL);
205 /* check if it is terrestrial or satellite */
206 adapter = g_getenv ("GST_DVB_ADAPTER");
208 g_object_set (dvbbasebin, "adapter", atoi (adapter), NULL);
209 g_object_set (dvbbasebin, "frequency",
210 atoi (g_hash_table_lookup (params, "frequency")), NULL);
211 type = g_hash_table_lookup (params, "type");
212 if (strcmp (type, "terrestrial") == 0) {
215 val = g_hash_table_lookup (params, "inversion");
216 if (strcmp (val, "INVERSION_OFF") == 0)
217 g_object_set (dvbbasebin, "inversion", 0, NULL);
218 else if (strcmp (val, "INVERSION_ON") == 0)
219 g_object_set (dvbbasebin, "inversion", 1, NULL);
221 g_object_set (dvbbasebin, "inversion", 2, NULL);
223 val = g_hash_table_lookup (params, "bandwidth");
224 if (strcmp (val, "BANDWIDTH_8_MHZ") == 0)
225 g_object_set (dvbbasebin, "bandwidth", 0, NULL);
226 else if (strcmp (val, "BANDWIDTH_7_MHZ") == 0)
227 g_object_set (dvbbasebin, "bandwidth", 1, NULL);
228 else if (strcmp (val, "BANDWIDTH_6_MHZ") == 0)
229 g_object_set (dvbbasebin, "bandwidth", 2, NULL);
231 g_object_set (dvbbasebin, "bandwidth", 3, NULL);
233 val = g_hash_table_lookup (params, "code-rate-hp");
234 if (strcmp (val, "FEC_NONE") == 0)
235 g_object_set (dvbbasebin, "code-rate-hp", 0, NULL);
236 else if (strcmp (val, "FEC_1_2") == 0)
237 g_object_set (dvbbasebin, "code-rate-hp", 1, NULL);
238 else if (strcmp (val, "FEC_2_3") == 0)
239 g_object_set (dvbbasebin, "code-rate-hp", 2, NULL);
240 else if (strcmp (val, "FEC_3_4") == 0)
241 g_object_set (dvbbasebin, "code-rate-hp", 3, NULL);
242 else if (strcmp (val, "FEC_4_5") == 0)
243 g_object_set (dvbbasebin, "code-rate-hp", 4, NULL);
244 else if (strcmp (val, "FEC_5_6") == 0)
245 g_object_set (dvbbasebin, "code-rate-hp", 5, NULL);
246 else if (strcmp (val, "FEC_6_7") == 0)
247 g_object_set (dvbbasebin, "code-rate-hp", 6, NULL);
248 else if (strcmp (val, "FEC_7_8") == 0)
249 g_object_set (dvbbasebin, "code-rate-hp", 7, NULL);
250 else if (strcmp (val, "FEC_8_9") == 0)
251 g_object_set (dvbbasebin, "code-rate-hp", 8, NULL);
253 g_object_set (dvbbasebin, "code-rate-hp", 9, NULL);
255 val = g_hash_table_lookup (params, "code-rate-lp");
256 if (strcmp (val, "FEC_NONE") == 0)
257 g_object_set (dvbbasebin, "code-rate-lp", 0, NULL);
258 else if (strcmp (val, "FEC_1_2") == 0)
259 g_object_set (dvbbasebin, "code-rate-lp", 1, NULL);
260 else if (strcmp (val, "FEC_2_3") == 0)
261 g_object_set (dvbbasebin, "code-rate-lp", 2, NULL);
262 else if (strcmp (val, "FEC_3_4") == 0)
263 g_object_set (dvbbasebin, "code-rate-lp", 3, NULL);
264 else if (strcmp (val, "FEC_4_5") == 0)
265 g_object_set (dvbbasebin, "code-rate-lp", 4, NULL);
266 else if (strcmp (val, "FEC_5_6") == 0)
267 g_object_set (dvbbasebin, "code-rate-lp", 5, NULL);
268 else if (strcmp (val, "FEC_6_7") == 0)
269 g_object_set (dvbbasebin, "code-rate-lp", 6, NULL);
270 else if (strcmp (val, "FEC_7_8") == 0)
271 g_object_set (dvbbasebin, "code-rate-lp", 7, NULL);
272 else if (strcmp (val, "FEC_8_9") == 0)
273 g_object_set (dvbbasebin, "code-rate-lp", 8, NULL);
275 g_object_set (dvbbasebin, "code-rate-lp", 9, NULL);
277 val = g_hash_table_lookup (params, "modulation");
278 if (strcmp (val, "QPSK") == 0)
279 g_object_set (dvbbasebin, "modulation", 0, NULL);
280 else if (strcmp (val, "QAM_16") == 0)
281 g_object_set (dvbbasebin, "modulation", 1, NULL);
282 else if (strcmp (val, "QAM_32") == 0)
283 g_object_set (dvbbasebin, "modulation", 2, NULL);
284 else if (strcmp (val, "QAM_64") == 0)
285 g_object_set (dvbbasebin, "modulation", 3, NULL);
286 else if (strcmp (val, "QAM_128") == 0)
287 g_object_set (dvbbasebin, "modulation", 4, NULL);
288 else if (strcmp (val, "QAM_256") == 0)
289 g_object_set (dvbbasebin, "modulation", 5, NULL);
291 g_object_set (dvbbasebin, "modulation", 6, NULL);
293 val = g_hash_table_lookup (params, "transmission-mode");
294 if (strcmp (val, "TRANSMISSION_MODE_2K") == 0)
295 g_object_set (dvbbasebin, "trans-mode", 0, NULL);
296 else if (strcmp (val, "TRANSMISSION_MODE_8K") == 0)
297 g_object_set (dvbbasebin, "trans-mode", 1, NULL);
299 g_object_set (dvbbasebin, "trans-mode", 2, NULL);
301 val = g_hash_table_lookup (params, "guard");
302 if (strcmp (val, "GUARD_INTERVAL_1_32") == 0)
303 g_object_set (dvbbasebin, "guard", 0, NULL);
304 else if (strcmp (val, "GUARD_INTERVAL_1_16") == 0)
305 g_object_set (dvbbasebin, "guard", 1, NULL);
306 else if (strcmp (val, "GUARD_INTERVAL_1_8") == 0)
307 g_object_set (dvbbasebin, "guard", 2, NULL);
308 else if (strcmp (val, "GUARD_INTERVAL_1_4") == 0)
309 g_object_set (dvbbasebin, "guard", 3, NULL);
311 g_object_set (dvbbasebin, "guard", 4, NULL);
313 val = g_hash_table_lookup (params, "hierarchy");
314 if (strcmp (val, "HIERARCHY_NONE") == 0)
315 g_object_set (dvbbasebin, "hierarchy", 0, NULL);
316 else if (strcmp (val, "HIERARCHY_1") == 0)
317 g_object_set (dvbbasebin, "hierarchy", 1, NULL);
318 else if (strcmp (val, "HIERARCHY_2") == 0)
319 g_object_set (dvbbasebin, "hierarchy", 2, NULL);
320 else if (strcmp (val, "HIERARCHY_4") == 0)
321 g_object_set (dvbbasebin, "hierarchy", 3, NULL);
323 g_object_set (dvbbasebin, "hierarchy", 4, NULL);
326 } else if (strcmp (type, "satellite") == 0) {
331 val = g_hash_table_lookup (params, "polarity");
333 g_object_set (dvbbasebin, "polarity", val, NULL);
337 val = g_hash_table_lookup (params, "diseqc-source");
339 g_object_set (dvbbasebin, "diseqc-source", atoi (val), NULL);
341 val = g_hash_table_lookup (params, "symbol-rate");
343 g_object_set (dvbbasebin, "symbol-rate", atoi (val), NULL);
346 } else if (strcmp (type, "cable") == 0) {
350 val = g_hash_table_lookup (params, "symbol-rate");
352 g_object_set (dvbbasebin, "symbol-rate", atoi (val) / 1000, NULL);
353 val = g_hash_table_lookup (params, "modulation");
354 if (strcmp (val, "QPSK") == 0)
355 g_object_set (dvbbasebin, "modulation", 0, NULL);
356 else if (strcmp (val, "QAM_16") == 0)
357 g_object_set (dvbbasebin, "modulation", 1, NULL);
358 else if (strcmp (val, "QAM_32") == 0)
359 g_object_set (dvbbasebin, "modulation", 2, NULL);
360 else if (strcmp (val, "QAM_64") == 0)
361 g_object_set (dvbbasebin, "modulation", 3, NULL);
362 else if (strcmp (val, "QAM_128") == 0)
363 g_object_set (dvbbasebin, "modulation", 4, NULL);
364 else if (strcmp (val, "QAM_256") == 0)
365 g_object_set (dvbbasebin, "modulation", 5, NULL);
367 g_object_set (dvbbasebin, "modulation", 6, NULL);
368 val = g_hash_table_lookup (params, "code-rate-hp");
369 if (strcmp (val, "FEC_NONE") == 0)
370 g_object_set (dvbbasebin, "code-rate-hp", 0, NULL);
371 else if (strcmp (val, "FEC_1_2") == 0)
372 g_object_set (dvbbasebin, "code-rate-hp", 1, NULL);
373 else if (strcmp (val, "FEC_2_3") == 0)
374 g_object_set (dvbbasebin, "code-rate-hp", 2, NULL);
375 else if (strcmp (val, "FEC_3_4") == 0)
376 g_object_set (dvbbasebin, "code-rate-hp", 3, NULL);
377 else if (strcmp (val, "FEC_4_5") == 0)
378 g_object_set (dvbbasebin, "code-rate-hp", 4, NULL);
379 else if (strcmp (val, "FEC_5_6") == 0)
380 g_object_set (dvbbasebin, "code-rate-hp", 5, NULL);
381 else if (strcmp (val, "FEC_6_7") == 0)
382 g_object_set (dvbbasebin, "code-rate-hp", 6, NULL);
383 else if (strcmp (val, "FEC_7_8") == 0)
384 g_object_set (dvbbasebin, "code-rate-hp", 7, NULL);
385 else if (strcmp (val, "FEC_8_9") == 0)
386 g_object_set (dvbbasebin, "code-rate-hp", 8, NULL);
388 g_object_set (dvbbasebin, "code-rate-hp", 9, NULL);
389 val = g_hash_table_lookup (params, "inversion");
390 if (strcmp (val, "INVERSION_OFF") == 0)
391 g_object_set (dvbbasebin, "inversion", 0, NULL);
392 else if (strcmp (val, "INVERSION_ON") == 0)
393 g_object_set (dvbbasebin, "inversion", 1, NULL);
395 g_object_set (dvbbasebin, "inversion", 2, NULL);
396 } else if (strcmp (type, "atsc") == 0) {
401 val = g_hash_table_lookup (params, "modulation");
402 if (strcmp (val, "QAM_64") == 0)
403 g_object_set (dvbbasebin, "modulation", 3, NULL);
404 else if (strcmp (val, "QAM_256") == 0)
405 g_object_set (dvbbasebin, "modulation", 5, NULL);
406 else if (strcmp (val, "8VSB") == 0)
407 g_object_set (dvbbasebin, "modulation", 7, NULL);
408 else if (strcmp (val, "16VSB") == 0)
409 g_object_set (dvbbasebin, "modulation", 8, NULL);
414 destroy_channels_hash (channels);
421 GST_ELEMENT_ERROR (dvbbasebin, RESOURCE, READ, (NULL),
422 ("Couldn't find configuration properties for channel \"%s\"",
424 destroy_channels_hash (channels);