[vlc-commits] DVB: privatize scan_session

Rémi Denis-Courmont git at videolan.org
Sat Mar 5 15:28:30 CET 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Mar  5 16:26:51 2011 +0200| [887ad85ce5400b44fcc7a1ecd129d055c3a7694c] | committer: Rémi Denis-Courmont

DVB: privatize scan_session

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=887ad85ce5400b44fcc7a1ecd129d055c3a7694c
---

 modules/access/dvb/access.c |   14 +++++-----
 modules/access/dvb/scan.c   |   57 ++++++++++++++++++++++++++++++++----------
 modules/access/dvb/scan.h   |   37 ++++------------------------
 3 files changed, 55 insertions(+), 53 deletions(-)

diff --git a/modules/access/dvb/access.c b/modules/access/dvb/access.c
index 83217ec..ac77b23 100644
--- a/modules/access/dvb/access.c
+++ b/modules/access/dvb/access.c
@@ -555,7 +555,6 @@ 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_configuration_t cfg;
-    scan_session_t session;
 
     /* */
     if( scan_Next( p_scan, &cfg ) )
@@ -571,8 +570,8 @@ static block_t *BlockScan( access_t *p_access )
     }
 
     /* */
-
-    if( scan_session_Init( VLC_OBJECT(p_access), &session, &cfg ) )
+    scan_session_t *session = scan_session_New( VLC_OBJECT(p_access), &cfg );
+    if( session == NULL )
         return NULL;
 
     /* */
@@ -593,6 +592,7 @@ static block_t *BlockScan( access_t *p_access )
     {
         msg_Err( p_access, "Failed to tune the frontend" );
         p_access->info.b_eof = true;
+        scan_session_Destroy( p_scan, session );
         return NULL;
     }
 
@@ -647,7 +647,7 @@ static block_t *BlockScan( access_t *p_access )
                 continue;
 
             msg_Err( p_access, "poll error: %m" );
-            scan_session_Clean( p_scan, &session );
+            scan_session_Destroy( p_scan, session );
 
             p_access->info.b_eof = true;
             return NULL;
@@ -687,7 +687,7 @@ static block_t *BlockScan( access_t *p_access )
             p_block->i_buffer = i_ret;
 
             /* */
-            if( scan_session_Push( &session, p_block ) )
+            if( scan_session_Push( session, p_block ) )
             {
                 msg_Dbg( p_access, "finished scanning current frequency" );
                 break;
@@ -697,9 +697,9 @@ static block_t *BlockScan( access_t *p_access )
 
     /* */
     if( i_best_snr > 0 )
-        scan_service_SetSNR( &session, i_best_snr );
+        scan_service_SetSNR( session, i_best_snr );
 
-    scan_session_Clean( p_scan, &session );
+    scan_session_Destroy( p_scan, session );
     return NULL;
 }
 
diff --git a/modules/access/dvb/scan.c b/modules/access/dvb/scan.c
index 31b9f00..e794c16 100644
--- a/modules/access/dvb/scan.c
+++ b/modules/access/dvb/scan.c
@@ -36,14 +36,18 @@
 #include <sys/types.h>
 
 /* Include dvbpsi headers */
-# include <dvbpsi/dvbpsi.h>
-# include <dvbpsi/descriptor.h>
-# include <dvbpsi/pat.h>
-# include <dvbpsi/pmt.h>
-# include <dvbpsi/dr.h>
-# include <dvbpsi/psi.h>
-# include <dvbpsi/demux.h>
-# include <dvbpsi/sdt.h>
+#include <dvbpsi/dvbpsi.h>
+#include <dvbpsi/descriptor.h>
+#include <dvbpsi/pat.h>
+#include <dvbpsi/pmt.h>
+#include <dvbpsi/dr.h>
+#include <dvbpsi/psi.h>
+#include <dvbpsi/demux.h>
+#include <dvbpsi/sdt.h>
+#ifdef _DVBPSI_DR_43_H_
+#   define DVBPSI_USE_NIT 1
+#   include <dvbpsi/nit.h>
+#endif
 
 #include "dvb.h"
 #include "scan.h"
@@ -87,6 +91,29 @@ struct scan_t
     scan_service_t **pp_service;
 };
 
+struct scan_session_t
+{
+    vlc_object_t *p_obj;
+
+    scan_configuration_t cfg;
+    int i_snr;
+
+    dvbpsi_handle pat;
+    dvbpsi_pat_t *p_pat;
+    int i_nit_pid;
+
+    dvbpsi_handle sdt;
+    dvbpsi_sdt_t *p_sdt;
+
+#ifdef DVBPSI_USE_NIT
+    dvbpsi_handle nit;
+    dvbpsi_nit_t *p_nit;
+#else
+#   warning NIT is not supported by your libdvbpsi version
+#endif
+
+};
+
 /* */
 static scan_service_t *scan_service_New( int i_program,
                                          const scan_configuration_t *p_cfg )
@@ -757,11 +784,12 @@ static void PSINewTableCallBack( scan_session_t *p_session, dvbpsi_handle h, uin
 #endif
 }
 
-
-int scan_session_Init( vlc_object_t *p_obj, scan_session_t *p_session, const scan_configuration_t *p_cfg )
+scan_session_t *scan_session_New( vlc_object_t *p_obj,
+                                  const scan_configuration_t *p_cfg )
 {
-    /* */
-    memset( p_session, 0, sizeof(*p_session) );
+    scan_session_t *p_session = malloc( sizeof( *p_session ) );
+    if( unlikely(p_session == NULL) )
+        return NULL;
     p_session->p_obj = p_obj;
     p_session->cfg = *p_cfg;
     p_session->i_snr = -1;
@@ -774,10 +802,10 @@ int scan_session_Init( vlc_object_t *p_obj, scan_session_t *p_session, const sca
     p_session->nit = NULL;
     p_session->p_nit = NULL;
 #endif
-    return VLC_SUCCESS;
+    return p_session;;
 }
 
-void scan_session_Clean( scan_t *p_scan, scan_session_t *p_session )
+void scan_session_Destroy( scan_t *p_scan, scan_session_t *p_session )
 {
     const int i_service_start = p_scan->i_service;
 
@@ -910,6 +938,7 @@ void scan_session_Clean( scan_t *p_scan, scan_session_t *p_session )
     if( p_session->p_nit )
         dvbpsi_DeleteNIT( p_session->p_nit );
 #endif
+    free( p_session );
 }
 
 static int ScanServiceCmp( const void *a, const void *b )
diff --git a/modules/access/dvb/scan.h b/modules/access/dvb/scan.h
index 878962a..10fe3b6 100644
--- a/modules/access/dvb/scan.h
+++ b/modules/access/dvb/scan.h
@@ -21,15 +21,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    02111, USA.
  *****************************************************************************/
 
-#ifdef _DVBPSI_DR_43_H_
-#   define DVBPSI_USE_NIT 1
-#   include <dvbpsi/nit.h>
-#endif
-
-#ifndef DVBPSI_USE_NIT
-#   warning NIT is not supported by your libdvbpsi version
-#endif
-
 typedef enum
 {
     SCAN_NONE,
@@ -94,27 +85,6 @@ typedef struct
     char c_polarization;
 } scan_configuration_t;
 
-typedef struct
-{
-    vlc_object_t *p_obj;
-
-    scan_configuration_t cfg;
-    int i_snr;
-
-    dvbpsi_handle pat;
-    dvbpsi_pat_t *p_pat;
-    int i_nit_pid;
-
-    dvbpsi_handle sdt;
-    dvbpsi_sdt_t *p_sdt;
-
-#ifdef DVBPSI_USE_NIT
-    dvbpsi_handle nit;
-    dvbpsi_nit_t *p_nit;
-#endif
-
-} scan_session_t;
-
 scan_t *scan_New( vlc_object_t *p_obj, const scan_parameter_t *p_parameter );
 void scan_Destroy( scan_t *p_scan );
 
@@ -123,8 +93,11 @@ int scan_Next( scan_t *p_scan, scan_configuration_t *p_cfg );
 block_t *scan_GetM3U( scan_t *p_scan );
 bool scan_IsCancelled( scan_t *p_scan );
 
-int  scan_session_Init( vlc_object_t *p_obj, scan_session_t *p_session, const scan_configuration_t *p_cfg );
-void scan_session_Clean( scan_t *p_scan, scan_session_t *p_session );
+typedef struct scan_session_t scan_session_t;
+
+scan_session_t *scan_session_New( vlc_object_t *,
+                                  const scan_configuration_t * );
+void scan_session_Destroy( scan_t *, scan_session_t * );
 bool scan_session_Push( scan_session_t *p_scan, block_t *p_block );
 void scan_service_SetSNR( scan_session_t *p_scan, int i_snr );
 



More information about the vlc-commits mailing list