[vlc-commits] x264: place SEI in start of first block, also copy all nals at once

Ilkka Ollakka git at videolan.org
Sat Sep 3 17:51:30 CEST 2011


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sat Sep  3 18:47:41 2011 +0300| [c4fa64d3d8b0d29c9a77a947780d2cd48df5f0e2] | committer: Ilkka Ollakka

x264: place SEI in start of first block, also copy all nals at once

libavcodec seems to do the same and didn't actually found a reaso earlier
patch did what it did. Copying nals helps if you do slices, so it doesn't
do one nal at a time.

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

 modules/codec/x264.c |   26 +++++++++++---------------
 1 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/modules/codec/x264.c b/modules/codec/x264.c
index ae3247e..967f2ef 100644
--- a/modules/codec/x264.c
+++ b/modules/codec/x264.c
@@ -1366,28 +1366,24 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
 
 
     /* Get size of block we need */
-    i_out = p_sys->i_sei_size;
     for( i = 0; i < i_nal; i++ )
         i_out += nal[i].i_payload;
 
-    p_block = block_New( p_enc, i_out );
+    p_block = block_New( p_enc, i_out + p_sys->i_sei_size );
     if( !p_block ) return NULL;
 
-    /* copy encoded data directly to block */
-    for( i = 0, i_out = 0; i < i_nal; i++ )
+    unsigned int i_offset = 0;
+    if( unlikely( p_sys->i_sei_size && ( i_nal > 1 ) ) )
     {
-        if( p_sys->i_sei_size && nal[i].i_type == NAL_SLICE )
-        {
-            /* insert x264 headers SEI nal before first SLICE nal */
-            memcpy( p_block->p_buffer, p_sys->p_sei, p_sys->i_sei_size );
-            i_out += p_sys->i_sei_size;
-            p_sys->i_sei_size = 0;
-            free( p_sys->p_sei );
-            p_sys->p_sei = NULL;
-        }
-        memcpy( p_block->p_buffer + i_out, nal[i].p_payload, nal[i].i_payload );
-        i_out += nal[i].i_payload;
+       /* insert x264 headers SEI nal into the first picture block at the start */
+       memcpy( p_block->p_buffer, p_sys->p_sei, p_sys->i_sei_size );
+       i_offset = p_sys->i_sei_size;
+       p_sys->i_sei_size = 0;
+       free( p_sys->p_sei );
+       p_sys->p_sei = NULL;
     }
+    /* copy encoded data directly to block */
+    memcpy( p_block->p_buffer + i_offset, nal[0].p_payload, i_out );
 
     if( pic.b_keyframe )
         p_block->i_flags |= BLOCK_FLAG_TYPE_I;



More information about the vlc-commits mailing list