]> git.sesse.net Git - vlc/blobdiff - modules/access/dvb/access.c
* all: ooops wrong order for ACCESS_SET_PRIVATE_ID...
[vlc] / modules / access / dvb / access.c
index ebda11b7bc9ea5ecdbcc1651cdad8587373aef80..2088d664eb1fbe40c8968e696748e5b8a77b0fbc 100644 (file)
@@ -1,10 +1,12 @@
 /*****************************************************************************
  * access.c: DVB card input v4l2 only
  *****************************************************************************
- * Copyright (C) 1998-2003 VideoLAN
+ * Copyright (C) 1998-2004 VideoLAN
  *
  * Authors: Johan Bilien <jobi@via.ecp.fr>
- *          Jean-Paul Saman <saman@natlab.research.philips.com>
+ *          Jean-Paul Saman <jpsaman@wxs.nl>
+ *          Christophe Massiot <massiot@via.ecp.fr>
+ *          Laurent Aimar <fenrir@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdio.h>
-#include <stdlib.h>
-
 #include <vlc/vlc.h>
 #include <vlc/input.h>
 
-#include "../../demux/mpeg/system.h"
-
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
 #include <fcntl.h>
 #include <sys/types.h>
 
-#ifdef HAVE_ERRNO_H
-#    include <string.h>
-#    include <errno.h>
-#endif
+#include <errno.h>
 
-#ifdef STRNCASECMP_IN_STRINGS_H
-#   include <strings.h>
-#endif
+#include "dvb.h"
 
-/* DVB Card Drivers */
-#include <linux/dvb/dmx.h>
-#include <linux/dvb/frontend.h>
+/*****************************************************************************
+ * Module descriptor
+ *****************************************************************************/
+static int  Open( vlc_object_t *p_this );
+static void Close( vlc_object_t *p_this );
 
