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., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
25
#include <glib-object.h>
30
/* this will do zap style channels.conf only for the moment*/
32
parse_channels_conf_from_file (const gchar * filename)
38
gchar *terrestrial[] = { "inversion", "bandwidth",
39
"code-rate-hp", "code-rate-lp", "modulation", "transmission-mode",
42
gchar *satellite[] = { "polarity", "diseqc-source",
46
GHashTable *res = NULL;
48
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
49
lines = g_strsplit (contents, "\n", 0);
50
res = g_hash_table_new (g_str_hash, g_str_equal);
54
while (line != NULL) {
57
gboolean parsed = FALSE;
58
GHashTable *params = g_hash_table_new_full (g_str_hash, g_str_equal,
61
fields = g_strsplit (line, ":", 0);
62
numfields = g_strv_length (fields);
67
g_hash_table_insert (params, g_strdup ("type"),
68
g_strdup ("satellite"));
69
for (j = 2; j <= 4; j++) {
70
g_hash_table_insert (params, g_strdup (satellite[j - 2]),
71
g_strdup (fields[j]));
73
g_hash_table_insert (params, g_strdup ("frequency"),
74
g_strdup_printf ("%d", atoi (fields[1]) * 1000));
76
} else if (numfields == 13) {
80
g_hash_table_insert (params, g_strdup ("type"),
81
g_strdup ("terrestrial"));
82
for (j = 2; j <= 9; j++) {
83
g_hash_table_insert (params, g_strdup (terrestrial[j - 2]),
84
g_strdup (fields[j]));
86
g_hash_table_insert (params, g_strdup ("frequency"),
87
g_strdup (fields[1]));
91
g_hash_table_insert (params, g_strdup ("sid"),
92
g_strdup (fields[numfields - 1]));
93
g_hash_table_insert (res, g_strdup (fields[0]), params);
106
remove_channel_from_hash (gpointer key, gpointer value, gpointer user_data)
111
g_hash_table_destroy ((GHashTable *) value);
116
destroy_channels_hash (GHashTable * channels)
118
g_hash_table_foreach_remove (channels, remove_channel_from_hash, NULL);
122
set_properties_for_channel (GObject * dvbbasebin, const gchar * channel_name)
124
gboolean ret = FALSE;
125
GHashTable *channels;
128
filename = g_strdup (g_getenv ("GST_DVB_CHANNELS_CONF"));
129
if (filename == NULL) {
130
guint major, minor, micro, nano;
132
gst_version (&major, &minor, µ, &nano);
133
filename = g_strdup_printf ("%s/.gstreamer-%d.%d/dvb-channels.conf",
134
g_get_home_dir (), major, minor);
136
channels = parse_channels_conf_from_file (filename);
140
GHashTable *params = g_hash_table_lookup (channels,
145
const gchar *adapter;
147
g_object_set (dvbbasebin, "program-numbers",
148
g_hash_table_lookup (params, "sid"), NULL);
149
/* check if it is terrestrial or satellite */
150
adapter = g_getenv ("GST_DVB_ADAPTER");
152
g_object_set (dvbbasebin, "adapter", atoi (adapter), NULL);
153
g_object_set (dvbbasebin, "frequency",
154
atoi (g_hash_table_lookup (params, "frequency")), NULL);
155
type = g_hash_table_lookup (params, "type");
156
if (strcmp (type, "terrestrial") == 0) {
159
val = g_hash_table_lookup (params, "inversion");
160
if (strcmp (val, "INVERSION_OFF") == 0)
161
g_object_set (dvbbasebin, "inversion", 0, NULL);
162
else if (strcmp (val, "INVERSION_ON") == 0)
163
g_object_set (dvbbasebin, "inversion", 1, NULL);
165
g_object_set (dvbbasebin, "inversion", 2, NULL);
167
val = g_hash_table_lookup (params, "bandwidth");
168
if (strcmp (val, "BANDWIDTH_8_MHZ") == 0)
169
g_object_set (dvbbasebin, "bandwidth", 0, NULL);
170
else if (strcmp (val, "BANDWIDTH_7_MHZ") == 0)
171
g_object_set (dvbbasebin, "bandwidth", 1, NULL);
172
else if (strcmp (val, "BANDWIDTH_6_MHZ") == 0)
173
g_object_set (dvbbasebin, "bandwidth", 2, NULL);
175
g_object_set (dvbbasebin, "bandwidth", 3, NULL);
177
val = g_hash_table_lookup (params, "code-rate-hp");
178
if (strcmp (val, "FEC_NONE") == 0)
179
g_object_set (dvbbasebin, "code-rate-hp", 0, NULL);
180
else if (strcmp (val, "FEC_1_2") == 0)
181
g_object_set (dvbbasebin, "code-rate-hp", 1, NULL);
182
else if (strcmp (val, "FEC_2_3") == 0)
183
g_object_set (dvbbasebin, "code-rate-hp", 2, NULL);
184
else if (strcmp (val, "FEC_3_4") == 0)
185
g_object_set (dvbbasebin, "code-rate-hp", 3, NULL);
186
else if (strcmp (val, "FEC_4_5") == 0)
187
g_object_set (dvbbasebin, "code-rate-hp", 4, NULL);
188
else if (strcmp (val, "FEC_5_6") == 0)
189
g_object_set (dvbbasebin, "code-rate-hp", 5, NULL);
190
else if (strcmp (val, "FEC_6_7") == 0)
191
g_object_set (dvbbasebin, "code-rate-hp", 6, NULL);
192
else if (strcmp (val, "FEC_7_8") == 0)
193
g_object_set (dvbbasebin, "code-rate-hp", 7, NULL);
194
else if (strcmp (val, "FEC_8_9") == 0)
195
g_object_set (dvbbasebin, "code-rate-hp", 8, NULL);
197
g_object_set (dvbbasebin, "code-rate-hp", 9, NULL);
199
val = g_hash_table_lookup (params, "code-rate-lp");
200
if (strcmp (val, "FEC_NONE") == 0)
201
g_object_set (dvbbasebin, "code-rate-lp", 0, NULL);
202
else if (strcmp (val, "FEC_1_2") == 0)
203
g_object_set (dvbbasebin, "code-rate-lp", 1, NULL);
204
else if (strcmp (val, "FEC_2_3") == 0)
205
g_object_set (dvbbasebin, "code-rate-lp", 2, NULL);
206
else if (strcmp (val, "FEC_3_4") == 0)
207
g_object_set (dvbbasebin, "code-rate-lp", 3, NULL);
208
else if (strcmp (val, "FEC_4_5") == 0)
209
g_object_set (dvbbasebin, "code-rate-lp", 4, NULL);
210
else if (strcmp (val, "FEC_5_6") == 0)
211
g_object_set (dvbbasebin, "code-rate-lp", 5, NULL);
212
else if (strcmp (val, "FEC_6_7") == 0)
213
g_object_set (dvbbasebin, "code-rate-lp", 6, NULL);
214
else if (strcmp (val, "FEC_7_8") == 0)
215
g_object_set (dvbbasebin, "code-rate-lp", 7, NULL);
216
else if (strcmp (val, "FEC_8_9") == 0)
217
g_object_set (dvbbasebin, "code-rate-lp", 8, NULL);
219
g_object_set (dvbbasebin, "code-rate-lp", 9, NULL);
221
val = g_hash_table_lookup (params, "modulation");
222
if (strcmp (val, "QPSK") == 0)
223
g_object_set (dvbbasebin, "modulation", 0, NULL);
224
else if (strcmp (val, "QAM_16") == 0)
225
g_object_set (dvbbasebin, "modulation", 1, NULL);
226
else if (strcmp (val, "QAM_32") == 0)
227
g_object_set (dvbbasebin, "modulation", 2, NULL);
228
else if (strcmp (val, "QAM_64") == 0)
229
g_object_set (dvbbasebin, "modulation", 3, NULL);
230
else if (strcmp (val, "QAM_128") == 0)
231
g_object_set (dvbbasebin, "modulation", 4, NULL);
232
else if (strcmp (val, "QAM_256") == 0)
233
g_object_set (dvbbasebin, "modulation", 5, NULL);
235
g_object_set (dvbbasebin, "modulation", 6, NULL);
237
val = g_hash_table_lookup (params, "transmission-mode");
238
if (strcmp (val, "TRANSMISSION_MODE_2K") == 0)
239
g_object_set (dvbbasebin, "trans-mode", 0, NULL);
240
else if (strcmp (val, "TRANSMISSION_MODE_8K") == 0)
241
g_object_set (dvbbasebin, "trans-mode", 1, NULL);
243
g_object_set (dvbbasebin, "trans-mode", 2, NULL);
245
val = g_hash_table_lookup (params, "guard");
246
if (strcmp (val, "GUARD_INTERVAL_1_32") == 0)
247
g_object_set (dvbbasebin, "guard", 0, NULL);
248
else if (strcmp (val, "GUARD_INTERVAL_1_16") == 0)
249
g_object_set (dvbbasebin, "guard", 1, NULL);
250
else if (strcmp (val, "GUARD_INTERVAL_1_8") == 0)
251
g_object_set (dvbbasebin, "guard", 2, NULL);
252
else if (strcmp (val, "GUARD_INTERVAL_1_4") == 0)
253
g_object_set (dvbbasebin, "guard", 3, NULL);
255
g_object_set (dvbbasebin, "guard", 4, NULL);
257
val = g_hash_table_lookup (params, "hierarchy");
258
if (strcmp (val, "HIERARCHY_NONE") == 0)
259
g_object_set (dvbbasebin, "hierarchy", 0, NULL);
260
else if (strcmp (val, "HIERARCHY_1") == 0)
261
g_object_set (dvbbasebin, "hierarchy", 1, NULL);
262
else if (strcmp (val, "HIERARCHY_2") == 0)
263
g_object_set (dvbbasebin, "hierarchy", 2, NULL);
264
else if (strcmp (val, "HIERARCHY_4") == 0)
265
g_object_set (dvbbasebin, "hierarchy", 3, NULL);
267
g_object_set (dvbbasebin, "hierarchy", 4, NULL);
270
} else if (strcmp (type, "satellite") == 0) {
275
val = g_hash_table_lookup (params, "polarity");
277
g_object_set (dvbbasebin, "polarity", val, NULL);
281
val = g_hash_table_lookup (params, "diseqc-source");
283
g_object_set (dvbbasebin, "diseqc-source", atoi (val), NULL);
285
val = g_hash_table_lookup (params, "symbol-rate");
287
g_object_set (dvbbasebin, "symbol-rate", atoi (val), NULL);
293
destroy_channels_hash (channels);