Commit e15e038c authored by François Cartegnie's avatar François Cartegnie 🤞

packetizer: h2xx: remove alloc/memcpy

Packetized input always contains 1 single NAL.
block_Alloc reserves 32 bytes for header, which
can be used for AnnexB.

In that case it removes almost all allocs+memcpy
towards AnnexB conversion, except N-1 extradata NAL

In all cases avoid memcpy/alloc for trailing NAL.
parent d2d14e81
...@@ -22,25 +22,6 @@ ...@@ -22,25 +22,6 @@
#include <vlc_block.h> #include <vlc_block.h>
#include <vlc_codec.h> #include <vlc_codec.h>
block_t *CreateAnnexbNAL( const uint8_t *p, size_t i_size )
{
block_t *p_nal;
p_nal = block_Alloc( 4 + i_size );
if( !p_nal ) return NULL;
/* Add start code */
p_nal->p_buffer[0] = 0x00;
p_nal->p_buffer[1] = 0x00;
p_nal->p_buffer[2] = 0x00;
p_nal->p_buffer[3] = 0x01;
/* Copy nalu */
memcpy( &p_nal->p_buffer[4], p, i_size );
return p_nal;
}
/**************************************************************************** /****************************************************************************
* PacketizeXXC1: Takes VCL blocks of data and creates annexe B type NAL stream * PacketizeXXC1: Takes VCL blocks of data and creates annexe B type NAL stream
* Will always use 4 byte 0 0 0 1 startcodes * Will always use 4 byte 0 0 0 1 startcodes
...@@ -66,7 +47,6 @@ block_t *PacketizeXXC1( decoder_t *p_dec, uint8_t i_nal_length_size, ...@@ -66,7 +47,6 @@ block_t *PacketizeXXC1( decoder_t *p_dec, uint8_t i_nal_length_size,
for( p = p_block->p_buffer; p < &p_block->p_buffer[p_block->i_buffer]; ) for( p = p_block->p_buffer; p < &p_block->p_buffer[p_block->i_buffer]; )
{ {
block_t *p_pic;
bool b_dummy; bool b_dummy;
int i_size = 0; int i_size = 0;
int i; int i;
...@@ -83,21 +63,52 @@ block_t *PacketizeXXC1( decoder_t *p_dec, uint8_t i_nal_length_size, ...@@ -83,21 +63,52 @@ block_t *PacketizeXXC1( decoder_t *p_dec, uint8_t i_nal_length_size,
break; break;
} }
block_t *p_part = CreateAnnexbNAL( p, i_size ); /* Convert AVC to AnnexB */
if( !p_part ) block_t *p_nal;
/* If data exactly match remaining bytes (1 NAL only or trailing one) */
if( i_size == p_block->p_buffer + p_block->i_buffer - p )
{
p_block->i_buffer = i_size;
p_block->p_buffer = p;
p_nal = block_Realloc( p_block, 4, i_size );
if( p_nal )
p_block = NULL;
}
else
{
p_nal = block_Alloc( 4 + i_size );
if( p_nal )
{
p_nal->i_dts = p_block->i_dts;
p_nal->i_pts = p_block->i_pts;
/* Copy nalu */
memcpy( &p_nal->p_buffer[4], p, i_size );
}
p += i_size;
}
if( !p_nal )
break; break;
p_part->i_dts = p_block->i_dts; /* Add start code */
p_part->i_pts = p_block->i_pts; p_nal->p_buffer[0] = 0x00;
p_nal->p_buffer[1] = 0x00;
p_nal->p_buffer[2] = 0x00;
p_nal->p_buffer[3] = 0x01;
/* Parse the NAL */ /* Parse the NAL */
if( ( p_pic = pf_nal_parser( p_dec, &b_dummy, p_part ) ) ) block_t *p_pic;
if( ( p_pic = pf_nal_parser( p_dec, &b_dummy, p_nal ) ) )
{ {
block_ChainAppend( &p_ret, p_pic ); block_ChainAppend( &p_ret, p_pic );
} }
p += i_size;
if( !p_block )
break;
} }
block_Release( p_block );
if( p_block )
block_Release( p_block );
return p_ret; return p_ret;
} }
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
#include <vlc_common.h> #include <vlc_common.h>
block_t *CreateAnnexbNAL( const uint8_t *p, size_t );
typedef block_t * (*pf_annexb_nal_packetizer)(decoder_t *, bool *, block_t *); typedef block_t * (*pf_annexb_nal_packetizer)(decoder_t *, bool *, block_t *);
block_t *PacketizeXXC1( decoder_t *, uint8_t, block_t **, pf_annexb_nal_packetizer ); block_t *PacketizeXXC1( decoder_t *, uint8_t, block_t **, pf_annexb_nal_packetizer );
......
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