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 };
}
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] );
}
& 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;
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;
}
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 )
{