Commit 5bbfc2b4 authored by Laurent Aimar's avatar Laurent Aimar

* plugins/ffmpeg/ffmpeg.c : with empty frame(data_packet) it won't segfault

    * plugins/avi/avi.c : use KeyFrame to seek, so video will not be bad as
        before
parent 5a70322c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* avi.c : AVI file Stream input module for vlc * avi.c : AVI file Stream input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: avi.c,v 1.1 2002/04/23 23:44:36 fenrir Exp $ * $Id: avi.c,v 1.2 2002/04/25 03:01:03 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
...@@ -105,7 +105,6 @@ static void __AVIFreeDemuxData( input_thread_t *p_input ) ...@@ -105,7 +105,6 @@ static void __AVIFreeDemuxData( input_thread_t *p_input )
RIFF_DeleteChunk( p_input->p_demux_data, p_avi_demux->p_movi ); RIFF_DeleteChunk( p_input->p_demux_data, p_avi_demux->p_movi );
if( p_avi_demux->p_idx1 != NULL ) if( p_avi_demux->p_idx1 != NULL )
RIFF_DeleteChunk( p_input->p_demux_data, p_avi_demux->p_idx1 ); RIFF_DeleteChunk( p_input->p_demux_data, p_avi_demux->p_idx1 );
return;
if( p_avi_demux->pp_info != NULL ) if( p_avi_demux->pp_info != NULL )
{ {
for( i = 0; i < p_avi_demux->i_streams; i++ ) for( i = 0; i < p_avi_demux->i_streams; i++ )
...@@ -113,16 +112,29 @@ static void __AVIFreeDemuxData( input_thread_t *p_input ) ...@@ -113,16 +112,29 @@ static void __AVIFreeDemuxData( input_thread_t *p_input )
if( p_avi_demux->pp_info[i] != NULL ) if( p_avi_demux->pp_info[i] != NULL )
{ {
#define p_info p_avi_demux->pp_info[i] #define p_info p_avi_demux->pp_info[i]
/* don't uses RIFF_DeleteChunk -> it will segfault here ( probably because of
data_packey already unallocated ? */
if( p_info->p_strl != NULL ) if( p_info->p_strl != NULL )
RIFF_DeleteChunk( p_input->p_demux_data, p_info->p_strl ); {
if( p_info->p_strh != NULL ) free( p_info->p_strl );
RIFF_DeleteChunk( p_input->p_demux_data,p_info->p_strh ); }
if( p_info->p_strh != NULL )
{
free( p_info->p_strh );
}
if( p_info->p_strf != NULL ) if( p_info->p_strf != NULL )
RIFF_DeleteChunk( p_input->p_demux_data,p_info->p_strf ); {
if( p_info->p_strd != NULL ) free( p_info->p_strf );
RIFF_DeleteChunk( p_input->p_demux_data,p_info->p_strd ); }
if( p_info->p_strd != NULL )
{
free( p_info->p_strd );
}
if( p_info->p_index != NULL ) if( p_info->p_index != NULL )
free( p_info->p_index ); {
free( p_info->p_index );
}
free( p_info ); free( p_info );
#undef p_info #undef p_info
} }
...@@ -198,7 +210,6 @@ int avi_ParseWaveFormatEx( waveformatex_t *h, byte_t *p_data ) ...@@ -198,7 +210,6 @@ int avi_ParseWaveFormatEx( waveformatex_t *h, byte_t *p_data )
static int __AVI_ParseStreamHeader( u32 i_id, int *i_number, u16 *i_type ) static int __AVI_ParseStreamHeader( u32 i_id, int *i_number, u16 *i_type )
{ {
int c1,c2,c3,c4; int c1,c2,c3,c4;
char str[3];
c1 = ( i_id ) & 0xFF; c1 = ( i_id ) & 0xFF;
c2 = ( i_id >> 8 ) & 0xFF; c2 = ( i_id >> 8 ) & 0xFF;
...@@ -209,10 +220,7 @@ static int __AVI_ParseStreamHeader( u32 i_id, int *i_number, u16 *i_type ) ...@@ -209,10 +220,7 @@ static int __AVI_ParseStreamHeader( u32 i_id, int *i_number, u16 *i_type )
{ {
return( -1 ); return( -1 );
} }
str[0] = c1; *i_number = (c1 - '0') * 10 + (c2 - '0' );
str[1] = c2;
str[2] = 0;
*i_number = atoi( str );
*i_type = ( c3 << 8) + c4; *i_type = ( c3 << 8) + c4;
return( 0 ); return( 0 );
} }
...@@ -306,7 +314,7 @@ static void __AVI_GetIndex( input_thread_t *p_input ) ...@@ -306,7 +314,7 @@ static void __AVI_GetIndex( input_thread_t *p_input )
return; return;
} }
i_read /= 16 ; i_read /= 16 ;
/* try to verify if we are beyond end of p_idx1 */ /* TODO try to verify if we are beyond end of p_idx1 */
for( i = 0; i < i_read; i++ ) for( i = 0; i < i_read; i++ )
{ {
byte_t *p_peek = p_buff + i * 16; byte_t *p_peek = p_buff + i * 16;
...@@ -445,7 +453,7 @@ static int AVIInit( input_thread_t *p_input ) ...@@ -445,7 +453,7 @@ static int AVIInit( input_thread_t *p_input )
es_descriptor_t *p_es_video = NULL; es_descriptor_t *p_es_video = NULL;
es_descriptor_t *p_es_audio = NULL; es_descriptor_t *p_es_audio = NULL;
int i,j; int i;
p_avi_demux = malloc( sizeof(demux_data_avi_file_t) ); p_avi_demux = malloc( sizeof(demux_data_avi_file_t) );
memset( p_avi_demux, 0, sizeof( demux_data_avi_file_t ) ); memset( p_avi_demux, 0, sizeof( demux_data_avi_file_t ) );
...@@ -636,7 +644,6 @@ static int AVIInit( input_thread_t *p_input ) ...@@ -636,7 +644,6 @@ static int AVIInit( input_thread_t *p_input )
p_input->stream.p_selected_program = p_input->stream.pp_programs[0]; p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
p_input->stream.p_new_program = p_input->stream.pp_programs[0] ; p_input->stream.p_new_program = p_input->stream.pp_programs[0] ;
/* FIXME FIXME id des es doit etre unique FIXME FIXME */
vlc_mutex_lock( &p_input->stream.stream_lock ); vlc_mutex_lock( &p_input->stream.stream_lock );
for( i = 0; i < p_avi_demux->i_streams; i++ ) for( i = 0; i < p_avi_demux->i_streams; i++ )
{ {
...@@ -646,17 +653,17 @@ static int AVIInit( input_thread_t *p_input ) ...@@ -646,17 +653,17 @@ static int AVIInit( input_thread_t *p_input )
switch( p_info->header.i_type ) switch( p_info->header.i_type )
{ {
case( FOURCC_auds ): case( FOURCC_auds ):
/* pour l'id j'ai mis 12 pr audio et 42 pour video */ /* pour l'id j'ai mis 12+i pr audio et 42+i pour video */
/* et le numero du flux(ici i) dans i_stream_id */ /* et le numero du flux(ici i) dans i_stream_id */
avi_ParseWaveFormatEx( &p_info->audio_format, avi_ParseWaveFormatEx( &p_info->audio_format,
p_info->p_strf->p_data->p_payload_start ); p_info->p_strf->p_data->p_payload_start );
p_es = input_AddES( p_input, p_es = input_AddES( p_input,
p_input->stream.p_selected_program, 12+i, p_input->stream.p_selected_program, 12+i,
p_info->p_strf->i_size ); p_info->p_strf->i_size );
p_es->i_cat = AUDIO_ES;
p_es->b_audio = 1; p_es->b_audio = 1;
p_es->i_type = p_es->i_type =
__AVI_AudioGetType( p_info->audio_format.i_formattag ); __AVI_AudioGetType( p_info->audio_format.i_formattag );
p_es->i_stream_id =i; /* FIXME */
if( p_es->i_type == 0 ) if( p_es->i_type == 0 )
{ {
intf_ErrMsg( "input error: stream(%d,0x%x) not supported", intf_ErrMsg( "input error: stream(%d,0x%x) not supported",
...@@ -666,9 +673,9 @@ static int AVIInit( input_thread_t *p_input ) ...@@ -666,9 +673,9 @@ static int AVIInit( input_thread_t *p_input )
} }
else else
{ {
if( p_es_audio == NULL ) p_es_audio = p_es; if( p_es_audio == NULL ) {p_es_audio = p_es;}
p_es->i_cat = AUDIO_ES;
} }
p_es->i_stream_id =i; /* FIXME */
break; break;
case( FOURCC_vids ): case( FOURCC_vids ):
...@@ -678,21 +685,22 @@ static int AVIInit( input_thread_t *p_input ) ...@@ -678,21 +685,22 @@ static int AVIInit( input_thread_t *p_input )
p_es = input_AddES( p_input, p_es = input_AddES( p_input,
p_input->stream.p_selected_program, 42+i, p_input->stream.p_selected_program, 42+i,
p_info->p_strf->i_size ); p_info->p_strf->i_size );
p_es->i_cat = VIDEO_ES;
p_es->b_audio = 0; p_es->b_audio = 0;
p_es->i_type = p_es->i_type =
__AVI_VideoGetType( p_info->video_format.i_compression ); __AVI_VideoGetType( p_info->video_format.i_compression );
p_es->i_stream_id =i; /* FIXME */
if( p_es->i_type == 0 ) if( p_es->i_type == 0 )
{ {
intf_ErrMsg( "input error: stream(%d,%4.4s) not supported", intf_ErrMsg( "input error: stream(%d,%4.4s) not supported",
i, i,
(char*)&p_info->video_format.i_compression); (char*)&p_info->video_format.i_compression);
p_es->i_cat = UNKNOWN_ES;
} }
else else
{ {
if( p_es_video == NULL ) p_es_video = p_es; if( p_es_video == NULL ) {p_es_video = p_es;}
p_es->i_cat = VIDEO_ES;
} }
p_es->i_stream_id =i; /* FIXME */
break; break;
default: default:
p_es = input_AddES( p_input, p_es = input_AddES( p_input,
...@@ -706,12 +714,9 @@ static int AVIInit( input_thread_t *p_input ) ...@@ -706,12 +714,9 @@ static int AVIInit( input_thread_t *p_input )
p_info->p_es = p_es; p_info->p_es = p_es;
p_info->i_cat = p_es->i_cat; p_info->i_cat = p_es->i_cat;
/* We copy strf for decoder in p_es->p_demux_data */ /* We copy strf for decoder in p_es->p_demux_data */
for( j = 0; j < p_info->p_strf->i_size; j++ ) memcpy( p_es->p_demux_data,
{ p_info->p_strf->p_data->p_payload_start,
*((byte_t*)p_es->p_demux_data + j) = p_info->p_strf->i_size );
*(p_info->p_strf->p_data->p_payload_start + j);
}
/* print informations on stream */ /* print informations on stream */
switch( p_es->i_cat ) switch( p_es->i_cat )
{ {
...@@ -741,30 +746,30 @@ static int AVIInit( input_thread_t *p_input ) ...@@ -741,30 +746,30 @@ static int AVIInit( input_thread_t *p_input )
} }
/* we select the first audio and video ES */ /* we select the first audio and video ES */
if( p_es_audio != NULL ) if( p_es_video != NULL )
{ {
input_SelectES( p_input, p_es_audio ); input_SelectES( p_input, p_es_video );
} }
else else
{ {
intf_Msg( "input init: no audio stream found !" ); intf_ErrMsg( "input error: no video stream found !" );
vlc_mutex_unlock( &p_input->stream.stream_lock );
return( -1 );
} }
if( p_es_video != NULL ) if( p_es_audio != NULL )
{ {
input_SelectES( p_input, p_es_video ); input_SelectES( p_input, p_es_audio );
} }
else else
{ {
intf_ErrMsg( "input error: no video stream found !" ); intf_Msg( "input init: no audio stream found !" );
return( -1 ); }
vlc_mutex_unlock( &p_input->stream.stream_lock );
} /* p_input->stream.p_selected_area->i_tell = 0; */
/* p_input->stream.p_selected_area->i_tell = 0; */
p_input->stream.i_mux_rate = p_avi_demux->avih.i_maxbytespersec / 50; p_input->stream.i_mux_rate = p_avi_demux->avih.i_maxbytespersec / 50;
p_input->stream.p_selected_program->b_is_ok = 1; p_input->stream.p_selected_program->b_is_ok = 1;
vlc_mutex_unlock( &p_input->stream.stream_lock ); vlc_mutex_unlock( &p_input->stream.stream_lock );
/* stoker les donnes p_demux_data dans p_input */
return( 0 ); return( 0 );
} }
...@@ -775,7 +780,7 @@ static void AVIEnd( input_thread_t *p_input ) ...@@ -775,7 +780,7 @@ static void AVIEnd( input_thread_t *p_input )
} }
static mtime_t __AVI_GetPTSAudio( AVIStreamInfo_t *p_info ) static mtime_t __AVI_GetPTS( AVIStreamInfo_t *p_info )
{ {
/* XXX you need to had p_info->i_date to have correct pts */ /* XXX you need to had p_info->i_date to have correct pts */
/* p_info->p_index[p_info->i_idxpos] need to be valid !! */ /* p_info->p_index[p_info->i_idxpos] need to be valid !! */
...@@ -787,7 +792,8 @@ static mtime_t __AVI_GetPTSAudio( AVIStreamInfo_t *p_info ) ...@@ -787,7 +792,8 @@ static mtime_t __AVI_GetPTSAudio( AVIStreamInfo_t *p_info )
i_pts = (mtime_t)( (double)1000000.0 * i_pts = (mtime_t)( (double)1000000.0 *
(double)p_info->p_index[p_info->i_idxpos].i_lengthtotal * (double)p_info->p_index[p_info->i_idxpos].i_lengthtotal *
(double)p_info->header.i_scale / (double)p_info->header.i_scale /
(double)p_info->header.i_rate); (double)p_info->header.i_rate /
(double)p_info->header.i_samplesize );
} }
else else
{ {
...@@ -799,33 +805,7 @@ static mtime_t __AVI_GetPTSAudio( AVIStreamInfo_t *p_info ) ...@@ -799,33 +805,7 @@ static mtime_t __AVI_GetPTSAudio( AVIStreamInfo_t *p_info )
return( i_pts ); return( i_pts );
} }
static mtime_t __AVI_GetPTSVideo( AVIStreamInfo_t *p_info )
{
/* XXX you need to had p_info->i_date to have correct pts */
mtime_t i_pts;
i_pts = (mtime_t)( (double)1000000.0 *
(double)p_info->i_idxpos *
(double)p_info->header.i_scale /
(double)p_info->header.i_rate);
return( i_pts );
}
static mtime_t __AVI_GetPTS( AVIStreamInfo_t *p_info )
{
switch( p_info->i_cat )
{
case( AUDIO_ES ):
return( __AVI_GetPTSAudio( p_info ) );
case( VIDEO_ES ):
return( __AVI_GetPTSVideo( p_info ) );
default:
return( mdate() + DEFAULT_PTS_DELAY );
}
}
static void __AVI_ControleUnPause()
{
}
static void __AVI_NextIndexEntry( input_thread_t *p_input, static void __AVI_NextIndexEntry( input_thread_t *p_input,
AVIStreamInfo_t *p_info ) AVIStreamInfo_t *p_info )
...@@ -835,74 +815,86 @@ static void __AVI_NextIndexEntry( input_thread_t *p_input, ...@@ -835,74 +815,86 @@ static void __AVI_NextIndexEntry( input_thread_t *p_input,
{ {
/* we need to verify if we reach end of file /* we need to verify if we reach end of file
or if index is broken and search manually */ or if index is broken and search manually */
intf_WarnMsg( 1, "input demux: out of index" );
} }
} }
static void __AVI_ReInitDate( demux_data_avi_file_t *p_avi_demux )
{
mtime_t i_ptsmin = 0;
int i;
int b_first = 1;
for( i = 0; i < p_avi_demux->i_streams; i++ )
{
#define p_info p_avi_demux->pp_info[i]
if( (p_info->p_es->p_decoder_fifo != NULL)
&&( !p_info->b_unselected ) )
{
i_ptsmin = __MIN( i_ptsmin,
__AVI_GetPTS( p_info ) );
if( b_first )
{
i_ptsmin = __AVI_GetPTS( p_info );
b_first = 0;
}
}
#undef p_info
}
p_avi_demux->i_date = mdate() + DEFAULT_PTS_DELAY - i_ptsmin;
}
static int __AVI_ReAlign( input_thread_t *p_input, static int __AVI_ReAlign( input_thread_t *p_input,
AVIStreamInfo_t *p_info ) AVIStreamInfo_t *p_info )
{ {
u32 i_pos; u32 u32_pos;
int i_idxpos; off_t i_pos;
__RIFF_TellPos( p_input, &i_pos );
__RIFF_TellPos( p_input, &u32_pos );
i_pos = (off_t)u32_pos - (off_t)p_info->i_idxoffset;
/* TODO verifier si on est dans p_movi */ /* TODO verifier si on est dans p_movi */
if( p_info->p_index[p_info->i_idxnb-1].i_offset + if( p_info->p_index[p_info->i_idxnb-1].i_offset <= i_pos )
p_info->i_idxoffset < i_pos )
{ {
return( -1 ); p_info->i_idxpos = p_info->i_idxnb-1;
return( 0 );
} }
i_idxpos = p_info->i_idxpos; if( i_pos <= p_info->p_index[0].i_offset )
i_pos -= p_info->i_idxoffset;
if( i_pos < 0 )
{ {
p_info->i_idxpos = 0; p_info->i_idxpos = 0;
return( 0 ); return( 0 );
} }
/* if we have seek in the current chunk then do nothing
__AVI_SeekToChunk will correct */
if( (p_info->p_index[p_info->i_idxpos].i_offset <= i_pos)
&& ( i_pos < p_info->p_index[p_info->i_idxpos].i_offset +
p_info->p_index[p_info->i_idxpos].i_length ) )
{
return( 0 );
}
while( p_info->p_index[i_idxpos].i_offset > i_pos ) if( i_pos >= p_info->p_index[p_info->i_idxpos].i_offset )
{ {
i_idxpos--; /* search for a chunk after i_idxpos */
if( i_idxpos <= 0 ) { return( -1 );} while( (p_info->p_index[p_info->i_idxpos].i_offset < i_pos)
&&( p_info->i_idxpos < p_info->i_idxnb - 1 ) )
{
p_info->i_idxpos++;
}
while( ((p_info->p_index[p_info->i_idxpos].i_flags&AVIIF_KEYFRAME) == 0)
&&( p_info->i_idxpos < p_info->i_idxnb - 1 ) )
{
p_info->i_idxpos++;
}
} }
else
while( p_info->p_index[i_idxpos].i_offset +
p_info->p_index[i_idxpos].i_length < i_pos )
{ {
i_idxpos++; /* search for a chunk before i_idxpos */
if( i_idxpos >= p_info->i_idxnb ) { return( -1 );} while( (p_info->p_index[p_info->i_idxpos].i_offset +
p_info->p_index[p_info->i_idxpos].i_length >= i_pos)
&&( p_info->i_idxpos > 0 ) )
{
p_info->i_idxpos--;
}
while( ((p_info->p_index[p_info->i_idxpos].i_flags&AVIIF_KEYFRAME) == 0)
&( p_info->i_idxpos > 0 ) )
{
p_info->i_idxpos--;
}
} }
p_info->i_idxpos = i_idxpos;
return( 0 ); return( 0 );
} }
static void __AVI_SynchroReInit( input_thread_t *p_input,
AVIStreamInfo_t *p_info_master,
AVIStreamInfo_t *p_info_slave )
{
demux_data_avi_file_t *p_avi_demux;
p_avi_demux = (demux_data_avi_file_t*)p_input->p_demux_data;
p_avi_demux->i_date = mdate() + DEFAULT_PTS_DELAY
- __AVI_GetPTS( p_info_master );
/* TODO: a optimiser */
p_info_slave->i_idxpos = 0;
p_info_slave->b_unselected = 1; /* to correct audio */
p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_OK;
}
/** -1 in case of error, 0 of EOF, 1 otherwise **/ /** -1 in case of error, 0 of EOF, 1 otherwise **/
static int AVIDemux( input_thread_t *p_input ) static int AVIDemux( input_thread_t *p_input )
{ {
...@@ -912,20 +904,6 @@ static int AVIDemux( input_thread_t *p_input ) ...@@ -912,20 +904,6 @@ static int AVIDemux( input_thread_t *p_input )
* juste une succesion de 00dc 01wb ... * juste une succesion de 00dc 01wb ...
* pire tout audio puis tout video ou vice versa * pire tout audio puis tout video ou vice versa
*/ */
/*
From xine-lib :
static uint32_t get_audio_pts (demux_avi_t *this, long posc, long posb)
{
if (this->avi->dwSampleSize==0)
return posc * (double) this->avi->dwScale_audio / this->avi->dwRate_audio * 90000.0;
else
return (this->avi->audio_index[posc].tot+posb)/this->avi->dwSampleSize * (double) this->avi->dwScale_audio / this->avi->dwRate_audio * 90000.0;
}
static uint32_t get_video_pts (demux_avi_t *this, long pos)
{
return pos * (double) this->avi->dwScale / this->avi->dwRate * 90000.0;
}
*/
/* TODO : * a better method to realign /* TODO : * a better method to realign
* verify that we are reading in p_movi * verify that we are reading in p_movi
* XXX be sure to send audio before video to avoid click * XXX be sure to send audio before video to avoid click
...@@ -976,8 +954,7 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos) ...@@ -976,8 +954,7 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos)
if( input_ClockManageControl( p_input, p_input->stream.p_selected_program, if( input_ClockManageControl( p_input, p_input->stream.p_selected_program,
(mtime_t)0) == PAUSE_S ) (mtime_t)0) == PAUSE_S )
{ {
__AVI_ControleUnPause(); __AVI_SynchroReInit( p_input, p_info_video, p_info_audio );
p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_REINIT;
} }
/* after updated p_avi_demux->pp_info[i]->b_unselected !! */ /* after updated p_avi_demux->pp_info[i]->b_unselected !! */
...@@ -985,19 +962,12 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos) ...@@ -985,19 +962,12 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos)
{ {
/* TODO check if we have seek */ /* TODO check if we have seek */
__AVI_ReAlign( p_input, p_info_video ); /*on se realigne pr la video */ __AVI_ReAlign( p_input, p_info_video ); /*on se realigne pr la video */
p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_OK; __AVI_SynchroReInit( p_input, p_info_video, p_info_audio );
p_avi_demux->i_date = mdate() + DEFAULT_PTS_DELAY
- __AVI_GetPTSVideo( p_info_video );
/* TODO: a optimiser */
p_info_audio->i_idxpos = 0;
p_info_audio->b_unselected = 1; /* to correct audio */
p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_OK;
} }
/* update i_date if previously unselected ES (ex: 2 channels audio ) */ /* update i_date if previously unselected ES (ex: 2 channels audio ) */
if( (p_info_audio != NULL)&&(p_info_audio->b_unselected )) if( (p_info_audio != NULL)&&(p_info_audio->b_unselected ))
{ {
intf_WarnMsg( 1, "input demux: reinit synchro for unselected es" );
/* we have to go to the good pts */ /* we have to go to the good pts */
/* we will reach p_info_ok pts */ /* we will reach p_info_ok pts */
while( __AVI_GetPTS( p_info_audio) < __AVI_GetPTS( p_info_video) ) while( __AVI_GetPTS( p_info_audio) < __AVI_GetPTS( p_info_video) )
...@@ -1014,8 +984,8 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos) ...@@ -1014,8 +984,8 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos)
} }
else else
{ {
if( __AVI_GetPTSAudio( p_info_audio ) <= if( __AVI_GetPTS( p_info_audio ) <=
__AVI_GetPTSVideo( p_info_video ) ) __AVI_GetPTS( p_info_video ) )
{ {
p_info = p_info_audio; p_info = p_info_audio;
} }
...@@ -1025,7 +995,7 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos) ...@@ -1025,7 +995,7 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos)
} }
} }
/* go the good chunk to read */ /* go to the good chunk to read */
__AVI_SeekToChunk( p_input, p_info ); __AVI_SeekToChunk( p_input, p_info );
...@@ -1043,10 +1013,11 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos) ...@@ -1043,10 +1013,11 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos)
__AVI_NextIndexEntry( p_input, p_info ); __AVI_NextIndexEntry( p_input, p_info );
return( 1 ); return( 1 );
} }
/*
intf_WarnMsg( 6, "input demux: read %4.4s chunk", intf_WarnMsg( 6, "input demux: read %4.4s chunk %d bytes",
(char*)&p_chunk->i_id); (char*)&p_chunk->i_id,
*/ p_chunk->i_size);
if( RIFF_LoadChunkDataInPES(p_input, p_chunk, &p_pes) != 0 ) if( RIFF_LoadChunkDataInPES(p_input, p_chunk, &p_pes) != 0 )
{ {
intf_ErrMsg( "input error: cannot read data" ); intf_ErrMsg( "input error: cannot read data" );
...@@ -1057,10 +1028,8 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos) ...@@ -1057,10 +1028,8 @@ static uint32_t get_video_pts (demux_avi_t *this, long pos)
p_pes->i_pts = p_avi_demux->i_date + __AVI_GetPTS( p_info ); p_pes->i_pts = p_avi_demux->i_date + __AVI_GetPTS( p_info );
p_pes->i_dts = 0; p_pes->i_dts = 0;
/* on update les donnes */
__AVI_NextIndexEntry( p_input, p_info ); __AVI_NextIndexEntry( p_input, p_info );
/* send to decoder */ /* send to decoder */
vlc_mutex_lock( &p_info->p_es->p_decoder_fifo->data_lock ); vlc_mutex_lock( &p_info->p_es->p_decoder_fifo->data_lock );
if( p_info->p_es->p_decoder_fifo->i_depth >= MAX_PACKETS_IN_FIFO ) if( p_info->p_es->p_decoder_fifo->i_depth >= MAX_PACKETS_IN_FIFO )
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ffmpeg.c: video decoder using ffmpeg library * ffmpeg.c: video decoder using ffmpeg library
***************************************************************************** *****************************************************************************
* Copyright (C) 1999-2001 VideoLAN * Copyright (C) 1999-2001 VideoLAN
* $Id: ffmpeg.c,v 1.1 2002/04/23 23:44:36 fenrir Exp $ * $Id: ffmpeg.c,v 1.2 2002/04/25 03:01:03 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -83,7 +83,7 @@ MODULE_CONFIG_STOP ...@@ -83,7 +83,7 @@ MODULE_CONFIG_STOP
MODULE_INIT_START MODULE_INIT_START
SET_DESCRIPTION( "ffmpeg video decoder module (MSMPEG4,MPEG4)" ) SET_DESCRIPTION( "ffmpeg video decoder module (MSMPEG4,MPEG4)" )
ADD_CAPABILITY( DECODER, 50 ) ADD_CAPABILITY( DECODER, 50 )
ADD_SHORTCUT( "ffmpeg_vdec" ) ADD_SHORTCUT( "ffmpeg" )
MODULE_INIT_STOP MODULE_INIT_STOP
MODULE_ACTIVATE_START MODULE_ACTIVATE_START
...@@ -94,17 +94,18 @@ MODULE_DEACTIVATE_START ...@@ -94,17 +94,18 @@ MODULE_DEACTIVATE_START
MODULE_DEACTIVATE_STOP MODULE_DEACTIVATE_STOP
static u16 __GetWordLittleEndianFromBuff( byte_t *p_buff ) static __inline__ u16 __GetWordLittleEndianFromBuff( byte_t *p_buff )
{ {
u16 i; u16 i;
i = (*p_buff) + ( *(p_buff + 1) <<8 ); i = (*p_buff) + ( *(p_buff + 1) <<8 );
return ( i ); return ( i );
} }
static u32 __GetDoubleWordLittleEndianFromBuff( byte_t *p_buff ) static __inline__ u32 __GetDoubleWordLittleEndianFromBuff( byte_t *p_buff )
{ {
u32 i; u32 i;
i = (*p_buff) + ( *(p_buff + 1) <<8 ) + ( *(p_buff + 2) <<16 ) + ( *(p_buff + 3) <<24 ); i = (*p_buff) + ( *(p_buff + 1) <<8 ) +
( *(p_buff + 2) <<16 ) + ( *(p_buff + 3) <<24 );
return ( i ); return ( i );
} }
...@@ -151,7 +152,7 @@ static int __ParseBitMapInfoHeader( bitmapinfoheader_t *h, byte_t *p_data ) ...@@ -151,7 +152,7 @@ static int __ParseBitMapInfoHeader( bitmapinfoheader_t *h, byte_t *p_data )
static pes_packet_t *__PES_GET( decoder_fifo_t *p_fifo ) static pes_packet_t *__PES_GET( decoder_fifo_t *p_fifo )
{ {
pes_packet_t *p_pes; pes_packet_t *p_pes;
/* get a p_pes ie data for a frame ! */
vlc_mutex_lock( &p_fifo->data_lock ); vlc_mutex_lock( &p_fifo->data_lock );
/* if fifo is emty wait */ /* if fifo is emty wait */
...@@ -232,10 +233,6 @@ static void __PACKET_NEXT( videodec_thread_t *p_vdec ) ...@@ -232,10 +233,6 @@ static void __PACKET_NEXT( videodec_thread_t *p_vdec )
p_vdec->i_data_size = p_vdec->p_data->p_payload_end - p_vdec->i_data_size = p_vdec->p_data->p_payload_end -
p_vdec->p_data->p_payload_start; p_vdec->p_data->p_payload_start;
} }
if( p_vdec->i_data_size == 0 )
{
p_vdec->p_data = NULL;
}
} while( p_vdec->i_data_size <= 0 ); } while( p_vdec->i_data_size <= 0 );
} }
...@@ -276,7 +273,6 @@ static __inline__ u32 __FfmpegChromaToFourCC( int i_ffmpegchroma ) ...@@ -276,7 +273,6 @@ static __inline__ u32 __FfmpegChromaToFourCC( int i_ffmpegchroma )
switch( i_ffmpegchroma ) switch( i_ffmpegchroma )
{ {
case( PIX_FMT_YUV420P ): case( PIX_FMT_YUV420P ):
return FOURCC_I420;
case( PIX_FMT_YUV422 ): case( PIX_FMT_YUV422 ):
return FOURCC_I420; return FOURCC_I420;
case( PIX_FMT_RGB24 ): case( PIX_FMT_RGB24 ):
...@@ -312,7 +308,6 @@ static int decoder_Run ( decoder_config_t * p_config ) ...@@ -312,7 +308,6 @@ static int decoder_Run ( decoder_config_t * p_config )
p_vdec->p_fifo = p_config->p_decoder_fifo; p_vdec->p_fifo = p_config->p_decoder_fifo;
p_vdec->p_config = p_config; p_vdec->p_config = p_config;
p_vdec->p_vout = NULL;
if( InitThread( p_vdec ) != 0 ) if( InitThread( p_vdec ) != 0 )
{ {
...@@ -364,8 +359,8 @@ static int InitThread( videodec_thread_t *p_vdec ) ...@@ -364,8 +359,8 @@ static int InitThread( videodec_thread_t *p_vdec )
/* we cannot create vout because we don't know what chroma */ /* we cannot create vout because we don't know what chroma */
/*init ffmpeg */ /*init ffmpeg */
/* XXX maybe it's not multi thread capable */ /* TODO: add a global variable to know if init was already done
/* TODO: add a global variable to know if init was already done */ in case we use it also for audio */
if( b_ffmpeginit == 0 ) if( b_ffmpeginit == 0 )
{ {
avcodec_init(); avcodec_init();
...@@ -462,7 +457,6 @@ static void DecodeThread( videodec_thread_t *p_vdec ) ...@@ -462,7 +457,6 @@ static void DecodeThread( videodec_thread_t *p_vdec )
int i_len; int i_len;
int b_gotpicture; int b_gotpicture;
int b_convert; int b_convert;
int i_aspect;
pes_packet_t *p_pes; pes_packet_t *p_pes;
AVPicture avpicture; /* ffmpeg picture */ AVPicture avpicture; /* ffmpeg picture */
...@@ -485,7 +479,7 @@ static void DecodeThread( videodec_thread_t *p_vdec ) ...@@ -485,7 +479,7 @@ static void DecodeThread( videodec_thread_t *p_vdec )
do do
{ {
__PACKET_FILL( p_vdec ); __PACKET_FILL( p_vdec );
if( p_vdec->p_fifo->b_die ) if( (p_vdec->p_fifo->b_die)||(p_vdec->p_fifo->b_error) )
{ {
return; return;
} }
...@@ -528,10 +522,6 @@ static void DecodeThread( videodec_thread_t *p_vdec ) ...@@ -528,10 +522,6 @@ static void DecodeThread( videodec_thread_t *p_vdec )
*/ */
/* create vout */ /* create vout */
/* FIXME */
/*
p_vdec->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3; AR_3_4_PICTURE
*/
/* ffmpeg set it for our with some codec */ /* ffmpeg set it for our with some codec */
if( (p_vdec->format.i_width == 0)||(p_vdec->format.i_height == 0) ) if( (p_vdec->format.i_width == 0)||(p_vdec->format.i_height == 0) )
...@@ -540,32 +530,15 @@ static void DecodeThread( videodec_thread_t *p_vdec ) ...@@ -540,32 +530,15 @@ static void DecodeThread( videodec_thread_t *p_vdec )
p_vdec->format.i_height = p_vdec->p_context->height; p_vdec->format.i_height = p_vdec->p_context->height;
} }
/* calculate i_aspect */ /* calculate i_aspect */
i_aspect = VOUT_ASPECT_FACTOR * p_vdec->format.i_width / p_vdec->i_aspect = VOUT_ASPECT_FACTOR * p_vdec->format.i_width /
p_vdec->format.i_height; p_vdec->format.i_height;
/* FIXME comment faire ca proprement */
/*
if( i_aspect == VOUT_ASPECT_FACTOR * 4 /3 )
{
i_aspect = 1;
}
else
{
if( i_aspect == VOUT_ASPECT_FACTOR * 16 /9 )
{
i_aspect = 2;
}
}
*/
p_vdec->i_aspect = i_aspect;
p_vdec->i_chroma = i_chroma; p_vdec->i_chroma = i_chroma;
intf_WarnMsg( 1, "vdec info: creating vout %dx%d chroma %4.4s %s %s", intf_WarnMsg( 1, "vdec info: creating vout %dx%d chroma %4.4s %s",
p_vdec->format.i_width, p_vdec->format.i_width,
p_vdec->format.i_height, p_vdec->format.i_height,
(char*)&i_chroma, (char*)&p_vdec->i_chroma,
b_convert ? "(with convertion)" : "", b_convert ? "(with convertion)" : "" );
/*i_aspect ==1 ? "aspect 4:3" : "aspect 16:9"*/
"free aspect" );
p_vdec->p_vout = vout_CreateThread( p_vdec->p_vout = vout_CreateThread(
NULL, NULL,
......
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