Commit 2171d2e9 authored by Laurent Aimar's avatar Laurent Aimar

* all: clean up.

parent e40e6065
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* libmp4.c : LibMP4 library for mp4 module for vlc * libmp4.c : LibMP4 library for mp4 module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: libmp4.c,v 1.32 2003/09/07 22:48:29 fenrir Exp $ * $Id: libmp4.c,v 1.33 2003/09/08 00:35:16 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -20,10 +20,6 @@ ...@@ -20,10 +20,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/ *****************************************************************************/
#include <stdlib.h> /* malloc(), free() */ #include <stdlib.h> /* malloc(), free() */
#include <stdarg.h>
#include <string.h> /* strdup() */
#include <errno.h>
#include <sys/types.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/input.h> #include <vlc/input.h>
...@@ -38,8 +34,6 @@ ...@@ -38,8 +34,6 @@
* Here are defined some macro to make life simpler but before using it * Here are defined some macro to make life simpler but before using it
* *look* at the code. * *look* at the code.
* *
* XXX: All macro are written in capital letters
*
*****************************************************************************/ *****************************************************************************/
#define MP4_BOX_HEADERSIZE( p_box ) \ #define MP4_BOX_HEADERSIZE( p_box ) \
( 8 + ( p_box->i_shortsize == 1 ? 8 : 0 ) \ ( 8 + ( p_box->i_shortsize == 1 ? 8 : 0 ) \
...@@ -122,16 +116,14 @@ ...@@ -122,16 +116,14 @@
*/ */
static uint32_t Get24bBE( uint8_t *p_buff ) static uint32_t Get24bBE( uint8_t *p )
{ {
return( ( p_buff[0] <<16 ) + ( p_buff[1] <<8 ) + p_buff[2] ); return( ( p[0] <<16 ) + ( p[1] <<8 ) + p[2] );
} }
static void GetUUID( UUID_t *p_uuid, uint8_t *p_buff ) static void GetUUID( UUID_t *p_uuid, uint8_t *p_buff )
{ {
memcpy( p_uuid, memcpy( p_uuid, p_buff, 16 );
p_buff,
16 );
} }
static void CreateUUID( UUID_t *p_uuid, uint32_t i_fourcc ) static void CreateUUID( UUID_t *p_uuid, uint32_t i_fourcc )
...@@ -143,39 +135,28 @@ static void CreateUUID( UUID_t *p_uuid, uint32_t i_fourcc ) ...@@ -143,39 +135,28 @@ static void CreateUUID( UUID_t *p_uuid, uint32_t i_fourcc )
/* some functions for mp4 encoding of variables */ /* some functions for mp4 encoding of variables */
void MP4_ConvertDate2Str( char *psz, uint64_t i_date ) static void MP4_ConvertDate2Str( char *psz, uint64_t i_date )
{ {
int i_day; int i_day;
int i_hour; int i_hour;
int i_min; int i_min;
int i_sec; int i_sec;
/* date begin at 1 jan 1904 */
i_date += ((1904ULL * 365) + 17) * 24 * 60 * 60;
i_day = i_date / ( 60*60*24); i_day = i_date / ( 60*60*24);
i_hour = ( i_date /( 60*60 ) ) % 60; i_hour = ( i_date /( 60*60 ) ) % 60;
i_min = ( i_date / 60 ) % 60; i_min = ( i_date / 60 ) % 60;
i_sec = i_date % 60; i_sec = i_date % 60;
/* FIXME do it correctly, date begin at 1 jan 1904 */
sprintf( psz, "%dd-%2.2dh:%2.2dm:%2.2ds", sprintf( psz, "%dd-%2.2dh:%2.2dm:%2.2ds",
i_day, i_hour, i_min, i_sec ); i_day, i_hour, i_min, i_sec );
} }
#if 0 /*****************************************************************************
static void DataDump( uint8_t *p_data, int i_data ) * Some prototypes.
{ *****************************************************************************/
int i; static MP4_Box_t *MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_father );
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 * Some basic functions to manipulate stream more easily in vlc
...@@ -187,7 +168,7 @@ static void DataDump( uint8_t *p_data, int i_data ) ...@@ -187,7 +168,7 @@ static void DataDump( uint8_t *p_data, int i_data )
* MP4_ReadData read data from the file in a buffer * MP4_ReadData read data from the file in a buffer
* *
*****************************************************************************/ *****************************************************************************/
off_t MP4_TellAbsolute( input_thread_t *p_input ) static off_t MP4_TellAbsolute( input_thread_t *p_input )
{ {
off_t i_pos; off_t i_pos;
...@@ -200,8 +181,7 @@ off_t MP4_TellAbsolute( input_thread_t *p_input ) ...@@ -200,8 +181,7 @@ off_t MP4_TellAbsolute( input_thread_t *p_input )
return( i_pos ); return( i_pos );
} }
int MP4_SeekAbsolute( input_thread_t *p_input, static int MP4_SeekAbsolute( input_thread_t *p_input, off_t i_pos)
off_t i_pos)
{ {
off_t i_filepos; off_t i_filepos;
...@@ -267,7 +247,7 @@ int MP4_SeekAbsolute( input_thread_t *p_input, ...@@ -267,7 +247,7 @@ int MP4_SeekAbsolute( input_thread_t *p_input,
} }
/* return 1 if success, 0 if fail */ /* return 1 if success, 0 if fail */
int MP4_ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size ) static int MP4_ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size )
{ {
data_packet_t *p_data; data_packet_t *p_data;
...@@ -462,7 +442,7 @@ int MP4_SeekStream( MP4_Stream_t *p_stream, off_t i_pos) ...@@ -462,7 +442,7 @@ int MP4_SeekStream( MP4_Stream_t *p_stream, off_t i_pos)
* *
* RETURN : 0 if it fail, 1 otherwise * RETURN : 0 if it fail, 1 otherwise
*****************************************************************************/ *****************************************************************************/
int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) static int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{ {
int i_read; int i_read;
uint8_t *p_peek; uint8_t *p_peek;
...@@ -523,7 +503,7 @@ int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -523,7 +503,7 @@ int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
***************************************************************************** *****************************************************************************
* if p_box == NULL, go to the next box in witch we are( at the begining ). * if p_box == NULL, go to the next box in witch we are( at the begining ).
*****************************************************************************/ *****************************************************************************/
int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) static int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{ {
MP4_Box_t box; MP4_Box_t box;
...@@ -549,16 +529,6 @@ int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -549,16 +529,6 @@ int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
} }
return( MP4_SeekStream( p_stream, p_box->i_size + p_box->i_pos ) ? 0 : 1 ); return( MP4_SeekStream( p_stream, p_box->i_size + p_box->i_pos ) ? 0 : 1 );
} }
/*****************************************************************************
* MP4_MP4_GotoBox : Go to this particular box
*****************************************************************************
* RETURN : 0 if it fail, 1 otherwise
*****************************************************************************/
int MP4_GotoBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
return( MP4_SeekStream( p_stream, p_box->i_pos ) ? 0 : 1 );
}
/***************************************************************************** /*****************************************************************************
* For all known box a loader is given, * For all known box a loader is given,
...@@ -579,10 +549,10 @@ static int MP4_ReadBoxContainerRaw( MP4_Stream_t *p_stream, MP4_Box_t *p_contain ...@@ -579,10 +549,10 @@ static int MP4_ReadBoxContainerRaw( MP4_Stream_t *p_stream, MP4_Box_t *p_contain
do do
{ {
p_box = malloc( sizeof( MP4_Box_t ) ); if( ( p_box = MP4_ReadBox( p_stream, p_container ) ) == NULL )
if( MP4_ReadBox( p_stream, p_box , p_container ) )
{ {
break;
}
/* chain this box with the father and the other at same level */ /* chain this box with the father and the other at same level */
if( !p_container->p_first ) if( !p_container->p_first )
{ {
...@@ -593,15 +563,7 @@ static int MP4_ReadBoxContainerRaw( MP4_Stream_t *p_stream, MP4_Box_t *p_contain ...@@ -593,15 +563,7 @@ static int MP4_ReadBoxContainerRaw( MP4_Stream_t *p_stream, MP4_Box_t *p_contain
p_container->p_last->p_next = p_box; p_container->p_last->p_next = p_box;
} }
p_container->p_last = p_box; p_container->p_last = p_box;
} } while( MP4_NextBox( p_stream, p_box ) == 1 );
else
{
/* free memory */
free( p_box );
break;
}
}while( MP4_NextBox( p_stream, p_box ) == 1 );
return( 1 ); return( 1 );
} }
...@@ -1804,7 +1766,6 @@ static void MP4_FreeBox_cmvd( MP4_Box_t *p_box ) ...@@ -1804,7 +1766,6 @@ static void MP4_FreeBox_cmvd( MP4_Box_t *p_box )
static int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) static int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{ {
MP4_Stream_t *p_stream_memory; MP4_Stream_t *p_stream_memory;
MP4_Box_t *p_umov;
MP4_Box_t *p_dcom; MP4_Box_t *p_dcom;
MP4_Box_t *p_cmvd; MP4_Box_t *p_cmvd;
...@@ -1834,9 +1795,9 @@ static int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1834,9 +1795,9 @@ static int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
return( 0 ); return( 0 );
} }
if( !( p_dcom = MP4_FindBox( p_box, FOURCC_dcom ) )|| if( ( p_dcom = MP4_BoxGet( p_box, "dcom" ) ) == NULL ||
!( p_cmvd = MP4_FindBox( p_box, FOURCC_cmvd ) )|| ( p_cmvd = MP4_BoxGet( p_box, "cmvd" ) ) == NULL ||
!( p_cmvd->data.p_cmvd->p_data ) ) p_cmvd->data.p_cmvd->p_data == NULL )
{ {
msg_Warn( p_stream->p_input, "Read Box: \"cmov\" incomplete" ); msg_Warn( p_stream->p_input, "Read Box: \"cmov\" incomplete" );
return( 1 ); return( 1 );
...@@ -1913,27 +1874,21 @@ static int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1913,27 +1874,21 @@ static int MP4_ReadBox_cmov( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
msg_Dbg( p_stream->p_input, msg_Dbg( p_stream->p_input,
"Read Box: \"cmov\" box succesfully uncompressed" ); "Read Box: \"cmov\" box succesfully uncompressed" );
//DataDump( p_data, p_cmvd->data.p_cmvd->i_uncompressed_size );
/* now create a memory stream */ /* 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->i_uncompressed_size,
p_cmvd->data.p_cmvd->p_data ); p_cmvd->data.p_cmvd->p_data );
//DataDump( p_stream_memory->p_buffer, p_stream_memory->i_stop );
/* and read uncompressd moov */ /* and read uncompressd moov */
p_umov = malloc( sizeof( MP4_Box_t ) ); p_box->data.p_cmov->p_moov = MP4_ReadBox( p_stream_memory, NULL );
i_result = MP4_ReadBox( p_stream_memory, p_umov, NULL );
p_box->data.p_cmov->p_moov = p_umov;
free( p_stream_memory ); free( p_stream_memory );
#ifdef MP4_VERBOSE #ifdef MP4_VERBOSE
msg_Dbg( p_stream->p_input, msg_Dbg( p_stream->p_input,
"Read Box: \"cmov\" compressed movie header completed" ); "Read Box: \"cmov\" compressed movie header completed" );
#endif #endif
return( i_result ); return( p_box->data.p_cmov->p_moov ? 1 : 0 );
#endif /* HAVE_ZLIB_H */ #endif /* HAVE_ZLIB_H */
} }
...@@ -2171,20 +2126,22 @@ static struct ...@@ -2171,20 +2126,22 @@ 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 * 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 ) static MP4_Box_t *MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_father )
{ {
int i_result; MP4_Box_t *p_box = malloc( sizeof( MP4_Box_t ) );
unsigned int i_index; unsigned int i_index;
if( !MP4_ReadBoxCommon( p_stream, p_box ) ) if( !MP4_ReadBoxCommon( p_stream, p_box ) )
{ {
msg_Warn( p_stream->p_input, "Cannot read one box" ); msg_Warn( p_stream->p_input, "Cannot read one box" );
return( 0 ); free( p_box );
return NULL;
} }
if( !p_box->i_size ) if( !p_box->i_size )
{ {
msg_Dbg( p_stream->p_input, "Found an empty box (null size)" ); msg_Dbg( p_stream->p_input, "Found an empty box (null size)" );
return( 0 ); free( p_box );
return NULL;
} }
p_box->p_father = p_father; p_box->p_father = p_father;
...@@ -2202,123 +2159,15 @@ int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father ) ...@@ -2202,123 +2159,15 @@ int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father )
msg_Warn( p_stream->p_input, msg_Warn( p_stream->p_input,
"Unknown box type %4.4s (uncompletetly loaded)", "Unknown box type %4.4s (uncompletetly loaded)",
(char*)&p_box->i_type ); (char*)&p_box->i_type );
return( 1 );
}
else
{
i_result =
(MP4_Box_Function[i_index].MP4_ReadBox_function)( p_stream, p_box );
}
return( i_result );
}
#if 0
/*****************************************************************************
* 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 );
} }
else if( !(MP4_Box_Function[i_index].MP4_ReadBox_function)( p_stream, p_box ) )
i_count = 0;
p_child = p_box->p_first;
while( p_child )
{ {
if( p_child->i_type == i_type ) free( p_box );
{ return NULL;
i_count++;
}
p_child = p_child->p_next;
}
return( i_count );
}
#endif
/*****************************************************************************
* MP4_FindBox: find first box with i_type child of p_box
* return NULL if not found
*****************************************************************************/
MP4_Box_t *MP4_FindBox( MP4_Box_t *p_box, uint32_t i_type )
{
MP4_Box_t *p_child;
if( !p_box )
{
return( NULL );
}
p_child = p_box->p_first;
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
* than p_box
*****************************************************************************/
MP4_Box_t *MP4_FindNextBox( MP4_Box_t *p_box )
{
MP4_Box_t *p_next;
if( !p_box )
{
return( NULL );
}
p_next = p_box->p_next;
while( p_next )
{
if( p_next->i_type == p_box->i_type )
{
return( p_next );
}
p_next = p_next->p_next;
}
return( NULL );
}
/*****************************************************************************
* MP4_FindNbBox: find the box i_number
*****************************************************************************/
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 );
} }
while( i_number ) return p_box;
{
if( !( p_child = p_child->p_next ) )
{
return( NULL );
}
i_number--;
}
return( p_child );
} }
#endif
/***************************************************************************** /*****************************************************************************
* MP4_FreeBox : free memory after read with MP4_ReadBox and all * MP4_FreeBox : free memory after read with MP4_ReadBox and all
...@@ -2327,21 +2176,19 @@ MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number ) ...@@ -2327,21 +2176,19 @@ MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number )
void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box ) void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box )
{ {
unsigned int i_index; unsigned int i_index;
MP4_Box_t *p_child; MP4_Box_t *p_child;
MP4_Box_t *p_next;
if( !p_box ) if( !p_box )
{ {
return; /* hehe */ return; /* hehe */
} }
p_child = p_box->p_first;
while( p_child ) for( p_child = p_box->p_first; p_child != NULL; )
{ {
MP4_Box_t *p_next;
p_next = p_child->p_next; p_next = p_child->p_next;
MP4_BoxFree( p_input, p_child ); 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;
} }
...@@ -2369,12 +2216,9 @@ void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box ) ...@@ -2369,12 +2216,9 @@ void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box )
} }
free( p_box->data.p_data ); free( p_box->data.p_data );
p_box->data.p_data = NULL;
} }
p_box->p_first = NULL; free( p_box );
p_box->p_last = NULL;
} }
/***************************************************************************** /*****************************************************************************
...@@ -2383,12 +2227,13 @@ void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box ) ...@@ -2383,12 +2227,13 @@ void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box )
* 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 * level boxes for the file, a sort of virtual contener
*****************************************************************************/ *****************************************************************************/
int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root ) MP4_Box_t *MP4_BoxGetRoot( input_thread_t *p_input )
{ {
MP4_Box_t *p_root;
MP4_Stream_t *p_stream; MP4_Stream_t *p_stream;
int i_result; int i_result;
MP4_SeekAbsolute( p_input, 0 ); /* Go to the begining */ p_root = malloc( sizeof( MP4_Box_t ) );
p_root->i_pos = 0; p_root->i_pos = 0;
p_root->i_type = VLC_FOURCC( 'r', 'o', 'o', 't' ); p_root->i_type = VLC_FOURCC( 'r', 'o', 'o', 't' );
p_root->i_shortsize = 1; p_root->i_shortsize = 1;
...@@ -2415,10 +2260,10 @@ int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root ) ...@@ -2415,10 +2260,10 @@ int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root )
/* check if there is a cmov, if so replace /* check if there is a cmov, if so replace
compressed moov by uncompressed one */ compressed moov by uncompressed one */
if( ( ( p_moov = MP4_FindBox( p_root, FOURCC_moov ) )&& if( ( ( p_moov = MP4_BoxGet( p_root, "moov" ) ) &&
( p_cmov = MP4_FindBox( p_moov, FOURCC_cmov ) ) ) || ( p_cmov = MP4_BoxGet( p_root, "moov/cmov" ) ) ) ||
( ( p_moov = MP4_FindBox( p_root, FOURCC_foov ) )&& ( ( p_moov = MP4_BoxGet( p_root, "foov" ) ) &&
( p_cmov = MP4_FindBox( p_moov, FOURCC_cmov ) ) ) ) ( p_cmov = MP4_BoxGet( p_root, "foov/cmov" ) ) ) )
{ {
/* rename the compressed moov as a box to skip */ /* rename the compressed moov as a box to skip */
p_moov->i_type = FOURCC_skip; p_moov->i_type = FOURCC_skip;
...@@ -2435,7 +2280,8 @@ int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root ) ...@@ -2435,7 +2280,8 @@ int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root )
p_root->p_first = p_moov; p_root->p_first = p_moov;
} }
} }
return( i_result );
return p_root;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* libmp4.h : LibMP4 library for mp4 module for vlc * libmp4.h : LibMP4 library for mp4 module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: libmp4.h,v 1.15 2003/08/17 20:45:50 fenrir Exp $ * $Id: libmp4.h,v 1.16 2003/09/08 00:35:16 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -776,35 +776,21 @@ typedef struct MP4_Box_s ...@@ -776,35 +776,21 @@ typedef struct MP4_Box_s
} MP4_Box_t; } MP4_Box_t;
/*---------------------------------------------------------------------------*/
/* */
/****----------------------- High level functions ------------------------****/
/* */
/*---------------------------------------------------------------------------*/
/*****************************************************************************
* Function for manipulate stream easily
*****************************************************************************/
off_t MP4_TellAbsolute( input_thread_t *p_input );
int MP4_SeekAbsolute( input_thread_t *p_input, off_t i_pos);
int MP4_ReadData( input_thread_t *p_input, uint8_t *p_buff, int i_size );
/***************************************************************************** /*****************************************************************************
* MP4_BoxGetRoot : Parse the entire file, and create all boxes in memory * 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 * level boxes
*
* RETURN : 1 if succes and 0 if it failed
*****************************************************************************/ *****************************************************************************/
int MP4_BoxGetRoot( input_thread_t *p_input, MP4_Box_t *p_root ); MP4_Box_t *MP4_BoxGetRoot( input_thread_t *p_input );
/***************************************************************************** /*****************************************************************************
* MP4_FreeBox : free memory allocated after read with MP4_ReadBox * MP4_FreeBox : free memory allocated after read with MP4_ReadBox
* or MP4_BoxGetRoot, this means also children boxes * or MP4_BoxGetRoot, this means also children boxes
* XXX : all children have to be allocated by a malloc !! and * XXX : all children have to be allocated by a malloc !! and
* p_box isn't freeing * p_box is freed
*****************************************************************************/ *****************************************************************************/
void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box ); void MP4_BoxFree( input_thread_t *p_input, MP4_Box_t *p_box );
...@@ -838,125 +824,3 @@ MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, char *psz_fmt, ... ); ...@@ -838,125 +824,3 @@ MP4_Box_t *MP4_BoxGet( MP4_Box_t *p_box, char *psz_fmt, ... );
*****************************************************************************/ *****************************************************************************/
int MP4_BoxCount( MP4_Box_t *p_box, char *psz_fmt, ... ); int MP4_BoxCount( MP4_Box_t *p_box, char *psz_fmt, ... );
/*---------------------------------------------------------------------------*/
/* */
/****---------------------- Medium level functions -----------------------****/
/* */
/*---------------------------------------------------------------------------*/
#if 0
/*****************************************************************************
* 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 );
#endif
/*****************************************************************************
* MP4_FindBox: find first box with i_type child of p_box
* return NULL if not found
*****************************************************************************/
MP4_Box_t *MP4_FindBox( MP4_Box_t *p_box, uint32_t i_type );
#if 0
/*****************************************************************************
* 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_FindNbBox: find the box i_number
*****************************************************************************/
MP4_Box_t *MP4_FindNbBox( MP4_Box_t *p_box, uint32_t i_number );
#endif
/*---------------------------------------------------------------------------*/
/****----------------------- Lower level functions -----------------------****/
/**** ****/
/****------Use them only when you known what they really do and need------****/
/**** ****/
/****---------------------------------------------------------------------****/
/*---------------------------------------------------------------------------*/
/**** ------- First some function to make abstract from input -------- */
/****************************************************************************
* MP4_InputStream create an stram with an input
*
****************************************************************************/
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
* it uses p_buffer XXX you have to unallocate yourself !
*
****************************************************************************/
MP4_Stream_t *MP4_MemoryStream( input_thread_t *p_input,
int i_size, uint8_t *p_buffer );
/****************************************************************************
* MP4_ReadStream read from a MP4_Stream_t
*
****************************************************************************/
int MP4_ReadStream( MP4_Stream_t *p_stream, uint8_t *p_buff, int i_size );
/****************************************************************************
* MP4_PeekStream guess it ;)
*
****************************************************************************/
int MP4_PeekStream( MP4_Stream_t *p_stream, uint8_t **pp_peek, int i_size );
/****************************************************************************
* MP4_TellStream give absolute position in the stream
* XXX for a memory stream give position from begining of the buffer
****************************************************************************/
off_t MP4_TellStream( MP4_Stream_t *p_stream );
/****************************************************************************
* MP4_SeekStream seek in a MP4_Stream_t
*
****************************************************************************/
int MP4_SeekStream( MP4_Stream_t *p_stream, off_t i_pos);
/*****************************************************************************
* MP4_ReadBox : parse the actual box and the children if they exist
*
* RETURN : 1 if succes and 0 if it failed
*****************************************************************************/
int MP4_ReadBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box, MP4_Box_t *p_father );
/*****************************************************************************
* MP4_ReadBoxCommon : Load only common parameters for all boxes
*****************************************************************************
* p_box need to be an already allocated MP4_Box_t, and all data
* will only be peek not read
*
* RETURN : 0 if it fail, 1 otherwise
*****************************************************************************/
int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
/*****************************************************************************
* MP4_MP4_GotoBox : Go to this particular box
*****************************************************************************
* RETURN : 0 if it fail, 1 otherwise
*****************************************************************************/
int MP4_GotoBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
/*****************************************************************************
* MP4_MP4_NextBox : Go to the next box wiithin p_box->p_father
*****************************************************************************
* if p_box == NULL, go to the next box in witch we are( at the begining ).
*****************************************************************************/
int MP4_NextBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box );
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mp4.c : MP4 file input module for vlc * mp4.c : MP4 file input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: mp4.c,v 1.35 2003/09/07 22:48:29 fenrir Exp $ * $Id: mp4.c,v 1.36 2003/09/08 00:35:16 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -138,21 +138,28 @@ static int Open( vlc_object_t * p_this ) ...@@ -138,21 +138,28 @@ static int Open( vlc_object_t * p_this )
p_input->pf_demux = Demux; p_input->pf_demux = Demux;
p_input->pf_demux_control = Control; p_input->pf_demux_control = Control;
/* create our structure that will contains all data */ /* create our structure that will contains all data */
p_input->p_demux_data = p_demux = malloc( sizeof( demux_sys_t ) ); p_input->p_demux_data = p_demux = malloc( sizeof( demux_sys_t ) );
memset( p_demux, 0, sizeof( demux_sys_t ) ); memset( p_demux, 0, sizeof( demux_sys_t ) );
/* Create stream facilities */
if( ( p_demux->s= stream_OpenInput( p_input ) ) == NULL )
{
msg_Err( p_input, "cannot create stream_t" );
free( p_demux );
return VLC_EGENERIC;
}
/* Now load all boxes ( except raw data ) */ /* Now load all boxes ( except raw data ) */
if( !MP4_BoxGetRoot( p_input, &p_demux->box_root ) ) if( ( p_demux->p_root = MP4_BoxGetRoot( p_input ) ) == NULL )
{ {
msg_Warn( p_input, "MP4 plugin discarded (not a valid file)" ); msg_Warn( p_input, "MP4 plugin discarded (not a valid file)" );
return VLC_EGENERIC; goto error;
} }
MP4_BoxDumpStructure( p_input, &p_demux->box_root ); MP4_BoxDumpStructure( p_input, p_demux->p_root );
if( ( p_ftyp = MP4_BoxGet( &p_demux->box_root, "/ftyp" ) ) ) if( ( p_ftyp = MP4_BoxGet( p_demux->p_root, "/ftyp" ) ) )
{ {
switch( p_ftyp->data.p_ftyp->i_major_brand ) switch( p_ftyp->data.p_ftyp->i_major_brand )
{ {
...@@ -174,9 +181,9 @@ static int Open( vlc_object_t * p_this ) ...@@ -174,9 +181,9 @@ static int Open( vlc_object_t * p_this )
} }
/* the file need to have one moov box */ /* the file need to have one moov box */
if( MP4_BoxCount( &p_demux->box_root, "/moov" ) <= 0 ) if( MP4_BoxCount( p_demux->p_root, "/moov" ) <= 0 )
{ {
MP4_Box_t *p_foov = MP4_BoxGet( &p_demux->box_root, "/foov" ); MP4_Box_t *p_foov = MP4_BoxGet( p_demux->p_root, "/foov" );
if( !p_foov ) if( !p_foov )
{ {
...@@ -187,7 +194,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -187,7 +194,7 @@ static int Open( vlc_object_t * p_this )
p_foov->i_type = FOURCC_moov; p_foov->i_type = FOURCC_moov;
} }
if( ( p_rmra = MP4_BoxGet( &p_demux->box_root, "/moov/rmra" ) ) ) if( ( p_rmra = MP4_BoxGet( p_demux->p_root, "/moov/rmra" ) ) )
{ {
playlist_t *p_playlist; playlist_t *p_playlist;
int i_count = MP4_BoxCount( p_rmra, "rmda" ); int i_count = MP4_BoxCount( p_rmra, "rmda" );
...@@ -267,7 +274,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -267,7 +274,7 @@ static int Open( vlc_object_t * p_this )
} }
} }
if( !(p_mvhd = MP4_BoxGet( &p_demux->box_root, "/moov/mvhd" ) ) ) if( !(p_mvhd = MP4_BoxGet( p_demux->p_root, "/moov/mvhd" ) ) )
{ {
if( !p_rmra ) if( !p_rmra )
{ {
...@@ -288,7 +295,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -288,7 +295,7 @@ static int Open( vlc_object_t * p_this )
} }
if( !( p_demux->i_tracks = if( !( p_demux->i_tracks =
MP4_BoxCount( &p_demux->box_root, "/moov/trak" ) ) ) MP4_BoxCount( p_demux->p_root, "/moov/trak" ) ) )
{ {
msg_Err( p_input, "cannot find any /moov/trak" ); msg_Err( p_input, "cannot find any /moov/trak" );
goto error; goto error;
...@@ -332,7 +339,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -332,7 +339,7 @@ static int Open( vlc_object_t * p_this )
/* now process each track and extract all usefull informations */ /* now process each track and extract all usefull informations */
for( i = 0; i < p_demux->i_tracks; i++ ) for( i = 0; i < p_demux->i_tracks; i++ )
{ {
p_trak = MP4_BoxGet( &p_demux->box_root, "/moov/trak[%d]", i ); p_trak = MP4_BoxGet( p_demux->p_root, "/moov/trak[%d]", i );
MP4_TrackCreate( p_input, &p_demux->track[i], p_trak ); MP4_TrackCreate( p_input, &p_demux->track[i], p_trak );
if( p_demux->track[i].b_ok ) if( p_demux->track[i].b_ok )
...@@ -391,7 +398,12 @@ static int Open( vlc_object_t * p_this ) ...@@ -391,7 +398,12 @@ static int Open( vlc_object_t * p_this )
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
Close( VLC_OBJECT( p_input ) ); stream_Release( p_demux->s );
if( p_demux->p_root )
{
MP4_BoxFree( p_input, p_demux->p_root );
}
free( p_demux );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -491,7 +503,6 @@ static int Demux( input_thread_t *p_input ) ...@@ -491,7 +503,6 @@ static int Demux( input_thread_t *p_input )
size_t i_size; size_t i_size;
off_t i_pos; off_t i_pos;
data_packet_t *p_data;
pes_packet_t *p_pes; pes_packet_t *p_pes;
/* caculate size and position for this sample */ /* caculate size and position for this sample */
...@@ -502,44 +513,20 @@ static int Demux( input_thread_t *p_input ) ...@@ -502,44 +513,20 @@ static int Demux( input_thread_t *p_input )
//msg_Dbg( p_input, "stream %d size=%6d pos=%8lld", i_track, i_size, i_pos ); //msg_Dbg( p_input, "stream %d size=%6d pos=%8lld", i_track, i_size, i_pos );
/* go,go go ! */ /* go,go go ! */
if( MP4_SeekAbsolute( p_input, i_pos ) ) if( stream_Seek( p_demux->s, i_pos ) )
{ {
msg_Warn( p_input, "track[0x%x] will be disabled (eof?)", track.i_track_ID ); msg_Warn( p_input, "track[0x%x] will be disabled (eof?)", track.i_track_ID );
MP4_TrackUnselect( p_input, &track ); MP4_TrackUnselect( p_input, &track );
break; break;
} }
/* now read pes */
/* now create a pes */ if( ( p_pes = stream_PesPacket( p_demux->s, i_size ) ) == NULL )
if( !(p_pes = input_NewPES( p_input->p_method_data ) ) )
{ {
break;
}
/* and a data packet for the data */
if( !(p_data = input_NewPacket( p_input->p_method_data, i_size ) ) )
{
input_DeletePES( p_input->p_method_data, p_pes );
break;
}
p_data->p_payload_end = p_data->p_payload_start + i_size;
/* initialisation of all the field */
p_pes->i_dts = p_pes->i_pts = 0;
p_pes->p_first = p_pes->p_last = p_data;
p_pes->i_nb_data = 1;
p_pes->i_pes_size = i_size;
if( i_size > 0 )
{
if( MP4_ReadData( p_input, p_data->p_payload_start, i_size ) )
{
input_DeletePES( p_input->p_method_data, p_pes );
msg_Warn( p_input, "track[0x%x] will be disabled (eof?)", track.i_track_ID ); msg_Warn( p_input, "track[0x%x] will be disabled (eof?)", track.i_track_ID );
MP4_TrackUnselect( p_input, &track ); MP4_TrackUnselect( p_input, &track );
break; break;
} }
}
p_pes->i_dts = p_pes->i_dts =
p_pes->i_pts = input_ClockGetTS( p_input, p_pes->i_pts = input_ClockGetTS( p_input,
p_input->stream.p_selected_program, p_input->stream.p_selected_program,
...@@ -657,7 +644,8 @@ static void Close ( vlc_object_t * p_this ) ...@@ -657,7 +644,8 @@ static void Close ( vlc_object_t * p_this )
demux_sys_t *p_demux = p_input->p_demux_data; demux_sys_t *p_demux = p_input->p_demux_data;
msg_Dbg( p_input, "freeing all memory" ); msg_Dbg( p_input, "freeing all memory" );
MP4_BoxFree( p_input, &p_demux->box_root );
MP4_BoxFree( p_input, p_demux->p_root );
for( i_track = 0; i_track < p_demux->i_tracks; i_track++ ) for( i_track = 0; i_track < p_demux->i_tracks; i_track++ )
{ {
MP4_TrackDestroy( p_input, &p_demux->track[i_track] ); MP4_TrackDestroy( p_input, &p_demux->track[i_track] );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mp4.h : MP4 file input module for vlc * mp4.h : MP4 file input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: mp4.h,v 1.6 2003/03/11 18:57:51 fenrir Exp $ * $Id: mp4.h,v 1.7 2003/09/08 00:35:16 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -127,7 +127,9 @@ typedef struct track_data_mp4_s ...@@ -127,7 +127,9 @@ typedef struct track_data_mp4_s
*****************************************************************************/ *****************************************************************************/
struct demux_sys_t struct demux_sys_t
{ {
MP4_Box_t box_root; /* container for the whole file */ stream_t *s;
MP4_Box_t *p_root; /* container for the whole file */
mtime_t i_pcr; mtime_t i_pcr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment