[vlc-commits] [Git][videolan/vlc][master] 12 commits: codec: cc: use a sanity check value defined in the specs

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Jun 13 06:44:19 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
9adff1fb by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: use a sanity check value defined in the specs

Corresponds to the "DVD Caption Block" caption_filler in [^1].
Doing a bit shift may also be faster.

[^1]: https://en.wikipedia.org/wiki/EIA-608#DVD_GOP_user_data_insertion

- - - - -
7ee7db54 by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: skip used bytes explicitly

- - - - -
ecf0ae1e by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: factorize the DVD Caption Block size

- - - - -
a2fae275 by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: move the b_truncate handling outside of the block loop

The b_truncate is an added field, not substracted. It corresponds to
caption_extra_field_added in [^1].
We add a single field rather than adding 2 fields and then removing one.

[^1] https://en.wikipedia.org/wiki/EIA-608#DVD_GOP_user_data_insertion

- - - - -
078b9651 by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: read the odd_field flag in each caption block

Rather than the value in the header.
If one bit is bogus only one block is impacted, rather than the whole caption.

- - - - -
9620537c by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: remove unused i_field_first

- - - - -
2d1a1e0d by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: return an error when trying to fill a full array

- - - - -
bce34332 by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: use return value from cc_AppendData()

- - - - -
7fa8bb70 by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: unroll the loop on the 2 fields

- - - - -
0fdf54d0 by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: add b_truncate back in the loop

Now that the loop is unrolled we don't need a special if at every iteration.

- - - - -
5dd3a8d0 by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: exit the loop when the CC array is full

- - - - -
354bd431 by Steve Lhomme at 2025-06-13T06:30:12+00:00
codec: cc: read all available blocks

Rather than not reading anything if all blocks are not available.
The b_truncate or i_count_cc2 bits could be bogus but we can still extract what we have.

- - - - -


2 changed files:

- modules/codec/cc.h
- modules/demux/ty.c


Changes:

=====================================
modules/codec/cc.h
=====================================
@@ -194,8 +194,11 @@ static inline void cc_ProbeCEA708( cc_data_t *c, uint8_t i_field, const uint8_t
     cc_ProbeCEA708OneByte( c, false, cc[1] );
 }
 
