Commit 9c36906f authored by Christophe Massiot's avatar Christophe Massiot

* modules/demux/ts.c, modules/access/dvb: Added support for the CAM device

  of linuxtv drivers. We currently only descramble one channel (this will
  change in the near future). Also fixed a few demux-related bugs.
parent 61c73831
......@@ -55,6 +55,7 @@ enum access_query_e
/* Special mode for access/demux communication
* XXX: avoid to use it unless you can't */
ACCESS_SET_PRIVATE_ID_STATE, /* arg1= int i_private_data, vlc_bool_t b_selected can fail */
ACCESS_SET_PRIVATE_ID_CA, /* arg1= int i_program_number, uint16_t i_vpid, uint16_t i_apid1, uint16_t i_apid2, uint16_t i_apid3, uint8_t i_length, uint8_t *p_data */
};
struct access_t
......
......@@ -61,6 +61,9 @@ static void Close( vlc_object_t *p_this );
#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")
......@@ -131,6 +134,7 @@ vlc_module_begin();
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,
......@@ -273,6 +277,14 @@ static int Open( vlc_object_t *p_this )
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;
}
......@@ -288,6 +300,10 @@ static void Close( vlc_object_t *p_this )
E_(DVRClose)( p_access );
E_(FrontendClose)( p_access );
if ( p_sys->b_cam )
E_(CAMClose)( p_access );
free( p_sys );
}
......@@ -391,6 +407,27 @@ static int Control( access_t *p_access, int i_query, va_list args )
}
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;
......@@ -475,6 +512,7 @@ static void VarInit( access_t *p_access )
/* */
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 );
......@@ -513,8 +551,9 @@ static int ParseMRL( access_t *p_access )
#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 ) \
......@@ -522,7 +561,7 @@ static int ParseMRL( access_t *p_access )
{ \
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 */
......@@ -539,6 +578,7 @@ static int ParseMRL( access_t *p_access )
{
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")
......
......@@ -51,6 +51,8 @@ struct access_sys_t
demux_handle_t p_demux_handles[MAX_DEMUX];
frontend_t *p_frontend;
vlc_bool_t b_budget_mode;
vlc_bool_t b_cam;
int i_cam_handle;
};
#define VIDEO0_TYPE 1
......@@ -74,3 +76,7 @@ int E_(DMXUnsetFilter)( access_t *, int i_fd );
int E_(DVROpen)( access_t * );
void E_(DVRClose)( access_t * );
int E_(CAMOpen)( access_t * );
int E_(CAMSet)( access_t *, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t,
uint16_t, uint8_t * );
void E_(CAMClose)( access_t * );
......@@ -46,6 +46,9 @@
#include <linux/errno.h>
#include "dvb.h"
#include "network.h"
#define DMX_BUFFER_SIZE (1024 * 1024)
/*
* Frontends
......@@ -1083,6 +1086,12 @@ int E_(DVROpen)( access_t * p_access )
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;
}
......@@ -1096,3 +1105,76 @@ void E_(DVRClose)( access_t * p_access )
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 );
}
}
......@@ -183,6 +183,8 @@ typedef struct
} iod_descriptor_t;
#define MAX_CAD 10
typedef struct
{
dvbpsi_handle handle;
......@@ -190,9 +192,15 @@ typedef struct
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
......@@ -536,7 +544,7 @@ static int Open( vlc_object_t *p_this )
}
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++ )
......@@ -818,7 +826,13 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
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;
......@@ -832,7 +846,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
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;
......@@ -843,7 +857,9 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
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++ )
{
......@@ -854,10 +870,13 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
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;
}
}
......@@ -877,6 +896,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
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;
}
}
......@@ -884,7 +904,9 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
}
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];
......@@ -894,17 +916,45 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
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:
......@@ -944,7 +994,9 @@ static void PIDInit( ts_pid_t *pid, vlc_bool_t b_psi, ts_psi_t *p_owner )
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 );
......@@ -975,8 +1027,11 @@ static void PIDClean( es_out_t *out, ts_pid_t *pid )
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] );
......@@ -1859,6 +1914,9 @@ static void PMTCallBack( demux_t *p_demux, dvbpsi_pmt_t *p_pmt )
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 */
......@@ -1915,6 +1973,9 @@ static void PMTCallBack( demux_t *p_demux, dvbpsi_pmt_t *p_pmt )
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 );
......@@ -1931,6 +1992,17 @@ static void PMTCallBack( demux_t *p_demux, dvbpsi_pmt_t *p_pmt )
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 );
......@@ -1952,6 +2024,15 @@ static void PMTCallBack( demux_t *p_demux, dvbpsi_pmt_t *p_pmt )
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 )
{
......@@ -2241,13 +2322,57 @@ static void PMTCallBack( demux_t *p_demux, dvbpsi_pmt_t *p_pmt )
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 )
......@@ -2319,7 +2444,7 @@ 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 */
......@@ -2393,6 +2518,8 @@ static void PATCallBack( demux_t *p_demux, dvbpsi_pat_t *p_pat )
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 )
......
......@@ -394,7 +394,8 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
case STREAM_CONTROL_ACCESS:
i_int = (int) va_arg( args, int );
if( i_int != ACCESS_SET_PRIVATE_ID_STATE )
if( i_int != ACCESS_SET_PRIVATE_ID_STATE
&& i_int != ACCESS_SET_PRIVATE_ID_CA )
{
msg_Err( s, "Hey, what are you thinking ?"
"DON'T USE STREAM_CONTROL_ACCESS !!!" );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment