#define DEVICE_TEXT N_("Device number to use on adapter")
#define DEVICE_LONGTEXT ""
+#define CAM_TEXT N_("Use CAM")
+#define CAM_LONGTEXT ""
+
#define FREQ_TEXT N_("Transponder/multiplex frequency")
#define FREQ_LONGTEXT N_("In kHz for DVB-S or Hz for DVB-C/T")
VLC_FALSE );
add_integer( "dvb-device", 0, NULL, DEVICE_TEXT, DEVICE_LONGTEXT,
VLC_TRUE );
+ add_bool( "dvb-cam", 0, NULL, CAM_TEXT, CAM_LONGTEXT, VLC_FALSE );
add_integer( "dvb-frequency", 11954000, NULL, FREQ_TEXT, FREQ_LONGTEXT,
VLC_FALSE );
add_integer( "dvb-inversion", 2, NULL, INVERSION_TEXT, INVERSION_LONGTEXT,
FilterSet( p_access, 0x0, OTHER_TYPE );
}
+ p_sys->b_cam = var_GetBool( p_access, "dvb-cam" );
+ if ( p_sys->b_cam )
+ {
+ msg_Dbg( p_access, "initing CAM..." );
+ if ( E_(CAMOpen)( p_access ) < 0 )
+ p_sys->b_cam = VLC_FALSE;
+ }
+
return VLC_SUCCESS;
}
E_(DVRClose)( p_access );
E_(FrontendClose)( p_access );
+
+ if ( p_sys->b_cam )
+ E_(CAMClose)( p_access );
+
free( p_sys );
}
}
break;
+ case ACCESS_SET_PRIVATE_ID_CA:
+ if ( p_sys->b_cam )
+ {
+ int i_program;
+ uint16_t i_vpid, i_apid1, i_apid2, i_apid3;
+ uint8_t i_cad_length;
+ uint8_t *p_cad;
+
+ i_program = (int)va_arg( args, int );
+ i_vpid = (int16_t)va_arg( args, int );
+ i_apid1 = (uint16_t)va_arg( args, int );
+ i_apid2 = (uint16_t)va_arg( args, int );
+ i_apid3 = (uint16_t)va_arg( args, int );
+ i_cad_length = (uint8_t)va_arg( args, int );
+ p_cad = (uint8_t *)va_arg( args, uint8_t * );
+
+ E_(CAMSet)( p_access, i_program, i_vpid, i_apid1, i_apid2,
+ i_apid3, i_cad_length, p_cad );
+ }
+ break;
+
default:
msg_Warn( p_access, "unimplemented query in control" );
return VLC_EGENERIC;
/* */
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-cam", VLC_VAR_BOOL | 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 );
#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 ); \
+ val.i_int = strtol( psz_parser + strlen(option "="), &psz_parser, \
+ 0 ); \
+ var_Set( p_access, "dvb-" option, val ); \
}
#define GET_OPTION_BOOL( option ) \
{ \
val.b_bool = strtol( psz_parser + strlen(option "="), &psz_parser, \
0 ); \
- var_Set( p_access, "dvb-" option, val ); \
+ var_Set( p_access, "dvb-" option, val ); \
}
/* Test for old syntax */
{
GET_OPTION_INT("adapter")
else GET_OPTION_INT("device")
+ else GET_OPTION_BOOL("cam")
else GET_OPTION_INT("frequency")
else GET_OPTION_INT("inversion")
else GET_OPTION_BOOL("probe")
#include <linux/errno.h>
#include "dvb.h"
+#include "network.h"
+
+#define DMX_BUFFER_SIZE (1024 * 1024)
/*
* Frontends
return VLC_EGENERIC;
}
+ if ( ioctl( p_sys->i_handle, DMX_SET_BUFFER_SIZE, DMX_BUFFER_SIZE ) < 0 )
+ {
+ msg_Warn( p_access, "couldn't set DMX_BUFFER_SIZE (%s)",
+ strerror(errno) );
+ }
+
return VLC_SUCCESS;
}
close( p_sys->i_handle );
}
+
+/*
+ * CAM device
+ *
+ * This uses the external cam_set program from libdvb-0.5.4
+ */
+
+/*****************************************************************************
+ * CAMOpen :
+ *****************************************************************************/
+int E_(CAMOpen)( access_t * p_access )
+{
+ access_sys_t *p_sys = p_access->p_sys;
+
+ p_sys->i_cam_handle = net_OpenTCP( p_access, "localhost", 4711 );
+ if ( p_sys->i_cam_handle < 0 )
+ {
+ return -VLC_EGENERIC;
+ }
+
+ return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * CAMSet :
+ *****************************************************************************/
+int E_(CAMSet)( access_t * p_access, uint16_t i_program, uint16_t i_vpid,
+ uint16_t i_apid1, uint16_t i_apid2, uint16_t i_apid3,
+ uint16_t i_cad_length, uint8_t *p_cad )
+{
+ access_sys_t *p_sys = p_access->p_sys;
+ uint8_t p_str[12];
+
+ memcpy( p_str, &i_program, 2 );
+ memcpy( p_str + 2, &i_vpid, 2 );
+ memcpy( p_str + 4, &i_apid1, 2 );
+ memcpy( p_str + 6, &i_apid2, 2 );
+ memcpy( p_str + 8, &i_apid3, 2 );
+ memcpy( p_str + 10, &i_cad_length, 2 );
+
+ if ( net_Write( p_access, p_sys->i_cam_handle, p_str, 12 ) != 12 )
+ {
+ msg_Err( p_access, "write 1 failed (%s)", strerror(errno) );
+ return -VLC_EGENERIC;
+ }
+
+ if ( i_cad_length )
+ {
+ if ( net_Write( p_access, p_sys->i_cam_handle, p_cad, i_cad_length )
+ != i_cad_length )
+ {
+ msg_Err( p_access, "write 2 failed (%s) %d", strerror(errno),
+ i_cad_length );
+ return -VLC_EGENERIC;
+ }
+ }
+
+ return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * CAMClose :
+ *****************************************************************************/
+void E_(CAMClose)( access_t * p_access )
+{
+ access_sys_t *p_sys = p_access->p_sys;
+
+ if ( p_sys->i_cam_handle )
+ {
+ close( p_sys->i_cam_handle );
+ }
+}
+
} iod_descriptor_t;
+#define MAX_CAD 10
+
typedef struct
{
dvbpsi_handle handle;
int i_version;
int i_number;
int i_pid_pcr;
+ int i_pid_pmt;
/* IOD stuff (mpeg4) */
iod_descriptor_t *iod;
+ /* Conditional Access descriptor */
+ int i_nb_cad;
+ uint8_t *cad[MAX_CAD];
+ uint8_t i_cad_length[MAX_CAD];
+
} ts_prg_psi_t;
typedef struct
}
else
{
- uint64_t i_ck = strtoll( psz, NULL, 16 );
+ uint64_t i_ck = strtoull( psz, NULL, 16 );
uint8_t ck[8];
int i;
for( i = 0; i < 8; i++ )
return VLC_EGENERIC;
#endif
case DEMUX_SET_GROUP:
+ {
+ uint16_t i_vpid = 0, i_apid1 = 0, i_apid2 = 0, i_apid3 = 0;
+ ts_prg_psi_t *p_prg = NULL;
+
i_int = (int)va_arg( args, int );
+ msg_Dbg( p_demux, "DEMUX_SET_GROUP %d", i_int );
+
if( p_sys->b_dvb_control && i_int > 0 && i_int != p_sys->i_dvb_program )
{
int i_pmt_pid = -1;
for( i_prg = 0; i_prg < pmt->psi->i_prg; i_prg++ )
{
- if( pmt->psi->prg[i_prg]->i_number == p_sys->i_dvb_program)
+ if( pmt->psi->prg[i_prg]->i_number == p_sys->i_dvb_program )
{
i_pmt_pid = p_sys->pmt[i]->i_pid;
break;
if( i_pmt_pid > 0 )
{
- stream_Control( p_demux->s, STREAM_CONTROL_ACCESS, ACCESS_SET_PRIVATE_ID_STATE, i_pmt_pid, VLC_FALSE );
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_STATE, i_pmt_pid,
+ VLC_FALSE );
/* All ES */
for( i = 2; i < 8192; i++ )
{
for( i_prg = 0; i_prg < pid->p_owner->i_prg; i_prg++ )
{
- if( pid->p_owner->prg[i_prg]->i_pid_pcr == i_pmt_pid && pid->es->id )
+ if( pid->p_owner->prg[i_prg]->i_pid_pmt == i_pmt_pid && pid->es->id )
{
/* We only remove es that aren't defined by extra pmt */
- stream_Control( p_demux->s, STREAM_CONTROL_ACCESS, ACCESS_SET_PRIVATE_ID_STATE, i, VLC_FALSE );
+ stream_Control( p_demux->s,
+ STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_STATE,
+ i, VLC_FALSE );
break;
}
}
if( pmt->psi->prg[i_prg]->i_number == i_int )
{
i_pmt_pid = p_sys->pmt[i]->i_pid;
+ p_prg = p_sys->pmt[i]->psi->prg[i_prg];
break;
}
}
}
if( i_pmt_pid > 0 )
{
- stream_Control( p_demux->s, STREAM_CONTROL_ACCESS, ACCESS_SET_PRIVATE_ID_STATE, i_pmt_pid, VLC_TRUE );
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_STATE, i_pmt_pid,
+ VLC_TRUE );
for( i = 2; i < 8192; i++ )
{
ts_pid_t *pid = &p_sys->pid[i];
for( i_prg = 0; i_prg < pid->p_owner->i_prg; i_prg++ )
{
- if( pid->p_owner->prg[i_prg]->i_pid_pcr == i_pmt_pid && pid->es->id )
+ if( pid->p_owner->prg[i_prg]->i_pid_pmt == i_pmt_pid && pid->es->id )
{
- /* We only remove es that aren't defined by extra pmt */
- stream_Control( p_demux->s, STREAM_CONTROL_ACCESS, ACCESS_SET_PRIVATE_ID_STATE, i, VLC_TRUE );
+ if ( pid->es->fmt.i_cat == VIDEO_ES && !i_vpid )
+ i_vpid = i;
+ if ( pid->es->fmt.i_cat == AUDIO_ES && !i_apid1 )
+ i_apid1 = i;
+ else if ( pid->es->fmt.i_cat == AUDIO_ES && !i_apid2 )
+ i_apid2 = i;
+ else if ( pid->es->fmt.i_cat == AUDIO_ES && !i_apid3 )
+ i_apid3 = i;
+
+ stream_Control( p_demux->s,
+ STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_STATE,
+ i, VLC_TRUE );
break;
}
}
}
+
+ /* Set CAM descrambling */
+ for ( i = 0; i < p_prg->i_nb_cad; i++ )
+ {
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_CA, p_prg->i_number,
+ i_vpid, i_apid1, i_apid2, i_apid3,
+ p_prg->i_cad_length[i],
+ p_prg->cad[i] );
+ }
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_CA, p_prg->i_number,
+ 0, 0, 0, 0, 0, NULL );
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_CA, 0,
+ 0, 0, 0, 0, 0, NULL );
}
}
return VLC_SUCCESS;
+ }
case DEMUX_GET_FPS:
case DEMUX_SET_TIME:
prg->i_version = -1;
prg->i_number = -1;
prg->i_pid_pcr = -1;
+ prg->i_pid_pmt = -1;
prg->iod = NULL;
+ prg->i_nb_cad = 0;
prg->handle = NULL;
TAB_APPEND( pid->psi->i_prg, pid->psi->prg, prg );
if( pid->psi->handle ) dvbpsi_DetachPMT( pid->psi->handle );
for( i = 0; i < pid->psi->i_prg; i++ )
{
+ int j;
if( pid->psi->prg[i]->iod )
IODFree( pid->psi->prg[i]->iod );
+ for ( j = 0; j < pid->psi->prg[i]->i_nb_cad; j++ )
+ free( pid->psi->prg[i]->cad[j] );
if( pid->psi->prg[i]->handle )
dvbpsi_DetachPMT( pid->psi->prg[i]->handle );
free( pid->psi->prg[i] );
ts_prg_psi_t *prg = NULL;
int i;
+ /* CA descriptor */
+ uint16_t i_vpid = 0, i_apid1 = 0, i_apid2 = 0, i_apid3 = 0;
+
msg_Dbg( p_demux, "PMTCallBack called" );
/* First find this PMT declared in PAT */
IODFree( prg->iod );
prg->iod = NULL;
}
+ for ( i = 0; i < prg->i_nb_cad; i++ )
+ free( prg->cad[i] );
+ prg->i_nb_cad = 0;
msg_Dbg( p_demux, "new PMT program number=%d version=%d pid_pcr=0x%x",
p_pmt->i_program_number, p_pmt->i_version, p_pmt->i_pcr_pid );
prg->iod = IODNew( p_dr->i_length, p_dr->p_data );
}
+ else if( p_dr->i_tag == 0x9 )
+ {
+ msg_Dbg( p_demux, " * descriptor : CA (0x9)" );
+
+ prg->cad[prg->i_nb_cad] = malloc( p_dr->i_length + 2 );
+ prg->cad[prg->i_nb_cad][0] = 0x9;
+ prg->cad[prg->i_nb_cad][1] = p_dr->i_length;
+ memcpy( prg->cad[prg->i_nb_cad] + 2, p_dr->p_data, p_dr->i_length );
+ prg->i_cad_length[prg->i_nb_cad] = p_dr->i_length + 2;
+ prg->i_nb_cad++;
+ }
else
{
msg_Dbg( p_demux, " * descriptor : unknown (0x%x)", p_dr->i_tag );
PIDFillFormat( pid, p_es->i_type );
pid->i_owner_number = prg->i_number;
+ if ( pid->es->fmt.i_cat == VIDEO_ES && !i_vpid )
+ i_vpid = p_es->i_pid;
+ if ( pid->es->fmt.i_cat == AUDIO_ES && !i_apid1 )
+ i_apid1 = p_es->i_pid;
+ else if ( pid->es->fmt.i_cat == AUDIO_ES && !i_apid2 )
+ i_apid2 = p_es->i_pid;
+ else if ( pid->es->fmt.i_cat == AUDIO_ES && !i_apid3 )
+ i_apid3 = p_es->i_pid;
+
if( p_es->i_type == 0x10 || p_es->i_type == 0x11 ||
p_es->i_type == 0x12 )
{
es_out_Add( p_demux->out, &pid->extra_es[i]->fmt);
}
}
+
+ for( p_dr = p_es->p_first_descriptor; p_dr != NULL;
+ p_dr = p_dr->p_next )
+ {
+ if( p_dr->i_tag == 0x9 )
+ {
+ msg_Dbg( p_demux, " * descriptor : CA (0x9)" );
+
+ prg->cad[prg->i_nb_cad] = malloc( p_dr->i_length + 2 );
+ prg->cad[prg->i_nb_cad][0] = 0x9;
+ prg->cad[prg->i_nb_cad][1] = p_dr->i_length;
+ memcpy( prg->cad[prg->i_nb_cad] + 2, p_dr->p_data, p_dr->i_length );
+ prg->i_cad_length[prg->i_nb_cad] = p_dr->i_length + 2;
+ prg->i_nb_cad++;
+ }
+ else
+ {
+ msg_Dbg( p_demux, " * descriptor : unknown (0x%x)",
+ p_dr->i_tag );
+ }
+ }
+
if( p_sys->b_dvb_control &&
( p_sys->i_dvb_program < 0 || p_sys->i_dvb_program == prg->i_number ) )
{
- stream_Control( p_demux->s, STREAM_CONTROL_ACCESS, ACCESS_SET_PRIVATE_ID_STATE, p_es->i_pid, VLC_FALSE );
+ /* Set demux filter */
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_STATE, p_es->i_pid,
+ VLC_TRUE );
}
}
dvbpsi_DeletePMT(p_pmt);
+
+ if( p_sys->b_dvb_control &&
+ ( p_sys->i_dvb_program < 0 || p_sys->i_dvb_program == prg->i_number ) )
+ {
+ /* Set CAM descrambling */
+ for ( i = 0; i < prg->i_nb_cad; i++ )
+ {
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_CA, prg->i_number,
+ i_vpid, i_apid1, i_apid2, i_apid3,
+ prg->i_cad_length[i], prg->cad[i] );
+ }
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_CA, prg->i_number,
+ 0, 0, 0, 0, 0, NULL );
+ stream_Control( p_demux->s, STREAM_CONTROL_ACCESS,
+ ACCESS_SET_PRIVATE_ID_CA, 0,
+ 0, 0, 0, 0, 0, NULL );
+ }
}
static void PATCallBack( demux_t *p_demux, dvbpsi_pat_t *p_pat )
int i_prg;
for( i_prg = 0; i_prg < pid->p_owner->i_prg; i_prg++ )
{
- if( pid->p_owner->prg[i_prg]->i_pid_pcr ==
+ if( pid->p_owner->prg[i_prg]->i_pid_pmt ==
pmt_rm[j]->i_pid && pid->es->id )
{
/* We only remove es that aren't defined by extra pmt */
p_demux );
pmt->psi->prg[pmt->psi->i_prg-1]->i_number =
p_program->i_number;
+ pmt->psi->prg[pmt->psi->i_prg-1]->i_pid_pmt =
+ p_program->i_pid;
/* Now select PID at access level */
if( p_sys->b_dvb_control )