* libmp4.c : LibMP4 library for mp4 module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: libmp4.c,v 1.22 2003/04/24 20:49:54 fenrir Exp $
+ * $Id: libmp4.c,v 1.23 2003/04/25 21:47:25 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
( 8 + ( p_box->i_shortsize == 1 ? 8 : 0 ) \
+ ( p_box->i_type == FOURCC_uuid ? 16 : 0 ) )
-#define MP4_BOX_DESCEND( p_box ) \
- MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) )
-
#define MP4_GET1BYTE( dst ) \
dst = *p_peek; p_peek++; i_read--
{ \
return( 0 ); \
} \
- if( !MP4_ReadStream( p_stream, p_peek, i_read ) )\
+ if( MP4_ReadStream( p_stream, p_peek, i_read ) )\
{ \
free( p_buff ); \
return( 0 ); \
vlc_mutex_lock( &p_input->stream.stream_lock );
i_pos= p_input->stream.p_selected_area->i_tell;
-// ( p_input->p_last_data - p_input->p_current_data );
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
int MP4_SeekAbsolute( input_thread_t *p_input,
- off_t i_pos)
+ off_t i_pos)
{
off_t i_filepos;
- if( i_pos >= p_input->stream.p_selected_area->i_size )
+ //msg_Warn( p_input, "seek to %lld/%lld", i_pos, p_input->stream.p_selected_area->i_size );
+
+ if( p_input->stream.p_selected_area->i_size > 0 &&
+ i_pos >= p_input->stream.p_selected_area->i_size )
{
- return( 0 );
+ msg_Warn( p_input, "seek:after end of file" );
+ return VLC_EGENERIC;
}
i_filepos = MP4_TellAbsolute( p_input );
- if( i_pos != i_filepos )
+
+ if( i_filepos == i_pos )
+ {
+ return VLC_SUCCESS;
+ }
+
+ if( p_input->stream.b_seekable &&
+ ( p_input->stream.i_method == INPUT_METHOD_FILE ||
+ i_pos - i_filepos < 0 ||
+ i_pos - i_filepos > 1024 ) )
{
input_AccessReinit( p_input );
p_input->pf_seek( p_input, i_pos );
+ return VLC_SUCCESS;
+ }
+ else if( i_pos - i_filepos > 0 )
+ {
+ data_packet_t *p_data;
+ int i_skip = i_pos - i_filepos;
+
+ msg_Warn( p_input, "will skip %d bytes, slow", i_skip );
+
+ while (i_skip > 0 )
+ {
+ int i_read;
+
+ i_read = input_SplitBuffer( p_input, &p_data,
+ __MIN( 4096, i_skip ) );
+ if( i_read < 0 )
+ {
+ msg_Warn( p_input, "seek:cannot read" );
+ return VLC_EGENERIC;
+ }
+ i_skip -= i_read;
+
+ input_DeletePacket( p_input->p_method_data, p_data );
+ if( i_read == 0 && i_skip > 0 )
+ {
+ msg_Warn( p_input, "seek:cannot read" );
+ return VLC_EGENERIC;
+ }
+ }
+ return VLC_SUCCESS;
+ }
+ else
+ {
+ msg_Warn( p_input, "seek:failed" );
+ return VLC_EGENERIC;
}
- return( 1 );
}
/* return 1 if success, 0 if fail */
if( !i_size )
{
- return( 1 );
+ return( VLC_SUCCESS );
}
do
i_read = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 1024 ) );
if( i_read <= 0 )
{
- return( 0 );
+ return( VLC_EGENERIC );
}
memcpy( p_buff, p_data->p_payload_start, i_read );
input_DeletePacket( p_input->p_method_data, p_data );
} while( i_size );
- return( 1 );
+ return( VLC_SUCCESS );
}
/*****************************************************************************
{
if( i_size > p_stream->i_stop - p_stream->i_start )
{
- return( 0 );
+ return( VLC_EGENERIC );
}
memcpy( p_buff,
p_stream->p_buffer + p_stream->i_start,
i_size );
p_stream->i_start += i_size;
- return( 1 );
+ return( VLC_SUCCESS );
}
else
{
}
else
{
+
+ if( p_stream->p_input->stream.p_selected_area->i_size > 0 )
+ {
+ int64_t i_max =
+ p_stream->p_input->stream.p_selected_area->i_size - MP4_TellAbsolute( p_stream->p_input );
+ if( i_size > i_max )
+ {
+ i_size = i_max;
+ }
+ }
return( input_Peek( p_stream->p_input, pp_peek, i_size ) );
}
}
if( i_pos < p_stream->i_stop )
{
p_stream->i_start = i_pos;
- return( 1 );
+ return( VLC_SUCCESS );
}
else
{
- return( 0 );
+ return( VLC_EGENERIC );
}
}
else
*****************************************************************************/
int MP4_ReadBoxCommon( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
- int i_read;
+ int i_read;
uint8_t *p_peek;
if( ( ( i_read = MP4_PeekStream( p_stream, &p_peek, 32 ) ) < 8 ) )
return( 0 ); /* out of bound */
}
}
- return( MP4_SeekStream( p_stream, p_box->i_size + p_box->i_pos ) );
+ return( MP4_SeekStream( p_stream, p_box->i_size + p_box->i_pos ) ? 0 : 1 );
}
/*****************************************************************************
* MP4_MP4_GotoBox : Go to this particular box
*****************************************************************************/
int MP4_GotoBox( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
- return( MP4_SeekStream( p_stream, p_box->i_pos ) );
+ return( MP4_SeekStream( p_stream, p_box->i_pos ) ? 0 : 1 );
}
int MP4_ReadBoxContainer( MP4_Stream_t *p_stream, MP4_Box_t *p_container )
{
-
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 */
}
/* enter box */
- MP4_BOX_DESCEND( p_container );
+ MP4_SeekStream( p_stream, p_container->i_pos + MP4_BOX_HEADERSIZE( p_container ) );
return( MP4_ReadBoxContainerRaw( p_stream, p_container ) );
}
MP4_READBOX_EXIT( 1 );
}
-int MP4_ReadBox_tref( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
-{
-
- if( p_box->i_size < (size_t)MP4_BOX_HEADERSIZE(p_box ) + 8 )
- {
- /* container is empty, 8 stand for the first header in this box */
- return( 1 );
- }
-
- if( !MP4_SeekStream( p_stream, p_box->i_pos + MP4_BOX_HEADERSIZE( p_box ) ) )
- {
- return( 0 );
- }
-
- MP4_ReadBoxContainerRaw( p_stream, p_box );
-
-#ifdef MP4_VERBOSE
- msg_Dbg( p_stream->p_input, "Read Box: \"tref\" " );
-
-#endif
- return( 1 );
-}
-
-
int MP4_ReadBox_mdhd( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
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 );
MP4_GET2BYTES( p_box->data.p_sample_soun->i_predefined );
MP4_READBOX_EXIT( 1 );
}
-#if 0
-int MP4_ReadBox_sample_mp4a( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
-{
- unsigned int i;
-
- MP4_READBOX_ENTER( MP4_Box_data_sample_mp4a_t );
-
- for( i = 0; i < 6 ; i++ )
- {
- MP4_GET1BYTE( p_box->data.p_sample_mp4a->i_reserved1[i] );
- }
-
- MP4_GET2BYTES( p_box->data.p_sample_mp4a->i_data_reference_index );
-
- for( i = 0; i < 2 ; i++ )
- {
- MP4_GET4BYTES( p_box->data.p_sample_mp4a->i_reserved2[i] );
- }
-
- MP4_GET2BYTES( p_box->data.p_sample_mp4a->i_channelcount );
- MP4_GET2BYTES( p_box->data.p_sample_mp4a->i_samplesize );
- MP4_GET2BYTES( p_box->data.p_sample_mp4a->i_predefined );
- 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 */
-
-#ifdef MP4_VERBOSE
- 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_sampleratelo / 65536 );
-
-#endif
- MP4_READBOX_EXIT( 1 );
-}
-#endif
int MP4_ReadBox_sample_vide( MP4_Stream_t *p_stream, MP4_Box_t *p_box )
{
{ FOURCC_hnti, MP4_ReadBoxContainer, MP4_FreeBox_Common },
{ FOURCC_rmra, MP4_ReadBoxContainer, MP4_FreeBox_Common },
{ FOURCC_rmda, MP4_ReadBoxContainer, MP4_FreeBox_Common },
+ { FOURCC_tref, MP4_ReadBoxContainer, MP4_FreeBox_Common },
/* specific box */
{ FOURCC_ftyp, MP4_ReadBox_ftyp, MP4_FreeBox_ftyp },
{ FOURCC_cmov, MP4_ReadBox_cmov, MP4_FreeBox_Common },
{ FOURCC_mvhd, MP4_ReadBox_mvhd, MP4_FreeBox_Common },
{ FOURCC_tkhd, MP4_ReadBox_tkhd, MP4_FreeBox_Common },
- { FOURCC_tref, MP4_ReadBox_tref, MP4_FreeBox_Common },
{ FOURCC_mdhd, MP4_ReadBox_mdhd, MP4_FreeBox_Common },
{ FOURCC_hdlr, MP4_ReadBox_hdlr, MP4_FreeBox_hdlr },
{ FOURCC_vmhd, MP4_ReadBox_vmhd, MP4_FreeBox_Common },
(MP4_Box_Function[i_index].MP4_ReadBox_function)( p_stream, p_box );
}
- if( !MP4_GotoBox( p_stream, p_box ) )
- {
- return( 0 );
- }
return( i_result );
}
+
#if 0
/*****************************************************************************
* MP4_CountBox: given a box, count how many child have the requested type
* mp4.c : MP4 file input module for vlc
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: mp4.c,v 1.25 2003/04/24 14:39:53 fenrir Exp $
+ * $Id: mp4.c,v 1.26 2003/04/25 21:47:25 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
static void __MP4End ( vlc_object_t * );
static int MP4Demux ( input_thread_t * );
+static int MP4DemuxRef( input_thread_t *p_input )
+{
+ return 0;
+}
+
/* New input could have something like that... */
static int MP4Seek ( input_thread_t *, mtime_t );
if( !p_input->stream.b_seekable )
{
msg_Warn( p_input, "MP4 plugin discarded (unseekable)" );
- return( -1 );
+ return( VLC_EGENERIC );
}
/* Initialize access plug-in structures. */
if( input_Peek( p_input, &p_peek, 8 ) < 8 )
{
msg_Warn( p_input, "MP4 plugin discarded (cannot peek)" );
- return( -1 );
+ return( VLC_EGENERIC );
}
break;
default:
msg_Warn( p_input, "MP4 plugin discarded (not a valid file)" );
- return( -1 );
+ return( VLC_EGENERIC );
}
/* create our structure that will contains all data */
p_demux = malloc( sizeof( demux_sys_t ) ) ) )
{
msg_Err( p_input, "out of memory" );
- return( -1 );
+ return( VLC_EGENERIC );
}
memset( p_demux, 0, sizeof( demux_sys_t ) );
p_input->p_demux_data = p_demux;
if( !MP4_BoxGetRoot( p_input, &p_demux->box_root ) )
{
msg_Warn( p_input, "MP4 plugin discarded (not a valid file)" );
- return( -1 );
+ return( VLC_EGENERIC );
}
MP4_BoxDumpStructure( p_input, &p_demux->box_root );
FIND_ANYWHERE );
if( p_playlist )
{
+ //p_playlist->pp_items[p_playlist->i_index]->b_autodeletion = VLC_TRUE;
for( i = 0; i < i_count; i++ )
{
MP4_Box_t *p_rdrf = MP4_BoxGet( p_rmra, "rmda[%d]/rdrf", i );
else
{
/* msg dbg relative ? */
- char *psz_absolute = alloca( strlen( p_input->psz_name ) + strlen( psz_ref ) + 1);
- char *end = strrchr( p_input->psz_name, '/' );
+ char *psz_absolute = alloca( strlen( p_input->psz_source ) + strlen( psz_ref ) + 1);
+ char *end = strrchr( p_input->psz_source, '/' );
if( end )
{
- int i_len = end + 1 - p_input->psz_name;
+ int i_len = end + 1 - p_input->psz_source;
- strncpy( psz_absolute, p_input->psz_name, i_len);
+ strncpy( psz_absolute, p_input->psz_source, i_len);
psz_absolute[i_len] = '\0';
}
else
if( !p_rmra )
{
msg_Err( p_input, "cannot find /moov/mvhd" );
+ MP4End( p_input );
+ return VLC_EGENERIC;
}
else
{
msg_Warn( p_input, "cannot find /moov/mvhd (pure ref file)" );
+ p_input->pf_demux = MP4DemuxRef;
+ return VLC_SUCCESS;
}
- MP4End( p_input );
- return( -1 );
}
else
{
{
msg_Err( p_input, "cannot find any /moov/trak" );
MP4End( p_input );
- return( -1 );
+ return( VLC_EGENERIC );
}
msg_Dbg( p_input, "find %d track%c",
p_demux->i_tracks,
vlc_mutex_unlock( &p_input->stream.stream_lock );
msg_Err( p_input, "cannot init stream" );
MP4End( p_input );
- return( -1 );
+ return( VLC_EGENERIC );
}
/* Needed to create program _before_ MP4_TrackCreate */
if( input_AddProgram( p_input, 0, 0) == NULL )
vlc_mutex_unlock( &p_input->stream.stream_lock );
msg_Err( p_input, "cannot add program" );
MP4End( p_input );
- return( -1 );
+ return( VLC_EGENERIC );
}
p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
/* XXX beurk and beurk, see MP4Demux and MP4Seek */
p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock );
- return( 0 );
-
+ return( VLC_SUCCESS );
}
/*****************************************************************************
//msg_Dbg( p_input, "stream %d size=%6d pos=%8lld", i_track, i_size, i_pos );
/* go,go go ! */
- if( ! MP4_SeekAbsolute( p_input, i_pos ) )
+ if( MP4_SeekAbsolute( p_input, i_pos ) )
{
msg_Warn( p_input, "track[0x%x] will be disabled (eof?)", track.i_track_ID );
MP4_TrackUnselect( p_input, &track );
p_pes->i_pes_size = i_size;
if( i_size > 0 )
{
- if( !MP4_ReadData( p_input, p_data->p_payload_start, i_size ) )
+ if( MP4_ReadData( p_input, p_data->p_payload_start, i_size ) )
{
input_DeletePES( p_input->p_method_data, p_pes );