Commit 5993fcca authored by Fiona Glaser's avatar Fiona Glaser

Faster NAL unit encoding and remove unused nal_decode

Small speedup at very high bitrates
parent 5d0904bf
......@@ -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;
}
/****************************************************************************
......
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