[vlc-commits] [Git][videolan/vlc][master] 6 commits: demux: ts: use define for PES header size

Steve Lhomme (@robUx4) gitlab at videolan.org
Sun Jan 21 09:23:58 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
73214b7a by François Cartegnie at 2024-01-21T09:01:11+00:00
demux: ts: use define for PES header size

- - - - -
e97f380c by François Cartegnie at 2024-01-21T09:01:11+00:00
demux: ts: prefix private flag with PRIVATE

- - - - -
855b2b99 by François Cartegnie at 2024-01-21T09:01:11+00:00
test: ts_pes: change pkt value size

full ts pkt size is misleading at PES level

- - - - -
c455f708 by François Cartegnie at 2024-01-21T09:01:11+00:00
test: ts_pes: add one more early output case

- - - - -
005e6023 by François Cartegnie at 2024-01-21T09:01:11+00:00
test: ts_pes: don't append PES header as continued payload

- - - - -
83621b88 by François Cartegnie at 2024-01-21T09:01:11+00:00
test: ts_pes: split end of fixed size aggregation tests

differentiating correct and overflowed

- - - - -


4 changed files:

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


Changes:

=====================================
modules/demux/mpeg/ts.c
=====================================
@@ -2596,7 +2596,7 @@ static block_t * ProcessTSPacket( demux_t *p_demux, ts_pid_t *pid, block_t *p_pk
 
                 /* ... or don't ignore for our Bluray still frames and seek hacks */
                 if(p[5] == 0x82 && !strncmp((const char *)&p[7], "VLC_DISCONTINU", 14))
-                    p_pkt->i_flags |= BLOCK_FLAG_SOURCE_RANDOM_ACCESS;
+                    p_pkt->i_flags |= BLOCK_FLAG_PRIVATE_SOURCE_RANDOM_ACCESS;
             }
 #if 0
             if( p[5]&0x40 )


=====================================
modules/demux/mpeg/ts_pes.c
=====================================
@@ -181,7 +181,7 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb,
 
     /* Seek discontinuity, we need to drop or output currently
      * gathered data */
