[vlc-commits] [Git][videolan/vlc][master] 2 commits: demux: ts: fix post discontinuity flag

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Nov 26 21:14:29 UTC 2022



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


Commits:
10ffa49f by Francois Cartegnie at 2022-11-26T20:59:42+00:00
demux: ts: fix post discontinuity flag

- - - - -
09a265cf by Francois Cartegnie at 2022-11-26T20:59:42+00:00
demux: ts: flag truncation as corruption

- - - - -


6 changed files:

- modules/demux/mpeg/ts.c
- modules/demux/mpeg/ts_pes.c
- modules/demux/mpeg/ts_pes.h
- modules/demux/mpeg/ts_streams.c
- modules/demux/mpeg/ts_streams_private.h
- test/modules/demux/ts_pes.c


Changes:

=====================================
modules/demux/mpeg/ts.c
=====================================
@@ -1547,7 +1547,7 @@ static void SendDataChain( demux_t *p_demux, ts_es_t *p_es, block_t *p_chain )
  * gathering stuff
  ****************************************************************************/
 static void ParsePESDataChain( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes,
-                               stime_t i_append_pcr )
+                               uint32_t i_flags, stime_t i_append_pcr )
 {
     uint8_t header[34];
     unsigned i_pes_size = 0;
@@ -1685,6 +1685,12 @@ static void ParsePESDataChain( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes,
             p_chain = p_chain->p_next;
             p_block->p_next = NULL;
 
+            if( i_flags )
+            {
+                p_block->i_flags |= i_flags;
+                i_flags = 0;
+            }
+
             if( !p_pmt->pcr.b_fix_done ) /* Not seen yet */
                 PCRFixHandle( p_demux, p_pmt, p_block );
 
@@ -1786,9 +1792,10 @@ static void ParsePESDataChain( demux_t *p_demux, ts_pid_t *pid, block_t *p_pes,
     }
 }
 
-static void PESDataChainHandle( vlc_object_t *p_obj, void *priv, block_t *p_data, stime_t i_appendpcr )
+static void PESDataChainHandle( vlc_object_t *p_obj, void *priv, block_t *p_data,
+                                uint32_t i_flags, stime_t i_appendpcr )
 {
-    ParsePESDataChain( (demux_t *)p_obj, (ts_pid_t *) priv, p_data, i_appendpcr );
+    ParsePESDataChain( (demux_t *)p_obj, (ts_pid_t *) priv, p_data, i_flags, i_appendpcr );
 }
 
 static block_t* ReadTSPacket( demux_t *p_demux )
@@ -1932,6 +1939,7 @@ static inline void FlushESBuffer( ts_stream_t *p_pes )
         p_pes->gather.p_data = NULL;
         p_pes->gather.pp_last = &p_pes->gather.p_data;
         p_pes->gather.i_saved = 0;
+        p_pes->gather.i_block_flags = 0;
     }
     if( p_pes->p_proc )
         ts_stream_processor_Reset( p_pes->p_proc );


