]> git.sesse.net Git - vlc/commitdiff
omxil: Move code for in-buffer conversion of H264 to annex b to h264_nal.h
authorMartin Storsjö <martin@martin.st>
Sun, 7 Oct 2012 22:27:43 +0000 (01:27 +0300)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 8 Oct 2012 09:38:00 +0000 (11:38 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/codec/h264_nal.h
modules/codec/omxil/omxil.c

index 1f90b05029d1c63f2c14d7ba3bced3fae8c1598f..f116f0ba8e7e8f8780cd7637ccc59293dd789944 100644 (file)
@@ -96,3 +96,25 @@ static int convert_sps_pps( decoder_t *p_dec, const uint8_t *p_buf,
     return VLC_SUCCESS;
 }
 
+/* Convert H.264 NAL format to annex b in-place */
+static void convert_h264_to_annexb( uint8_t *p_buf, uint32_t i_len,
+                                    int i_nal_size )
+{
+    if( i_nal_size < 3 || i_nal_size > 4 )
+        return;
+
+    /* This only works for NAL sizes 3-4 */
+    while( i_len >= i_nal_size )
+    {
+        uint32_t nal_len = 0;
+        for( int i = 0; i < i_nal_size; i++ ) {
+            nal_len = (nal_len << 8) | p_buf[i];
+            p_buf[i] = 0;
+        }
+        p_buf[i_nal_size - 1] = 1;
+        if( nal_len > INT_MAX || nal_len > (unsigned int) i_len )
+            break;
+        p_buf += nal_len + i_nal_size;
+        i_len -= nal_len + i_nal_size;
+    }
+}
index e33ab3646c993186bc15f81ead1aa0f6f4e9228e..0733648ba652754dea93a4b4fa79c90430cf0a08 100644 (file)
@@ -1363,26 +1363,11 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
             block_Release(p_block);
         }
 
-        /* Convert H.264 NAL format to annex b */
-        if( p_sys->i_nal_size_length >= 3 && p_sys->i_nal_size_length <= 4 )
-        {
-            /* This only works for NAL sizes 3-4 */
-            int i_len = p_header->nFilledLen, i;
-            uint8_t* ptr = p_header->pBuffer;
-            while( i_len >= p_sys->i_nal_size_length )
-            {
-                uint32_t nal_len = 0;
-                for( i = 0; i < p_sys->i_nal_size_length; i++ ) {
-                    nal_len = (nal_len << 8) | ptr[i];
-                    ptr[i] = 0;
-                }
-                ptr[p_sys->i_nal_size_length - 1] = 1;
-                if( nal_len > INT_MAX || nal_len > (unsigned int) i_len )
-                    break;
-                ptr   += nal_len + p_sys->i_nal_size_length;
-                i_len -= nal_len + p_sys->i_nal_size_length;
-            }
-        }
+        /* Convert H.264 NAL format to annex b. Doesn't do anything if
+         * i_nal_size_length == 0, which is the case for codecs other
+         * than H.264 */
+        convert_h264_to_annexb( p_header->pBuffer, p_header->nFilledLen,
+                                p_sys->i_nal_size_length );
 #ifdef OMXIL_EXTRA_DEBUG
         msg_Dbg( p_dec, "EmptyThisBuffer %p, %p, %i", p_header, p_header->pBuffer,
                  (int)p_header->nFilledLen );