-    if( p_pkt->i_flags & BLOCK_FLAG_SOURCE_RANDOM_ACCESS )
+    if( p_pkt->i_flags & BLOCK_FLAG_PRIVATE_SOURCE_RANDOM_ACCESS )
     {
         p_pes->gather.i_saved = 0;
         /* Flush/output current */
@@ -213,7 +213,7 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb,
     if ( unlikely(p_pes->gather.i_saved > 0) )
     {
         /* Saved from previous packet end */
-        assert(p_pes->gather.i_saved < 6);
+        assert(p_pes->gather.i_saved < TS_PES_HEADER_SIZE);
         if( !b_aligned_ts_payload )
         {
             p_pkt = block_Realloc( p_pkt, p_pes->gather.i_saved, p_pkt->i_buffer );
@@ -227,7 +227,7 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb,
     {
         assert( p_pes->gather.i_saved == 0 );
 
-        if( p_pes->gather.p_data == NULL && b_unit_start && !b_first_sync_done && p_pkt->i_buffer >= 6 )
+        if( p_pes->gather.p_data == NULL && b_unit_start && !b_first_sync_done && p_pkt->i_buffer >= TS_PES_HEADER_SIZE )
         {
             if( likely(b_aligned_ts_payload) )
             {
@@ -260,7 +260,7 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb,
             /* now points to PES header */
             p_pes->gather.i_data_size = GetWBE(&p_pkt->p_buffer[4]);
             if( p_pes->gather.i_data_size > 0 )
-                p_pes->gather.i_data_size += 6;
+                p_pes->gather.i_data_size += TS_PES_HEADER_SIZE;
             b_first_sync_done = true; /* Because if size is 0, we would not look for second sync */
         }
         else
@@ -297,11 +297,11 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb,
                 {
                     b_ret |= ts_pes_Push( cb, p_pes, NULL, true, i_append_pcr );
                     /* now points to PES header */
-                    if( p_pkt->i_buffer >= 6 )
+                    if( p_pkt->i_buffer >= TS_PES_HEADER_SIZE )
                     {
                         p_pes->gather.i_data_size = GetWBE(&p_pkt->p_buffer[4]);
                         if( p_pes->gather.i_data_size > 0 )
-                            p_pes->gather.i_data_size += 6;
+                            p_pes->gather.i_data_size += TS_PES_HEADER_SIZE;
                     }
                 }
                 /* Append or finish current/start new PES depending on unit_start */
@@ -310,7 +310,7 @@ bool ts_pes_Gather( ts_pes_parse_callback *cb,
             }
         }
 
-        if( unlikely(p_pkt && p_pkt->i_buffer < 6) )
+        if( unlikely(p_pkt && p_pkt->i_buffer < TS_PES_HEADER_SIZE) )
         {
             /* save and prepend to next packet */
             assert(!b_single_payload);


=====================================
modules/demux/mpeg/ts_pes.h
=====================================
@@ -20,7 +20,9 @@
 #ifndef VLC_TS_PES_H
 #define VLC_TS_PES_H
 
-#define BLOCK_FLAG_SOURCE_RANDOM_ACCESS (1 << BLOCK_FLAG_PRIVATE_SHIFT)
+#define BLOCK_FLAG_PRIVATE_SOURCE_RANDOM_ACCESS (1 << BLOCK_FLAG_PRIVATE_SHIFT)
+
+#define TS_PES_HEADER_SIZE 6
 
 typedef struct
 {


=====================================
test/modules/demux/ts_pes.c
=====================================
@@ -92,6 +92,11 @@ int main(void)
     pes.transport = TS_TRANSPORT_PES;
     pes.gather.pp_last = &pes.gather.p_data;
 
+    /* filler packet */
+    const uint8_t dummy0[] = {
+        0xFF,
+    };
+
     /* General case, aligned payloads */
     /* payload == 0 */
     const uint8_t aligned0[] = {
@@ -102,7 +107,7 @@ int main(void)
     ASSERT(output);
     block_ChainProperties(output, &outputcount, &outputsize, NULL);
     ASSERT(outputcount == 1);
-    ASSERT(outputsize == 6+3);
+    ASSERT(outputsize == TS_PES_HEADER_SIZE+3);
     ASSERT(!memcmp(aligned0, output->p_buffer, outputsize));
     RESET;
     /* no output if not unit start */
@@ -127,7 +132,7 @@ int main(void)
     ASSERT(output);
     block_ChainProperties(output, &outputcount, &outputsize, NULL);
     ASSERT(outputcount == 1);
-    ASSERT(outputsize == 6+3+6);
+    ASSERT(outputsize == TS_PES_HEADER_SIZE+3+6);
     ASSERT(!memcmp(aligned1, output->p_buffer, outputsize));
     RESET;
     /* no output if not unit start */
@@ -143,13 +148,27 @@ int main(void)
     ASSERT(!output);
     RESET;
 
-    /* packets assembly, payload > 188 - 6 - 4 */
-    PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
+    /* packets assembly, exact size, payload > 150 - TS_PES_HEADER_SIZE - 4 */
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
     SetWBE(&pkt->p_buffer[4], 250);
     ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
     ASSERT(!output);
     ASSERT(pes.gather.i_data_size == 256);
-    PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
+    PKT_FROMSZ(dummy0, 106-sizeof(dummy0));
+    ASSERT(ts_pes_Gather(&cb, &pes, pkt, false, true, 0));
+    ASSERT(output);
+    block_ChainProperties(output, &outputcount, &outputsize, NULL);
+    ASSERT(outputcount == 1);
+    ASSERT(outputsize == 256);
+    RESET;
+
+    /* packets assembly, incorrect size, overflow by %15 pkt loss or size field corruption */
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
+    SetWBE(&pkt->p_buffer[4], 250);
+    ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
+    ASSERT(!output);
+    ASSERT(pes.gather.i_data_size == 256);
+    PKT_FROMSZ(dummy0, 150-sizeof(dummy0));
     ASSERT(ts_pes_Gather(&cb, &pes, pkt, false, true, 0));
     ASSERT(output);
     block_ChainProperties(output, &outputcount, &outputsize, NULL);
@@ -157,41 +176,56 @@ int main(void)
     ASSERT(outputsize == 256);
     RESET;
 
-    /* no packets assembly from unit start */
+    /* no packets assembly from unit start, early termination by fixed size */
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
+    SetWBE(&pkt->p_buffer[4], 250);
+    ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
+    ASSERT(!output);
+    ASSERT(pes.gather.i_data_size == 256);
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
+    ASSERT(ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
+    ASSERT(output);
+    block_ChainProperties(output, &outputcount, &outputsize, NULL);
+    ASSERT(outputcount == 2);
+    RESET;
+
+    /* no packets assembly from unit start, early termination by undef size  */
     PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
     SetWBE(&pkt->p_buffer[4], 250);
     ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
     ASSERT(!output);
     ASSERT(pes.gather.i_data_size == 256);
     PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
+    SetWBE(&pkt->p_buffer[4], 0);
     ASSERT(ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
     ASSERT(output);
     block_ChainProperties(output, &outputcount, &outputsize, NULL);
-    ASSERT(outputcount == 2);
+    ASSERT(outputcount == 1);
+    ASSERT(outputsize == 188);
     RESET;
 
     /* packets assembly, payload undef, use next sync code from another payload undef */
-    PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
     SetWBE(&pkt->p_buffer[4], 0);
     ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
     ASSERT(!output);
     ASSERT(pes.gather.i_data_size == 0);
-    PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
     SetWBE(&pkt->p_buffer[4], 0);
     ASSERT(ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
     ASSERT(output);
     block_ChainProperties(output, &outputcount, &outputsize, NULL);
     ASSERT(outputcount == 1);
-    ASSERT(outputsize == 188);
+    ASSERT(outputsize == 150);
     RESET;
 
     /* packets assembly, payload undef, use next sync code from fixed size */
-    PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
     SetWBE(&pkt->p_buffer[4], 0);
     ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
     ASSERT(!output);
     ASSERT(pes.gather.i_data_size == 0);
-    PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
     ASSERT(ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
     ASSERT(output);
     block_ChainProperties(output, &outputcount, &outputsize, NULL);
@@ -199,7 +233,7 @@ int main(void)
     RESET;
 
     /* packets assembly, payload undef, use next sync code from fixed size but uncomplete */
-    PKT_FROMSZ(aligned1, 188-sizeof(aligned1));
+    PKT_FROMSZ(aligned1, 150-sizeof(aligned1));
     SetWBE(&pkt->p_buffer[4], 0);
     ASSERT(!ts_pes_Gather(&cb, &pes, pkt, true, true, 0));
     ASSERT(!output);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c08d8d3f830bb8aa65b83792429705478e7a17d9...83621b88b456ff7f91a6452213c2c22286e42452

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/c08d8d3f830bb8aa65b83792429705478e7a17d9...83621b88b456ff7f91a6452213c2c22286e42452
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