-#include "dvb.h"
+#define CACHING_TEXT N_("Caching value in ms")
+#define CACHING_LONGTEXT N_( \
+    "Allows you to modify the default caching value for dvb streams. This " \
+    "value should be set in millisecond units." )
+
+#define PROGRAM_TEXT N_("Program to decode")
+#define PROGRAM_LONGTEXT N_("This is a workaround for a bug in the input")
+
+#define ADAPTER_TEXT N_("Adapter card to tune")
+#define ADAPTER_LONGTEXT N_("Adapter cards have a device file in directory named /dev/dvb/adapter[n] with n>=0.")
+
+#define DEVICE_TEXT N_("Device number to use on adapter")
+#define DEVICE_LONGTEXT ""
+
+#define FREQ_TEXT N_("Transponder/multiplex frequency")
+#define FREQ_LONGTEXT N_("In kHz for DVB-S or Hz for DVB-C/T")
+
+#define INVERSION_TEXT N_("Inversion mode")
+#define INVERSION_LONGTEXT N_("Inversion mode [0=off, 1=on, 2=auto]")
+
+#define PROBE_TEXT N_("Probe DVB card for capabilities")
+#define PROBE_LONGTEXT N_("Some DVB cards do not like to be probed for their capabilities.")
+
+#define LNB_LOF1_TEXT N_("Antenna lnb_lof1 (kHz)")
+#define LNB_LOF1_LONGTEXT ""
+
+#define LNB_LOF2_TEXT N_("Antenna lnb_lof2 (kHz)")
+#define LNB_LOF2_LONGTEXT ""
+
+#define LNB_SLOF_TEXT N_("Antenna lnb_slof (kHz)")
+#define LNB_SLOF_LONGTEXT ""
+
+/* Satellite */
+#define BUDGET_TEXT N_("Budget mode")
+#define BUDGET_LONGTEXT N_("This allows you to stream an entire transponder with a budget card.")
+
+#define SATNO_TEXT N_("Satellite number in the Diseqc system")
+#define SATNO_LONGTEXT N_("[0=no diseqc, 1-4=normal diseqc, -1=A, -2=B simple diseqc]")
+
+#define VOLTAGE_TEXT N_("LNB voltage")
+#define VOLTAGE_LONGTEXT N_("In Volts [0, 13=vertical, 18=horizontal]")
+
+#define TONE_TEXT N_("22 kHz tone")
+#define TONE_LONGTEXT N_("[0=off, 1=on, -1=auto]")
+
+#define FEC_TEXT N_("Transponder FEC")
+#define FEC_LONGTEXT N_("FEC=Forward Error Correction mode [9=auto]")
+
+#define SRATE_TEXT N_("Transponder symbol rate in kHz")
+#define SRATE_LONGTEXT ""
+
+/* Cable */
+#define MODULATION_TEXT N_("Modulation type")
+#define MODULATION_LONGTEXT N_("Modulation type for front-end device.")
+
+/* Terrestrial */
+#define CODE_RATE_HP_TEXT N_("Terrestrial high priority stream code rate (FEC)")
+#define CODE_RATE_HP_LONGTEXT ""
+
+#define CODE_RATE_LP_TEXT N_("Terrestrial low priority stream code rate (FEC)")
+#define CODE_RATE_LP_LONGTEXT ""
+
+#define BANDWIDTH_TEXT N_("Terrestrial bandwidth")
+#define BANDWIDTH_LONGTEXT N_("Terrestrial bandwidth [0=auto,6,7,8 in MHz]")
+
+#define GUARD_TEXT N_("Terrestrial guard interval")
+#define GUARD_LONGTEXT ""
+
+#define TRANSMISSION_TEXT N_("Terrestrial transmission mode")
+#define TRANSMISSION_LONGTEXT ""
+
+#define HIERARCHY_TEXT N_("Terrestrial hierarchy mode")
+#define HIERARCHY_LONGTEXT ""
+
+vlc_module_begin();
+    set_shortname( _("DVB") );
+    set_description( N_("DVB input with v4l2 support") );
+
+    add_integer( "dvb-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT,
+                 CACHING_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-adapter", 0, NULL, ADAPTER_TEXT, ADAPTER_LONGTEXT,
+                 VLC_FALSE );
+    add_integer( "dvb-device", 0, NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "dvb-frequency", 11954000, NULL, FREQ_TEXT, FREQ_LONGTEXT,
+                 VLC_FALSE );
+    add_integer( "dvb-inversion", 2, NULL, INVERSION_TEXT, INVERSION_LONGTEXT,
+                 VLC_TRUE );
+    add_bool( "dvb-probe", 1, NULL, PROBE_TEXT, PROBE_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-lnb-lof1", 9750000, NULL, LNB_LOF1_TEXT,
+                 LNB_LOF1_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-lnb-lof2", 10600000, NULL, LNB_LOF2_TEXT,
+                 LNB_LOF2_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-lnb-slof", 11700000, NULL, LNB_SLOF_TEXT,
+                 LNB_SLOF_LONGTEXT, VLC_TRUE );
+    /* DVB-S (satellite) */
+    add_bool( "dvb-budget-mode", 0, NULL, BUDGET_TEXT, BUDGET_LONGTEXT,
+              VLC_TRUE );
+    add_integer( "dvb-satno", 0, NULL, SATNO_TEXT, SATNO_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "dvb-voltage", 13, NULL, VOLTAGE_TEXT, VOLTAGE_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "dvb-tone", -1, NULL, TONE_TEXT, TONE_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "dvb-fec", 9, NULL, FEC_TEXT, FEC_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-srate", 27500000, NULL, SRATE_TEXT, SRATE_LONGTEXT,
+                 VLC_FALSE );
+    /* DVB-T (terrestrial) */
+    add_integer( "dvb-modulation", 0, NULL, MODULATION_TEXT,
+                 MODULATION_LONGTEXT, VLC_TRUE );
+    /* DVB-T (terrestrial) */
+    add_integer( "dvb-code-rate-hp", 9, NULL, CODE_RATE_HP_TEXT,
+                 CODE_RATE_HP_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-code-rate-lp", 9, NULL, CODE_RATE_LP_TEXT,
+                 CODE_RATE_LP_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-bandwidth", 0, NULL, BANDWIDTH_TEXT, BANDWIDTH_LONGTEXT,
+                 VLC_TRUE );
+    add_integer( "dvb-guard", 0, NULL, GUARD_TEXT, GUARD_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-transmission", 0, NULL, TRANSMISSION_TEXT,
+                 TRANSMISSION_LONGTEXT, VLC_TRUE );
+    add_integer( "dvb-hierarchy", 0, NULL, HIERARCHY_TEXT, HIERARCHY_LONGTEXT,
+                 VLC_TRUE );
+
+    set_capability( "access2", 0 );
+    add_shortcut( "dvb" );
+    add_shortcut( "dvb-s" );
+    add_shortcut( "qpsk" );
+    add_shortcut( "dvb-c" );
+    add_shortcut( "cable" );
+    add_shortcut( "dvb-t" );
+    add_shortcut( "terrestrial" );
+    add_shortcut( "satellite" );    /* compatibility with the interface. */
+    set_callbacks( Open, Close );
+vlc_module_end();
 
-#define SATELLITE_READ_ONCE 3
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
-                              size_t i_len);
-static int     SatelliteSetArea    ( input_thread_t *, input_area_t * );
-static int     SatelliteSetProgram ( input_thread_t *, pgrm_descriptor_t * );
-static void    SatelliteSeek       ( input_thread_t *, off_t );
+static block_t *Block( access_t * );
+static int Control( access_t *, int, va_list );
+
+#define SATELLITE_READ_ONCE 3
+#define TS_PACKET_SIZE 188
+
+static void FilterUnset( access_t *, int i_max );
+static void FilterUnsetPID( access_t *, int i_pid );
+static void FilterSet( access_t *, int i_pid, int i_type );
+
+static void VarInit( access_t * );
+static int  ParseMRL( access_t * );
+
 
 /*****************************************************************************
  * Open: open the frontend device
  *****************************************************************************/
