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 #if defined(WIN32) || defined(WINCE)
53 # define FREQ_LONGTEXT N_("In kHz for DVB-S or Hz for DVB-C/T")
55 # define FREQ_LONGTEXT N_("In kHz for DVB-C/S/T")
58 #define INVERSION_TEXT N_("Inversion mode")
59 #define INVERSION_LONGTEXT N_("Inversion mode [0=off, 1=on, 2=auto]")
60 static const int i_inversion_list[] = { -1, 0, 1, 2 };
61 static const char *ppsz_inversion_text[] = { N_("Undefined"), N_("Off"),
62 N_("On"), N_("Auto") };
64 #define PROBE_TEXT N_("Probe DVB card for capabilities")
65 #define PROBE_LONGTEXT N_("Some DVB cards do not like to be probed for their " \
66 "capabilities, you can disable this feature if you experience some " \
69 #define BUDGET_TEXT N_("Budget mode")
70 #define BUDGET_LONGTEXT N_("This allows you to stream an entire transponder " \
71 "with a \"budget\" card.")
74 #if defined(WIN32) || defined(WINCE)
75 # define NETID_TEXT N_("Network Identifier")
76 # define NETID_LONGTEXT ""
78 # define SATNO_TEXT N_("Satellite number in the Diseqc system")
79 # define SATNO_LONGTEXT N_("[0=no diseqc, 1-4=satellite number].")
82 #define VOLTAGE_TEXT N_("LNB voltage")
83 #define VOLTAGE_LONGTEXT N_("In Volts [0, 13=vertical, 18=horizontal].")
85 #define HIGH_VOLTAGE_TEXT N_("High LNB voltage")
86 #define HIGH_VOLTAGE_LONGTEXT N_("Enable high voltage if your cables are " \
87 "particularly long. This is not supported by all frontends.")
89 #define TONE_TEXT N_("22 kHz tone")
90 #define TONE_LONGTEXT N_("[0=off, 1=on, -1=auto].")
92 #define FEC_TEXT N_("Transponder FEC")
93 #define FEC_LONGTEXT N_("FEC=Forward Error Correction mode [9=auto].")
95 #define SRATE_TEXT N_("Transponder symbol rate in kHz")
96 #define SRATE_LONGTEXT ""
98 #define LNB_LOF1_TEXT N_("Antenna lnb_lof1 (kHz)")
99 #define LNB_LOF1_LONGTEXT N_("Low Band Local Osc Freq in kHz usually 9.75GHz")
101 #define LNB_LOF2_TEXT N_("Antenna lnb_lof2 (kHz)")
102 #define LNB_LOF2_LONGTEXT N_("High Band Local Osc Freq in kHz usually 10.6GHz")
104 #define LNB_SLOF_TEXT N_("Antenna lnb_slof (kHz)")
105 #define LNB_SLOF_LONGTEXT N_( \
106 "Low Noise Block switch freq in kHz usually 11.7GHz")
109 #define MODULATION_TEXT N_("Modulation type")
110 #define MODULATION_LONGTEXT N_("QAM constellation points " \
111 "[16, 32, 64, 128, 256]")
112 static const int i_qam_list[] = { -1, 16, 32, 64, 128, 256 };
113 static const char *ppsz_qam_text[] = { N_("Undefined"), N_("16"), N_("32"),
114 N_("64"), N_("128"), N_("256") };
117 #define CODE_RATE_HP_TEXT N_("Terrestrial high priority stream code rate (FEC)")
118 #define CODE_RATE_HP_LONGTEXT N_("High Priority FEC Rate " \
119 "[Undefined,1/2,2/3,3/4,5/6,7/8]")
120 static const int i_hp_fec_list[] = { -1, 1, 2, 3, 4, 5 };
121 static const char *ppsz_hp_fec_text[] = { N_("Undefined"), N_("1/2"), N_("2/3"),
122 N_("3/4"), N_("5/6"), N_("7/8") };
124 #define CODE_RATE_LP_TEXT N_("Terrestrial low priority stream code rate (FEC)")
125 #define CODE_RATE_LP_LONGTEXT N_("Low Priority FEC Rate " \
126 "[Undefined,1/2,2/3,3/4,5/6,7/8]")
127 static const int i_lp_fec_list[] = { -1, 1, 2, 3, 4, 5 };
128 static const char *ppsz_lp_fec_text[] = { N_("Undefined"), N_("1/2"), N_("2/3"),
129 N_("3/4"), N_("5/6"), N_("7/8") };
131 #define BANDWIDTH_TEXT N_("Terrestrial bandwidth")
132 #define BANDWIDTH_LONGTEXT N_("Terrestrial bandwidth [0=auto,6,7,8 in MHz]")
133 static const int i_band_list[] = { -1, 6, 7, 8 };
134 static const char *ppsz_band_text[] = { N_("Undefined"), N_("6 MHz"),
135 N_("7 MHz"), N_("8 MHz") };
137 #define GUARD_TEXT N_("Terrestrial guard interval")
138 #define GUARD_LONGTEXT N_("Guard interval [Undefined,1/4,1/8,1/16,1/32]")
139 static const int i_guard_list[] = { -1, 4, 8, 16, 32 };
140 static const char *ppsz_guard_text[] = { N_("Undefined"), N_("1/4"), N_("1/8"),
141 N_("1/16"), N_("1/32") };
143 #define TRANSMISSION_TEXT N_("Terrestrial transmission mode")
144 #define TRANSMISSION_LONGTEXT N_("Transmission mode [Undefined,2k,8k]")
145 static const int i_transmission_list[] = { -1, 2, 8 };
146 static const char *ppsz_transmission_text[] = { N_("Undefined"), N_("2k"),
149 #define HIERARCHY_TEXT N_("Terrestrial hierarchy mode")
150 #define HIERARCHY_LONGTEXT N_("Hierarchy alpha value [Undefined,1,2,4]")
151 static const int i_hierarchy_list[] = { -1, 1, 2, 4 };
152 static const char *ppsz_hierarchy_text[] = { N_("Undefined"), N_("1"),
155 /* BDA module additional DVB-S Parameters */
156 #define AZIMUTH_TEXT N_("Satellite Azimuth")
157 #define AZIMUTH_LONGTEXT N_("Satellite Azimuth in tenths of degree")
158 #define ELEVATION_TEXT N_("Satellite Elevation")
159 #define ELEVATION_LONGTEXT N_("Satellite Elevation in tenths of degree")
160 #define LONGITUDE_TEXT N_("Satellite Longitude")
161 #define LONGITUDE_LONGTEXT N_( \
162 "Satellite Longitude in 10ths of degree, -ve=West")
163 #define POLARISATION_TEXT N_("Satellite Polarisation")
164 #define POLARISATION_LONGTEXT N_("Satellite Polarisation [H/V/L/R]")
165 static const char *ppsz_polar_list[] = { "H", "V", "L", "R" };
166 static const char *ppsz_polar_text[] = { N_("Horizontal"), N_("Vertical"),
167 N_("Circular Left"), N_("Circular Right") };
170 set_shortname( _("DVB") );
171 set_description( _("DirectShow DVB input") );
172 set_category( CAT_INPUT );
173 set_subcategory( SUBCAT_INPUT_ACCESS );
175 add_integer( "dvb-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
176 CACHING_LONGTEXT, VLC_TRUE );
178 add_integer( "dvb-frequency", 11954000, NULL, FREQ_TEXT, FREQ_LONGTEXT,
181 # if defined(WIN32) || defined(WINCE)
183 add_integer( "dvb-adapter", 0, NULL, ADAPTER_TEXT, ADAPTER_LONGTEXT,
186 add_integer( "dvb-device", 0, NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
189 add_bool( "dvb-probe", 1, NULL, PROBE_TEXT, PROBE_LONGTEXT, VLC_TRUE );
191 add_bool( "dvb-budget-mode", 0, NULL, BUDGET_TEXT, BUDGET_LONGTEXT,
196 /* DVB-S (satellite) */
197 add_integer( "dvb-inversion", 2, NULL, INVERSION_TEXT,
198 INVERSION_LONGTEXT, VLC_TRUE );
200 change_integer_list( i_inversion_list, ppsz_inversion_text, 0 );
201 # if defined(WIN32) || defined(WINCE)
202 add_string( "dvb-polarisation", NULL, NULL, POLARISATION_TEXT,
203 POLARISATION_LONGTEXT, VLC_TRUE );
205 change_string_list( ppsz_polar_list, ppsz_polar_text, 0 );
206 add_integer( "dvb-network-id", 0, NULL, NETID_TEXT, NETID_LONGTEXT,
209 add_integer( "dvb-azimuth", 0, NULL, AZIMUTH_TEXT, AZIMUTH_LONGTEXT,
212 add_integer( "dvb-elevation", 0, NULL, ELEVATION_TEXT,
213 ELEVATION_LONGTEXT, VLC_TRUE );
214 add_integer( "dvb-longitude", 0, NULL, LONGITUDE_TEXT,
215 LONGITUDE_LONGTEXT, VLC_TRUE );
217 /* Note: Polaristion H = voltage 18; V = voltage 13; */
219 add_integer( "dvb-satno", 0, NULL, SATNO_TEXT, SATNO_LONGTEXT,
222 add_integer( "dvb-voltage", 13, NULL, VOLTAGE_TEXT, VOLTAGE_LONGTEXT,
225 add_bool( "dvb-high-voltage", 0, NULL, HIGH_VOLTAGE_TEXT,
226 HIGH_VOLTAGE_LONGTEXT, VLC_TRUE );
228 add_integer( "dvb-tone", -1, NULL, TONE_TEXT, TONE_LONGTEXT,
232 add_integer( "dvb-lnb-lof1", 0, NULL, LNB_LOF1_TEXT,
233 LNB_LOF1_LONGTEXT, VLC_TRUE );
235 add_integer( "dvb-lnb-lof2", 0, NULL, LNB_LOF2_TEXT,
236 LNB_LOF2_LONGTEXT, VLC_TRUE );
238 add_integer( "dvb-lnb-slof", 0, NULL, LNB_SLOF_TEXT,
239 LNB_SLOF_LONGTEXT, VLC_TRUE );
242 add_integer( "dvb-fec", 9, NULL, FEC_TEXT, FEC_LONGTEXT, VLC_TRUE );
244 add_integer( "dvb-srate", 27500000, NULL, SRATE_TEXT, SRATE_LONGTEXT,
249 add_integer( "dvb-modulation", -1, NULL, MODULATION_TEXT,
250 MODULATION_LONGTEXT, VLC_TRUE );
252 change_integer_list( i_qam_list, ppsz_qam_text, 0 );
254 /* DVB-T (terrestrial) */
255 add_integer( "dvb-code-rate-hp", -1, NULL, CODE_RATE_HP_TEXT,
256 CODE_RATE_HP_LONGTEXT, VLC_TRUE );
258 change_integer_list( i_hp_fec_list, ppsz_hp_fec_text, 0 );
259 add_integer( "dvb-code-rate-lp", -1, NULL, CODE_RATE_LP_TEXT,
260 CODE_RATE_LP_LONGTEXT, VLC_TRUE );
262 change_integer_list( i_lp_fec_list, ppsz_lp_fec_text, 0 );
263 add_integer( "dvb-bandwidth", 0, NULL, BANDWIDTH_TEXT, BANDWIDTH_LONGTEXT,
266 change_integer_list( i_band_list, ppsz_band_text, 0 );
267 add_integer( "dvb-guard", -1, NULL, GUARD_TEXT, GUARD_LONGTEXT, VLC_TRUE );
269 change_integer_list( i_guard_list, ppsz_guard_text, 0 );
270 add_integer( "dvb-transmission", -1, NULL, TRANSMISSION_TEXT,
271 TRANSMISSION_LONGTEXT, VLC_TRUE );
273 change_integer_list( i_transmission_list, ppsz_transmission_text, 0 );
274 add_integer( "dvb-hierarchy", -1, NULL, HIERARCHY_TEXT, HIERARCHY_LONGTEXT,
277 change_integer_list( i_hierarchy_list, ppsz_hierarchy_text, 0 );
279 set_capability( "access2", 0 );
280 add_shortcut( "dvb" ); /* Generic name */
282 add_shortcut( "dvb-s" ); /* Satellite */
283 add_shortcut( "dvbs" );
284 add_shortcut( "qpsk" );
285 add_shortcut( "satellite" );
287 add_shortcut( "dvb-c" ); /* Cable */
288 add_shortcut( "dvbc" );
289 add_shortcut( "qam" );
290 add_shortcut( "cable" );
292 add_shortcut( "dvbt" ); /* Terrestrial */
293 add_shortcut( "dvb-t" );
294 add_shortcut( "ofdm" );
295 add_shortcut( "terrestrial" );
297 add_shortcut( "atsc" ); /* Atsc */
298 add_shortcut( "usdigital" );
300 set_callbacks( Open, Close );
304 /*****************************************************************************
305 * Open: open direct show device as an access module
306 *****************************************************************************/
307 static int Open( vlc_object_t *p_this )
309 access_t *p_access = (access_t*)p_this;
311 const char* psz_module = "dvb";
312 const int i_param_count = 19;
313 const char* psz_param[] = { "frequency", "bandwidth",
314 "srate", "azimuth", "elevation", "longitude", "polarisation",
315 "modulation", "caching", "lnb-lof1", "lnb-lof2", "lnb-slof",
316 "inversion", "network-id", "code-rate-hp", "code-rate-lp",
317 "guard", "transmission", "hierarchy" };
319 const int i_type[] = { VLC_VAR_INTEGER, VLC_VAR_INTEGER,
320 VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER,
321 VLC_VAR_STRING, VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER,
322 VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER,
323 VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER, VLC_VAR_INTEGER,
326 char psz_full_name[128];
329 /* Only if selected */
330 if( *p_access->psz_access == '\0' )
334 p_access->pf_read = NULL;
335 p_access->pf_block = Block; /* Function to read compressed data */
336 p_access->pf_control = Control; /* Function to control the module */
337 p_access->pf_seek = NULL;
338 p_access->info.i_update = 0;
339 p_access->info.i_size = 0;
340 p_access->info.i_pos = 0;
341 p_access->info.b_eof = VLC_FALSE;
342 p_access->info.i_title = 0;
343 p_access->info.i_seekpoint = 0;
344 p_access->p_sys = p_sys = (access_sys_t *)malloc( sizeof( access_sys_t ) );
348 memset( p_sys, 0, sizeof( access_sys_t ) );
350 for( int i = 0; i < i_param_count; i++ )
352 snprintf( psz_full_name, 128, "%s-%s\0", psz_module,
354 var_Create( p_access, psz_full_name, i_type[i] | VLC_VAR_DOINHERIT );
357 /* Parse the command line */
358 if( ParsePath( p_access, psz_module, i_param_count, psz_param, i_type ) )
364 /* Build directshow graph */
365 dvb_newBDAGraph( p_access );
367 i_ret = VLC_EGENERIC;
369 if( strncmp( p_access->psz_access, "qpsk", 4 ) == 0 ||
370 strncmp( p_access->psz_access, "dvb-s", 5 ) == 0 ||
371 strncmp( p_access->psz_access, "dvbs", 4 ) == 0 ||
372 strncmp( p_access->psz_access, "satellite", 9 ) == 0 )
374 i_ret = dvb_SubmitDVBSTuneRequest( p_access );
376 if( strncmp( p_access->psz_access, "cable", 5 ) == 0 ||
377 strncmp( p_access->psz_access, "dvb-c", 5 ) == 0 ||
378 strncmp( p_access->psz_access, "dvbc", 4 ) == 0 ||
379 strncmp( p_access->psz_access, "qam", 3 ) == 0 )
381 i_ret = dvb_SubmitDVBCTuneRequest( p_access );
383 if( strncmp( p_access->psz_access, "terrestrial", 11 ) == 0 ||
384 strncmp( p_access->psz_access, "dvb-t", 5 ) == 0 ||
385 strncmp( p_access->psz_access, "ofdm", 4 ) == 0 ||
386 strncmp( p_access->psz_access, "dvbt", 4 ) == 0 )
388 i_ret = dvb_SubmitDVBTTuneRequest( p_access );
390 if( strncmp( p_access->psz_access, "usdigital", 9 ) == 0 ||
391 strncmp( p_access->psz_access, "atsc", 4 ) == 0 )
393 i_ret = dvb_SubmitATSCTuneRequest( p_access );
396 if( i_ret != VLC_SUCCESS )
397 msg_Warn( p_access, "DVB_Open: Unsupported Network %s",
398 p_access->psz_access);
402 /*****************************************************************************
404 * Parses the path passed to VLC treating it as a MRL which
405 * is organized as a sequence of <key>=<value> pairs separated by a colon
406 * e.g. :key1=value1:key2=value2:key3=value3.
407 * Each <key> is matched to one of the parameters passed in psz_param using
408 * whatever characters are provided. e.g. fr = fre = frequency
409 *****************************************************************************/
410 static int ParsePath( access_t *p_access, const char* psz_module,
411 const int i_param_count, const char** psz_param, const int* i_type )
413 const int MAXPARAM = 20;
414 BOOL b_used[MAXPARAM];
419 int i_token_len, i_param_len, i_this_param;
420 char psz_full_name[128];
422 if( i_param_count > MAXPARAM )
424 msg_Warn( p_access, "ParsePath: Too many parameters: %d > %d",
425 i_param_count, MAXPARAM );
428 for( int i = 0; i < i_param_count; i++ )
430 psz_parser = p_access->psz_path;
431 if( strlen( psz_parser ) <= 0 )
434 i_token_len = strcspn( psz_parser, ":" );
435 if( i_token_len <= 0 )
436 i_token_len = strcspn( ++psz_parser, ":" );
440 psz_token = strndup( psz_parser, i_token_len );
441 i_param_len = strcspn( psz_token, "=" );
442 if( i_param_len <= 0 )
444 msg_Warn( p_access, "ParsePath: Unspecified parameter %s",
451 for( int i = 0; i < i_param_count; i++ )
453 if( strncmp( psz_token, psz_param[i], i_param_len ) == 0 )
459 if( i_this_param < 0 )
461 msg_Warn( p_access, "ParsePath: Unknown parameter %s", psz_token );
466 if( b_used[i_this_param] )
468 msg_Warn( p_access, "ParsePath: Duplicate parameter %s",
474 b_used[i_this_param] = TRUE;
476 /* if "=" was found in token then value starts at
477 * psz_token + i_paramlen + 1
478 * else there is no value specified so we use an empty string */
479 psz_value = psz_token + i_param_len + 1;
480 if( i_param_len >= i_token_len )
482 if( i_type[i_this_param] == VLC_VAR_STRING )
483 v_value.psz_string = strdup( psz_value );
484 if( i_type[i_this_param] == VLC_VAR_INTEGER )
485 v_value.i_int = atol( psz_value );
486 snprintf( psz_full_name, 128, "%s-%s\0", psz_module,
487 psz_param[i_this_param] );
488 var_Set( p_access, psz_full_name, v_value );
492 if( i_token_len >= strlen( psz_parser ) )
494 psz_parser += i_token_len + 1;
495 i_token_len = strcspn( psz_parser, ":" );
501 /*****************************************************************************
502 * AccessClose: close device
503 *****************************************************************************/
504 static void Close( vlc_object_t *p_this )
506 access_t *p_access = (access_t *)p_this;
507 access_sys_t *p_sys = p_access->p_sys;
509 dvb_deleteBDAGraph( p_access );
511 vlc_mutex_destroy( &p_sys->lock );
512 vlc_cond_destroy( &p_sys->wait );
517 /*****************************************************************************
519 *****************************************************************************/
520 static int Control( access_t *p_access, int i_query, va_list args )
522 vlc_bool_t *pb_bool, b_bool;
528 case ACCESS_CAN_SEEK: /* 0 */
529 case ACCESS_CAN_FASTSEEK: /* 1 */
530 case ACCESS_CAN_PAUSE: /* 2 */
531 case ACCESS_CAN_CONTROL_PACE: /* 3 */
532 pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
533 *pb_bool = VLC_FALSE;
535 case ACCESS_GET_MTU: /* 4 */
536 pi_int = (int*)va_arg( args, int * );
539 case ACCESS_GET_PTS_DELAY: /* 5 */
540 pi_64 = (int64_t*)va_arg( args, int64_t * );
541 *pi_64 = var_GetInteger( p_access, "dvb-caching" ) * 1000;
544 case ACCESS_GET_TITLE_INFO: /* 6 */
545 case ACCESS_GET_META: /* 7 */
546 case ACCESS_SET_PAUSE_STATE: /* 8 */
547 case ACCESS_SET_TITLE: /* 9 */
548 case ACCESS_SET_SEEKPOINT: /* 10 */
549 case ACCESS_GET_CONTENT_TYPE:
552 case ACCESS_SET_PRIVATE_ID_STATE: /* 11 */
553 i_int = (int)va_arg( args, int );
554 b_bool = (vlc_bool_t)va_arg( args, vlc_bool_t );
556 case ACCESS_SET_PRIVATE_ID_CA: /* 12 -From Demux */
560 "DVB_Control: Unimplemented query in control %d", i_query );
567 /*****************************************************************************
569 *****************************************************************************/
570 static block_t *Block( access_t *p_access )
575 if( p_access->b_die )
578 l_buffer_len = dvb_GetBufferSize( p_access );
579 if( l_buffer_len < 0 )
581 p_access->info.b_eof = VLC_TRUE;
585 p_block = block_New( p_access, l_buffer_len );
586 if( dvb_ReadBuffer( p_access, &l_buffer_len, p_block->p_buffer ) < 0 )
588 p_access->info.b_eof = VLC_TRUE;