]> git.sesse.net Git - vlc/blobdiff - modules/demux/mp4/libmp4.c
* mp4: fix a string format.
[vlc] / modules / demux / mp4 / libmp4.c
index 07b17f21864dfbdd1861b3a612dfe5d8b82515f1..1e7476b6111b13ac52a5d6d028e18acdce6c2208 100644 (file)
@@ -2,7 +2,7 @@
  * 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.20 2003/04/16 16:32:42 fenrir Exp $
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -162,14 +162,14 @@ static uint64_t GetQWBE( uint8_t *p_buff )
 
 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 */
 }
@@ -192,7 +192,23 @@ void MP4_ConvertDate2Str( char *psz, uint64_t i_date )
                    i_day, i_hour, i_min, i_sec );
 }
 
+#if 0
+static void DataDump( uint8_t *p_data, int i_data )
+{
+    int i;
+    fprintf( stderr, "\nDumping %d bytes\n", i_data );
+    for( i = 0; i < i_data; i++ )
+    {
+        int c;
 
+        c = p_data[i];
+        if( c < 32 || c > 127 ) c = '.';
+        fprintf( stderr, "%c", c );
+        if( i % 60 == 59 ) fprintf( stderr, "\n" );
+    }
+    fprintf( stderr, "\n" );
+}
+#endif
 
 /*****************************************************************************
  * Some basic functions to manipulate stream more easily in vlc
@@ -231,8 +247,8 @@ int MP4_SeekAbsolute( input_thread_t *p_input,
     i_filepos = MP4_TellAbsolute( p_input );
     if( i_pos != i_filepos )
     {
-        p_input->pf_seek( p_input, i_pos );
         input_AccessReinit( p_input );
+        p_input->pf_seek( p_input, i_pos );
     }
     return( 1 );
 }
@@ -299,7 +315,7 @@ MP4_Stream_t *MP4_InputStream( input_thread_t *p_input )
 
 /****************************************************************************
  * 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 !
  *
  ****************************************************************************/
