Commit f992190e authored by Gildas Bazin's avatar Gildas Bazin

* src/input/mem_stream.c: fixed a couple of bugs.

* modules/demux/mp4/libmp4.c: use stream_MemoryDelete() instead of free() + some coding style changes.
parent e3204a6d
...@@ -151,8 +151,7 @@ static void MP4_ConvertDate2Str( char *psz, uint64_t i_date ) ...@@ -151,8 +151,7 @@ static void MP4_ConvertDate2Str( char *psz, uint64_t i_date )
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;
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 );
} }
/***************************************************************************** /*****************************************************************************
...@@ -176,7 +175,7 @@ int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -176,7 +175,7 @@ int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box )
if( ( ( i_read = stream_Peek( p_stream, &p_peek, 32 ) ) < 8 ) ) if( ( ( i_read = stream_Peek( p_stream, &p_peek, 32 ) ) < 8 ) )
{ {
return( 0 ); return 0;
} }
p_box->i_pos = stream_Tell( p_stream ); p_box->i_pos = stream_Tell( p_stream );
...@@ -216,15 +215,13 @@ int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -216,15 +215,13 @@ int MP4_ReadBoxCommon( stream_t *p_stream, MP4_Box_t *p_box )
if( p_box->i_size ) if( p_box->i_size )
{ {
msg_Dbg( p_stream, "found Box: %4.4s size "I64Fd, msg_Dbg( p_stream, "found Box: %4.4s size "I64Fd,
(char*)&p_box->i_type, (char*)&p_box->i_type, p_box->i_size );
p_box->i_size );
} }
#endif #endif
return( 1 ); return 1;
} }
/***************************************************************************** /*****************************************************************************
* MP4_NextBox : Go to the next box * MP4_NextBox : Go to the next box
***************************************************************************** *****************************************************************************
...@@ -242,7 +239,7 @@ static int MP4_NextBox( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -242,7 +239,7 @@ static int MP4_NextBox( stream_t *p_stream, MP4_Box_t *p_box )
if( !p_box->i_size ) if( !p_box->i_size )
{ {
return( 2 ); /* Box with infinite size */ return 2; /* Box with infinite size */
} }
if( p_box->p_father ) if( p_box->p_father )
...@@ -251,7 +248,7 @@ static int MP4_NextBox( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -251,7 +248,7 @@ static int MP4_NextBox( stream_t *p_stream, MP4_Box_t *p_box )
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 ) p_box->p_father->i_size + p_box->p_father->i_pos )
{ {
return( 0 ); /* out of bound */ return 0; /* out of bound */
} }
} }
if( stream_Seek( p_stream, p_box->i_size + p_box->i_pos ) ) if( stream_Seek( p_stream, p_box->i_size + p_box->i_pos ) )
...@@ -276,43 +273,36 @@ static int MP4_ReadBoxContainerRaw( stream_t *p_stream, MP4_Box_t *p_container ) ...@@ -276,43 +273,36 @@ static int MP4_ReadBoxContainerRaw( stream_t *p_stream, MP4_Box_t *p_container )
(off_t)(p_container->i_pos + p_container->i_size) ) (off_t)(p_container->i_pos + p_container->i_size) )
{ {
/* there is no box to load */ /* there is no box to load */
return( 0 ); return 0;
} }
do do
{ {
if( ( p_box = MP4_ReadBox( p_stream, p_container ) ) == NULL ) if( ( p_box = MP4_ReadBox( p_stream, p_container ) ) == NULL ) break;
{
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 ) p_container->p_first = p_box;
{ else p_container->p_last->p_next = p_box;
p_container->p_first = p_box;
}
else
{
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 ); } while( MP4_NextBox( p_stream, p_box ) == 1 );
return( 1 ); return 1;
} }
static int MP4_ReadBoxContainer( stream_t *p_stream, MP4_Box_t *p_container ) static int MP4_ReadBoxContainer( stream_t *p_stream, MP4_Box_t *p_container )
{ {
if( p_container->i_size <= (size_t)MP4_BOX_HEADERSIZE(p_container ) + 8 ) if( p_container->i_size <= (size_t)MP4_BOX_HEADERSIZE(p_container ) + 8 )
{ {
/* container is empty, 8 stand for the first header in this box */ /* container is empty, 8 stand for the first header in this box */
return( 1 ); return 1;
} }
/* enter box */ /* enter box */
stream_Seek( p_stream, p_container->i_pos + MP4_BOX_HEADERSIZE( p_container ) ); stream_Seek( p_stream, p_container->i_pos +
MP4_BOX_HEADERSIZE( p_container ) );
return( MP4_ReadBoxContainerRaw( p_stream, p_container ) ); return MP4_ReadBoxContainerRaw( p_stream, p_container );
} }
static void MP4_FreeBox_Common( MP4_Box_t *p_box ) static void MP4_FreeBox_Common( MP4_Box_t *p_box )
...@@ -323,7 +313,8 @@ static void MP4_FreeBox_Common( MP4_Box_t *p_box ) ...@@ -323,7 +313,8 @@ static void MP4_FreeBox_Common( MP4_Box_t *p_box )
static int MP4_ReadBoxSkip( stream_t *p_stream, MP4_Box_t *p_box ) static int MP4_ReadBoxSkip( stream_t *p_stream, MP4_Box_t *p_box )
{ {
/* XXX sometime moov is hiden in a free box */ /* XXX sometime moov is hiden in a free box */
if( p_box->p_father && p_box->p_father->i_type == VLC_FOURCC( 'r', 'o', 'o', 't' )&& if( p_box->p_father &&
p_box->p_father->i_type == VLC_FOURCC( 'r', 'o', 'o', 't' ) &&
p_box->i_type == FOURCC_free ) p_box->i_type == FOURCC_free )
{ {
uint8_t *p_peek; uint8_t *p_peek;
...@@ -348,12 +339,12 @@ static int MP4_ReadBoxSkip( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -348,12 +339,12 @@ static int MP4_ReadBoxSkip( stream_t *p_stream, MP4_Box_t *p_box )
} }
} }
} }
/* Nothing to do */ /* Nothing to do */
#ifdef MP4_VERBOSE #ifdef MP4_VERBOSE
msg_Dbg( p_stream, "skip box: \"%4.4s\"", msg_Dbg( p_stream, "skip box: \"%4.4s\"", (char*)&p_box->i_type );
(char*)&p_box->i_type );
#endif #endif
return( 1 ); return 1;
} }
static int MP4_ReadBox_ftyp( stream_t *p_stream, MP4_Box_t *p_box ) static int MP4_ReadBox_ftyp( stream_t *p_stream, MP4_Box_t *p_box )
...@@ -1744,31 +1735,32 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1744,31 +1735,32 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
{ {
MP4_Box_t *p_dcom; MP4_Box_t *p_dcom;
MP4_Box_t *p_cmvd; MP4_Box_t *p_cmvd;
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
stream_t *p_stream_memory; stream_t *p_stream_memory;
z_stream z_data; z_stream z_data;
uint8_t *p_data; uint8_t *p_data;
#endif
int i_result; int i_result;
#endif
if( !( p_box->data.p_cmov = malloc( sizeof( MP4_Box_data_cmov_t ) ) ) ) if( !( p_box->data.p_cmov = malloc( sizeof( MP4_Box_data_cmov_t ) ) ) )
{ {
msg_Err( p_stream, "out of memory" ); msg_Err( p_stream, "out of memory" );
return( 0 ); return 0;
} }
memset( p_box->data.p_cmov, 0, sizeof( MP4_Box_data_cmov_t ) ); memset( p_box->data.p_cmov, 0, sizeof( MP4_Box_data_cmov_t ) );
if( !p_box->p_father || if( !p_box->p_father ||
( p_box->p_father->i_type != FOURCC_moov && p_box->p_father->i_type != FOURCC_foov) ) ( p_box->p_father->i_type != FOURCC_moov &&
p_box->p_father->i_type != FOURCC_foov ) )
{ {
msg_Warn( p_stream, "Read box: \"cmov\" box alone" ); msg_Warn( p_stream, "Read box: \"cmov\" box alone" );
return( 1 ); return 1;
} }
if( !(i_result = MP4_ReadBoxContainer( p_stream, p_box ) ) ) if( !MP4_ReadBoxContainer( p_stream, p_box ) )
{ {
return( 0 ); return 0;
} }
if( ( p_dcom = MP4_BoxGet( p_box, "dcom" ) ) == NULL || if( ( p_dcom = MP4_BoxGet( p_box, "dcom" ) ) == NULL ||
...@@ -1776,28 +1768,28 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1776,28 +1768,28 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
p_cmvd->data.p_cmvd->p_data == NULL ) p_cmvd->data.p_cmvd->p_data == NULL )
{ {
msg_Warn( p_stream, "read box: \"cmov\" incomplete" ); msg_Warn( p_stream, "read box: \"cmov\" incomplete" );
return( 1 ); return 1;
} }
if( p_dcom->data.p_dcom->i_algorithm != FOURCC_zlib ) if( p_dcom->data.p_dcom->i_algorithm != FOURCC_zlib )
{ {
msg_Dbg( p_stream, "read box: \"cmov\" compression algorithm : %4.4s not supported", msg_Dbg( p_stream, "read box: \"cmov\" compression algorithm : %4.4s "
(char*)&p_dcom->data.p_dcom->i_algorithm ); "not supported", (char*)&p_dcom->data.p_dcom->i_algorithm );
return( 1 ); return 1;
} }
#ifndef HAVE_ZLIB_H #ifndef HAVE_ZLIB_H
msg_Dbg( p_stream, msg_Dbg( p_stream, "read box: \"cmov\" zlib unsupported" );
"read box: \"cmov\" zlib unsupported" ); return 1;
return( 1 );
#else #else
/* decompress data */ /* decompress data */
/* allocate a new buffer */ /* allocate a new buffer */
if( !( p_data = malloc( p_cmvd->data.p_cmvd->i_uncompressed_size ) ) ) if( !( p_data = malloc( p_cmvd->data.p_cmvd->i_uncompressed_size ) ) )
{ {
msg_Err( p_stream, msg_Err( p_stream, "read box: \"cmov\" not enough memory to "
"read box: \"cmov\" not enough memory to uncompress data" ); "uncompress data" );
return( 1 ); return 1;
} }
/* init default structures */ /* init default structures */
z_data.next_in = p_cmvd->data.p_cmvd->p_data; z_data.next_in = p_cmvd->data.p_cmvd->p_data;
...@@ -1809,62 +1801,57 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box ) ...@@ -1809,62 +1801,57 @@ static int MP4_ReadBox_cmov( stream_t *p_stream, MP4_Box_t *p_box )
z_data.opaque = (voidpf)Z_NULL; z_data.opaque = (voidpf)Z_NULL;
/* init zlib */ /* init zlib */
if( ( i_result = inflateInit( &z_data ) ) != Z_OK ) if( inflateInit( &z_data ) != Z_OK )
{ {
msg_Err( p_stream, msg_Err( p_stream, "read box: \"cmov\" error while uncompressing" );
"read box: \"cmov\" error while uncompressing data" );
free( p_data ); free( p_data );
return( 1 ); return 1;
} }
/* uncompress */ /* uncompress */
i_result = inflate( &z_data, Z_NO_FLUSH ); i_result = inflate( &z_data, Z_NO_FLUSH );
if( ( i_result != Z_OK )&&( i_result != Z_STREAM_END ) ) if( i_result != Z_OK && i_result != Z_STREAM_END )
{ {
msg_Err( p_stream, msg_Err( p_stream, "read box: \"cmov\" error while uncompressing" );
"read box: \"cmov\" error while uncompressing data" );
free( p_data ); free( p_data );
return( 1 ); return 1;
} }
if( p_cmvd->data.p_cmvd->i_uncompressed_size != z_data.total_out ) if( p_cmvd->data.p_cmvd->i_uncompressed_size != z_data.total_out )
{ {
msg_Warn( p_stream, msg_Warn( p_stream, "read box: \"cmov\" uncompressing data size "
"read box: \"cmov\" uncompressing data size mismatch" ); "mismatch" );
} }
p_cmvd->data.p_cmvd->i_uncompressed_size = z_data.total_out; p_cmvd->data.p_cmvd->i_uncompressed_size = z_data.total_out;
/* close zlib */ /* close zlib */
i_result = inflateEnd( &z_data ); if( inflateEnd( &z_data ) != Z_OK )
if( i_result != Z_OK )
{ {
msg_Warn( p_stream, msg_Warn( p_stream, "read box: \"cmov\" error while uncompressing "
"read box: \"cmov\" error while uncompressing data (ignored)" ); "data (ignored)" );
} }
free( p_cmvd->data.p_cmvd->p_data ); free( p_cmvd->data.p_cmvd->p_data );
p_cmvd->data.p_cmvd->p_data = p_data; p_cmvd->data.p_cmvd->p_data = p_data;
p_cmvd->data.p_cmvd->b_compressed = 0; p_cmvd->data.p_cmvd->b_compressed = 0;
msg_Dbg( p_stream, msg_Dbg( p_stream, "read box: \"cmov\" box succesfully uncompressed" );
"read box: \"cmov\" box succesfully uncompressed" );
/* now create a memory stream */ /* now create a memory stream */
p_stream_memory = stream_MemoryNew( VLC_OBJECT(p_stream), p_stream_memory =
p_cmvd->data.p_cmvd->p_data, stream_MemoryNew( VLC_OBJECT(p_stream), p_cmvd->data.p_cmvd->p_data,
p_cmvd->data.p_cmvd->i_uncompressed_size); p_cmvd->data.p_cmvd->i_uncompressed_size );
/* and read uncompressd moov */ /* and read uncompressd moov */
p_box->data.p_cmov->p_moov = MP4_ReadBox( p_stream_memory, NULL ); p_box->data.p_cmov->p_moov = MP4_ReadBox( p_stream_memory, NULL );
free( p_stream_memory ); stream_MemoryDelete( p_stream_memory, VLC_FALSE );
#ifdef MP4_VERBOSE #ifdef MP4_VERBOSE
msg_Dbg( p_stream, msg_Dbg( p_stream, "read box: \"cmov\" compressed movie header completed");
"read box: \"cmov\" compressed movie header completed" );
#endif #endif
return( p_box->data.p_cmov->p_moov ? 1 : 0 );
return p_box->data.p_cmov->p_moov ? 1 : 0;
#endif /* HAVE_ZLIB_H */ #endif /* HAVE_ZLIB_H */
} }
......
/***************************************************************************** /*****************************************************************************
* mem_stream.c * mem_stream.c: stream_t wrapper around memory buffer
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2004 VideoLAN * Copyright (C) 1999-2004 VideoLAN
* $Id: stream.c 9390 2004-11-22 09:56:48Z fenrir $ * $Id: stream.c 9390 2004-11-22 09:56:48Z fenrir $
...@@ -48,8 +48,7 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, ...@@ -48,8 +48,7 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
stream_t *s = vlc_object_create( p_this, VLC_OBJECT_STREAM ); stream_t *s = vlc_object_create( p_this, VLC_OBJECT_STREAM );
stream_sys_t *p_sys; stream_sys_t *p_sys;
if( !s ) if( !s ) return NULL;
return NULL;
s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) ); s->p_sys = p_sys = malloc( sizeof( stream_sys_t ) );
p_sys->i_pos = 0; p_sys->i_pos = 0;
...@@ -59,7 +58,7 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, ...@@ -59,7 +58,7 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
s->pf_block = NULL; s->pf_block = NULL;
s->pf_read = AStreamReadMem; /* Set up later */ s->pf_read = AStreamReadMem; /* Set up later */
s->pf_peek = AStreamPeekMem; s->pf_peek = AStreamPeekMem;
s->pf_control= AStreamControl; s->pf_control = AStreamControl;
vlc_object_attach( s, p_this ); vlc_object_attach( s, p_this );
return s; return s;
...@@ -67,13 +66,12 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer, ...@@ -67,13 +66,12 @@ stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
void stream_MemoryDelete( stream_t *s, vlc_bool_t b_free_buffer ) void stream_MemoryDelete( stream_t *s, vlc_bool_t b_free_buffer )
{ {
if( b_free_buffer ) if( b_free_buffer ) free( s->p_sys->p_buffer );
{
free( s->p_sys->p_buffer );
}
free( s->p_sys ); free( s->p_sys );
vlc_object_detach( s );
vlc_object_destroy( s ); vlc_object_destroy( s );
} }
/**************************************************************************** /****************************************************************************
* AStreamControl: * AStreamControl:
****************************************************************************/ ****************************************************************************/
...@@ -112,6 +110,7 @@ static int AStreamControl( stream_t *s, int i_query, va_list args ) ...@@ -112,6 +110,7 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
i_64 = __MAX( i_64, 0 ); i_64 = __MAX( i_64, 0 );
i_64 = __MIN( i_64, s->p_sys->i_size ); i_64 = __MIN( i_64, s->p_sys->i_size );
p_sys->i_pos = i_64; p_sys->i_pos = i_64;
break;
case STREAM_GET_MTU: case STREAM_GET_MTU:
return VLC_EGENERIC; return VLC_EGENERIC;
......
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