-int E_(Open) ( vlc_object_t *p_this )
+static int Open( vlc_object_t *p_this )
 {
-    struct dvb_frontend_info frontend_info;
-    struct dvb_frontend_parameters fep;
-    input_thread_t *    p_input = (input_thread_t *)p_this;
-    input_socket_t *    p_satellite;
-    char *              psz_parser;
-    char *              psz_next;
-    int                 i_fd = 0;
-    unsigned int        u_adapter = 1;
-    unsigned int        u_device = 0;
-    unsigned int        u_freq = 0;
-    unsigned int        u_srate = 0;
-    unsigned int        u_lnb_lof1;
-    unsigned int        u_lnb_lof2;
-    unsigned int        u_lnb_slof;
-    int                 i_bandwidth = 0;
-    int                 i_modulation = 0;
-    int                 i_guard = 0;
-    int                 i_transmission = 0;
-    int                 i_hierarchy = 0;
-    vlc_bool_t          b_polarisation = 0;
-    int                 i_fec = 0;
-    int                 i_code_rate_HP = 0;
-    int                 i_code_rate_LP = 0;
-    vlc_bool_t          b_diseqc;
-    vlc_bool_t          b_probe;
-    char                dvr[] = DVR;
-    char                frontend[] = FRONTEND;
-    int                 i_len = 0;
-
-    /* parse the options passed in command line : */
-    psz_parser = strdup( p_input->psz_name );
-
-    if( !psz_parser )
+    access_t     *p_access = (access_t*)p_this;
+    access_sys_t *p_sys;
+
+    /* Only if selected */
+    if( *p_access->psz_access == '\0' )
+        return VLC_EGENERIC;
+
+    /* Set up access */
+    p_access->pf_read = NULL;
+    p_access->pf_block = Block;
+    p_access->pf_control = Control;
+    p_access->pf_seek = NULL;
+    p_access->info.i_update = 0;
+    p_access->info.i_size = 0;
+    p_access->info.i_pos = 0;
+    p_access->info.b_eof = VLC_FALSE;
+    p_access->info.i_title = 0;
+    p_access->info.i_seekpoint = 0;
+
+    p_access->p_sys = p_sys = malloc( sizeof( access_sys_t ) );
+    memset( p_sys, 0, sizeof( access_sys_t ) );
+
+    /* Create all variables */
+    VarInit( p_access );
+
+    /* Parse the command line */
+    if( ParseMRL( p_access ) )
     {
-        return( -1 );
+        free( p_sys );
+        return VLC_EGENERIC;
     }
 
-    // Get adapter and device number to use for this dvb card
-    u_adapter = config_GetInt( p_input, "adapter" );
-    u_device  = config_GetInt( p_input, "device" );
-  
-    /* Determine frontend device information and capabilities */
-    b_probe = config_GetInt( p_input, "probe" );
-    if (b_probe)
+    /* Getting frontend info */
+    if( E_(FrontendOpen)( p_access) )
     {
-        if ( ioctl_InfoFrontend(p_input, &frontend_info, u_adapter, u_device) < 0 )
-        {
-            msg_Err( p_input, "(access) cannot determine frontend info" );
-            return -1;
-        }
+        free( p_sys );
+        return VLC_EGENERIC;
     }
-    else /* no frontend probing is done so use default border values. */
+
+    /* Setting frontend parameters for tuning the hardware */
+    msg_Dbg( p_access, "trying to tune the frontend...");
+    if( E_(FrontendSet)( p_access ) < 0 )
     {
-        msg_Dbg( p_input, "using default values for frontend info" );
-        i_len = sizeof(FRONTEND);
-        if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
-        {
-            msg_Err( p_input, "snprintf() truncated string for FRONTEND" );
-            frontend[sizeof(FRONTEND)] = '\0';
-        }
-        strncpy(frontend_info.name, frontend, 128);
-
-        msg_Dbg(p_input, "method of access is %s", p_input->psz_access);
-        
-        frontend_info.type = FE_QPSK;
-        if (strncmp( p_input->psz_access, "qpsk",4 ) ==0)
-            frontend_info.type = FE_QPSK;
-        else if (strncmp( p_input->psz_access, "cable",5 ) ==0)
-            frontend_info.type = FE_QAM;
-        else if (strncmp( p_input->psz_access, "terrestrial",11) ==0)
-            frontend_info.type = FE_OFDM;
-
-        frontend_info.frequency_max =   12999000;
-        frontend_info.frequency_min =    9750000;
-        frontend_info.symbol_rate_max = 30000000;
-        frontend_info.symbol_rate_min =  1000000;
+        E_(FrontendClose)( p_access );
+        free( p_sys );
+        return VLC_EGENERIC;
     }
-    
-    /* Register Callback functions */
-    p_input->pf_read = SatelliteRead;
-    p_input->pf_set_program = SatelliteSetProgram;
-    p_input->pf_set_area = SatelliteSetArea;
-    p_input->pf_seek = SatelliteSeek;
-
-    u_freq = (unsigned int)strtol( psz_parser, &psz_next, 10 );
-    if( *psz_next )
+
+    /* Opening DVR device */
+    if( E_(DVROpen)( p_access ) < 0 )
     {
-        psz_parser = psz_next + 1;
-        b_polarisation = (vlc_bool_t)strtol( psz_parser, &psz_next, 10 );
-        if( *psz_next )
-        {
-            psz_parser = psz_next + 1;
-            i_fec = (int)strtol( psz_parser, &psz_next, 10 );
-            if( *psz_next )
-            {
-                psz_parser = psz_next + 1;
-                u_srate = (unsigned int)strtol( psz_parser, &psz_next, 10 );
-            }
-        }
+        E_(FrontendClose)( p_access );
+        free( p_sys );
+        return VLC_EGENERIC;
     }
 
-    /* Workaround for backwards compatibility */
-    if (strncmp( p_input->psz_access, "satellite",9 ) ==0)
+    p_sys->b_budget_mode = var_GetBool( p_access, "dvb-budget-mode" );
+    if( p_sys->b_budget_mode )
     {
-        msg_Warn( p_input, "invalid frequency %d possibly in kHz, trying value *1000 Hz", u_freq );
-        u_freq *= 1000;
+        msg_Dbg( p_access, "setting filter on all PIDs" );
+        FilterSet( p_access, 0x2000, OTHER_TYPE );
     }
-    
-    /* Validating input values */
-    if ( ((u_freq) > frontend_info.frequency_max) ||
-         ((u_freq) < frontend_info.frequency_min) )
+    else
     {
-        msg_Warn( p_input, "invalid frequency %d (Hz), using default one", u_freq );
-        u_freq = config_GetInt( p_input, "frequency" );
-        if ( ((u_freq) > frontend_info.frequency_max) ||
-             ((u_freq) < frontend_info.frequency_min) )
-        {
-            msg_Err( p_input, "invalid default frequency" );
-            return -1;
-        }
+        msg_Dbg( p_access, "setting filter on PAT" );
+        FilterSet( p_access, 0x0, OTHER_TYPE );
     }
 
-    /* Workaround for backwards compatibility */
-    if (strncmp( p_input->psz_access, "satellite", 9 ) ==0)
-    {
-        msg_Warn( p_input, "invalid symbol rate %d possibly specified in kHz, trying value *1000 Hz", u_freq );
-        u_srate *= 1000;
-    }
-    
-    if ( ((u_srate) > frontend_info.symbol_rate_max) ||
-         ((u_srate) < frontend_info.symbol_rate_min) )
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Close : Close the device
+ *****************************************************************************/
+static void Close( vlc_object_t *p_this )
+{
+    access_t     *p_access = (access_t*)p_this;
+    access_sys_t *p_sys = p_access->p_sys;
+
+    FilterUnset( p_access, p_sys->b_budget_mode ? 1 : MAX_DEMUX );
+
+    E_(DVRClose)( p_access );
+    E_(FrontendClose)( p_access );
+    free( p_sys );
+}
+
+/*****************************************************************************
+ * Block:
+ *****************************************************************************/
+static block_t *Block( access_t *p_access )
+{
+    access_sys_t *p_sys = p_access->p_sys;
+    struct timeval timeout;
+    fd_set fds;
+    int i_ret;
+    block_t *p_block;
+
+    /* Initialize file descriptor set */
+    FD_ZERO( &fds );
+    FD_SET( p_sys->i_handle, &fds );
+
+    /* We'll wait 0.5 second if nothing happens */
+    timeout.tv_sec = 0;
+    timeout.tv_usec = 500000;
+
+    /* Find if some data is available */
+    while( (i_ret = select( p_sys->i_handle + 1, &fds, NULL, NULL, &timeout )) == 0 ||
+           (i_ret < 0 && errno == EINTR) )
     {
-        msg_Warn( p_input, "invalid symbol rate, using default one" );
-        u_srate = config_GetInt( p_input, "symbol-rate" );
-        if ( ((u_srate) > frontend_info.symbol_rate_max) ||
-             ((u_srate) < frontend_info.symbol_rate_min) )
-        {
-            msg_Err( p_input, "invalid default symbol rate" );
-            return -1;
-        }
+        FD_ZERO( &fds );
+        FD_SET( p_sys->i_handle, &fds );
+        timeout.tv_sec = 0;
+        timeout.tv_usec = 500000;
+
+        if( p_access->b_die )
+            return NULL;
     }
 
-    if( b_polarisation && (b_polarisation != 1) )
+    if ( i_ret < 0 )
     {
-        msg_Warn( p_input, "invalid polarization, using default one" );
-        b_polarisation = config_GetInt( p_input, "polarization" );
-        if( b_polarisation && b_polarisation != 1 )
-        {
-            msg_Err( p_input, "invalid default polarization" );
-            return -1;
-        }
+        msg_Err( p_access, "select error (%s)", strerror(errno) );
+        return NULL;
     }
 
-    if( (i_fec > 9) || (i_fec < 1) )
+    p_block = block_New( p_access, SATELLITE_READ_ONCE * TS_PACKET_SIZE );
+    if( ( p_block->i_buffer = read( p_sys->i_handle, p_block->p_buffer, SATELLITE_READ_ONCE * TS_PACKET_SIZE ) ) <= 0 )
     {
-        msg_Warn( p_input, "invalid FEC, using default one" );
-        i_fec = config_GetInt( p_input, "fec" );
-        if( (i_fec > 9) || (i_fec < 1) )
-        {
-            msg_Err( p_input, "invalid default FEC" );
-            return -1;
-        }
+        msg_Err( p_access, "read failed (%s)", strerror(errno) );
+        block_Release( p_block );
+        return NULL;
     }
 
-    /* Get antenna configuration options */
-    b_diseqc = config_GetInt( p_input, "diseqc" );
-    u_lnb_lof1 = config_GetInt( p_input, "lnb-lof1" );
-    u_lnb_lof2 = config_GetInt( p_input, "lnb-lof2" );
-    u_lnb_slof = config_GetInt( p_input, "lnb-slof" );
+    return p_block;
+}
+
+/*****************************************************************************
+ * Control:
+ *****************************************************************************/
+static int Control( access_t *p_access, int i_query, va_list args )
+{
+    access_sys_t *p_sys = p_access->p_sys;
+    vlc_bool_t   *pb_bool, b_bool;
+    int          *pi_int, i_int;
+    int64_t      *pi_64;
 
-    /* Setting frontend parameters for tuning the hardware */      
-    switch( frontend_info.type )
+    switch( i_query )
     {
-        /* DVB-S: satellite and budget cards (nova) */
-        case FE_QPSK:
-            fep.frequency = u_freq;
-            fep.inversion = dvb_DecodeInversion(p_input, (int) b_polarisation);
-            fep.u.qpsk.symbol_rate = u_srate;
-            fep.u.qpsk.fec_inner = dvb_DecodeFEC(p_input, i_fec); 
-            msg_Dbg( p_input, "satellite (QPSK) frontend found on %s", frontend_info.name );
+        /* */
+        case ACCESS_CAN_SEEK:
+        case ACCESS_CAN_FASTSEEK:
+        case ACCESS_CAN_PAUSE:
+        case ACCESS_CAN_CONTROL_PACE:
+            pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
+            *pb_bool = VLC_FALSE;
             break;
-            
-        /* DVB-C */
-        case FE_QAM:
-            i_modulation  = config_GetInt(p_input, "modulation");
-
-            fep.frequency = u_freq;
-            fep.inversion = dvb_DecodeInversion(p_input, (int) b_polarisation);
-            fep.u.qam.symbol_rate = u_srate;
-            fep.u.qam.fec_inner = dvb_DecodeFEC(p_input, i_fec); 
-            fep.u.qam.modulation = dvb_DecodeModulation(p_input, i_modulation); 
-            msg_Dbg( p_input, "cable (QAM) frontend found on %s", frontend_info.name );
+        /* */
+        case ACCESS_GET_MTU:
+            pi_int = (int*)va_arg( args, int * );
+            *pi_int = SATELLITE_READ_ONCE * TS_PACKET_SIZE;
             break;
 
-        /* DVB-T */
-        case FE_OFDM:
-            i_bandwidth = config_GetInt( p_input, "bandwidth");
-            i_code_rate_HP = config_GetInt(p_input, "code-rate-hp");
-            i_code_rate_LP = config_GetInt(p_input, "code-rate-lp");
-            i_modulation  = config_GetInt(p_input, "modulation");
-            i_transmission = config_GetInt(p_input, "transmission");
-            i_guard = config_GetInt(p_input, "guard");
-            i_hierarchy = config_GetInt(p_input, "hierarchy");
-            
-            fep.frequency = u_freq;
-            fep.inversion = dvb_DecodeInversion(p_input, (int) b_polarisation);
-            fep.u.ofdm.bandwidth = dvb_DecodeBandwidth(p_input, i_bandwidth);
-            fep.u.ofdm.code_rate_HP = dvb_DecodeFEC(p_input, i_code_rate_HP); 
-            fep.u.ofdm.code_rate_LP = dvb_DecodeFEC(p_input, i_code_rate_LP);
-            fep.u.ofdm.constellation = dvb_DecodeModulation(p_input, i_modulation); 
-            fep.u.ofdm.transmission_mode = dvb_DecodeTransmission(p_input, i_transmission);
-            fep.u.ofdm.guard_interval = dvb_DecodeGuardInterval(p_input, i_guard);
-            fep.u.ofdm.hierarchy_information = dvb_DecodeHierarchy(p_input, i_hierarchy);
-            msg_Dbg( p_input, "terrestrial (OFDM) frontend found on %s", frontend_info.name );
+        case ACCESS_GET_PTS_DELAY:
+            pi_64 = (int64_t*)va_arg( args, int64_t * );
+            *pi_64 = var_GetInteger( p_access, "dvb-caching" ) * 1000;
             break;
 
-        default:
-            msg_Err( p_input, "Could not determine frontend type on %s", frontend_info.name );
-            return -1;
-    }
-
-    /* Initialise structure */
-    p_satellite = malloc( sizeof( input_socket_t ) );
-
-    if( p_satellite == NULL )
-    {
-        msg_Err( p_input, "out of memory" );
-        return -1;
-    }
+        /* */
+        case ACCESS_SET_PAUSE_STATE:
+        case ACCESS_GET_TITLE_INFO:
+        case ACCESS_SET_TITLE:
+        case ACCESS_SET_SEEKPOINT:
+            return VLC_EGENERIC;
+
+        case ACCESS_SET_PRIVATE_ID_STATE:
+            i_int  = (int)va_arg( args, int );               /* Private data (pid for now)*/
+            b_bool = (vlc_bool_t)va_arg( args, vlc_bool_t ); /* b_selected */
+            if( !p_sys->b_budget_mode )
+            {
+                /* FIXME we may want to give the real type (me ?, I don't ;) */
+                if( b_bool )
+                    FilterSet( p_access, i_int, OTHER_TYPE );
+                else
+                    FilterUnsetPID( p_access, i_int );
+            }
+            break;
 
-    p_input->p_access_data = (void *)p_satellite;
+        default:
+            msg_Err( p_access, "unimplemented query in control" );
+            return VLC_EGENERIC;
 
-    /* Open the DVR device */
-    i_len = sizeof(DVR);
-    if (snprintf(dvr, sizeof(DVR), DVR, u_adapter, u_device) >= i_len)
-    {
-        msg_Err( p_input, "snprintf() truncated string for DVR" );
-        dvr[sizeof(DVR)] = '\0';
     }
-    msg_Dbg( p_input, "opening DVR device '%s'", dvr );
+    return VLC_SUCCESS;
+}
 
-    if( (p_satellite->i_handle = open( dvr,
-                                   /*O_NONBLOCK | O_LARGEFILE*/0 )) == (-1) )
-    {
-#   ifdef HAVE_ERRNO_H
-        msg_Warn( p_input, "cannot open `%s' (%s)", dvr, strerror(errno) );
-#   else
-        msg_Warn( p_input, "cannot open `%s'", dvr );
-#   endif
-        free( p_satellite );
-        return -1;
-    }
+/*****************************************************************************
+ * FilterSet/FilterUnset:
+ *****************************************************************************/
+static void FilterSet( access_t *p_access, int i_pid, int i_type )
+{
+    access_sys_t *p_sys = p_access->p_sys;
+    int i;
 
-    /* Initialize the Satellite Card */
-    switch (ioctl_SetFrontend (p_input, fep, b_polarisation,
-                               u_lnb_lof1, u_lnb_lof2, u_lnb_slof,
-                               u_adapter, u_device ))
+    /* Find first free slot */
+    for( i = 0; i < MAX_DEMUX; i++ )
     {
-        case -2:
-            msg_Err( p_input, "frontend returned an unexpected event" );
-            close( p_satellite->i_handle );
-            free( p_satellite );
-            return -1;
-        case -3:
-            msg_Err( p_input, "frontend returned no event" );
-            close( p_satellite->i_handle );
-            free( p_satellite );
-            return -1;
-        case -4:
-            msg_Err( p_input, "frontend: timeout when polling for event" );
-            close( p_satellite->i_handle );
-            free( p_satellite );
-            return -1;
-        case -5:
-            msg_Err( p_input, "an error occured when polling frontend device" );
-            close( p_satellite->i_handle );
-            free( p_satellite );
-            return -1;
-        case -1:
-            msg_Err( p_input, "frontend returned a failure event" );
-            close( p_satellite->i_handle );
-            free( p_satellite );
-            return -1;
-        default:
+        if( !p_sys->p_demux_handles[i].i_type )
             break;
-    }
 
-    msg_Dbg( p_input, "setting filter on PAT" );
+        if( p_sys->p_demux_handles[i].i_pid == i_pid )
+            return; /* Already set */
+    }
 
-    if ( ioctl_SetDMXFilter(p_input, 0, &i_fd, 21, u_adapter, u_device ) < 0 )
+    if( i >= MAX_DEMUX )
     {
-#   ifdef HAVE_ERRNO_H
-        msg_Err( p_input, "an error occured when setting filter on PAT (%s)", strerror(errno) );
-#   else
-        msg_Err( p_input, "an error occured when setting filter on PAT" );
-#   endif        
-        close( p_satellite->i_handle );
-        free( p_satellite );
-        return -1;
+        msg_Err( p_access, "no free p_demux_handles !" );
+        return;
     }
 
-    if( input_InitStream( p_input, sizeof( stream_ts_data_t ) ) == -1 )
+    if( E_(DMXSetFilter)( p_access, i_pid,
+                           &p_sys->p_demux_handles[i].i_handle, i_type ) )
     {
-        msg_Err( p_input, "could not initialize stream structure" );
-        close( p_satellite->i_handle );
-        free( p_satellite );
-        return( -1 );
+        msg_Err( p_access, "DMXSetFilter failed" );
+        return;
     }
-
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-
-    p_input->stream.b_pace_control = 1;
-    p_input->stream.b_seekable = 0;
-    p_input->stream.p_selected_area->i_tell = 0;
-
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-
-    p_input->i_mtu = SATELLITE_READ_ONCE * TS_PACKET_SIZE;
-    p_input->stream.i_method = INPUT_METHOD_SATELLITE;
-
-    return 0;
+    p_sys->p_demux_handles[i].i_type = i_type;
+    p_sys->p_demux_handles[i].i_pid = i_pid;
 }
 