@@ -316,7 +332,7 @@ MP4_Stream_t *MP4_MemoryStream( input_thread_t *p_input,
     p_stream->p_input = p_input;
     p_stream->i_start = 0;
     p_stream->i_stop = i_size;
-    if( !p_stream->p_buffer )
+    if( !p_buffer )
     {
         if( !( p_stream->p_buffer = malloc( i_size ) ) )
         {
@@ -343,7 +359,7 @@ int MP4_ReadStream( MP4_Stream_t *p_stream, uint8_t *p_buff, int i_size )
         {
             return( 0 );
         }
-        memcpy( p_buff, 
+        memcpy( p_buff,
                 p_stream->p_buffer + p_stream->i_start,
                 i_size );
         p_stream->i_start += i_size;
@@ -467,22 +483,20 @@ int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         CreateUUID( &p_box->i_uuid, p_box->i_type );
     }
 #ifdef MP4_VERBOSE
-    /* 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,
-                 (uint32_t)p_box->i_size );
+        msg_Dbg( p_stream->p_input, "Found Box: %4.4s size "I64Fd,
+                 (char*)&p_box->i_type,
+                 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 ).
  *****************************************************************************/
@@ -504,7 +518,7 @@ int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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 */
@@ -533,7 +547,7 @@ int MP4_ReadBoxContainerRaw( MP4_Stream_t *p_stream, MP4_Box_t *p_container )
 {
     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 */
@@ -594,11 +608,8 @@ int MP4_ReadBoxSkip( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 {
     /* 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 );
 }
@@ -661,11 +672,11 @@ int MP4_ReadBox_mvhd(  MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         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] );
@@ -678,23 +689,23 @@ int MP4_ReadBox_mvhd(  MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     {
         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,
@@ -716,7 +727,7 @@ int MP4_ReadBox_tkhd(  MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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 )
@@ -735,7 +746,7 @@ int MP4_ReadBox_tkhd(  MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         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] );
@@ -751,12 +762,12 @@ int MP4_ReadBox_tkhd(  MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     }
     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,
@@ -778,7 +789,7 @@ int MP4_ReadBox_tref( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         /* 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 );
@@ -822,15 +833,15 @@ int MP4_ReadBox_mdhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         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 );
@@ -850,10 +861,10 @@ int MP4_ReadBox_mdhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
 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 );
 
@@ -861,11 +872,8 @@ int MP4_ReadBox_hdlr( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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
@@ -880,31 +888,30 @@ void MP4_FreeBox_hdlr( input_thread_t *p_input, MP4_Box_t *p_box )
 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 );
 
@@ -913,11 +920,10 @@ int MP4_ReadBox_smhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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 );
 }
@@ -925,7 +931,7 @@ int MP4_ReadBox_smhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
 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 );
 
@@ -943,14 +949,13 @@ int MP4_ReadBox_hmhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
                       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 );
@@ -976,8 +981,8 @@ int MP4_ReadBox_urn( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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,
@@ -995,11 +1000,11 @@ void MP4_FreeBox_urn( input_thread_t *p_input, MP4_Box_t *p_box )
 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 );
 
@@ -1015,23 +1020,22 @@ int MP4_ReadBox_dref( MP4_Stream_t *p_stream, MP4_Box_t *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 );
@@ -1044,30 +1048,28 @@ void MP4_FreeBox_stts( input_thread_t *p_input, MP4_Box_t *p_box )
 {
     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 );
@@ -1094,7 +1096,7 @@ static int MP4_ReadLengthDescriptor( uint8_t **pp_peek, int64_t  *i_read )
         (*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 )
@@ -1128,7 +1130,7 @@ 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 );
@@ -1149,11 +1151,12 @@ int MP4_ReadBox_esds( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     if( i_type != 0x04)/* MP4DecConfigDescrTag */
     {
+        es_descriptor.p_decConfigDescr = NULL;
         MP4_READBOX_EXIT( 1 ); /* rest isn't interesting up to now */
     }
 
     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 );
@@ -1166,13 +1169,15 @@ int MP4_ReadBox_esds( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     MP4_GET1BYTE( i_type );
     if( i_type !=  0x05 )/* MP4DecSpecificDescrTag */
     {
+        es_descriptor.p_decConfigDescr->i_decoder_specific_info_len = 0;
+        es_descriptor.p_decConfigDescr->p_decoder_specific_info  = NULL;
         MP4_READBOX_EXIT( 1 );
     }
 
     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 );
@@ -1203,10 +1208,16 @@ int MP4_ReadBox_sample_soun( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     MP4_GET2BYTES( p_box->data.p_sample_soun->i_data_reference_index );
 
+    MP4_GET2BYTES( p_box->data.p_sample_soun->i_qt_version );
+    MP4_GET2BYTES( p_box->data.p_sample_soun->i_qt_revision_level );
+    MP4_GET4BYTES( p_box->data.p_sample_soun->i_qt_vendor );
+
+#if 0
     for( i = 0; i < 2 ; i++ )
     {
         MP4_GET4BYTES( p_box->data.p_sample_soun->i_reserved2[i] );
     }
+#endif
 
     MP4_GET2BYTES( p_box->data.p_sample_soun->i_channelcount );
     MP4_GET2BYTES( p_box->data.p_sample_soun->i_samplesize );
@@ -1215,14 +1226,40 @@ int MP4_ReadBox_sample_soun( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     MP4_GET2BYTES( p_box->data.p_sample_soun->i_sampleratehi );
     MP4_GET2BYTES( p_box->data.p_sample_soun->i_sampleratelo );
 
-    MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 28 );
+    if( p_box->data.p_sample_soun->i_qt_version == 1 &&
+        i_read >= 16 )
+    {
+        /* qt3+ */
+        MP4_GET4BYTES( p_box->data.p_sample_soun->i_sample_per_packet );
+        MP4_GET4BYTES( p_box->data.p_sample_soun->i_bytes_per_packet );
+        MP4_GET4BYTES( p_box->data.p_sample_soun->i_bytes_per_frame );
+        MP4_GET4BYTES( p_box->data.p_sample_soun->i_bytes_per_sample );
+
+#ifdef MP4_VERBOSE
+        msg_Dbg( p_stream->p_input,
+                 "Read Box: \"soun\" qt3+ sample/packet=%d bytes/packet=%d bytes/frame=%d bytes/sample=%d",
+                 p_box->data.p_sample_soun->i_sample_per_packet, p_box->data.p_sample_soun->i_bytes_per_packet,
+                 p_box->data.p_sample_soun->i_bytes_per_frame, p_box->data.p_sample_soun->i_bytes_per_sample );
+#endif
+        MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 44 );
+    }
+    else
+    {
+        p_box->data.p_sample_soun->i_sample_per_packet = 0;
+        p_box->data.p_sample_soun->i_bytes_per_packet = 0;
+        p_box->data.p_sample_soun->i_bytes_per_frame = 0;
+        p_box->data.p_sample_soun->i_bytes_per_sample = 0;
+
+        msg_Dbg( p_stream->p_input, "Read Box: \"soun\" mp4 or qt1/2 (rest="I64Fd")", i_read );
+        MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) + 28 );
+    }
     MP4_ReadBoxContainerRaw( p_stream, p_box ); /* esds */
 
 #ifdef MP4_VERBOSE
     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
@@ -1232,7 +1269,7 @@ int MP4_ReadBox_sample_soun( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 #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 );
 
@@ -1254,7 +1291,7 @@ int MP4_ReadBox_sample_mp4a( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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 */
 
@@ -1262,7 +1299,7 @@ int MP4_ReadBox_sample_mp4a( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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
@@ -1272,7 +1309,7 @@ int MP4_ReadBox_sample_mp4a( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
 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 );
 
@@ -1293,7 +1330,7 @@ int MP4_ReadBox_sample_vide( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     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 );
 
@@ -1305,10 +1342,10 @@ int MP4_ReadBox_sample_vide( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     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,
@@ -1329,7 +1366,7 @@ int MP4_ReadBox_stsd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     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 );
 
@@ -1347,16 +1384,16 @@ int MP4_ReadBox_stsz( MP4_Stream_t *p_stream, MP4_Box_t *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++ )
@@ -1364,9 +1401,8 @@ int MP4_ReadBox_stsz( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
             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 );
@@ -1383,18 +1419,18 @@ void MP4_FreeBox_stsz( input_thread_t *p_input, MP4_Box_t *p_box )
 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++ )
@@ -1403,9 +1439,8 @@ int MP4_ReadBox_stsc( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         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 );
 
@@ -1423,14 +1458,14 @@ void MP4_FreeBox_stsc( input_thread_t *p_input, MP4_Box_t *p_box )
 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++ )
@@ -1452,9 +1487,8 @@ int MP4_ReadBox_stco_co64( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
             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 );
 
@@ -1470,14 +1504,14 @@ void MP4_FreeBox_stco_co64( input_thread_t *p_input, MP4_Box_t *p_box )
 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++ )
@@ -1487,9 +1521,8 @@ int MP4_ReadBox_stss( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         /* 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 );
 
@@ -1505,7 +1538,7 @@ void MP4_FreeBox_stss( input_thread_t *p_input, MP4_Box_t *p_box )
 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 );
@@ -1513,10 +1546,10 @@ int MP4_ReadBox_stsh( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     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 );
 
 
@@ -1526,9 +1559,8 @@ int MP4_ReadBox_stsh( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         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
@@ -1545,12 +1577,12 @@ void MP4_FreeBox_stsh( input_thread_t *p_input, MP4_Box_t *p_box )
 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++ )
@@ -1558,9 +1590,8 @@ int MP4_ReadBox_stdp( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
         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 );
 
@@ -1576,7 +1607,7 @@ void MP4_FreeBox_stdp( input_thread_t *p_input, MP4_Box_t *p_box )
 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 );
@@ -1584,13 +1615,13 @@ int MP4_ReadBox_padb( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     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 );
 
 
@@ -1603,9 +1634,8 @@ int MP4_ReadBox_padb( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
         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 );
 
@@ -1624,7 +1654,7 @@ void MP4_FreeBox_padb( input_thread_t *p_input, MP4_Box_t *p_box )
 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 );
@@ -1638,7 +1668,7 @@ int MP4_ReadBox_elst( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         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 );
 
 
@@ -1662,9 +1692,8 @@ int MP4_ReadBox_elst( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         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 );
 
@@ -1684,18 +1713,18 @@ int MP4_ReadBox_cprt( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 {
     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
@@ -1718,17 +1747,13 @@ void MP4_FreeBox_cprt( input_thread_t *p_input, MP4_Box_t *p_box )
 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 );
 }
 
@@ -1736,29 +1761,28 @@ int MP4_ReadBox_cmvd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 {
     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 )
@@ -1771,14 +1795,14 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, 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 ) ) ) )
@@ -1787,7 +1811,7 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
         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 ) )
     {
@@ -1799,7 +1823,7 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     {
         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 ) )
@@ -1810,11 +1834,8 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     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 );
     }
 
@@ -1822,12 +1843,12 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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 );
     }
@@ -1843,7 +1864,7 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     /* 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 );
@@ -1853,7 +1874,7 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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 );
@@ -1861,16 +1882,16 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
     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)" );
     }
 
@@ -1879,24 +1900,27 @@ int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
     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" );
 
+    //DataDump( p_data, p_cmvd->data.p_cmvd->i_uncompressed_size );
     /* 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 );
 
+    //DataDump( p_stream_memory->p_buffer, p_stream_memory->i_stop );
+
     /* 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 );
@@ -1928,9 +1952,8 @@ int MP4_ReadBox_rdrf( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
 #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
@@ -1984,9 +2007,8 @@ int MP4_ReadBox_rmvc( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 
 #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
@@ -2001,7 +2023,7 @@ int MP4_ReadBox_rmvc( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
 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 [] =
 {
@@ -2059,23 +2081,46 @@ static struct
 
     /* for codecs */
     { FOURCC_soun,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
-    { FOURCC__mp3,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_ms02,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_ms11,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
     { FOURCC_ms55,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC__mp3,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
     { FOURCC_mp4a,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_twos,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_sowt,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_QDMC,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_QDM2,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_ima4,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_IMA4,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_dvi,   MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_alaw,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_ulaw,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_raw,   MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_MAC3,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
+    { FOURCC_MAC6,  MP4_ReadBox_sample_soun,    MP4_FreeBox_Common },
 
     { FOURCC_vide,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_mp4v,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_SVQ1,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+    { FOURCC_SVQ3,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_DIVX,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_h263,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_cvid,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_3IV1,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+    { FOURCC_3iv1,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_3IV2,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+    { FOURCC_3iv2,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+    { FOURCC_3IVD,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+    { FOURCC_3ivd,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+    { FOURCC_3VID,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+    { FOURCC_3vid,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_mjpa,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_mjpb,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
     { FOURCC_mjqt,  NULL,                       NULL }, /* found in mjpa/b */
     { FOURCC_mjht,  NULL,                       NULL },
+    { FOURCC_dvc,   MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+    { FOURCC_dvp,   MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
+
     { FOURCC_jpeg,  MP4_ReadBox_sample_vide,    MP4_FreeBox_Common },
 
     { FOURCC_mp4s,  NULL,                       MP4_FreeBox_Common },
@@ -2104,14 +2149,14 @@ static struct
 
 
 /*****************************************************************************
- * 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" );
@@ -2136,16 +2181,13 @@ int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father )
     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 );
     }
 
@@ -2157,14 +2199,14 @@ int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father )
 }
 #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 );
@@ -2175,12 +2217,12 @@ int MP4_CountBox( MP4_Box_t *p_box, uint32_t i_type )
     while( p_child )
     {
         if( p_child->i_type == i_type )
-        {   
+        {
             i_count++;
         }
         p_child = p_child->p_next;
     }
-    
+
     return( i_count );
 }
 #endif
@@ -2193,7 +2235,7 @@ int MP4_CountBox( MP4_Box_t *p_box, uint32_t i_type )
 MP4_Box_t *MP4_FindBox( MP4_Box_t *p_box, uint32_t i_type )
 {
     MP4_Box_t *p_child;
-    
+
     if( !p_box )
     {
         return( NULL );
@@ -2203,25 +2245,25 @@ MP4_Box_t *MP4_FindBox( MP4_Box_t *p_box, uint32_t i_type )
     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 );
@@ -2244,7 +2286,7 @@ MP4_Box_t *MP4_FindNextBox( MP4_Box_t *p_box )
 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 );
@@ -2263,7 +2305,7 @@ MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number )
 #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 )
@@ -2284,7 +2326,7 @@ 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 */
@@ -2301,12 +2343,9 @@ void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box )
         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
         {
@@ -2319,21 +2358,20 @@ void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box )
 
     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' );
@@ -2346,27 +2384,27 @@ int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root )
     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;
@@ -2390,11 +2428,8 @@ static void __MP4_BoxDumpStructure( input_thread_t *p_input,
 
     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
     {
@@ -2405,13 +2440,10 @@ static void __MP4_BoxDumpStructure( input_thread_t *p_input,
         {
             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;
@@ -2420,7 +2452,6 @@ static void __MP4_BoxDumpStructure( input_thread_t *p_input,
         __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 )
@@ -2447,7 +2478,7 @@ static void __get_token( char **ppsz_path, char **ppsz_token, int *pi_number )
         return;
     }
     i_len = 0;
-    while(  (*ppsz_path)[i_len] && 
+    while(  (*ppsz_path)[i_len] &&
             (*ppsz_path)[i_len] != '/' && (*ppsz_path)[i_len] != '[' )
     {
         i_len++;
@@ -2457,13 +2488,13 @@ static void __get_token( char **ppsz_path, char **ppsz_token, int *pi_number )
         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)++;
@@ -2495,7 +2526,6 @@ static void __MP4_BoxGet( MP4_Box_t **pp_result,
     size_t  i_size;
 #endif
 
-    
     if( !p_box )
     {
         *pp_result = NULL;
@@ -2526,7 +2556,7 @@ static void __MP4_BoxGet( MP4_Box_t **pp_result,
         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 )
         {
@@ -2624,10 +2654,9 @@ static void __MP4_BoxGet( MP4_Box_t **pp_result,
             *pp_result = NULL;
             return;
         }
-        
+
         free( psz_token );
     }
-    
 }
 
 /*****************************************************************************
@@ -2635,7 +2664,7 @@ static void __MP4_BoxGet( MP4_Box_t **pp_result,
  *****************************************************************************
  * Path Format: . .. / as usual
  *              [number] to specifie box number ex: trak[12]
- *              
+ *
  * ex: /moov/trak[12]
  *     ../mdia
  *****************************************************************************/
@@ -2644,7 +2673,7 @@ MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, char *psz_fmt, ... )
     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 );
 
@@ -2656,7 +2685,7 @@ MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, char *psz_fmt, ... )
  *****************************************************************************
  * Path Format: . .. / as usual
  *              [number] to specifie box number ex: trak[12]
- *              
+ *
  * ex: /moov/trak[12]
  *     ../mdia
  *****************************************************************************/
@@ -2666,14 +2695,14 @@ int MP4_BoxCount( MP4_Box_t *p_box, char *psz_fmt, ... )
     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)
     {