]> git.sesse.net Git - vlc/blob - modules/access/dtv/access.c
DTV: adjust DVB-S frequency and send tone
[vlc] / modules / access / dtv / access.c
1 /**
2  * @file access.c
3  * @brief Digital broadcasting input module for VLC media player
4  */
5 /*****************************************************************************
6  * Copyright © 2011 Rémi Denis-Courmont
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1
11  * 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
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  ****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <vlc_common.h>
28 #include <vlc_access.h>
29 #include <vlc_plugin.h>
30 #include <vlc_dialog.h>
31
32 #include "dtv/dtv.h"
33
34 #define CACHING_TEXT N_("Caching value (ms)")
35 #define CACHING_LONGTEXT N_( \
36     "The cache size (delay) for digital broadcasts (in milliseconds).")
37
38 #define ADAPTER_TEXT N_("DVB adapter")
39 #define ADAPTER_LONGTEXT N_( \
40     "If there is more than one digital broadcasting adapter, " \
41     "the adapter number must be selected. Numbering start from zero.")
42
43 #define DEVICE_TEXT N_("DVB device")
44 #define DEVICE_LONGTEXT N_( \
45     "If the selected adapter has more than one tuner, " \
46     "the tuner number must be selected. Numbering start from zero.")
47
48 #define BUDGET_TEXT N_("Do not demultiplex")
49 #define BUDGET_LONGTEXT N_( \
50     "Only useful programs are normally demultiplexed from the transponder. " \
51     "This option will disable demultiplexing and receive all programs.")
52
53 #define FREQ_TEXT N_("Frequency (kHz)")
54 #define FREQ_LONGTEXT N_( \
55     "TV channels are grouped by transponder (a.k.a. multiplex) " \
56     "on a given frequency. This is required to tune the receiver.")
57
58 #define MODULATION_TEXT N_("Modulation / Constellation")
59 #define MODULATION_LONGTEXT N_( \
60     "The digital signal can be modulated according with different " \
61     "constellations (depending on the delivery system). " \
62     "If the demodulator cannot detect the constellation automatically, " \
63     "it needs to be configured manually.")
64 static const char *const modulation_vlc[] = { "",
65     "QAM", "16QAM", "32QAM", "64QAM", "128QAM", "256QAM",
66     "8VSB", "16VSB",
67     "QPSK", "DQPSK", "8PSK", "16APSK", "32APSK",
68 };
69 static const char *const modulation_user[] = { N_("Undefined"),
70     "Auto QAM", "16-QAM", "32-QAM", "64-QAM", "128-QAM", "256-QAM",
71     "8-VSB", "16-VSB",
72     "QPSK", "DQPSK", "8-PSK", "16-APSK", "32-APSK",
73 };
74
75 #define SRATE_TEXT N_("Symbol rate (bauds)")
76 #define SRATE_LONGTEXT N_( \
77     "The symbol rate must be specified manually for some systems, " \
78     "notably DVB-C, DVB-S and DVB-S2.")
79
80 #define INVERSION_TEXT N_("Spectrum inversion")
81 #define INVERSION_LONGTEXT N_( \
82     "If the demodulator cannot detect spectral inversion correctly, " \
83     "it needs to be configured manually.")
84 const int auto_off_on_vlc[] = { -1, 0, 1 };
85 static const char *const auto_off_on_user[] = { N_("Automatic"),
86     N_("Off"), N_("On") };
87
88 #define CODE_RATE_TEXT N_("FEC code rate")
89 #define CODE_RATE_HP_TEXT N_("High-priority code rate")
90 #define CODE_RATE_LP_TEXT N_("Low-priority code rate")
91 #define CODE_RATE_LONGTEXT N_( \
92     "The code rate for Forward Error Correction can be specified.")
93 static const char *const code_rate_vlc[] = { "",
94     "none", /*"1/4", "1/3",*/ "1/2", "3/5", "2/3", "3/4",
95     "4/5", "5/6", "6/7", "7/8", "8/9", "9/10",
96 };
97 static const char *const code_rate_user[] = { N_("Automatic"),
98     N_("None"), /*"1/4", "1/3",*/ "1/2", "3/5", "2/3", "3/4",
99     "4/5", "5/6", "6/7", "7/8", "8/9", "9/10",
100 };
101
102 #define TRANSMISSION_TEXT N_("Transmission mode")
103 const int transmission_vlc[] = { -1,
104     2, 4, 8, /*16, 32,*/
105 };
106 static const char *const transmission_user[] = { N_("Automatic"),
107     "2k", "4k", "8k", /*"16k", "32k", */
108 };
109
110 #define BANDWIDTH_TEXT N_("Bandwidth (MHz)")
111 const int bandwidth_vlc[] = { 0,
112     8, 7, 6,
113 };
114 static const char *const bandwidth_user[] = { N_("Automatic"),
115     N_("8 MHz"), N_("7 MHz"), N_("6 MHz"),
116 };
117
118 #define GUARD_TEXT N_("Guard interval")
119 const char *const guard_vlc[] = { "",
120     /*"1/128",*/ "1/32", "1/16", /*"19/128",*/ "1/8", /*"9/256",*/ "1/4",
121 };
122 static const char *const guard_user[] = { N_("Automatic"),
123     /*"1/128",*/ "1/32", "1/16", /*"19/128",*/ "1/8", /*"9/256",*/ "1/4",
124 };
125
126 #define HIERARCHY_TEXT N_("Hierarchy mode")
127 const int hierarchy_vlc[] = { -1,
128     0, 1, 2, 4,
129 };
130 static const char *const hierarchy_user[] = { N_("Automatic"),
131     N_("None"), "1", "2", "4",
132 };
133
134 #define PILOT_TEXT N_("Pilot")
135
136 #define ROLLOFF_TEXT N_("Roll-off factor")
137 const int rolloff_vlc[] = { -1,
138     35, 20, 25,
139 };
140 static const char *const rolloff_user[] = { N_("Automatic"),
141     N_("0.35 (same as DVB-S)"), N_("0.20"), N_("0.25"),
142 };
143
144 #define POLARIZATION_TEXT N_("Polarization (Voltage)")
145 #define POLARIZATION_LONGTEXT N_( \
146     "To select the polarization of the transponder, a different voltage " \
147     "is normally applied to the low noise block-downconverter (LNB).")
148 static const char *const polarization_vlc[] = { "", "V", "H", "R", "L" };
149 static const char *const polarization_user[] = { N_("Unspecified (0V)"),
150     N_("Vertical (13V)"), N_("Horizontal (18V)"),
151     N_("Circular Right Hand (13V)"), N_("Circular Left Hand (18V)") };
152
153 #define HIGH_VOLTAGE_TEXT N_("High LNB voltage")
154 #define HIGH_VOLTAGE_LONGTEXT N_( \
155     "If the cables between the satellilte low noise block-downconverter and " \
156     "the receiver are long, higher voltage may be required.\n" \
157     "Not all receivers support this.")
158
159 #define LNB_LOW_TEXT N_("Local oscillator low frequency (kHz)")
160 #define LNB_HIGH_TEXT N_("Local oscillator high frequency (kHz)")
161 #define LNB_LONGTEXT N_( \
162     "The downconverter (LNB) will substract the local oscillator frequency " \
163     "from the satellite transmission frequency. " \
164     "The intermediate frequency (IF) on the RF cable is the result.")
165 #define LNB_SWITCH_TEXT N_("Universal LNB switch frequency (kHz)")
166 #define LNB_SWITCH_LONGTEXT N_( \
167     "If the satellite transmission frequency exceeds the switch frequency, " \
168     "the oscillator high frequency will be used as reference. " \
169     "Furthermore the automatic continuous 22kHz tone will be sent.")
170 #define TONE_TEXT N_("Continuous 22kHz tone")
171 #define TONE_LONGTEXT N_( \
172     "A continuous tone at 22kHz can be sent on the cable. " \
173     "This normally selects the higher frequency band from a universal LNB.")
174
175 #if 0
176 #define SATNO_TEXT N_("DiSEqC LNB number")
177 #define SATNO_LONGTEXT N_( \
178     "If the satellite receiver is connected to multiple " \
179     "low noise block-downconverters (LNB) through a DiSEqC 1.0 switch, " \
180     "the correct LNB can be selected (1 to 4). " \
181     "If there is no switch, this parameter should be 0.")
182 #endif
183
184 static int  Open (vlc_object_t *);
185 static void Close (vlc_object_t *);
186
187 vlc_module_begin ()
188     set_shortname (N_("DTV"))
189     set_description (N_("Digital Television and Radio (Linux DVB)"))
190     set_category (CAT_INPUT)
191     set_subcategory (SUBCAT_INPUT_ACCESS)
192     set_capability ("access", 0)
193     set_callbacks (Open, Close)
194     add_shortcut ("dtv", "tv", "dvb", /* "radio", "dab",*/
195                   "cable", "dvb-c", "satellite", "dvb-s", "dvb-s2",
196                   "terrestrial", "dvb-t", "atsc")
197
198     /* All options starting with dvb- can be overriden in the MRL, so they
199      * must all be "safe". Nevertheless, we do not mark as safe those that are
200      * really specific to the local system (e.g. device ID...).
201      * It wouldn't make sense to deliver those through a playlist. */
202
203     add_integer ("dvb-caching", DEFAULT_PTS_DELAY / 1000,
204                  CACHING_TEXT, CACHING_LONGTEXT, true)
205         change_integer_range (0, 60000)
206         change_safe ()
207 #ifdef __linux__
208     add_integer ("dvb-adapter", 0, ADAPTER_TEXT, ADAPTER_LONGTEXT, false)
209         change_integer_range (0, 255)
210     add_integer ("dvb-device", 0, DEVICE_TEXT, DEVICE_LONGTEXT, false)
211         change_integer_range (0, 255)
212     add_bool ("dvb-budget-mode", false, BUDGET_TEXT, BUDGET_LONGTEXT, true)
213 #endif
214     add_integer ("dvb-frequency", 0, FREQ_TEXT, FREQ_LONGTEXT, false)
215         change_integer_range (0, 107999999)
216         change_safe ()
217     add_integer ("dvb-inversion", -1, INVERSION_TEXT, INVERSION_LONGTEXT, true)
218         change_integer_list (auto_off_on_vlc, auto_off_on_user)
219         change_safe ()
220
221     set_section (N_("Terrestrial reception parameters"), NULL)
222     add_integer ("dvb-bandwidth", -1, BANDWIDTH_TEXT, BANDWIDTH_TEXT, true)
223         change_integer_list (bandwidth_vlc, bandwidth_user)
224         change_safe ()
225     add_string ("dvb-code-rate-hp", "",
226                 CODE_RATE_HP_TEXT, CODE_RATE_LONGTEXT, false)
227         change_string_list (code_rate_vlc, code_rate_user, NULL)
228         change_safe ()
229     add_string ("dvb-code-rate-lp", "",
230                 CODE_RATE_LP_TEXT, CODE_RATE_LONGTEXT, false)
231         change_string_list (code_rate_vlc, code_rate_user, NULL)
232         change_safe ()
233     add_integer ("dvb-transmission", 0,
234                  TRANSMISSION_TEXT, TRANSMISSION_TEXT, true)
235         change_integer_list (transmission_vlc, transmission_user)
236         change_safe ()
237     add_string ("dvb-guard", "", GUARD_TEXT, GUARD_TEXT, true)
238         change_string_list (guard_vlc, guard_user, NULL)
239         change_safe ()
240     add_integer ("dvb-hierarchy", -1, HIERARCHY_TEXT, HIERARCHY_TEXT, true)
241         change_integer_list (hierarchy_vlc, hierarchy_user)
242         change_safe ()
243
244     set_section (N_("Cable and satellite reception parameters"), NULL)
245     add_string ("dvb-modulation", 0,
246                  MODULATION_TEXT, MODULATION_LONGTEXT, false)
247         change_string_list (modulation_vlc, modulation_user, NULL)
248         change_safe ()
249     add_integer ("dvb-srate", 0, SRATE_TEXT, SRATE_LONGTEXT, false)
250         change_integer_range (0, UINT64_C(0xffffffff))
251         change_safe ()
252     add_string ("dvb-code-rate", "", CODE_RATE_TEXT, CODE_RATE_LONGTEXT, true)
253         change_string_list (code_rate_vlc, code_rate_user, NULL)
254         change_safe ()
255     add_integer ("dvb-fec", 9, " ", " ", true)
256         change_integer_range (0, 9)
257         change_private ()
258         change_safe ()
259     set_section (N_("DVB-S2 parameters"), NULL)
260     add_integer ("dvb-pilot", -1, PILOT_TEXT, PILOT_TEXT, true)
261         change_integer_list (auto_off_on_vlc, auto_off_on_user)
262         change_safe ()
263     add_integer ("dvb-rolloff", -1, ROLLOFF_TEXT, ROLLOFF_TEXT, true)
264         change_integer_list (rolloff_vlc, rolloff_user)
265         change_safe ()
266     set_section (N_("Satellite equipment control"), NULL)
267     add_string ("dvb-polarization", "",
268                 POLARIZATION_TEXT, POLARIZATION_LONGTEXT, false)
269         change_string_list (polarization_vlc, polarization_user, NULL)
270         change_safe ()
271     add_integer ("dvb-voltage", 13, " ", " ", true)
272         change_integer_range (0, 18)
273         change_private ()
274         change_safe ()
275 #ifdef __linux__
276     add_bool ("dvb-high-voltage", false,
277               HIGH_VOLTAGE_TEXT, HIGH_VOLTAGE_LONGTEXT, false)
278 #endif
279     add_integer ("dvb-lnb-low", 0, LNB_LOW_TEXT, LNB_LONGTEXT, true)
280         change_integer_range (0, 0x7fffffff)
281         add_deprecated_alias ("dvb-lnb-lof1")
282     add_integer ("dvb-lnb-high", 0, LNB_HIGH_TEXT, LNB_LONGTEXT, true)
283         change_integer_range (0, 0x7fffffff)
284         add_deprecated_alias ("dvb-lnb-lof2")
285     add_integer ("dvb-lnb-switch", 11700000,
286                  LNB_SWITCH_TEXT, LNB_SWITCH_LONGTEXT, true)
287         change_integer_range (0, 0x7fffffff)
288         add_deprecated_alias ("dvb-lnb-slof")
289     add_integer ("dvb-tone", -1, TONE_TEXT, TONE_LONGTEXT, true)
290         change_integer_list (auto_off_on_vlc, auto_off_on_user)
291 #if 0
292     add_integer ("dvb-satno", 0, SATNO_TEXT, SATNO_LONGTEXT, true)
293         change_integer_range (0, 4)
294         change_safe ()
295 #endif
296 vlc_module_end ()
297
298 struct access_sys_t
299 {
300     dvb_device_t *dev;
301 };
302
303 struct delsys
304 {
305     int (*setup) (vlc_object_t *, dvb_device_t *, unsigned freq);
306     /* TODO: scan stuff */
307 };
308
309 static block_t *Read (access_t *);
310 static int Control (access_t *, int, va_list);
311 static const delsys_t *GuessSystem (const char *, dvb_device_t *);
312 static int Tune (vlc_object_t *, dvb_device_t *, const delsys_t *, unsigned);
313 static unsigned var_InheritFrequency (vlc_object_t *);
314
315 static int Open (vlc_object_t *obj)
316 {
317     access_t *access = (access_t *)obj;
318     access_sys_t *sys = malloc (sizeof (*sys));
319     if (unlikely(sys == NULL))
320         return VLC_ENOMEM;
321
322     var_LocationParse (obj, access->psz_location, "dvb-");
323     unsigned freq = var_InheritFrequency (obj);
324
325     dvb_device_t *dev = dvb_open (obj, freq != 0);
326     if (dev == NULL)
327     {
328         free (sys);
329         return VLC_EGENERIC;
330     }
331
332     sys->dev = dev;
333     access->p_sys = sys;
334
335     if (freq != 0)
336     {
337         const delsys_t *delsys = GuessSystem (access->psz_access, dev);
338         if (delsys == NULL || Tune (obj, dev, delsys, freq))
339         {
340             msg_Err (obj, "tuning to %u kHz failed", freq);
341             dialog_Fatal (obj, N_("Digital broadcasting"),
342                           N_("The selected digital tuner does not support "
343                              "the specified parameters.\n"
344                              "Please check the preferences."));
345             goto error;
346         }
347     }
348     dvb_add_pid (dev, 0);
349
350     access->pf_block = Read;
351     access->pf_control = Control;
352     if (access->psz_demux == NULL || !access->psz_demux[0])
353     {
354         free (access->psz_demux);
355         access->psz_demux = strdup ("ts");
356     }
357     return VLC_SUCCESS;
358
359 error:
360     Close (obj);
361     access->p_sys = NULL;
362     return VLC_EGENERIC;
363 }
364
365 static void Close (vlc_object_t *obj)
366 {
367     access_t *access = (access_t *)obj;
368     access_sys_t *sys = access->p_sys;
369
370     dvb_close (sys->dev);
371     free (sys);
372 }
373
374 static block_t *Read (access_t *access)
375 {
376 #define BUFSIZE (20*188)
377     block_t *block = block_Alloc (BUFSIZE);
378     if (unlikely(block == NULL))
379         return NULL;
380
381     access_sys_t *sys = access->p_sys;
382     ssize_t val = dvb_read (sys->dev, block->p_buffer, BUFSIZE);
383
384     if (val <= 0)
385     {
386         if (val == 0)
387             access->info.b_eof = true;
388         block_Release (block);
389         return NULL;
390     }
391
392     block->i_buffer = val;
393     return block;
394 }
395
396 static int Control (access_t *access, int query, va_list args)
397 {
398     access_sys_t *sys = access->p_sys;
399     dvb_device_t *dev = sys->dev;
400
401     switch (query)
402     {
403         case ACCESS_CAN_SEEK:
404         case ACCESS_CAN_FASTSEEK:
405         case ACCESS_CAN_PAUSE:
406         case ACCESS_CAN_CONTROL_PACE:
407         {
408             bool *v = va_arg (args, bool *);
409             *v = false;
410             return VLC_SUCCESS;
411         }
412
413         case ACCESS_GET_PTS_DELAY:
414         {
415             int64_t *v = va_arg (args, int64_t *);
416             *v = var_InheritInteger (access, "dvb-caching") * INT64_C(1000);
417             return VLC_SUCCESS;
418         }
419
420         case ACCESS_GET_TITLE_INFO:
421         case ACCESS_GET_META:
422             return VLC_EGENERIC;
423
424         case ACCESS_GET_CONTENT_TYPE:
425         {
426             char **pt = va_arg (args, char **);
427             *pt = strdup ("video/MP2T");
428             return VLC_SUCCESS;
429         }
430
431         case ACCESS_SET_PAUSE_STATE:
432         case ACCESS_SET_TITLE:
433         case ACCESS_SET_SEEKPOINT:
434             return VLC_EGENERIC;
435
436         case ACCESS_GET_SIGNAL:
437             *va_arg (args, double *) = dvb_get_snr (dev);
438             *va_arg (args, double *) = dvb_get_signal_strength (dev);
439             return VLC_SUCCESS;
440
441         case ACCESS_SET_PRIVATE_ID_STATE:
442         {
443             unsigned pid = va_arg (args, unsigned);
444             bool add = va_arg (args, unsigned);
445
446             if (unlikely(pid > 0x1FFF))
447                 return VLC_EGENERIC;
448             if (add)
449             {
450                 if (dvb_add_pid (dev, pid))
451                     return VLC_EGENERIC;
452             }
453             else
454                 dvb_remove_pid (dev, pid);
455             return VLC_SUCCESS;
456         }
457
458         case ACCESS_SET_PRIVATE_ID_CA:
459             /* TODO */
460             return VLC_EGENERIC;
461
462         case ACCESS_GET_PRIVATE_ID_STATE:
463             return VLC_EGENERIC;
464     }
465
466     msg_Warn (access, "unimplemented query %d in control", query);
467     return VLC_EGENERIC;
468 }
469
470
471 /*** Generic tuning ***/
472
473 /** Determines which delivery system to use. */
474 static const delsys_t *GuessSystem (const char *scheme, dvb_device_t *dev)
475 {
476     /* NOTE: We should guess the delivery system for the "cable", "satellite"
477      * and "terrestrial" shortcuts (i.e. DVB, ISDB, ATSC...). But there is
478      * seemingly no sane way to do get the info with Linux DVB version 5.2.
479      * In particular, the frontend infos distinguish only the modulator class
480      * (QPSK, QAM, OFDM or ATSC).
481      *
482      * Furthermore, if the demodulator supports 2G, we cannot guess whether
483      * 1G or 2G is intended. For backward compatibility, 1G is assumed
484      * (this is not a limitation of Linux DVB). We will probably need something
485      * smarter when 2G (semi automatic) scanning is implemented. */
486     if (!strcasecmp (scheme, "cable"))
487         scheme = "dvb-c";
488     else
489     if (!strcasecmp (scheme, "satellite"))
490         scheme = "dvb-s";
491     else
492     if (!strcasecmp (scheme, "terrestrial"))
493         scheme = "dvb-t";
494
495     if (!strcasecmp (scheme, "atsc"))
496         return &atsc;
497     if (!strcasecmp (scheme, "dvb-c"))
498         return &dvbc;
499     if (!strcasecmp (scheme, "dvb-s"))
500         return &dvbs;
501     if (!strcasecmp (scheme, "dvb-s2"))
502         return &dvbs2;
503     if (!strcasecmp (scheme, "dvb-t"))
504         return &dvbt;
505
506     return dvb_guess_system (dev);
507 }
508
509 /** Set parameters and tune the device */
510 static int Tune (vlc_object_t *obj, dvb_device_t *dev, const delsys_t *delsys,
511                  unsigned freq)
512 {
513     if (delsys->setup (obj, dev, freq)
514      || dvb_set_inversion (dev, var_InheritInteger (obj, "dvb-inversion"))
515      || dvb_tune (dev))
516         return VLC_EGENERIC;
517     return VLC_SUCCESS;
518 }
519
520 static unsigned var_InheritFrequency (vlc_object_t *obj)
521 {
522     unsigned freq = var_InheritInteger (obj, "dvb-frequency");
523     if (freq >= 108000000)
524     {
525         msg_Err (obj, "%u kHz frequency is too high.", freq);
526         freq /= 1000;
527         msg_Info (obj, "Assuming %u kHz carrier frequency instead.", freq);
528     }
529     return freq;
530 }
531
532 static char *var_InheritCodeRate (vlc_object_t *obj)
533 {
534     char *code_rate = var_InheritString (obj, "dvb-code-rate");
535     if (code_rate != NULL)
536         return code_rate;
537
538     /* Backward compatibility with VLC < 1.2 (= Linux DVBv3 enum) */
539     unsigned fec = var_InheritInteger (obj, "dvb-fec");
540     if (fec < 9)
541     {
542         static const char linux_dvb[9][5] = {
543             "none", "1/2", "2/3", "3/4", "4/5", "5/6", "6/7", "7/8" };
544         msg_Warn (obj, "\"fec=%u\" option is obsolete. "
545                        "Use \"code-rate=%s\" instead.", fec, linux_dvb[fec]);
546         return strdup (linux_dvb[fec]);
547     }
548     return NULL;
549 }
550
551 static char *var_InheritModulation (vlc_object_t *obj)
552 {
553     char *mod = var_InheritString (obj, "dvb-modulation");
554     if (mod == NULL)
555         return mod;
556
557     char *end;
558     unsigned long l = strtol (mod, &end, 0);
559     if (*end != '\0') /* not a number = not from VLC < 1.2 */
560         return mod;
561
562     /* Backward compatibility with VLC < 1.2 */
563     const char *str;
564     switch (l)
565     {
566         case -1:  str = "QPSK";   break;
567         case 0:   str = "QAM";    break;
568         case 8:   str = "8VSB";   break;
569         case 16:  str = "16QAM";  break;
570         case 32:  str = "32QAM";  break;
571         case 64:  str = "64QAM";  break;
572         case 128: str = "128QAM"; break;
573         case 256: str = "256QAM"; break;
574         default:  return mod;
575     }
576
577     msg_Warn (obj, "\"modulation=%ld\" option is obsolete. "
578                    "Use \"modulation=%s\" instead.", l, str);
579     return strdup (str);
580 }
581
582
583 /*** ATSC ***/
584 static int atsc_setup (vlc_object_t *obj, dvb_device_t *dev, unsigned freq)
585 {
586     char *mod = var_InheritModulation (obj);
587
588     int ret = dvb_set_atsc (dev, freq, mod);
589     free (mod);
590     return ret;
591 }
592
593 const delsys_t atsc = { .setup = atsc_setup };
594
595
596 /*** DVB-C ***/
597 static int dvbc_setup (vlc_object_t *obj, dvb_device_t *dev, unsigned freq)
598 {
599     char *mod = var_InheritModulation (obj);
600     char *fec = var_InheritCodeRate (obj);
601     unsigned srate = var_InheritInteger (obj, "dvb-srate");
602
603     int ret = dvb_set_dvbc (dev, freq, mod, srate, fec);
604     free (fec);
605     free (mod);
606     return ret;
607 }
608
609 const delsys_t dvbc = { .setup = dvbc_setup };
610
611
612 /*** DVB-S ***/
613 static char var_InheritPolarization (vlc_object_t *obj)
614 {
615     char pol;
616     char *polstr = var_InheritString (obj, "dvb-polarization");
617     if (polstr != NULL)
618     {
619         pol = *polstr;
620         free (polstr);
621         if (unlikely(pol >= 'a' && pol <= 'z'))
622             pol -= 'a' - 'A';
623         return pol;
624     }
625
626     /* Backward compatibility with VLC for Linux < 1.2 */
627     unsigned voltage = var_InheritInteger (obj, "dvb-voltage");
628     switch (voltage)
629     {
630         case 13:  pol = 'V'; break;
631         case 18:  pol = 'H'; break;
632         default:  return 0;
633     }
634
635     msg_Warn (obj, "\"voltage=%u\" option is obsolete. "
636                    "Use \"polarization=%c\" instead.", voltage, pol);
637     return pol;
638 }
639
640 static int sec_setup (vlc_object_t *obj, dvb_device_t *dev, unsigned freq)
641 {
642     char pol = var_InheritPolarization (obj);
643     unsigned lowf = var_InheritInteger (obj, "dvb-lnb-low");
644     unsigned highf = var_InheritInteger (obj, "dvb-lnb-high");
645     unsigned switchf = var_InheritInteger (obj, "dvb-lnb-switch");
646
647     return dvb_set_sec (dev, freq, pol, lowf, highf, switchf);
648 }
649
650 static int dvbs_setup (vlc_object_t *obj, dvb_device_t *dev, unsigned freq)
651 {
652     char *fec = var_InheritCodeRate (obj);
653     uint32_t srate = var_InheritInteger (obj, "dvb-srate");
654
655     /* FIXME: adjust frequency (offset) */
656     int ret = dvb_set_dvbs (dev, freq, srate, fec);
657     free (fec);
658     if (ret == 0)
659         ret = sec_setup (obj, dev, freq);
660     return ret;
661 }
662
663 static int dvbs2_setup (vlc_object_t *obj, dvb_device_t *dev, unsigned freq)
664 {
665     char *mod = var_InheritModulation (obj);
666     char *fec = var_InheritCodeRate (obj);
667     uint32_t srate = var_InheritInteger (obj, "dvb-srate");
668     int pilot = var_InheritInteger (obj, "dvb-pilot");
669     int rolloff = var_InheritInteger (obj, "dvb-rolloff");
670
671     /* FIXME: adjust frequency (offset)? */
672     int ret = dvb_set_dvbs2 (dev, freq, mod, srate, fec, pilot, rolloff);
673     free (fec);
674     free (mod);
675     if (ret == 0)
676         ret = sec_setup (obj, dev, freq);
677     return ret;
678 }
679
680 const delsys_t dvbs = { .setup = dvbs_setup };
681 const delsys_t dvbs2 = { .setup = dvbs2_setup };
682
683
684 /*** DVB-T ***/
685 static int dvbt_setup (vlc_object_t *obj, dvb_device_t *dev, unsigned freq)
686 {
687     char *mod = var_InheritModulation (obj);
688     char *fec_hp = var_InheritString (obj, "dvb-code-rate-hp");
689     char *fec_lp = var_InheritString (obj, "dvb-code-rate-lp");
690     char *guard = var_InheritString (obj, "dvb-guard");
691     uint32_t bw = var_InheritInteger (obj, "dvb-bandwidth");
692     int tx = var_InheritInteger (obj, "dvb-transmission");
693     int h = var_InheritInteger (obj, "dvb-hierarchy");
694
695     int ret = dvb_set_dvbt (dev, freq, mod, fec_hp, fec_lp, bw, tx, guard, h);
696     free (guard);
697     free (fec_lp);
698     free (fec_hp);
699     free (mod);
700     return ret;
701 }
702
703 const delsys_t dvbt = { .setup = dvbt_setup };