Commit 057ed2ca authored by Jean-Paul Saman's avatar Jean-Paul Saman

Rework in DVB plugin to allow tuning to DVB-T cards.

- cleanup of messages
- adding status events messages from frontend
- separated tuning for DVB-S, DVB-T and DVB-C into seperate functions.
parent e26f8fd1
......@@ -334,7 +334,7 @@ int E_(Open) ( vlc_object_t *p_this )
}
else
{
msg_Warn(p_input,"DVV Input syntax has changed, please see documentation for further informations");
msg_Warn(p_input,"DVB Input syntax has changed, please see documentation for further informations");
u_freq = (unsigned int)i_test;
if( *psz_next )
{
......@@ -408,7 +408,9 @@ int E_(Open) ( vlc_object_t *p_this )
return -1;
}
}
/* Setting frontend parameters for tuning the hardware */
msg_Dbg( p_input, "Trying to tune to channel ...");
switch( frontend_info.type )
{
/* DVB-S: satellite and budget cards (nova) */
......@@ -418,6 +420,14 @@ int E_(Open) ( vlc_object_t *p_this )
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 );
if (ioctl_SetQPSKFrontend (p_input, fep, b_polarisation,
u_lnb_lof1, u_lnb_lof2, u_lnb_slof,
u_adapter, u_device )<0)
{
msg_Err( p_input, "DVB-S frontend returned a failure event" );
return -1;
}
break;
/* DVB-C */
......@@ -428,6 +438,11 @@ int E_(Open) ( vlc_object_t *p_this )
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 );
if (ioctl_SetQAMFrontend (p_input, fep, u_adapter, u_device )<0)
{
msg_Err( p_input, "DVB-C frontend returned a failure event" );
return -1;
}
break;
/* DVB-T */
......@@ -442,12 +457,17 @@ int E_(Open) ( vlc_object_t *p_this )
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 );
if (ioctl_SetOFDMFrontend (p_input, fep,u_adapter, u_device )<0)
{
msg_Err( p_input, "DVB-T frontend returned a failure event" );
return -1;
}
break;
default:
msg_Err( p_input, "Could not determine frontend type on %s", frontend_info.name );
return -1;
}
msg_Dbg( p_input, "Tuning done.");
/* Initialise structure */
p_satellite = malloc( sizeof( input_socket_t ) );
......@@ -481,40 +501,6 @@ int E_(Open) ( vlc_object_t *p_this )
return -1;
}
/* 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 ))
{
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:
break;
}
msg_Dbg( p_input, "setting filter on PAT" );
/* Set Filter on PAT packet */
......
......@@ -187,6 +187,7 @@ int ioctl_InfoFrontend(input_thread_t * p_input, struct dvb_frontend_info *info,
return 0;
}
/* QPSK only */
int ioctl_DiseqcSendMsg (input_thread_t *p_input, int fd, fe_sec_voltage_t v, struct diseqc_cmd_t **cmd,
fe_sec_tone_mode_t t, fe_sec_mini_cmd_t b)
{
......@@ -258,6 +259,7 @@ int ioctl_DiseqcSendMsg (input_thread_t *p_input, int fd, fe_sec_voltage_t v, st
return err;
}
/* QPSK only */
int ioctl_SetupSwitch (input_thread_t *p_input, int frontend_fd, int switch_pos,
int voltage_18, int hiband)
{
......@@ -288,14 +290,13 @@ int ioctl_SetupSwitch (input_thread_t *p_input, int frontend_fd, int switch_pos,
}
/*****************************************************************************
* ioctl_SetFrontend : controls the FE device
* ioctl_SetQPSKFrontend : controls the FE device
*****************************************************************************/
int ioctl_SetFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep, int b_polarisation,
int ioctl_SetQPSKFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep, int b_polarisation,
unsigned int u_lnb_lof1, unsigned int u_lnb_lof2, unsigned int u_lnb_slof,
unsigned int u_adapter, unsigned int u_device )
{
int ret;
int i;
int front;
int hiband;
char frontend[] = FRONTEND;
......@@ -304,18 +305,18 @@ int ioctl_SetFrontend (input_thread_t * p_input, struct dvb_frontend_parameters
i_len = sizeof(FRONTEND);
if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
{
msg_Err(p_input, "ioctl_SetFrontEnd snprintf() truncated string for FRONTEND" );
msg_Err(p_input, "DVB-S: FrontEnd snprintf() truncated string for FRONTEND" );
frontend[sizeof(FRONTEND)] = '\0';
}
/* Open the frontend device */
msg_Dbg(p_input, "Opening frontend %s", frontend);
msg_Dbg(p_input, "DVB-S: Opening frontend %s", frontend);
if(( front = open(frontend,O_RDWR)) < 0)
{
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "failed to open frontend (%s)", strerror(errno));
msg_Err(p_input, "DVB-S: failed to open frontend (%s)", strerror(errno));
# else
msg_Err(p_input, "failed to open frontend");
msg_Err(p_input, "DVB-S: failed to open frontend");
# endif
return -1;
}
......@@ -326,7 +327,7 @@ int ioctl_SetFrontend (input_thread_t * p_input, struct dvb_frontend_parameters
if ((ret=ioctl_SetupSwitch (p_input, front, 0, b_polarisation, hiband))<0)
{
msg_Err(p_input, "ioctl_SetupSwitch failed (%d)", ret);
msg_Err(p_input, "DVB-S: Setup frontend switch failed (%d)", ret);
return -1;
}
......@@ -340,41 +341,110 @@ int ioctl_SetFrontend (input_thread_t * p_input, struct dvb_frontend_parameters
{
close(front);
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "ioctl_SetFrontend: ioctl FE_SET_FRONTEND failed (%d) %s", ret, strerror(errno));
msg_Err(p_input, "DVB-S: setting frontend failed (%d) %s", ret, strerror(errno));
# else
msg_Err(p_input, "ioctl_SetFrontend: ioctl FE_SET_FRONTEND failed (%d)", ret);
msg_Err(p_input, "DVB-S: setting frontend failed (%d)", ret);
# endif
return -1;
}
for (i=0; i<3; i++)
ret = ioctl_CheckFrontend(p_input, front);
/* Fixme: Return this instead of closing it.
Close front end device */
close(front);
return ret;
}
int ioctl_SetOFDMFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep,
unsigned int u_adapter, unsigned int u_device )
{
int ret;
int front;
char frontend[] = FRONTEND;
int i_len;
i_len = sizeof(FRONTEND);
if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
{
fe_status_t s;
if ((ret=ioctl(front, FE_READ_STATUS, &s))<0)
msg_Err(p_input, "DVB-T FrontEnd snprintf() truncated string for FRONTEND" );
frontend[sizeof(FRONTEND)] = '\0';
}
/* Open the frontend device */
msg_Dbg(p_input, "DVB-T: Opening frontend %s", frontend);
if(( front = open(frontend,O_RDWR)) < 0)
{
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "ioctl FE_READ_STATUS failed (%d) %s", ret, strerror(errno));
msg_Err(p_input, "DVB-T: failed to open frontend (%s)", strerror(errno));
# else
msg_Err(p_input, "ioctl FE_READ_STATUS failed (%d)", ret);
msg_Err(p_input, "DVB-T: failed to open frontend");
# endif
return -1;
}
if (s & FE_HAS_LOCK)
/* Now send it all to the frontend device */
if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0)
{
msg_Dbg(p_input, "ioctl_SetFrontend: tuning status == 0x%02x!!! ..."
"tuning succeeded", s);
ret = 0;
break;
close(front);
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "DVB-T: setting frontend failed (%d) %s", ret, strerror(errno));
# else
msg_Err(p_input, "DVB-T: setting frontend failed (%d)", ret);
# endif
return -1;
}
else
ret = ioctl_CheckFrontend(p_input, front);
/* Fixme: Return this instead of closing it.
Close front end device */
close(front);
return ret;
}
int ioctl_SetQAMFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep,
unsigned int u_adapter, unsigned int u_device )
{
int ret;
int front;
char frontend[] = FRONTEND;
int i_len;
i_len = sizeof(FRONTEND);
if (snprintf(frontend, sizeof(FRONTEND), FRONTEND, u_adapter, u_device) >= i_len)
{
msg_Dbg(p_input, "ioctl_SetFrontend: tuning status == 0x%02x!!! ..."
"tuning failed", s);
ret = -1;
msg_Err(p_input, "DVB-C: FrontEnd snprintf() truncated string for FRONTEND" );
frontend[sizeof(FRONTEND)] = '\0';
}
usleep( 500000 );
/* Open the frontend device */
msg_Dbg(p_input, "DVB-C: Opening frontend %s", frontend);
if(( front = open(frontend,O_RDWR)) < 0)
{
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "DVB-C: failed to open frontend (%s)", strerror(errno));
# else
msg_Err(p_input, "DVB-C: failed to open frontend");
# endif
return -1;
}
/* Now send it all to the frontend device */
if ((ret=ioctl(front, FE_SET_FRONTEND, &fep)) < 0)
{
close(front);
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "DVB-C: setting frontend failed (%d) %s", ret, strerror(errno));
# else
msg_Err(p_input, "DVB-C: setting frontend failed (%d)", ret);
# endif
return -1;
}
/* Check Status of frontend */
ret = ioctl_CheckFrontend(p_input, front);
/* Fixme: Return this instead of closing it.
Close front end device */
close(front);
......@@ -386,6 +456,7 @@ int ioctl_SetFrontend (input_thread_t * p_input, struct dvb_frontend_parameters
******************************************************************/
static int ioctl_CheckFrontend(input_thread_t * p_input, int front)
{
int i;
int ret;
struct pollfd pfd[1];
struct dvb_frontend_event event;
......@@ -393,6 +464,61 @@ static int ioctl_CheckFrontend(input_thread_t * p_input, int front)
pfd[0].fd = front;
pfd[0].events = POLLIN;
#if 1
for (i=0; i<3; i++)
{
fe_status_t status;
if ((ret=ioctl(front, FE_READ_STATUS, &status))<0)
{
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "reading frontend status failed (%d) %s", ret, strerror(errno));
# else
msg_Err(p_input, "reading frontend status failed (%d)", ret);
# endif
}
if (status & FE_HAS_SIGNAL) /* found something above the noise level */
msg_Dbg(p_input, "check frontend ... has signal");
if (status & FE_HAS_CARRIER) /* found a DVB signal */
msg_Dbg(p_input, "check frontend ... has carrier");
if (status & FE_HAS_VITERBI) /* FEC is stable */
msg_Dbg(p_input, "check frontend ... has stable fec");
if (status & FE_HAS_SYNC) /* found sync bytes */
msg_Dbg(p_input, "check frontend ... has sync");
if (status & FE_HAS_LOCK) /* everything's working... */
{
msg_Dbg(p_input, "check frontend ... has lock");
msg_Dbg(p_input, "check frontend ... tuning status == 0x%02x!!! ..."
"tuning succeeded", status);
return 0;
}
if (status & FE_TIMEDOUT) /* no lock within the last ~2 seconds */
{
msg_Dbg(p_input, "check frontend ... tuning status == 0x%02x!!! ..."
"tuning failed", status);
msg_Err(p_input, "check frontend ... timed out");
return -2;
}
if (status & FE_REINIT)
{
/* frontend was reinitialized, */
/* application is recommned to reset */
/* DiSEqC, tone and parameters */
msg_Dbg(p_input, "DVB-S: tuning status == 0x%02x!!! ..."
"tuning failed", status);
msg_Err(p_input, "check frontend ... resend frontend parameters");
return -1;
}
usleep( 500000 );
}
#else
if (poll(pfd,1,3000))
{
if (pfd[0].revents & POLLIN)
......@@ -400,9 +526,9 @@ static int ioctl_CheckFrontend(input_thread_t * p_input, int front)
if ( (ret=ioctl(front, FE_GET_EVENT, &event)) < 0)
{
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "ioctl_CheckFrontend: ioctl FE_GET_EVENT failed (%d) %s", ret, strerror(errno));
msg_Err(p_input, "check frontend ... error occured (%d) %s", ret, strerror(errno));
# else
msg_Err(p_input, "ioctl_CheckFrontend: ioctl FE_GET_EVENT failed (%d)", ret);
msg_Err(p_input, "check frontend ... error occured (%d)", ret);
# endif
return -5;
}
......@@ -410,48 +536,49 @@ static int ioctl_CheckFrontend(input_thread_t * p_input, int front)
switch(event.status)
{
case FE_HAS_SIGNAL: /* found something above the noise level */
msg_Dbg(p_input, "ioctl_CheckFrontend: FE_HAS_SIGNAL");
msg_Dbg(p_input, "check frontend ... has signal");
break;
case FE_HAS_CARRIER: /* found a DVB signal */
msg_Dbg(p_input, "ioctl_CheckFrontend: FE_HAS_CARRIER");
msg_Dbg(p_input, "check frontend ... has carrier");
break;
case FE_HAS_VITERBI: /* FEC is stable */
msg_Dbg(p_input, "ioctl_CheckFrontend: FE_HAS_VITERBI");
msg_Dbg(p_input, "check frontend ... has stable fec");
break;
case FE_HAS_SYNC: /* found sync bytes */
msg_Dbg(p_input, "ioctl_CheckFrontend: FE_HAS_SYNC");
msg_Dbg(p_input, "check frontend ... has sync");
break;
case FE_HAS_LOCK: /* everything's working... */
msg_Dbg(p_input, "ioctl_CheckFrontend: FE_HAS_LOCK");
break;
msg_Dbg(p_input, "check frontend ... has lock");
return 0;
case FE_TIMEDOUT: /* no lock within the last ~2 seconds */
msg_Dbg(p_input, "ioctl_CheckFrontend: FE_TIMEDOUT");
msg_Err(p_input, "check frontend ... timed out");
return -2;
case FE_REINIT: /* frontend was reinitialized, */
/* application is recommned to reset */
/* DiSEqC, tone and parameters */
msg_Dbg(p_input, "ioctl_CheckFrontend: FE_REINIT");
msg_Err(p_input, "check frontend ... resend frontend parameters");
return -1;
}
}
else
{
/* should come here */
msg_Err(p_input, "ioctl_CheckFrontend: event() failed");
msg_Err(p_input, "check frontend ... no event occured");
return -3;
}
}
else
{
# ifdef HAVE_ERRNO_H
msg_Err(p_input, "ioctl_CheckFrontend: poll() failed (%s)", strerror(errno));
msg_Err(p_input, "check frontend ... timeout when polling for event (%s)", strerror(errno));
# else
msg_Err(p_input, "ioctl_CheckFrontend: poll() failed");
msg_Err(p_input, "check frontend ... timeout when polling for event ");
# endif
return -4;
}
#endif
return 0;
return -1;
}
/*****************************************************************************
......
......@@ -33,9 +33,13 @@
/*****************************************************************************
* Prototypes
*****************************************************************************/
int ioctl_SetFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep, int b_polarisation,
int ioctl_SetQPSKFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep, int b_polarisation,
unsigned int u_lnb_lof1, unsigned int u_lnb_lof2, unsigned int u_lnb_slof,
unsigned int u_adapter, unsigned int u_device );
int ioctl_SetOFDMFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep,
unsigned int u_adapter, unsigned int u_device );
int ioctl_SetQAMFrontend (input_thread_t * p_input, struct dvb_frontend_parameters fep,
unsigned int u_adapter, unsigned int u_device );
int ioctl_SetDMXFilter(input_thread_t * p_input, int i_pid, int *pi_fd, int i_type, unsigned int u_adapter, unsigned int u_device );
int ioctl_UnsetDMXFilter(input_thread_t * p_input, int pi_fd);
int ioctl_InfoFrontend(input_thread_t * p_input, struct dvb_frontend_info *info, unsigned int u_adapter, unsigned int u_device );
......@@ -50,3 +54,4 @@ fe_transmit_mode_t dvb_DecodeTransmission(input_thread_t * p_input, int transmis
fe_guard_interval_t dvb_DecodeGuardInterval(input_thread_t * p_input, int guard);
fe_hierarchy_t dvb_DecodeHierarchy(input_thread_t * p_input, int hierarchy);
fe_spectral_inversion_t dvb_DecodeInversion(input_thread_t * p_input, int inversion);
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