]> git.sesse.net Git - vlc/blob - modules/access/bda/bda.c
BDA - additional DVB-S parameters added
[vlc] / modules / access / bda / bda.c
1 /*****************************************************************************
2  * bda.c : BDA access module for vlc
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  *
6  * Author: Ken Self <kens@campoz.fslife.co.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program 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 General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "bda.h"
27
28 /*****************************************************************************
29  * Access: local prototypes
30  *****************************************************************************/
31 static int  Open( vlc_object_t *p_this );
32 static int  ParsePath( access_t *p_access, const char* psz_module,
33     const int i_param_count, const char** psz_param, const int* i_type );
34 static void Close( vlc_object_t *p_this );
35 static block_t *Block( access_t * );
36 static int Control( access_t *, int, va_list );
37
38
39 #define CACHING_TEXT N_("Caching value in ms")
40 #define CACHING_LONGTEXT N_( \
41     "Caching value for DVB streams. This " \
42     "value should be set in milliseconds." )
43
44 #define ADAPTER_TEXT N_("Adapter card to tune")
45 #define ADAPTER_LONGTEXT N_("Adapter cards have a device file in directory " \
46     "named /dev/dvb/adapter[n] with n>=0.")
47
48 #define DEVICE_TEXT N_("Device number to use on adapter")
49 #define DEVICE_LONGTEXT ""
50
51 #define FREQ_TEXT N_("Transponder/multiplex frequency")
52 #if defined(WIN32) || defined(WINCE)
53 #    define FREQ_LONGTEXT N_("In kHz for DVB-S or Hz for DVB-C/T")
54 #else
55 #    define FREQ_LONGTEXT N_("In kHz for DVB-C/S/T")
56 #endif
57
58 #define INVERSION_TEXT N_("Inversion mode")
59 #define INVERSION_LONGTEXT N_("Inversion mode [0=off, 1=on, 2=auto]")
60
61 #define PROBE_TEXT N_("Probe DVB card for capabilities")
62 #define PROBE_LONGTEXT N_("Some DVB cards do not like to be probed for their " \
63     "capabilities, you can disable this feature if you experience some " \
64     "trouble.")
65
66 #define BUDGET_TEXT N_("Budget mode")
67 #define BUDGET_LONGTEXT N_("This allows you to stream an entire transponder " \
68     "with a \"budget\" card.")
69
70 /* Satellite */
71 #define SATNO_TEXT N_("Satellite number in the Diseqc system")
72 #define SATNO_LONGTEXT N_("[0=no diseqc, 1-4=satellite number].")
73
74 #define VOLTAGE_TEXT N_("LNB voltage")
75 #define VOLTAGE_LONGTEXT N_("In Volts [0, 13=vertical, 18=horizontal].")
76
77 #define HIGH_VOLTAGE_TEXT N_("High LNB voltage")
78 #define HIGH_VOLTAGE_LONGTEXT N_("Enable high voltage if your cables are " \
79     "particularly long. This is not supported by all frontends.")
80
81 #define TONE_TEXT N_("22 kHz tone")
82 #define TONE_LONGTEXT N_("[0=off, 1=on, -1=auto].")
83
84 #define FEC_TEXT N_("Transponder FEC")
85 #define FEC_LONGTEXT N_("FEC=Forward Error Correction mode [9=auto].")
86
87 #define SRATE_TEXT N_("Transponder symbol rate in kHz")
88 #define SRATE_LONGTEXT ""
89
90 #define LNB_LOF1_TEXT N_("Antenna lnb_lof1 (kHz)")
91 #define LNB_LOF1_LONGTEXT N_("Low Band Local Osc Freq in kHz usually 9.75GHz")
92
93 #define LNB_LOF2_TEXT N_("Antenna lnb_lof2 (kHz)")
94 #define LNB_LOF2_LONGTEXT N_("High Band Local Osc Freq in kHz usually 10.6GHz")
95
96 #define LNB_SLOF_TEXT N_("Antenna lnb_slof (kHz)")
97 #define LNB_SLOF_LONGTEXT N_( \
98     "Low Noise Block switch freq in kHz usually 11.7GHz")
99
100 /* Cable */
101 #define MODULATION_TEXT N_("Modulation type")
102 #define MODULATION_LONGTEXT N_("QAM constellation points " \
103     "[16, 32, 64, 128, 256]")
104 static const int i_qam_list[] = { -1, 16, 32, 64, 128, 256 };
105 static const char *ppsz_qam_text[] = { N_("Undefined"), N_("16"), N_("32"),
106     N_("64"), N_("128"), N_("256") };
107
108 /* Terrestrial */
109 #define CODE_RATE_HP_TEXT N_("Terrestrial high priority stream code rate (FEC)")
110 #define CODE_RATE_HP_LONGTEXT ""
111
112 #define CODE_RATE_LP_TEXT N_("Terrestrial low priority stream code rate (FEC)")
113 #define CODE_RATE_LP_LONGTEXT ""
114
115 #define BANDWIDTH_TEXT N_("Terrestrial bandwidth")
116 #define BANDWIDTH_LONGTEXT N_("Terrestrial bandwidth [0=auto,6,7,8 in MHz]")
117 static const int i_band_list[] = { -1, 6, 7, 8 };
118 static const char *ppsz_band_text[] = { N_("Undefined"), N_("6"), N_("7"),
119     N_("8") };
120
121 #define GUARD_TEXT N_("Terrestrial guard interval")
122 #define GUARD_LONGTEXT ""
123
124 #define TRANSMISSION_TEXT N_("Terrestrial transmission mode")
125 #define TRANSMISSION_LONGTEXT ""
126
127 #define HIERARCHY_TEXT N_("Terrestrial hierarchy mode")
128 #define HIERARCHY_LONGTEXT ""
129
130 /* BDA module additional DVB-S Parameters */
131 #define AZIMUTH_TEXT N_("Satellite Azimuth")
132 #define AZIMUTH_LONGTEXT N_("Satellite Azimuth in tenths of degree")
133 #define ELEVATION_TEXT N_("Satellite Elevation")
134 #define ELEVATION_LONGTEXT N_("Satellite Elevation in tenths of degree")
135 #define LONGITUDE_TEXT N_("Satellite Longitude")
136 #define LONGITUDE_LONGTEXT N_( \
137     "Satellite Longitude in 10ths of degree, -ve=West")
138 #define POLARISATION_TEXT N_("Satellite Polarisation")
139 #define POLARISATION_LONGTEXT N_("Satellite Polarisation [H/V/L/R]")
140 static const char *ppsz_polar_list[] = { "H", "V", "L", "R" };
141 static const char *ppsz_polar_text[] = { N_("Horizontal"), N_("Vertical"),
142     N_("Circular Left"), N_("Circular Right") };
143
144 vlc_module_begin();
145     set_shortname( _("DVB") );
146     set_description( _("DirectShow DVB input") );
147     set_category( CAT_INPUT );
148     set_subcategory( SUBCAT_INPUT_ACCESS );
149
150     add_integer( "dvb-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
151                  CACHING_LONGTEXT, VLC_TRUE );
152     add_integer( "dvb-frequency", 11954000, NULL, FREQ_TEXT, FREQ_LONGTEXT,
153                  VLC_FALSE );
154 #   if defined(WIN32) || defined(WINCE)
155 #   else
156         add_integer( "dvb-adapter", 0, NULL, ADAPTER_TEXT, ADAPTER_LONGTEXT,
157                      VLC_FALSE );
158         add_integer( "dvb-device", 0, NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
159                      VLC_TRUE );
160         add_integer( "dvb-inversion", 2, NULL, INVERSION_TEXT,
161             INVERSION_LONGTEXT, VLC_TRUE );
162         add_bool( "dvb-probe", 1, NULL, PROBE_TEXT, PROBE_LONGTEXT, VLC_TRUE );
163         add_bool( "dvb-budget-mode", 0, NULL, BUDGET_TEXT, BUDGET_LONGTEXT,
164                   VLC_TRUE );
165 #   endif
166
167     /* DVB-S (satellite) */
168 #   if defined(WIN32) || defined(WINCE)
169         add_integer( "dvb-azimuth", 0, NULL, AZIMUTH_TEXT, AZIMUTH_LONGTEXT,
170             VLC_TRUE );
171         add_integer( "dvb-elevation", 0, NULL, ELEVATION_TEXT,
172             ELEVATION_LONGTEXT, VLC_TRUE );
173         add_integer( "dvb-longitude", 0, NULL, LONGITUDE_TEXT,
174             LONGITUDE_LONGTEXT, VLC_TRUE );
175         add_string( "dvb-polarisation", NULL, NULL, POLARISATION_TEXT,
176             POLARISATION_LONGTEXT, VLC_TRUE );
177             change_string_list( ppsz_polar_list, ppsz_polar_text, 0 );
178             /* Note: Polaristion H = voltage 18; V = voltage 13; */
179 #   else
180         add_integer( "dvb-satno", 0, NULL, SATNO_TEXT, SATNO_LONGTEXT,
181             VLC_TRUE );
182         add_integer( "dvb-voltage", 13, NULL, VOLTAGE_TEXT, VOLTAGE_LONGTEXT,
183             VLC_TRUE );
184         add_bool( "dvb-high-voltage", 0, NULL, HIGH_VOLTAGE_TEXT,
185             HIGH_VOLTAGE_LONGTEXT, VLC_TRUE );
186         add_integer( "dvb-tone", -1, NULL, TONE_TEXT, TONE_LONGTEXT,
187             VLC_TRUE );
188 #   endif
189     add_integer( "dvb-lnb-lof1", 0, NULL, LNB_LOF1_TEXT,
190         LNB_LOF1_LONGTEXT, VLC_TRUE );
191     add_integer( "dvb-lnb-lof2", 0, NULL, LNB_LOF2_TEXT,
192         LNB_LOF2_LONGTEXT, VLC_TRUE );
193     add_integer( "dvb-lnb-slof", 0, NULL, LNB_SLOF_TEXT,
194         LNB_SLOF_LONGTEXT, VLC_TRUE );
195
196     add_integer( "dvb-fec", 9, NULL, FEC_TEXT, FEC_LONGTEXT, VLC_TRUE );
197     add_integer( "dvb-srate", 27500000, NULL, SRATE_TEXT, SRATE_LONGTEXT,
198         VLC_FALSE );
199
200     /* DVB-C (cable) */
201     add_integer( "dvb-modulation", 0, NULL, MODULATION_TEXT,
202         MODULATION_LONGTEXT, VLC_TRUE );
203         change_integer_list( i_qam_list, ppsz_qam_text, 0 );
204
205     /* DVB-T (terrestrial) */
206     add_integer( "dvb-code-rate-hp", 9, NULL, CODE_RATE_HP_TEXT,
207         CODE_RATE_HP_LONGTEXT, VLC_TRUE );
208     add_integer( "dvb-code-rate-lp", 9, NULL, CODE_RATE_LP_TEXT,
209         CODE_RATE_LP_LONGTEXT, VLC_TRUE );
210     add_integer( "dvb-bandwidth", 0, NULL, BANDWIDTH_TEXT, BANDWIDTH_LONGTEXT,
211         VLC_TRUE );
212         change_integer_list( i_band_list, ppsz_band_text, 0 );
213     add_integer( "dvb-guard", 0, NULL, GUARD_TEXT, GUARD_LONGTEXT, VLC_TRUE );
214     add_integer( "dvb-transmission", 0, NULL, TRANSMISSION_TEXT,
215         TRANSMISSION_LONGTEXT, VLC_TRUE );
216     add_integer( "dvb-hierarchy", 0, NULL, HIERARCHY_TEXT, HIERARCHY_LONGTEXT,
217         VLC_TRUE );
218
219     set_capability( "access2", 0 );
220     add_shortcut( "dvb" );      /* Generic name */
221
222     add_shortcut( "dvb-s" );    /* Satellite */
223     add_shortcut( "qpsk" );
224     add_shortcut( "satellite" );
225
226     add_shortcut( "dvb-c" );    /* Cable */
227     add_shortcut( "cable" );
228
229     add_shortcut( "dvb-t" );    /* Terrestrial */
230     add_shortcut( "terrestrial" );
231
232     add_shortcut( "atsc" );     /* Atsc */
233     add_shortcut( "usdigital" );
234
235     set_callbacks( Open, Close );
236 vlc_module_end();
237
238
239 /*****************************************************************************
240  * Open: open direct show device as an access module
241  *****************************************************************************/
242 static int Open( vlc_object_t *p_this )
243 {
244     access_t     *p_access = (access_t*)p_this;
245     access_sys_t *p_sys;
246     const char* psz_module  = "dvb";
247     const int   i_param_count = 12;
248     const char* psz_param[] = { "frequency", "bandwidth",
249         "srate", "azimuth", "elevation", "longitude", "polarisation",
250         "modulation", "caching", "lnb-lof1", "lnb-lof2", "lnb-slof" };
251
252     const int   i_type[] = { VLC_VAR_INTEGER, VLC_VAR_INTEGER,
253         VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER,
254         VLC_VAR_STRING, VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER,
255         VLC_VAR_INTEGER, VLC_VAR_INTEGER };
256
257     char  psz_full_name[128];
258     int i_ret;
259
260    /* Only if selected */
261     if( *p_access->psz_access == '\0' )
262         return VLC_EGENERIC;
263
264     /* Setup Access */
265     p_access->pf_read = NULL;
266     p_access->pf_block = Block;     /* Function to read compressed data */
267     p_access->pf_control = Control; /* Function to control the module */
268     p_access->pf_seek = NULL;
269     p_access->info.i_update = 0;
270     p_access->info.i_size = 0;
271     p_access->info.i_pos = 0;
272     p_access->info.b_eof = VLC_FALSE;
273     p_access->info.i_title = 0;
274     p_access->info.i_seekpoint = 0;
275     p_access->p_sys = p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
276     if( !p_sys )
277         return VLC_ENOMEM;
278
279     memset( p_sys, 0, sizeof( access_sys_t ) );
280
281     for( int i = 0; i < i_param_count; i++ )
282     {
283         snprintf( psz_full_name, 128, "%s-%s\0", psz_module,
284                   psz_param[i] );
285         var_Create( p_access, psz_full_name, i_type[i] | VLC_VAR_DOINHERIT );
286     }
287
288     /* Parse the command line */
289     if( ParsePath( p_access, psz_module, i_param_count, psz_param, i_type ) )
290     {
291         free( p_sys );
292         return VLC_EGENERIC;
293     }
294
295     /* Build directshow graph */
296     dvb_newBDAGraph( p_access );
297
298     i_ret = VLC_EGENERIC;
299
300     if( strncmp( p_access->psz_access, "qpsk", 4 ) == 0 ||
301         strncmp( p_access->psz_access, "dvb-s", 5 ) == 0 ||
302         strncmp( p_access->psz_access, "satellite", 9 ) == 0 )
303     {
304         i_ret = dvb_SubmitDVBSTuneRequest( p_access );
305     }
306     if( strncmp( p_access->psz_access, "cable", 5 ) == 0 ||
307         strncmp( p_access->psz_access, "dvb-c", 5 ) == 0 )
308     {
309         i_ret = dvb_SubmitDVBCTuneRequest( p_access );
310     }
311     if( strncmp( p_access->psz_access, "terrestrial", 11 ) == 0 ||
312         strncmp( p_access->psz_access, "dvb-t", 5 ) == 0 )
313     {
314         i_ret = dvb_SubmitDVBTTuneRequest( p_access );
315     }
316     if( strncmp( p_access->psz_access, "usdigital", 9 ) == 0 ||
317         strncmp( p_access->psz_access, "atsc", 4 ) == 0 )
318     {
319         i_ret = dvb_SubmitATSCTuneRequest( p_access );
320     }
321
322     if( i_ret != VLC_SUCCESS )
323         msg_Warn( p_access, "DVB_Open: Unsupported Network %s",
324             p_access->psz_access);
325     return i_ret;
326 }
327
328 /*****************************************************************************
329  * ParsePath:
330  * Parses the path passed to VLC treating it as a MRL which
331  * is organized as a sequence of <key>=<value> pairs separated by a colon
332  * e.g. :key1=value1:key2=value2:key3=value3.
333  * Each <key> is matched to one of the parameters passed in psz_param using
334  * whatever characters are provided. e.g. fr = fre = frequency
335  *****************************************************************************/
336 static int ParsePath( access_t *p_access, const char* psz_module,
337     const int i_param_count, const char** psz_param, const int* i_type )
338 {
339     const int   MAXPARAM = 20;
340     BOOL        b_used[MAXPARAM];
341     char*       psz_parser;
342     char*       psz_token;
343     char*       psz_value;
344     vlc_value_t v_value;
345     int         i_token_len, i_param_len, i_this_param;
346     char        psz_full_name[128];
347
348     if( i_param_count > MAXPARAM )
349     {
350         msg_Warn( p_access, "ParsePath: Too many parameters: %d > %d",
351             i_param_count, MAXPARAM );
352             return VLC_EGENERIC;
353     }
354     for( int i = 0; i < i_param_count; i++ )
355         b_used[i] = FALSE;
356     psz_parser = p_access->psz_path;
357     if( strlen( psz_parser ) <= 0 )
358         return VLC_SUCCESS;
359
360     i_token_len = strcspn( psz_parser, ":" );
361     if( i_token_len <= 0 )
362         i_token_len  = strcspn( ++psz_parser, ":" );
363  
364     do
365     {
366         psz_token = strndup( psz_parser, i_token_len );
367         i_param_len  = strcspn( psz_token, "=" );
368         if( i_param_len <= 0 )
369         {
370             msg_Warn( p_access, "ParsePath: Unspecified parameter %s",
371                 psz_token );
372             if( psz_token )
373                 free( psz_token );
374             return VLC_EGENERIC;
375         }
376         i_this_param = -1;
377         for( int i = 0; i < i_param_count; i++ )
378         {
379             if( strncmp( psz_token, psz_param[i], i_param_len ) == 0 )
380             {
381                 i_this_param = i;
382                 break;
383             }
384         }
385         if( i_this_param < 0 )
386         {
387             msg_Warn( p_access, "ParsePath: Unknown parameter %s", psz_token );
388             if( psz_token )
389                 free( psz_token );
390             return VLC_EGENERIC;
391         }
392         if( b_used[i_this_param] )
393         {
394             msg_Warn( p_access, "ParsePath: Duplicate parameter %s",
395                 psz_token );
396             if( psz_token )
397                 free( psz_token );
398             return VLC_EGENERIC;
399         }
400         b_used[i_this_param] = TRUE;
401
402         /* if "=" was found in token then value starts at 
403          * psz_token + i_paramlen + 1
404          * else there is no value specified so we use an empty string */
405         psz_value = psz_token + i_param_len + 1;
406         if( i_param_len >= i_token_len )
407             psz_value--;
408         if( i_type[i_this_param] == VLC_VAR_STRING )
409              v_value.psz_string = strdup( psz_value );
410         if( i_type[i_this_param] == VLC_VAR_INTEGER )
411              v_value.i_int = atol( psz_value );
412         snprintf( psz_full_name, 128, "%s-%s\0", psz_module,
413             psz_param[i_this_param] );
414         var_Set( p_access, psz_full_name, v_value );
415
416         if( psz_token )
417             free( psz_token );
418         if( i_token_len >= strlen( psz_parser ) )
419             break;
420         psz_parser += i_token_len + 1;
421         i_token_len = strcspn( psz_parser, ":" );
422     }
423     while( TRUE );
424     return VLC_SUCCESS;
425 }
426
427 /*****************************************************************************
428  * AccessClose: close device
429  *****************************************************************************/
430 static void Close( vlc_object_t *p_this )
431 {
432     access_t     *p_access = (access_t *)p_this;
433     access_sys_t *p_sys    = p_access->p_sys;
434
435     dvb_deleteBDAGraph( p_access );
436
437     vlc_mutex_destroy( &p_sys->lock );
438     vlc_cond_destroy( &p_sys->wait );
439
440     free( p_sys );
441 }
442
443 /*****************************************************************************
444  * Control:
445  *****************************************************************************/
446 static int Control( access_t *p_access, int i_query, va_list args )
447 {
448     vlc_bool_t   *pb_bool, b_bool;
449     int          *pi_int, i_int;
450     int64_t      *pi_64;
451
452     switch( i_query )
453     {
454     case ACCESS_CAN_SEEK:           /* 0 */
455     case ACCESS_CAN_FASTSEEK:       /* 1 */
456     case ACCESS_CAN_PAUSE:          /* 2 */
457     case ACCESS_CAN_CONTROL_PACE:   /* 3 */
458         pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
459         *pb_bool = VLC_FALSE;
460         break;
461     case ACCESS_GET_MTU:            /* 4 */
462         pi_int = (int*)va_arg( args, int * );
463         *pi_int = 0;
464         break;
465     case ACCESS_GET_PTS_DELAY:      /* 5 */
466         pi_64 = (int64_t*)va_arg( args, int64_t * );
467         *pi_64 = var_GetInteger( p_access, "dvb-caching" ) * 1000;
468         break;
469         /* */
470     case ACCESS_GET_TITLE_INFO:     /* 6 */
471     case ACCESS_GET_META:           /* 7 */
472     case ACCESS_SET_PAUSE_STATE:    /* 8 */
473     case ACCESS_SET_TITLE:          /* 9 */
474     case ACCESS_SET_SEEKPOINT:      /* 10 */
475         return VLC_EGENERIC;
476
477     case ACCESS_SET_PRIVATE_ID_STATE: /* 11 */
478         i_int  = (int)va_arg( args, int );
479         b_bool = (vlc_bool_t)va_arg( args, vlc_bool_t );
480         break;
481     case ACCESS_SET_PRIVATE_ID_CA:  /* 12 -From Demux */
482         break;
483     default:
484         msg_Warn( p_access,
485                   "DVB_Control: Unimplemented query in control %d", i_query );
486         return VLC_EGENERIC;
487     }
488
489     return VLC_SUCCESS;
490 }
491
492 /*****************************************************************************
493  * Block:
494  *****************************************************************************/
495 static block_t *Block( access_t *p_access )
496 {
497     block_t *p_block;
498     long l_buffer_len;
499
500     if( p_access->b_die )
501         return NULL;
502
503     l_buffer_len = dvb_GetBufferSize( p_access );
504     if( l_buffer_len < 0 )
505     {
506         p_access->info.b_eof = VLC_TRUE;
507         return NULL;
508     }
509
510     p_block = block_New( p_access, l_buffer_len );
511     if( dvb_ReadBuffer( p_access, &l_buffer_len, p_block->p_buffer ) < 0 )
512     {
513         p_access->info.b_eof = VLC_TRUE;
514         return NULL;
515     }
516
517     return p_block;
518 }