Commit 5bd2bacf authored by Pádraig Brady's avatar Pádraig Brady Committed by Laurent Aimar

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: default avatarLaurent Aimar <fenrir@videolan.org>
parent ff9fe43d
......@@ -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] );
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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 )
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment