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 along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 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 )
202 add_integer( "dvb-adapter", 0, NULL, ADAPTER_TEXT, ADAPTER_LONGTEXT,
204 add_integer( "dvb-device", 0, NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
206 add_integer( "dvb-frequency", 0, NULL, FREQ_TEXT, FREQ_LONGTEXT,
208 add_integer( "dvb-inversion", 2, NULL, INVERSION_TEXT, INVERSION_LONGTEXT,
210 add_bool( "dvb-probe", 1, NULL, PROBE_TEXT, PROBE_LONGTEXT, true )
211 add_bool( "dvb-budget-mode", 0, NULL, BUDGET_TEXT, BUDGET_LONGTEXT,
213 /* DVB-S (satellite) */
214 add_integer( "dvb-satno", 0, NULL, SATNO_TEXT, SATNO_LONGTEXT,
216 add_integer( "dvb-voltage", 13, NULL, VOLTAGE_TEXT, VOLTAGE_LONGTEXT,
218 add_bool( "dvb-high-voltage", 0, NULL, HIGH_VOLTAGE_TEXT,
219 HIGH_VOLTAGE_LONGTEXT, true )
220 add_integer( "dvb-tone", -1, NULL, TONE_TEXT, TONE_LONGTEXT,
222 add_integer( "dvb-fec", 9, NULL, FEC_TEXT, FEC_LONGTEXT, true )
223 add_integer( "dvb-srate", 27500000, NULL, SRATE_TEXT, SRATE_LONGTEXT,
225 add_integer( "dvb-lnb-lof1", 0, NULL, LNB_LOF1_TEXT,
226 LNB_LOF1_LONGTEXT, true )
227 add_integer( "dvb-lnb-lof2", 0, NULL, LNB_LOF2_TEXT,
228 LNB_LOF2_LONGTEXT, true )
229 add_integer( "dvb-lnb-slof", 0, NULL, LNB_SLOF_TEXT,
230 LNB_SLOF_LONGTEXT, true )
232 add_integer( "dvb-modulation", 0, NULL, MODULATION_TEXT,
233 MODULATION_LONGTEXT, true )
234 /* DVB-T (terrestrial) */
235 add_integer( "dvb-code-rate-hp", 9, NULL, CODE_RATE_HP_TEXT,
236 CODE_RATE_HP_LONGTEXT, true )
237 add_integer( "dvb-code-rate-lp", 9, NULL, CODE_RATE_LP_TEXT,
238 CODE_RATE_LP_LONGTEXT, true )
239 add_integer( "dvb-bandwidth", 0, NULL, BANDWIDTH_TEXT, BANDWIDTH_LONGTEXT,
241 add_integer( "dvb-guard", 0, NULL, GUARD_TEXT, GUARD_LONGTEXT, true )
242 add_integer( "dvb-transmission", 0, NULL, TRANSMISSION_TEXT,
243 TRANSMISSION_LONGTEXT, true )
244 add_integer( "dvb-hierarchy", 0, NULL, HIERARCHY_TEXT, HIERARCHY_LONGTEXT,
247 /* MMI HTTP interface */
248 set_section( N_("HTTP server" ), 0 )
249 add_string( "dvb-http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT,
251 add_string( "dvb-http-user", NULL, NULL, USER_TEXT, USER_LONGTEXT,
253 add_password( "dvb-http-password", NULL, NULL, PASSWORD_TEXT,
254 PASSWORD_LONGTEXT, true )
255 add_string( "dvb-http-acl", NULL, NULL, ACL_TEXT, ACL_LONGTEXT,
257 add_string( "dvb-http-intf-cert", NULL, NULL, CERT_TEXT, CERT_LONGTEXT,
259 add_string( "dvb-http-intf-key", NULL, NULL, KEY_TEXT, KEY_LONGTEXT,
261 add_string( "dvb-http-intf-ca", NULL, NULL, CA_TEXT, CA_LONGTEXT,
263 add_string( "dvb-http-intf-crl", NULL, NULL, CRL_TEXT, CRL_LONGTEXT,
267 set_capability( "access", 0 )
268 add_shortcut( "dvb" ) /* Generic name */
270 add_shortcut( "dvb-s" ) /* Satellite */
271 add_shortcut( "qpsk" )
272 add_shortcut( "satellite" )
274 add_shortcut( "dvb-c" ) /* Cable */
275 add_shortcut( "cable" )
277 add_shortcut( "dvb-t" ) /* Terrestrial */
278 add_shortcut( "terrestrial" )
280 add_shortcut( "atsc" ) /* Atsc */
281 add_shortcut( "usdigital" )
283 set_callbacks( Open, Close )
288 /*****************************************************************************
290 *****************************************************************************/
291 static block_t *Block( access_t * );
292 static int Control( access_t *, int, va_list );
294 static block_t *BlockScan( access_t * );
296 #define DVB_READ_ONCE 20
297 #define DVB_READ_ONCE_START 2
298 #define DVB_READ_ONCE_SCAN 1
299 #define TS_PACKET_SIZE 188
301 #define DVB_SCAN_MAX_SIGNAL_TIME (300*1000)
302 #define DVB_SCAN_MAX_LOCK_TIME (5000*1000)
303 #define DVB_SCAN_MAX_PROBE_TIME (30000*1000)
305 static void FilterUnset( access_t *, int i_max );
306 static void FilterUnsetPID( access_t *, int i_pid );
307 static void FilterSet( access_t *, int i_pid, int i_type );
309 static void VarInit( access_t * );
310 static int ParseMRL( access_t * );
312 /*****************************************************************************
313 * Open: open the frontend device
314 *****************************************************************************/
315 static int Open( vlc_object_t *p_this )
317 access_t *p_access = (access_t*)p_this;
320 /* Only if selected */
321 if( *p_access->psz_access == '\0' )
325 p_access->pf_read = NULL;
326 p_access->pf_block = Block;
327 p_access->pf_control = Control;
328 p_access->pf_seek = NULL;
330 access_InitFields( p_access );
332 p_access->p_sys = p_sys = calloc( 1, sizeof( access_sys_t ) );
336 /* Create all variables */
339 /* Parse the command line */
340 if( ParseMRL( p_access ) )
346 /* Getting frontend info */
347 if( FrontendOpen( p_access) )
354 p_sys->b_scan_mode = var_GetInteger( p_access, "dvb-frequency" ) == 0;
355 if( p_sys->b_scan_mode )
357 msg_Dbg( p_access, "DVB scan mode selected" );
358 p_access->pf_block = BlockScan;
362 /* Setting frontend parameters for tuning the hardware */
363 msg_Dbg( p_access, "trying to tune the frontend...");
364 if( FrontendSet( p_access ) < 0 )
366 FrontendClose( p_access );
372 /* Opening DVR device */
373 if( DVROpen( p_access ) < 0 )
375 FrontendClose( p_access );
380 if( p_sys->b_scan_mode )
382 scan_parameter_t parameter;
384 msg_Dbg( p_access, "setting filter on PAT/NIT/SDT (DVB only)" );
385 FilterSet( p_access, 0x00, OTHER_TYPE ); // PAT
386 FilterSet( p_access, 0x10, OTHER_TYPE ); // NIT
387 FilterSet( p_access, 0x11, OTHER_TYPE ); // SDT
389 if( FrontendGetScanParameter( p_access, ¶meter ) ||
390 scan_Init( VLC_OBJECT(p_access), &p_sys->scan, ¶meter ) )
392 Close( VLC_OBJECT(p_access) );
398 p_sys->b_budget_mode = var_GetBool( p_access, "dvb-budget-mode" );
399 if( p_sys->b_budget_mode )
401 msg_Dbg( p_access, "setting filter on all PIDs" );
402 FilterSet( p_access, 0x2000, OTHER_TYPE );
406 msg_Dbg( p_access, "setting filter on PAT" );
407 FilterSet( p_access, 0x0, OTHER_TYPE );
413 HTTPOpen( p_access );
417 if( p_sys->b_scan_mode )
418 p_sys->i_read_once = DVB_READ_ONCE_SCAN;
419 else if( p_sys->b_budget_mode )
420 p_sys->i_read_once = DVB_READ_ONCE;
422 p_sys->i_read_once = DVB_READ_ONCE_START;
427 /*****************************************************************************
428 * Close : Close the device
429 *****************************************************************************/
430 static void Close( vlc_object_t *p_this )
432 access_t *p_access = (access_t*)p_this;
433 access_sys_t *p_sys = p_access->p_sys;
435 FilterUnset( p_access, p_sys->b_budget_mode && !p_sys->b_scan_mode ? 1 : MAX_DEMUX );
437 DVRClose( p_access );
438 FrontendClose( p_access );
439 if( p_sys->b_scan_mode )
440 scan_Clean( &p_sys->scan );
442 CAMClose( p_access );
445 if( !p_sys->b_scan_mode )
446 HTTPClose( p_access );
452 /*****************************************************************************
454 *****************************************************************************/
455 static block_t *Block( access_t *p_access )
457 access_sys_t *p_sys = p_access->p_sys;
462 struct pollfd ufds[2];
465 /* Initialize file descriptor sets */
466 memset (ufds, 0, sizeof (ufds));
467 ufds[0].fd = p_sys->i_handle;
468 ufds[0].events = POLLIN;
469 ufds[1].fd = p_sys->i_frontend_handle;
470 ufds[1].events = POLLPRI;
472 /* We'll wait 0.5 second if nothing happens */
473 /* Find if some data is available */
474 i_ret = poll( ufds, 2, 500 );
476 if ( !vlc_object_alive (p_access) )
484 msg_Err( p_access, "poll error: %m" );
488 if ( p_sys->i_ca_handle && mdate() > p_sys->i_ca_next_event )
491 p_sys->i_ca_next_event = mdate() + p_sys->i_ca_timeout;
494 if ( ufds[1].revents )
496 FrontendPoll( p_access );
500 if ( p_sys->i_httpd_timeout && mdate() > p_sys->i_httpd_timeout )
502 vlc_mutex_lock( &p_sys->httpd_mutex );
503 if ( p_sys->b_request_frontend_info )
505 msg_Warn( p_access, "frontend timeout for HTTP interface" );
506 p_sys->b_request_frontend_info = false;
507 p_sys->psz_frontend_info = strdup( "Timeout getting info\n" );
509 if ( p_sys->b_request_mmi_info )
511 msg_Warn( p_access, "MMI timeout for HTTP interface" );
512 p_sys->b_request_mmi_info = false;
513 p_sys->psz_mmi_info = strdup( "Timeout getting info\n" );
515 vlc_cond_signal( &p_sys->httpd_cond );
516 vlc_mutex_unlock( &p_sys->httpd_mutex );
519 if ( p_sys->b_request_frontend_info )
521 FrontendStatus( p_access );
524 if ( p_sys->b_request_mmi_info )
526 CAMStatus( p_access );
530 if ( p_sys->i_frontend_timeout && mdate() > p_sys->i_frontend_timeout )
532 msg_Warn( p_access, "no lock, tuning again" );
533 FrontendSet( p_access );
536 if ( ufds[0].revents )
538 p_block = block_New( p_access,
539 p_sys->i_read_once * TS_PACKET_SIZE );
540 if( ( i_ret = read( p_sys->i_handle, p_block->p_buffer,
541 p_sys->i_read_once * TS_PACKET_SIZE ) ) <= 0 )
543 msg_Warn( p_access, "read failed (%m)" );
544 block_Release( p_block );
547 p_block->i_buffer = i_ret;
552 if( p_sys->i_read_once < DVB_READ_ONCE )
553 p_sys->i_read_once++;
555 /* Update moderatly the signal properties */
556 if( (p_sys->i_stat_counter++ % 100) == 0 )
557 p_access->info.i_update |= INPUT_UPDATE_SIGNAL;
562 /*****************************************************************************
564 *****************************************************************************/
565 static block_t *BlockScan( access_t *p_access )
567 access_sys_t *p_sys = p_access->p_sys;
568 scan_t *p_scan = &p_sys->scan;
569 scan_configuration_t cfg;
570 scan_session_t session;
573 if( scan_Next( p_scan, &cfg ) )
575 const bool b_first_eof = !p_access->info.b_eof;
578 msg_Warn( p_access, "Scanning finished" );
581 p_access->info.b_eof = true;
582 return b_first_eof ? scan_GetM3U( p_scan ) : NULL;
587 if( scan_session_Init( VLC_OBJECT(p_access), &session, &cfg ) )
591 msg_Dbg( p_access, "Scanning frequency %d", cfg.i_frequency );
592 var_SetInteger( p_access, "dvb-frequency", cfg.i_frequency );
593 var_SetInteger( p_access, "dvb-bandwidth", cfg.i_bandwidth );
595 /* Setting frontend parameters for tuning the hardware */
596 if( FrontendSet( p_access ) < 0 )
598 msg_Err( p_access, "Failed to tune the frontend" );
599 p_access->info.b_eof = true;
604 int64_t i_scan_start = mdate();
606 bool b_has_dvb_signal = false;
607 bool b_has_lock = false;
612 struct pollfd ufds[2];
615 /* Initialize file descriptor sets */
616 memset (ufds, 0, sizeof (ufds));
617 ufds[0].fd = p_sys->i_handle;
618 ufds[0].events = POLLIN;
619 ufds[1].fd = p_sys->i_frontend_handle;
620 ufds[1].events = POLLPRI;
622 /* We'll wait 0.1 second if nothing happens */
623 /* Find if some data is available */
624 i_ret = poll( ufds, 2, 100 );
626 if( !vlc_object_alive (p_access) || scan_IsCancelled( p_scan ) )
631 const mtime_t i_scan_time = mdate() - i_scan_start;
632 frontend_status_t status;
634 FrontendGetStatus( p_access, &status );
636 b_has_dvb_signal |= status.b_has_carrier;
637 b_has_lock |= status.b_has_lock;
639 if( ( !b_has_dvb_signal && i_scan_time > DVB_SCAN_MAX_SIGNAL_TIME ) ||
640 ( !b_has_lock && i_scan_time > DVB_SCAN_MAX_LOCK_TIME ) ||
641 ( i_scan_time > DVB_SCAN_MAX_PROBE_TIME ) )
643 msg_Dbg( p_access, "timed out scanning current frequency (s=%d l=%d)", b_has_dvb_signal, b_has_lock );
653 msg_Err( p_access, "poll error: %m" );
654 scan_session_Clean( p_scan, &session );
656 p_access->info.b_eof = true;
660 if( ufds[1].revents )
662 frontend_statistic_t stat;
664 FrontendPoll( p_access );
666 if( !FrontendGetStatistic( p_access, &stat ) )
668 if( stat.i_snr > i_best_snr )
669 i_best_snr = stat.i_snr;
673 if ( p_sys->i_frontend_timeout && mdate() > p_sys->i_frontend_timeout )
675 msg_Warn( p_access, "no lock, tuning again" );
676 FrontendSet( p_access );
679 if ( ufds[0].revents )
681 const int i_read_once = 1;
682 block_t *p_block = block_New( p_access, i_read_once * TS_PACKET_SIZE );
684 if( ( i_ret = read( p_sys->i_handle, p_block->p_buffer,
685 i_read_once * TS_PACKET_SIZE ) ) <= 0 )
687 msg_Warn( p_access, "read failed (%m)" );
688 block_Release( p_block );
691 p_block->i_buffer = i_ret;
694 if( scan_session_Push( &session, p_block ) )
696 msg_Dbg( p_access, "finished scanning current frequency" );
704 scan_service_SetSNR( &session, i_best_snr );
706 scan_session_Clean( p_scan, &session );
710 /*****************************************************************************
712 *****************************************************************************/
713 static int Control( access_t *p_access, int i_query, va_list args )
715 access_sys_t *p_sys = p_access->p_sys;
716 bool *pb_bool, b_bool;
721 frontend_statistic_t stat;
726 case ACCESS_CAN_SEEK:
727 case ACCESS_CAN_FASTSEEK:
728 case ACCESS_CAN_PAUSE:
729 case ACCESS_CAN_CONTROL_PACE:
730 pb_bool = (bool*)va_arg( args, bool* );
734 case ACCESS_GET_PTS_DELAY:
735 pi_64 = (int64_t*)va_arg( args, int64_t * );
736 *pi_64 = (int64_t)var_GetInteger( p_access, "dvb-caching" ) * 1000;
740 case ACCESS_SET_PAUSE_STATE:
741 case ACCESS_GET_TITLE_INFO:
742 case ACCESS_SET_TITLE:
743 case ACCESS_SET_SEEKPOINT:
744 case ACCESS_GET_CONTENT_TYPE:
747 case ACCESS_GET_SIGNAL:
748 pf1 = (double*)va_arg( args, double * );
749 pf2 = (double*)va_arg( args, double * );
752 if( !FrontendGetStatistic( p_access, &stat ) )
754 *pf1 = (double)stat.i_snr / 65535.0;
755 *pf2 = (double)stat.i_signal_strenth / 65535.0;
759 case ACCESS_SET_PRIVATE_ID_STATE:
760 if( p_sys->b_scan_mode )
763 i_int = (int)va_arg( args, int ); /* Private data (pid for now)*/
764 b_bool = (bool)va_arg( args, int ); /* b_selected */
765 if( !p_sys->b_budget_mode )
767 /* FIXME we may want to give the real type (me ?, I don't ;) */
769 FilterSet( p_access, i_int, OTHER_TYPE );
771 FilterUnsetPID( p_access, i_int );
775 case ACCESS_SET_PRIVATE_ID_CA:
776 if( p_sys->b_scan_mode )
779 p_pmt = (dvbpsi_pmt_t *)va_arg( args, dvbpsi_pmt_t * );
781 CAMSet( p_access, p_pmt );
785 msg_Warn( p_access, "unimplemented query in control" );
792 /*****************************************************************************
793 * FilterSet/FilterUnset:
794 *****************************************************************************/
795 static void FilterSet( access_t *p_access, int i_pid, int i_type )
797 access_sys_t *p_sys = p_access->p_sys;
800 /* Find first free slot */
801 for( i = 0; i < MAX_DEMUX; i++ )
803 if( !p_sys->p_demux_handles[i].i_type )
806 if( p_sys->p_demux_handles[i].i_pid == i_pid )
807 return; /* Already set */
812 msg_Err( p_access, "no free p_demux_handles !" );
816 if( DMXSetFilter( p_access, i_pid,
817 &p_sys->p_demux_handles[i].i_handle, i_type ) )
819 msg_Err( p_access, "DMXSetFilter failed" );
822 p_sys->p_demux_handles[i].i_type = i_type;
823 p_sys->p_demux_handles[i].i_pid = i_pid;
825 if( p_sys->i_read_once < DVB_READ_ONCE )
826 p_sys->i_read_once++;
829 static void FilterUnset( access_t *p_access, int i_max )
831 access_sys_t *p_sys = p_access->p_sys;
834 for( i = 0; i < i_max; i++ )
836 if( p_sys->p_demux_handles[i].i_type )
838 DMXUnsetFilter( p_access, p_sys->p_demux_handles[i].i_handle );
839 p_sys->p_demux_handles[i].i_type = 0;
844 static void FilterUnsetPID( access_t *p_access, int i_pid )
846 access_sys_t *p_sys = p_access->p_sys;
849 for( i = 0; i < MAX_DEMUX; i++ )
851 if( p_sys->p_demux_handles[i].i_type &&
852 p_sys->p_demux_handles[i].i_pid == i_pid )
854 DMXUnsetFilter( p_access, p_sys->p_demux_handles[i].i_handle );
855 p_sys->p_demux_handles[i].i_type = 0;
860 /*****************************************************************************
862 *****************************************************************************/
863 static void VarInit( access_t *p_access )
866 var_Create( p_access, "dvb-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
869 var_Create( p_access, "dvb-adapter", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
870 var_Create( p_access, "dvb-device", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
871 var_Create( p_access, "dvb-frequency", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
872 var_Create( p_access, "dvb-inversion", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
873 var_Create( p_access, "dvb-probe", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
874 var_Create( p_access, "dvb-budget-mode", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
877 var_Create( p_access, "dvb-satno", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
878 var_Create( p_access, "dvb-voltage", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
879 var_Create( p_access, "dvb-high-voltage", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
880 var_Create( p_access, "dvb-tone", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
881 var_Create( p_access, "dvb-fec", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
882 var_Create( p_access, "dvb-srate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
883 var_Create( p_access, "dvb-lnb-lof1", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
884 var_Create( p_access, "dvb-lnb-lof2", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
885 var_Create( p_access, "dvb-lnb-slof", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
888 var_Create( p_access, "dvb-modulation", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
891 var_Create( p_access, "dvb-code-rate-hp", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
892 var_Create( p_access, "dvb-code-rate-lp", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
893 var_Create( p_access, "dvb-bandwidth", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
894 var_Create( p_access, "dvb-transmission", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
895 var_Create( p_access, "dvb-guard", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
896 var_Create( p_access, "dvb-hierarchy", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
899 var_Create( p_access, "dvb-http-host", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
900 var_Create( p_access, "dvb-http-user", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
901 var_Create( p_access, "dvb-http-password", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
902 var_Create( p_access, "dvb-http-acl", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
903 var_Create( p_access, "dvb-http-intf-cert", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
904 var_Create( p_access, "dvb-http-intf-key", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
905 var_Create( p_access, "dvb-http-intf-ca", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
906 var_Create( p_access, "dvb-http-intf-crl", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
911 static int ParseMRL( access_t *p_access )
913 char *psz_dup = strdup( p_access->psz_path );
914 char *psz_parser = psz_dup;
918 #define GET_OPTION_INT( option ) \
919 if ( !strncmp( psz_parser, option "=", strlen(option "=") ) ) \
921 val.i_int = strtol( psz_parser + strlen(option "="), &psz_parser, \
923 var_Set( p_access, "dvb-" option, val ); \
926 #define GET_OPTION_BOOL( option ) \
927 if ( !strncmp( psz_parser, option "=", strlen(option "=") ) ) \
929 val.b_bool = strtol( psz_parser + strlen(option "="), &psz_parser, \
931 var_Set( p_access, "dvb-" option, val ); \
934 /* Test for old syntax */
935 strtol( psz_parser, &psz_next, 10 );
936 if( psz_next != psz_parser )
938 msg_Err( p_access, "the DVB input old syntax is deprecated, use vlc "
939 "-p dvb to see an explanation of the new syntax" );
940 dialog_FatalWait( p_access, _("Input syntax is deprecated"), "%s",
941 _("The given syntax is deprecated. Run \"vlc -p dvb\" to see an " \
942 "explanation of the new syntax.") );
949 GET_OPTION_INT("adapter")
950 else GET_OPTION_INT("device")
951 else GET_OPTION_INT("frequency")
952 else GET_OPTION_INT("inversion")
953 else GET_OPTION_BOOL("probe")
954 else GET_OPTION_BOOL("budget-mode")
956 else GET_OPTION_INT("voltage")
957 else GET_OPTION_BOOL("high-voltage")
958 else GET_OPTION_INT("tone")
959 else GET_OPTION_INT("satno")
960 else GET_OPTION_INT("fec")
961 else GET_OPTION_INT("srate")
962 else GET_OPTION_INT("lnb-lof1")
963 else GET_OPTION_INT("lnb-lof2")
964 else GET_OPTION_INT("lnb-slof")
966 else GET_OPTION_INT("modulation")
968 else GET_OPTION_INT("code-rate-hp")
969 else GET_OPTION_INT("code-rate-lp")
970 else GET_OPTION_INT("bandwidth")
971 else GET_OPTION_INT("transmission")
972 else GET_OPTION_INT("guard")
973 else GET_OPTION_INT("hierarchy")
975 /* Redundant with voltage but much easier to use */
976 else if( !strncmp( psz_parser, "polarization=",
977 strlen( "polarization=" ) ) )
979 psz_parser += strlen( "polarization=" );
980 if ( *psz_parser == 'V' || *psz_parser == 'v' )
982 else if ( *psz_parser == 'H' || *psz_parser == 'h' )
986 msg_Err( p_access, "illegal polarization %c", *psz_parser );
987 dialog_Fatal( p_access, _("Invalid polarization"),
988 _("The provided polarization \"%c\" is not valid."),
993 var_Set( p_access, "dvb-voltage", val );
997 msg_Err( p_access, "unknown option (%s)", psz_parser );
1005 #undef GET_OPTION_INT
1006 #undef GET_OPTION_BOOL