]> git.sesse.net Git - vlc/blobdiff - modules/access/dvb/scan.c
DVB-S scanning support
[vlc] / modules / access / dvb / scan.c
index cd855ed2baad5ba165d94fa85c51ac326e7f1524..fd69202ed2cdff73becf0b8da09cdd5fbb2c4a73 100644 (file)
@@ -1,9 +1,10 @@
 /*****************************************************************************
  * scan.c: DVB scanner helpers
  *****************************************************************************
- * Copyright (C) 2008 the VideoLAN team
+ * Copyright (C) 2008,2010 the VideoLAN team
  *
  * Authors: Laurent Aimar <fenrir@videolan.org>
+ *          David Kaplan <david@2of1.org>
  *
  * 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
@@ -31,6 +32,7 @@
 #include <vlc_plugin.h>
 #include <vlc_access.h>
 #include <vlc_dialog.h>
+#include <vlc_fs.h>
 
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
@@ -116,10 +118,17 @@ int scan_Init( vlc_object_t *p_obj, scan_t *p_scan, const scan_parameter_t *p_pa
                  p_parameter->bandwidth.i_min, p_parameter->bandwidth.i_max );
         msg_Dbg( p_obj, " - exhaustive mode %s", p_parameter->b_exhaustive ? "on" : "off" );
     }
+    else if( p_parameter->type == SCAN_DVB_S )
+    {
+        msg_Dbg( p_obj, "DVB-S scanning:" );
+        msg_Dbg( p_obj, " - satellite [%s]", p_parameter->sat_info.psz_name );
+    }
     else
     {
         return VLC_EGENERIC;
     }
+    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" );
 
     p_scan->p_obj = VLC_OBJECT(p_obj);
     p_scan->i_index = 0;
@@ -130,6 +139,7 @@ int scan_Init( vlc_object_t *p_obj, scan_t *p_scan, const scan_parameter_t *p_pa
 
     return VLC_SUCCESS;
 }
+
 void scan_Clean( scan_t *p_scan )
 {
     if( p_scan->p_dialog != NULL )
@@ -140,6 +150,157 @@ void scan_Clean( scan_t *p_scan )
     TAB_CLEAN( p_scan->i_service, p_scan->pp_service );
 }
 
+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 );
+
+    int *pi_count = &p_scan->parameter.sat_info.i_count;
+
+    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( !*pi_count )
+    {
+        scan_dvbs_transponder_t *p_transponders = malloc( sizeof( scan_dvbs_transponder_t ) );
+
+        DIR *p_dir;
+
+        char *psz_dir = NULL;
+        char *data_dir = config_GetDataDir( p_scan->p_obj );
+
+        if( asprintf( &psz_dir, "%s" DIR_SEP "dvb" DIR_SEP "dvb-s", data_dir ) == -1 )
+            psz_dir = NULL;
+        free( data_dir );
+
+        if( !psz_dir )
+        {
+            free( p_scan->parameter.sat_info.psz_name );
+            return VLC_EGENERIC;
+        }
+
+        /* open config directory */
+        if( !( p_dir = vlc_opendir( psz_dir ) ) )
+        {
+            msg_Err( p_scan->p_obj, "could not open satellite info directory (%s)", psz_dir );
+            free( p_scan->parameter.sat_info.psz_name );
+            return VLC_EGENERIC;
+        }
+
+        /* find the requested file in the directory */
+        for( ; ; ) {
+            char *psz_filename;
+
+            if( ! (psz_filename = vlc_readdir( p_dir ) ) )
+                break;
+
+            if( !strncmp( p_scan->parameter.sat_info.psz_name, psz_filename, 20 ) )
+            {
+                if( asprintf( &p_scan->parameter.sat_info.psz_path, "%s" DIR_SEP "%s", psz_dir, psz_filename ) == -1 )
+                    p_scan->parameter.sat_info.psz_path = NULL;
+
+                free( psz_filename );
+                break;
+            }
+        }
+
+        closedir( p_dir );
+
+        if( !p_scan->parameter.sat_info.psz_path )
+        {
+            msg_Err( p_scan->p_obj, "could not find satellite config (%s)", p_scan->parameter.sat_info.psz_name );
+            free( p_scan->parameter.sat_info.psz_name );
+            return VLC_EGENERIC;
+        }
+
+        msg_Dbg( p_scan->p_obj, "using satellite config file (%s)", p_scan->parameter.sat_info.psz_path );
+
+        FILE *f = vlc_fopen( p_scan->parameter.sat_info.psz_path, "r" );
+
+        /* parse file */
+        if( f )
+        {
+            char type;
+            char psz_fec[3];
+
+            int res;
+            do
+            {
+                if ( ( res = fscanf( f, "%c %d %c %d %s\n",
+                            &type,
+                            &p_transponders[*pi_count].i_frequency,
+                            &p_transponders[*pi_count].c_polarization,
+                            &p_transponders[*pi_count].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[*pi_count].i_fec = 9;    /* FEC_AUTO */
+                else
+                    p_transponders[*pi_count].i_fec = 1 + ( ( p_fec-psz_fec_list ) / 3 );
+
+                (*pi_count)++;
+
+                p_transponders = realloc(p_transponders, ( *pi_count + 1 ) * sizeof( scan_dvbs_transponder_t ) );
+            } while (res != EOF);
+
+            msg_Dbg( p_scan->p_obj, "parsed %d transponders from config", *pi_count);
+
+            fclose( f );
+        }
+        else
+        {
+            msg_Err( p_scan->p_obj, "failed to open satellite file (%s)", p_scan->parameter.sat_info.psz_path );
+            free( p_scan->parameter.sat_info.psz_name );
+            free( p_scan->parameter.sat_info.psz_path );
+            return VLC_EGENERIC;
+        }
+        free( p_scan->parameter.sat_info.psz_name );
+        free( p_scan->parameter.sat_info.psz_path );
+
+        p_scan->parameter.sat_info.p_transponders = p_transponders;
+    }
+
+    if( p_scan->i_index < *pi_count )
+    {
+        /* setup params for scan */
+        p_cfg->i_bandwidth = p_scan->parameter.sat_info.p_transponders[p_scan->i_index].i_symbol_rate / 1000;
+        p_cfg->i_frequency = p_scan->parameter.sat_info.p_transponders[p_scan->i_index].i_frequency;
+        p_cfg->i_fec = p_scan->parameter.sat_info.p_transponders[p_scan->i_index].i_fec;
+        p_cfg->c_polarization = p_scan->parameter.sat_info.p_transponders[p_scan->i_index].c_polarization;
+
+        msg_Dbg( p_scan->p_obj,
+                 "transponder [%d/%d]: frequency=%d, symbolrate=%d, fec=%d, polarization=%c",
+                 p_scan->i_index + 1,
+                 *pi_count,
+                 p_cfg->i_frequency,
+                 p_cfg->i_bandwidth,
+                 p_cfg->i_fec,
+                 p_cfg->c_polarization );
+
+        *pf_pos = (double)p_scan->i_index / *pi_count;
+
+        return VLC_SUCCESS;
+    }
+
+    if( p_scan->parameter.sat_info.p_transponders )
+    {
+        free( p_scan->parameter.sat_info.p_transponders );
+        p_scan->parameter.sat_info.p_transponders = NULL;
+    }
+
+    return VLC_EGENERIC;
+}
+
 static int ScanDvbCNextFast( 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 );
@@ -280,6 +441,14 @@ static int ScanDvbTNext( scan_t *p_scan, scan_configuration_t *p_cfg, double *pf
         return ScanDvbTNextFast( p_scan, p_cfg, pf_pos );
 }
 
+static int ScanDvbSNext( scan_t *p_scan, scan_configuration_t *p_cfg, double *pf_pos )
+{
+    if( p_scan->parameter.b_exhaustive )
+        msg_Dbg( p_scan->p_obj, "no exhaustive svb-d scan mode" );
+
+    return ScanDvbSNextFast( p_scan, p_cfg, pf_pos );
+}
+
 int scan_Next( scan_t *p_scan, scan_configuration_t *p_cfg )
 {
     double f_position;
@@ -297,6 +466,9 @@ int scan_Next( scan_t *p_scan, scan_configuration_t *p_cfg )
     case SCAN_DVB_C:
         i_ret = ScanDvbCNext( p_scan, p_cfg, &f_position );
         break;
+    case SCAN_DVB_S:
+        i_ret = ScanDvbSNext( p_scan, p_cfg, &f_position );
+        break;
     default:
         i_ret = VLC_EGENERIC;
         break;
@@ -789,14 +961,20 @@ block_t *scan_GetM3U( scan_t *p_scan )
                   s->i_network_id, s->i_nit_version, s->i_sdt_version,
                   s->cfg.i_frequency, s->cfg.i_bandwidth, s->i_snr );
 
+        if( !s->cfg.i_fec )
+            s->cfg.i_fec = 9;   /* FEC_AUTO */
+
         char *psz;
         if( asprintf( &psz, "#EXTINF:,,%s\n"
                         "#EXTVLCOPT:program=%d\n"
-                        "dvb://frequency=%d:bandwidth=%d\n"
+                        "dvb://frequency=%d:bandwidth=%d:voltage=%d:fec=%d\n"
                         "\n",
                       s->psz_name && * s->psz_name ? s->psz_name : "Unknown",
                       s->i_program,
-                      s->cfg.i_frequency, s->cfg.i_bandwidth ) < 0 )
+                      s->cfg.i_frequency,
+                      s->cfg.i_bandwidth,
+                      s->cfg.c_polarization == 'H' ? 18 : 13,
+                      s->cfg.i_fec ) < 0 )
             psz = NULL;
         if( psz )
         {