DVB: privatize scan_t
authorRémi Denis-Courmont <remi@remlab.net>
Sat, 5 Mar 2011 14:13:00 +0000 (16:13 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Sat, 5 Mar 2011 14:13:00 +0000 (16:13 +0200)
modules/access/dvb/access.c
modules/access/dvb/dvb.h
modules/access/dvb/linux_dvb.c
modules/access/dvb/scan.c
modules/access/dvb/scan.h

index 2bcb2d4..83217ec 100644 (file)
@@ -53,6 +53,7 @@
 # include <dvbpsi/sdt.h>
 
 #include "dvb.h"
+#include "scan.h"
 
 /*****************************************************************************
  * Module descriptor
@@ -338,8 +339,8 @@ static int Open( vlc_object_t *p_this )
     }
 
     /* */
-    p_sys->b_scan_mode = var_GetInteger( p_access, "dvb-frequency" ) == 0;
-    if( p_sys->b_scan_mode )
+    bool b_scan_mode = var_GetInteger( p_access, "dvb-frequency" ) == 0;
+    if( b_scan_mode )
     {
         msg_Dbg( p_access, "DVB scan mode selected" );
         p_access->pf_block = BlockScan;
@@ -364,9 +365,10 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    if( p_sys->b_scan_mode )
+    if( b_scan_mode )
     {
         scan_parameter_t parameter;
+        scan_t *p_scan;
 
         msg_Dbg( p_access, "setting filter on PAT/NIT/SDT (DVB only)" );
         FilterSet( p_access, 0x00, OTHER_TYPE );    // PAT
@@ -374,11 +376,13 @@ static int Open( vlc_object_t *p_this )
         FilterSet( p_access, 0x11, OTHER_TYPE );    // SDT
 
         if( FrontendGetScanParameter( p_access, &parameter ) ||
-            scan_Init( VLC_OBJECT(p_access), &p_sys->scan, &parameter ) )
+            (p_scan = scan_New( VLC_OBJECT(p_access), &parameter )) == NULL )
         {
             Close( VLC_OBJECT(p_access) );
             return VLC_EGENERIC;
         }
+        p_sys->scan = p_scan;
+        p_sys->i_read_once = DVB_READ_ONCE_SCAN;
     }
     else
     {
@@ -387,11 +391,13 @@ static int Open( vlc_object_t *p_this )
         {
             msg_Dbg( p_access, "setting filter on all PIDs" );
             FilterSet( p_access, 0x2000, OTHER_TYPE );
+            p_sys->i_read_once = DVB_READ_ONCE;
         }
         else
         {
             msg_Dbg( p_access, "setting filter on PAT" );
             FilterSet( p_access, 0x0, OTHER_TYPE );
+            p_sys->i_read_once = DVB_READ_ONCE_START;
         }
 
         CAMOpen( p_access );
@@ -401,15 +407,8 @@ static int Open( vlc_object_t *p_this )
 #endif
     }
 
-    if( p_sys->b_scan_mode )
-        p_sys->i_read_once = DVB_READ_ONCE_SCAN;
-    else if( p_sys->b_budget_mode )
-        p_sys->i_read_once = DVB_READ_ONCE;
-    else
-        p_sys->i_read_once = DVB_READ_ONCE_START;
-
     free( p_access->psz_demux );
-    p_access->psz_demux = strdup( p_sys->b_scan_mode ? "m3u8" : "ts" );
+    p_access->psz_demux = strdup( p_sys->scan ? "m3u8" : "ts" );
     return VLC_SUCCESS;
 }
 
@@ -421,19 +420,19 @@ static void Close( vlc_object_t *p_this )
     access_t     *p_access = (access_t*)p_this;
     access_sys_t *p_sys = p_access->p_sys;
 
-    FilterUnset( p_access, p_sys->b_budget_mode && !p_sys->b_scan_mode ? 1 : MAX_DEMUX );
+    FilterUnset( p_access, p_sys->b_budget_mode && !p_sys->scan ? 1 : MAX_DEMUX );
 
     DVRClose( p_access );
     FrontendClose( p_access );
-    if( p_sys->b_scan_mode )
-        scan_Clean( &p_sys->scan );
+    if( p_sys->scan != NULL )
+        scan_Destroy( p_sys->scan );
     else
+    {
         CAMClose( p_access );
-
 #ifdef ENABLE_HTTPD
-    if( !p_sys->b_scan_mode )
         HTTPClose( p_access );
 #endif
+    }
 
     free( p_sys );
 }
