1 /*****************************************************************************
2 * bda.c : BDA access module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
6 * Author: Ken Self <kens@campoz.fslife.co.uk>
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.
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.
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 *****************************************************************************/
23 /*****************************************************************************
25 *****************************************************************************/
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 );
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." )
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.")
48 #define DEVICE_TEXT N_("Device number to use on adapter")
49 #define DEVICE_LONGTEXT ""
51 #define FREQ_TEXT N_("Transponder/multiplex frequency")
52 #define FREQ_LONGTEXT N_("In kHz for DVB-S or Hz for DVB-C/T")
54 #define INVERSION_TEXT N_("Inversion mode")
55 #define INVERSION_LONGTEXT N_("Inversion mode [0=off, 1=on, 2=auto]")
57 #define PROBE_TEXT N_("Probe DVB card for capabilities")
58 #define PROBE_LONGTEXT N_("Some DVB cards do not like to be probed for their " \
59 "capabilities, you can disable this feature if you experience some " \
62 #define BUDGET_TEXT N_("Budget mode")
63 #define BUDGET_LONGTEXT N_("This allows you to stream an entire transponder " \
64 "with a \"budget\" card.")
67 #define SATNO_TEXT N_("Satellite number in the Diseqc system")
68 #define SATNO_LONGTEXT N_("[0=no diseqc, 1-4=satellite number].")
70 #define VOLTAGE_TEXT N_("LNB voltage")
71 #define VOLTAGE_LONGTEXT N_("In Volts [0, 13=vertical, 18=horizontal].")
73 #define HIGH_VOLTAGE_TEXT N_("High LNB voltage")
74 #define HIGH_VOLTAGE_LONGTEXT N_("Enable high voltage if your cables are " \
75 "particularly long. This is not supported by all frontends.")
77 #define TONE_TEXT N_("22 kHz tone")
78 #define TONE_LONGTEXT N_("[0=off, 1=on, -1=auto].")
80 #define FEC_TEXT N_("Transponder FEC")
81 #define FEC_LONGTEXT N_("FEC=Forward Error Correction mode [9=auto].")
83 #define SRATE_TEXT N_("Transponder symbol rate in kHz")
84 #define SRATE_LONGTEXT ""
86 #define LNB_LOF1_TEXT N_("Antenna lnb_lof1 (kHz)")
87 #define LNB_LOF1_LONGTEXT ""
89 #define LNB_LOF2_TEXT N_("Antenna lnb_lof2 (kHz)")
90 #define LNB_LOF2_LONGTEXT ""
92 #define LNB_SLOF_TEXT N_("Antenna lnb_slof (kHz)")
93 #define LNB_SLOF_LONGTEXT ""
96 #define MODULATION_TEXT N_("Modulation type")
97 #define MODULATION_LONGTEXT N_("QAM constellation points " \
98 "[16, 32, 64, 128, 256]")
99 static const int i_qam_list[] = { -1, 16, 32, 64, 128, 256 };
100 static const char *ppsz_qam_text[] = { N_("Undefined"), N_("16"), N_("32"),
101 N_("64"), N_("128"), N_("256") };
104 #define CODE_RATE_HP_TEXT N_("Terrestrial high priority stream code rate (FEC)")
105 #define CODE_RATE_HP_LONGTEXT ""
107 #define CODE_RATE_LP_TEXT N_("Terrestrial low priority stream code rate (FEC)")
108 #define CODE_RATE_LP_LONGTEXT ""
110 #define BANDWIDTH_TEXT N_("Terrestrial bandwidth")
111 #define BANDWIDTH_LONGTEXT N_("Terrestrial bandwidth [0=auto,6,7,8 in MHz]")
112 static const int i_band_list[] = { -1, 6, 7, 8 };
113 static const char *ppsz_band_text[] = { N_("Undefined"), N_("6"), N_("7"),
116 #define GUARD_TEXT N_("Terrestrial guard interval")
117 #define GUARD_LONGTEXT ""
119 #define TRANSMISSION_TEXT N_("Terrestrial transmission mode")
120 #define TRANSMISSION_LONGTEXT ""
122 #define HIERARCHY_TEXT N_("Terrestrial hierarchy mode")
123 #define HIERARCHY_LONGTEXT ""
125 /* BDA module additional DVB-S Parameters */
126 #define AZIMUTH_TEXT N_("Satellite Azimuth")
127 #define AZIMUTH_LONGTEXT N_("Satellite Azimuth in tenths of degree")
128 #define ELEVATION_TEXT N_("Satellite Elevation")
129 #define ELEVATION_LONGTEXT N_("Satellite Elevation in tenths of degree")
130 #define LONGITUDE_TEXT N_("Satellite Longitude")
131 #define LONGITUDE_LONGTEXT N_( \
132 "Satellite Longitude in 10ths of degree, -ve=West")
133 #define POLARISATION_TEXT N_("Satellite Polarisation")
134 #define POLARISATION_LONGTEXT N_("Satellite Polarisation [H/V/L/R]")
135 static const char *ppsz_polar_list[] = { "H", "V", "L", "R" };
136 static const char *ppsz_polar_text[] = { N_("Horizontal"), N_("Vertical"),
137 N_("Circular Left"), N_("Circular Right") };
140 set_shortname( _("DVB") );
141 set_description( _("DirectShow DVB input") );
142 set_category( CAT_INPUT );
143 set_subcategory( SUBCAT_INPUT_ACCESS );
145 add_integer( "dvb-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
146 CACHING_LONGTEXT, VLC_TRUE );
147 add_integer( "dvb-frequency", 11954000, NULL, FREQ_TEXT, FREQ_LONGTEXT,
149 # if defined(WIN32) || defined(WINCE)
151 add_integer( "dvb-adapter", 0, NULL, ADAPTER_TEXT, ADAPTER_LONGTEXT,
153 add_integer( "dvb-device", 0, NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
155 add_integer( "dvb-inversion", 2, NULL, INVERSION_TEXT,
156 INVERSION_LONGTEXT, VLC_TRUE );
157 add_bool( "dvb-probe", 1, NULL, PROBE_TEXT, PROBE_LONGTEXT, VLC_TRUE );
158 add_bool( "dvb-budget-mode", 0, NULL, BUDGET_TEXT, BUDGET_LONGTEXT,
162 /* DVB-S (satellite) */
163 # if defined(WIN32) || defined(WINCE)
164 add_integer( "dvb-azimuth", 0, NULL, AZIMUTH_TEXT, AZIMUTH_LONGTEXT,
166 add_integer( "dvb-elevation", 0, NULL, ELEVATION_TEXT,
167 ELEVATION_LONGTEXT, VLC_FALSE );
168 add_integer( "dvb-longitude", 0, NULL, LONGITUDE_TEXT,
169 LONGITUDE_LONGTEXT, VLC_FALSE );
170 add_string( "dvb-polarisation", NULL, NULL, POLARISATION_TEXT,
171 POLARISATION_LONGTEXT, VLC_FALSE );
172 change_string_list( ppsz_polar_list, ppsz_polar_text, 0 );
173 /* Note: Polaristion H = voltage 18; V = voltage 13; */
175 add_integer( "dvb-satno", 0, NULL, SATNO_TEXT, SATNO_LONGTEXT,
177 add_integer( "dvb-voltage", 13, NULL, VOLTAGE_TEXT, VOLTAGE_LONGTEXT,
179 add_bool( "dvb-high-voltage", 0, NULL, HIGH_VOLTAGE_TEXT,
180 HIGH_VOLTAGE_LONGTEXT, VLC_TRUE );
181 add_integer( "dvb-tone", -1, NULL, TONE_TEXT, TONE_LONGTEXT,
183 add_integer( "dvb-lnb-lof1", 0, NULL, LNB_LOF1_TEXT,
184 LNB_LOF1_LONGTEXT, VLC_TRUE );
185 add_integer( "dvb-lnb-lof2", 0, NULL, LNB_LOF2_TEXT,
186 LNB_LOF2_LONGTEXT, VLC_TRUE );
187 add_integer( "dvb-lnb-slof", 0, NULL, LNB_SLOF_TEXT,
188 LNB_SLOF_LONGTEXT, VLC_TRUE );
190 add_integer( "dvb-fec", 9, NULL, FEC_TEXT, FEC_LONGTEXT, VLC_TRUE );
191 add_integer( "dvb-srate", 27500000, NULL, SRATE_TEXT, SRATE_LONGTEXT,
195 add_integer( "dvb-modulation", 0, NULL, MODULATION_TEXT,
196 MODULATION_LONGTEXT, VLC_TRUE );
197 change_integer_list( i_qam_list, ppsz_qam_text, 0 );
199 /* DVB-T (terrestrial) */
200 add_integer( "dvb-code-rate-hp", 9, NULL, CODE_RATE_HP_TEXT,
201 CODE_RATE_HP_LONGTEXT, VLC_TRUE );
202 add_integer( "dvb-code-rate-lp", 9, NULL, CODE_RATE_LP_TEXT,
203 CODE_RATE_LP_LONGTEXT, VLC_TRUE );
204 add_integer( "dvb-bandwidth", 0, NULL, BANDWIDTH_TEXT, BANDWIDTH_LONGTEXT,
206 change_integer_list( i_band_list, ppsz_band_text, 0 );
207 add_integer( "dvb-guard", 0, NULL, GUARD_TEXT, GUARD_LONGTEXT, VLC_TRUE );
208 add_integer( "dvb-transmission", 0, NULL, TRANSMISSION_TEXT,
209 TRANSMISSION_LONGTEXT, VLC_TRUE );
210 add_integer( "dvb-hierarchy", 0, NULL, HIERARCHY_TEXT, HIERARCHY_LONGTEXT,
213 set_capability( "access2", 0 );
214 add_shortcut( "dvb" ); /* Generic name */
216 add_shortcut( "dvb-s" ); /* Satellite */
217 add_shortcut( "qpsk" );
218 add_shortcut( "satellite" );
220 add_shortcut( "dvb-c" ); /* Cable */
221 add_shortcut( "cable" );
223 add_shortcut( "dvb-t" ); /* Terrestrial */
224 add_shortcut( "terrestrial" );
226 add_shortcut( "atsc" ); /* Atsc */
227 add_shortcut( "usdigital" );
229 set_callbacks( Open, Close );
233 /*****************************************************************************
234 * Open: open direct show device as an access module
235 *****************************************************************************/
236 static int Open( vlc_object_t *p_this )
238 access_t *p_access = (access_t*)p_this;
240 const char* psz_module = "dvb";
241 const int i_param_count = 9;
242 const char* psz_param[] = { "frequency", "bandwidth",
243 "srate", "azimuth", "elevation", "longitude", "polarisation",
244 "modulation", "caching" };
246 const int i_type[] = { VLC_VAR_INTEGER, VLC_VAR_INTEGER,
247 VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER,
248 VLC_VAR_STRING, VLC_VAR_INTEGER, VLC_VAR_INTEGER };
250 char psz_full_name[128];
253 /* Only if selected */
254 if( *p_access->psz_access == '\0' )
258 p_access->pf_read = NULL;
259 p_access->pf_block = Block; /* Function to read compressed data */
260 p_access->pf_control = Control; /* Function to control the module */
261 p_access->pf_seek = NULL;
262 p_access->info.i_update = 0;
263 p_access->info.i_size = 0;
264 p_access->info.i_pos = 0;
265 p_access->info.b_eof = VLC_FALSE;
266 p_access->info.i_title = 0;
267 p_access->info.i_seekpoint = 0;
268 p_access->p_sys = p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
272 memset( p_sys, 0, sizeof( access_sys_t ) );
274 for( int i = 0; i < i_param_count; i++ )
276 snprintf( psz_full_name, 128, "%s-%s\0", psz_module,
278 var_Create( p_access, psz_full_name, i_type[i] | VLC_VAR_DOINHERIT );
281 /* Parse the command line */
282 if( ParsePath( p_access, psz_module, i_param_count, psz_param, i_type ) )
288 /* Build directshow graph */
289 dvb_newBDAGraph( p_access );
291 i_ret = VLC_EGENERIC;
293 if( strncmp( p_access->psz_access, "qpsk", 4 ) == 0 ||
294 strncmp( p_access->psz_access, "dvb-s", 5 ) == 0 ||
295 strncmp( p_access->psz_access, "satellite", 9 ) == 0 )
297 i_ret = dvb_SubmitDVBSTuneRequest( p_access );
299 if( strncmp( p_access->psz_access, "cable", 5 ) == 0 ||
300 strncmp( p_access->psz_access, "dvb-c", 5 ) == 0 )
302 i_ret = dvb_SubmitDVBCTuneRequest( p_access );
304 if( strncmp( p_access->psz_access, "terrestrial", 11 ) == 0 ||
305 strncmp( p_access->psz_access, "dvb-t", 5 ) == 0 )
307 i_ret = dvb_SubmitDVBTTuneRequest( p_access );
309 if( strncmp( p_access->psz_access, "usdigital", 9 ) == 0 ||
310 strncmp( p_access->psz_access, "atsc", 4 ) == 0 )
312 i_ret = dvb_SubmitATSCTuneRequest( p_access );
315 if( i_ret != VLC_SUCCESS )
316 msg_Warn( p_access, "DVB_Open: Unsupported Network %s",
317 p_access->psz_access);
321 /*****************************************************************************
323 * Parses the path passed to VLC treating it as a MRL which
324 * is organized as a sequence of <key>=<value> pairs separated by a colon
325 * e.g. :key1=value1:key2=value2:key3=value3.
326 * Each <key> is matched to one of the parameters passed in psz_param using
327 * whatever characters are provided. e.g. fr = fre = frequency
328 *****************************************************************************/
329 static int ParsePath( access_t *p_access, const char* psz_module,
330 const int i_param_count, const char** psz_param, const int* i_type )
332 const int MAXPARAM = 20;
333 BOOL b_used[MAXPARAM];
338 int i_token_len, i_param_len, i_this_param;
339 char psz_full_name[128];
341 if( i_param_count > MAXPARAM )
343 msg_Warn( p_access, "ParsePath: Too many parameters: %d > %d",
344 i_param_count, MAXPARAM );
347 for( int i = 0; i < i_param_count; i++ )
349 psz_parser = p_access->psz_path;
350 if( strlen( psz_parser ) <= 0 )
353 i_token_len = strcspn( psz_parser, ":" );
354 if( i_token_len <= 0 )
355 i_token_len = strcspn( ++psz_parser, ":" );
359 psz_token = strndup( psz_parser, i_token_len );
360 i_param_len = strcspn( psz_token, "=" );
361 if( i_param_len <= 0 )
363 msg_Warn( p_access, "ParsePath: Unspecified parameter %s",
370 for( int i = 0; i < i_param_count; i++ )
372 if( strncmp( psz_token, psz_param[i], i_param_len ) == 0 )
378 if( i_this_param < 0 )
380 msg_Warn( p_access, "ParsePath: Unknown parameter %s", psz_token );
385 if( b_used[i_this_param] )
387 msg_Warn( p_access, "ParsePath: Duplicate parameter %s",
393 b_used[i_this_param] = TRUE;
395 /* if "=" was found in token then value starts at
396 * psz_token + i_paramlen + 1
397 * else there is no value specified so we use an empty string */
398 psz_value = psz_token + i_param_len + 1;
399 if( i_param_len >= i_token_len )
401 if( i_type[i_this_param] == VLC_VAR_STRING )
402 v_value.psz_string = strdup( psz_value );
403 if( i_type[i_this_param] == VLC_VAR_INTEGER )
404 v_value.i_int = atol( psz_value );
405 snprintf( psz_full_name, 128, "%s-%s\0", psz_module,
406 psz_param[i_this_param] );
407 var_Set( p_access, psz_full_name, v_value );
411 if( i_token_len >= strlen( psz_parser ) )
413 psz_parser += i_token_len + 1;
414 i_token_len = strcspn( psz_parser, ":" );
420 /*****************************************************************************
421 * AccessClose: close device
422 *****************************************************************************/
423 static void Close( vlc_object_t *p_this )
425 access_t *p_access = (access_t *)p_this;
426 access_sys_t *p_sys = p_access->p_sys;
428 dvb_deleteBDAGraph( p_access );
430 vlc_mutex_destroy( &p_sys->lock );
431 vlc_cond_destroy( &p_sys->wait );
436 /*****************************************************************************
438 *****************************************************************************/
439 static int Control( access_t *p_access, int i_query, va_list args )
441 vlc_bool_t *pb_bool, b_bool;
447 case ACCESS_CAN_SEEK: /* 0 */
448 case ACCESS_CAN_FASTSEEK: /* 1 */
449 case ACCESS_CAN_PAUSE: /* 2 */
450 case ACCESS_CAN_CONTROL_PACE: /* 3 */
451 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
452 *pb_bool = VLC_FALSE;
454 case ACCESS_GET_MTU: /* 4 */
455 pi_int = (int*)va_arg( args, int * );
458 case ACCESS_GET_PTS_DELAY: /* 5 */
459 pi_64 = (int64_t*)va_arg( args, int64_t * );
460 *pi_64 = var_GetInteger( p_access, "dvb-caching" ) * 1000;
463 case ACCESS_GET_TITLE_INFO: /* 6 */
464 case ACCESS_GET_META: /* 7 */
465 case ACCESS_SET_PAUSE_STATE: /* 8 */
466 case ACCESS_SET_TITLE: /* 9 */
467 case ACCESS_SET_SEEKPOINT: /* 10 */
470 case ACCESS_SET_PRIVATE_ID_STATE: /* 11 */
471 i_int = (int)va_arg( args, int );
472 b_bool = (vlc_bool_t)va_arg( args, vlc_bool_t );
474 case ACCESS_SET_PRIVATE_ID_CA: /* 12 -From Demux */
478 "DVB_Control: Unimplemented query in control %d", i_query );
485 /*****************************************************************************
487 *****************************************************************************/
488 static block_t *Block( access_t *p_access )
493 if( p_access->b_die )
496 l_buffer_len = dvb_GetBufferSize( p_access );
497 if( l_buffer_len < 0 )
500 p_block = block_New( p_access, l_buffer_len );
501 if( dvb_ReadBuffer( p_access, &l_buffer_len, p_block->p_buffer ) < 0 )