commit 5bd2bacf60872c96d68ee497f8e8eadd057ae421 Author: Pádraig Brady Date: Fri Jan 29 16:18:11 2010 +0000 closed captions: Correctly determine the field for SCTE-20 streams * 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 diff --git a/modules/codec/cc.h b/modules/codec/cc.h index cb3740f..f582c36 100644 --- a/modules/codec/cc.h +++ b/modules/codec/cc.h @@ -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] ); } diff --git a/modules/codec/libmpeg2.c b/modules/codec/libmpeg2.c index b7d2d15..1189ee9 100644 --- a/modules/codec/libmpeg2.c +++ b/modules/codec/libmpeg2.c @@ -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; diff --git a/modules/packetizer/h264.c b/modules/packetizer/h264.c index d3f9d33..d667f4b 100644 --- a/modules/packetizer/h264.c +++ b/modules/packetizer/h264.c @@ -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; diff --git a/modules/packetizer/mpegvideo.c b/modules/packetizer/mpegvideo.c index a09016f..52f5480 100644 --- a/modules/packetizer/mpegvideo.c +++ b/modules/packetizer/mpegvideo.c @@ -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 ) {