[vlc-commits] packetizer: avparser: remove useless realloc/copy
Francois Cartegnie
git at videolan.org
Tue Apr 6 18:18:44 UTC 2021
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Apr 6 18:27:17 2021 +0200| [73b0d14c170a1ce6407a235eecd890e3a21bf68d] | committer: Francois Cartegnie
packetizer: avparser: remove useless realloc/copy
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=73b0d14c170a1ce6407a235eecd890e3a21bf68d
---
modules/packetizer/avparser.c | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/modules/packetizer/avparser.c b/modules/packetizer/avparser.c
index f8a0b3d1bb..849120722f 100644
--- a/modules/packetizer/avparser.c
+++ b/modules/packetizer/avparser.c
@@ -183,20 +183,35 @@ static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
if( unlikely( i_outlen <= 0 || !p_outdata ) )
goto out;
- block_t * p_ret = block_Alloc( i_outlen );
-
- if( unlikely ( !p_ret ) )
- goto out;
+ block_t * p_ret;
+ if( (size_t)i_outlen < p_block->i_buffer )
+ {
+ p_ret = block_Alloc( i_outlen );
+ if( unlikely ( !p_ret ) )
+ goto out;
+ }
+ else /* just pass block as-is */
+ {
+ p_ret = p_block;
+ }
- p_ret->i_flags = p_block->i_flags;
+ if( p_ret != p_block )
+ {
+ p_ret->i_flags = p_block->i_flags;
- if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
- p_block->i_flags &= ~BLOCK_FLAG_DISCONTINUITY;
+ if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
+ p_block->i_flags &= ~BLOCK_FLAG_DISCONTINUITY;
- memcpy( p_ret->p_buffer, p_outdata, i_outlen );
- p_ret->i_pts = p_block->i_pts;
- p_ret->i_dts = p_block->i_dts;
- p_block->i_pts = p_block->i_dts = VLC_TICK_INVALID;
+ memcpy( p_ret->p_buffer, p_outdata, i_outlen );
+ p_ret->i_pts = p_block->i_pts;
+ p_ret->i_dts = p_block->i_dts;
+ p_block->i_pts = p_block->i_dts = VLC_TICK_INVALID;
+ }
+ else /* as-is block is now used */
+ {
+ p_sys->i_offset = 0;
+ *pp_block = NULL;
+ }
if( p_dec->fmt_in.i_cat == VIDEO_ES )
{
More information about the vlc-commits
mailing list