1 /*****************************************************************************
2 * access.c: DVB card input v4l2 only
3 *****************************************************************************
4 * Copyright (C) 1998-2005 the VideoLAN team
6 * Authors: Johan Bilien <jobi@via.ecp.fr>
7 * Jean-Paul Saman <jpsaman _at_ videolan _dot_ org>
8 * Christophe Massiot <massiot@via.ecp.fr>
9 * Laurent Aimar <fenrir@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_access.h>
37 #include <vlc_input.h>
38 #include <vlc_interface.h>
39 #include <vlc_dialog.h>
46 #include <sys/types.h>
51 /* Include dvbpsi headers */
52 #ifdef HAVE_DVBPSI_DR_H
53 # include <dvbpsi/dvbpsi.h>
54 # include <dvbpsi/descriptor.h>
55 # include <dvbpsi/pat.h>
56 # include <dvbpsi/pmt.h>
57 # include <dvbpsi/dr.h>
58 # include <dvbpsi/psi.h>
59 # include <dvbpsi/demux.h>
60 # include <dvbpsi/sdt.h>
63 # include "descriptor.h"
64 # include "tables/pat.h"
65 # include "tables/pmt.h"
66 # include "descriptors/dr.h"
69 # include "tables/sdt.h"
73 # include "vlc_httpd.h"
78 /*****************************************************************************
80 *****************************************************************************/
81 static int Open( vlc_object_t *p_this );
82 static void Close( vlc_object_t *p_this );
84 #define CACHING_TEXT N_("Caching value in ms")
85 #define CACHING_LONGTEXT N_( \
86 "Caching value for DVB streams. This " \
87 "value should be set in milliseconds." )
89 #define ADAPTER_TEXT N_("Adapter card to tune")
90 #define ADAPTER_LONGTEXT N_("Adapter cards have a device file in directory named /dev/dvb/adapter[n] with n>=0.")
92 #define DEVICE_TEXT N_("Device number to use on adapter")
93 #define DEVICE_LONGTEXT ""
95 #define FREQ_TEXT N_("Transponder/multiplex frequency")
96 #define FREQ_LONGTEXT N_("In kHz for DVB-S or Hz for DVB-C/T")
98 #define INVERSION_TEXT N_("Inversion mode")
99 #define INVERSION_LONGTEXT N_("Inversion mode [0=off, 1=on, 2=auto]")
101 #define PROBE_TEXT N_("Probe DVB card for capabilities")
102 #define PROBE_LONGTEXT N_("Some DVB cards do not like to be probed for their capabilities, you can disable this feature if you experience some trouble.")
104 #define BUDGET_TEXT N_("Budget mode")
105 #define BUDGET_LONGTEXT N_("This allows you to stream an entire transponder with a \"budget\" card.")
108 #define SATNO_TEXT N_("Satellite number in the Diseqc system")
109 #define SATNO_LONGTEXT N_("[0=no diseqc, 1-4=satellite number].")
111 #define VOLTAGE_TEXT N_("LNB voltage")
112 #define VOLTAGE_LONGTEXT N_("In Volts [0, 13=vertical, 18=horizontal].")
114 #define HIGH_VOLTAGE_TEXT N_("High LNB voltage")
115 #define HIGH_VOLTAGE_LONGTEXT N_("Enable high voltage if your cables are " \
116 "particularly long. This is not supported by all frontends.")
118 #define TONE_TEXT N_("22 kHz tone")
119 #define TONE_LONGTEXT N_("[0=off, 1=on, -1=auto].")
121 #define FEC_TEXT N_("Transponder FEC")
122 #define FEC_LONGTEXT N_("FEC=Forward Error Correction mode [9=auto].")
124 #define SRATE_TEXT N_("Transponder symbol rate in kHz")
125 #define SRATE_LONGTEXT ""
127 #define LNB_LOF1_TEXT N_("Antenna lnb_lof1 (kHz)")
128 #define LNB_LOF1_LONGTEXT ""
130 #define LNB_LOF2_TEXT N_("Antenna lnb_lof2 (kHz)")
131 #define LNB_LOF2_LONGTEXT ""
133 #define LNB_SLOF_TEXT N_("Antenna lnb_slof (kHz)")
134 #define LNB_SLOF_LONGTEXT ""
137 #define MODULATION_TEXT N_("Modulation type")
138 #define MODULATION_LONGTEXT N_("Modulation type for front-end device.")
141 #define CODE_RATE_HP_TEXT N_("Terrestrial high priority stream code rate (FEC)")
142 #define CODE_RATE_HP_LONGTEXT ""
144 #define CODE_RATE_LP_TEXT N_("Terrestrial low priority stream code rate (FEC)")
145 #define CODE_RATE_LP_LONGTEXT ""
147 #define BANDWIDTH_TEXT N_("Terrestrial bandwidth")
148 #define BANDWIDTH_LONGTEXT N_("Terrestrial bandwidth [0=auto,6,7,8 in MHz]")
150 #define GUARD_TEXT N_("Terrestrial guard interval")
151 #define GUARD_LONGTEXT ""
153 #define TRANSMISSION_TEXT N_("Terrestrial transmission mode")
154 #define TRANSMISSION_LONGTEXT ""
156 #define HIERARCHY_TEXT N_("Terrestrial hierarchy mode")
157 #define HIERARCHY_LONGTEXT ""
159 #define HOST_TEXT N_( "HTTP Host address" )
160 #define HOST_LONGTEXT N_( \
161 "To enable the internal HTTP server, set its address and port here." )
163 #define USER_TEXT N_( "HTTP user name" )
164 #define USER_LONGTEXT N_( \
165 "User name the administrator will use to log into " \
166 "the internal HTTP server." )
168 #define PASSWORD_TEXT N_( "HTTP password" )
169 #define PASSWORD_LONGTEXT N_( \
170 "Password the administrator will use to log into " \
171 "the internal HTTP server." )
173 #define ACL_TEXT N_( "HTTP ACL" )
174 #define ACL_LONGTEXT N_( \
175 "Access control list (equivalent to .hosts) file path, " \
176 "which will limit the range of IPs entitled to log into the internal " \
179 #define CERT_TEXT N_( "Certificate file" )
180 #define CERT_LONGTEXT N_( "HTTP interface x509 PEM certificate file " \
183 #define KEY_TEXT N_( "Private key file" )
184 #define KEY_LONGTEXT N_( "HTTP interface x509 PEM private key file" )
186 #define CA_TEXT N_( "Root CA file" )
187 #define CA_LONGTEXT N_( "HTTP interface x509 PEM trusted root CA " \
188 "certificates file" )
190 #define CRL_TEXT N_( "CRL file" )
191 #define CRL_LONGTEXT N_( "HTTP interface Certificates Revocation List file" )
194 set_shortname( N_("DVB") )
195 set_description( N_("DVB input with v4l2 support") )
196 set_category( CAT_INPUT )
197 set_subcategory( SUBCAT_INPUT_ACCESS )
199 add_integer( "dvb-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
200 CACHING_LONGTEXT, true )
201 add_integer( "dvb-adapter", 0, NULL, ADAPTER_TEXT, ADAPTER_LONGTEXT,
203 add_integer( "dvb-device", 0, NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
205 add_integer( "dvb-frequency", 0, NULL, FREQ_TEXT, FREQ_LONGTEXT,
207 add_integer( "dvb-inversion", 2, NULL, INVERSION_TEXT, INVERSION_LONGTEXT,
209 add_bool( "dvb-probe", 1, NULL, PROBE_TEXT, PROBE_LONGTEXT, true )
210 add_bool( "dvb-budget-mode", 0, NULL, BUDGET_TEXT, BUDGET_LONGTEXT,
212 /* DVB-S (satellite) */
213 add_integer( "dvb-satno", 0, NULL, SATNO_TEXT, SATNO_LONGTEXT,
215 add_integer( "dvb-voltage", 13, NULL, VOLTAGE_TEXT, VOLTAGE_LONGTEXT,
217 add_bool( "dvb-high-voltage", 0, NULL, HIGH_VOLTAGE_TEXT,
218 HIGH_VOLTAGE_LONGTEXT, true )
219 add_integer( "dvb-tone", -1, NULL, TONE_TEXT, TONE_LONGTEXT,
221 add_integer( "dvb-fec", 9, NULL, FEC_TEXT, FEC_LONGTEXT, true )
222 add_integer( "dvb-srate", 27500000, NULL, SRATE_TEXT, SRATE_LONGTEXT,
224 add_integer( "dvb-lnb-lof1", 0, NULL, LNB_LOF1_TEXT,
225 LNB_LOF1_LONGTEXT, true )
226 add_integer( "dvb-lnb-lof2", 0, NULL, LNB_LOF2_TEXT,
227 LNB_LOF2_LONGTEXT, true )
228 add_integer( "dvb-lnb-slof", 0, NULL, LNB_SLOF_TEXT,
229 LNB_SLOF_LONGTEXT, true )
231 add_integer( "dvb-modulation", 0, NULL, MODULATION_TEXT,
232 MODULATION_LONGTEXT, true )
233 /* DVB-T (terrestrial) */
234 add_integer( "dvb-code-rate-hp", 9, NULL, CODE_RATE_HP_TEXT,
235 CODE_RATE_HP_LONGTEXT, true )
236 add_integer( "dvb-code-rate-lp", 9, NULL, CODE_RATE_LP_TEXT,
237 CODE_RATE_LP_LONGTEXT, true )
238 add_integer( "dvb-bandwidth", 0, NULL, BANDWIDTH_TEXT, BANDWIDTH_LONGTEXT,
240 add_integer( "dvb-guard", 0, NULL, GUARD_TEXT, GUARD_LONGTEXT, true )
241 add_integer( "dvb-transmission", 0, NULL, TRANSMISSION_TEXT,
242 TRANSMISSION_LONGTEXT, true )
243 add_integer( "dvb-hierarchy", 0, NULL, HIERARCHY_TEXT, HIERARCHY_LONGTEXT,
246 /* MMI HTTP interface */
247 set_section( N_("HTTP server" ), 0 )
248 add_string( "dvb-http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT,
250 add_string( "dvb-http-user", NULL, NULL, USER_TEXT, USER_LONGTEXT,
252 add_string( "dvb-http-password", NULL, NULL, PASSWORD_TEXT,
253 PASSWORD_LONGTEXT, true )
254 add_string( "dvb-http-acl", NULL, NULL, ACL_TEXT, ACL_LONGTEXT,
256 add_string( "dvb-http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT,
258 add_string( "dvb-http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT,
260 add_string( "dvb-http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT,
262 add_string( "dvb-http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT,
266 set_capability( "access", 0 )
267 add_shortcut( "dvb" ) /* Generic name */
269 add_shortcut( "dvb-s" ) /* Satellite */
270 add_shortcut( "qpsk" )
271 add_shortcut( "satellite" )
273 add_shortcut( "dvb-c" ) /* Cable */
274 add_shortcut( "cable" )
276 add_shortcut( "dvb-t" ) /* Terrestrial */
277 add_shortcut( "terrestrial" )
279 add_shortcut( "atsc" ) /* Atsc */
280 add_shortcut( "usdigital" )
282 set_callbacks( Open, Close )
287 /*****************************************************************************
289 *****************************************************************************/
290 static block_t *Block( access_t * );
291 static int Control( access_t *, int, va_list );
293 static block_t *BlockScan( access_t * );
295 #define DVB_READ_ONCE 20
296 #define DVB_READ_ONCE_START 2
297 #define DVB_READ_ONCE_SCAN 1
298 #define TS_PACKET_SIZE 188
300 #define DVB_SCAN_MAX_SIGNAL_TIME (300*1000)
301 #define DVB_SCAN_MAX_LOCK_TIME (5000*1000)
302 #define DVB_SCAN_MAX_PROBE_TIME (30000*1000)
304 static void FilterUnset( access_t *, int i_max );
305 static void FilterUnsetPID( access_t *, int i_pid );
306 static void FilterSet( access_t *, int i_pid, int i_type );
308 static void VarInit( access_t * );
309 static int ParseMRL( access_t * );
311 /*****************************************************************************
312 * Open: open the frontend device
313 *****************************************************************************/
314 static int Open( vlc_object_t *p_this )
316 access_t *p_access = (access_t*)p_this;
319 /* Only if selected */
320 if( *p_access->psz_access == '\0' )
324 p_access->pf_read = NULL;
325 p_access->pf_block = Block;
326 p_access->pf_control = Control;
327 p_access->pf_seek = NULL;
329 access_InitFields( p_access );
331 p_access->p_sys = p_sys = calloc( 1, sizeof( access_sys_t ) );
335 /* Create all variables */
338 /* Parse the command line */
339 if( ParseMRL( p_access ) )
345 /* Getting frontend info */
346 if( FrontendOpen( p_access) )
353 p_sys->b_scan_mode = var_GetInteger( p_access, "dvb-frequency" ) == 0;
354 if( p_sys->b_scan_mode )
356 msg_Dbg( p_access, "DVB scan mode selected" );
357 p_access->pf_block = BlockScan;
361 /* Setting frontend parameters for tuning the hardware */
362 msg_Dbg( p_access, "trying to tune the frontend...");
363 if( FrontendSet( p_access ) < 0 )
365 FrontendClose( p_access );
371 /* Opening DVR device */
372 if( DVROpen( p_access ) < 0 )
374 FrontendClose( p_access );
379 if( p_sys->b_scan_mode )
381 scan_parameter_t parameter;
383 msg_Dbg( p_access, "setting filter on PAT/NIT/SDT (DVB only)" );
384 FilterSet( p_access, 0x00, OTHER_TYPE ); // PAT
385 FilterSet( p_access, 0x10, OTHER_TYPE ); // NIT
386 FilterSet( p_access, 0x11, OTHER_TYPE ); // SDT
388 if( FrontendGetScanParameter( p_access, ¶meter ) ||
389 scan_Init( VLC_OBJECT(p_access), &p_sys->scan, ¶meter ) )
391 Close( VLC_OBJECT(p_access) );
397 p_sys->b_budget_mode = var_GetBool( p_access, "dvb-budget-mode" );
398 if( p_sys->b_budget_mode )
400 msg_Dbg( p_access, "setting filter on all PIDs" );
401 FilterSet( p_access, 0x2000, OTHER_TYPE );
405 msg_Dbg( p_access, "setting filter on PAT" );
406 FilterSet( p_access, 0x0, OTHER_TYPE );
412 HTTPOpen( p_access );
416 if( p_sys->b_scan_mode )
417 p_sys->i_read_once = DVB_READ_ONCE_SCAN;
418 else if( p_sys->b_budget_mode )
419 p_sys->i_read_once = DVB_READ_ONCE;
421 p_sys->i_read_once = DVB_READ_ONCE_START;
426 /*****************************************************************************
427 * Close : Close the device
428 *****************************************************************************/
429 static void Close( vlc_object_t *p_this )
431 access_t *p_access = (access_t*)p_this;
432 access_sys_t *p_sys = p_access->p_sys;
434 FilterUnset( p_access, p_sys->b_budget_mode && !p_sys->b_scan_mode ? 1 : MAX_DEMUX );
436 DVRClose( p_access );
437 FrontendClose( p_access );
438 if( p_sys->b_scan_mode )
439 scan_Clean( &p_sys->scan );
441 CAMClose( p_access );
444 if( !p_sys->b_scan_mode )
445 HTTPClose( p_access );
451 /*****************************************************************************
453 *****************************************************************************/
454 static block_t *Block( access_t *p_access )
456 access_sys_t *p_sys = p_access->p_sys;
461 struct pollfd ufds[2];
464 /* Initialize file descriptor sets */
465 memset (ufds, 0, sizeof (ufds));
466 ufds[0].fd = p_sys->i_handle;
467 ufds[0].events = POLLIN;
468 ufds[1].fd = p_sys->i_frontend_handle;
469 ufds[1].events = POLLPRI;
471 /* We'll wait 0.5 second if nothing happens */
472 /* Find if some data is available */
473 i_ret = poll( ufds, 2, 500 );
475 if ( !vlc_object_alive (p_access) )
483 msg_Err( p_access, "poll error: %m" );
487 if ( p_sys->i_ca_handle && mdate() > p_sys->i_ca_next_event )
490 p_sys->i_ca_next_event = mdate() + p_sys->i_ca_timeout;
493 if ( ufds[1].revents )
495 FrontendPoll( p_access );
499 if ( p_sys->i_httpd_timeout && mdate() > p_sys->i_httpd_timeout )
501 vlc_mutex_lock( &p_sys->httpd_mutex );
502 if ( p_sys->b_request_frontend_info )
504 msg_Warn( p_access, "frontend timeout for HTTP interface" );
505 p_sys->b_request_frontend_info = false;
506 p_sys->psz_frontend_info = strdup( "Timeout getting info\n" );
508 if ( p_sys->b_request_mmi_info )
510 msg_Warn( p_access, "MMI timeout for HTTP interface" );
511 p_sys->b_request_mmi_info = false;
512 p_sys->psz_mmi_info = strdup( "Timeout getting info\n" );
514 vlc_cond_signal( &p_sys->httpd_cond );
515 vlc_mutex_unlock( &p_sys->httpd_mutex );
518 if ( p_sys->b_request_frontend_info )
520 FrontendStatus( p_access );
523 if ( p_sys->b_request_mmi_info )
525 CAMStatus( p_access );
529 if ( p_sys->i_frontend_timeout && mdate() > p_sys->i_frontend_timeout )
531 msg_Warn( p_access, "no lock, tuning again" );
532 FrontendSet( p_access );
535 if ( ufds[0].revents )
537 p_block = block_New( p_access,
538 p_sys->i_read_once * TS_PACKET_SIZE );
539 if( ( i_ret = read( p_sys->i_handle, p_block->p_buffer,
540 p_sys->i_read_once * TS_PACKET_SIZE ) ) <= 0 )
542 msg_Warn( p_access, "read failed (%m)" );
543 block_Release( p_block );
546 p_block->i_buffer = i_ret;
551 if( p_sys->i_read_once < DVB_READ_ONCE )
552 p_sys->i_read_once++;
554 /* Update moderatly the signal properties */
555 if( (p_sys->i_stat_counter++ % 100) == 0 )
556 p_access->info.i_update |= INPUT_UPDATE_SIGNAL;
561 /*****************************************************************************
563 *****************************************************************************/
564 static block_t *BlockScan( access_t *p_access )
566 access_sys_t *p_sys = p_access->p_sys;
567 scan_t *p_scan = &p_sys->scan;
568 scan_configuration_t cfg;
569 scan_session_t session;
572 if( scan_Next( p_scan, &cfg ) )
574 const bool b_first_eof = !p_access->info.b_eof;
577 msg_Warn( p_access, "Scanning finished" );
580 p_access->info.b_eof = true;
581 return b_first_eof ? scan_GetM3U( p_scan ) : NULL;
586 if( scan_session_Init( VLC_OBJECT(p_access), &session, &cfg ) )
590 msg_Dbg( p_access, "Scanning frequency %d", cfg.i_frequency );
591 var_SetInteger( p_access, "dvb-frequency", cfg.i_frequency );
592 var_SetInteger( p_access, "dvb-bandwidth", cfg.i_bandwidth );
594 /* Setting frontend parameters for tuning the hardware */
595 if( FrontendSet( p_access ) < 0 )
597 msg_Err( p_access, "Failed to tune the frontend" );
598 p_access->info.b_eof = true;
603 int64_t i_scan_start = mdate();
605 bool b_has_dvb_signal = false;
606 bool b_has_lock = false;
611 struct pollfd ufds[2];
614 /* Initialize file descriptor sets */
615 memset (ufds, 0, sizeof (ufds));
616 ufds[0].fd = p_sys->i_handle;
617 ufds[0].events = POLLIN;
618 ufds[1].fd = p_sys->i_frontend_handle;
619 ufds[1].events = POLLPRI;
621 /* We'll wait 0.1 second if nothing happens */
622 /* Find if some data is available */
623 i_ret = poll( ufds, 2, 100 );
625 if( !vlc_object_alive (p_access) || scan_IsCancelled( p_scan ) )
630 const mtime_t i_scan_time = mdate() - i_scan_start;
631 frontend_status_t status;
633 FrontendGetStatus( p_access, &status );
635 b_has_dvb_signal |= status.b_has_carrier;
636 b_has_lock |= status.b_has_lock;
638 if( ( !b_has_dvb_signal && i_scan_time > DVB_SCAN_MAX_SIGNAL_TIME ) ||
639 ( !b_has_lock && i_scan_time > DVB_SCAN_MAX_LOCK_TIME ) ||
640 ( i_scan_time > DVB_SCAN_MAX_PROBE_TIME ) )
642 msg_Dbg( p_access, "timed out scanning current frequency (s=%d l=%d)", b_has_dvb_signal, b_has_lock );
652 msg_Err( p_access, "poll error: %m" );
653 scan_session_Clean( p_scan, &session );
655 p_access->info.b_eof = true;
659 if( ufds[1].revents )
661 frontend_statistic_t stat;
663 FrontendPoll( p_access );
665 if( !FrontendGetStatistic( p_access, &stat ) )
667 if( stat.i_snr > i_best_snr )
668 i_best_snr = stat.i_snr;
672 if ( p_sys->i_frontend_timeout && mdate() > p_sys->i_frontend_timeout )
674 msg_Warn( p_access, "no lock, tuning again" );
675 FrontendSet( p_access );
678 if ( ufds[0].revents )
680 const int i_read_once = 1;
681 block_t *p_block = block_New( p_access, i_read_once * TS_PACKET_SIZE );
683 if( ( i_ret = read( p_sys->i_handle, p_block->p_buffer,
684 i_read_once * TS_PACKET_SIZE ) ) <= 0 )
686 msg_Warn( p_access, "read failed (%m)" );
687 block_Release( p_block );
690 p_block->i_buffer = i_ret;
693 if( scan_session_Push( &session, p_block ) )
695 msg_Dbg( p_access, "finished scanning current frequency" );
703 scan_service_SetSNR( &session, i_best_snr );
705 scan_session_Clean( p_scan, &session );
709 /*****************************************************************************
711 *****************************************************************************/
712 static int Control( access_t *p_access, int i_query, va_list args )
714 access_sys_t *p_sys = p_access->p_sys;
715 bool *pb_bool, b_bool;
720 frontend_statistic_t stat;
725 case ACCESS_CAN_SEEK:
726 case ACCESS_CAN_FASTSEEK:
727 case ACCESS_CAN_PAUSE:
728 case ACCESS_CAN_CONTROL_PACE:
729 pb_bool = (bool*)va_arg( args, bool* );
733 case ACCESS_GET_PTS_DELAY:
734 pi_64 = (int64_t*)va_arg( args, int64_t * );
735 *pi_64 = var_GetInteger( p_access, "dvb-caching" ) * 1000;
739 case ACCESS_SET_PAUSE_STATE:
740 case ACCESS_GET_TITLE_INFO:
741 case ACCESS_SET_TITLE:
742 case ACCESS_SET_SEEKPOINT:
743 case ACCESS_GET_CONTENT_TYPE:
746 case ACCESS_GET_SIGNAL:
747 pf1 = (double*)va_arg( args, double * );
748 pf2 = (double*)va_arg( args, double * );
751 if( !FrontendGetStatistic( p_access, &stat ) )
753 *pf1 = (double)stat.i_snr / 65535.0;
754 *pf2 = (double)stat.i_signal_strenth / 65535.0;
758 case ACCESS_SET_PRIVATE_ID_STATE:
759 if( p_sys->b_scan_mode )
762 i_int = (int)va_arg( args, int ); /* Private data (pid for now)*/
763 b_bool = (bool)va_arg( args, int ); /* b_selected */
764 if( !p_sys->b_budget_mode )
766 /* FIXME we may want to give the real type (me ?, I don't ;) */
768 FilterSet( p_access, i_int, OTHER_TYPE );
770 FilterUnsetPID( p_access, i_int );
774 case ACCESS_SET_PRIVATE_ID_CA:
775 if( p_sys->b_scan_mode )
778 p_pmt = (dvbpsi_pmt_t *)va_arg( args, dvbpsi_pmt_t * );
780 CAMSet( p_access, p_pmt );
784 msg_Warn( p_access, "unimplemented query in control" );
791 /*****************************************************************************
792 * FilterSet/FilterUnset:
793 *****************************************************************************/
794 static void FilterSet( access_t *p_access, int i_pid, int i_type )
796 access_sys_t *p_sys = p_access->p_sys;
799 /* Find first free slot */
800 for( i = 0; i < MAX_DEMUX; i++ )
802 if( !p_sys->p_demux_handles[i].i_type )
805 if( p_sys->p_demux_handles[i].i_pid == i_pid )
806 return; /* Already set */
811 msg_Err( p_access, "no free p_demux_handles !" );
815 if( DMXSetFilter( p_access, i_pid,
816 &p_sys->p_demux_handles[i].i_handle, i_type ) )
818 msg_Err( p_access, "DMXSetFilter failed" );
821 p_sys->p_demux_handles[i].i_type = i_type;
822 p_sys->p_demux_handles[i].i_pid = i_pid;
824 if( p_sys->i_read_once < DVB_READ_ONCE )
825 p_sys->i_read_once++;
828 static void FilterUnset( access_t *p_access, int i_max )
830 access_sys_t *p_sys = p_access->p_sys;
833 for( i = 0; i < i_max; i++ )
835 if( p_sys->p_demux_handles[i].i_type )
837 DMXUnsetFilter( p_access, p_sys->p_demux_handles[i].i_handle );
838 p_sys->p_demux_handles[i].i_type = 0;
843 static void FilterUnsetPID( access_t *p_access, int i_pid )
845 access_sys_t *p_sys = p_access->p_sys;
848 for( i = 0; i < MAX_DEMUX; i++ )
850 if( p_sys->p_demux_handles[i].i_type &&
851 p_sys->p_demux_handles[i].i_pid == i_pid )
853 DMXUnsetFilter( p_access, p_sys->p_demux_handles[i].i_handle );
854 p_sys->p_demux_handles[i].i_type = 0;
859 /*****************************************************************************
861 *****************************************************************************/
862 static void VarInit( access_t *p_access )
865 var_Create( p_access, "dvb-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
868 var_Create( p_access, "dvb-adapter", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
869 var_Create( p_access, "dvb-device", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
870 var_Create( p_access, "dvb-frequency", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
871 var_Create( p_access, "dvb-inversion", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
872 var_Create( p_access, "dvb-probe", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
873 var_Create( p_access, "dvb-budget-mode", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
876 var_Create( p_access, "dvb-satno", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
877 var_Create( p_access, "dvb-voltage", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
878 var_Create( p_access, "dvb-high-voltage", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
879 var_Create( p_access, "dvb-tone", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
880 var_Create( p_access, "dvb-fec", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
881 var_Create( p_access, "dvb-srate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
882 var_Create( p_access, "dvb-lnb-lof1", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
883 var_Create( p_access, "dvb-lnb-lof2", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
884 var_Create( p_access, "dvb-lnb-slof", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
887 var_Create( p_access, "dvb-modulation", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
890 var_Create( p_access, "dvb-code-rate-hp", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
891 var_Create( p_access, "dvb-code-rate-lp", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
892 var_Create( p_access, "dvb-bandwidth", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
893 var_Create( p_access, "dvb-transmission", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
894 var_Create( p_access, "dvb-guard", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
895 var_Create( p_access, "dvb-hierarchy", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
898 var_Create( p_access, "dvb-http-host", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
899 var_Create( p_access, "dvb-http-user", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
900 var_Create( p_access, "dvb-http-password", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
901 var_Create( p_access, "dvb-http-acl", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
902 var_Create( p_access, "dvb-http-intf-cert", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
903 var_Create( p_access, "dvb-http-intf-key", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
904 var_Create( p_access, "dvb-http-intf-ca", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
905 var_Create( p_access, "dvb-http-intf-crl", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
910 static int ParseMRL( access_t *p_access )
912 char *psz_dup = strdup( p_access->psz_path );
913 char *psz_parser = psz_dup;
917 #define GET_OPTION_INT( option ) \
918 if ( !strncmp( psz_parser, option "=", strlen(option "=") ) ) \
920 val.i_int = strtol( psz_parser + strlen(option "="), &psz_parser, \
922 var_Set( p_access, "dvb-" option, val ); \
925 #define GET_OPTION_BOOL( option ) \
926 if ( !strncmp( psz_parser, option "=", strlen(option "=") ) ) \
928 val.b_bool = strtol( psz_parser + strlen(option "="), &psz_parser, \
930 var_Set( p_access, "dvb-" option, val ); \
933 /* Test for old syntax */
934 strtol( psz_parser, &psz_next, 10 );
935 if( psz_next != psz_parser )
937 msg_Err( p_access, "the DVB input old syntax is deprecated, use vlc "
938 "-p dvb to see an explanation of the new syntax" );
939 dialog_FatalWait( p_access, _("Input syntax is deprecated"),
940 _("The given syntax is deprecated. Run \"vlc -p dvb\" to see an " \
941 "explanation of the new syntax.") );
948 GET_OPTION_INT("adapter")
949 else GET_OPTION_INT("device")
950 else GET_OPTION_INT("frequency")
951 else GET_OPTION_INT("inversion")
952 else GET_OPTION_BOOL("probe")
953 else GET_OPTION_BOOL("budget-mode")
955 else GET_OPTION_INT("voltage")
956 else GET_OPTION_BOOL("high-voltage")
957 else GET_OPTION_INT("tone")
958 else GET_OPTION_INT("satno")
959 else GET_OPTION_INT("fec")
960 else GET_OPTION_INT("srate")
961 else GET_OPTION_INT("lnb-lof1")
962 else GET_OPTION_INT("lnb-lof2")
963 else GET_OPTION_INT("lnb-slof")
965 else GET_OPTION_INT("modulation")
967 else GET_OPTION_INT("code-rate-hp")
968 else GET_OPTION_INT("code-rate-lp")
969 else GET_OPTION_INT("bandwidth")
970 else GET_OPTION_INT("transmission")
971 else GET_OPTION_INT("guard")
972 else GET_OPTION_INT("hierarchy")
974 /* Redundant with voltage but much easier to use */
975 else if( !strncmp( psz_parser, "polarization=",
976 strlen( "polarization=" ) ) )
978 psz_parser += strlen( "polarization=" );
979 if ( *psz_parser == 'V' || *psz_parser == 'v' )
981 else if ( *psz_parser == 'H' || *psz_parser == 'h' )
985 msg_Err( p_access, "illegal polarization %c", *psz_parser );
986 dialog_Fatal( p_access, _("Invalid polarization"),
987 _("The provided polarization \"%c\" is not valid."),
992 var_Set( p_access, "dvb-voltage", val );
996 msg_Err( p_access, "unknown option (%s)", psz_parser );
1004 #undef GET_OPTION_INT
1005 #undef GET_OPTION_BOOL