[vlc-commits] packetizer: avparser: remove useless realloc/copy

Francois Cartegnie git at videolan.org
Wed Apr 7 08:11:00 UTC 2021


vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Apr  6 18:27:17 2021 +0200| [b864b80b9b208c8e1703d6b9a4c92e463eb6239e] | committer: Francois Cartegnie

packetizer: avparser: remove useless realloc/copy

(cherry picked from commit 73b0d14c170a1ce6407a235eecd890e3a21bf68d)

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=b864b80b9b208c8e1703d6b9a4c92e463eb6239e
---

 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 44131f9382..272f494b21 100644
--- a/modules/packetizer/avparser.c
+++ b/modules/packetizer/avparser.c
@@ -182,20 +182,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_TS_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_TS_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