~ubuntu-branches/ubuntu/precise/gst-plugins-bad0.10/precise-proposed

« back to all changes in this revision

Viewing changes to sys/dvb/parsechannels.c

Tags: upstream-0.10.5.3
Import upstream version 0.10.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
20
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
21
 * Boston, MA 02111-1307, USA.
 
22
 */
 
23
 
 
24
#include <glib.h>
 
25
#include <glib-object.h>
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
#include <gst/gst.h>
 
29
 
 
30
/* this will do zap style channels.conf only for the moment*/
 
31
GHashTable *
 
32
parse_channels_conf_from_file (const gchar * filename)
 
33
{
 
34
  gchar *contents;
 
35
  gchar **lines;
 
36
  gchar *line;
 
37
  gchar **fields;
 
38
  gchar *terrestrial[] = { "inversion", "bandwidth",
 
39
    "code-rate-hp", "code-rate-lp", "modulation", "transmission-mode",
 
40
    "guard", "hierarchy"
 
41
  };
 
42
  gchar *satellite[] = { "polarity", "diseqc-source",
 
43
    "symbol-rate"
 
44
  };
 
45
  int i;
 
46
  GHashTable *res = NULL;
 
47
 
 
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);
 
51
 
 
52
    i = 0;
 
53
    line = lines[0];
 
54
    while (line != NULL) {
 
55
      if (line[0] != '#') {
 
56
        int numfields;
 
57
        gboolean parsed = FALSE;
 
58
        GHashTable *params = g_hash_table_new_full (g_str_hash, g_str_equal,
 
59
            g_free, g_free);
 
60
 
 
61
        fields = g_strsplit (line, ":", 0);
 
62
        numfields = g_strv_length (fields);
 
63
        if (numfields == 8) {
 
64
          /* satellite */
 
65
          int j;
 
66
 
 
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]));
 
72
          }
 
73
          g_hash_table_insert (params, g_strdup ("frequency"),
 
74
              g_strdup_printf ("%d", atoi (fields[1]) * 1000));
 
75
          parsed = TRUE;
 
76
        } else if (numfields == 13) {
 
77
          /* terrestrial */
 
78
          int j;
 
79
 
 
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]));
 
85
          }
 
86
          g_hash_table_insert (params, g_strdup ("frequency"),
 
87
              g_strdup (fields[1]));
 
88
          parsed = TRUE;
 
89
        }
 
90
        if (parsed) {
 
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);
 
94
        }
 
95
        g_strfreev (fields);
 
96
      }
 
97
      line = lines[++i];
 
98
    }
 
99
    g_strfreev (lines);
 
100
    g_free (contents);
 
101
  }
 
102
  return res;
 
103
}
 
104
 
 
105
static gboolean
 
106
remove_channel_from_hash (gpointer key, gpointer value, gpointer user_data)
 
107
{
 
108
  if (key)
 
109
    g_free (key);
 
110
  if (value)
 
111
    g_hash_table_destroy ((GHashTable *) value);
 
112
  return TRUE;
 
113
}
 
114
 
 
115
static void
 
116
destroy_channels_hash (GHashTable * channels)
 
117
{
 
118
  g_hash_table_foreach_remove (channels, remove_channel_from_hash, NULL);
 
119
}
 
120
 
 
121
gboolean
 
122
set_properties_for_channel (GObject * dvbbasebin, const gchar * channel_name)
 
123
{
 
124
  gboolean ret = FALSE;
 
125
  GHashTable *channels;
 
126
  gchar *filename;
 
127
 
 
128
  filename = g_strdup (g_getenv ("GST_DVB_CHANNELS_CONF"));
 
129
  if (filename == NULL) {
 
130
    guint major, minor, micro, nano;
 
131
 
 
132
    gst_version (&major, &minor, &micro, &nano);
 
133
    filename = g_strdup_printf ("%s/.gstreamer-%d.%d/dvb-channels.conf",
 
134
        g_get_home_dir (), major, minor);
 
135
  }
 
136
  channels = parse_channels_conf_from_file (filename);
 
137
  g_free (filename);
 
138
 
 
139
  if (channels) {
 
140
    GHashTable *params = g_hash_table_lookup (channels,
 
141
        channel_name);
 
142
 
 
143
    if (params) {
 
144
      gchar *type;
 
145
      const gchar *adapter;
 
146
 
 
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");
 
151
      if (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) {
 
157
        gchar *val;
 
158
 
 
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);
 
164
        else
 
165
          g_object_set (dvbbasebin, "inversion", 2, NULL);
 
166
 
 
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);
 
174
        else
 
175
          g_object_set (dvbbasebin, "bandwidth", 3, NULL);
 
176
 
 
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);
 
196
        else
 
197
          g_object_set (dvbbasebin, "code-rate-hp", 9, NULL);
 
198
 
 
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);
 
218
        else
 
219
          g_object_set (dvbbasebin, "code-rate-lp", 9, NULL);
 
220
 
 
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);
 
234
        else
 
235
          g_object_set (dvbbasebin, "modulation", 6, NULL);
 
236
 
 
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);
 
242
        else
 
243
          g_object_set (dvbbasebin, "trans-mode", 2, NULL);
 
244
 
 
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);
 
254
        else
 
255
          g_object_set (dvbbasebin, "guard", 4, NULL);
 
256
 
 
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);
 
266
        else
 
267
          g_object_set (dvbbasebin, "hierarchy", 4, NULL);
 
268
 
 
269
        ret = TRUE;
 
270
      } else if (strcmp (type, "satellite") == 0) {
 
271
        gchar *val;
 
272
 
 
273
        ret = TRUE;
 
274
 
 
275
        val = g_hash_table_lookup (params, "polarity");
 
276
        if (val)
 
277
          g_object_set (dvbbasebin, "polarity", val, NULL);
 
278
        else
 
279
          ret = FALSE;
 
280
 
 
281
        val = g_hash_table_lookup (params, "diseqc-source");
 
282
        if (val)
 
283
          g_object_set (dvbbasebin, "diseqc-source", atoi (val), NULL);
 
284
 
 
285
        val = g_hash_table_lookup (params, "symbol-rate");
 
286
        if (val)
 
287
          g_object_set (dvbbasebin, "symbol-rate", atoi (val), NULL);
 
288
        else
 
289
          ret = FALSE;
 
290
      }
 
291
 
 
292
    }
 
293
    destroy_channels_hash (channels);
 
294
  }
 
295
 
 
296
  return ret;
 
297
}