[vlc-commits] [Git][videolan/vlc][master] demux: ps: unify es creation code

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu Apr 28 11:34:43 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
8036a0f6 by Francois Cartegnie at 2022-04-28T11:16:24+00:00
demux: ps: unify es creation code

- - - - -


2 changed files:

- modules/demux/mpeg/ps.c
- modules/demux/mpeg/ps.h


Changes:

=====================================
modules/demux/mpeg/ps.c
=====================================
@@ -121,6 +121,25 @@ static int Control( demux_t *p_demux, int i_query, va_list args );
 static int      ps_pkt_resynch( stream_t *, int, bool );
 static block_t *ps_pkt_read   ( stream_t * );
 
+static void CreateOrUpdateES( demux_t*p_demux )
+{
+    demux_sys_t *p_sys = p_demux->p_sys;
+
+    for( int i = 0; i < PS_TK_COUNT; i++ )
+    {
+        ps_track_t *tk = &p_sys->tk[i];
+        if( !tk->b_updated )
+            continue;
+
+        if( tk->es )
+            es_out_Del( p_demux->out, tk->es );
+
+        if( tk->fmt.i_cat != UNKNOWN_ES )
+            tk->es = es_out_Add( p_demux->out, &tk->fmt );
+        tk->b_updated = false;
+    }
+}
+
 /*****************************************************************************
  * Open
  *****************************************************************************/
@@ -483,23 +502,8 @@ static int Demux( demux_t *p_demux )
         break;
 
     case PS_STREAM_ID_SYSTEM_HEADER:
-        if( !ps_pkt_parse_system( p_pkt->p_buffer, p_pkt->i_buffer,
-                                  &p_sys->psm, p_sys->tk ) )
-        {
-            int i;
-            for( i = 0; i < PS_TK_COUNT; i++ )
-            {
-                ps_track_t *tk = &p_sys->tk[i];
-
-                if( !tk->b_configured && tk->fmt.i_cat != UNKNOWN_ES )
-                {
-                    if( tk->b_seen )
-                        tk->es = es_out_Add( p_demux->out, &tk->fmt );
-                     /* else create when seeing packet */
-                    tk->b_configured = true;
-                }
-            }
-        }
+        ps_pkt_parse_system( p_pkt->p_buffer, p_pkt->i_buffer,
+                            &p_sys->psm, p_sys->tk );
         block_Release( p_pkt );
         break;
 
@@ -572,9 +576,9 @@ static int Demux( demux_t *p_demux )
 #endif
                     }
 
-                    tk->es = es_out_Add( p_demux->out, &tk->fmt );
                     b_new = true;
                     tk->b_configured = true;
+                    tk->b_updated = true;
                 }
                 else
                 {
@@ -582,16 +586,13 @@ static int Demux( demux_t *p_demux )
                 }
             }
 
-            /* Late creation from system header */
-            if( !tk->b_seen && tk->b_configured && !tk->es && tk->fmt.i_cat != UNKNOWN_ES )
-                tk->es = es_out_Add( p_demux->out, &tk->fmt );
-
-            tk->b_seen = true;
+            /* Create all configured/updated ES when seeing a track packet */
+            if( tk->b_updated )
+                CreateOrUpdateES( p_demux );
 
             /* The popular VCD/SVCD subtitling WinSubMux does not
              * renumber the SCRs when merging subtitles into the PES */
-            if( tk->b_seen && !p_sys->b_bad_scr &&
-                p_sys->format == MPEG_PS &&
+            if( !p_sys->b_bad_scr && p_sys->format == MPEG_PS &&
                 ( tk->fmt.i_codec == VLC_CODEC_OGT ||
                   tk->fmt.i_codec == VLC_CODEC_CVD ) )
             {


=====================================
modules/demux/mpeg/ps.h
=====================================
@@ -57,7 +57,7 @@ static inline const uint8_t *ps_id_to_lang( const ps_psm_t *, uint16_t );
 typedef struct
 {
     bool        b_configured;
-    bool        b_seen;
+    bool        b_updated;
     int         i_skip;
     int         i_id;
     int         i_next_block_flags;
@@ -75,7 +75,7 @@ static inline void ps_track_init( ps_track_t tk[PS_TK_COUNT] )
     for( i = 0; i < PS_TK_COUNT; i++ )
     {
         tk[i].b_configured = false;
-        tk[i].b_seen = false;
+        tk[i].b_updated = false;
         tk[i].i_skip = 0;
         tk[i].i_id   = 0;
         tk[i].i_next_block_flags = 0;
@@ -710,7 +710,8 @@ static inline int ps_psm_fill( ps_psm_t *p_psm,
     /* Check/Modify our existing tracks */
     for( int i = 0; i < PS_TK_COUNT; i++ )
     {
-        if( !tk[i].b_configured || !tk[i].es ) continue;
+        if( !tk[i].b_configured )
+            continue;
 
         ps_track_t tk_tmp;
         es_format_Init( &tk_tmp.fmt, UNKNOWN_ES, 0 );
@@ -725,12 +726,12 @@ static inline int ps_psm_fill( ps_psm_t *p_psm,
             continue;
         }
 
-        es_out_Del( out, tk[i].es );
-        es_format_Clean( &tk[i].fmt );
-
+        /* replace with new version */
         tk_tmp.b_configured = true;
+        tk_tmp.b_updated = true;
+        tk_tmp.es = tk[i].es;
+        es_format_Clean( &tk[i].fmt );
         tk[i] = tk_tmp;
-        tk[i].es = es_out_Add( out, &tk[i].fmt );
     }
 
     return VLC_SUCCESS;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/8036a0f6f4c93c2a9fb981dec5734bb554e8a0bc

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/8036a0f6f4c93c2a9fb981dec5734bb554e8a0bc
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