[vlc-commits] commit: mp4: find nal limits on 0*001 startcode instead 0001 ( Ilkka Ollakka )

git at videolan.org git at videolan.org
Sun Jun 13 22:36:17 CEST 2010


vlc | branch: master | Ilkka Ollakka <ileoo at videolan.org> | Sun Jun 13 15:01:11 2010 +0300| [aa51f404602d10086947b870d0cc9541e0e67a42] | committer: Ilkka Ollakka 

mp4: find nal limits on 0*001 startcode instead 0001

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

 modules/mux/mp4.c |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/modules/mux/mp4.c b/modules/mux/mp4.c
index 27e4e81..f459b52 100644
--- a/modules/mux/mp4.c
+++ b/modules/mux/mp4.c
@@ -873,37 +873,44 @@ static bo_t *GetAvcCTag( mp4_stream_t *p_stream )
         uint8_t *p_buffer = p_stream->fmt.p_extra;
         int     i_buffer = p_stream->fmt.i_extra;
 
-        while( i_buffer > 4 &&
-            p_buffer[0] == 0 && p_buffer[1] == 0 &&
-            p_buffer[2] == 0 && p_buffer[3] == 1 )
+        while( i_buffer > 3 )
         {
-            const int i_nal_type = p_buffer[4]&0x1f;
+            /* seek startcode */
+            while( p_buffer[0] != 0 || p_buffer[1] != 0 ||
+                   p_buffer[2] != 1 )
+            {
+                 i_buffer--;
+                 p_buffer++;
+            }
+            const int i_nal_type = p_buffer[3]&0x1f;
             int i_offset    = 1;
             int i_size      = 0;
             int i_startcode = 0;
  
-            //msg_Dbg( p_stream, "we found a startcode for NAL with TYPE:%d", i_nal_type );
  
-            for( i_offset = 1; i_offset+3 < i_buffer ; i_offset++)
+            for( i_offset = 1; i_offset+2 < i_buffer ; i_offset++)
             {
                 if( p_buffer[i_offset] == 0 && p_buffer[i_offset+1] == 0 &&
-                    p_buffer[i_offset+2] == 0 && p_buffer[i_offset+3] == 1 )
+                    p_buffer[i_offset+2] == 1 )
                 {
                     /* we found another startcode */
                     i_startcode = i_offset;
+                    while( p_buffer[i_startcode-1] == 0 && i_startcode > 0 )
+                        i_startcode--;
                     break;
                 }
             }
             i_size = i_startcode ? i_startcode : i_buffer;
+
             if( i_nal_type == 7 )
             {
-                p_sps = &p_buffer[4];
-                i_sps_size = i_size - 4;
+                p_sps = &p_buffer[3];
+                i_sps_size = i_size - 3;
             }
             if( i_nal_type == 8 )
             {
-                p_pps = &p_buffer[4];
-                i_pps_size = i_size - 4;
+                p_pps = &p_buffer[3];
+                i_pps_size = i_size - 3;
             }
             i_buffer -= i_size;
             p_buffer += i_size;



More information about the vlc-commits mailing list