[vlc-commits] [Git][videolan/vlc][master] 4 commits: demux: ts: don't borrow dvbpsi handle in hotfix

Steve Lhomme (@robUx4) gitlab at videolan.org
Wed Feb 14 07:25:55 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
7b696d69 by François Cartegnie at 2024-02-14T06:50:59+00:00
demux: ts: don't borrow dvbpsi handle in hotfix

- - - - -
624ce2a6 by François Cartegnie at 2024-02-14T06:50:59+00:00
demux: ts: conceal dvbpsi into psip context

- - - - -
5838f8ce by François Cartegnie at 2024-02-14T06:50:59+00:00
demux: ts: conceal dvbpsi into si context

- - - - -
348ee31a by François Cartegnie at 2024-02-14T06:50:59+00:00
demux: ts: conceal dvbpsi into psi context

- - - - -


9 changed files:

- modules/demux/mpeg/ts_hotfixes.c
- modules/demux/mpeg/ts_psi.c
- modules/demux/mpeg/ts_psi.h
- modules/demux/mpeg/ts_psip.c
- modules/demux/mpeg/ts_psip.h
- modules/demux/mpeg/ts_si.c
- modules/demux/mpeg/ts_si.h
- modules/demux/mpeg/ts_streams.c
- modules/demux/mpeg/ts_streams_private.h


Changes:

=====================================
modules/demux/mpeg/ts_hotfixes.c
=====================================
@@ -214,7 +214,7 @@ codecprobingend:
 static void BuildPATCallback( void *p_opaque, block_t *p_block )
 {
     ts_pid_t *pat_pid = (ts_pid_t *) p_opaque;
-    dvbpsi_packet_push( pat_pid->u.p_pat->handle, p_block->p_buffer );
+    ts_psi_Packet_Push( pat_pid, p_block->p_buffer );
     block_Release( p_block );
 }
 
@@ -224,8 +224,7 @@ static void BuildPMTCallback( void *p_opaque, block_t *p_block )
     assert(program_pid->type == TYPE_PMT);
     while( p_block )
     {
-        dvbpsi_packet_push( program_pid->u.p_pmt->handle,
-                            p_block->p_buffer );
+        ts_psi_Packet_Push( program_pid, p_block->p_buffer );
         block_t *p_next = p_block->p_next;
         block_Release( p_block );
         p_block = p_next;
@@ -304,7 +303,11 @@ void MissingPATPMTFixup( demux_t *p_demux )
         .b_discontinuity = false
     };
 