-/*****************************************************************************
- * Close : Close the device
- *****************************************************************************/
-void E_(Close) ( vlc_object_t *p_this )
+static void FilterUnset( access_t *p_access, int i_max )
 {
-    input_thread_t *    p_input = (input_thread_t *)p_this;
-    input_socket_t *    p_satellite;
-    unsigned int        i_es_index;
+    access_sys_t *p_sys = p_access->p_sys;
+    int i;
 
-    if ( p_input->stream.p_selected_program )
+    for( i = 0; i < i_max; i++ )
     {
-        for ( i_es_index = 1 ;
-                i_es_index < p_input->stream.p_selected_program->i_es_number;
-                i_es_index ++ )
+        if( p_sys->p_demux_handles[i].i_type )
         {
-#define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
-            if ( p_es->p_decoder_fifo )
-            {
-                ioctl_UnsetDMXFilter(p_input, p_es->i_demux_fd );
-            }
-#undef p_es
+            E_(DMXUnsetFilter)( p_access, p_sys->p_demux_handles[i].i_handle );
+            p_sys->p_demux_handles[i].i_type = 0;
         }
     }
-
-    p_satellite = (input_socket_t *)p_input;
-    close( p_satellite->i_handle );
 }
 
-/*****************************************************************************
- * SatelliteRead: reads data from the satellite card
- *****************************************************************************/
-static ssize_t SatelliteRead( input_thread_t * p_input, byte_t * p_buffer,
-                              size_t i_len )
+static void FilterUnsetPID( access_t *p_access, int i_pid )
 {
-    input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
-    ssize_t i_ret;
-    unsigned int u_adapter = 1;
-    unsigned int u_device = 0;
-    unsigned int i;
-
-    // Get adapter and device number to use for this dvb card
-    u_adapter = config_GetInt( p_input, "adapter" );
-    u_device  = config_GetInt( p_input, "device" );
-
-    /* if not set, set filters to the PMTs */
-    for( i = 0; i < p_input->stream.i_pgrm_number; i++ )
+    access_sys_t *p_sys = p_access->p_sys;
+    int i;
+
+    for( i = 0; i < MAX_DEMUX; i++ )
     {
-        if ( p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd == 0 )
+        if( p_sys->p_demux_handles[i].i_type &&
+            p_sys->p_demux_handles[i].i_pid == i_pid )
         {
-            ioctl_SetDMXFilter(p_input, p_input->stream.pp_programs[i]->pp_es[0]->i_id,
-                       &p_input->stream.pp_programs[i]->pp_es[0]->i_demux_fd,
-                       21, u_adapter, u_device );
+            E_(DMXUnsetFilter)( p_access, p_sys->p_demux_handles[i].i_handle );
+            p_sys->p_demux_handles[i].i_type = 0;
         }
     }
-
-    i_ret = read( p_access_data->i_handle, p_buffer, i_len );
-    if( i_ret < 0 )
-    {
-#   ifdef HAVE_ERRNO_H
-        msg_Err( p_input, "read failed (%s)", strerror(errno) );
-#   else
-        msg_Err( p_input, "read failed" );
-#   endif
-    }
-
-    return i_ret;
 }
 
 /*****************************************************************************
- * SatelliteSetArea : Does nothing
+ * VarInit/ParseMRL:
  *****************************************************************************/
