From d21665d886638b08862e41bc68ea62472a646ca1 Mon Sep 17 00:00:00 2001 From: Jason Garrett-Glaser Date: Thu, 4 Sep 2008 00:43:54 -0700 Subject: [PATCH] Faster NAL unit encoding and remove unused nal_decode Small speedup at very high bitrates --- common/common.c | 48 +++--------------------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/common/common.c b/common/common.c index f628f8d2..77e3a8ce 100644 --- a/common/common.c +++ b/common/common.c @@ -642,8 +642,6 @@ int x264_nal_encode( void *p_data, int *pi_data, int b_annexeb, x264_nal_t *nal 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 */ if( b_annexeb ) @@ -658,21 +656,12 @@ 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( i_count == 2 && *src <= 0x03 ) - { + if( src[0] <= 0x03 && !src[-2] && !src[-1] ) *dst++ = 0x03; - i_count = 0; - } - if( *src == 0 ) - { - i_count++; - } - else - { - i_count = 0; - } *dst++ = *src++; } *pi_data = dst - (uint8_t*)p_data; @@ -680,37 +669,6 @@ int x264_nal_encode( void *p_data, int *pi_data, int b_annexeb, x264_nal_t *nal return *pi_data; } -/**************************************************************************** - * x264_nal_decode: - ****************************************************************************/ -int x264_nal_decode( x264_nal_t *nal, void *p_data, int i_data ) -{ - uint8_t *src = p_data; - uint8_t *end = &src[i_data]; - uint8_t *dst = nal->p_payload; - - nal->i_type = src[0]&0x1f; - nal->i_ref_idc = (src[0] >> 5)&0x03; - - src++; - - while( src < end ) - { - if( src < end - 3 && src[0] == 0x00 && src[1] == 0x00 && src[2] == 0x03 ) - { - *dst++ = 0x00; - *dst++ = 0x00; - - src += 3; - continue; - } - *dst++ = *src++; - } - - nal->i_payload = dst - (uint8_t*)p_data; - return 0; -} - /**************************************************************************** -- 2.47.3