-    BuildPAT( GetPID(p_sys, 0)->u.p_pat->handle,
+    dvbpsi_t *handle = dvbpsi_new( NULL, DVBPSI_MSG_DEBUG );
+    if( !handle )
+        return;
+
+    BuildPAT( handle,
             &p_sys->pids.pat, BuildPATCallback,
             0, 1,
             &patstream,
@@ -313,6 +316,7 @@ void MissingPATPMTFixup( demux_t *p_demux )
     /* PAT callback should have been triggered */
     if( p_program_pid->type != TYPE_PMT )
     {
+        dvbpsi_delete( handle );
         msg_Err( p_demux, "PAT creation failed" );
         return;
     }
@@ -359,7 +363,7 @@ void MissingPATPMTFixup( demux_t *p_demux )
             j++;
         }
 
-        BuildPMT( GetPID(p_sys, 0)->u.p_pat->handle, VLC_OBJECT(p_demux),
+        BuildPMT( handle, VLC_OBJECT(p_demux),
                  mux_standard,
                 p_program_pid, BuildPMTCallback,
                 0, 1,
@@ -374,4 +378,6 @@ void MissingPATPMTFixup( demux_t *p_demux )
     }
     free(esstreams);
     free(mapped);
+
+    dvbpsi_delete( handle );
 }


=====================================
modules/demux/mpeg/ts_psi.c
=====================================
@@ -31,6 +31,7 @@
 #include <dvbpsi/pat.h>
 #include <dvbpsi/pmt.h>
 #include <dvbpsi/dr.h>
+#include "../../mux/mpeg/dvbpsi_compat.h" /* dvbpsi_messages */
 
 #include <vlc_demux.h>
 #include <vlc_bits.h>
@@ -62,6 +63,12 @@
 
 #include <assert.h>
 
+struct ts_psi_context_t
+{
+    dvbpsi_t *p_handle;
+    void (*pf_detach)(dvbpsi_t *);
+};
+
 static void PIDFillFormat( demux_t *, ts_stream_t *p_pes, int i_stream_type, ts_transport_type_t * );
 static void PMTCallBack( void *data, dvbpsi_pmt_t *p_dvbpsipmt );
 static ts_standards_e ProbePMTStandard( const dvbpsi_pmt_t *p_dvbpsipmt );
@@ -178,11 +185,12 @@ static void PATCallBack( void *data, dvbpsi_pat_t *p_dvbpsipat )
         if( !b_existing || pmtpid->u.p_pmt->i_number != p_program->i_number )
         {
             if( b_existing && pmtpid->u.p_pmt->i_number != p_program->i_number )
-                dvbpsi_pmt_detach(pmtpid->u.p_pmt->handle);
+                dvbpsi_pmt_detach(pmtpid->u.p_pmt->p_ctx->p_handle);
 
-            if( !dvbpsi_pmt_attach( pmtpid->u.p_pmt->handle, p_program->i_number, PMTCallBack, p_demux ) )
+            if( !dvbpsi_pmt_attach( pmtpid->u.p_pmt->p_ctx->p_handle, p_program->i_number, PMTCallBack, p_demux ) )
                 msg_Err( p_demux, "PATCallback failed attaching PMTCallback to program %d",
                          p_program->i_number );
+            pmtpid->u.p_pmt->p_ctx->pf_detach = dvbpsi_pmt_detach;
         }
 
         pmtpid->u.p_pmt->i_number = p_program->i_number;
@@ -2124,7 +2132,7 @@ static void PMTCallBack( void *data, dvbpsi_pmt_t *p_dvbpsipmt )
         if ( PIDSetup( p_demux, TYPE_PSIP, atsc_base_pid, pmtpid ) )
         {
             ts_psip_t *p_psip = atsc_base_pid->u.p_psip;
-            if( !ATSC_Attach_Dvbpsi_Base_Decoders( p_psip->handle, atsc_base_pid ) )
+            if( !ATSC_Attach_Dvbpsi_Base_Decoders( p_psip->p_ctx, atsc_base_pid ) )
             {
                 msg_Err( p_demux, "dvbpsi_atsc_AttachMGT/STT failed for program %d",
                          p_pmt->i_number );
@@ -2249,7 +2257,7 @@ int UserPmt( demux_t *p_demux, const char *psz_fmt )
     /* Dummy PMT */
     ts_pmt_t *p_pmt = pmtpid->u.p_pmt;
     p_pmt->i_number   = i_number != 0 ? i_number : TS_USER_PMT_NUMBER;
-    if( !dvbpsi_pmt_attach( p_pmt->handle,
+    if( !dvbpsi_pmt_attach( p_pmt->p_ctx->p_handle,
                             ((i_number != TS_USER_PMT_NUMBER ? i_number : 1)),
                             PMTCallBack, p_demux ) )
     {
@@ -2350,13 +2358,42 @@ bool ts_psi_PAT_Attach( ts_pid_t *patpid, void *cbdata )
 {
     if( unlikely(patpid->type != TYPE_PAT || patpid->i_pid != TS_PSI_PAT_PID) )
         return false;
-    return dvbpsi_pat_attach( patpid->u.p_pat->handle, PATCallBack, cbdata );
+    patpid->u.p_pat->p_ctx->pf_detach = dvbpsi_pat_detach;
+    return dvbpsi_pat_attach( patpid->u.p_pat->p_ctx->p_handle, PATCallBack, cbdata );
 }
 
 void ts_psi_Packet_Push( ts_pid_t *p_pid, const uint8_t *p_pktbuffer )
 {
     if( p_pid->type == TYPE_PAT )
-        dvbpsi_packet_push( p_pid->u.p_pat->handle, (uint8_t *) p_pktbuffer );
+        dvbpsi_packet_push( p_pid->u.p_pat->p_ctx->p_handle, (uint8_t *) p_pktbuffer );
     else if( p_pid->type == TYPE_PMT )
-        dvbpsi_packet_push( p_pid->u.p_pmt->handle, (uint8_t *) p_pktbuffer );
+        dvbpsi_packet_push( p_pid->u.p_pmt->p_ctx->p_handle, (uint8_t *) p_pktbuffer );
+}
+
+void ts_psi_context_Delete( ts_psi_context_t *p_ctx )
+{
+    if( dvbpsi_decoder_present( p_ctx->p_handle ) )
+    {
+        assert( p_ctx->pf_detach );
+        p_ctx->pf_detach( p_ctx->p_handle );
+    }
+    dvbpsi_delete( p_ctx->p_handle );
+    free( p_ctx );
+}
+
+ts_psi_context_t * ts_psi_context_New( demux_t *p_demux )
+{
+    ts_psi_context_t *p_ctx = malloc(sizeof(*p_ctx));
+    if(likely(p_ctx))
+    {
+        p_ctx->p_handle = dvbpsi_new( &dvbpsi_messages, DVBPSI_MSG_DEBUG );
+        if( !p_ctx->p_handle )
+        {
+            free( p_ctx );
+            return NULL;
+        }
+        p_ctx->p_handle->p_sys = (void *) p_demux;
+        p_ctx->pf_detach = NULL;
+    }
+    return p_ctx;
 }


=====================================
modules/demux/mpeg/ts_psi.h
=====================================
@@ -29,6 +29,11 @@ typedef enum
     TS_PMT_REGISTRATION_ARIB,
 } ts_pmt_registration_type_t;
 
+typedef struct ts_psi_context_t ts_psi_context_t;
+
+ts_psi_context_t * ts_psi_context_New( demux_t * );
+void ts_psi_context_Delete( ts_psi_context_t * );
+
 bool ts_psi_PAT_Attach( ts_pid_t *, void * );
 void ts_psi_Packet_Push( ts_pid_t *, const uint8_t * );
 


=====================================
modules/demux/mpeg/ts_psip.c
=====================================
@@ -38,6 +38,7 @@
 #include <dvbpsi/atsc_ett.h>
 #include <dvbpsi/atsc_stt.h>
 #include <dvbpsi/dr_a0.h>
+#include "../../mux/mpeg/dvbpsi_compat.h" /* dvbpsi_messages */
 /* Custom decoders */
 #include <dvbpsi/psi.h>
 #include "ts_decoders.h"
@@ -76,6 +77,8 @@ static inline char *grab_notempty( char **ppsz )
 
 struct ts_psip_context_t
 {
+    dvbpsi_t *p_handle;
+    int       i_version;
     dvbpsi_atsc_mgt_t *p_mgt; /* Used to match (EITx,ETTx)<->PIDn */
     dvbpsi_atsc_stt_t *p_stt; /* Time reference for EIT/EAS */
     dvbpsi_atsc_vct_t *p_vct; /* Required for EIT vchannel -> program remapping */
@@ -85,17 +88,28 @@ struct ts_psip_context_t
     DECL_ARRAY(dvbpsi_atsc_eit_t *) eits; /* For EIT pid, used on new ETT update */
 };
 
+static void ATSC_Detach_Dvbpsi_Decoders( dvbpsi_t *p_handle );
+
 void ts_psip_Packet_Push( ts_pid_t *p_pid, const uint8_t *p_pktbuffer )
 {
-    if( p_pid->u.p_psip->handle->p_decoder && likely(p_pid->type == TYPE_PSIP) )
-        dvbpsi_packet_push( p_pid->u.p_psip->handle, (uint8_t *) p_pktbuffer );
+    ts_psip_context_t *p_ctx = p_pid->u.p_psip->p_ctx;
+    if( p_ctx->p_handle->p_decoder && likely(p_pid->type == TYPE_PSIP) )
+        dvbpsi_packet_push( p_ctx->p_handle, (uint8_t *) p_pktbuffer );
 }
 
-ts_psip_context_t * ts_psip_context_New( void )
+ts_psip_context_t * ts_psip_context_New( demux_t *p_demux )
 {
     ts_psip_context_t *p_ctx = malloc(sizeof(*p_ctx));
     if(likely(p_ctx))
     {
+        p_ctx->p_handle = dvbpsi_new( &dvbpsi_messages, DVBPSI_MSG_DEBUG );
+        if( !p_ctx->p_handle )
+        {
+            free( p_ctx );
+            return NULL;
+        }
+        p_ctx->p_handle->p_sys = (void *) p_demux;
+        p_ctx->i_version = -1;
         p_ctx->p_mgt = NULL;
         p_ctx->p_stt = NULL;
         p_ctx->p_vct = NULL;
@@ -112,6 +126,9 @@ void ts_psip_context_Delete( ts_psip_context_t *p_ctx )
     assert( !p_ctx->p_mgt || !p_ctx->etts.i_size );
     assert( !p_ctx->p_vct || !p_ctx->eits.i_size );
 
+    ATSC_Detach_Dvbpsi_Decoders( p_ctx->p_handle );
+    dvbpsi_delete( p_ctx->p_handle );
+
     if( p_ctx->p_mgt )
         dvbpsi_atsc_DeleteMGT( p_ctx->p_mgt );
     if( p_ctx->p_stt )
@@ -269,7 +286,7 @@ static bool ATSC_Ready_SubDecoders( dvbpsi_t *p_handle, void *p_cb_pid )
     return true;
 }
 
-void ATSC_Detach_Dvbpsi_Decoders( dvbpsi_t *p_handle )
+static void ATSC_Detach_Dvbpsi_Decoders( dvbpsi_t *p_handle )
 {
     if( dvbpsi_decoder_present( p_handle ) )
         dvbpsi_DetachDemux( p_handle );
@@ -422,7 +439,7 @@ static void ATSC_EIT_Callback( void *p_pid, dvbpsi_atsc_eit_t* p_eit )
         return;
     }
 
-    demux_t *p_demux = (demux_t *) p_eit_pid->u.p_psip->handle->p_sys;
+    demux_t *p_demux = (demux_t *) p_eit_pid->u.p_psip->p_ctx->p_handle->p_sys;
     demux_sys_t *p_sys = p_demux->p_sys;
     ts_pid_t *p_base_pid = GetPID(p_sys, ATSC_BASE_PID);
     ts_psip_t *p_basepsip = p_base_pid->u.p_psip;
@@ -521,7 +538,7 @@ static void ATSC_ETT_Callback( void *p_pid, dvbpsi_atsc_ett_t *p_ett )
         return;
     }
 
-    demux_t *p_demux = (demux_t *) p_ett_pid->u.p_psip->handle->p_sys;
+    demux_t *p_demux = (demux_t *) p_ett_pid->u.p_psip->p_ctx->p_handle->p_sys;
     demux_sys_t *p_sys = p_demux->p_sys;
     ts_pid_t *p_base_pid = GetPID(p_sys, ATSC_BASE_PID);
     ts_psip_t *p_basepsip = p_base_pid->u.p_psip;
@@ -598,7 +615,7 @@ static void ATSC_VCT_Callback( void *p_cb_basepid, dvbpsi_atsc_vct_t* p_vct )
         dvbpsi_atsc_DeleteVCT( p_vct );
         return;
     }
-    demux_t *p_demux = (demux_t *) p_base_pid->u.p_psip->handle->p_sys;
+    demux_t *p_demux = (demux_t *) p_base_pid->u.p_psip->p_ctx->p_handle->p_sys;
     ts_psip_context_t *p_ctx = p_base_pid->u.p_psip->p_ctx;
 
     if( !p_ctx->p_a65 && !(p_ctx->p_a65 = atsc_a65_handle_New( NULL )) )
@@ -674,10 +691,10 @@ static void ATSC_MGT_Callback( void *p_cb_basepid, dvbpsi_atsc_mgt_t* p_mgt )
         return;
     }
     ts_psip_t *p_mgtpsip = p_base_pid->u.p_psip;
-    demux_t *p_demux = (demux_t *) p_mgtpsip->handle->p_sys;
+    demux_t *p_demux = (demux_t *) p_mgtpsip->p_ctx->p_handle->p_sys;
     demux_sys_t *p_sys = p_demux->p_sys;
 
-    if( ( p_mgtpsip->i_version != -1 && p_mgtpsip->i_version == p_mgt->i_version ) ||
+    if( ( p_mgtpsip->p_ctx->i_version != -1 && p_mgtpsip->p_ctx->i_version == p_mgt->i_version ) ||
           p_mgt->b_current_next == 0 )
     {
         dvbpsi_atsc_DeleteMGT( p_mgt );
@@ -686,7 +703,7 @@ static void ATSC_MGT_Callback( void *p_cb_basepid, dvbpsi_atsc_mgt_t* p_mgt )
 
     /* Easy way, delete and recreate every child if any new version comes
      * (We don't need to keep PID active as with video/PMT update) */
-    if( p_mgtpsip->i_version != -1 )
+    if( p_mgtpsip->p_ctx->i_version != -1 )
     {
         if( p_mgtpsip->p_ctx->p_vct )
         {
@@ -703,7 +720,7 @@ static void ATSC_MGT_Callback( void *p_cb_basepid, dvbpsi_atsc_mgt_t* p_mgt )
         ARRAY_RESET(p_mgtpsip->eit);
 
         /* Remove EAS */
-        dvbpsi_demux_t *p_dvbpsi_demux = (dvbpsi_demux_t *) p_mgtpsip->handle->p_decoder;
+        dvbpsi_demux_t *p_dvbpsi_demux = (dvbpsi_demux_t *) p_mgtpsip->p_ctx->p_handle->p_decoder;
         dvbpsi_demux_subdec_t *p_subdec = dvbpsi_demuxGetSubDec( p_dvbpsi_demux, SCTE18_TABLE_ID, 0x00 );
         if( p_subdec )
         {
@@ -715,7 +732,7 @@ static void ATSC_MGT_Callback( void *p_cb_basepid, dvbpsi_atsc_mgt_t* p_mgt )
     if( p_mgtpsip->p_ctx->p_mgt )
         dvbpsi_atsc_DeleteMGT( p_mgtpsip->p_ctx->p_mgt );
     p_mgtpsip->p_ctx->p_mgt = p_mgt;
-    p_mgtpsip->i_version = p_mgt->i_version;
+    p_mgtpsip->p_ctx->i_version = p_mgt->i_version;
 
     for( const dvbpsi_atsc_mgt_table_t *p_tab = p_mgt->p_first_table;
                                         p_tab; p_tab = p_tab->p_next )
@@ -726,7 +743,7 @@ static void ATSC_MGT_Callback( void *p_cb_basepid, dvbpsi_atsc_mgt_t* p_mgt )
             const uint8_t i_table_id = (p_tab->i_table_type == ATSC_TABLE_TYPE_CVCT)
                                      ? ATSC_CVCT_TABLE_ID
                                      : ATSC_TVCT_TABLE_ID;
-            if( !ATSC_ATTACH( p_mgtpsip->handle, VCT, i_table_id,
+            if( !ATSC_ATTACH( p_mgtpsip->p_ctx->p_handle, VCT, i_table_id,
                               GetPID(p_sys, 0)->u.p_pat->i_ts_id, p_base_pid ) )
                 msg_Dbg( p_demux, "  * pid=%d listening for ATSC VCT", p_base_pid->i_pid );
         }
@@ -740,7 +757,7 @@ static void ATSC_MGT_Callback( void *p_cb_basepid, dvbpsi_atsc_mgt_t* p_mgt )
             {
                 SetPIDFilter( p_demux->p_sys, pid, true );
                 pid->u.p_psip->p_ctx->i_tabletype = p_tab->i_table_type;
-                ATSC_Ready_SubDecoders( pid->u.p_psip->handle, pid );
+                ATSC_Ready_SubDecoders( pid->u.p_psip->p_ctx->p_handle, pid );
                 msg_Dbg( p_demux, "  * pid=%d reserved for ATSC EIT", pid->i_pid );
                 ARRAY_APPEND( p_mgtpsip->eit, pid );
             }
@@ -755,7 +772,7 @@ static void ATSC_MGT_Callback( void *p_cb_basepid, dvbpsi_atsc_mgt_t* p_mgt )
             {
                 SetPIDFilter( p_sys, pid, true );
                 pid->u.p_psip->p_ctx->i_tabletype = p_tab->i_table_type;
-                ATSC_Ready_SubDecoders( pid->u.p_psip->handle, pid );
+                ATSC_Ready_SubDecoders( pid->u.p_psip->p_ctx->p_handle, pid );
                 msg_Dbg( p_demux, "  * pid=%d reserved for ATSC ETT", pid->i_pid );
                 ARRAY_APPEND( p_mgtpsip->eit, pid );
             }
@@ -765,7 +782,7 @@ static void ATSC_MGT_Callback( void *p_cb_basepid, dvbpsi_atsc_mgt_t* p_mgt )
     }
 
     if( SCTE18_SI_BASE_PID == ATSC_BASE_PID &&
-        ts_dvbpsi_AttachRawSubDecoder( p_mgtpsip->handle, SCTE18_TABLE_ID, 0x00,
+        ts_dvbpsi_AttachRawSubDecoder( p_mgtpsip->p_ctx->p_handle, SCTE18_TABLE_ID, 0x00,
                                        SCTE18_Section_Callback, p_base_pid ) )
     {
         msg_Dbg( p_demux, "  * pid=%d listening for EAS", p_base_pid->i_pid );
@@ -782,10 +799,10 @@ static void ATSC_STT_Callback( void *p_cb_basepid, dvbpsi_atsc_stt_t* p_stt )
         dvbpsi_atsc_DeleteSTT( p_stt );
         return;
     }
-    demux_t *p_demux = (demux_t *) p_base_pid->u.p_psip->handle->p_sys;
+    demux_t *p_demux = (demux_t *) p_base_pid->u.p_psip->p_ctx->p_handle->p_sys;
     demux_sys_t *p_sys = p_demux->p_sys;
     ts_psip_context_t *p_ctx = p_base_pid->u.p_psip->p_ctx;
-    dvbpsi_t *p_handle = p_base_pid->u.p_psip->handle;
+    dvbpsi_t *p_handle = p_base_pid->u.p_psip->p_ctx->p_handle;
 
     if( !p_ctx->p_stt ) /* First call */
     {
@@ -828,11 +845,11 @@ static void ATSC_STT_RawCallback( dvbpsi_t *p_handle, const dvbpsi_psi_section_t
     }
 }
 
-bool ATSC_Attach_Dvbpsi_Base_Decoders( dvbpsi_t *p_handle, void *p_base_pid )
+bool ATSC_Attach_Dvbpsi_Base_Decoders( ts_psip_context_t *p_ctx, void *p_base_pid )
 {
-    if( !ATSC_ATTACH_WITH_FIXED_DECODER( p_handle, STT, ATSC_STT_TABLE_ID, 0x00, p_base_pid ) )
+    if( !ATSC_ATTACH_WITH_FIXED_DECODER( p_ctx->p_handle, STT, ATSC_STT_TABLE_ID, 0x00, p_base_pid ) )
     {
-        ATSC_Detach_Dvbpsi_Decoders( p_handle ); /* shouldn't be any, except demux */
+        ATSC_Detach_Dvbpsi_Decoders( p_ctx->p_handle ); /* shouldn't be any, except demux */
         return false;
     }
     return true;


=====================================
modules/demux/mpeg/ts_psip.h
=====================================
@@ -60,10 +60,9 @@ typedef struct ts_psip_context_t ts_psip_context_t;
 
 void ts_psip_Packet_Push( ts_pid_t *, const uint8_t * );
 
-ts_psip_context_t * ts_psip_context_New( void );
+ts_psip_context_t * ts_psip_context_New( demux_t * );
 void ts_psip_context_Delete( ts_psip_context_t * );
 
-bool ATSC_Attach_Dvbpsi_Base_Decoders( dvbpsi_t *p_handle, void *p_cb_data );
-void ATSC_Detach_Dvbpsi_Decoders( dvbpsi_t *p_handle );
+bool ATSC_Attach_Dvbpsi_Base_Decoders( ts_psip_context_t *, void *p_cb_data );
 
 #endif


=====================================
modules/demux/mpeg/ts_si.c
=====================================
@@ -37,6 +37,7 @@
 #include <dvbpsi/tot.h> /* TDT support */
 #include <dvbpsi/dr.h>
 #include <dvbpsi/psi.h>
+#include "../../mux/mpeg/dvbpsi_compat.h" /* dvbpsi_messages */
 
 #include "ts_si.h"
 #include "ts_arib.h"
@@ -55,6 +56,12 @@
 #include <assert.h>
 #include <limits.h>
 
+struct ts_si_context_t
+{
+    dvbpsi_t *p_handle;
+    int       i_version;
+};
+
 #ifndef SI_DEBUG_EIT
  #define SI_DEBUG_TIMESHIFT(t)
 #else
@@ -74,8 +81,8 @@ static void SINewTableCallBack( dvbpsi_t *h, uint8_t i_table_id,
 void ts_si_Packet_Push( ts_pid_t *p_pid, const uint8_t *p_pktbuffer )
 {
     if( likely(p_pid->type == TYPE_SI) &&
-        dvbpsi_decoder_present( p_pid->u.p_si->handle ) )
-        dvbpsi_packet_push( p_pid->u.p_si->handle, (uint8_t *) p_pktbuffer );
+        dvbpsi_decoder_present( p_pid->u.p_si->p_ctx->p_handle ) )
+        dvbpsi_packet_push( p_pid->u.p_si->p_ctx->p_handle, (uint8_t *) p_pktbuffer );
 }
 
 static char *EITConvertToUTF8( demux_t *p_demux,
@@ -154,14 +161,14 @@ static void SDTCallBack( demux_t *p_demux, dvbpsi_sdt_t *p_sdt )
 
     if( p_sys->es_creation != CREATE_ES ||
        !p_sdt->b_current_next ||
-        p_sdt->i_version == sdt->u.p_si->i_version )
+        p_sdt->i_version == sdt->u.p_si->p_ctx->i_version )
     {
         dvbpsi_sdt_delete( p_sdt );
         return;
     }
 
     /* First callback */
-    if( sdt->u.p_si->i_version == -1 )
+    if( sdt->u.p_si->p_ctx->i_version == -1 )
     {
         attach_SI_decoders( TS_SI_EIT_PID, "EIT", eitpid );
         attach_SI_decoders( TS_SI_TDT_PID, "TDT", tdtpid );
@@ -333,7 +340,7 @@ static void SDTCallBack( demux_t *p_demux, dvbpsi_sdt_t *p_sdt )
         vlc_meta_Delete( p_meta );
     }
 
-    sdt->u.p_si->i_version = p_sdt->i_version;
+    sdt->u.p_si->p_ctx->i_version = p_sdt->i_version;
     dvbpsi_sdt_delete( p_sdt );
 }
 
@@ -396,7 +403,7 @@ static void TDTCallBack( demux_t *p_demux, dvbpsi_tot_t *p_tdt )
     /* Because libdvbpsi is broken and deduplicating timestamp tables,
      * we need to reset it to get next timestamp callback */
     ts_pid_t *pid = ts_pid_Get( &p_sys->pids, TS_SI_TDT_PID );
-    dvbpsi_decoder_reset( pid->u.p_si->handle->p_decoder, true );
+    dvbpsi_decoder_reset( pid->u.p_si->p_ctx->p_handle->p_decoder, true );
     dvbpsi_tot_delete(p_tdt);
 
     es_out_Control( p_demux->out, ES_OUT_SET_EPG_TIME, (int64_t) p_sys->i_network_time );
@@ -806,8 +813,33 @@ bool ts_attach_SI_Tables_Decoders( ts_pid_t *p_pid )
     if( p_pid->type != TYPE_SI )
         return false;
 
-    if( dvbpsi_decoder_present( p_pid->u.p_si->handle ) )
+    if( dvbpsi_decoder_present( p_pid->u.p_si->p_ctx->p_handle ) )
         return true;
 
-    return dvbpsi_AttachDemux( p_pid->u.p_si->handle, SINewTableCallBack, p_pid );
+    return dvbpsi_AttachDemux( p_pid->u.p_si->p_ctx->p_handle, SINewTableCallBack, p_pid );
+}
+
+void ts_si_context_Delete( ts_si_context_t *p_ctx )
+{
+    if( dvbpsi_decoder_present( p_ctx->p_handle ) )
+        dvbpsi_DetachDemux( p_ctx->p_handle );
+    dvbpsi_delete( p_ctx->p_handle );
+    free( p_ctx );
+}
+
+ts_si_context_t * ts_si_context_New( demux_t *p_demux )
+{
+    ts_si_context_t *p_ctx = malloc(sizeof(*p_ctx));
+    if(likely(p_ctx))
+    {
+        p_ctx->p_handle = dvbpsi_new( &dvbpsi_messages, DVBPSI_MSG_DEBUG );
+        if( !p_ctx->p_handle )
+        {
+            free( p_ctx );
+            return NULL;
+        }
+        p_ctx->p_handle->p_sys = (void *) p_demux;
+        p_ctx->i_version = -1;
+    }
+    return p_ctx;
 }


=====================================
modules/demux/mpeg/ts_si.h
=====================================
@@ -37,8 +37,13 @@
 #define TS_SI_RUNSTATUS_RUNNING   0x04
 #define TS_SI_RUNSTATUS_OFF_AIR   0x05
 
+typedef struct ts_si_context_t ts_si_context_t;
+
 void ts_si_Packet_Push( ts_pid_t *, const uint8_t * );
 
+ts_si_context_t * ts_si_context_New( demux_t * );
+void ts_si_context_Delete( ts_si_context_t * );
+
 bool ts_attach_SI_Tables_Decoders( ts_pid_t * );
 
 #endif


=====================================
modules/demux/mpeg/ts_streams.c
=====================================
@@ -26,17 +26,6 @@
 #include "ts_streams.h"
 #include "ts_streams_private.h"
 
-#ifndef _DVBPSI_DVBPSI_H_
- #include <dvbpsi/dvbpsi.h>
-#endif
-#ifndef _DVBPSI_DEMUX_H_
- #include <dvbpsi/demux.h>
-#endif
-#include <dvbpsi/descriptor.h>
-#include <dvbpsi/pat.h>
-#include <dvbpsi/pmt.h>
-#include "../../mux/mpeg/dvbpsi_compat.h" /* dvbpsi_messages */
-
 #include <vlc_demux.h>
 #include <vlc_es.h>
 #include <vlc_es_out.h>
@@ -45,24 +34,18 @@
 #include "ts_pid.h"
 #include "ts.h"
 
+#include "ts_psi.h"
+#include "ts_si.h"
 #include "ts_psip.h"
 
-static inline bool handle_Init( demux_t *p_demux, dvbpsi_t **handle )
-{
-    *handle = dvbpsi_new( &dvbpsi_messages, DVBPSI_MSG_DEBUG );
-    if( !*handle )
-        return false;
-    (*handle)->p_sys = (void *) p_demux;
-    return true;
-}
-
 ts_pat_t *ts_pat_New( demux_t *p_demux )
 {
     ts_pat_t *pat = malloc( sizeof( ts_pat_t ) );
     if( !pat )
         return NULL;
 
-    if( !handle_Init( p_demux, &pat->handle ) )
+    pat->p_ctx = ts_psi_context_New( p_demux );
+    if( !pat->p_ctx )
     {
         free( pat );
         return NULL;
@@ -78,9 +61,7 @@ ts_pat_t *ts_pat_New( demux_t *p_demux )
 
 void ts_pat_Del( demux_t *p_demux, ts_pat_t *pat )
 {
-    if( dvbpsi_decoder_present( pat->handle ) )
-        dvbpsi_pat_detach( pat->handle );
-    dvbpsi_delete( pat->handle );
+    ts_psi_context_Delete( pat->p_ctx );
     for( int i=0; i<pat->programs.i_size; i++ )
         PIDRelease( p_demux, pat->programs.p_elems[i] );
     ARRAY_RESET( pat->programs );
@@ -105,7 +86,8 @@ ts_pmt_t *ts_pmt_New( demux_t *p_demux )
     if( !pmt )
         return NULL;
 
-    if( !handle_Init( p_demux, &pmt->handle ) )
+    pmt->p_ctx = ts_psi_context_New( p_demux );
+    if( !pmt->p_ctx )
     {
         free( pmt );
         return NULL;
@@ -146,9 +128,7 @@ ts_pmt_t *ts_pmt_New( demux_t *p_demux )
 
 void ts_pmt_Del( demux_t *p_demux, ts_pmt_t *pmt )
 {
-    if( dvbpsi_decoder_present( pmt->handle ) )
-        dvbpsi_pmt_detach( pmt->handle );
-    dvbpsi_delete( pmt->handle );
+    ts_psi_context_Delete( pmt->p_ctx );
     for( int i=0; i<pmt->e_streams.i_size; i++ )
         PIDRelease( p_demux, pmt->e_streams.p_elems[i] );
     ARRAY_RESET( pmt->e_streams );
@@ -326,13 +306,13 @@ ts_si_t *ts_si_New( demux_t *p_demux )
     if( !si )
         return NULL;
 
-    if( !handle_Init( p_demux, &si->handle ) )
+    si->p_ctx = ts_si_context_New( p_demux );
+    if( !si->p_ctx )
     {
         free( si );
         return NULL;
     }
 
-    si->i_version  = -1;
     si->eitpid = NULL;
     si->tdtpid = NULL;
     si->cdtpid = NULL;
@@ -342,9 +322,7 @@ ts_si_t *ts_si_New( demux_t *p_demux )
 
 void ts_si_Del( demux_t *p_demux, ts_si_t *si )
 {
-    if( dvbpsi_decoder_present( si->handle ) )
-        dvbpsi_DetachDemux( si->handle );
-    dvbpsi_delete( si->handle );
+    ts_si_context_Delete( si->p_ctx );
     if( si->eitpid )
         PIDRelease( p_demux, si->eitpid );
     if( si->tdtpid )
@@ -356,17 +334,10 @@ void ts_si_Del( demux_t *p_demux, ts_si_t *si )
 
 void ts_psip_Del( demux_t *p_demux, ts_psip_t *psip )
 {
-    if( psip->p_ctx )
-        ts_psip_context_Delete( psip->p_ctx );
+    ts_psip_context_Delete( psip->p_ctx );
 
     ts_pes_ChainDelete_es( p_demux, psip->p_eas_es );
 
-    if( psip->handle )
-    {
-        ATSC_Detach_Dvbpsi_Decoders( psip->handle );
-        dvbpsi_delete( psip->handle );
-    }
-
     for( int i=0; i<psip->eit.i_size; i++ )
         PIDRelease( p_demux, psip->eit.p_elems[i] );
     ARRAY_RESET( psip->eit );
@@ -380,21 +351,15 @@ ts_psip_t *ts_psip_New( demux_t *p_demux )
     if( !psip )
         return NULL;
 
-    if( !handle_Init( p_demux, &psip->handle ) )
+    psip->p_ctx = ts_psip_context_New( p_demux );
+    if( !psip->p_ctx )
     {
         free( psip );
         return NULL;
     }
 
     ARRAY_INIT( psip->eit );
-    psip->i_version  = -1;
     psip->p_eas_es = NULL;
-    psip->p_ctx = ts_psip_context_New();
-    if( !psip->p_ctx )
-    {
-        ts_psip_Del( p_demux, psip );
-        psip = NULL;
-    }
 
     return psip;
 }


=====================================
modules/demux/mpeg/ts_streams_private.h
=====================================
@@ -19,7 +19,7 @@
 #ifndef VLC_TS_STREAMS_PRIVATE_H
 #define VLC_TS_STREAMS_PRIVATE_H
 
-typedef struct dvbpsi_s dvbpsi_t;
+typedef struct ts_psi_context_t ts_psi_context_t;
 typedef struct ts_sections_processor_t ts_sections_processor_t;
 
 #include "mpeg4_iod.h"
@@ -31,17 +31,17 @@ typedef struct ts_sections_processor_t ts_sections_processor_t;
 
 struct ts_pat_t
 {
+    ts_psi_context_t *p_ctx;
     int             i_version;
     int             i_ts_id;
     bool            b_generated;
-    dvbpsi_t       *handle;
     DECL_ARRAY(ts_pid_t *) programs;
 
 };
 
 struct ts_pmt_t
 {
-    dvbpsi_t       *handle;
+    ts_psi_context_t *p_ctx;
     int             i_version;
     int             i_number;
     int             i_pid_pcr;
@@ -150,8 +150,7 @@ typedef struct ts_si_context_t ts_si_context_t;
 
 struct ts_si_t
 {
-    dvbpsi_t *handle;
-    int       i_version;
+    ts_si_context_t *p_ctx;
     /* Track successfully set pid */
     ts_pid_t *eitpid;
     ts_pid_t *tdtpid;
@@ -162,10 +161,8 @@ typedef struct ts_psip_context_t ts_psip_context_t;
 
 struct ts_psip_t
 {
-    dvbpsi_t       *handle;
-    int             i_version;
-    ts_es_t    *p_eas_es;
     ts_psip_context_t *p_ctx;
+    ts_es_t    *p_eas_es;
     /* Used to track list of active pid for eit/ett, to call PIDRelease on them.
        VCT table could have been used, but PIDSetup can fail, and we can't alter
        the VCT table accordingly without going ahead of more troubles */



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cb58ece06c2f734e3691dfda4aa85833874d0d84...348ee31a5d57348345d63e8f246bdc40eb7b10a2

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cb58ece06c2f734e3691dfda4aa85833874d0d84...348ee31a5d57348345d63e8f246bdc40eb7b10a2
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list