-static int SatelliteSetArea( input_thread_t * p_input, input_area_t * p_area )
+static void VarInit( access_t *p_access )
 {
-    return -1;
+    /* */
+    var_Create( p_access, "dvb-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+
+    /* */
+    var_Create( p_access, "dvb-adapter", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-device", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-frequency", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-inversion", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-probe", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-lnb-lof1", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-lnb-lof2", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-lnb-slof", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+
+    /* */
+    var_Create( p_access, "dvb-budget-mode", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-satno", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-voltage", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-tone", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-fec", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-srate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+
+    /* */
+    var_Create( p_access, "dvb-modulation", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+
+    /* */
+    var_Create( p_access, "dvb-code-rate-hp", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-code-rate-lp", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-bandwidth", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-transmission", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-guard", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
+    var_Create( p_access, "dvb-hierarchy", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
 }
 
-/*****************************************************************************
- * SatelliteSetProgram : Sets the card filters according to the
- *                 selected program,
- *                 and makes the appropriate changes to stream structure.
- *****************************************************************************/
-int SatelliteSetProgram( input_thread_t    * p_input,
-                         pgrm_descriptor_t * p_new_prg )
+/* */
+static int ParseMRL( access_t *p_access )
 {
-    unsigned int i_es_index;
-    vlc_value_t val;
-    unsigned int u_adapter = 1;
-    unsigned int u_device = 0;
-    unsigned int u_video_type = 1; /* default video type */
-    unsigned int u_audio_type = 2; /* default audio type */
-
-    /* Get adapter and device number to use for this dvb card */
-    u_adapter = config_GetInt( p_input, "adapter" );
-    u_device  = config_GetInt( p_input, "device" );
-
-    if ( p_input->stream.p_selected_program )
+    char *psz_dup = strdup( p_access->psz_path );
+    char *psz_parser = psz_dup;
+    char *psz_next;
+    vlc_value_t         val;
+
+#define GET_OPTION_INT( option )                                            \
+    if ( !strncmp( psz_parser, option "=", strlen(option "=") ) )           \
+    {                                                                       \
+        val.i_int = strtol( psz_parser+strlen(option "="), &psz_parser, 0 );\
+        var_Set( p_access, "dvb-" option, val );                             \
+    }
+
+#define GET_OPTION_BOOL( option )                                           \
+    if ( !strncmp( psz_parser, option "=", strlen(option "=") ) )           \
+    {                                                                       \
+        val.b_bool = strtol( psz_parser + strlen(option "="), &psz_parser,  \
+                             0 );                                           \
+        var_Set( p_access, "dvb-" option, val );                             \
+    }
+
+    /* Test for old syntax */
+    strtol( psz_parser, &psz_next, 10 );
+    if( psz_next != psz_parser )
     {
-        for ( i_es_index = 1 ; /* 0 should be the PMT */
-                i_es_index < p_input->stream.p_selected_program->i_es_number ;
-                i_es_index ++ )
+        msg_Err( p_access, "the DVB input old syntax is deprecated, use vlc "
+                          "-p dvb to see an explanation of the new syntax" );
+        free( psz_dup );
+        return VLC_EGENERIC;
+    }
+
+    while( *psz_parser )
+    {
+        GET_OPTION_INT("adapter")
+        else GET_OPTION_INT("device")
+        else GET_OPTION_INT("frequency")
+        else GET_OPTION_INT("inversion")
+        else GET_OPTION_BOOL("probe")
+        else GET_OPTION_INT("lnb-lof1")
+        else GET_OPTION_INT("lnb-lof2")
+        else GET_OPTION_INT("lnb-slof")
+
+        else GET_OPTION_BOOL("budget-mode")
+        else GET_OPTION_INT("voltage")
+        else GET_OPTION_INT("tone")
+        else GET_OPTION_INT("fec")
+        else GET_OPTION_INT("srate")
+
+        else GET_OPTION_INT("modulation")
+
+        else GET_OPTION_INT("code-rate-hp")
+        else GET_OPTION_INT("code-rate-lp")
+        else GET_OPTION_INT("bandwidth")
+        else GET_OPTION_INT("transmission")
+        else GET_OPTION_INT("guard")
+        else GET_OPTION_INT("hierarchy")
+
+        else if( !strncmp( psz_parser, "satno=",
+                           strlen( "satno=" ) ) )
         {
-#define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
-            if ( p_es->p_decoder_fifo )
-            {
-                input_UnselectES( p_input , p_es );
-            }
-            if ( p_es->i_demux_fd > 0)
+            psz_parser += strlen( "satno=" );
+            if ( *psz_parser == 'A' || *psz_parser == 'a' )
+                val.i_int = -1;
+            else if ( *psz_parser == 'B' || *psz_parser == 'b' )
+                val.i_int = -2;
+            else
+                val.i_int = strtol( psz_parser, &psz_parser, 0 );
+            var_Set( p_access, "dvb-satno", val );
+        }
+        /* Redundant with voltage but much easier to use */
+        else if( !strncmp( psz_parser, "polarization=",
+                           strlen( "polarization=" ) ) )
+        {
+            psz_parser += strlen( "polarization=" );
+            if ( *psz_parser == 'V' || *psz_parser == 'v' )
+                val.i_int = 13;
+            else if ( *psz_parser == 'H' || *psz_parser == 'h' )
+                val.i_int = 18;
+            else
             {
-                ioctl_UnsetDMXFilter(p_input, p_es->i_demux_fd );
-                p_es->i_demux_fd = 0;
+                msg_Err( p_access, "illegal polarization %c", *psz_parser );
+                free( psz_dup );
+                return VLC_EGENERIC;
             }
-#undef p_es
+            var_Set( p_access, "dvb-voltage", val );
         }
-    }
-
-    for (i_es_index = 1 ; i_es_index < p_new_prg->i_es_number ; i_es_index ++ )
-    {
-#define p_es p_new_prg->pp_es[i_es_index]
-        switch( p_es->i_cat )
+        else
         {
-            case MPEG1_VIDEO_ES:
-            case MPEG2_VIDEO_ES:
-            case MPEG2_MOTO_VIDEO_ES:
-                if ( input_SelectES( p_input , p_es ) == 0 )
-                {
-                    ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, u_video_type,
-                                       u_adapter, u_device);
-                    u_video_type += 5;
-                }
-                break;
-            case MPEG1_AUDIO_ES:
-            case MPEG2_AUDIO_ES:
-                if ( input_SelectES( p_input , p_es ) == 0 )
-                {
-                    ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, u_audio_type,
-                                       u_adapter, u_device);
-                    input_SelectES( p_input , p_es );
-                    u_audio_type += 5;
-                }
-                break;
-            default:
-                ioctl_SetDMXFilter(p_input, p_es->i_id, &p_es->i_demux_fd, 21, u_adapter, u_device);
-                input_SelectES( p_input , p_es );
-                msg_Warn(p_input, "ES streamtype 0x%d found used as DMX_PES_OTHER !!",(int) p_es->i_cat);
-                break;
-#undef p_es
+            msg_Err( p_access, "unknown option (%s)", psz_parser );
+            free( psz_dup );
+            return VLC_EGENERIC;
         }
-    }
 
-    p_input->stream.p_selected_program = p_new_prg;
-
-    /* Update the navigation variables without triggering a callback */
-    val.i_int = p_new_prg->i_number;
-    var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
-
-    return 0;
-}
+        psz_parser++;
+    }
+#undef GET_OPTION_INT
+#undef GET_OPTION_BOOL
 
-/*****************************************************************************
- * SatelliteSeek: does nothing (not a seekable stream
- *****************************************************************************/
-static void SatelliteSeek( input_thread_t * p_input, off_t i_off )
-{
-    ;
+    free( psz_dup );
+    return VLC_SUCCESS;
 }