@@ -554,14 +553,10 @@ static block_t *Block( access_t *p_access )
 static block_t *BlockScan( access_t *p_access )
 {
     access_sys_t *p_sys = p_access->p_sys;
-    scan_t *p_scan = &p_sys->scan;
+    scan_t *p_scan = p_sys->scan;
     scan_configuration_t cfg;
     scan_session_t session;
 
-    /* set satellite config file path */
-    if( p_scan->parameter.type == SCAN_DVB_S )
-        p_scan->parameter.sat_info.psz_name = var_GetString( p_access, "dvb-satellite" );
-
     /* */
     if( scan_Next( p_scan, &cfg ) )
     {
@@ -581,23 +576,15 @@ static block_t *BlockScan( access_t *p_access )
         return NULL;
 
     /* */
-    if( p_scan->parameter.type == SCAN_DVB_S )
-    {
-        msg_Dbg( p_access,
-                 "Scanning frequency %d, symbol rate = %d, fec = %d",
-                 cfg.i_frequency,
-                 cfg.i_bandwidth,
-                 cfg.i_fec );
-    }
-    else
-        msg_Dbg( p_access, "Scanning frequency %d, bandwidth = %d",
-                 cfg.i_frequency,
-                 cfg.i_bandwidth );
-
+    msg_Dbg( p_access, "Scanning frequency %d", cfg.i_frequency );
     var_SetInteger( p_access, "dvb-frequency", cfg.i_frequency );
+    msg_Dbg( p_access, " bandwidth %d", cfg.i_bandwidth );
     var_SetInteger( p_access, "dvb-bandwidth", cfg.i_bandwidth );
     if ( cfg.i_fec )
+    {
+        msg_Dbg( p_access, " FEC %d", cfg.i_fec );
         var_SetInteger( p_access, "dvb-fec", cfg.i_fec );
+    }
     if ( cfg.c_polarization )
         var_SetInteger( p_access, "dvb-voltage", cfg.c_polarization == 'H' ? 18 : 13 );
 
@@ -766,7 +753,7 @@ static int Control( access_t *p_access, int i_query, va_list args )
             return VLC_SUCCESS;
 
         case ACCESS_SET_PRIVATE_ID_STATE:
-            if( p_sys->b_scan_mode )
+            if( p_sys->scan )
                 return VLC_EGENERIC;
 
             i_int  = (int)va_arg( args, int );               /* Private data (pid for now)*/
@@ -782,7 +769,7 @@ static int Control( access_t *p_access, int i_query, va_list args )
             break;
 
         case ACCESS_SET_PRIVATE_ID_CA:
-            if( p_sys->b_scan_mode )
+            if( p_sys->scan )
                 return VLC_EGENERIC;
 
             p_pmt = (dvbpsi_pmt_t *)va_arg( args, dvbpsi_pmt_t * );
index 57ccfbf..64a53b4 100644 (file)
@@ -23,9 +23,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    02111, USA.
  *****************************************************************************/
 
-
-#include "scan.h"
-
 /*****************************************************************************
  * Local structures
  *****************************************************************************/
@@ -51,6 +48,9 @@ typedef struct
     bool b_has_lock;
 } frontend_status_t;
 
+typedef struct scan_parameter_t scan_parameter_t;
+typedef struct scan_t scan_t;
+
 typedef struct en50221_session_t
 {
     int i_slot;
@@ -145,7 +145,6 @@ struct access_sys_t
     demux_handle_t p_demux_handles[MAX_DEMUX];
     frontend_t *p_frontend;
     bool b_budget_mode;
-    bool b_scan_mode;
 
     /* CA management */
     int i_ca_handle;
@@ -180,7 +179,7 @@ struct access_sys_t
 #endif
 
     /* Scan */
-    scan_t scan;
+    scan_t *scan;
 };
 
 #define VIDEO0_TYPE     1
index b84033e..71a8d7f 100644 (file)
@@ -61,6 +61,7 @@
 #endif
 
 #include "dvb.h"
+#include "scan.h"
 
 #define DMX      "/dev/dvb/adapter%d/demux%d"
 #define FRONTEND "/dev/dvb/adapter%d/frontend%d"
@@ -402,6 +403,8 @@ 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" );
 
     return VLC_SUCCESS;
 }
