* libmp4.c : LibMP4 library for mp4 module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: libmp4.c,v 1.13 2003/01/25 16:58:34 fenrir Exp $
+ * $Id: libmp4.c,v 1.14 2003/02/07 01:22:55 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
static void GetUUID( UUID_t *p_uuid, uint8_t *p_buff )
{
- memcpy( p_uuid,
+ memcpy( p_uuid,
p_buff,
16 );
}
static void CreateUUID( UUID_t *p_uuid, uint32_t i_fourcc )
{
- /* made by 0xXXXXXXXX-0011-0010-8000-00aa00389b71
+ /* made by 0xXXXXXXXX-0011-0010-8000-00aa00389b71
where XXXXXXXX is the fourcc */
/* FIXME implement this */
}
/****************************************************************************
* MP4_MemoryStream create a memory stream
- * if p_buffer == NULL, will allocate a buffer of i_size, else
+ * if p_buffer == NULL, will allocate a buffer of i_size, else
* it uses p_buffer XXX you have to unallocate it yourself !
*
****************************************************************************/
{
return( 0 );
}
- memcpy( p_buff,
+ memcpy( p_buff,
p_stream->p_buffer + p_stream->i_start,
i_size );
p_stream->i_start += i_size;
/* FIXME how to write uint64_t ??? */
if( p_box->i_size )
{
- msg_Dbg( p_stream->p_input, "Found Box: %c%c%c%c size %d",
- (p_box->i_type)&0xff, (p_box->i_type>>8)&0xff,
- (p_box->i_type>>16)&0xff, (p_box->i_type>>24)&0xff,
+ msg_Dbg( p_stream->p_input, "Found Box: %4.4s size %d",
+ (char*)&p_box->i_type,
(uint32_t)p_box->i_size );
}
#endif
- return( 1 );
+ return( 1 );
}
/*****************************************************************************
- * MP4_MP4_NextBox : Go to the next box
+ * MP4_MP4_NextBox : Go to the next box
*****************************************************************************
* if p_box == NULL, go to the next box in witch we are( at the begining ).
*****************************************************************************/
if( p_box->p_father )
{
/* check if it's within p-father */
- if( p_box->i_size + p_box->i_pos >=
+ if( p_box->i_size + p_box->i_pos >=
p_box->p_father->i_size + p_box->p_father->i_pos )
{
return( 0 ); /* out of bound */
{
MP4_Box_t *p_box;
- if( MP4_TellStream( p_stream ) + 8 >
+ if( MP4_TellStream( p_stream ) + 8 >
(off_t)(p_container->i_pos + p_container->i_size) )
{
/* there is no box to load */
{
/* Nothing to do */
#ifdef MP4_VERBOSE
- msg_Dbg( p_stream->p_input, "Skip box: \"%c%c%c%c\"",
- (p_box->i_type)&0xff,
- (p_box->i_type>>8)&0xff,
- (p_box->i_type>>16)&0xff,
- (p_box->i_type>>24)&0xff );
+ msg_Dbg( p_stream->p_input, "Skip box: \"%4.4s\"",
+ (char*)&p_box->i_type );
#endif
return( 1 );
}
MP4_GET4BYTES( p_box->data.p_mvhd->i_timescale );
MP4_GET4BYTES( p_box->data.p_mvhd->i_duration );
}
- MP4_GET4BYTES( p_box->data.p_mvhd->i_rate );
- MP4_GET2BYTES( p_box->data.p_mvhd->i_volume );
+ MP4_GET4BYTES( p_box->data.p_mvhd->i_rate );
+ MP4_GET2BYTES( p_box->data.p_mvhd->i_volume );
MP4_GET2BYTES( p_box->data.p_mvhd->i_reserved1 );
-
+
for( i = 0; i < 2; i++ )
{
MP4_GET4BYTES( p_box->data.p_mvhd->i_reserved2[i] );
{
MP4_GET4BYTES( p_box->data.p_mvhd->i_predefined[i] );
}
-
+
MP4_GET4BYTES( p_box->data.p_mvhd->i_next_track_id );
-
-
+
+
#ifdef MP4_VERBOSE
MP4_ConvertDate2Str( s_creation_time, p_box->data.p_mvhd->i_creation_time );
- MP4_ConvertDate2Str( s_modification_time,
+ MP4_ConvertDate2Str( s_modification_time,
p_box->data.p_mvhd->i_modification_time );
if( p_box->data.p_mvhd->i_rate )
{
- MP4_ConvertDate2Str( s_duration,
+ MP4_ConvertDate2Str( s_duration,
p_box->data.p_mvhd->i_duration / p_box->data.p_mvhd->i_rate );
}
else
{
s_duration[0] = 0;
- }
+ }
msg_Dbg( p_stream->p_input, "Read Box: \"mvhd\" creation %s modification %s time scale %d duration %s rate %f volume %f next track id %d",
s_creation_time,
s_modification_time,
char s_duration[128];
#endif
MP4_READBOX_ENTER( MP4_Box_data_tkhd_t );
-
+
MP4_GETVERSIONFLAGS( p_box->data.p_tkhd );
if( p_box->data.p_tkhd->i_version )
MP4_GET4BYTES( p_box->data.p_tkhd->i_reserved );
MP4_GET4BYTES( p_box->data.p_tkhd->i_duration );
}
-
+
for( i = 0; i < 2; i++ )
{
MP4_GET4BYTES( p_box->data.p_tkhd->i_reserved2[i] );
}
MP4_GET4BYTES( p_box->data.p_tkhd->i_width );
MP4_GET4BYTES( p_box->data.p_tkhd->i_height );
-
+
#ifdef MP4_VERBOSE
MP4_ConvertDate2Str( s_creation_time, p_box->data.p_mvhd->i_creation_time );
MP4_ConvertDate2Str( s_modification_time, p_box->data.p_mvhd->i_modification_time );
MP4_ConvertDate2Str( s_duration, p_box->data.p_mvhd->i_duration );
-
+
msg_Dbg( p_stream->p_input, "Read Box: \"tkhd\" creation %s modification %s duration %s track ID %d layer %d volume %f width %f height %f",
s_creation_time,
s_modification_time,
/* container is empty, 8 stand for the first header in this box */
return( 1 );
}
-
+
if( !MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) ) )
{
return( 0 );
MP4_GET4BYTES( p_box->data.p_mdhd->i_timescale );
MP4_GET4BYTES( p_box->data.p_mdhd->i_duration );
}
- i_language = GetWBE( p_peek );
+ i_language = GetWBE( p_peek );
for( i = 0; i < 3; i++ )
{
- p_box->data.p_mdhd->i_language[i] =
+ p_box->data.p_mdhd->i_language[i] =
( ( i_language >> ( (2-i)*5 ) )&0x1f ) + 0x60;
}
MP4_GET2BYTES( p_box->data.p_mdhd->i_predefined );
-
+
#ifdef MP4_VERBOSE
MP4_ConvertDate2Str( s_creation_time, p_box->data.p_mdhd->i_creation_time );
MP4_ConvertDate2Str( s_modification_time, p_box->data.p_mdhd->i_modification_time );
int MP4_ReadBox_hdlr( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
- MP4_READBOX_ENTER( MP4_Box_data_hdlr_t );
+ MP4_READBOX_ENTER( MP4_Box_data_hdlr_t );
MP4_GETVERSIONFLAGS( p_box->data.p_hdlr );
-
+
MP4_GET4BYTES( p_box->data.p_hdlr->i_predefined );
MP4_GETFOURCC( p_box->data.p_hdlr->i_handler_type );
memcpy( p_box->data.p_hdlr->psz_name, p_peek, i_read );
#ifdef MP4_VERBOSE
- msg_Dbg( p_stream->p_input, "Read Box: \"hdlr\" hanler type %c%c%c%c name %s",
- ( p_box->data.p_hdlr->i_handler_type )&0xff,
- ( p_box->data.p_hdlr->i_handler_type >> 8 )&0xff,
- ( p_box->data.p_hdlr->i_handler_type >> 16 )&0xff,
- ( p_box->data.p_hdlr->i_handler_type >> 24 )&0xff,
+ msg_Dbg( p_stream->p_input, "Read Box: \"hdlr\" hanler type %4.4s name %s",
+ (char*)&p_box->data.p_hdlr->i_handler_type,
p_box->data.p_hdlr->psz_name );
#endif
int MP4_ReadBox_vmhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
-
- MP4_READBOX_ENTER( MP4_Box_data_vmhd_t );
+
+ MP4_READBOX_ENTER( MP4_Box_data_vmhd_t );
MP4_GETVERSIONFLAGS( p_box->data.p_vmhd );
-
+
MP4_GET2BYTES( p_box->data.p_vmhd->i_graphics_mode );
for( i = 0; i < 3; i++ )
{
MP4_GET2BYTES( p_box->data.p_vmhd->i_opcolor[i] );
}
-
+
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"vmhd\" graphics-mode %d opcolor (%d, %d, %d)",
p_box->data.p_vmhd->i_graphics_mode,
p_box->data.p_vmhd->i_opcolor[0],
p_box->data.p_vmhd->i_opcolor[1],
p_box->data.p_vmhd->i_opcolor[2] );
-
#endif
MP4_READBOX_EXIT( 1 );
}
int MP4_ReadBox_smhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
- MP4_READBOX_ENTER( MP4_Box_data_smhd_t );
+ MP4_READBOX_ENTER( MP4_Box_data_smhd_t );
MP4_GETVERSIONFLAGS( p_box->data.p_smhd );
MP4_GET2BYTES( p_box->data.p_smhd->i_balance );
MP4_GET2BYTES( p_box->data.p_smhd->i_reserved );
-
+
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"smhd\" balance %f",
(float)p_box->data.p_smhd->i_balance / 256 );
-
#endif
MP4_READBOX_EXIT( 1 );
}
int MP4_ReadBox_hmhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
- MP4_READBOX_ENTER( MP4_Box_data_hmhd_t );
+ MP4_READBOX_ENTER( MP4_Box_data_hmhd_t );
MP4_GETVERSIONFLAGS( p_box->data.p_hmhd );
p_box->data.p_hmhd->i_avg_PDU_size,
p_box->data.p_hmhd->i_max_bitrate,
p_box->data.p_hmhd->i_avg_bitrate );
-
#endif
MP4_READBOX_EXIT( 1 );
}
int MP4_ReadBox_url( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
- MP4_READBOX_ENTER( MP4_Box_data_url_t );
+ MP4_READBOX_ENTER( MP4_Box_data_url_t );
MP4_GETVERSIONFLAGS( p_box->data.p_url );
MP4_GETSTRINGZ( p_box->data.p_url->psz_location );
MP4_GETVERSIONFLAGS( p_box->data.p_urn );
MP4_GETSTRINGZ( p_box->data.p_urn->psz_name );
- MP4_GETSTRINGZ( p_box->data.p_urn->psz_location );
-
+ MP4_GETSTRINGZ( p_box->data.p_urn->psz_location );
+
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"urn\" name %s location %s",
p_box->data.p_urn->psz_name,
int MP4_ReadBox_dref( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_READBOX_ENTER( MP4_Box_data_dref_t );
-
+
MP4_GETVERSIONFLAGS( p_box->data.p_dref );
MP4_GET4BYTES( p_box->data.p_dref->i_entry_count );
-
+
MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 8 );
MP4_ReadBoxContainerRaw( p_stream, p_box );
int MP4_ReadBox_stts( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
- MP4_READBOX_ENTER( MP4_Box_data_stts_t );
+ MP4_READBOX_ENTER( MP4_Box_data_stts_t );
MP4_GETVERSIONFLAGS( p_box->data.p_stts );
MP4_GET4BYTES( p_box->data.p_stts->i_entry_count );
- p_box->data.p_stts->i_sample_count =
+ p_box->data.p_stts->i_sample_count =
calloc( sizeof( uint32_t ), p_box->data.p_stts->i_entry_count );
p_box->data.p_stts->i_sample_delta =
calloc( sizeof( uint32_t ), p_box->data.p_stts->i_entry_count );
-
+
for( i = 0; (i < p_box->data.p_stts->i_entry_count )&&( i_read >=8 ); i++ )
{
MP4_GET4BYTES( p_box->data.p_stts->i_sample_count[i] );
MP4_GET4BYTES( p_box->data.p_stts->i_sample_delta[i] );
}
-
-
+
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"stts\" entry-count %d",
p_box->data.p_stts->i_entry_count );
{
FREE( p_box->data.p_stts->i_sample_count );
FREE( p_box->data.p_stts->i_sample_delta );
-
}
int MP4_ReadBox_ctts( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
MP4_READBOX_ENTER( MP4_Box_data_ctts_t );
-
+
MP4_GETVERSIONFLAGS( p_box->data.p_ctts );
-
+
MP4_GET4BYTES( p_box->data.p_ctts->i_entry_count );
- p_box->data.p_ctts->i_sample_count =
+ p_box->data.p_ctts->i_sample_count =
calloc( sizeof( uint32_t ), p_box->data.p_ctts->i_entry_count );
p_box->data.p_ctts->i_sample_offset =
calloc( sizeof( uint32_t ), p_box->data.p_ctts->i_entry_count );
-
+
for( i = 0; (i < p_box->data.p_ctts->i_entry_count )&&( i_read >=8 ); i++ )
{
MP4_GET4BYTES( p_box->data.p_ctts->i_sample_count[i] );
MP4_GET4BYTES( p_box->data.p_ctts->i_sample_offset[i] );
}
-
-
+
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"ctts\" entry-count %d",
p_box->data.p_ctts->i_entry_count );
(*i_read)--;
i_len = ( i_len << 7 ) + ( i_b&0x7f );
} while( i_b&0x80 );
- return( i_len );
+ return( i_len );
}
int MP4_ReadBox_esds( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
if( es_descriptor.b_url )
{
unsigned int i_len;
-
+
MP4_GET1BYTE( i_len );
es_descriptor.psz_URL = calloc( sizeof(char), i_len + 1 );
memcpy( es_descriptor.psz_URL, p_peek, i_len );
}
i_len = MP4_ReadLengthDescriptor( &p_peek, &i_read );
- es_descriptor.p_decConfigDescr =
+ es_descriptor.p_decConfigDescr =
malloc( sizeof( MP4_descriptor_decoder_config_t ));
MP4_GET1BYTE( es_descriptor.p_decConfigDescr->i_objectTypeIndication );
i_len = MP4_ReadLengthDescriptor( &p_peek, &i_read );
es_descriptor.p_decConfigDescr->i_decoder_specific_info_len = i_len;
es_descriptor.p_decConfigDescr->p_decoder_specific_info = malloc( i_len );
- memcpy( es_descriptor.p_decConfigDescr->p_decoder_specific_info,
+ memcpy( es_descriptor.p_decConfigDescr->p_decoder_specific_info,
p_peek, i_len );
MP4_READBOX_EXIT( 1 );
msg_Dbg( p_stream->p_input, "Read Box: \"soun\" in stsd channel %d sample size %d sampl rate %f",
p_box->data.p_sample_soun->i_channelcount,
p_box->data.p_sample_soun->i_samplesize,
- (float)p_box->data.p_sample_soun->i_sampleratehi +
+ (float)p_box->data.p_sample_soun->i_sampleratehi +
(float)p_box->data.p_sample_soun->i_sampleratelo / 65536 );
#endif
#if 0
int MP4_ReadBox_sample_mp4a( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
- unsigned int i;
+ unsigned int i;
MP4_READBOX_ENTER( MP4_Box_data_sample_mp4a_t );
MP4_GET2BYTES( p_box->data.p_sample_mp4a->i_reserved3 );
MP4_GET2BYTES( p_box->data.p_sample_mp4a->i_sampleratehi );
MP4_GET2BYTES( p_box->data.p_sample_mp4a->i_sampleratelo );
-
+
MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 28 );
MP4_ReadBoxContainerRaw( p_stream, p_box ); /* esds */
msg_Dbg( p_stream->p_input, "Read Box: \"mp4a\" in stsd channel %d sample size %d sampl rate %f",
p_box->data.p_sample_mp4a->i_channelcount,
p_box->data.p_sample_mp4a->i_samplesize,
- (float)p_box->data.p_sample_mp4a->i_sampleratehi +
+ (float)p_box->data.p_sample_mp4a->i_sampleratehi +
(float)p_box->data.p_sample_mp4a->i_sampleratelo / 65536 );
#endif
int MP4_ReadBox_sample_vide( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
- unsigned int i;
+ unsigned int i;
MP4_READBOX_ENTER( MP4_Box_data_sample_vide_t );
MP4_GET2BYTES( p_box->data.p_sample_vide->i_width );
MP4_GET2BYTES( p_box->data.p_sample_vide->i_height );
-
+
MP4_GET4BYTES( p_box->data.p_sample_vide->i_horizresolution );
MP4_GET4BYTES( p_box->data.p_sample_vide->i_vertresolution );
MP4_GET2BYTES( p_box->data.p_sample_vide->i_depth );
MP4_GET2BYTES( p_box->data.p_sample_vide->i_predefined4 );
-
+
MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 78);
MP4_ReadBoxContainerRaw( p_stream, p_box );
-
+
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"vide\" in stsd %dx%d depth %d",
p_box->data.p_sample_vide->i_width,
MP4_GET4BYTES( p_box->data.p_stsd->i_entry_count );
- MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 8 );
+ MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 8 );
MP4_ReadBoxContainerRaw( p_stream, p_box );
unsigned int i;
MP4_READBOX_ENTER( MP4_Box_data_stsz_t );
-
+
MP4_GETVERSIONFLAGS( p_box->data.p_stsz );
-
+
MP4_GET4BYTES( p_box->data.p_stsz->i_sample_size );
MP4_GET4BYTES( p_box->data.p_stsz->i_sample_count );
- p_box->data.p_stsz->i_entry_size =
+ p_box->data.p_stsz->i_entry_size =
calloc( sizeof( uint32_t ), p_box->data.p_stsz->i_sample_count );
-
+
if( !p_box->data.p_stsz->i_sample_size )
{
for( i=0; (i<p_box->data.p_stsz->i_sample_count)&&(i_read >= 4 ); i++ )
MP4_GET4BYTES( p_box->data.p_stsz->i_entry_size[i] );
}
}
-
-
-#ifdef MP4_VERBOSE
+
+#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"stsz\" sample-size %d sample-count %d",
p_box->data.p_stsz->i_sample_size,
p_box->data.p_stsz->i_sample_count );
int MP4_ReadBox_stsc( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
-
+
MP4_READBOX_ENTER( MP4_Box_data_stsc_t );
MP4_GETVERSIONFLAGS( p_box->data.p_stsc );
-
+
MP4_GET4BYTES( p_box->data.p_stsc->i_entry_count );
- p_box->data.p_stsc->i_first_chunk =
+ p_box->data.p_stsc->i_first_chunk =
calloc( sizeof( uint32_t ), p_box->data.p_stsc->i_entry_count );
- p_box->data.p_stsc->i_samples_per_chunk =
+ p_box->data.p_stsc->i_samples_per_chunk =
calloc( sizeof( uint32_t ), p_box->data.p_stsc->i_entry_count );
- p_box->data.p_stsc->i_sample_description_index =
+ p_box->data.p_stsc->i_sample_description_index =
calloc( sizeof( uint32_t ), p_box->data.p_stsc->i_entry_count );
for( i = 0; (i < p_box->data.p_stsc->i_entry_count )&&( i_read >= 12 );i++ )
MP4_GET4BYTES( p_box->data.p_stsc->i_samples_per_chunk[i] );
MP4_GET4BYTES( p_box->data.p_stsc->i_sample_description_index[i] );
}
-
-
-#ifdef MP4_VERBOSE
+
+#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"stsc\" entry-count %d",
p_box->data.p_stsc->i_entry_count );
int MP4_ReadBox_stco_co64( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
-
+
MP4_READBOX_ENTER( MP4_Box_data_co64_t );
MP4_GETVERSIONFLAGS( p_box->data.p_co64 );
MP4_GET4BYTES( p_box->data.p_co64->i_entry_count );
- p_box->data.p_co64->i_chunk_offset =
+ p_box->data.p_co64->i_chunk_offset =
calloc( sizeof( uint64_t ), p_box->data.p_co64->i_entry_count );
for( i = 0; i < p_box->data.p_co64->i_entry_count; i++ )
MP4_GET8BYTES( p_box->data.p_co64->i_chunk_offset[i] );
}
}
-
-
-#ifdef MP4_VERBOSE
+
+#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"co64\" entry-count %d",
p_box->data.p_co64->i_entry_count );
int MP4_ReadBox_stss( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
-
- MP4_READBOX_ENTER( MP4_Box_data_stss_t );
+
+ MP4_READBOX_ENTER( MP4_Box_data_stss_t );
MP4_GETVERSIONFLAGS( p_box->data.p_stss );
MP4_GET4BYTES( p_box->data.p_stss->i_entry_count );
- p_box->data.p_stss->i_sample_number =
+ p_box->data.p_stss->i_sample_number =
calloc( sizeof( uint32_t ), p_box->data.p_stss->i_entry_count );
for( i = 0; (i < p_box->data.p_stss->i_entry_count )&&( i_read >= 4 ); i++ )
/* XXX in libmp4 sample begin at 0 */
p_box->data.p_stss->i_sample_number[i]--;
}
-
-
-#ifdef MP4_VERBOSE
+
+#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"stss\" entry-count %d",
p_box->data.p_stss->i_entry_count );
int MP4_ReadBox_stsh( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
-
+
MP4_READBOX_ENTER( MP4_Box_data_stsh_t );
MP4_GETVERSIONFLAGS( p_box->data.p_stsh );
MP4_GET4BYTES( p_box->data.p_stsh->i_entry_count );
- p_box->data.p_stsh->i_shadowed_sample_number =
+ p_box->data.p_stsh->i_shadowed_sample_number =
calloc( sizeof( uint32_t ), p_box->data.p_stsh->i_entry_count );
- p_box->data.p_stsh->i_sync_sample_number =
+ p_box->data.p_stsh->i_sync_sample_number =
calloc( sizeof( uint32_t ), p_box->data.p_stsh->i_entry_count );
MP4_GET4BYTES( p_box->data.p_stsh->i_shadowed_sample_number[i] );
MP4_GET4BYTES( p_box->data.p_stsh->i_sync_sample_number[i] );
}
-
-
-#ifdef MP4_VERBOSE
+
+#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"stsh\" entry-count %d",
p_box->data.p_stsh->i_entry_count );
#endif
int MP4_ReadBox_stdp( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
-
- MP4_READBOX_ENTER( MP4_Box_data_stdp_t );
+
+ MP4_READBOX_ENTER( MP4_Box_data_stdp_t );
MP4_GETVERSIONFLAGS( p_box->data.p_stdp );
- p_box->data.p_stdp->i_priority =
+ p_box->data.p_stdp->i_priority =
calloc( sizeof( uint16_t ), i_read / 2 );
for( i = 0; i < i_read / 2 ; i++ )
MP4_GET2BYTES( p_box->data.p_stdp->i_priority[i] );
}
-
-
-#ifdef MP4_VERBOSE
+
+#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"stdp\" entry-count "I64Fd,
i_read / 2 );
int MP4_ReadBox_padb( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
-
+
MP4_READBOX_ENTER( MP4_Box_data_padb_t );
MP4_GETVERSIONFLAGS( p_box->data.p_padb );
MP4_GET4BYTES( p_box->data.p_padb->i_sample_count );
- p_box->data.p_padb->i_reserved1 =
+ p_box->data.p_padb->i_reserved1 =
calloc( sizeof( uint16_t ), ( p_box->data.p_padb->i_sample_count + 1 ) / 2 );
- p_box->data.p_padb->i_pad2 =
+ p_box->data.p_padb->i_pad2 =
calloc( sizeof( uint16_t ), ( p_box->data.p_padb->i_sample_count + 1 ) / 2 );
- p_box->data.p_padb->i_reserved2 =
+ p_box->data.p_padb->i_reserved2 =
calloc( sizeof( uint16_t ), ( p_box->data.p_padb->i_sample_count + 1 ) / 2 );
- p_box->data.p_padb->i_pad1 =
+ p_box->data.p_padb->i_pad1 =
calloc( sizeof( uint16_t ), ( p_box->data.p_padb->i_sample_count + 1 ) / 2 );
p_peek += 1; i_read -= 1;
}
-
-
-#ifdef MP4_VERBOSE
+
+#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"stdp\" entry-count "I64Fd,
i_read / 2 );
int MP4_ReadBox_elst( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
unsigned int i;
-
+
MP4_READBOX_ENTER( MP4_Box_data_padb_t );
MP4_GETVERSIONFLAGS( p_box->data.p_elst );
calloc( sizeof( uint64_t ), p_box->data.p_elst->i_entry_count );
p_box->data.p_elst->i_media_rate_integer =
calloc( sizeof( uint16_t ), p_box->data.p_elst->i_entry_count );
- p_box->data.p_elst->i_media_rate_fraction=
+ p_box->data.p_elst->i_media_rate_fraction=
calloc( sizeof( uint16_t ), p_box->data.p_elst->i_entry_count );
MP4_GET2BYTES( p_box->data.p_elst->i_media_rate_integer[i] );
MP4_GET2BYTES( p_box->data.p_elst->i_media_rate_fraction[i] );
}
-
-
-#ifdef MP4_VERBOSE
+
+#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"elst\" entry-count "I64Fd,
i_read / 2 );
{
unsigned int i_language;
unsigned int i;
-
+
MP4_READBOX_ENTER( MP4_Box_data_cprt_t );
MP4_GETVERSIONFLAGS( p_box->data.p_cprt );
- i_language = GetWBE( p_peek );
+ i_language = GetWBE( p_peek );
for( i = 0; i < 3; i++ )
{
- p_box->data.p_cprt->i_language[i] =
+ p_box->data.p_cprt->i_language[i] =
( ( i_language >> ( (2-i)*5 ) )&0x1f ) + 0x60;
}
- p_peek += 2; i_read -= 2;
+ p_peek += 2; i_read -= 2;
MP4_GETSTRINGZ( p_box->data.p_cprt->psz_notice );
#ifdef MP4_VERBOSE
int MP4_ReadBox_dcom( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_READBOX_ENTER( MP4_Box_data_dcom_t );
-
+
MP4_GETFOURCC( p_box->data.p_dcom->i_algorithm );
#ifdef MP4_VERBOSE
- msg_Dbg( p_stream->p_input,
- "Read Box: \"dcom\" compression algorithm : %c%c%c%c",
- ( p_box->data.p_dcom->i_algorithm )&0xff,
- ( p_box->data.p_dcom->i_algorithm >> 8 )&0xff,
- ( p_box->data.p_dcom->i_algorithm >> 16 )&0xff,
- ( p_box->data.p_dcom->i_algorithm >> 24 )&0xff );
-#endif
-
+ msg_Dbg( p_stream->p_input,
+ "Read Box: \"dcom\" compression algorithm : %4.4s",
+ (char*)&p_box->data.p_dcom->i_algorithm );
+#endif
MP4_READBOX_EXIT( 1 );
}
{
MP4_READBOX_ENTER( MP4_Box_data_cmvd_t );
-
MP4_GET4BYTES( p_box->data.p_cmvd->i_uncompressed_size );
p_box->data.p_cmvd->i_compressed_size = i_read;
-
+
if( !( p_box->data.p_cmvd->p_data = malloc( i_read ) ) )
{
msg_Dbg( p_stream->p_input, "Read Box: \"cmvd\" not enough memory to load data" );
return( 1 );
}
-
+
/* now copy compressed data */
memcpy( p_box->data.p_cmvd->p_data,
p_peek,
i_read);
-
+
p_box->data.p_cmvd->b_compressed = 1;
-
+
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, "Read Box: \"cmvd\" compressed data size %d",
p_box->data.p_cmvd->i_compressed_size );
-#endif
-
+#endif
+
MP4_READBOX_EXIT( 1 );
}
void MP4_FreeBox_cmvd( input_thread_t *p_input, MP4_Box_t *p_box )
{
MP4_Stream_t *p_stream_memory;
MP4_Box_t *p_umov;
-
+
MP4_Box_t *p_dcom;
MP4_Box_t *p_cmvd;
#ifdef HAVE_ZLIB_H
z_stream z_data;
#endif
uint8_t *p_data;
-
+
int i_result;
if( !( p_box->data.p_cmov = malloc( sizeof( MP4_Box_data_cmov_t ) ) ) )
return( 0 );
}
memset( p_box->data.p_cmov, 0, sizeof( MP4_Box_data_cmov_t ) );
-
+
if( !( p_box->p_father )||
( p_box->p_father->i_type != FOURCC_moov ) )
{
{
return( 0 );
}
-
+
if( !( p_dcom = MP4_FindBox( p_box, FOURCC_dcom ) )||
!( p_cmvd = MP4_FindBox( p_box, FOURCC_cmvd ) )||
!( p_cmvd->data.p_cmvd->p_data ) )
if( p_dcom->data.p_dcom->i_algorithm != FOURCC_zlib )
{
- msg_Dbg( p_stream->p_input, "Read Box: \"cmov\" compression algorithm : %c%c%c%c not supported",
- ( p_dcom->data.p_dcom->i_algorithm )&0xff,
- ( p_dcom->data.p_dcom->i_algorithm >> 8 )&0xff,
- ( p_dcom->data.p_dcom->i_algorithm >> 16 )&0xff,
- ( p_dcom->data.p_dcom->i_algorithm >> 24 )&0xff );
+ msg_Dbg( p_stream->p_input, "Read Box: \"cmov\" compression algorithm : %4.4s not supported",
+ (char*)&p_dcom->data.p_dcom->i_algorithm );
return( 1 );
}
msg_Dbg( p_stream->p_input,
"Read Box: \"cmov\" zlib unsupported" );
return( 1 );
-#else
+#else
/* decompress data */
/* allocate a new buffer */
if( !( p_data = malloc( p_cmvd->data.p_cmvd->i_uncompressed_size ) ) )
{
- msg_Err( p_stream->p_input,
+ msg_Err( p_stream->p_input,
"Read Box: \"cmov\" not enough memory to uncompress data" );
return( 1 );
}
/* init zlib */
if( ( i_result = inflateInit( &z_data ) ) != Z_OK )
{
- msg_Err( p_stream->p_input,
+ msg_Err( p_stream->p_input,
"Read Box: \"cmov\" error while uncompressing data" );
free( p_data );
return( 1 );
i_result = inflate( &z_data, Z_NO_FLUSH );
if( ( i_result != Z_OK )&&( i_result != Z_STREAM_END ) )
{
- msg_Err( p_stream->p_input,
+ msg_Err( p_stream->p_input,
"Read Box: \"cmov\" error while uncompressing data" );
free( p_data );
return( 1 );
if( p_cmvd->data.p_cmvd->i_uncompressed_size != z_data.total_out )
{
- msg_Warn( p_stream->p_input,
+ msg_Warn( p_stream->p_input,
"Read Box: \"cmov\" uncompressing data size mismatch" );
}
p_cmvd->data.p_cmvd->i_uncompressed_size = z_data.total_out;
- /* close zlib */
+ /* close zlib */
i_result = inflateEnd( &z_data );
if( i_result != Z_OK )
{
- msg_Warn( p_stream->p_input,
+ msg_Warn( p_stream->p_input,
"Read Box: \"cmov\" error while uncompressing data (ignored)" );
}
p_cmvd->data.p_cmvd->p_data = p_data;
p_cmvd->data.p_cmvd->b_compressed = 0;
- msg_Dbg( p_stream->p_input,
+ msg_Dbg( p_stream->p_input,
"Read Box: \"cmov\" box succesfully uncompressed" );
/* now create a memory stream */
- p_stream_memory = MP4_MemoryStream( p_stream->p_input,
+ p_stream_memory = MP4_MemoryStream( p_stream->p_input,
p_cmvd->data.p_cmvd->i_uncompressed_size,
p_cmvd->data.p_cmvd->p_data );
/* and read uncompressd moov */
p_umov = malloc( sizeof( MP4_Box_t ) );
-
+
i_result = MP4_ReadBox( p_stream_memory, p_umov, NULL );
-
+
p_box->data.p_cmov->p_moov = p_umov;
free( p_stream_memory );
#ifdef MP4_VERBOSE
- msg_Dbg( p_stream->p_input,
+ msg_Dbg( p_stream->p_input,
"Read Box: \"cmov\" compressed movie header completed" );
#endif
return( i_result );
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input,
- "Read Box: \"rdrf\" type:%c%c%c%c ref %s",
- p_box->data.p_rdrf->i_ref_type&0xff, (p_box->data.p_rdrf->i_ref_type>>8)&0xff,
- (p_box->data.p_rdrf->i_ref_type>>16)&0xff, (p_box->data.p_rdrf->i_ref_type>>24)&0xff,
+ "Read Box: \"rdrf\" type:%4.4s ref %s",
+ (char*)&p_box->data.p_rdrf->i_ref_type,
p_box->data.p_rdrf->psz_ref );
#endif
#ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input,
- "Read Box: \"rmvc\" gestaltType:%c%c%c%c val1:0x%x val2:0x%x checkType:0x%x",
- p_box->data.p_rmvc->i_gestaltType&0xff, (p_box->data.p_rmvc->i_gestaltType>>8)&0xff,
- (p_box->data.p_rmvc->i_gestaltType>>16)&0xff,(p_box->data.p_rmvc->i_gestaltType>>24)&0xff,
+ "Read Box: \"rmvc\" gestaltType:%4.4s val1:0x%x val2:0x%x checkType:0x%x",
+ (char*)&p_box->data.p_rmvc->i_gestaltType,
p_box->data.p_rmvc->i_val1,p_box->data.p_rmvc->i_val2,
p_box->data.p_rmvc->i_checkType );
#endif
static struct
{
uint32_t i_type;
- int (*MP4_ReadBox_function )( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
+ int (*MP4_ReadBox_function )( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
void (*MP4_FreeBox_function )( input_thread_t *p_input, MP4_Box_t *p_box );
} MP4_Box_Function [] =
{
{ FOURCC_mjpb, MP4_ReadBox_sample_vide, MP4_FreeBox_Common },
{ FOURCC_mjqt, NULL, NULL }, /* found in mjpa/b */
{ FOURCC_mjht, NULL, NULL },
-
+
{ FOURCC_jpeg, MP4_ReadBox_sample_vide, MP4_FreeBox_Common },
{ FOURCC_mp4s, NULL, MP4_FreeBox_Common },
/*****************************************************************************
- * MP4_ReadBox : parse the actual box and the children
+ * MP4_ReadBox : parse the actual box and the children
* XXX : Do not go to the next box
*****************************************************************************/
int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father )
{
int i_result;
unsigned int i_index;
-
+
if( !MP4_ReadBoxCommon( p_stream, p_box ) )
{
msg_Warn( p_stream->p_input, "Cannot read one box" );
if( MP4_Box_Function[i_index].MP4_ReadBox_function == NULL )
{
msg_Warn( p_stream->p_input,
- "Unknown box type %c%c%c%c (uncompletetly loaded)",
- (p_box->i_type)&0xff,
- (p_box->i_type>>8)&0xff,
- (p_box->i_type>>16)&0xff,
- (p_box->i_type>>24)&0xff );
+ "Unknown box type %4.4s (uncompletetly loaded)",
+ (char*)&p_box->i_type );
return( 1 );
}
else
{
- i_result =
+ i_result =
(MP4_Box_Function[i_index].MP4_ReadBox_function)( p_stream, p_box );
}
}
#if 0
/*****************************************************************************
- * MP4_CountBox: given a box, count how many child have the requested type
- * FIXME : support GUUID
+ * MP4_CountBox: given a box, count how many child have the requested type
+ * FIXME : support GUUID
*****************************************************************************/
int MP4_CountBox( MP4_Box_t *p_box, uint32_t i_type )
{
unsigned int i_count;
MP4_Box_t *p_child;
-
+
if( !p_box )
{
return( 0 );
while( p_child )
{
if( p_child->i_type == i_type )
- {
+ {
i_count++;
}
p_child = p_child->p_next;
}
-
+
return( i_count );
}
#endif
MP4_Box_t *MP4_FindBox( MP4_Box_t *p_box, uint32_t i_type )
{
MP4_Box_t *p_child;
-
+
if( !p_box )
{
return( NULL );
while( p_child )
{
if( p_child->i_type == i_type )
- {
+ {
return( p_child );
}
p_child = p_child->p_next;
}
-
+
return( NULL );
}
#if 0
/*****************************************************************************
- * MP4_FindNextBox: find next box with thesame type and at the same level
+ * MP4_FindNextBox: find next box with thesame type and at the same level
* than p_box
*****************************************************************************/
MP4_Box_t *MP4_FindNextBox( MP4_Box_t *p_box )
{
MP4_Box_t *p_next;
-
+
if( !p_box )
{
return( NULL );
MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number )
{
MP4_Box_t *p_child = p_box->p_first;
-
+
if( !p_child )
{
return( NULL );
#endif
/*****************************************************************************
- * MP4_FreeBox : free memory after read with MP4_ReadBox and all
+ * MP4_FreeBox : free memory after read with MP4_ReadBox and all
* the children
*****************************************************************************/
void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box )
MP4_BoxFree( p_input, p_child );
/* MP4_FreeBoxChildren have free all data expect p_child itself */
free( p_child );
- p_child = p_next;
+ p_child = p_next;
}
/* Now search function to call */
if( MP4_Box_Function[i_index].MP4_FreeBox_function == NULL )
{
/* Should not happen */
- msg_Warn( p_input,
- "cannot free box %c%c%c%c, type unknown",
- (p_box->i_type)&0xff,
- (p_box->i_type >> 8)&0xff,
- (p_box->i_type >> 16)&0xff,
- (p_box->i_type >> 24)&0xff );
+ msg_Warn( p_input,
+ "cannot free box %4.4s, type unknown",
+ (char*)&p_box->i_type );
}
else
{
p_box->p_first = NULL;
p_box->p_last = NULL;
-
+
}
/*****************************************************************************
* MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory
*****************************************************************************
- * The first box is a virtual box "root" and is the father for all first
+ * The first box is a virtual box "root" and is the father for all first
* level boxes for the file, a sort of virtual contener
*****************************************************************************/
int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root )
{
-
MP4_Stream_t *p_stream;
int i_result;
-
+
MP4_SeekAbsolute( p_input, 0 ); /* Go to the begining */
p_root->i_pos = 0;
p_root->i_type = VLC_FOURCC( 'r', 'o', 'o', 't' );
p_root->p_first = NULL;
p_root->p_last = NULL;
p_root->p_next = NULL;
-
+
p_stream = MP4_InputStream( p_input );
-
+
i_result = MP4_ReadBoxContainerRaw( p_stream, p_root );
free( p_stream );
-
+
if( i_result )
{
- MP4_Box_t *p_child;
+ MP4_Box_t *p_child;
MP4_Box_t *p_moov;
MP4_Box_t *p_cmov;
- /* check if there is a cmov, if so replace
+ /* check if there is a cmov, if so replace
compressed moov by uncompressed one */
if( ( p_moov = MP4_FindBox( p_root, FOURCC_moov ) )&&
( p_cmov = MP4_FindBox( p_moov, FOURCC_cmov ) ) )
{
/* rename the compressed moov as a box to skip */
p_moov->i_type = FOURCC_skip;
-
+
/* get uncompressed p_moov */
p_moov = p_cmov->data.p_cmov->p_moov;
p_cmov->data.p_cmov->p_moov = NULL;
if( !i_level )
{
- msg_Dbg( p_input, "Dumping root Box \"%c%c%c%c \"",
- (p_box->i_type ) &0xff,
- (p_box->i_type >>8 ) &0xff,
- (p_box->i_type >>16 ) &0xff,
- (p_box->i_type >>24) &0xff );
+ msg_Dbg( p_input, "Dumping root Box \"%4.4s\"",
+ (char*)&p_box->i_type );
}
else
{
{
str[i*5] = '|';
}
- sprintf( str + i_level * 5, "+ %c%c%c%c size %d",
- (p_box->i_type ) &0xff,
- (p_box->i_type>>8 ) &0xff,
- (p_box->i_type>>16 ) &0xff,
- (p_box->i_type>>24 ) &0xff,
+ sprintf( str + i_level * 5, "+ %4.4s size %d",
+ (char*)&p_box->i_type,
(uint32_t)p_box->i_size );
-
+
msg_Dbg( p_input, "%s", str );
}
p_child = p_box->p_first;
__MP4_BoxDumpStructure( p_input, p_child, i_level + 1 );
p_child = p_child->p_next;
}
-
}
void MP4_BoxDumpStructure( input_thread_t *p_input, MP4_Box_t *p_box )
return;
}
i_len = 0;
- while( (*ppsz_path)[i_len] &&
+ while( (*ppsz_path)[i_len] &&
(*ppsz_path)[i_len] != '/' && (*ppsz_path)[i_len] != '[' )
{
i_len++;
i_len = 1;
}
*ppsz_token = malloc( i_len + 1 );
-
+
memcpy( *ppsz_token, *ppsz_path, i_len );
(*ppsz_token)[i_len] = '\0';
*ppsz_path += i_len;
-
+
if( **ppsz_path == '[' )
{
(*ppsz_path)++;
size_t i_size;
#endif
-
if( !p_box )
{
*pp_result = NULL;
int i_number;
__get_token( &psz_path, &psz_token, &i_number );
-// fprintf( stderr, "path:'%s', token:'%s' n:%d\n",
+// fprintf( stderr, "path:'%s', token:'%s' n:%d\n",
// psz_path,psz_token,i_number );
if( !psz_token )
{
*pp_result = NULL;
return;
}
-
+
free( psz_token );
}
-
}
/*****************************************************************************
*****************************************************************************
* Path Format: . .. / as usual
* [number] to specifie box number ex: trak[12]
- *
+ *
* ex: /moov/trak[12]
* ../mdia
*****************************************************************************/
va_list args;
MP4_Box_t *p_result;
- va_start( args, psz_fmt );
+ va_start( args, psz_fmt );
__MP4_BoxGet( &p_result, p_box, psz_fmt, args );
va_end( args );
*****************************************************************************
* Path Format: . .. / as usual
* [number] to specifie box number ex: trak[12]
- *
+ *
* ex: /moov/trak[12]
* ../mdia
*****************************************************************************/
int i_count;
MP4_Box_t *p_result, *p_next;
- va_start( args, psz_fmt );
+ va_start( args, psz_fmt );
__MP4_BoxGet( &p_result, p_box, psz_fmt, args );
va_end( args );
if( !p_result )
{
return( 0 );
}
-
+
i_count = 1;
for( p_next = p_result->p_next; p_next != NULL; p_next = p_next->p_next)
{
* mp4.c : MP4 file input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: mp4.c,v 1.16 2003/01/28 16:57:28 sam Exp $
+ * $Id: mp4.c,v 1.17 2003/02/07 01:22:55 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
*((uint8_t*)p) = ( (dw)&0xff ); \
*((uint8_t*)p+1) = ( ((dw)>> 8)&0xff )
-
+
/*****************************************************************************
* MP4Init: check file and initializes MP4 structures
*****************************************************************************/
switch( p_ftyp->data.p_ftyp->i_major_brand )
{
case( FOURCC_isom ):
- msg_Dbg( p_input,
+ msg_Dbg( p_input,
"ISO Media file (isom) version %d.",
p_ftyp->data.p_ftyp->i_minor_version );
break;
default:
msg_Dbg( p_input,
- "unrecognized major file specification (%c%c%c%c).",
- p_ftyp->data.p_ftyp->i_major_brand&0xff,
- ( p_ftyp->data.p_ftyp->i_major_brand >> 8)&0xff,
- ( p_ftyp->data.p_ftyp->i_major_brand >> 16 )&0xff,
- ( p_ftyp->data.p_ftyp->i_major_brand >> 24 )&0xff );
+ "unrecognized major file specification (%4.4s).",
+ (char*)&p_ftyp->data.p_ftyp->i_major_brand );
break;
}
}
/* the file need to have one moov box */
if( MP4_BoxCount( &p_demux->box_root, "/moov" ) != 1 )
{
- msg_Err( p_input,
+ msg_Err( p_input,
"MP4 plugin discarded (%d moov boxes)",
MP4_BoxCount( &p_demux->box_root, "/moov" ) );
// MP4End( p_input );
p_demux->i_duration = p_mvhd->data.p_mvhd->i_duration;
}
- if( !( p_demux->i_tracks =
+ if( !( p_demux->i_tracks =
MP4_BoxCount( &p_demux->box_root, "/moov/trak" ) ) )
{
msg_Err( p_input, "cannot find any /moov/trak" );
psz_cat,
p_demux->track[i].b_enable ? "enable":"disable",
p_demux->track[i].i_language[0],
- p_demux->track[i].i_language[1],
+ p_demux->track[i].i_language[1],
p_demux->track[i].i_language[2] );
}
else
demux_sys_t *p_demux = p_input->p_demux_data;
unsigned int i_track;
- /* XXX beurk, beuRK and BEURK,
+ /* XXX beurk, beuRK and BEURK,
but only way I've found to detect seek from interface */
if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
{
mtime_t i_date;
-
+
/* first wait for empty buffer, arbitrary time FIXME */
msleep( DEFAULT_PTS_DELAY );
/* *** calculate new date *** */
- i_date = (mtime_t)1000000 *
+ i_date = (mtime_t)1000000 *
(mtime_t)p_demux->i_duration /
- (mtime_t)p_demux->i_timescale *
+ (mtime_t)p_demux->i_timescale *
(mtime_t)MP4_TellAbsolute( p_input ) /
(mtime_t)p_input->stream.p_selected_area->i_size;
MP4Seek( p_input, i_date );
}
-
+
/* first wait for the good time to read a packet */
input_ClockManageRef( p_input,
p_input->stream.p_selected_program,
/* update pcr XXX in mpeg scale so in 90000 unit/s */
p_demux->i_pcr = MP4_GetMoviePTS( p_demux ) * 9 / 100;
-
+
/* we will read 100ms for each stream so ...*/
p_demux->i_time += __MAX( p_demux->i_timescale / 10 , 1 );
-
+
for( i_track = 0; i_track < p_demux->i_tracks; i_track++ )
{
break;
}
- /* send it to decoder and update time of this track
+ /* send it to decoder and update time of this track
it also launch a new decoder if needed */
MP4_DecodeSample( p_input ,
&p_demux->track[i_track],
}
}
-
+
/* now check if all tracks are finished or unhandled*/
-
+
for( i_track = 0; i_track < p_demux->i_tracks; i_track++ )
{
if( ( p_demux->track[i_track].b_ok )&&
/* First update update global time */
p_demux->i_time = i_date * p_demux->i_timescale / 1000000;
p_demux->i_pcr = __MAX( MP4_GetMoviePTS( p_demux ) - DEFAULT_PTS_DELAY,
- 0 ) * 9 / 100;
-
+ 0 ) * 9 / 100;
+
/* Now for each stream try to go to this time */
for( i_track = 0; i_track < p_demux->i_tracks; i_track++ )
{
****************************************************************************/
/****************************************************************************
- * MP4_TrackSynchro : synchronize a track with movie time after seek or
+ * MP4_TrackSynchro : synchronize a track with movie time after seek or
* for newly selected track
*****************************************************************************
* TODO add support of Edit List (edts/elts) and Shadow Sync Sample(stsh)
{
if( p_track->i_sample >= p_track->i_sample_count )
{
- msg_Warn( p_input,
+ msg_Warn( p_input,
"track[Id 0x%x] will be disabled (seeking too far)",
p_track->i_track_ID );
MP4_StopDecoder( p_input, p_track );
{
p_track->i_chunk++;
}
-
}
if( p_track->i_sample >= p_track->i_sample_count )
{
{
if( i_index > 0 )
{
- msg_Dbg( p_input, "stts gives %d --> %d (sample number)",
- p_track->i_sample,
+ msg_Dbg( p_input, "stts gives %d --> %d (sample number)",
+ p_track->i_sample,
p_stss->data.p_stss->i_sample_number[i_index-1] );
p_track->i_sample = p_stss->data.p_stss->i_sample_number[i_index-1];
/* new track.i_sample is less than old so i_chunk can only decreased */
- while( p_track->i_chunk > 0 &&
+ while( p_track->i_chunk > 0 &&
p_track->i_sample < p_track->chunk[p_track->i_chunk].i_sample_first )
{
p_track->i_chunk--;
}
else
{
- msg_Dbg( p_input, "stts gives %d --> %d (sample number)",
- p_track->i_sample,
+ msg_Dbg( p_input, "stts gives %d --> %d (sample number)",
+ p_track->i_sample,
p_stss->data.p_stss->i_sample_number[i_index-1] );
p_track->i_sample = p_stss->data.p_stss->i_sample_number[i_index];
/* new track.i_sample is more than old so i_chunk can only increased */
}
else
{
- msg_Dbg( p_input,
- "track[Id 0x%x] does not provide Sync Sample Box (stss)",
+ msg_Dbg( p_input,
+ "track[Id 0x%x] does not provide Sync Sample Box (stss)",
p_track->i_track_ID );
}
MP4_Box_t *p_hdlr;
MP4_Box_t *p_vmhd;
- MP4_Box_t *p_smhd;
+ MP4_Box_t *p_smhd;
/* hint track unsuported */
/* by default, we don't known the categorie */
p_demux_track->i_cat = UNKNOWN_ES;
-
+
if( !p_tkhd )
{
return;
}
/* do we launch this track by default ? */
- p_demux_track->b_enable =
+ p_demux_track->b_enable =
( ( p_tkhd->data.p_tkhd->i_flags&MP4_TRACK_ENABLED ) != 0 );
p_demux_track->i_track_ID = p_tkhd->data.p_tkhd->i_track_ID;
p_demux_track->i_width = p_tkhd->data.p_tkhd->i_width / 65536;
p_demux_track->i_height = p_tkhd->data.p_tkhd->i_height / 65536;
-
+
if( ( p_elst = MP4_BoxGet( p_trak, "edts/elst" ) ) )
{
/* msg_Warn( p_input, "unhandled box: edts --> FIXME" ); */
if( p_tref )
{
/* msg_Warn( p_input, "unhandled box: tref --> FIXME" ); */
- }
+ }
p_mdhd = MP4_BoxGet( p_trak, "mdia/mdhd" );
p_hdlr = MP4_BoxGet( p_trak, "mdia/hdlr" );
-
+
if( ( !p_mdhd )||( !p_hdlr ) )
{
return;
p_demux_track->i_timescale = p_mdhd->data.p_mdhd->i_timescale;
- for( i = 0; i < 3; i++ )
+ for( i = 0; i < 3; i++ )
{
p_demux_track->i_language[i] = p_mdhd->data.p_mdhd->i_language[i];
}
p_mdhd->data.p_mdhd->i_language[3] = 0;
-
+
switch( p_hdlr->data.p_hdlr->i_handler_type )
{
case( FOURCC_soun ):
}
p_demux_track->i_cat = VIDEO_ES;
break;
-
+
default:
return;
}
{
return;
}
-
+
if( !( p_demux_track->p_stsd = MP4_BoxGet( p_trak,"mdia/minf/stbl/stsd") ) )
{
return;
}
-
+
/* Create chunk index table */
if( !MP4_CreateChunksIndex( p_input,p_demux_track ) )
{
return; /* cannot create chunks index */
}
-
+
/* create sample index table needed for reading and seeking */
if( !MP4_CreateSamplesIndex( p_input, p_demux_track ) )
{
return; /* cannot create samples index */
}
-
- p_demux_track->b_ok = 1;
+
+ p_demux_track->b_ok = 1;
}
-
/* now create basic chunk data, the rest will be filled by MP4_CreateSamplesIndex */
unsigned int i_chunk;
unsigned int i_index, i_last;
-
if( ( !(p_co64 = MP4_BoxGet( p_demux_track->p_stbl, "stco" ) )&&
- !(p_co64 = MP4_BoxGet( p_demux_track->p_stbl, "co64" ) ) )||
+ !(p_co64 = MP4_BoxGet( p_demux_track->p_stbl, "co64" ) ) )||
( !(p_stsc = MP4_BoxGet( p_demux_track->p_stbl, "stsc" ) ) ))
{
return( 0 );
}
-
+
p_demux_track->i_chunk_count = p_co64->data.p_co64->i_entry_count;
if( !p_demux_track->i_chunk_count )
{
msg_Warn( p_input, "no chunk defined" );
return( 0 );
}
- p_demux_track->chunk = calloc( p_demux_track->i_chunk_count,
+ p_demux_track->chunk = calloc( p_demux_track->i_chunk_count,
sizeof( chunk_data_mp4_t ) );
/* first we read chunk offset */
for( i_chunk = 0; i_chunk < p_demux_track->i_chunk_count; i_chunk++ )
{
- p_demux_track->chunk[i_chunk].i_offset =
+ p_demux_track->chunk[i_chunk].i_offset =
p_co64->data.p_co64->i_chunk_offset[i_chunk];
}
- /* now we read index for SampleEntry( soun vide mp4a mp4v ...)
- to be used for the sample XXX begin to 1
+ /* now we read index for SampleEntry( soun vide mp4a mp4v ...)
+ to be used for the sample XXX begin to 1
We construct it begining at the end */
i_last = p_demux_track->i_chunk_count; /* last chunk proceded */
i_index = p_stsc->data.p_stsc->i_entry_count;
for( i_chunk = p_stsc->data.p_stsc->i_first_chunk[i_index] - 1;
i_chunk < i_last; i_chunk++ )
{
- p_demux_track->chunk[i_chunk].i_sample_description_index =
+ p_demux_track->chunk[i_chunk].i_sample_description_index =
p_stsc->data.p_stsc->i_sample_description_index[i_index];
p_demux_track->chunk[i_chunk].i_sample_count =
p_stsc->data.p_stsc->i_samples_per_chunk[i_index];
i_last = p_stsc->data.p_stsc->i_first_chunk[i_index] - 1;
}
- p_demux_track->chunk[i_chunk].i_sample_first = 0;
+ p_demux_track->chunk[0].i_sample_first = 0;
for( i_chunk = 1; i_chunk < p_demux_track->i_chunk_count; i_chunk++ )
{
p_demux_track->chunk[i_chunk].i_sample_first =
- p_demux_track->chunk[i_chunk-1].i_sample_first +
+ p_demux_track->chunk[i_chunk-1].i_sample_first +
p_demux_track->chunk[i_chunk-1].i_sample_count;
-
}
-
- msg_Dbg( p_input,
+
+ msg_Dbg( p_input,
"track[Id 0x%x] read %d chunk",
p_demux_track->i_track_ID,
p_demux_track->i_chunk_count );
track_data_mp4_t *p_demux_track )
{
MP4_Box_t *p_stts; /* makes mapping between sample and decoding time,
- ctts make same mapping but for composition time,
+ ctts make same mapping but for composition time,
not yet used and probably not usefull */
- MP4_Box_t *p_stsz; /* gives sample size of each samples, there is also stz2
- that uses a compressed form FIXME make them in libmp4
+ MP4_Box_t *p_stsz; /* gives sample size of each samples, there is also stz2
+ that uses a compressed form FIXME make them in libmp4
as a unique type */
/* TODO use also stss and stsh table for seeking */
/* FIXME use edit table */
int64_t i_index;
int64_t i_index_sample_used;
- int64_t i_last_dts;
-
+ int64_t i_last_dts;
+
p_stts = MP4_BoxGet( p_demux_track->p_stbl, "stts" );
p_stsz = MP4_BoxGet( p_demux_track->p_stbl, "stsz" ); /* FIXME and stz2 */
-
if( ( !p_stts )||( !p_stsz ) )
{
msg_Warn( p_input, "cannot read sample table" );
- return( 0 );
+ return( 0 );
}
-
+
p_demux_track->i_sample_count = p_stsz->data.p_stsz->i_sample_count;
{
/* 2: each sample can have a different size */
p_demux_track->i_sample_size = 0;
- p_demux_track->p_sample_size =
+ p_demux_track->p_sample_size =
calloc( p_demux_track->i_sample_count, sizeof( uint32_t ) );
-
+
for( i_sample = 0; i_sample < p_demux_track->i_sample_count; i_sample++ )
{
- p_demux_track->p_sample_size[i_sample] =
+ p_demux_track->p_sample_size[i_sample] =
p_stsz->data.p_stsz->i_entry_size[i_sample];
}
}
now use stts */
/* if we don't want to waste too much memory, we can't expand
- the box !, so each chunk will contain an "extract" of this table
+ the box !, so each chunk will contain an "extract" of this table
for fast research */
-
+
i_last_dts = 0;
i_index = 0; i_index_sample_used =0;
int64_t i_entry, i_sample_count, i;
/* save last dts */
p_demux_track->chunk[i_chunk].i_first_dts = i_last_dts;
- /* count how many entries needed for this chunk
+ /* count how many entries needed for this chunk
for p_sample_delta_dts and p_sample_count_dts */
i_sample_count = p_demux_track->chunk[i_chunk].i_sample_count;
i_sample_count -= p_stts->data.p_stts->i_sample_count[i_index+i_entry];
if( i_entry == 0 )
{
- i_sample_count += i_index_sample_used; /* don't count already used sample
+ i_sample_count += i_index_sample_used; /* don't count already used sample
int this entry */
}
i_entry++;
}
/* allocate them */
- p_demux_track->chunk[i_chunk].p_sample_count_dts =
+ p_demux_track->chunk[i_chunk].p_sample_count_dts =
calloc( i_entry, sizeof( uint32_t ) );
p_demux_track->chunk[i_chunk].p_sample_delta_dts =
calloc( i_entry, sizeof( uint32_t ) );
{
int64_t i_used;
int64_t i_rest;
-
+
i_rest = p_stts->data.p_stts->i_sample_count[i_index] - i_index_sample_used;
i_used = __MIN( i_rest, i_sample_count );
p_demux_track->chunk[i_chunk].p_sample_delta_dts[i] =
p_stts->data.p_stts->i_sample_delta[i_index];
-
- i_last_dts += i_used *
+
+ i_last_dts += i_used *
p_demux_track->chunk[i_chunk].p_sample_delta_dts[i];
if( i_index_sample_used >=
i_index_sample_used = 0;
}
}
-
+
}
- msg_Dbg( p_input,
- "track[Id 0x%x] read %d samples length:"I64Fd"s",
+ msg_Dbg( p_input,
+ "track[Id 0x%x] read %d samples length:"I64Fd"s",
p_demux_track->i_track_ID,
p_demux_track->i_sample_count,
i_last_dts / p_demux_track->i_timescale );
if( !p_demux_track->chunk[i_chunk].i_sample_description_index )
{
- msg_Warn( p_input,
+ msg_Warn( p_input,
"invalid SampleEntry index (track[Id 0x%x])",
p_demux_track->i_track_ID );
return;
- }
- p_sample = MP4_BoxGet( p_demux_track->p_stsd,
- "[%d]",
+ }
+ p_sample = MP4_BoxGet( p_demux_track->p_stsd,
+ "[%d]",
p_demux_track->chunk[i_chunk].i_sample_description_index - 1 );
if( ( !p_sample )||( !p_sample->data.p_data ) )
{
- msg_Warn( p_input,
+ msg_Warn( p_input,
"cannot find SampleEntry (track[Id 0x%x])",
p_demux_track->i_track_ID );
return;
vlc_mutex_lock( &p_input->stream.stream_lock );
p_demux_track->p_es = input_AddES( p_input,
- p_input->stream.p_selected_program,
+ p_input->stream.p_selected_program,
p_demux_track->i_track_ID,
0 );
vlc_mutex_unlock( &p_input->stream.stream_lock );
p_decoder_specific_info = NULL;
p_pes_init = NULL;
- /* now see if esds is present and if so create a data packet
+ /* now see if esds is present and if so create a data packet
with decoder_specific_info */
#define p_decconfig p_esds->data.p_esds->es_descriptor.p_decConfigDescr
if( ( p_esds = MP4_BoxGet( p_sample, "esds" ) )&&
p_demux_track->p_es->i_fourcc = VLC_FOURCC( 'm','p','4','a' );
break;
/* true MPEG 2 audio */
- case( 0x69):
+ case( 0x69):
p_demux_track->p_es->i_fourcc = VLC_FOURCC( 'm','p','g','a' );
break;
case( 0x6a): /* MPEG1 video */
break;
default:
/* Unknown entry, but don't touch i_fourcc */
- msg_Warn( p_input,
+ msg_Warn( p_input,
"unknown objectTypeIndication(0x%x) (Track[ID 0x%x])",
p_decconfig->i_objectTypeIndication,
p_demux_track->i_track_ID );
break;
}
- i_decoder_specific_info_len =
+ i_decoder_specific_info_len =
p_decconfig->i_decoder_specific_info_len;
- p_decoder_specific_info =
+ p_decoder_specific_info =
p_decconfig->p_decoder_specific_info;
}
#undef p_decconfig
/* some last initialisation */
- /* XXX I create a bitmapinfoheader_t or
- waveformatex_t for each stream, up to now it's the best thing
- I've found but it could exist a better solution :) as something
+ /* XXX I create a bitmapinfoheader_t or
+ waveformatex_t for each stream, up to now it's the best thing
+ I've found but it could exist a better solution :) as something
like adding some new fields in p_es ...
XXX I don't set all values, only thoses that are interesting or known
- --> bitmapinfoheader_t : width and height
+ --> bitmapinfoheader_t : width and height
--> waveformatex_t : channels, samplerate, bitspersample
- and at the end I add p_decoder_specific_info
+ and at the end I add p_decoder_specific_info
TODO set more values
switch( p_demux_track->i_cat )
{
- case( VIDEO_ES ):
- /* now create a bitmapinfoheader_t for decoder and
+ case( VIDEO_ES ):
+ /* now create a bitmapinfoheader_t for decoder and
add information found in p_esds */
/* XXX XXX + 16 are for avoid segfault when ffmpeg access beyong the data */
p_init = malloc( sizeof( BITMAPINFOHEADER ) + i_decoder_specific_info_len + 16 );
{
data_packet_t *p_data;
- memcpy( p_init + sizeof( BITMAPINFOHEADER ),
+ memcpy( p_init + sizeof( BITMAPINFOHEADER ),
p_decoder_specific_info,
i_decoder_specific_info_len);
return( 0 );
}
/* caculate size and position for this sample */
- i_size = p_demux_track->i_sample_size ?
- p_demux_track->i_sample_size :
+ i_size = p_demux_track->i_sample_size ?
+ p_demux_track->i_sample_size :
p_demux_track->p_sample_size[p_demux_track->i_sample];
i_pos = MP4_GetTrackPos( p_demux_track );
*pp_pes = NULL;
return( 0 );
}
-
+
/* initialisation of all the field */
(*pp_pes)->i_dts =
(*pp_pes)->i_pts = MP4_GetTrackPTS( p_demux_track );
(*pp_pes)->i_nb_data = 1;
(*pp_pes)->i_pes_size = i_size;
- if( !i_size )
+ if( !i_size )
{
return( 1 );
}
-
+
/* msg_Dbg( p_input, "will read %d bytes", i_size ); */
if( !MP4_ReadData( p_input, p_data->p_payload_start, i_size ) )
{
return( 0 );
}
- return( 1 );
+ return( 1 );
}
}
/* don't forget to convert in mpeg clock */
- /* FIXME correct ffmpeg to use dts instead of pts that it incorrect
+ /* FIXME correct ffmpeg to use dts instead of pts that it incorrect
and, set it here ( and correct avi demux ) */
p_pes->i_dts =
p_pes->i_pts = input_ClockGetTS( p_input,
p_input->stream.p_selected_program,
p_pes->i_pts * 9/100);
-
+
input_DecodePES( p_demux_track->p_es->p_decoder_fifo, p_pes );
-
+
/* now update sample position */
p_demux_track->i_sample++; /* easy ;) */
if( p_demux_track->i_sample >= p_demux_track->i_sample_count )
p_demux_track->chunk[p_demux_track->i_chunk].i_sample_first +
p_demux_track->chunk[p_demux_track->i_chunk].i_sample_count )
{
- /* we haven't reached the end of the track, so see if we
- have to change the decoder for the next frame because
+ /* we haven't reached the end of the track, so see if we
+ have to change the decoder for the next frame because
i_sample_description_index has changed */
p_demux_track->i_chunk++;
- if( p_demux_track->chunk[p_demux_track->i_chunk-1].i_sample_description_index
+ if( p_demux_track->chunk[p_demux_track->i_chunk-1].i_sample_description_index
!= p_demux_track->chunk[p_demux_track->i_chunk].i_sample_description_index )
{
/* FIXME */
- msg_Warn( p_input,
+ msg_Warn( p_input,
"SampleEntry has changed, starting a new decoder" );
MP4_StopDecoder( p_input, p_demux_track );
MP4_StartDecoder( p_input, p_demux_track );
}
}
-
return( 1 );
}