@ -31,10 +31,11 @@ typedef struct {
INT64 movi_end ;
offset_t movi_list ;
AVIIndex * first , * last ;
int framenum ;
} AVIContext ;
# ifdef DEBUG
void print_tag ( const char * str , unsigned int tag , int size )
static void print_tag ( const char * str , unsigned int tag , int size )
{
printf ( " %s: tag=%c%c%c%c size=0x%x \n " ,
str , tag & 0xff ,
@ -45,7 +46,7 @@ void print_tag(const char *str, unsigned int tag, int size)
}
# endif
int avi_read_header ( AVFormatContext * s , AVFormatParameters * ap )
static int avi_read_header ( AVFormatContext * s , AVFormatParameters * ap )
{
AVIContext * avi = s - > priv_data ;
ByteIOContext * pb = & s - > pb ;
@ -68,6 +69,7 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
stream_index = - 1 ;
codec_type = - 1 ;
frame_period = 0 ;
avi - > framenum = 0 ;
for ( ; ; ) {
if ( url_feof ( pb ) )
goto fail ;
@ -94,16 +96,15 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
break ;
case MKTAG ( ' a ' , ' v ' , ' i ' , ' h ' ) :
/* avi header */
/* using frame_period is bad idea */
frame_period = get_le32 ( pb ) ;
bit_rate = get_le32 ( pb ) * 8 ;
url_fskip ( pb , 4 * 4 ) ;
s - > nb_streams = get_le32 ( pb ) ;
for ( i = 0 ; i < s - > nb_streams ; i + + ) {
AVStream * st ;
st = av_malloc ( sizeof ( AVStream ) ) ;
AVStream * st = av_mallocz ( sizeof ( AVStream ) ) ;
if ( ! st )
goto fail ;
memset ( st , 0 , sizeof ( AVStream ) ) ;
s - > streams [ i ] = st ;
}
url_fskip ( pb , size - 7 * 4 ) ;
@ -122,16 +123,13 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
get_le32 ( pb ) ; /* XXX: initial frame ? */
get_le32 ( pb ) ; /* scale */
get_le32 ( pb ) ; /* rate */
url_fskip ( pb , size - 7 * 4 ) ;
size - = 6 * 4 ;
break ;
case MKTAG ( ' a ' , ' u ' , ' d ' , ' s ' ) :
codec_type = CODEC_TYPE_AUDIO ;
/* nothing really useful */
url_fskip ( pb , size - 4 ) ;
break ;
default :
goto fail ;
}
url_fskip ( pb , size - 4 ) ;
break ;
case MKTAG ( ' s ' , ' t ' , ' r ' , ' f ' ) :
/* stream header */
@ -188,35 +186,34 @@ int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
return 0 ;
}
int avi_read_packet ( AVFormatContext * s , AVPacket * pkt )
static int avi_read_packet ( AVFormatContext * s , AVPacket * pkt )
{
AVIContext * avi = s - > priv_data ;
ByteIOContext * pb = & s - > pb ;
int n , d1 , d2 , size ;
find_next :
for ( ; ; ) {
if ( url_feof ( pb ) | | url_ftell ( pb ) > = avi - > movi_end )
return - 1 ;
d1 = get_byte ( pb ) ;
if ( d1 < ' 0 ' | | d1 > ' 9 ' )
goto find_next ;
d2 = get_byte ( pb ) ;
if ( d2 < ' 0 ' | | d2 > ' 9 ' )
goto find_next ;
n = ( d1 - ' 0 ' ) * 10 + ( d2 - ' 0 ' ) ;
d1 = get_byte ( pb ) - ' 0 ' ;
d2 = get_byte ( pb ) - ' 0 ' ;
if ( d1 < 0 | | d1 > 9 | | d2 < 0 | | d2 > 9 )
continue ;
n = d1 * 10 + d2 ;
if ( n < 0 | | n > = s - > nb_streams )
goto find_next ;
continue ;
d1 = get_byte ( pb ) ;
d2 = get_byte ( pb ) ;
if ( ( d1 ! = ' d ' & & d2 ! = ' c ' ) & &
( d1 ! = ' w ' & & d2 ! = ' b ' ) )
goto find_next ;
if ( ( d1 = = ' d ' & & d2 = = ' c ' )
| | ( d1 = = ' w ' & & d2 = = ' b ' ) )
break ;
}
size = get_le32 ( pb ) ;
av_new_packet ( pkt , size ) ;
pkt - > stream_index = n ;
pkt - > pts = avi - > framenum + + ;
get_buffer ( pb , pkt - > data , pkt - > size ) ;
@ -226,7 +223,7 @@ int avi_read_packet(AVFormatContext *s, AVPacket *pkt)
return 0 ;
}
int avi_read_close ( AVFormatContext * s )
static int avi_read_close ( AVFormatContext * s )
{
return 0 ;
}