Commit 4cc02ca6 authored by François Cartegnie's avatar François Cartegnie 🤞

access: dvb: scan: convert DVB-S v3 scan to scanlist

parent e51246e2
......@@ -388,7 +388,19 @@ static int ScanParametersDvbS( access_t *p_access, scan_parameter_t *p_scan )
p_scan->frequency.i_min = p_frontend->info.frequency_min;
p_scan->frequency.i_max = p_frontend->info.frequency_max;
/* set satellite config file path */
p_scan->sat_info.psz_name = var_InheritString( p_access, "dvb-satellite" );
char *psz_name = var_InheritString( p_access, "dvb-satellite" );
if( psz_name )
{
char *data_dir = config_GetDataDir();
if( !data_dir || -1 == asprintf( &p_scan->psz_scanlist_file,
"%s" DIR_SEP "dvb" DIR_SEP "dvb-s" DIR_SEP "%s", data_dir, psz_name ) )
{
p_scan->psz_scanlist_file = NULL;
}
p_scan->scanlist_format = FORMAT_DVBv3;
free( data_dir );
free( psz_name );
}
return VLC_SUCCESS;
}
......
......@@ -32,7 +32,6 @@
#include <vlc_common.h>
#include <vlc_block.h>
#include <vlc_dialog.h>
#include <vlc_fs.h>
#include <vlc_charset.h>
#include <vlc_access.h>
......@@ -82,14 +81,6 @@ typedef struct
} scan_service_t;
typedef struct
{
int i_frequency;
int i_symbol_rate;
int i_fec;
char c_polarization;
} scan_dvbs_transponder_t;
struct scan_t
{
vlc_object_t *p_obj;
......@@ -101,10 +92,6 @@ struct scan_t
int i_service;
scan_service_t **pp_service;
/* dvbv3 list file */
scan_dvbs_transponder_t *p_transponders;
unsigned i_transponders;
scan_list_entry_t *p_scanlist;
size_t i_scanlist;
const scan_list_entry_t *p_current;
......@@ -188,16 +175,27 @@ void scan_parameter_Init( scan_parameter_t *p_dst )
void scan_parameter_Clean( scan_parameter_t *p_dst )
{
if( p_dst->sat_info.psz_name )
free( p_dst->sat_info.psz_name );
free( p_dst->psz_scanlist_file );
}
static void scan_parameter_Copy( const scan_parameter_t *p_src, scan_parameter_t *p_dst )
{
scan_parameter_Clean( p_dst );
*p_dst = *p_src;
if( p_src->sat_info.psz_name )
p_dst->sat_info.psz_name = strdup( p_src->sat_info.psz_name );
if( p_src->psz_scanlist_file )
p_dst->psz_scanlist_file = strdup( p_src->psz_scanlist_file );
}
static void scan_Prepare( vlc_object_t *p_obj, const scan_parameter_t *p_parameter, scan_t *p_scan )
{
if( p_parameter->type == SCAN_DVB_S &&
p_parameter->psz_scanlist_file && p_parameter->scanlist_format == FORMAT_DVBv3 )
{
p_scan->p_scanlist =
scan_list_dvbv3_load( p_obj, p_parameter->psz_scanlist_file, &p_scan->i_scanlist );
if( p_scan->p_scanlist )
msg_Dbg( p_scan->p_obj, "using satellite config file (%s)", p_parameter->psz_scanlist_file );
}
}
static void scan_Debug_Parameters( vlc_object_t *p_obj, const scan_parameter_t *p_parameter )
......@@ -220,8 +218,8 @@ static void scan_Debug_Parameters( vlc_object_t *p_obj, const scan_parameter_t *
if( p_parameter->type == SCAN_DVB_C )
msg_Dbg( p_obj, " - scannin modulations %s", p_parameter->b_modulation_set ? "off" : "on" );
if( p_parameter->type == SCAN_DVB_S )
msg_Dbg( p_obj, " - satellite [%s]", p_parameter->sat_info.psz_name );
if( p_parameter->type == SCAN_DVB_S && p_parameter->psz_scanlist_file )
msg_Dbg( p_obj, " - satellite [%s]", p_parameter->psz_scanlist_file );
msg_Dbg( p_obj, " - use NIT %s", p_parameter->b_use_nit ? "on" : "off" );
msg_Dbg( p_obj, " - FTA only %s", p_parameter->b_free_only ? "on" : "off" );
......@@ -245,9 +243,11 @@ scan_t *scan_New( vlc_object_t *p_obj, const scan_parameter_t *p_parameter )
scan_parameter_Copy( p_parameter, &p_scan->parameter );
p_scan->i_time_start = mdate();
p_scan->p_scanlist = NULL;
p_scan->p_current = p_scan->p_scanlist;
p_scan->i_scanlist = 0;
scan_Prepare( p_obj, p_parameter, p_scan );
p_scan->p_current = p_scan->p_scanlist;
scan_Debug_Parameters( p_obj, p_parameter );
return p_scan;
......@@ -273,118 +273,30 @@ void scan_Destroy( scan_t *p_scan )
static int ScanDvbSNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double *pf_pos )
{
msg_Dbg( p_scan->p_obj, "Scan index %"PRId64, p_scan->i_index );
if( !p_scan->parameter.sat_info.psz_name )
{
msg_Err( p_scan->p_obj, "no satellite selected" );
return VLC_EGENERIC;
}
/* if there are no transponders in mem, laod from config file */
if( p_scan->i_transponders == 0 )
{
char *psz_path = NULL;
char *data_dir = config_GetDataDir();
if( !data_dir ||
asprintf( &psz_path, "%s" DIR_SEP "dvb" DIR_SEP "dvb-s" DIR_SEP "%s", data_dir,
p_scan->parameter.sat_info.psz_name ) == -1 )
{
free( data_dir );
return VLC_EGENERIC;
}
free( data_dir );
msg_Dbg( p_scan->p_obj, "using satellite config file (%s)", psz_path );
FILE *f = vlc_fopen( psz_path, "r" );
if( !f )
{
msg_Err( p_scan->p_obj, "failed to open satellite file (%s)", psz_path );
free( psz_path );
const scan_list_entry_t *p_entry = p_scan->p_current;
if( !p_entry )
return VLC_EGENERIC;
}
free( psz_path );
/* parse file */
scan_dvbs_transponder_t *p_transponders = malloc( sizeof( scan_dvbs_transponder_t ) );
if( !p_transponders )
{
fclose( f );
return VLC_ENOMEM;
}
char type;
char psz_fec[3];
int res;
do
{
if ( ( res = fscanf( f, "%c %d %c %d %2s\n",
&type,
&p_transponders[p_scan->i_transponders].i_frequency,
&p_transponders[p_scan->i_transponders].c_polarization,
&p_transponders[p_scan->i_transponders].i_symbol_rate,
psz_fec ) ) != 5 )
{
msg_Dbg( p_scan->p_obj, "error parsing transponder from file" );
continue;
}
/* decode fec */
char psz_fec_list[] = "1/22/33/44/55/66/77/88/9";
char *p_fec = strstr( psz_fec_list, psz_fec );
if ( !p_fec )
p_transponders[p_scan->i_transponders].i_fec = 9; /* FEC_AUTO */
else
p_transponders[p_scan->i_transponders].i_fec = 1 + ( ( p_fec-psz_fec_list ) / 3 );
p_scan->i_transponders++;
scan_dvbs_transponder_t *p_realloc = realloc( p_transponders, ( p_scan->i_transponders + 1 ) * sizeof(*p_realloc) );
if( p_realloc )
p_transponders = p_realloc;
else
res = EOF;
} while (res != EOF);
msg_Dbg( p_scan->p_obj, "parsed %d transponders from config", p_scan->i_transponders);
p_scan->p_transponders = p_transponders;
fclose( f );
}
if( p_scan->i_index < p_scan->i_transponders )
{
/* setup params for scan */
p_cfg->i_symbol_rate = p_scan->p_transponders[p_scan->i_index].i_symbol_rate / 1000;
p_cfg->i_frequency = p_scan->p_transponders[p_scan->i_index].i_frequency;
p_cfg->i_fec = p_scan->p_transponders[p_scan->i_index].i_fec;
p_cfg->c_polarization = p_scan->p_transponders[p_scan->i_index].c_polarization;
p_cfg->i_symbol_rate = p_entry->i_rate / 1000;
p_cfg->i_frequency = p_entry->i_freq;
p_cfg->i_fec = p_entry->i_fec;
p_cfg->c_polarization = ( p_entry->polarization == POLARIZATION_HORIZONTAL ) ? 'H' : 'V';
msg_Dbg( p_scan->p_obj,
"transponder [%"PRId64"/%d]: frequency=%d, symbolrate=%d, fec=%d, polarization=%c",
"transponder [%"PRId64"/%zd]: frequency=%d, symbolrate=%d, fec=%d, polarization=%c",
p_scan->i_index + 1,
p_scan->i_transponders,
p_scan->i_scanlist,
p_cfg->i_frequency,
p_cfg->i_symbol_rate,
p_cfg->i_fec,
p_cfg->c_polarization );
*pf_pos = (double)p_scan->i_index / p_scan->i_transponders;
p_scan->i_index++;
p_scan->p_current = p_scan->p_current->p_next;
*pf_pos = (double) p_scan->i_index / p_scan->i_scanlist;
return VLC_SUCCESS;
}
if( p_scan->p_transponders )
{
free( p_scan->p_transponders );
p_scan->p_transponders = NULL;
p_scan->i_transponders = 0;
}
return VLC_EGENERIC;
}
static int ScanDvbCNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double *pf_pos )
......
......@@ -59,11 +59,12 @@ typedef struct scan_parameter_t
unsigned i_count;
} bandwidth;
struct
char *psz_scanlist_file;
enum
{
char *psz_name; /* satellite name */
FORMAT_DVBv3,
} scanlist_format;
} sat_info;
} scan_parameter_t;
typedef struct
......
......@@ -79,6 +79,16 @@ static bool scan_list_entry_add( scan_list_entry_t ***ppp_last, scan_list_entry_
return false;
}
static void scan_list_parse_fec( scan_list_entry_t *p_entry, const char *psz )
{
const char *psz_fec_list = "1/22/33/44/55/66/77/88/9";
const char *psz_fec = strstr( psz_fec_list, psz );
if ( !psz_fec )
p_entry->i_fec = 9; /* FEC_AUTO */
else
p_entry->i_fec = 1 + ( ( psz_fec - psz_fec_list ) / 3 );
}
void scan_list_entries_release( scan_list_entry_t *p_list )
{
while( p_list )
......@@ -88,3 +98,96 @@ void scan_list_entries_release( scan_list_entry_t *p_list )
p_list = p_next;
}
}
scan_list_entry_t * scan_list_dvbv3_load( vlc_object_t *p_obj, const char *psz_source, size_t *pi_count )
{
FILE *p_file = vlc_fopen( psz_source, "r" );
if( !p_file )
{
msg_Err( p_obj, "failed to open satellite file (%s)", psz_source );
return NULL;
}
scan_list_entry_t *p_list = NULL;
scan_list_entry_t **pp_list_last = &p_list;
scan_list_entry_t *p_entry = NULL;
*pi_count = 0;
const char *psz_delims = " \t";
char *psz_line = NULL;
size_t i_len = 0;
ssize_t i_read;
while ( (i_read = getline( &psz_line, &i_len, p_file )) != -1 )
{
char *psz_token;
char *p_save = NULL;
if( p_entry && scan_list_entry_add( &pp_list_last, p_entry ) )
(*pi_count)++;
p_entry = scan_list_entry_New();
if( unlikely(p_entry == NULL) )
continue;
/* DELIVERY */
if( !(psz_token = strtok_r( psz_line, psz_delims, &p_save )) )
continue;
if( !strcmp( psz_token, "S" ) )
{
p_entry->delivery = DELIVERY_DVBS;
}
else if( !strcmp( psz_token, "S2" ) )
{
p_entry->delivery = DELIVERY_DVBS2;
}
/* Parse the delivery format */
if( p_entry->delivery == DELIVERY_DVBS || p_entry->delivery == DELIVERY_DVBS2 )
{
/* FREQUENCY */
if( !(psz_token = strtok_r( NULL, psz_delims, &p_save )) )
continue;
p_entry->i_freq = atoi( psz_token );
/* POLARIZATION */
if( !(psz_token = strtok_r( NULL, psz_delims, &p_save )) )
continue;
p_entry->polarization = !strcasecmp(psz_token, "H") ? POLARIZATION_HORIZONTAL
: POLARIZATION_VERTICAL;
/* RATE */
if( !(psz_token = strtok_r( NULL, psz_delims, &p_save )) )
continue;
p_entry->i_rate = atoi( psz_token );
/* FEC */
if( !(psz_token = strtok_r( NULL, psz_delims, &p_save )) )
continue;
scan_list_parse_fec( p_entry, psz_token );
/* INVERSION */
if( !(psz_token = strtok_r( NULL, psz_delims, &p_save )) )
continue;
/* MODULATION */
if( !(psz_token = strtok_r( NULL, psz_delims, &p_save )) )
continue;
/* STREAM_ID */
if( !(psz_token = strtok_r( NULL, psz_delims, &p_save )) )
continue;
p_entry->i_stream_id = atoi( psz_token );
}
}
if( p_entry && scan_list_entry_add( &pp_list_last, p_entry ) )
(*pi_count)++;
fclose( p_file );
return p_list;
}
......@@ -53,6 +53,8 @@ typedef struct scan_list_entry_t
} scan_list_entry_t;
scan_list_entry_t * scan_list_dvbv3_load( vlc_object_t *, const char *, size_t * );
void scan_list_entries_release( scan_list_entry_t * );
#endif
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