@@ -410,7 +413,6 @@ static int ScanParametersDvbC( access_t *p_access, scan_parameter_t *p_scan )
 {
     const frontend_t *p_frontend = p_access->p_sys->p_frontend;
 
-
     memset( p_scan, 0, sizeof(*p_scan) );
     p_scan->type = SCAN_DVB_C;
     p_scan->b_exhaustive = false;
@@ -434,7 +436,6 @@ static int ScanParametersDvbT( access_t *p_access, scan_parameter_t *p_scan )
 {
     const frontend_t *p_frontend = p_access->p_sys->p_frontend;
 
-
     memset( p_scan, 0, sizeof(*p_scan) );
     p_scan->type = SCAN_DVB_T;
     p_scan->b_exhaustive = false;
index 87ddc72..8cfe306 100644 (file)
 # include <dvbpsi/sdt.h>
 
 #include "dvb.h"
+#include "scan.h"
+
+struct scan_t
+{
+    vlc_object_t *p_obj;
+    struct dialog_progress_bar_t *p_dialog;
+    int64_t i_index;
+    scan_parameter_t parameter;
+    int64_t i_time_start;
+
+    int            i_service;
+    scan_service_t **pp_service;
+};
 
 /* */
 scan_service_t *scan_service_New( int i_program, const scan_configuration_t *p_cfg  )
@@ -77,7 +90,7 @@ void scan_service_Delete( scan_service_t *p_srv )
 }
 
 /* */
-int scan_Init( vlc_object_t *p_obj, scan_t *p_scan, const scan_parameter_t *p_parameter )
+scan_t *scan_New( vlc_object_t *p_obj, const scan_parameter_t *p_parameter )
 {
     if( p_parameter->type == SCAN_DVB_T )
     {
@@ -104,11 +117,15 @@ int scan_Init( vlc_object_t *p_obj, scan_t *p_scan, const scan_parameter_t *p_pa
     }
     else
     {
-        return VLC_EGENERIC;
+        return NULL;
     }
     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" );
 
+    scan_t *p_scan = malloc( sizeof( *p_scan ) );
+    if( unlikely(p_scan == NULL) )
+        return NULL;
+
     p_scan->p_obj = VLC_OBJECT(p_obj);
     p_scan->i_index = 0;
     p_scan->p_dialog = NULL;
@@ -116,10 +133,10 @@ int scan_Init( vlc_object_t *p_obj, scan_t *p_scan, const scan_parameter_t *p_pa
     p_scan->parameter = *p_parameter;
     p_scan->i_time_start = mdate();
 
-    return VLC_SUCCESS;
+    return p_scan;
 }
 
-void scan_Clean( scan_t *p_scan )
+void scan_Destroy( scan_t *p_scan )
 {
     if( p_scan->p_dialog != NULL )
         dialog_ProgressDestroy( p_scan->p_dialog );
@@ -127,6 +144,7 @@ void scan_Clean( scan_t *p_scan )
     for( int i = 0; i < p_scan->i_service; i++ )
         scan_service_Delete( p_scan->pp_service[i] );
     TAB_CLEAN( p_scan->i_service, p_scan->pp_service );
+    free( p_scan );
 }
 
 static int ScanDvbSNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double *pf_pos )
index 41609ea..67f365f 100644 (file)
@@ -46,7 +46,7 @@ typedef struct
     char c_polarization;
 } scan_dvbs_transponder_t;
 
-typedef struct
+struct scan_parameter_t
 {
     scan_type_t type;
     bool b_exhaustive;
@@ -80,8 +80,7 @@ typedef struct
         scan_dvbs_transponder_t *p_transponders;
         int i_count;
     } sat_info;
-
-} scan_parameter_t;
+};
 
 typedef struct
 {
@@ -143,24 +142,11 @@ typedef struct
 
 } scan_session_t;
 
-typedef struct
-{
-    vlc_object_t *p_obj;
-    struct dialog_progress_bar_t *p_dialog;
-    int64_t i_index;
-    scan_parameter_t parameter;
-    int64_t i_time_start;
-
-    int            i_service;
-    scan_service_t **pp_service;
-} scan_t;
-
-
 scan_service_t *scan_service_New( int i_program, const scan_configuration_t *p_cfg  );
 void scan_service_Delete( scan_service_t *p_srv );
 
-int  scan_Init( vlc_object_t *p_obj, scan_t *p_scan, const scan_parameter_t *p_parameter );
-void scan_Clean( scan_t *p_scan );
+scan_t *scan_New( vlc_object_t *p_obj, const scan_parameter_t *p_parameter );
+void scan_Destroy( scan_t *p_scan );
 
 int scan_Next( scan_t *p_scan, scan_configuration_t *p_cfg );