=====================================
modules/demux/mpeg/ts_pes.c
=====================================
@@ -105,12 +105,14 @@ static bool ts_pes_Push( ts_pes_parse_callback *cb,
     if ( b_unit_start && p_pes->gather.p_data )
     {
         block_t *p_datachain = p_pes->gather.p_data;
+        uint32_t i_flags = p_pes->gather.i_block_flags;
         /* Flush the pes from pid */
         p_pes->gather.p_data = NULL;
         p_pes->gather.i_data_size = 0;
         p_pes->gather.i_gathered = 0;
+        p_pes->gather.i_block_flags = 0;
         p_pes->gather.pp_last = &p_pes->gather.p_data;
-        cb->pf_parse( cb->p_obj, cb->priv, p_datachain, p_pes->gather.i_append_pcr );
+        cb->pf_parse( cb->p_obj, cb->priv, p_datachain, i_flags, p_pes->gather.i_append_pcr );
         b_ret = true;
     }
 
@@ -191,13 +193,21 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb,
     /* On dropped blocks discontinuity */
     else if( p_pkt->i_flags & BLOCK_FLAG_DISCONTINUITY )
     {
+        /* If we know the final size and didn't gather enough bytes it is corrupted
+           or if the discontinuity doesn't carry the start code */
+        if( p_pes->gather.i_gathered && (p_pes->gather.i_data_size ||
+                                         (b_aligned_ts_payload && !b_unit_start) ) )
+            p_pes->gather.i_block_flags |= BLOCK_FLAG_CORRUPTED;
+        b_ret |= ts_pes_Push( cb, p_pes, NULL, true, i_append_pcr );
+
         /* it can't match the target size and need to resync on sync code */
         p_pes->gather.i_data_size = 0;
         /* can't reuse prev bytes to lookup sync code */
         p_pes->gather.i_saved = 0;
         /* Propagate to output block to notify packetizers/decoders */
         if( p_pes->p_es )
-            p_pes->p_es->i_next_block_flags |= BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED;
+            p_pes->p_es->i_next_block_flags |= BLOCK_FLAG_DISCONTINUITY;
+        p_pes->gather.i_block_flags|= BLOCK_FLAG_DISCONTINUITY;
     }
 
     if ( unlikely(p_pes->gather.i_saved > 0) )


=====================================
modules/demux/mpeg/ts_pes.h
=====================================
@@ -26,7 +26,7 @@ typedef struct
 {
     vlc_object_t *p_obj;
     void *priv;
-    void(*pf_parse)(vlc_object_t *, void *, block_t *, stime_t);
+    void(*pf_parse)(vlc_object_t *, void *, block_t *, uint32_t, stime_t );
 } ts_pes_parse_callback;
 
 bool ts_pes_Drain( ts_pes_parse_callback *cb, ts_stream_t *p_pes );


=====================================
modules/demux/mpeg/ts_streams.c
=====================================
@@ -288,6 +288,7 @@ ts_stream_t *ts_stream_New( demux_t *p_demux, ts_pmt_t *p_program )
     pes->gather.p_data = NULL;
     pes->gather.pp_last = &pes->gather.p_data;
     pes->gather.i_saved = 0;
+    pes->gather.i_block_flags = 0;
     pes->gather.i_append_pcr = VLC_TICK_INVALID;
     pes->b_broken_PUSI_conformance = false;
     pes->b_always_receive = false;


=====================================
modules/demux/mpeg/ts_streams_private.h
=====================================
@@ -128,6 +128,7 @@ struct ts_stream_t
         uint8_t     saved[5];
         size_t      i_saved;
         stime_t     i_append_pcr;
+        uint32_t    i_block_flags;
     } gather;
 
     bool        b_always_receive;


=====================================
test/modules/demux/ts_pes.c
=====================================
@@ -31,13 +31,15 @@
 
 #include "../../libvlc/test.h"
 
-static void Parse(vlc_object_t *obj, void *priv, block_t *data, stime_t t)
+static void Parse(vlc_object_t *obj, void *priv, block_t *data,
+                  uint32_t i_flags, stime_t t)
 {
     VLC_UNUSED(obj);
     VLC_UNUSED(t);
     block_t **pp_append = (block_t **) priv;
     fprintf(stderr, "recv: ");
     data = block_ChainGather(data);
+    data->i_flags = i_flags;
     for(size_t i=0; i<data->i_buffer; i++)
         fprintf(stderr, "%2.2x ", data->p_buffer[i]);
     fprintf(stderr, "\n");
@@ -267,5 +269,35 @@ int main()
         RESET;
     }
 
+    /* PKT FLAGS */
+    PKT_FROM(aligned1);
+    pkt->i_buffer -= 1;
+    ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
+    PKT_FROM(aligned1);
+    pkt->i_flags |= BLOCK_FLAG_DISCONTINUITY;
+    ASSERT(ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
+    ASSERT(output);
+    block_ChainProperties(output, &outputcount, &outputsize, NULL);
+    ASSERT(outputcount == 2);
+    ASSERT(outputsize == sizeof(aligned1) * 2 - 1);
+    ASSERT(output->i_flags & BLOCK_FLAG_CORRUPTED); /* First block is corrupted 15/16 bytes */
+    ASSERT((output->i_flags & BLOCK_FLAG_DISCONTINUITY) == 0);
+    ASSERT(output->p_next->i_flags == BLOCK_FLAG_DISCONTINUITY); /* Next block resumes as discont */
+    RESET;
+
+    PKT_FROM(aligned1);
+    SetWBE(&pkt->p_buffer[4], 0); /* Set 0 sized to prevent immediate output */
+    ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
+    PKT_FROM(aligned1);
+    SetWBE(&pkt->p_buffer[4], 0);
+    pkt->i_flags |= BLOCK_FLAG_DISCONTINUITY;
+    ASSERT(ts_pes_Gather(&cb, &pes, pkt, true, true, 0)); /* should output on sync||discont */
+    ASSERT(output);
+    block_ChainProperties(output, &outputcount, &outputsize, NULL);
+    ASSERT(outputcount == 1);
+    ASSERT(outputsize == sizeof(aligned1));
+    //ASSERT(output->i_flags == BLOCK_FLAG_CORRUPTED); /* First might be corrupted but we don't really know */
+    RESET;
+
     return 0;
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/183398650f0e30846a2fd481efdc79ecb538ed92...09a265cf0cb48d31caa11753dda712bb4231e90b

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/183398650f0e30846a2fd481efdc79ecb538ed92...09a265cf0cb48d31caa11753dda712bb4231e90b
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