]> git.sesse.net Git - vlc/commitdiff
closed captions: Correctly determine the field for SCTE-20 streams
authorPádraig Brady <P@draigBrady.com>
Fri, 29 Jan 2010 16:18:11 +0000 (16:18 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Sat, 30 Jan 2010 13:03:14 +0000 (14:03 +0100)
* modules/codec/cc.h (cc_Extract): Merge repeated field (3) with first
field (1).  Use the TOP_FIRST_FIELD in the determination of field.
* modules/codec/libmpeg2.c (DecodeBlock): Pass whether "top field first"
* modules/packetizer/mpegvideo.c (ParseMPEGBlock): Likewise.

Signed-off-by: Laurent Aimar <fenrir@videolan.org>
modules/codec/cc.h
modules/codec/libmpeg2.c
modules/packetizer/h264.c
modules/packetizer/mpegvideo.c

index cb3740fd2a7f9958251fbef391dc22447005ef9f..f582c36eb2c179c841298086ecdaed04e5bc05b7 100644 (file)
@@ -77,7 +77,7 @@ static inline void cc_AppendData( cc_data_t *c, int i_field, const uint8_t cc[2]
     c->p_data[c->i_data++] = cc[1];
 }
 
-static inline void cc_Extract( cc_data_t *c, const uint8_t *p_src, int i_src )
+static inline void cc_Extract( cc_data_t *c, bool b_top_field_first, const uint8_t *p_src, int i_src )
 {
     static const uint8_t p_cc_ga94[4] = { 0x47, 0x41, 0x39, 0x34 };
     static const uint8_t p_cc_dvd[4] = { 0x43, 0x43, 0x01, 0xf8 };
@@ -212,12 +212,15 @@ static inline void cc_Extract( cc_data_t *c, const uint8_t *p_src, int i_src )
             }
             bs_skip( &s, 1 );
 
-            if( i_field_idx != 1 && i_field_idx != 2 )
+            if( i_field_idx == 0 )
                 continue;
             if( c->i_data + 2*3 > CC_MAX_DATA_SIZE )
                 continue;
 
-            const int i_field = i_field_idx - 1;
+            /* 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, i_field, &cc[0] );
         }
index b7d2d1507ff2d4d07dfc9a4a85b4bacf9de3adfb..1189ee9dbcfd121e97cfdd30772abb77ad9e9faa 100644 (file)
@@ -453,17 +453,21 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                              & PIC_MASK_CODING_TYPE) == PIC_FLAG_CODING_TYPE_B )
                     p_sys->i_cc_flags = BLOCK_FLAG_TYPE_B;
                 else p_sys->i_cc_flags = BLOCK_FLAG_TYPE_I;
+                bool b_top_field_first = p_sys->p_info->current_picture->flags
+                                           & PIC_FLAG_TOP_FIELD_FIRST;
 
                 if( p_sys->i_gop_user_data > 2 )
                 {
                     /* We now have picture info for any cached user_data out of the gop */
-                    cc_Extract( &p_sys->cc, &p_sys->p_gop_user_data[0], p_sys->i_gop_user_data );
+                    cc_Extract( &p_sys->cc, b_top_field_first,
+                                &p_sys->p_gop_user_data[0], p_sys->i_gop_user_data );
                     p_sys->i_gop_user_data = 0;
                 }
 
                 /* Extract the CC from the user_data of the picture */
                 if( p_info->user_data_len > 2 )
-                    cc_Extract( &p_sys->cc, &p_info->user_data[0], p_info->user_data_len );
+                    cc_Extract( &p_sys->cc, b_top_field_first,
+                                &p_info->user_data[0], p_info->user_data_len );
             }
         }
         break;
index d3f9d33a4359b14397c87cd5b12c9801a011d5ac..d667f4ba49eeb23cf41daced73d0a0f48cf8e1a1 100644 (file)
@@ -1129,7 +1129,7 @@ static void ParseSei( decoder_t *p_dec, block_t *p_frag )
             if( i_t35 >= 5 &&
                 !memcmp( p_t35, p_dvb1_data_start_code, sizeof(p_dvb1_data_start_code) ) )
             {
-                cc_Extract( &p_sys->cc_next, &p_t35[3], i_t35 - 3 );
+                cc_Extract( &p_sys->cc_next, true, &p_t35[3], i_t35 - 3 );
             }
         }
         i_used += i_size;
index a09016f26b6ae4492d1877c21be6a43ff4dfa7ed..52f548084787d455e1758958cd2eda5d28347a1d 100644 (file)
@@ -630,7 +630,8 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
     }
     else if( p_frag->p_buffer[3] == 0xb2 && p_frag->i_buffer > 4 )
     {
-        cc_Extract( &p_sys->cc, &p_frag->p_buffer[4], p_frag->i_buffer - 4 );
+        cc_Extract( &p_sys->cc, p_sys->i_top_field_first,
+                    &p_frag->p_buffer[4], p_frag->i_buffer - 4 );
     }
     else if( p_frag->p_buffer[3] == 0x00 )
     {