@ -83,11 +83,11 @@ static int mov_metadata_trkn(MOVContext *c, AVIOContext *pb, unsigned len)
{
{
char buf [ 16 ] ;
char buf [ 16 ] ;
get_be 16( pb ) ; // unknown
avio_rb 16( pb ) ; // unknown
snprintf ( buf , sizeof ( buf ) , " %d " , get_be 16( pb ) ) ;
snprintf ( buf , sizeof ( buf ) , " %d " , avio_rb 16( pb ) ) ;
av_metadata_set2 ( & c - > fc - > metadata , " track " , buf , 0 ) ;
av_metadata_set2 ( & c - > fc - > metadata , " track " , buf , 0 ) ;
get_be 16( pb ) ; // total tracks
avio_rb 16( pb ) ; // total tracks
return 0 ;
return 0 ;
}
}
@ -119,7 +119,7 @@ static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len,
int i ;
int i ;
for ( i = 0 ; i < len ; i + + ) {
for ( i = 0 ; i < len ; i + + ) {
uint8_t t , c = get_byte ( pb ) ;
uint8_t t , c = avio_r8 ( pb ) ;
if ( c < 0x80 & & p < end )
if ( c < 0x80 & & p < end )
* p + + = c ;
* p + + = c ;
else
else
@ -165,17 +165,17 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
}
}
if ( c - > itunes_metadata & & atom . size > 8 ) {
if ( c - > itunes_metadata & & atom . size > 8 ) {
int data_size = get_be 32( pb ) ;
int data_size = avio_rb 32( pb ) ;
int tag = get_le 32( pb ) ;
int tag = avio_rl 32( pb ) ;
if ( tag = = MKTAG ( ' d ' , ' a ' , ' t ' , ' a ' ) ) {
if ( tag = = MKTAG ( ' d ' , ' a ' , ' t ' , ' a ' ) ) {
data_type = get_be 32( pb ) ; // type
data_type = avio_rb 32( pb ) ; // type
get_be 32( pb ) ; // unknown
avio_rb 32( pb ) ; // unknown
str_size = data_size - 16 ;
str_size = data_size - 16 ;
atom . size - = 16 ;
atom . size - = 16 ;
} else return 0 ;
} else return 0 ;
} else if ( atom . size > 4 & & key & & ! c - > itunes_metadata ) {
} else if ( atom . size > 4 & & key & & ! c - > itunes_metadata ) {
str_size = get_be 16( pb ) ; // string length
str_size = avio_rb 16( pb ) ; // string length
langcode = get_be 16( pb ) ;
langcode = avio_rb 16( pb ) ;
ff_mov_lang_to_iso639 ( langcode , language ) ;
ff_mov_lang_to_iso639 ( langcode , language ) ;
atom . size - = 4 ;
atom . size - = 4 ;
} else
} else
@ -201,7 +201,7 @@ static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if ( data_type = = 3 | | ( data_type = = 0 & & langcode < 0x800 ) ) { // MAC Encoded
if ( data_type = = 3 | | ( data_type = = 0 & & langcode < 0x800 ) ) { // MAC Encoded
mov_read_mac_string ( c , pb , str_size , str , sizeof ( str ) ) ;
mov_read_mac_string ( c , pb , str_size , str , sizeof ( str ) ) ;
} else {
} else {
get_buffer ( pb , str , str_size ) ;
avio_read ( pb , str , str_size ) ;
str [ str_size ] = 0 ;
str [ str_size ] = 0 ;
}
}
av_metadata_set2 ( & c - > fc - > metadata , key , str , 0 ) ;
av_metadata_set2 ( & c - > fc - > metadata , key , str , 0 ) ;
@ -228,23 +228,23 @@ static int mov_read_chpl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if ( ( atom . size - = 5 ) < 0 )
if ( ( atom . size - = 5 ) < 0 )
return 0 ;
return 0 ;
version = get_byte ( pb ) ;
version = avio_r8 ( pb ) ;
get_be 24( pb ) ;
avio_rb 24( pb ) ;
if ( version )
if ( version )
get_be 32( pb ) ; // ???
avio_rb 32( pb ) ; // ???
nb_chapters = get_byte ( pb ) ;
nb_chapters = avio_r8 ( pb ) ;
for ( i = 0 ; i < nb_chapters ; i + + ) {
for ( i = 0 ; i < nb_chapters ; i + + ) {
if ( atom . size < 9 )
if ( atom . size < 9 )
return 0 ;
return 0 ;
start = get_be 64( pb ) ;
start = avio_rb 64( pb ) ;
str_len = get_byte ( pb ) ;
str_len = avio_r8 ( pb ) ;
if ( ( atom . size - = 9 + str_len ) < 0 )
if ( ( atom . size - = 9 + str_len ) < 0 )
return 0 ;
return 0 ;
get_buffer ( pb , str , str_len ) ;
avio_read ( pb , str , str_len ) ;
str [ str_len ] = 0 ;
str [ str_len ] = 0 ;
ff_new_chapter ( c - > fc , i , ( AVRational ) { 1 , 10000000 } , start , AV_NOPTS_VALUE , str ) ;
ff_new_chapter ( c - > fc , i , ( AVRational ) { 1 , 10000000 } , start , AV_NOPTS_VALUE , str ) ;
}
}
@ -264,14 +264,14 @@ static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom)
a . size = atom . size ;
a . size = atom . size ;
a . type = 0 ;
a . type = 0 ;
if ( atom . size > = 8 ) {
if ( atom . size > = 8 ) {
a . size = get_be 32( pb ) ;
a . size = avio_rb 32( pb ) ;
a . type = get_le 32( pb ) ;
a . type = avio_rl 32( pb ) ;
}
}
av_dlog ( c - > fc , " type: %08x '%.4s' parent:'%.4s' sz: % " PRId64 " % " PRId64 " % " PRId64 " \n " ,
av_dlog ( c - > fc , " type: %08x '%.4s' parent:'%.4s' sz: % " PRId64 " % " PRId64 " % " PRId64 " \n " ,
a . type , ( char * ) & a . type , ( char * ) & atom . type , a . size , total_size , atom . size ) ;
a . type , ( char * ) & a . type , ( char * ) & atom . type , a . size , total_size , atom . size ) ;
total_size + = 8 ;
total_size + = 8 ;
if ( a . size = = 1 ) { /* 64 bit extended size */
if ( a . size = = 1 ) { /* 64 bit extended size */
a . size = get_be 64( pb ) - 8 ;
a . size = avio_rb 64( pb ) - 8 ;
total_size + = 8 ;
total_size + = 8 ;
}
}
if ( a . size = = 0 ) {
if ( a . size = = 0 ) {
@ -331,8 +331,8 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
get_be 32( pb ) ; // version + flags
avio_rb 32( pb ) ; // version + flags
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
if ( entries > = UINT_MAX / sizeof ( * sc - > drefs ) )
if ( entries > = UINT_MAX / sizeof ( * sc - > drefs ) )
return - 1 ;
return - 1 ;
sc - > drefs = av_mallocz ( entries * sizeof ( * sc - > drefs ) ) ;
sc - > drefs = av_mallocz ( entries * sizeof ( * sc - > drefs ) ) ;
@ -342,14 +342,14 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom)
for ( i = 0 ; i < sc - > drefs_count ; i + + ) {
for ( i = 0 ; i < sc - > drefs_count ; i + + ) {
MOVDref * dref = & sc - > drefs [ i ] ;
MOVDref * dref = & sc - > drefs [ i ] ;
uint32_t size = get_be 32( pb ) ;
uint32_t size = avio_rb 32( pb ) ;
int64_t next = url_ftell ( pb ) + size - 4 ;
int64_t next = url_ftell ( pb ) + size - 4 ;
if ( size < 12 )
if ( size < 12 )
return - 1 ;
return - 1 ;
dref - > type = get_le 32( pb ) ;
dref - > type = avio_rl 32( pb ) ;
get_be 32( pb ) ; // version + flags
avio_rb 32( pb ) ; // version + flags
av_dlog ( c - > fc , " type %.4s size %d \n " , ( char * ) & dref - > type , size ) ;
av_dlog ( c - > fc , " type %.4s size %d \n " , ( char * ) & dref - > type , size ) ;
if ( dref - > type = = MKTAG ( ' a ' , ' l ' , ' i ' , ' s ' ) & & size > 150 ) {
if ( dref - > type = = MKTAG ( ' a ' , ' l ' , ' i ' , ' s ' ) & & size > 150 ) {
@ -359,33 +359,33 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom)
url_fskip ( pb , 10 ) ;
url_fskip ( pb , 10 ) ;
volume_len = get_byte ( pb ) ;
volume_len = avio_r8 ( pb ) ;
volume_len = FFMIN ( volume_len , 27 ) ;
volume_len = FFMIN ( volume_len , 27 ) ;
get_buffer ( pb , dref - > volume , 27 ) ;
avio_read ( pb , dref - > volume , 27 ) ;
dref - > volume [ volume_len ] = 0 ;
dref - > volume [ volume_len ] = 0 ;
av_log ( c - > fc , AV_LOG_DEBUG , " volume %s, len %d \n " , dref - > volume , volume_len ) ;
av_log ( c - > fc , AV_LOG_DEBUG , " volume %s, len %d \n " , dref - > volume , volume_len ) ;
url_fskip ( pb , 12 ) ;
url_fskip ( pb , 12 ) ;
len = get_byte ( pb ) ;
len = avio_r8 ( pb ) ;
len = FFMIN ( len , 63 ) ;
len = FFMIN ( len , 63 ) ;
get_buffer ( pb , dref - > filename , 63 ) ;
avio_read ( pb , dref - > filename , 63 ) ;
dref - > filename [ len ] = 0 ;
dref - > filename [ len ] = 0 ;
av_log ( c - > fc , AV_LOG_DEBUG , " filename %s, len %d \n " , dref - > filename , len ) ;
av_log ( c - > fc , AV_LOG_DEBUG , " filename %s, len %d \n " , dref - > filename , len ) ;
url_fskip ( pb , 16 ) ;
url_fskip ( pb , 16 ) ;
/* read next level up_from_alias/down_to_target */
/* read next level up_from_alias/down_to_target */
dref - > nlvl_from = get_be 16( pb ) ;
dref - > nlvl_from = avio_rb 16( pb ) ;
dref - > nlvl_to = get_be 16( pb ) ;
dref - > nlvl_to = avio_rb 16( pb ) ;
av_log ( c - > fc , AV_LOG_DEBUG , " nlvl from %d, nlvl to %d \n " ,
av_log ( c - > fc , AV_LOG_DEBUG , " nlvl from %d, nlvl to %d \n " ,
dref - > nlvl_from , dref - > nlvl_to ) ;
dref - > nlvl_from , dref - > nlvl_to ) ;
url_fskip ( pb , 16 ) ;
url_fskip ( pb , 16 ) ;
for ( type = 0 ; type ! = - 1 & & url_ftell ( pb ) < next ; ) {
for ( type = 0 ; type ! = - 1 & & url_ftell ( pb ) < next ; ) {
type = get_be 16( pb ) ;
type = avio_rb 16( pb ) ;
len = get_be 16( pb ) ;
len = avio_rb 16( pb ) ;
av_log ( c - > fc , AV_LOG_DEBUG , " type %d, len %d \n " , type , len ) ;
av_log ( c - > fc , AV_LOG_DEBUG , " type %d, len %d \n " , type , len ) ;
if ( len & 1 )
if ( len & 1 )
len + = 1 ;
len + = 1 ;
@ -394,7 +394,7 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom)
dref - > path = av_mallocz ( len + 1 ) ;
dref - > path = av_mallocz ( len + 1 ) ;
if ( ! dref - > path )
if ( ! dref - > path )
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
get_buffer ( pb , dref - > path , len ) ;
avio_read ( pb , dref - > path , len ) ;
if ( len > volume_len & & ! strncmp ( dref - > path , dref - > volume , volume_len ) ) {
if ( len > volume_len & & ! strncmp ( dref - > path , dref - > volume , volume_len ) ) {
len - = volume_len ;
len - = volume_len ;
memmove ( dref - > path , dref - > path + volume_len , len ) ;
memmove ( dref - > path , dref - > path + volume_len , len ) ;
@ -409,7 +409,7 @@ static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom)
dref - > dir = av_malloc ( len + 1 ) ;
dref - > dir = av_malloc ( len + 1 ) ;
if ( ! dref - > dir )
if ( ! dref - > dir )
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
get_buffer ( pb , dref - > dir , len ) ;
avio_read ( pb , dref - > dir , len ) ;
dref - > dir [ len ] = 0 ;
dref - > dir [ len ] = 0 ;
for ( j = 0 ; j < len ; j + + )
for ( j = 0 ; j < len ; j + + )
if ( dref - > dir [ j ] = = ' : ' )
if ( dref - > dir [ j ] = = ' : ' )
@ -435,12 +435,12 @@ static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
/* component type */
/* component type */
ctype = get_le 32( pb ) ;
ctype = avio_rl 32( pb ) ;
type = get_le 32( pb ) ; /* component subtype */
type = avio_rl 32( pb ) ; /* component subtype */
av_dlog ( c - > fc , " ctype= %.4s (0x%08x) \n " , ( char * ) & ctype , ctype ) ;
av_dlog ( c - > fc , " ctype= %.4s (0x%08x) \n " , ( char * ) & ctype , ctype ) ;
av_dlog ( c - > fc , " stype= %.4s \n " , ( char * ) & type ) ;
av_dlog ( c - > fc , " stype= %.4s \n " , ( char * ) & type ) ;
@ -454,9 +454,9 @@ static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
else if ( type = = MKTAG ( ' s ' , ' u ' , ' b ' , ' p ' ) )
else if ( type = = MKTAG ( ' s ' , ' u ' , ' b ' , ' p ' ) )
st - > codec - > codec_type = AVMEDIA_TYPE_SUBTITLE ;
st - > codec - > codec_type = AVMEDIA_TYPE_SUBTITLE ;
get_be 32( pb ) ; /* component manufacture */
avio_rb 32( pb ) ; /* component manufacture */
get_be 32( pb ) ; /* component flags */
avio_rb 32( pb ) ; /* component flags */
get_be 32( pb ) ; /* component flags mask */
avio_rb 32( pb ) ; /* component flags mask */
return 0 ;
return 0 ;
}
}
@ -470,13 +470,13 @@ int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom)
return 0 ;
return 0 ;
st = fc - > streams [ fc - > nb_streams - 1 ] ;
st = fc - > streams [ fc - > nb_streams - 1 ] ;
get_be 32( pb ) ; /* version + flags */
avio_rb 32( pb ) ; /* version + flags */
len = ff_mp4_read_descr ( fc , pb , & tag ) ;
len = ff_mp4_read_descr ( fc , pb , & tag ) ;
if ( tag = = MP4ESDescrTag ) {
if ( tag = = MP4ESDescrTag ) {
get_be 16( pb ) ; /* ID */
avio_rb 16( pb ) ; /* ID */
get_byte ( pb ) ; /* priority */
avio_r8 ( pb ) ; /* priority */
} else
} else
get_be 16( pb ) ; /* ID */
avio_rb 16( pb ) ; /* ID */
len = ff_mp4_read_descr ( fc , pb , & tag ) ;
len = ff_mp4_read_descr ( fc , pb , & tag ) ;
if ( tag = = MP4DecConfigDescrTag )
if ( tag = = MP4DecConfigDescrTag )
@ -498,7 +498,7 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0 ;
return 0 ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
ac3info = get_be 24( pb ) ;
ac3info = avio_rb 24( pb ) ;
acmod = ( ac3info > > 11 ) & 0x7 ;
acmod = ( ac3info > > 11 ) & 0x7 ;
lfeon = ( ac3info > > 10 ) & 0x1 ;
lfeon = ( ac3info > > 10 ) & 0x1 ;
st - > codec - > channels = ( ( int [ ] ) { 2 , 1 , 2 , 3 , 3 , 4 , 4 , 5 } ) [ acmod ] + lfeon ;
st - > codec - > channels = ( ( int [ ] ) { 2 , 1 , 2 , 3 , 3 , 4 , 4 , 5 } ) [ acmod ] + lfeon ;
@ -508,8 +508,8 @@ static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
static int mov_read_pasp ( MOVContext * c , AVIOContext * pb , MOVAtom atom )
static int mov_read_pasp ( MOVContext * c , AVIOContext * pb , MOVAtom atom )
{
{
const int num = get_be 32( pb ) ;
const int num = avio_rb 32( pb ) ;
const int den = get_be 32( pb ) ;
const int den = avio_rb 32( pb ) ;
AVStream * st ;
AVStream * st ;
if ( c - > fc - > nb_streams < 1 )
if ( c - > fc - > nb_streams < 1 )
@ -547,12 +547,12 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
char * comp_brands_str ;
char * comp_brands_str ;
uint8_t type [ 5 ] = { 0 } ;
uint8_t type [ 5 ] = { 0 } ;
get_buffer ( pb , type , 4 ) ;
avio_read ( pb , type , 4 ) ;
if ( strcmp ( type , " qt " ) )
if ( strcmp ( type , " qt " ) )
c - > isom = 1 ;
c - > isom = 1 ;
av_log ( c - > fc , AV_LOG_DEBUG , " ISO: File Type Major Brand: %.4s \n " , ( char * ) & type ) ;
av_log ( c - > fc , AV_LOG_DEBUG , " ISO: File Type Major Brand: %.4s \n " , ( char * ) & type ) ;
av_metadata_set2 ( & c - > fc - > metadata , " major_brand " , type , 0 ) ;
av_metadata_set2 ( & c - > fc - > metadata , " major_brand " , type , 0 ) ;
minor_ver = get_be 32( pb ) ; /* minor version */
minor_ver = avio_rb 32( pb ) ; /* minor version */
snprintf ( minor_ver_str , sizeof ( minor_ver_str ) , " %d " , minor_ver ) ;
snprintf ( minor_ver_str , sizeof ( minor_ver_str ) , " %d " , minor_ver ) ;
av_metadata_set2 ( & c - > fc - > metadata , " minor_version " , minor_ver_str , 0 ) ;
av_metadata_set2 ( & c - > fc - > metadata , " minor_version " , minor_ver_str , 0 ) ;
@ -562,7 +562,7 @@ static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
comp_brands_str = av_malloc ( comp_brand_size + 1 ) ; /* Add null terminator */
comp_brands_str = av_malloc ( comp_brand_size + 1 ) ; /* Add null terminator */
if ( ! comp_brands_str )
if ( ! comp_brands_str )
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
get_buffer ( pb , comp_brands_str , comp_brand_size ) ;
avio_read ( pb , comp_brands_str , comp_brand_size ) ;
comp_brands_str [ comp_brand_size ] = 0 ;
comp_brands_str [ comp_brand_size ] = 0 ;
av_metadata_set2 ( & c - > fc - > metadata , " compatible_brands " , comp_brands_str , 0 ) ;
av_metadata_set2 ( & c - > fc - > metadata , " compatible_brands " , comp_brands_str , 0 ) ;
av_freep ( & comp_brands_str ) ;
av_freep ( & comp_brands_str ) ;
@ -615,27 +615,27 @@ static int mov_read_mdhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
version = get_byte ( pb ) ;
version = avio_r8 ( pb ) ;
if ( version > 1 )
if ( version > 1 )
return - 1 ; /* unsupported */
return - 1 ; /* unsupported */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
if ( version = = 1 ) {
if ( version = = 1 ) {
creation_time = get_be 64( pb ) ;
creation_time = avio_rb 64( pb ) ;
get_be 64( pb ) ;
avio_rb 64( pb ) ;
} else {
} else {
creation_time = get_be 32( pb ) ;
creation_time = avio_rb 32( pb ) ;
get_be 32( pb ) ; /* modification time */
avio_rb 32( pb ) ; /* modification time */
}
}
mov_metadata_creation_time ( & st - > metadata , creation_time ) ;
mov_metadata_creation_time ( & st - > metadata , creation_time ) ;
sc - > time_scale = get_be 32( pb ) ;
sc - > time_scale = avio_rb 32( pb ) ;
st - > duration = ( version = = 1 ) ? get_be 64( pb ) : get_be 32( pb ) ; /* duration */
st - > duration = ( version = = 1 ) ? avio_rb 64( pb ) : avio_rb 32( pb ) ; /* duration */
lang = get_be 16( pb ) ; /* language */
lang = avio_rb 16( pb ) ; /* language */
if ( ff_mov_lang_to_iso639 ( lang , language ) )
if ( ff_mov_lang_to_iso639 ( lang , language ) )
av_metadata_set2 ( & st - > metadata , " language " , language , 0 ) ;
av_metadata_set2 ( & st - > metadata , " language " , language , 0 ) ;
get_be 16( pb ) ; /* quality */
avio_rb 16( pb ) ; /* quality */
return 0 ;
return 0 ;
}
}
@ -643,37 +643,37 @@ static int mov_read_mdhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
static int mov_read_mvhd ( MOVContext * c , AVIOContext * pb , MOVAtom atom )
static int mov_read_mvhd ( MOVContext * c , AVIOContext * pb , MOVAtom atom )
{
{
time_t creation_time ;
time_t creation_time ;
int version = get_byte ( pb ) ; /* version */
int version = avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
if ( version = = 1 ) {
if ( version = = 1 ) {
creation_time = get_be 64( pb ) ;
creation_time = avio_rb 64( pb ) ;
get_be 64( pb ) ;
avio_rb 64( pb ) ;
} else {
} else {
creation_time = get_be 32( pb ) ;
creation_time = avio_rb 32( pb ) ;
get_be 32( pb ) ; /* modification time */
avio_rb 32( pb ) ; /* modification time */
}
}
mov_metadata_creation_time ( & c - > fc - > metadata , creation_time ) ;
mov_metadata_creation_time ( & c - > fc - > metadata , creation_time ) ;
c - > time_scale = get_be 32( pb ) ; /* time scale */
c - > time_scale = avio_rb 32( pb ) ; /* time scale */
av_dlog ( c - > fc , " time scale = %i \n " , c - > time_scale ) ;
av_dlog ( c - > fc , " time scale = %i \n " , c - > time_scale ) ;
c - > duration = ( version = = 1 ) ? get_be 64( pb ) : get_be 32( pb ) ; /* duration */
c - > duration = ( version = = 1 ) ? avio_rb 64( pb ) : avio_rb 32( pb ) ; /* duration */
get_be 32( pb ) ; /* preferred scale */
avio_rb 32( pb ) ; /* preferred scale */
get_be 16( pb ) ; /* preferred volume */
avio_rb 16( pb ) ; /* preferred volume */
url_fskip ( pb , 10 ) ; /* reserved */
url_fskip ( pb , 10 ) ; /* reserved */
url_fskip ( pb , 36 ) ; /* display matrix */
url_fskip ( pb , 36 ) ; /* display matrix */
get_be 32( pb ) ; /* preview time */
avio_rb 32( pb ) ; /* preview time */
get_be 32( pb ) ; /* preview duration */
avio_rb 32( pb ) ; /* preview duration */
get_be 32( pb ) ; /* poster time */
avio_rb 32( pb ) ; /* poster time */
get_be 32( pb ) ; /* selection time */
avio_rb 32( pb ) ; /* selection time */
get_be 32( pb ) ; /* selection duration */
avio_rb 32( pb ) ; /* selection duration */
get_be 32( pb ) ; /* current time */
avio_rb 32( pb ) ; /* current time */
get_be 32( pb ) ; /* next track ID */
avio_rb 32( pb ) ; /* next track ID */
return 0 ;
return 0 ;
}
}
@ -697,7 +697,7 @@ static int mov_read_smi(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
st - > codec - > extradata_size = 0x5a + atom . size ;
st - > codec - > extradata_size = 0x5a + atom . size ;
memcpy ( st - > codec - > extradata , " SVQ3 " , 4 ) ; // fake
memcpy ( st - > codec - > extradata , " SVQ3 " , 4 ) ; // fake
get_buffer ( pb , st - > codec - > extradata + 0x5a , atom . size ) ;
avio_read ( pb , st - > codec - > extradata + 0x5a , atom . size ) ;
av_dlog ( c - > fc , " Reading SMI % " PRId64 " %s \n " , atom . size , st - > codec - > extradata + 0x5a ) ;
av_dlog ( c - > fc , " Reading SMI % " PRId64 " %s \n " , atom . size , st - > codec - > extradata + 0x5a ) ;
return 0 ;
return 0 ;
}
}
@ -711,7 +711,7 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0 ;
return 0 ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
little_endian = get_be 16( pb ) ;
little_endian = avio_rb 16( pb ) ;
av_dlog ( c - > fc , " enda %d \n " , little_endian ) ;
av_dlog ( c - > fc , " enda %d \n " , little_endian ) ;
if ( little_endian = = 1 ) {
if ( little_endian = = 1 ) {
switch ( st - > codec - > codec_id ) {
switch ( st - > codec - > codec_id ) {
@ -755,7 +755,7 @@ static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st - > codec - > extradata_size = size - FF_INPUT_BUFFER_PADDING_SIZE ;
st - > codec - > extradata_size = size - FF_INPUT_BUFFER_PADDING_SIZE ;
AV_WB32 ( buf , atom . size + 8 ) ;
AV_WB32 ( buf , atom . size + 8 ) ;
AV_WL32 ( buf + 4 , atom . type ) ;
AV_WL32 ( buf + 4 , atom . type ) ;
get_buffer ( pb , buf + 8 , atom . size ) ;
avio_read ( pb , buf + 8 , atom . size ) ;
return 0 ;
return 0 ;
}
}
@ -777,7 +777,7 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if ( ! st - > codec - > extradata )
if ( ! st - > codec - > extradata )
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
st - > codec - > extradata_size = atom . size ;
st - > codec - > extradata_size = atom . size ;
get_buffer ( pb , st - > codec - > extradata , atom . size ) ;
avio_read ( pb , st - > codec - > extradata , atom . size ) ;
} else if ( atom . size > 8 ) { /* to read frma, esds atoms */
} else if ( atom . size > 8 ) { /* to read frma, esds atoms */
if ( mov_read_default ( c , pb , atom ) < 0 )
if ( mov_read_default ( c , pb , atom ) < 0 )
return - 1 ;
return - 1 ;
@ -806,7 +806,7 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if ( ! st - > codec - > extradata )
if ( ! st - > codec - > extradata )
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
st - > codec - > extradata_size = atom . size ;
st - > codec - > extradata_size = atom . size ;
get_buffer ( pb , st - > codec - > extradata , atom . size ) ;
avio_read ( pb , st - > codec - > extradata , atom . size ) ;
return 0 ;
return 0 ;
}
}
@ -834,7 +834,7 @@ static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
st - > codec - > extradata_size = atom . size - 40 ;
st - > codec - > extradata_size = atom . size - 40 ;
url_fskip ( pb , 40 ) ;
url_fskip ( pb , 40 ) ;
get_buffer ( pb , st - > codec - > extradata , atom . size - 40 ) ;
avio_read ( pb , st - > codec - > extradata , atom . size - 40 ) ;
return 0 ;
return 0 ;
}
}
@ -849,10 +849,10 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
if ( entries > = UINT_MAX / sizeof ( int64_t ) )
if ( entries > = UINT_MAX / sizeof ( int64_t ) )
return - 1 ;
return - 1 ;
@ -864,10 +864,10 @@ static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if ( atom . type = = MKTAG ( ' s ' , ' t ' , ' c ' , ' o ' ) )
if ( atom . type = = MKTAG ( ' s ' , ' t ' , ' c ' , ' o ' ) )
for ( i = 0 ; i < entries ; i + + )
for ( i = 0 ; i < entries ; i + + )
sc - > chunk_offsets [ i ] = get_be 32( pb ) ;
sc - > chunk_offsets [ i ] = avio_rb 32( pb ) ;
else if ( atom . type = = MKTAG ( ' c ' , ' o ' , ' 6 ' , ' 4 ' ) )
else if ( atom . type = = MKTAG ( ' c ' , ' o ' , ' 6 ' , ' 4 ' ) )
for ( i = 0 ; i < entries ; i + + )
for ( i = 0 ; i < entries ; i + + )
sc - > chunk_offsets [ i ] = get_be 64( pb ) ;
sc - > chunk_offsets [ i ] = avio_rb 64( pb ) ;
else
else
return - 1 ;
return - 1 ;
@ -926,13 +926,13 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
int dref_id = 1 ;
int dref_id = 1 ;
MOVAtom a = { AV_RL32 ( " stsd " ) } ;
MOVAtom a = { AV_RL32 ( " stsd " ) } ;
int64_t start_pos = url_ftell ( pb ) ;
int64_t start_pos = url_ftell ( pb ) ;
int size = get_be 32( pb ) ; /* size */
int size = avio_rb 32( pb ) ; /* size */
uint32_t format = get_le 32( pb ) ; /* data format */
uint32_t format = avio_rl 32( pb ) ; /* data format */
if ( size > = 16 ) {
if ( size > = 16 ) {
get_be 32( pb ) ; /* reserved */
avio_rb 32( pb ) ; /* reserved */
get_be 16( pb ) ; /* reserved */
avio_rb 16( pb ) ; /* reserved */
dref_id = get_be 16( pb ) ;
dref_id = avio_rb 16( pb ) ;
}
}
if ( st - > codec - > codec_tag & &
if ( st - > codec - > codec_tag & &
@ -984,21 +984,21 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
int color_greyscale ;
int color_greyscale ;
st - > codec - > codec_id = id ;
st - > codec - > codec_id = id ;
get_be 16( pb ) ; /* version */
avio_rb 16( pb ) ; /* version */
get_be 16( pb ) ; /* revision level */
avio_rb 16( pb ) ; /* revision level */
get_be 32( pb ) ; /* vendor */
avio_rb 32( pb ) ; /* vendor */
get_be 32( pb ) ; /* temporal quality */
avio_rb 32( pb ) ; /* temporal quality */
get_be 32( pb ) ; /* spatial quality */
avio_rb 32( pb ) ; /* spatial quality */
st - > codec - > width = get_be 16( pb ) ; /* width */
st - > codec - > width = avio_rb 16( pb ) ; /* width */
st - > codec - > height = get_be 16( pb ) ; /* height */
st - > codec - > height = avio_rb 16( pb ) ; /* height */
get_be 32( pb ) ; /* horiz resolution */
avio_rb 32( pb ) ; /* horiz resolution */
get_be 32( pb ) ; /* vert resolution */
avio_rb 32( pb ) ; /* vert resolution */
get_be 32( pb ) ; /* data size, always 0 */
avio_rb 32( pb ) ; /* data size, always 0 */
get_be 16( pb ) ; /* frames per samples */
avio_rb 16( pb ) ; /* frames per samples */
len = get_byte ( pb ) ; /* codec name, pascal string */
len = avio_r8 ( pb ) ; /* codec name, pascal string */
if ( len > 31 )
if ( len > 31 )
len = 31 ;
len = 31 ;
mov_read_mac_string ( c , pb , len , st - > codec - > codec_name , 32 ) ;
mov_read_mac_string ( c , pb , len , st - > codec - > codec_name , 32 ) ;
@ -1008,8 +1008,8 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
if ( ! memcmp ( st - > codec - > codec_name , " Planar Y'CbCr 8-bit 4:2:0 " , 25 ) )
if ( ! memcmp ( st - > codec - > codec_name , " Planar Y'CbCr 8-bit 4:2:0 " , 25 ) )
st - > codec - > codec_tag = MKTAG ( ' I ' , ' 4 ' , ' 2 ' , ' 0 ' ) ;
st - > codec - > codec_tag = MKTAG ( ' I ' , ' 4 ' , ' 2 ' , ' 0 ' ) ;
st - > codec - > bits_per_coded_sample = get_be 16( pb ) ; /* depth */
st - > codec - > bits_per_coded_sample = avio_rb 16( pb ) ; /* depth */
st - > codec - > color_table_id = get_be 16( pb ) ; /* colortable id */
st - > codec - > color_table_id = avio_rb 16( pb ) ; /* colortable id */
av_dlog ( c - > fc , " depth %d, ctab id %d \n " ,
av_dlog ( c - > fc , " depth %d, ctab id %d \n " ,
st - > codec - > bits_per_coded_sample , st - > codec - > color_table_id ) ;
st - > codec - > bits_per_coded_sample , st - > codec - > color_table_id ) ;
/* figure out the palette situation */
/* figure out the palette situation */
@ -1059,23 +1059,23 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
}
}
} else {
} else {
/* load the palette from the file */
/* load the palette from the file */
color_start = get_be 32( pb ) ;
color_start = avio_rb 32( pb ) ;
color_count = get_be 16( pb ) ;
color_count = avio_rb 16( pb ) ;
color_end = get_be 16( pb ) ;
color_end = avio_rb 16( pb ) ;
if ( ( color_start < = 255 ) & &
if ( ( color_start < = 255 ) & &
( color_end < = 255 ) ) {
( color_end < = 255 ) ) {
for ( j = color_start ; j < = color_end ; j + + ) {
for ( j = color_start ; j < = color_end ; j + + ) {
/* each R, G, or B component is 16 bits;
/* each R, G, or B component is 16 bits;
* only use the top 8 bits ; skip alpha bytes
* only use the top 8 bits ; skip alpha bytes
* up front */
* up front */
get_byte ( pb ) ;
avio_r8 ( pb ) ;
get_byte ( pb ) ;
avio_r8 ( pb ) ;
r = get_byte ( pb ) ;
r = avio_r8 ( pb ) ;
get_byte ( pb ) ;
avio_r8 ( pb ) ;
g = get_byte ( pb ) ;
g = avio_r8 ( pb ) ;
get_byte ( pb ) ;
avio_r8 ( pb ) ;
b = get_byte ( pb ) ;
b = avio_r8 ( pb ) ;
get_byte ( pb ) ;
avio_r8 ( pb ) ;
st - > codec - > palctrl - > palette [ j ] =
st - > codec - > palctrl - > palette [ j ] =
( r < < 16 ) | ( g < < 8 ) | ( b ) ;
( r < < 16 ) | ( g < < 8 ) | ( b ) ;
}
}
@ -1085,38 +1085,38 @@ int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
}
}
} else if ( st - > codec - > codec_type = = AVMEDIA_TYPE_AUDIO ) {
} else if ( st - > codec - > codec_type = = AVMEDIA_TYPE_AUDIO ) {
int bits_per_sample , flags ;
int bits_per_sample , flags ;
uint16_t version = get_be 16( pb ) ;
uint16_t version = avio_rb 16( pb ) ;
st - > codec - > codec_id = id ;
st - > codec - > codec_id = id ;
get_be 16( pb ) ; /* revision level */
avio_rb 16( pb ) ; /* revision level */
get_be 32( pb ) ; /* vendor */
avio_rb 32( pb ) ; /* vendor */
st - > codec - > channels = get_be 16( pb ) ; /* channel count */
st - > codec - > channels = avio_rb 16( pb ) ; /* channel count */
av_dlog ( c - > fc , " audio channels %d \n " , st - > codec - > channels ) ;
av_dlog ( c - > fc , " audio channels %d \n " , st - > codec - > channels ) ;
st - > codec - > bits_per_coded_sample = get_be 16( pb ) ; /* sample size */
st - > codec - > bits_per_coded_sample = avio_rb 16( pb ) ; /* sample size */
sc - > audio_cid = get_be 16( pb ) ;
sc - > audio_cid = avio_rb 16( pb ) ;
get_be 16( pb ) ; /* packet size = 0 */
avio_rb 16( pb ) ; /* packet size = 0 */
st - > codec - > sample_rate = ( ( get_be 32( pb ) > > 16 ) ) ;
st - > codec - > sample_rate = ( ( avio_rb 32( pb ) > > 16 ) ) ;
//Read QT version 1 fields. In version 0 these do not exist.
//Read QT version 1 fields. In version 0 these do not exist.
av_dlog ( c - > fc , " version =%d, isom =%d \n " , version , c - > isom ) ;
av_dlog ( c - > fc , " version =%d, isom =%d \n " , version , c - > isom ) ;
if ( ! c - > isom ) {
if ( ! c - > isom ) {
if ( version = = 1 ) {
if ( version = = 1 ) {
sc - > samples_per_frame = get_be 32( pb ) ;
sc - > samples_per_frame = avio_rb 32( pb ) ;
get_be 32( pb ) ; /* bytes per packet */
avio_rb 32( pb ) ; /* bytes per packet */
sc - > bytes_per_frame = get_be 32( pb ) ;
sc - > bytes_per_frame = avio_rb 32( pb ) ;
get_be 32( pb ) ; /* bytes per sample */
avio_rb 32( pb ) ; /* bytes per sample */
} else if ( version = = 2 ) {
} else if ( version = = 2 ) {
get_be 32( pb ) ; /* sizeof struct only */
avio_rb 32( pb ) ; /* sizeof struct only */
st - > codec - > sample_rate = av_int2dbl ( get_be 64( pb ) ) ; /* float 64 */
st - > codec - > sample_rate = av_int2dbl ( avio_rb 64( pb ) ) ; /* float 64 */
st - > codec - > channels = get_be 32( pb ) ;
st - > codec - > channels = avio_rb 32( pb ) ;
get_be 32( pb ) ; /* always 0x7F000000 */
avio_rb 32( pb ) ; /* always 0x7F000000 */
st - > codec - > bits_per_coded_sample = get_be 32( pb ) ; /* bits per channel if sound is uncompressed */
st - > codec - > bits_per_coded_sample = avio_rb 32( pb ) ; /* bits per channel if sound is uncompressed */
flags = get_be 32( pb ) ; /* lpcm format specific flag */
flags = avio_rb 32( pb ) ; /* lpcm format specific flag */
sc - > bytes_per_frame = get_be 32( pb ) ; /* bytes per audio packet if constant */
sc - > bytes_per_frame = avio_rb 32( pb ) ; /* bytes per audio packet if constant */
sc - > samples_per_frame = get_be 32( pb ) ; /* lpcm frames per audio packet if constant */
sc - > samples_per_frame = avio_rb 32( pb ) ; /* lpcm frames per audio packet if constant */
if ( format = = MKTAG ( ' l ' , ' p ' , ' c ' , ' m ' ) )
if ( format = = MKTAG ( ' l ' , ' p ' , ' c ' , ' m ' ) )
st - > codec - > codec_id = ff_mov_get_lpcm_codec_id ( st - > codec - > bits_per_coded_sample , flags ) ;
st - > codec - > codec_id = ff_mov_get_lpcm_codec_id ( st - > codec - > bits_per_coded_sample , flags ) ;
}
}
@ -1249,9 +1249,9 @@ static int mov_read_stsd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
{
int entries ;
int entries ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
return ff_mov_read_stsd_entries ( c , pb , entries ) ;
return ff_mov_read_stsd_entries ( c , pb , entries ) ;
}
}
@ -1267,10 +1267,10 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
av_dlog ( c - > fc , " track[%i].stsc.entries = %i \n " , c - > fc - > nb_streams - 1 , entries ) ;
av_dlog ( c - > fc , " track[%i].stsc.entries = %i \n " , c - > fc - > nb_streams - 1 , entries ) ;
@ -1282,9 +1282,9 @@ static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc - > stsc_count = entries ;
sc - > stsc_count = entries ;
for ( i = 0 ; i < entries ; i + + ) {
for ( i = 0 ; i < entries ; i + + ) {
sc - > stsc_data [ i ] . first = get_be 32( pb ) ;
sc - > stsc_data [ i ] . first = avio_rb 32( pb ) ;
sc - > stsc_data [ i ] . count = get_be 32( pb ) ;
sc - > stsc_data [ i ] . count = avio_rb 32( pb ) ;
sc - > stsc_data [ i ] . id = get_be 32( pb ) ;
sc - > stsc_data [ i ] . id = avio_rb 32( pb ) ;
}
}
return 0 ;
return 0 ;
}
}
@ -1300,9 +1300,9 @@ static int mov_read_stps(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
get_be 32( pb ) ; // version + flags
avio_rb 32( pb ) ; // version + flags
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
if ( entries > = UINT_MAX / sizeof ( * sc - > stps_data ) )
if ( entries > = UINT_MAX / sizeof ( * sc - > stps_data ) )
return - 1 ;
return - 1 ;
sc - > stps_data = av_malloc ( entries * sizeof ( * sc - > stps_data ) ) ;
sc - > stps_data = av_malloc ( entries * sizeof ( * sc - > stps_data ) ) ;
@ -1311,7 +1311,7 @@ static int mov_read_stps(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc - > stps_count = entries ;
sc - > stps_count = entries ;
for ( i = 0 ; i < entries ; i + + ) {
for ( i = 0 ; i < entries ; i + + ) {
sc - > stps_data [ i ] = get_be 32( pb ) ;
sc - > stps_data [ i ] = avio_rb 32( pb ) ;
//av_dlog(c->fc, "stps %d\n", sc->stps_data[i]);
//av_dlog(c->fc, "stps %d\n", sc->stps_data[i]);
}
}
@ -1329,10 +1329,10 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
av_dlog ( c - > fc , " keyframe_count = %d \n " , entries ) ;
av_dlog ( c - > fc , " keyframe_count = %d \n " , entries ) ;
@ -1344,7 +1344,7 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc - > keyframe_count = entries ;
sc - > keyframe_count = entries ;
for ( i = 0 ; i < entries ; i + + ) {
for ( i = 0 ; i < entries ; i + + ) {
sc - > keyframes [ i ] = get_be 32( pb ) ;
sc - > keyframes [ i ] = avio_rb 32( pb ) ;
//av_dlog(c->fc, "keyframes[]=%d\n", sc->keyframes[i]);
//av_dlog(c->fc, "keyframes[]=%d\n", sc->keyframes[i]);
}
}
return 0 ;
return 0 ;
@ -1363,20 +1363,20 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
if ( atom . type = = MKTAG ( ' s ' , ' t ' , ' s ' , ' z ' ) ) {
if ( atom . type = = MKTAG ( ' s ' , ' t ' , ' s ' , ' z ' ) ) {
sample_size = get_be 32( pb ) ;
sample_size = avio_rb 32( pb ) ;
if ( ! sc - > sample_size ) /* do not overwrite value computed in stsd */
if ( ! sc - > sample_size ) /* do not overwrite value computed in stsd */
sc - > sample_size = sample_size ;
sc - > sample_size = sample_size ;
field_size = 32 ;
field_size = 32 ;
} else {
} else {
sample_size = 0 ;
sample_size = 0 ;
get_be 24( pb ) ; /* reserved */
avio_rb 24( pb ) ; /* reserved */
field_size = get_byte ( pb ) ;
field_size = avio_r8 ( pb ) ;
}
}
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
av_dlog ( c - > fc , " sample_size = %d sample_count = %d \n " , sc - > sample_size , entries ) ;
av_dlog ( c - > fc , " sample_size = %d sample_count = %d \n " , sc - > sample_size , entries ) ;
@ -1403,7 +1403,7 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
}
}
if ( get_buffer ( pb , buf , num_bytes ) < num_bytes ) {
if ( avio_read ( pb , buf , num_bytes ) < num_bytes ) {
av_freep ( & sc - > sample_sizes ) ;
av_freep ( & sc - > sample_sizes ) ;
av_free ( buf ) ;
av_free ( buf ) ;
return - 1 ;
return - 1 ;
@ -1431,9 +1431,9 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
av_dlog ( c - > fc , " track[%i].stts.entries = %i \n " , c - > fc - > nb_streams - 1 , entries ) ;
av_dlog ( c - > fc , " track[%i].stts.entries = %i \n " , c - > fc - > nb_streams - 1 , entries ) ;
@ -1448,8 +1448,8 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
int sample_duration ;
int sample_duration ;
int sample_count ;
int sample_count ;
sample_count = get_be 32( pb ) ;
sample_count = avio_rb 32( pb ) ;
sample_duration = get_be 32( pb ) ;
sample_duration = avio_rb 32( pb ) ;
sc - > stts_data [ i ] . count = sample_count ;
sc - > stts_data [ i ] . count = sample_count ;
sc - > stts_data [ i ] . duration = sample_duration ;
sc - > stts_data [ i ] . duration = sample_duration ;
@ -1476,9 +1476,9 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
av_dlog ( c - > fc , " track[%i].ctts.entries = %i \n " , c - > fc - > nb_streams - 1 , entries ) ;
av_dlog ( c - > fc , " track[%i].ctts.entries = %i \n " , c - > fc - > nb_streams - 1 , entries ) ;
@ -1490,8 +1490,8 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc - > ctts_count = entries ;
sc - > ctts_count = entries ;
for ( i = 0 ; i < entries ; i + + ) {
for ( i = 0 ; i < entries ; i + + ) {
int count = get_be 32( pb ) ;
int count = avio_rb 32( pb ) ;
int duration = get_be 32( pb ) ;
int duration = avio_rb 32( pb ) ;
sc - > ctts_data [ i ] . count = count ;
sc - > ctts_data [ i ] . count = count ;
sc - > ctts_data [ i ] . duration = duration ;
sc - > ctts_data [ i ] . duration = duration ;
@ -1837,7 +1837,7 @@ static int mov_read_ilst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
static int mov_read_meta ( MOVContext * c , AVIOContext * pb , MOVAtom atom )
static int mov_read_meta ( MOVContext * c , AVIOContext * pb , MOVAtom atom )
{
{
while ( atom . size > 8 ) {
while ( atom . size > 8 ) {
uint32_t tag = get_le 32( pb ) ;
uint32_t tag = avio_rl 32( pb ) ;
atom . size - = 4 ;
atom . size - = 4 ;
if ( tag = = MKTAG ( ' h ' , ' d ' , ' l ' , ' r ' ) ) {
if ( tag = = MKTAG ( ' h ' , ' d ' , ' l ' , ' r ' ) ) {
url_fseek ( pb , - 8 , SEEK_CUR ) ;
url_fseek ( pb , - 8 , SEEK_CUR ) ;
@ -1864,8 +1864,8 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
st = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] ;
sc = st - > priv_data ;
sc = st - > priv_data ;
version = get_byte ( pb ) ;
version = avio_r8 ( pb ) ;
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
/*
/*
MOV_TRACK_ENABLED 0x0001
MOV_TRACK_ENABLED 0x0001
MOV_TRACK_IN_MOVIE 0x0002
MOV_TRACK_IN_MOVIE 0x0002
@ -1874,36 +1874,36 @@ static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
*/
*/
if ( version = = 1 ) {
if ( version = = 1 ) {
get_be 64( pb ) ;
avio_rb 64( pb ) ;
get_be 64( pb ) ;
avio_rb 64( pb ) ;
} else {
} else {
get_be 32( pb ) ; /* creation time */
avio_rb 32( pb ) ; /* creation time */
get_be 32( pb ) ; /* modification time */
avio_rb 32( pb ) ; /* modification time */
}
}
st - > id = ( int ) get_be 32( pb ) ; /* track id (NOT 0 !)*/
st - > id = ( int ) avio_rb 32( pb ) ; /* track id (NOT 0 !)*/
get_be 32( pb ) ; /* reserved */
avio_rb 32( pb ) ; /* reserved */
/* highlevel (considering edits) duration in movie timebase */
/* highlevel (considering edits) duration in movie timebase */
( version = = 1 ) ? get_be 64( pb ) : get_be 32( pb ) ;
( version = = 1 ) ? avio_rb 64( pb ) : avio_rb 32( pb ) ;
get_be 32( pb ) ; /* reserved */
avio_rb 32( pb ) ; /* reserved */
get_be 32( pb ) ; /* reserved */
avio_rb 32( pb ) ; /* reserved */
get_be 16( pb ) ; /* layer */
avio_rb 16( pb ) ; /* layer */
get_be 16( pb ) ; /* alternate group */
avio_rb 16( pb ) ; /* alternate group */
get_be 16( pb ) ; /* volume */
avio_rb 16( pb ) ; /* volume */
get_be 16( pb ) ; /* reserved */
avio_rb 16( pb ) ; /* reserved */
//read in the display matrix (outlined in ISO 14496-12, Section 6.2.2)
//read in the display matrix (outlined in ISO 14496-12, Section 6.2.2)
// they're kept in fixed point format through all calculations
// they're kept in fixed point format through all calculations
// ignore u,v,z b/c we don't need the scale factor to calc aspect ratio
// ignore u,v,z b/c we don't need the scale factor to calc aspect ratio
for ( i = 0 ; i < 3 ; i + + ) {
for ( i = 0 ; i < 3 ; i + + ) {
display_matrix [ i ] [ 0 ] = get_be 32( pb ) ; // 16.16 fixed point
display_matrix [ i ] [ 0 ] = avio_rb 32( pb ) ; // 16.16 fixed point
display_matrix [ i ] [ 1 ] = get_be 32( pb ) ; // 16.16 fixed point
display_matrix [ i ] [ 1 ] = avio_rb 32( pb ) ; // 16.16 fixed point
get_be 32( pb ) ; // 2.30 fixed point (not used)
avio_rb 32( pb ) ; // 2.30 fixed point (not used)
}
}
width = get_be 32( pb ) ; // 16.16 fixed point track width
width = avio_rb 32( pb ) ; // 16.16 fixed point track width
height = get_be 32( pb ) ; // 16.16 fixed point track height
height = avio_rb 32( pb ) ; // 16.16 fixed point track height
sc - > width = width > > 16 ;
sc - > width = width > > 16 ;
sc - > height = height > > 16 ;
sc - > height = height > > 16 ;
@ -1937,10 +1937,10 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
MOVTrackExt * trex = NULL ;
MOVTrackExt * trex = NULL ;
int flags , track_id , i ;
int flags , track_id , i ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
flags = get_be 24( pb ) ;
flags = avio_rb 24( pb ) ;
track_id = get_be 32( pb ) ;
track_id = avio_rb 32( pb ) ;
if ( ! track_id )
if ( ! track_id )
return - 1 ;
return - 1 ;
frag - > track_id = track_id ;
frag - > track_id = track_id ;
@ -1954,21 +1954,21 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return - 1 ;
return - 1 ;
}
}
if ( flags & 0x01 ) frag - > base_data_offset = get_be 64( pb ) ;
if ( flags & 0x01 ) frag - > base_data_offset = avio_rb 64( pb ) ;
else frag - > base_data_offset = frag - > moof_offset ;
else frag - > base_data_offset = frag - > moof_offset ;
if ( flags & 0x02 ) frag - > stsd_id = get_be 32( pb ) ;
if ( flags & 0x02 ) frag - > stsd_id = avio_rb 32( pb ) ;
else frag - > stsd_id = trex - > stsd_id ;
else frag - > stsd_id = trex - > stsd_id ;
frag - > duration = flags & 0x08 ? get_be 32( pb ) : trex - > duration ;
frag - > duration = flags & 0x08 ? avio_rb 32( pb ) : trex - > duration ;
frag - > size = flags & 0x10 ? get_be 32( pb ) : trex - > size ;
frag - > size = flags & 0x10 ? avio_rb 32( pb ) : trex - > size ;
frag - > flags = flags & 0x20 ? get_be 32( pb ) : trex - > flags ;
frag - > flags = flags & 0x20 ? avio_rb 32( pb ) : trex - > flags ;
av_dlog ( c - > fc , " frag flags 0x%x \n " , frag - > flags ) ;
av_dlog ( c - > fc , " frag flags 0x%x \n " , frag - > flags ) ;
return 0 ;
return 0 ;
}
}
static int mov_read_chap ( MOVContext * c , AVIOContext * pb , MOVAtom atom )
static int mov_read_chap ( MOVContext * c , AVIOContext * pb , MOVAtom atom )
{
{
c - > chapter_track = get_be 32( pb ) ;
c - > chapter_track = avio_rb 32( pb ) ;
return 0 ;
return 0 ;
}
}
@ -1983,13 +1983,13 @@ static int mov_read_trex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
c - > trex_data = trex ;
c - > trex_data = trex ;
trex = & c - > trex_data [ c - > trex_count + + ] ;
trex = & c - > trex_data [ c - > trex_count + + ] ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
trex - > track_id = get_be 32( pb ) ;
trex - > track_id = avio_rb 32( pb ) ;
trex - > stsd_id = get_be 32( pb ) ;
trex - > stsd_id = avio_rb 32( pb ) ;
trex - > duration = get_be 32( pb ) ;
trex - > duration = avio_rb 32( pb ) ;
trex - > size = get_be 32( pb ) ;
trex - > size = avio_rb 32( pb ) ;
trex - > flags = get_be 32( pb ) ;
trex - > flags = avio_rb 32( pb ) ;
return 0 ;
return 0 ;
}
}
@ -2017,12 +2017,12 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sc = st - > priv_data ;
sc = st - > priv_data ;
if ( sc - > pseudo_stream_id + 1 ! = frag - > stsd_id )
if ( sc - > pseudo_stream_id + 1 ! = frag - > stsd_id )
return 0 ;
return 0 ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
flags = get_be 24( pb ) ;
flags = avio_rb 24( pb ) ;
entries = get_be 32( pb ) ;
entries = avio_rb 32( pb ) ;
av_dlog ( c - > fc , " flags 0x%x entries %d \n " , flags , entries ) ;
av_dlog ( c - > fc , " flags 0x%x entries %d \n " , flags , entries ) ;
if ( flags & 0x001 ) data_offset = get_be 32( pb ) ;
if ( flags & 0x001 ) data_offset = avio_rb 32( pb ) ;
if ( flags & 0x004 ) first_sample_flags = get_be 32( pb ) ;
if ( flags & 0x004 ) first_sample_flags = avio_rb 32( pb ) ;
if ( flags & 0x800 ) {
if ( flags & 0x800 ) {
MOVStts * ctts_data ;
MOVStts * ctts_data ;
if ( ( uint64_t ) entries + sc - > ctts_count > = UINT_MAX / sizeof ( * sc - > ctts_data ) )
if ( ( uint64_t ) entries + sc - > ctts_count > = UINT_MAX / sizeof ( * sc - > ctts_data ) )
@ -2043,12 +2043,12 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
unsigned sample_duration = frag - > duration ;
unsigned sample_duration = frag - > duration ;
int keyframe ;
int keyframe ;
if ( flags & 0x100 ) sample_duration = get_be 32( pb ) ;
if ( flags & 0x100 ) sample_duration = avio_rb 32( pb ) ;
if ( flags & 0x200 ) sample_size = get_be 32( pb ) ;
if ( flags & 0x200 ) sample_size = avio_rb 32( pb ) ;
if ( flags & 0x400 ) sample_flags = get_be 32( pb ) ;
if ( flags & 0x400 ) sample_flags = avio_rb 32( pb ) ;
if ( flags & 0x800 ) {
if ( flags & 0x800 ) {
sc - > ctts_data [ sc - > ctts_count ] . count = 1 ;
sc - > ctts_data [ sc - > ctts_count ] . count = 1 ;
sc - > ctts_data [ sc - > ctts_count ] . duration = get_be 32( pb ) ;
sc - > ctts_data [ sc - > ctts_count ] . duration = avio_rb 32( pb ) ;
sc - > ctts_count + + ;
sc - > ctts_count + + ;
}
}
if ( ( keyframe = st - > codec - > codec_type = = AVMEDIA_TYPE_AUDIO | |
if ( ( keyframe = st - > codec - > codec_type = = AVMEDIA_TYPE_AUDIO | |
@ -2077,11 +2077,11 @@ static int mov_read_wide(MOVContext *c, AVIOContext *pb, MOVAtom atom)
if ( atom . size < 8 )
if ( atom . size < 8 )
return 0 ; /* continue */
return 0 ; /* continue */
if ( get_be 32( pb ) ! = 0 ) { /* 0 sized mdat atom... use the 'wide' atom size */
if ( avio_rb 32( pb ) ! = 0 ) { /* 0 sized mdat atom... use the 'wide' atom size */
url_fskip ( pb , atom . size - 4 ) ;
url_fskip ( pb , atom . size - 4 ) ;
return 0 ;
return 0 ;
}
}
atom . type = get_le 32( pb ) ;
atom . type = avio_rl 32( pb ) ;
atom . size - = 8 ;
atom . size - = 8 ;
if ( atom . type ! = MKTAG ( ' m ' , ' d ' , ' a ' , ' t ' ) ) {
if ( atom . type ! = MKTAG ( ' m ' , ' d ' , ' a ' , ' t ' ) ) {
url_fskip ( pb , atom . size ) ;
url_fskip ( pb , atom . size ) ;
@ -2100,17 +2100,17 @@ static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
long cmov_len , moov_len ;
long cmov_len , moov_len ;
int ret = - 1 ;
int ret = - 1 ;
get_be 32( pb ) ; /* dcom atom */
avio_rb 32( pb ) ; /* dcom atom */
if ( get_le 32( pb ) ! = MKTAG ( ' d ' , ' c ' , ' o ' , ' m ' ) )
if ( avio_rl 32( pb ) ! = MKTAG ( ' d ' , ' c ' , ' o ' , ' m ' ) )
return - 1 ;
return - 1 ;
if ( get_le 32( pb ) ! = MKTAG ( ' z ' , ' l ' , ' i ' , ' b ' ) ) {
if ( avio_rl 32( pb ) ! = MKTAG ( ' z ' , ' l ' , ' i ' , ' b ' ) ) {
av_log ( c - > fc , AV_LOG_ERROR , " unknown compression for cmov atom ! " ) ;
av_log ( c - > fc , AV_LOG_ERROR , " unknown compression for cmov atom ! " ) ;
return - 1 ;
return - 1 ;
}
}
get_be 32( pb ) ; /* cmvd atom */
avio_rb 32( pb ) ; /* cmvd atom */
if ( get_le 32( pb ) ! = MKTAG ( ' c ' , ' m ' , ' v ' , ' d ' ) )
if ( avio_rl 32( pb ) ! = MKTAG ( ' c ' , ' m ' , ' v ' , ' d ' ) )
return - 1 ;
return - 1 ;
moov_len = get_be 32( pb ) ; /* uncompressed size */
moov_len = avio_rb 32( pb ) ; /* uncompressed size */
cmov_len = atom . size - 6 * 4 ;
cmov_len = atom . size - 6 * 4 ;
cmov_data = av_malloc ( cmov_len ) ;
cmov_data = av_malloc ( cmov_len ) ;
@ -2121,7 +2121,7 @@ static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_free ( cmov_data ) ;
av_free ( cmov_data ) ;
return AVERROR ( ENOMEM ) ;
return AVERROR ( ENOMEM ) ;
}
}
get_buffer ( pb , cmov_data , cmov_len ) ;
avio_read ( pb , cmov_data , cmov_len ) ;
if ( uncompress ( moov_data , ( uLongf * ) & moov_len , ( const Bytef * ) cmov_data , cmov_len ) ! = Z_OK )
if ( uncompress ( moov_data , ( uLongf * ) & moov_len , ( const Bytef * ) cmov_data , cmov_len ) ! = Z_OK )
goto free_and_return ;
goto free_and_return ;
if ( ffio_init_context ( & ctx , moov_data , moov_len , 0 , NULL , NULL , NULL , NULL ) ! = 0 )
if ( ffio_init_context ( & ctx , moov_data , moov_len , 0 , NULL , NULL , NULL , NULL ) ! = 0 )
@ -2152,18 +2152,18 @@ static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
return 0 ;
return 0 ;
sc = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] - > priv_data ;
sc = c - > fc - > streams [ c - > fc - > nb_streams - 1 ] - > priv_data ;
get_byte ( pb ) ; /* version */
avio_r8 ( pb ) ; /* version */
get_be 24( pb ) ; /* flags */
avio_rb 24( pb ) ; /* flags */
edit_count = get_be 32( pb ) ; /* entries */
edit_count = avio_rb 32( pb ) ; /* entries */
if ( ( uint64_t ) edit_count * 12 + 8 > atom . size )
if ( ( uint64_t ) edit_count * 12 + 8 > atom . size )
return - 1 ;
return - 1 ;
for ( i = 0 ; i < edit_count ; i + + ) {
for ( i = 0 ; i < edit_count ; i + + ) {
int time ;
int time ;
int duration = get_be 32( pb ) ; /* Track duration */
int duration = avio_rb 32( pb ) ; /* Track duration */
time = get_be 32( pb ) ; /* Media time */
time = avio_rb 32( pb ) ; /* Media time */
get_be 32( pb ) ; /* Media rate */
avio_rb 32( pb ) ; /* Media rate */
if ( i = = 0 & & time > = - 1 ) {
if ( i = = 0 & & time > = - 1 ) {
sc - > time_offset = time ! = - 1 ? time : - duration ;
sc - > time_offset = time ! = - 1 ? time : - duration ;
}
}
@ -2314,7 +2314,7 @@ static void mov_read_chapters(AVFormatContext *s)
}
}
// the first two bytes are the length of the title
// the first two bytes are the length of the title
len = get_be 16( sc - > pb ) ;
len = avio_rb 16( sc - > pb ) ;
if ( len > sample - > size - 2 )
if ( len > sample - > size - 2 )
continue ;
continue ;
title_len = 2 * len + 1 ;
title_len = 2 * len + 1 ;
@ -2324,7 +2324,7 @@ static void mov_read_chapters(AVFormatContext *s)
// The samples could theoretically be in any encoding if there's an encd
// The samples could theoretically be in any encoding if there's an encd
// atom following, but in practice are only utf-8 or utf-16, distinguished
// atom following, but in practice are only utf-8 or utf-16, distinguished
// instead by the presence of a BOM
// instead by the presence of a BOM
ch = get_be 16( sc - > pb ) ;
ch = avio_rb 16( sc - > pb ) ;
if ( ch = = 0xfeff )
if ( ch = = 0xfeff )
avio_get_str16be ( sc - > pb , len , title , title_len ) ;
avio_get_str16be ( sc - > pb , len , title , title_len ) ;
else if ( ch = = 0xfffe )
else if ( ch = = 0xfffe )