In some rare (but significant) cases, the optimized nal_encode algorithm gave incorrect results.
uint8_t *dst = p_data;
uint8_t *src = nal->p_payload;
uint8_t *end = &nal->p_payload[nal->i_payload];
+ int i_count = 0;
/* FIXME this code doesn't check overflow */
/* nal header */
*dst++ = ( 0x00 << 7 ) | ( nal->i_ref_idc << 5 ) | nal->i_type;
- if( src < end ) *dst++ = *src++;
- if( src < end ) *dst++ = *src++;
while( src < end )
{
- if( src[0] <= 0x03 && !src[-2] && !src[-1] )
+ if( i_count == 2 && *src <= 0x03 )
+ {
*dst++ = 0x03;
+ i_count = 0;
+ }
+ if( *src == 0 )
+ i_count++;
+ else
+ i_count = 0;
*dst++ = *src++;
}
*pi_data = dst - (uint8_t*)p_data;