Commit ee653a2e authored by Laurent Aimar's avatar Laurent Aimar

* plugins/avi/avi.c : you can now use slow and fast reading.

                          After seeking, audio and video synchro is better.
parent f7cee4f2
...@@ -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.9 2002/04/30 16:42:14 fenrir Exp $ * $Id: avi.c,v 1.10 2002/05/02 10:54:34 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
...@@ -1216,6 +1216,7 @@ static int __AVI_ReAlign( input_thread_t *p_input ) ...@@ -1216,6 +1216,7 @@ static int __AVI_ReAlign( input_thread_t *p_input )
{ {
u32 u32_pos; u32 u32_pos;
off_t i_pos; off_t i_pos;
int b_after = 0;
demux_data_avi_file_t *p_avi_demux; demux_data_avi_file_t *p_avi_demux;
AVIStreamInfo_t *p_info; AVIStreamInfo_t *p_info;
...@@ -1249,7 +1250,14 @@ static int __AVI_ReAlign( input_thread_t *p_input ) ...@@ -1249,7 +1250,14 @@ static int __AVI_ReAlign( input_thread_t *p_input )
/* don't do anything we are in the current chunk */ /* don't do anything we are in the current chunk */
return( 0 ); return( 0 );
} }
if( i_pos < p_info->p_index[p_info->i_idxposc].i_offset )
{
b_after = 0;
}
else
{
b_after = 1;
}
/* now find in what chunk we are */ /* now find in what chunk we are */
while( ( i_pos < p_info->p_index[p_info->i_idxposc].i_offset ) while( ( i_pos < p_info->p_index[p_info->i_idxposc].i_offset )
&&( p_info->i_idxposc > 0 ) ) &&( p_info->i_idxposc > 0 ) )
...@@ -1271,28 +1279,25 @@ static int __AVI_ReAlign( input_thread_t *p_input ) ...@@ -1271,28 +1279,25 @@ static int __AVI_ReAlign( input_thread_t *p_input )
if( ( !p_info->header.i_samplesize ) && ( p_info->i_cat == VIDEO_ES ) ) if( ( !p_info->header.i_samplesize ) && ( p_info->i_cat == VIDEO_ES ) )
{ {
/* only for chunk stream */ /* only for chunk stream */
int i_idxposc = p_info->i_idxposc; if( b_after )
int i_idxposc_b = p_info->i_idxposc; /* before */
int i_idxposc_a ; /* after */
while( ( i_idxposc_b > 0 )
&&((p_info->p_index[i_idxposc_b].i_flags&AVIIF_KEYFRAME) == 0) )
{ {
i_idxposc_b--; while(!(p_info->p_index[p_info->i_idxposc].i_flags&AVIIF_KEYFRAME) )
{
if( __AVI_NextIndexEntry( p_input, p_info ) != 0 )
{
break;
}
}
} }
else
while((p_info->p_index[p_info->i_idxposc].i_flags&AVIIF_KEYFRAME) == 0 ) {
{ while( ( p_info->i_idxposc > 0 ) &&
if( __AVI_NextIndexEntry( p_input, p_info ) != 0 ) (!(p_info->p_index[p_info->i_idxposc].i_flags&AVIIF_KEYFRAME)) )
{ {
break; p_info->i_idxposc--;
} }
} }
i_idxposc_a = p_info->i_idxposc; __AVI_GoToStreamChunk( p_input, p_info, p_info->i_idxposc );
i_idxposc = (i_idxposc_a - i_idxposc <
i_idxposc - i_idxposc_b ) ? i_idxposc_a : i_idxposc_b;
__AVI_GoToStreamChunk( p_input, p_info, i_idxposc );
} }
return( 0 ); return( 0 );
...@@ -1422,7 +1427,8 @@ static pes_packet_t *__AVI_GetFrameInPES( input_thread_t *p_input, ...@@ -1422,7 +1427,8 @@ static pes_packet_t *__AVI_GetFrameInPES( input_thread_t *p_input,
static void __AVI_DecodePES( AVIStreamInfo_t *p_info, static void __AVI_DecodePES( AVIStreamInfo_t *p_info,
pes_packet_t *p_pes, pes_packet_t *p_pes,
mtime_t i_date ) mtime_t i_date,
int i_rate )
{ {
pes_packet_t *p_pes_next; pes_packet_t *p_pes_next;
if( ( !p_info )||( !p_pes ) ) if( ( !p_info )||( !p_pes ) )
...@@ -1442,7 +1448,8 @@ static void __AVI_DecodePES( AVIStreamInfo_t *p_info, ...@@ -1442,7 +1448,8 @@ static void __AVI_DecodePES( AVIStreamInfo_t *p_info,
{ {
p_pes_next = p_pes->p_next; p_pes_next = p_pes->p_next;
p_pes->p_next = NULL; p_pes->p_next = NULL;
p_pes->i_pts += i_date; p_pes->i_pts = i_date + p_pes->i_pts * (mtime_t)i_rate /
(mtime_t)DEFAULT_RATE;
input_DecodePES( p_info->p_es->p_decoder_fifo, p_pes ); input_DecodePES( p_info->p_es->p_decoder_fifo, p_pes );
p_pes = p_pes_next; p_pes = p_pes_next;
} while( p_pes != NULL ); } while( p_pes != NULL );
...@@ -1512,19 +1519,46 @@ static int AVIDemux( input_thread_t *p_input ) ...@@ -1512,19 +1519,46 @@ static int AVIDemux( input_thread_t *p_input )
{ {
__AVI_SynchroReInit( p_input ); /* resynchro, and make pts audio __AVI_SynchroReInit( p_input ); /* resynchro, and make pts audio
and video egual */ and video egual */
p_avi_demux->i_rate = DEFAULT_RATE;
} }
if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT ) if( p_input->stream.p_selected_program->i_synchro_state == SYNCHRO_REINIT )
{ {
/*realign audio and video stream to the good pts*/ msleep( 200000 ); /* 200ms delay to have empty audio and video buffer*/
/*realign audio and video stream to the good pts*/
if( __AVI_ReAlign( p_input ) != 0 ) if( __AVI_ReAlign( p_input ) != 0 )
{ {
return( 0 ); /* assume EOF */ return( 0 ); /* assume EOF */
} }
__AVI_SynchroReInit( p_input ); /* resynchro, and make pts audio __AVI_SynchroReInit( p_input ); /* resynchro, and make pts audio
and video egual */ and video egual */
p_avi_demux->i_rate = DEFAULT_RATE;
} }
vlc_mutex_lock( &p_input->stream.stream_lock );
if( p_input->stream.control.i_rate != p_avi_demux->i_rate )
{
msleep( 200000 );
p_avi_demux->i_rate = p_input->stream.control.i_rate;
p_avi_demux->i_date = mdate() + DEFAULT_PTS_DELAY
- __AVI_GetPTS( p_avi_demux->p_info_video ) *
(mtime_t)p_avi_demux->i_rate /
(mtime_t)DEFAULT_RATE ;
if( p_avi_demux->i_rate == DEFAULT_RATE )
{
if( p_avi_demux->p_info_audio )
{
p_avi_demux->p_info_audio->b_selected = 1;
}
}
}
if( p_avi_demux->i_rate != DEFAULT_RATE )
{
p_avi_demux->p_info_audio = NULL;
}
vlc_mutex_unlock( &p_input->stream.stream_lock );
/* take care of newly selected audio ES */ /* take care of newly selected audio ES */
if( (p_avi_demux->p_info_audio != NULL) if( (p_avi_demux->p_info_audio != NULL)
&&(p_avi_demux->p_info_audio->b_selected )) &&(p_avi_demux->p_info_audio->b_selected ))
...@@ -1560,9 +1594,9 @@ static int AVIDemux( input_thread_t *p_input ) ...@@ -1560,9 +1594,9 @@ static int AVIDemux( input_thread_t *p_input )
} }
/* send them to decoder */ /* send them to decoder */
__AVI_DecodePES( p_avi_demux->p_info_audio, p_pes_audio, __AVI_DecodePES( p_avi_demux->p_info_audio, p_pes_audio,
p_avi_demux->i_date ); p_avi_demux->i_date, p_avi_demux->i_rate );
__AVI_DecodePES( p_avi_demux->p_info_video, p_pes_video, __AVI_DecodePES( p_avi_demux->p_info_video, p_pes_video,
p_avi_demux->i_date ); p_avi_demux->i_date, p_avi_demux->i_rate );
if( !p_pes_video ) /* no more video */ if( !p_pes_video ) /* no more video */
{ /* currently i need a video stream */ { /* currently i need a video stream */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* avi.h : AVI file Stream input module for vlc * avi.h : AVI file Stream input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: avi.h,v 1.3 2002/04/30 12:35:24 fenrir Exp $ * $Id: avi.h,v 1.4 2002/05/02 10:54:34 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
...@@ -142,7 +142,7 @@ typedef struct AVIStreamInfo_s ...@@ -142,7 +142,7 @@ typedef struct AVIStreamInfo_s
typedef struct demux_data_avi_file_s typedef struct demux_data_avi_file_s
{ {
mtime_t i_date; mtime_t i_date;
int i_rate;
riffchunk_t *p_riff; riffchunk_t *p_riff;
riffchunk_t *p_hdrl; riffchunk_t *p_hdrl;
riffchunk_t *p_movi; riffchunk_t *p_movi;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* libioRIFF.c : AVI file Stream input module for vlc * libioRIFF.c : AVI file Stream input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: libioRIFF.c,v 1.2 2002/04/30 12:35:24 fenrir Exp $ * $Id: libioRIFF.c,v 1.3 2002/05/02 10:54:34 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
...@@ -47,12 +47,8 @@ static int RIFF_FindListChunk( input_thread_t *p_input, riffchunk_t * ...@@ -47,12 +47,8 @@ static int RIFF_FindListChunk( input_thread_t *p_input, riffchunk_t *
static void RIFF_DeleteChunk( input_thread_t * p_input, riffchunk_t *p_chunk ); static void RIFF_DeleteChunk( input_thread_t * p_input, riffchunk_t *p_chunk );
/*
ces fonctions on besoin de pouvoir faire des seek
static int RIFF_GoToChunk(input_thread_t * p_input,riffchunk_t *p_riff); static int RIFF_GoToChunk(input_thread_t * p_input,riffchunk_t *p_riff);
*/
static u32 RIFF_4cToI(char c1,char c2,char c3,char c4);
static char * RIFF_IToStr(u32 i); static char * RIFF_IToStr(u32 i);
/*************************************************************************/ /*************************************************************************/
...@@ -373,15 +369,6 @@ static int RIFF_GoToChunk(input_thread_t * p_input, riffchunk_t *p_riff) ...@@ -373,15 +369,6 @@ static int RIFF_GoToChunk(input_thread_t * p_input, riffchunk_t *p_riff)
return( -1 ); return( -1 );
} }
static u32 RIFF_4cToI(char c1,char c2,char c3,char c4)
{
u32 i;
i = ( ((u32)c1) << 24 ) + ( ((u32)c2) << 16 ) + ( ((u32)c3) << 8 ) + (u32)c4;
return i;
}
static char * RIFF_IToStr(u32 l) static char * RIFF_IToStr(u32 l)
{ {
char *str; char *str;
...@@ -389,7 +376,7 @@ static char * RIFF_IToStr(u32 l) ...@@ -389,7 +376,7 @@ static char * RIFF_IToStr(u32 l)
str=calloc(5,sizeof(char)); str=calloc(5,sizeof(char));
for( i = 0; i < 4; i++) for( i = 0; i < 4; i++)
{ {
str[i] = ( l >> ( (3-i) * 8) )&0xFF; str[i] = ( l >> ( i * 8) )&0xFF;
} }
str[5] = 0; str[5] = 0;
return( str ); return( str );
......
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