[vlc-commits] packetizer: h2xx: remove alloc/memcpy
Francois Cartegnie
git at videolan.org
Sat Dec 19 15:48:36 CET 2015
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Dec 19 13:01:37 2015 +0100| [e15e038c62b91e5a3c8eb2ccf6a358e1d7a51c8a] | committer: Francois 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e15e038c62b91e5a3c8eb2ccf6a358e1d7a51c8a
---
modules/packetizer/hxxx_common.c | 65 ++++++++++++++++++++++----------------
modules/packetizer/hxxx_common.h | 2 --
2 files changed, 38 insertions(+), 29 deletions(-)
diff --git a/modules/packetizer/hxxx_common.c b/modules/packetizer/hxxx_common.c
index 16ad7be..1a7a414 100644
--- a/modules/packetizer/hxxx_common.c
+++ b/modules/packetizer/hxxx_common.c
@@ -22,25 +22,6 @@
#include <vlc_block.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
* 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,
for( p = p_block->p_buffer; p < &p_block->p_buffer[p_block->i_buffer]; )
{
- block_t *p_pic;
bool b_dummy;
int i_size = 0;
int i;
@@ -83,21 +63,52 @@ block_t *PacketizeXXC1( decoder_t *p_dec, uint8_t i_nal_length_size,
break;
}
- block_t *p_part = CreateAnnexbNAL( p, i_size );
- if( !p_part )
+ /* Convert AVC to AnnexB */
+ 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;
- p_part->i_dts = p_block->i_dts;
- p_part->i_pts = p_block->i_pts;
+ /* 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;
/* 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 );
}
- p += i_size;
+
+ if( !p_block )
+ break;
}
- block_Release( p_block );
+
+ if( p_block )
+ block_Release( p_block );
return p_ret;
}
diff --git a/modules/packetizer/hxxx_common.h b/modules/packetizer/hxxx_common.h
index cb831a6..c4b7ba9 100644
--- a/modules/packetizer/hxxx_common.h
+++ b/modules/packetizer/hxxx_common.h
@@ -26,8 +26,6 @@
#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 *);
block_t *PacketizeXXC1( decoder_t *, uint8_t, block_t **, pf_annexb_nal_packetizer );
More information about the vlc-commits
mailing list