]> git.sesse.net Git - vlc/blobdiff - modules/demux/avi/libavi.c
Fixed a compilation warning
[vlc] / modules / demux / avi / libavi.c
index 5978484ac86d329c550c1528574af50e9de2ed07..dfd89478283ecf765a21b33dd426349c49739725 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include <stdlib.h>                                      /* malloc(), free() */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
 #include <vlc_demux.h>
@@ -32,7 +35,7 @@
 
 #define __EVEN( x ) ( (x)&0x01 ? (x)+1 : (x) )
 
-static vlc_fourcc_t GetFOURCC( byte_t *p_buff )
+static vlc_fourcc_t GetFOURCC( const byte_t *p_buff )
 {
     return VLC_FOURCC( p_buff[0], p_buff[1], p_buff[2], p_buff[3] );
 }
@@ -47,7 +50,7 @@ void    _AVI_ChunkFree( stream_t *, avi_chunk_t *p_chk );
  ****************************************************************************/
 static int AVI_ChunkReadCommon( stream_t *s, avi_chunk_t *p_chk )
 {
-    uint8_t  *p_peek;
+    const uint8_t *p_peek;
     int i_peek;
 
     memset( p_chk, 0, sizeof( avi_chunk_t ) );
@@ -112,7 +115,7 @@ static int AVI_NextChunk( stream_t *s, avi_chunk_t *p_chk )
 static int AVI_ChunkRead_list( stream_t *s, avi_chunk_t *p_container )
 {
     avi_chunk_t *p_chk;
-    uint8_t *p_peek;
+    const uint8_t *p_peek;
     vlc_bool_t b_seekable;
 
     if( p_container->common.i_chunk_size > 0 && p_container->common.i_chunk_size < 8 )
@@ -131,6 +134,13 @@ static int AVI_ChunkRead_list( stream_t *s, avi_chunk_t *p_container )
 
     p_container->list.i_type = GetFOURCC( p_peek + 8 );
 
+    /* XXX fixed for on2 hack */
+    if( p_container->common.i_chunk_fourcc == AVIFOURCC_ON2 && p_container->list.i_type == AVIFOURCC_ON2f )
+    {
+        p_container->common.i_chunk_fourcc = AVIFOURCC_RIFF;
+        p_container->list.i_type = AVIFOURCC_AVI;
+    }
+
     if( p_container->common.i_chunk_fourcc == AVIFOURCC_LIST &&
         p_container->list.i_type == AVIFOURCC_movi )
     {
@@ -173,7 +183,7 @@ static int AVI_ChunkRead_list( stream_t *s, avi_chunk_t *p_container )
             break;
         }
         if( p_chk->common.p_father->common.i_chunk_size > 0 &&
-           ( stream_Tell( s ) >=
+           ( stream_Tell( s ) >
               (off_t)p_chk->common.p_father->common.i_chunk_pos +
                (off_t)__EVEN( p_chk->common.p_father->common.i_chunk_size ) ) )
         {
@@ -210,43 +220,44 @@ static int AVI_ChunkRead_list( stream_t *s, avi_chunk_t *p_container )
     p_read += 8; \
     i_read -= 8
 
+#define AVI_READ( res, func, size ) \
+    if( i_read < size ) { \
+        free( p_buff); \
+        return VLC_EGENERIC; \
+    } \
+    i_read -= size; \
+    res = func( p_read ); \
+    p_read += size \
+
 #define AVI_READCHUNK_EXIT( code ) \
     free( p_buff ); \
-    if( i_read < 0 ) \
-    { \
-        msg_Warn( (vlc_object_t*)s, "not enough data" ); \
-    } \
     return code
 
+static inline uint8_t GetB( uint8_t *ptr )
+{
+    return *ptr;
+}
+
 #define AVI_READ1BYTE( i_byte ) \
-    i_byte = *p_read; \
-    p_read++; \
-    i_read--
+    AVI_READ( i_byte, GetB, 1 )
 
 #define AVI_READ2BYTES( i_word ) \
-    i_word = GetWLE( p_read ); \
-    p_read += 2; \
-    i_read -= 2
+    AVI_READ( i_word, GetWLE, 2 )
 
 #define AVI_READ4BYTES( i_dword ) \
-    i_dword = GetDWLE( p_read ); \
-    p_read += 4; \
-    i_read -= 4
+    AVI_READ( i_dword, GetDWLE, 4 )
 
-#define AVI_READ8BYTES( i_dword ) \
-    i_dword = GetQWLE( p_read ); \
-    p_read += 8; \
-    i_read -= 8
+#define AVI_READ8BYTES( i_qword ) \
+    AVI_READ( i_qword, GetQWLE, 8 )
 
 #define AVI_READFOURCC( i_dword ) \
-    i_dword = GetFOURCC( p_read ); \
-    p_read += 4; \
-    i_read -= 4
+    AVI_READ( i_dword, GetFOURCC, 4 )
 
 static int AVI_ChunkRead_avih( stream_t *s, avi_chunk_t *p_chk )
 {
     AVI_READCHUNK_ENTER;
 
+    p_chk->common.i_chunk_fourcc = AVIFOURCC_avih;
     AVI_READ4BYTES( p_chk->avih.i_microsecperframe);
     AVI_READ4BYTES( p_chk->avih.i_maxbytespersec );
     AVI_READ4BYTES( p_chk->avih.i_reserved1 );
@@ -433,7 +444,7 @@ static int AVI_ChunkRead_strd( stream_t *s, avi_chunk_t *p_chk )
 
 static void AVI_ChunkFree_strd( avi_chunk_t *p_chk )
 {
-    if( p_chk->strd.p_data ) free( p_chk->strd.p_data );
+    free( p_chk->strd.p_data );
 }
 
 static int AVI_ChunkRead_idx1( stream_t *s, avi_chunk_t *p_chk )
@@ -472,7 +483,7 @@ static void AVI_ChunkFree_idx1( avi_chunk_t *p_chk )
 {
     p_chk->idx1.i_entry_count = 0;
     p_chk->idx1.i_entry_max   = 0;
-    FREENULL( p_chk->idx1.entry )
+    FREENULL( p_chk->idx1.entry );
 }
 
 
@@ -651,8 +662,10 @@ static struct
 } AVI_Chunk_Function [] =
 {
     { AVIFOURCC_RIFF, AVI_ChunkRead_list, AVI_ChunkFree_nothing },
+    { AVIFOURCC_ON2,  AVI_ChunkRead_list, AVI_ChunkFree_nothing },
     { AVIFOURCC_LIST, AVI_ChunkRead_list, AVI_ChunkFree_nothing },
     { AVIFOURCC_avih, AVI_ChunkRead_avih, AVI_ChunkFree_nothing },
+    { AVIFOURCC_ON2h, AVI_ChunkRead_avih, AVI_ChunkFree_nothing },
     { AVIFOURCC_strh, AVI_ChunkRead_strh, AVI_ChunkFree_nothing },
     { AVIFOURCC_strf, AVI_ChunkRead_strf, AVI_ChunkFree_strf },
     { AVIFOURCC_strd, AVI_ChunkRead_strd, AVI_ChunkFree_strd },
@@ -730,7 +743,7 @@ int  _AVI_ChunkRead( stream_t *s, avi_chunk_t *p_chk, avi_chunk_t *p_father )
         return AVI_Chunk_Function[i_index].AVI_ChunkRead_function( s, p_chk );
     }
     else if( ( ((char*)&p_chk->common.i_chunk_fourcc)[0] == 'i' &&
-               ((char*)&p_chk->common.i_chunk_fourcc)[1] == 'x' ) || 
+               ((char*)&p_chk->common.i_chunk_fourcc)[1] == 'x' ) ||
              ( ((char*)&p_chk->common.i_chunk_fourcc)[2] == 'i' &&
                ((char*)&p_chk->common.i_chunk_fourcc)[3] == 'x' ) )
     {
@@ -793,7 +806,8 @@ static void AVI_ChunkDumpDebug_level( vlc_object_t *p_obj,
     {
         str[i * 5] = '|';
     }
-    if( p_chk->common.i_chunk_fourcc == AVIFOURCC_RIFF||
+    if( p_chk->common.i_chunk_fourcc == AVIFOURCC_RIFF ||
+        p_chk->common.i_chunk_fourcc == AVIFOURCC_ON2  ||
         p_chk->common.i_chunk_fourcc == AVIFOURCC_LIST )
     {
         sprintf( str + i_level * 5,