From 654e549862a0bf56671de13d38ad5c512d2a9efe Mon Sep 17 00:00:00 2001 From: Fiona Glaser Date: Fri, 5 Sep 2008 23:14:23 -0700 Subject: [PATCH] Revert part of r963 In some rare (but significant) cases, the optimized nal_encode algorithm gave incorrect results. --- common/common.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/common/common.c b/common/common.c index 77e3a8ce..96b6f2bd 100644 --- a/common/common.c +++ b/common/common.c @@ -641,6 +641,7 @@ int x264_nal_encode( void *p_data, int *pi_data, int b_annexeb, x264_nal_t *nal 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 */ @@ -656,12 +657,17 @@ int x264_nal_encode( void *p_data, int *pi_data, int b_annexeb, x264_nal_t *nal /* 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; -- 2.40.0