Fixed syntax for VC1 coming from some ASF (packetizer).
authorLaurent Aimar <fenrir@videolan.org>
Tue, 28 Apr 2009 21:04:35 +0000 (23:04 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Thu, 30 Apr 2009 19:01:34 +0000 (21:01 +0200)
The sequence header/entry point are not repeated yet.

modules/packetizer/vc1.c

index 3bd126e..d5f6c63 100644 (file)
@@ -89,6 +89,7 @@ struct decoder_sys_t
 
 
     mtime_t i_interpolated_dts;
+    bool    b_check_startcode;
 };
 
 typedef enum
@@ -151,6 +152,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->pp_last = &p_sys->p_frame;
 
     p_sys->i_interpolated_dts = -1;
+    p_sys->b_check_startcode = p_dec->fmt_in.b_packetized;
 
     if( p_dec->fmt_out.i_extra > 0 )
     {
@@ -193,7 +195,37 @@ static block_t *Packetize( decoder_t *p_dec, block_t **pp_block )
 {
     decoder_sys_t *p_sys = p_dec->p_sys;
 
-    return packetizer_Packetize( &p_sys->packetizer, pp_block );
+    if( p_sys->b_check_startcode && pp_block && *pp_block )
+    {
+        /* Fix syntax for (some?) VC1 from asf */
+        const int i_startcode = sizeof(p_vc1_startcode);
+
+        block_t *p_block = *pp_block;
+        if( p_block->i_buffer > 0 &&
+            ( p_block->i_buffer < i_startcode ||
+              memcmp( p_block->p_buffer, p_vc1_startcode, i_startcode ) ) )
+        {
+            *pp_block = p_block = block_Realloc( p_block, i_startcode+1, p_block->i_buffer );
+            if( p_block )
+            {
+                memcpy( p_block->p_buffer, p_vc1_startcode, i_startcode );
+
+                if( p_sys->b_sequence_header && p_sys->sh.b_interlaced &&
+                    p_block->i_buffer > i_startcode+1 &&
+                    (p_block->p_buffer[i_startcode+1] & 0xc0) == 0xc0 )
+                    p_block->p_buffer[i_startcode] = IDU_TYPE_FIELD;
+                else
+                    p_block->p_buffer[i_startcode] = IDU_TYPE_FRAME;
+            }
+        }
+        p_sys->b_check_startcode = false;
+    }
+
+    block_t *p_au = packetizer_Packetize( &p_sys->packetizer, pp_block );
+    if( !p_au )
+        p_sys->b_check_startcode = p_dec->fmt_in.b_packetized;
+
+    return p_au;
 }
 
 static void PacketizeReset( void *p_private, bool b_broken )