]> git.sesse.net Git - vlc/blobdiff - plugins/avi/libioRIFF.c
* ALL: the first libvlc commit.
[vlc] / plugins / avi / libioRIFF.c
index 3255eafda1cd6583f8e19d54a80a4998b60b24ac..86c4cdcb11c8e8a81ee78dfbf0c93bb3308cf537 100644 (file)
@@ -2,7 +2,7 @@
  * libioRIFF.c : AVI file Stream input module for vlc
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: libioRIFF.c,v 1.4 2002/05/04 16:51:05 fenrir Exp $
+ * $Id: libioRIFF.c,v 1.7 2002/06/01 12:31:58 sam Exp $
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  * 
  * This program is free software; you can redistribute it and/or modify
@@ -81,7 +81,7 @@ static int    __RIFF_SkipBytes(input_thread_t * p_input,int nb)
     }
     else
     {
-        intf_WarnMsg( 1, "input demux: cannot seek, it will take times" );
+        msg_Warn( p_input, "cannot seek, it will take times" );
         if( nb < 0 ) { return( -1 ); }
         i_rest = nb;
         while (i_rest != 0 )
@@ -128,7 +128,7 @@ static riffchunk_t     * RIFF_ReadChunk(input_thread_t * p_input)
  
        if((p_riff = malloc( sizeof(riffchunk_t))) == NULL)
        {
-               intf_ErrMsg("input error: not enough memory (ioriff)" );
+               msg_Err( p_input, "out of memory" );
                return NULL;
        }
        
@@ -139,7 +139,7 @@ static riffchunk_t     * RIFF_ReadChunk(input_thread_t * p_input)
        count=input_Peek( p_input, &p_peek, 12 );
        if( count < 8 )
        {
-               intf_ErrMsg( "input error: cannot peek() (ioriff)" );
+               msg_Err( p_input, "cannot peek()" );
                free(p_riff);
                return NULL;
        }
@@ -171,7 +171,7 @@ static int RIFF_NextChunk( input_thread_t * p_input,riffchunk_t *p_rifffather)
 
        if( ( p_riff = RIFF_ReadChunk( p_input ) ) == NULL )
        {
-               intf_ErrMsg( "ioriff: cannot read chunk." );
+               msg_Err( p_input, "cannot read chunk" );
                return( -1 );
        }
        i_len = p_riff->i_size;
@@ -181,9 +181,9 @@ static int RIFF_NextChunk( input_thread_t * p_input,riffchunk_t *p_rifffather)
        {
                i_lenfather=p_rifffather->i_size; 
         if ( i_lenfather%2 !=0 ) {i_lenfather++;}
-               if ( p_rifffather->i_pos + i_lenfather <= p_riff->i_pos + i_len )
+               if ( p_rifffather->i_pos + i_lenfather  <= p_riff->i_pos + i_len + 8 )
                {
-            intf_ErrMsg( "ioriff: next chunk out of bound" );
+                        msg_Err( p_input, "next chunk out of bounds" );
                        free( p_riff );
                        return( 1 ); /* pas dans nos frontiere */
                }
@@ -191,7 +191,7 @@ static int RIFF_NextChunk( input_thread_t * p_input,riffchunk_t *p_rifffather)
        if ( __RIFF_SkipBytes( p_input,i_len + 8 ) != 0 )
        { 
                free( p_riff );
-               intf_ErrMsg( "input error: cannot go to the next chunk (ioriff)." );
+               msg_Err( p_input, "cannot go to the next chunk" );
                return( -1 );
        }
        free( p_riff );
@@ -205,7 +205,7 @@ static int  RIFF_DescendChunk(input_thread_t * p_input)
 {
        if ( __RIFF_SkipBytes(p_input,12) != 0)
        {
-               intf_ErrMsg( "input error: cannot go into chunk." );
+               msg_Err( p_input, "cannot go into chunk" );
                return ( -1 );
        }
        return( 0 );
@@ -229,7 +229,7 @@ static int  RIFF_AscendChunk(input_thread_t * p_input ,riffchunk_t *p_rifffather)
 
     if (( __RIFF_SkipBytes(p_input,i_skip)) != 0)
        {
-               intf_ErrMsg( "ioriff: cannot exit from subchunk.");
+               msg_Err( p_input, "cannot exit from subchunk" );
                return( -1 );
        }
        return( 0 );
@@ -280,7 +280,7 @@ static int  RIFF_LoadChunkData(input_thread_t * p_input,riffchunk_t *p_riff )
        RIFF_GoToChunkData(p_input);
        if ( input_SplitBuffer( p_input, &p_riff->p_data, p_riff->i_size ) != p_riff->i_size )
        {
-        intf_ErrMsg( "ioriff: cannot read enough data " );
+               msg_Err( p_input, "cannot read enough data " );
                return ( -1 );
        }
        if ( p_riff->i_size%2 != 0) 
@@ -291,11 +291,13 @@ static int        RIFF_LoadChunkData(input_thread_t * p_input,riffchunk_t *p_riff )
 }
 
 static int     RIFF_LoadChunkDataInPES(input_thread_t * p_input,
-                                    pes_packet_t **pp_pes)
+                                    pes_packet_t **pp_pes,
+                                    int i_size_index)
 {
     u32 i_read;
     data_packet_t *p_data;
     riffchunk_t   *p_riff;
+    int i_size;
     
     if( (p_riff = RIFF_ReadChunk( p_input )) == NULL )
     {
@@ -309,6 +311,16 @@ static int RIFF_LoadChunkDataInPES(input_thread_t * p_input,
     {
         return( -1 );
     }
+
+    if( (!p_riff->i_size) || (!i_size_index ) )
+    {
+        i_size = __MAX( i_size_index, p_riff->i_size );
+    }
+    else
+    {
+        i_size = __MIN( p_riff->i_size, i_size_index );
+    }
+    
     if( p_riff->i_size == 0 )
     {
         p_data = input_NewPacket( p_input->p_method_data, 0 );
@@ -321,7 +333,7 @@ static int  RIFF_LoadChunkDataInPES(input_thread_t * p_input,
         
     do
     {
-        i_read = input_SplitBuffer(p_input, &p_data, p_riff->i_size - 
+        i_read = input_SplitBuffer(p_input, &p_data, i_size - 
                                                     (*pp_pes)->i_pes_size );
         if( i_read < 0 )
         {
@@ -344,9 +356,9 @@ static int  RIFF_LoadChunkDataInPES(input_thread_t * p_input,
             (*pp_pes)->i_pes_size += ( p_data->p_payload_end -
                                        p_data->p_payload_start );
         }
-    } while( ((*pp_pes)->i_pes_size < p_riff->i_size)&&(i_read != 0) );
+    } while( ((*pp_pes)->i_pes_size < i_size)&&(i_read != 0) );
    /* i_read =  0 si fin du stream sinon block */
-       if ( p_riff->i_size%2 != 0) 
+       if ( i_size%2 != 0) 
     {
        __RIFF_SkipBytes(p_input,1);
     } /* aligne sur un mot */
@@ -388,7 +400,7 @@ static int   RIFF_TestFileHeader( input_thread_t * p_input, riffchunk_t ** pp_ri
     
     if( *pp_riff == NULL )
     {
-        intf_ErrMsg( "input error: cannot retrieve header" );
+        msg_Err( p_input, "cannot retrieve header" );
         return( -1 );
     }
     if( (*pp_riff)->i_id != FOURCC_RIFF )