]> git.sesse.net Git - vlc/blobdiff - plugins/avi/avi.c
* avi.c : quick hack to read file created by ffmpeg. I think it should
[vlc] / plugins / avi / avi.c
index adc9e8ab1ce6ec4ab6c130e160bfea65a3d782da..fca2b87169f1aacee217aaebd4508e3be2b5f7ba 100644 (file)
@@ -2,7 +2,7 @@
  * avi.c : AVI file Stream input module for vlc
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: avi.c,v 1.29 2002/07/02 17:54:49 fenrir Exp $
+ * $Id: avi.c,v 1.31 2002/07/15 19:33:02 fenrir Exp $
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  * 
  * This program is free software; you can redistribute it and/or modify
@@ -195,56 +195,7 @@ static int AVI_AudioGetType( u32 i_type )
             return( 0 );
     }
 }
-static int AVI_VideoGetType( u32 i_type )
-{
-    switch( i_type )
-    {
-        case( FOURCC_DIV1 ): /* FIXME it is for msmpeg4v1 or old mpeg4 ?? */
-        case( FOURCC_div1 ):
-        case( FOURCC_MPG4 ):
-        case( FOURCC_mpg4 ):
-            return( MSMPEG4v1_VIDEO_ES );
-
-        case( FOURCC_DIV2 ):
-        case( FOURCC_div2 ):
-        case( FOURCC_MP42 ):
-        case( FOURCC_mp42 ):
-            return( MSMPEG4v2_VIDEO_ES );
-         
-        case( FOURCC_MPG3 ):
-        case( FOURCC_mpg3 ):
-        case( FOURCC_div3 ):
-        case( FOURCC_MP43 ):
-        case( FOURCC_mp43 ):
-        case( FOURCC_DIV3 ):
-        case( FOURCC_DIV4 ):
-        case( FOURCC_div4 ):
-        case( FOURCC_DIV5 ):
-        case( FOURCC_div5 ):
-        case( FOURCC_DIV6 ):
-        case( FOURCC_div6 ):
-        case( FOURCC_AP41 ):
-        case( FOURCC_3IV1 ):
-            return( MSMPEG4v3_VIDEO_ES );
-
-        case( FOURCC_DIVX ):
-        case( FOURCC_divx ):
-        case( FOURCC_MP4S ):
-        case( FOURCC_mp4s ):
-        case( FOURCC_M4S2 ):
-        case( FOURCC_m4s2 ):
-        case( FOURCC_xvid ):
-        case( FOURCC_XVID ):
-        case( FOURCC_XviD ):
-        case( FOURCC_DX50 ):
-        case( FOURCC_mp4v ):
-        case( FOURCC_4    ):
-            return( MPEG4_VIDEO_ES );
 
-        default:
-            return( 0 );
-    }
-}
 /* Test if it seems that it's a key frame */
 static int AVI_GetKeyFlag( int i_type, u8 *p_byte )
 {
@@ -606,8 +557,8 @@ static int AVIInit( input_thread_t *p_input )
     riffchunk_t *p_strl,*p_strh,*p_strf;
     demux_data_avi_file_t *p_avi_demux;
     es_descriptor_t *p_es = NULL; /* for not warning */
-
-    int i;
+    char *name;
+    int i, i_codec;
 
     if( !( p_input->p_demux_data = 
                     p_avi_demux = malloc( sizeof(demux_data_avi_file_t) ) ) )
@@ -781,15 +732,21 @@ static int AVIInit( input_thread_t *p_input )
                 p_es->i_cat = VIDEO_ES;
                 AVI_Parse_BitMapInfoHeader( &p_info->video_format,
                                    p_strf->p_data->p_payload_start ); 
+
+                /* XXX quick hack for playing ffmpeg video, I don't know 
+                    who is doing something wrong */
+                p_info->header.i_samplesize = 0;
                 p_es->b_audio = 0;
-                p_es->i_type = 
-                    AVI_VideoGetType( p_info->video_format.i_compression );
-                if( !p_es->i_type )
+                if( !AVI_GetVideoCodec( p_info->video_format.i_compression,
+                                   &i_codec,
+                                   &name ) )
                 {
                     msg_Warn( p_input, "stream(%d,%4.4s) not supported", i,
                               (char*)&p_info->video_format.i_compression);
                     p_es->i_cat = UNKNOWN_ES;
                 }
+
+                p_es->i_type = i_codec;
                 break;
             default:
                 msg_Err( p_input, "unknown stream(%d) type", i );
@@ -827,8 +784,7 @@ static int AVIInit( input_thread_t *p_input )
     p_avi_demux->p_movi = p_movi;
     
     /* get index  XXX need to have p_movi */
-    if( ( p_avi_demux->b_seekable )
-        &&( p_avi_demux->avih.i_flags&AVIF_HASINDEX ) ) 
+    if( p_avi_demux->b_seekable )
     {
         /* get index */
         __AVI_GetIndex( p_input ); 
@@ -864,6 +820,7 @@ static int AVIInit( input_thread_t *p_input )
         switch( p_info->p_es->i_cat )
         {
             case( VIDEO_ES ):
+
                 msg_Dbg( p_input, "video(%4.4s) %dx%d %dbpp %ffps",
                          (char*)&p_info->video_format.i_compression,
                          p_info->video_format.i_width,
@@ -1034,8 +991,8 @@ static int __AVI_GetDataInPES( input_thread_t *p_input,
 
     do
     {
-        i_read = input_SplitBuffer(p_input, &p_data, i_size - 
-                                                    (*pp_pes)->i_pes_size );
+        i_read = input_SplitBuffer(p_input, &p_data, __MIN( i_size - 
+                                                              (*pp_pes)->i_pes_size, 1024 ) );
         if( i_read < 0 )
         {
             return( (*pp_pes)->i_pes_size );
@@ -1966,6 +1923,54 @@ static int __AVIDemux_ChunkAction( int i_streams_max,
     return( 4 );
 }
 
+static int AVI_NotSeekableRecover( input_thread_t *p_input )
+{
+    byte_t *p_id;
+    u32 i_id;
+    int i_number, i_type;
+    data_packet_t *p_pack;
+
+    for( ; ; )
+    {
+        if( input_Peek( p_input, &p_id, 4 ) < 4 )
+        {
+            return( 0 ); /* Failed */
+        }
+        i_id = GetDWLE( p_id );
+        switch( i_id )
+        {
+            case( FOURCC_idx1 ):
+            case( FOURCC_JUNK ):
+            case( FOURCC_LIST ):
+                return( 1 );
+            default:
+                AVI_ParseStreamHeader( i_id, &i_number, &i_type );
+                if( i_number <= 99 )
+                {
+                    switch( i_type )
+                    {
+                        case( TWOCC_wb ):
+                        case( TWOCC_db ):
+                        case( TWOCC_dc ):
+                        case( TWOCC_pc ):
+                            return( 1 );
+                    }
+                }
+                else
+                {
+
+                }
+        }
+        /* Read 1 byte VERY unoptimised */
+        if( input_SplitBuffer( p_input, &p_pack, 1) < 1 )
+        {
+            return( 0 );
+        }
+        input_DeletePacket( p_input->p_method_data, p_pack);
+    }
+
+}
+
 static int AVIDemux_NotSeekable( input_thread_t *p_input,
                                  AVIStreamInfo_t *p_info_master,
                                  AVIStreamInfo_t *p_info_slave )
@@ -2046,9 +2051,18 @@ static int AVIDemux_NotSeekable( input_thread_t *p_input,
                     return( 0 );
                 case( 4 ): /* Error */
                     RIFF_DeleteChunk( p_input, p_ck );
-                    msg_Err( p_input, "unknown chunk id %4.4s trying to recover", &p_ck->i_id );
-                    msg_Err( p_input, "cannot recover, dying" );
-                    return( -1 );
+                    msg_Warn( p_input, "unknown chunk id 0x%8.8x, trying to recover", p_ck->i_id );
+                    if( !AVI_NotSeekableRecover( p_input ) )
+                    {
+                        msg_Err( p_input, "cannot recover, dying" );
+                        return( -1 );
+                    }
+                    else
+                    {
+                        msg_Warn( p_input, "recovered sucessfully" );
+                    }
+                    b_load = 0;
+                    break;
             }
 
         } while( !b_load );
@@ -2201,6 +2215,7 @@ static int AVIDemux( input_thread_t *p_input )
         p_avi_demux->i_rate = p_input->stream.control.i_rate;
     }
     vlc_mutex_unlock( &p_input->stream.stream_lock );    
+    p_avi_demux->i_rate = DEFAULT_RATE;
     if( p_avi_demux->i_rate != DEFAULT_RATE )
     {
         p_info_slave = NULL;