Commit a82c7e3e authored by Laurent Aimar's avatar Laurent Aimar
Browse files

* dvn: first pass to port dvb to new api. (it doesn't even yet compile,

I haven't tried :)
parent 299cea2f
......@@ -6,6 +6,7 @@
* Authors: Johan Bilien <jobi@via.ecp.fr>
* 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
......@@ -26,14 +27,9 @@
/*****************************************************************************
* 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
......@@ -41,36 +37,16 @@
#include <fcntl.h>
#include <sys/types.h>
#ifdef HAVE_ERRNO_H
# include <string.h>
# include <errno.h>
#endif
#ifdef STRNCASECMP_IN_STRINGS_H
# include <strings.h>
#endif
#include <errno.h>
#include "dvb.h"
#define SATELLITE_READ_ONCE 3
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static int Open( vlc_object_t *p_this );
static void Close( vlc_object_t *p_this );
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer,
size_t i_len);
static int SetArea ( input_thread_t *, input_area_t * );
static int SetProgram ( input_thread_t *, pgrm_descriptor_t * );
static void Seek ( input_thread_t *, off_t );
static void AllocateDemux( input_thread_t * p_input, int i_pid,
int i_type );
static void CloseProgram( input_thread_t * p_input );
/*****************************************************************************
* Module descriptor
*****************************************************************************/
static int Open( vlc_object_t *p_this );
static void Close( vlc_object_t *p_this );
#define CACHING_TEXT N_("Caching value in ms")
#define CACHING_LONGTEXT N_( \
"Allows you to modify the default caching value for dvb streams. This " \
......@@ -206,218 +182,106 @@ vlc_module_begin();
set_callbacks( Open, Close );
vlc_module_end();
/*****************************************************************************
* Open: open the frontend device
* Local prototypes
*****************************************************************************/
#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_input, "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_input, "dvb-" option, val ); \
}
static int Open( vlc_object_t *p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
thread_dvb_data_t * p_dvb;
char * psz_parser;
char * psz_next;
vlc_value_t val;
int i_test;
/* Initialize structure */
p_dvb = (thread_dvb_data_t *)malloc( sizeof( thread_dvb_data_t ) );
if( p_dvb == NULL )
{
msg_Err( p_input, "out of memory" );
return -1;
}
memset( p_dvb, 0, sizeof(thread_dvb_data_t) );
p_input->p_access_data = (void *)p_dvb;
/* Register callback functions */
p_input->pf_read = Read;
p_input->pf_set_program = SetProgram;
p_input->pf_set_area = SetArea;
p_input->pf_seek = Seek;
static block_t *Block( access_t * );
static int Control( access_t *, int, va_list );
/* Parse the options passed in command line */
psz_parser = strdup( p_input->psz_name );
if ( !psz_parser )
{
free( p_dvb );
return( -1 );
}
var_Create( p_input, "dvb-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Get( p_input, "dvb-caching", &val );
p_input->i_pts_delay = val.i_int * 1000;
var_Create( p_input, "dvb-adapter", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-device", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-frequency", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-inversion", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-probe", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-lnb-lof1", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-lnb-lof2", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-lnb-slof", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
#define SATELLITE_READ_ONCE 3
#if 0
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer,
size_t i_len);
static int SetArea ( input_thread_t *, input_area_t * );
static int SetProgram ( input_thread_t *, pgrm_descriptor_t * );
static void Seek ( input_thread_t *, off_t );
static void AllocateDemux( input_thread_t * p_input, int i_pid,
int i_type );
static void CloseProgram( input_thread_t * p_input );
#endif
var_Create( p_input, "dvb-budget-mode", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-satno", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-voltage", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-tone", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-fec", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-srate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
static void FilterUnset( access_t *, int i_start, int i_max );
static void FilterSet( access_t *, int i_pid, int i_type );
var_Create( p_input, "dvb-modulation", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
static void VarInit( access_t * );
static int ParseMRL( access_t * );
var_Create( p_input, "dvb-code-rate-hp", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-code-rate-lp", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-bandwidth", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-transmission", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-guard", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
var_Create( p_input, "dvb-hierarchy", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
i_test = strtol( psz_parser, &psz_next, 10 );
if ( psz_next == psz_parser )
{
for ( ; ; )
{
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=" ) ) )
{
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_input, "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
{
msg_Err( p_input, "illegal polarization %c", *psz_parser );
free( p_dvb );
return -1;
}
var_Set( p_input, "dvb-voltage", val );
}
if ( *psz_parser )
psz_parser++;
else
break;
}
}
else
/*****************************************************************************
* Open: open the frontend device
*****************************************************************************/
static int Open( vlc_object_t *p_this )
{
access_t *p_access = (access_t*)p_this;
access_sys_t *p_sys;
/* Only if selected */
if( *p_access->psz_acces == '\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 ) )
{
msg_Err( p_input, "the DVB input old syntax is deprecated, use vlc " \
"-p dvb to see an explanation of the new syntax" );
free( p_dvb );
return -1;
free( p_sys );
return VLC_EGENERIC;
}
/* Getting frontend info */
if ( E_(FrontendOpen)( p_input ) < 0 )
if( E_(FrontendOpen)( p_access) )
{
free( p_dvb );
return -1;
free( p_sys );
return VLC_EGENERIC;
}
/* Setting frontend parameters for tuning the hardware */
msg_Dbg( p_input, "trying to tune the frontend...");
if ( E_(FrontendSet)( p_input ) < 0 )
/* Setting frontend parameters for tuning the hardware */
msg_Dbg( p_access, "trying to tune the frontend...");
if( E_(FrontendSet)( p_access ) < 0 )
{
E_(FrontendClose)( p_input );
free( p_dvb );
return -1;
E_(FrontendClose)( p_access );
free( p_sys );
return VLC_EGENERIC;
}
/* Opening DVR device */
if ( E_(DVROpen)( p_input ) < 0 )
/* Opening DVR device */
if( E_(DVROpen)( p_access ) < 0 )
{
E_(FrontendClose)( p_input );
free( p_dvb );
return -1;
E_(FrontendClose)( p_access );
free( p_sys );
return VLC_EGENERIC;
}
var_Get( p_input, "dvb-budget-mode", &val );
p_dvb->b_budget_mode = val.b_bool;
if ( val.b_bool )
p_sys->b_budget_mode = var_GetBool( p_access, "dvb-budget-mode" );
if( p_sys->b_budget_mode )
{
msg_Dbg( p_input, "setting filter on all PIDs" );
AllocateDemux( p_input, 0x2000, OTHER_TYPE );
msg_Dbg( p_access, "setting filter on all PIDs" );
AllocateDemux( p_access, 0x2000, OTHER_TYPE );
}
else
{
msg_Dbg( p_input, "setting filter on PAT" );
AllocateDemux( p_input, 0x0, OTHER_TYPE );
}
if( input_InitStream( p_input, sizeof( stream_ts_data_t ) ) == -1 )
{
msg_Err( p_input, "could not initialize stream structure" );
E_(FrontendClose)( p_input );
close( p_dvb->i_handle );
free( p_dvb );
return( -1 );
msg_Dbg( p_access, "setting filter on PAT" );
AllocateDemux( p_access, 0x0, OTHER_TYPE );
}
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.b_pace_control = 0;
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;
return VLC_SUCCESS;
}
/*****************************************************************************
......@@ -425,261 +289,311 @@ static int Open( vlc_object_t *p_this )
*****************************************************************************/
static void Close( vlc_object_t *p_this )
{
input_thread_t * p_input = (input_thread_t *)p_this;
thread_dvb_data_t * p_dvb = (thread_dvb_data_t *)p_input->p_access_data;
access_t *p_access = (access_t*)p_this;
access_sys_t *p_sys = p_access->p_sys;
if ( !p_dvb->b_budget_mode )
{
CloseProgram( p_input );
}
if ( p_dvb->p_demux_handles[0].i_type )
{
E_(DMXUnsetFilter)( p_input, p_dvb->p_demux_handles[0].i_handle );
p_dvb->p_demux_handles[0].i_type = 0;
}
E_(DVRClose)( p_input );
E_(FrontendClose)( p_input );
free( p_dvb );
FilterUnset( p_access, 0, p_sys->b_budget_mode ? 1 : MAX_DEMUX );
E_(DVRClose)( p_access );
E_(FrontendClose)( p_access );
free( p_sys );
}
/*****************************************************************************
* Read: reads data from the satellite card
* Block:
*****************************************************************************/
static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer,
size_t i_len )
static block_t *Block( access_t *p_access )
{
thread_dvb_data_t * p_dvb = (thread_dvb_data_t *)p_input->p_access_data;
ssize_t i_ret;
vlc_value_t val;
access_t *p_access = (access_t*)p_this;
access_sys_t *p_sys = p_access->p_sys;
struct timeval timeout;
fd_set fds;
if ( !p_dvb->b_budget_mode && !p_dvb->p_demux_handles[1].i_type )
{
int i_program;
unsigned int i;
var_Get( p_input, "program", &val );
i_program = val.i_int;
/* FIXME : this is not demux2-compatible */
for ( i = 0; i < p_input->stream.i_pgrm_number; i++ )
{
/* Only set a filter on the selected program : some boards
* (read: Dreambox) only have 8 filters, so you don't want to
* spend them on unwanted PMTs. --Meuuh */
if ( !i_program
|| p_input->stream.pp_programs[i]->i_number == i_program )
{
msg_Dbg( p_input, "setting filter on PMT pid %d",
p_input->stream.pp_programs[i]->pp_es[0]->i_id );
AllocateDemux( p_input,
p_input->stream.pp_programs[i]->pp_es[0]->i_id,
OTHER_TYPE );
}
}
}
/* Find if some data is available. This won't work under Windows. */
int i_ret;
block_t *p_block;
/* Initialize file descriptor set */
FD_ZERO( &fds );
FD_SET( p_dvb->i_handle, &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_dvb->i_handle + 1, &fds,
NULL, NULL, &timeout )) == 0
|| (i_ret < 0 && errno == EINTR) )
while( (i_ret = select( p_sys->i_handle + 1, &fds, NULL, NULL, &timeout )) == 0 ||
(i_ret < 0 && errno == EINTR) )
{
FD_ZERO( &fds );
FD_SET( p_dvb->i_handle, &fds );
FD_SET( p_sys->i_handle, &fds );
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
if ( p_input->b_die || p_input->b_error )
{
return 0;
}
if( p_access->b_die )
return NULL;
}
if ( i_ret < 0 )
{
#ifdef HAVE_ERRNO_H
msg_Err( p_input, "select error (%s)", strerror(errno) );
#else
msg_Err( p_input, "select error" );
#endif
return -1;
return NULL;
}
i_ret = read( p_dvb->i_handle, p_buffer, i_len );
if( i_ret < 0 )
p_block = block_New( p_access, p_sys->i_mtu );
if( ( p_block->i_buffer = read( p_sys->i_handle, p_block->p_buffer, SATELLITE_READ_ONCE * TS_PACKET_SIZE ) ) <= 0 )
{
#ifdef HAVE_ERRNO_H
msg_Err( p_input, "read failed (%s)", strerror(errno) );
#else
msg_Err( p_input, "read failed" );
#endif
block_Release( p_block );
return NULL;
}
return i_ret;
}
/*****************************************************************************
* SetArea : Does nothing
*****************************************************************************/
static int SetArea( input_thread_t * p_input, input_area_t * p_area )
{
return -1;
return p_block;
}
/*****************************************************************************
* SetProgram : Sets the card filters according to the selected program,
* and makes the appropriate changes to stream structure.
* Control:
*****************************************************************************/
static int SetProgram( input_thread_t * p_input,
pgrm_descriptor_t * p_new_prg )
static int Control( access_t *p_access, int i_query, va_list args )
{
thread_dvb_data_t * p_dvb = (thread_dvb_data_t *)p_input->p_access_data;
unsigned int i_es_index;
vlc_value_t val;
int i_video_type = VIDEO0_TYPE;
int i_audio_type = AUDIO0_TYPE;
if ( p_input->stream.p_selected_program )
{
for ( i_es_index = 0; /* 0 should be the PMT */
i_es_index < p_input->stream.p_selected_program->i_es_number;
i_es_index ++ )
{
#define p_es p_input->stream.p_selected_program->pp_es[i_es_index]
if ( p_es->p_dec )
{
input_UnselectES( p_input , p_es );
}
#undef p_es
}
}
if ( !p_dvb->b_budget_mode )
{
msg_Dbg( p_input, "unsetting filters on all pids" );
CloseProgram( p_input );
msg_Dbg( p_input, "setting filter on PMT pid %d",
p_new_prg->pp_es[0]->i_id );
AllocateDemux( p_input, p_new_prg->pp_es[0]->i_id, OTHER_TYPE );
}
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;
vlc_value_t val;
for ( i_es_index = 1; i_es_index < p_new_prg->i_es_number;
i_es_index++ )
switch( i_query )
{
#define p_es p_new_prg->pp_es[i_es_index]
switch( p_es->i_cat )
{
case VIDEO_ES:
if ( !p_dvb->b_budget_mode )
{
msg_Dbg(p_input, "setting filter on video ES 0x%x",
p_es->i_id);
/* Always set the filter. This may seem a little odd, but
* it allows you to stream the video with demuxstream
* without having a decoder or a stream output behind.
* The result is you'll sometimes filter a PID which you
* don't really want, but in the most common cases it
* should be OK. --Meuuh */
AllocateDemux( p_input, p_es->i_id, i_video_type );
i_video_type += TYPE_INTERVAL;
}
input_SelectES( p_input, p_es );
/* */
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;
/* */
case ACCESS_GET_MTU:
pi_int = (int*)va_arg( args, int * );
*pi_int = SATELLITE_READ_ONCE * TS_PACKET_SIZE;
break;
case AUDIO_ES:
if ( !p_dvb->b_budget_mode )
{
msg_Dbg(p_input, "setting filter on audio ES 0x%x",
p_es->i_id);
AllocateDemux( p_input, p_es->i_id, i_audio_type );
i_audio_type += TYPE_INTERVAL;
}
input_SelectES( p_input, p_es );
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:
if ( !p_dvb->b_budget_mode )
/* */
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:
b_bool = (vlc_bool_t)va_arg( args, vlc_bool_t ); /* b_selected */
i_int = (int)va_arg( args, int ); /* Private data (pid for now)*/
if( !p_sys->b_budget_mode )
{
msg_Dbg(p_input, "setting filter on other ES 0x%x",
p_es->i_id);