-static inline void cc_AppendData( cc_data_t *c, uint8_t cc_preamble, const uint8_t cc[2] )
+static inline bool cc_AppendData( cc_data_t *c, uint8_t cc_preamble, const uint8_t cc[2] )
 {
+    if (c->i_data + 3 > ARRAY_SIZE(c->p_data))
+        return false;
+
     const uint8_t i_field = cc_preamble & 0x03;
     if( i_field == 0 || i_field == 1 ) /* NTSC_CC_FIELD_1 NTSC_CC_FIELD_2 */
     {
@@ -211,6 +214,7 @@ static inline void cc_AppendData( cc_data_t *c, uint8_t cc_preamble, const uint8
     c->p_data[c->i_data++] = cc_preamble;
     c->p_data[c->i_data++] = cc[0];
     c->p_data[c->i_data++] = cc[1];
+    return true;
 }
 
 static inline void cc_Extract( cc_data_t *c, enum cc_payload_type_e i_payload_type,
@@ -229,11 +233,9 @@ static inline void cc_Extract( cc_data_t *c, enum cc_payload_type_e i_payload_ty
     {
         for( int i = 0; i + 2 < i_src; i += 3 )
         {
-            if( c->i_data + 3 > CC_MAX_DATA_SIZE )
-                break;
-
             const uint8_t *cc = &p_src[i];
-            cc_AppendData( c, cc[0], &cc[1] );
+            if (!cc_AppendData( c, cc[0], &cc[1] ))
+                break;
         }
         c->b_reorder = true;
     }
@@ -275,10 +277,8 @@ static inline void cc_Extract( cc_data_t *c, enum cc_payload_type_e i_payload_ty
 
         for( i = 0; i < i_count_cc; i++, cc += 3 )
         {
-            if( c->i_data + 3 > CC_MAX_DATA_SIZE )
+            if (!cc_AppendData( c, cc[0], &cc[1] ))
                 break;
-
-            cc_AppendData( c, cc[0], &cc[1] );
         }
         c->b_reorder = true;
     }
@@ -298,29 +298,22 @@ static inline void cc_Extract( cc_data_t *c, enum cc_payload_type_e i_payload_ty
          *              u8 cc_data_2
          */
         const int b_truncate = p_src[4] & 0x01;
-        const int i_field_first = (p_src[4] & 0x80) ? 0 : 1;
-        const int i_count_cc2 = ((p_src[4] >> 1) & 0x1f) + b_truncate;
+        const int i_count_cc2 = ((p_src[4] >> 1) & 0x1f);
         const uint8_t *cc = &p_src[5];
+        i_src -= 5;
         int i;
 
-        if( i_src < 4+1+6*i_count_cc2 - ( b_truncate ? 3 : 0) )
-            return;
-        for( i = 0; i < i_count_cc2; i++ )
+#define CC_ALIGNMENT_TEST   (0x7f)
+
+        for( i = 0; i < 2*i_count_cc2 + b_truncate && i_src >= 3; i++, cc+=3 )
         {
-            int j;
-            for( j = 0; j < 2; j++, cc += 3 )
+            if( (cc[0] >> 1) == CC_ALIGNMENT_TEST )
             {
-                const int i_field = j == i_field_first ? 0 : 1;
-
-                if( b_truncate && i == i_count_cc2 - 1 && j == 1 )
+                const bool even_field = (cc[0] & 0x01) ? 0 : 1;
+                if (!cc_AppendData( c, CC_PKT_BYTE0(even_field), &cc[1] ))
                     break;
-                if( (cc[0] & 0xfe) != 0xfe )
-                    continue;
-                if( c->i_data + 3 > CC_MAX_DATA_SIZE )
-                    continue;
-
-                cc_AppendData( c, CC_PKT_BYTE0(i_field), &cc[1] );
             }
+            i_src -= 3;
         }
         c->b_reorder = false;
     }
@@ -330,10 +323,9 @@ static inline void cc_Extract( cc_data_t *c, enum cc_payload_type_e i_payload_ty
         for( int i_cc_count = i_src >> 2; i_cc_count > 0;
              i_cc_count--, cc += 4 )
         {
-            if( c->i_data + 3 > CC_MAX_DATA_SIZE )
-                return;
             uint8_t i_field = (cc[0] & 0x02) >> 1;
-            cc_AppendData( c, CC_PKT_BYTE0(i_field), &cc[2] );
+            if (!cc_AppendData( c, CC_PKT_BYTE0(i_field), &cc[2] ))
+                return;
         }
         c->b_reorder = false;
     }
@@ -372,15 +364,14 @@ static inline void cc_Extract( cc_data_t *c, enum cc_payload_type_e i_payload_ty
 
             if( i_field_idx == 0 )
                 continue;
-            if( c->i_data + 2*3 > CC_MAX_DATA_SIZE )
-                continue;
 
             /* 1,2,3 -> 0,1,0. I.E. repeated field 3 is merged with field 1 */
             int i_field = ((i_field_idx - 1) & 1);
             if (!b_top_field_first)
                 i_field ^= 1;
 
-            cc_AppendData( c, CC_PKT_BYTE0(i_field), &cc[0] );
+            if (!cc_AppendData( c, CC_PKT_BYTE0(i_field), &cc[0] ))
+                continue;
         }
         c->b_reorder = true;
     }
@@ -438,9 +429,8 @@ static inline void cc_Extract( cc_data_t *c, enum cc_payload_type_e i_payload_ty
             cc += 1;
             for( int i = 0; i < i_count_cc; i++, cc += 3 )
             {
-                if( c->i_data + 3 > CC_MAX_DATA_SIZE )
+                if (!cc_AppendData( c, cc[0], &cc[1] ))
                     break;
-                cc_AppendData( c, cc[0], &cc[1] );
             }
         }
         /* remaining data */


=====================================
modules/demux/ty.c
=====================================
@@ -1029,9 +1029,6 @@ static int DemuxRecCc( demux_t *p_demux, ty_rec_hdr_t *rec_hdr, block_t *p_block
     if( i_field == 1 )
         DemuxDecodeXds( p_demux, rec_hdr->ex[0], rec_hdr->ex[1] );
 
-    if( p_sys->cc.i_data + 3 > CC_MAX_DATA_SIZE )
-        return 0;
-
     cc_AppendData( &p_sys->cc, CC_PKT_BYTE0(i_field), rec_hdr->ex );
     return 0;
 }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5503b393ec578aca23fb3cb237ade492ff5586d5...354bd431fe744b55178610a6d0521c462f0013ef

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5503b393ec578aca23fb3cb237ade492ff5586d5...354bd431fe744b55178610a6d0521c462f0013ef
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