Mercurial > mplayer.hg
changeset 17636:b849a99cdc3c
Second-try commit of this patch.
1. Include audio_delay as an argument to demux_seek.
2. Modify demux_seek_avi to adjust the audio/video stream positions so
that mplayer/mencoder will instantly be in sync even when -delay is
specified.
I've quadruple checked this time; hopefully I haven't missed anything.
line wrap: on
line diff
--- a/libmpdemux/demux_aac.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_aac.c Fri Feb 17 01:57:41 2006 +0000 @@ -207,7 +207,7 @@ //This is an almost verbatim copy of high_res_mp3_seek(), from demux_audio.c -static void demux_aac_seek(demuxer_t *demuxer, float rel_seek_secs, int flags) +static void demux_aac_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { aac_priv_t *priv = (aac_priv_t *) demuxer->priv; demux_stream_t *d_audio=demuxer->audio;
--- a/libmpdemux/demux_asf.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_asf.c Fri Feb 17 01:57:41 2006 +0000 @@ -369,7 +369,7 @@ extern void skip_audio_frame(sh_audio_t *sh_audio); -static void demux_seek_asf(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_seek_asf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ demux_stream_t *d_audio=demuxer->audio; demux_stream_t *d_video=demuxer->video; sh_audio_t *sh_audio=d_audio->sh;
--- a/libmpdemux/demux_audio.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_audio.c Fri Feb 17 01:57:41 2006 +0000 @@ -476,7 +476,7 @@ } } -static void demux_audio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_audio_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ sh_audio_t* sh_audio; stream_t* s; int base,pos;
--- a/libmpdemux/demux_avi.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_avi.c Fri Feb 17 01:57:41 2006 +0000 @@ -618,7 +618,7 @@ //extern float initial_pts_delay; -void demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,int flags){ +void demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ avi_priv_t *priv=demuxer->priv; demux_stream_t *d_audio=demuxer->audio; demux_stream_t *d_video=demuxer->video; @@ -706,8 +706,8 @@ curr_audio_pos/=align; curr_audio_pos*=align; #else - curr_audio_pos=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; - curr_audio_pos-=sh_audio->audio.dwStart; + /* immediate seeking to audio position, including when streams are delayed */ + curr_audio_pos=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; curr_audio_pos*=sh_audio->audio.dwSampleSize; #endif @@ -733,7 +733,8 @@ } else { // VBR audio - int chunks=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; + /* immediate seeking to audio position, including when streams are delayed */ + int chunks=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; audio_chunk_pos=0; // find audio chunk pos:
--- a/libmpdemux/demux_avs.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_avs.c Fri Feb 17 01:57:41 2006 +0000 @@ -375,7 +375,7 @@ } } -static void demux_seek_avs(demuxer_t *demuxer, float rel_seek_secs,int flags) +static void demux_seek_avs(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { demux_stream_t *d_video=demuxer->video; sh_video_t *sh_video=d_video->sh;
--- a/libmpdemux/demux_demuxers.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_demuxers.c Fri Feb 17 01:57:41 2006 +0000 @@ -57,7 +57,7 @@ return 0; } -static void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,int flags) { +static void demux_demuxers_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags) { dd_priv_t* priv; float pos; priv=demuxer->priv; @@ -66,13 +66,13 @@ priv->sd->stream->eof = 0; // Seek video - demux_seek(priv->vd,rel_seek_secs,flags); + demux_seek(priv->vd,rel_seek_secs,audio_delay,flags); // Get the new pos pos = demuxer->video->pts; if(priv->ad != priv->vd) { sh_audio_t* sh = (sh_audio_t*)demuxer->audio->sh; - demux_seek(priv->ad,pos,1); + demux_seek(priv->ad,pos,audio_delay,1); // In case the demuxer don't set pts if(!demuxer->audio->pts) demuxer->audio->pts = pos-((ds_tell_pts(demuxer->audio)-sh->a_in_buffer_len)/(float)sh->i_bps); @@ -80,7 +80,7 @@ } if(priv->sd != priv->vd) - demux_seek(priv->sd,pos,1); + demux_seek(priv->sd,pos,audio_delay,1); }
--- a/libmpdemux/demux_film.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_film.c Fri Feb 17 01:57:41 2006 +0000 @@ -46,7 +46,7 @@ unsigned int film_version; } film_data_t; -static void demux_seek_film(demuxer_t *demuxer, float rel_seek_secs, int flags) +static void demux_seek_film(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { film_data_t *film_data = (film_data_t *)demuxer->priv; int new_current_chunk=(flags&1)?0:film_data->current_chunk;
--- a/libmpdemux/demux_fli.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_fli.c Fri Feb 17 01:57:41 2006 +0000 @@ -22,7 +22,7 @@ unsigned int *frame_size; } fli_frames_t; -static void demux_seek_fli(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_seek_fli(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ fli_frames_t *frames = (fli_frames_t *)demuxer->priv; sh_video_t *sh_video = demuxer->video->sh; int newpos=(flags&1)?0:frames->current_frame;
--- a/libmpdemux/demux_lavf.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_lavf.c Fri Feb 17 01:57:41 2006 +0000 @@ -389,9 +389,9 @@ return 1; } -static void demux_seek_lavf(demuxer_t *demuxer, float rel_seek_secs, int flags){ +static void demux_seek_lavf(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags){ lavf_priv_t *priv = demuxer->priv; - mp_msg(MSGT_DEMUX,MSGL_DBG2,"demux_seek_lavf(%p, %f, %d)\n", demuxer, rel_seek_secs, flags); + mp_msg(MSGT_DEMUX,MSGL_DBG2,"demux_seek_lavf(%p, %f, %f, %d)\n", demuxer, rel_seek_secs, audio_delay, flags); #if LIBAVFORMAT_BUILD < 4619 av_seek_frame(priv->avfc, -1, priv->last_pts + rel_seek_secs*AV_TIME_BASE);
--- a/libmpdemux/demux_mf.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_mf.c Fri Feb 17 01:57:41 2006 +0000 @@ -15,7 +15,7 @@ #include "stheader.h" #include "mf.h" -static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_seek_mf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ mf_t * mf = (mf_t *)demuxer->priv; sh_video_t * sh_video = demuxer->video->sh; int newpos = (flags & 1)?0:mf->curr_frame;
--- a/libmpdemux/demux_mov.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_mov.c Fri Feb 17 01:57:41 2006 +0000 @@ -2007,7 +2007,7 @@ return pts; } -static void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){ +static void demux_seek_mov(demuxer_t *demuxer,float pts,float audio_delay,int flags){ mov_priv_t* priv=demuxer->priv; demux_stream_t* ds; mov_track_t* trak;
--- a/libmpdemux/demux_mpc.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_mpc.c Fri Feb 17 01:57:41 2006 +0000 @@ -153,7 +153,7 @@ return 1; } -static void demux_mpc_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_mpc_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ sh_audio_t* sh_audio = demuxer->audio->sh; da_priv_t* priv = demuxer->priv; stream_t* s = demuxer->stream;
--- a/libmpdemux/demux_mpg.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_mpg.c Fri Feb 17 01:57:41 2006 +0000 @@ -676,7 +676,7 @@ extern void skip_audio_frame(sh_audio_t *sh_audio); -void demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,int flags){ +void demux_seek_mpg(demuxer_t *demuxer,float rel_seek_secs,float audio_delay, int flags){ demux_stream_t *d_audio=demuxer->audio; demux_stream_t *d_video=demuxer->video; sh_audio_t *sh_audio=d_audio->sh;
--- a/libmpdemux/demux_nsv.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_nsv.c Fri Feb 17 01:57:41 2006 +0000 @@ -34,7 +34,7 @@ /** * Seeking still to be implemented */ -static void demux_seek_nsv ( demuxer_t *demuxer, float rel_seek_secs, int flags ) +static void demux_seek_nsv ( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags ) { // seeking is not yet implemented }
--- a/libmpdemux/demux_nuv.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_nuv.c Fri Feb 17 01:57:41 2006 +0000 @@ -63,7 +63,7 @@ /** * Seek to a position relative to the current position, indicated in time. */ -static void demux_seek_nuv ( demuxer_t *demuxer, float rel_seek_secs, int flags ) +static void demux_seek_nuv ( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags ) { #define MAX_TIME 1000000 nuv_priv_t* priv = demuxer->priv;
--- a/libmpdemux/demux_ogg.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_ogg.c Fri Feb 17 01:57:41 2006 +0000 @@ -1422,7 +1422,7 @@ } -static void demux_ogg_seek(demuxer_t *demuxer,float rel_seek_secs,int flags) { +static void demux_ogg_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags) { ogg_demuxer_t* ogg_d = demuxer->priv; ogg_sync_state* sync = &ogg_d->sync; ogg_page* page= &ogg_d->page;
--- a/libmpdemux/demux_pva.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_pva.c Fri Feb 17 01:57:41 2006 +0000 @@ -466,7 +466,7 @@ return 1; } -static void demux_seek_pva(demuxer_t * demuxer,float rel_seek_secs,int flags) +static void demux_seek_pva(demuxer_t * demuxer,float rel_seek_secs,float audio_delay,int flags) { int total_bitrate=0; off_t dest_offset;
--- a/libmpdemux/demux_rawaudio.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_rawaudio.c Fri Feb 17 01:57:41 2006 +0000 @@ -79,7 +79,7 @@ return 1; } -static void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_rawaudio_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ stream_t* s = demuxer->stream; sh_audio_t* sh_audio = demuxer->audio->sh; off_t base,pos;
--- a/libmpdemux/demux_rawdv.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_rawdv.c Fri Feb 17 01:57:41 2006 +0000 @@ -36,7 +36,7 @@ dv_decoder_t *decoder; } rawdv_frames_t; -static void demux_seek_rawdv(demuxer_t *demuxer,float rel_seek_secs,int flags) +static void demux_seek_rawdv(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags) { rawdv_frames_t *frames = (rawdv_frames_t *)demuxer->priv; sh_video_t *sh_video = demuxer->video->sh;
--- a/libmpdemux/demux_rawvideo.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_rawvideo.c Fri Feb 17 01:57:41 2006 +0000 @@ -118,7 +118,7 @@ return 1; } -static void demux_rawvideo_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_rawvideo_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ stream_t* s = demuxer->stream; sh_video_t* sh_video = demuxer->video->sh; off_t pos;
--- a/libmpdemux/demux_real.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_real.c Fri Feb 17 01:57:41 2006 +0000 @@ -1825,7 +1825,7 @@ } /* please upload RV10 samples WITH INDEX CHUNK */ -static void demux_seek_real(demuxer_t *demuxer, float rel_seek_secs, int flags) +static void demux_seek_real(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { real_priv_t *priv = demuxer->priv; demux_stream_t *d_audio = demuxer->audio;
--- a/libmpdemux/demux_realaud.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_realaud.c Fri Feb 17 01:57:41 2006 +0000 @@ -341,7 +341,7 @@ #if 0 /* please upload RV10 samples WITH INDEX CHUNK */ -int demux_seek_ra(demuxer_t *demuxer, float rel_seek_secs, int flags) +int demux_seek_ra(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { real_priv_t *priv = demuxer->priv; demux_stream_t *d_audio = demuxer->audio;
--- a/libmpdemux/demux_ts.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_ts.c Fri Feb 17 01:57:41 2006 +0000 @@ -3071,7 +3071,7 @@ extern int sync_video_packet(demux_stream_t *); extern int skip_video_packet(demux_stream_t *); -static void demux_seek_ts(demuxer_t *demuxer, float rel_seek_secs, int flags) +static void demux_seek_ts(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { demux_stream_t *d_audio=demuxer->audio; demux_stream_t *d_video=demuxer->video;
--- a/libmpdemux/demux_ty.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_ty.c Fri Feb 17 01:57:41 2006 +0000 @@ -1237,7 +1237,7 @@ return( 1 ); } -static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, int flags ) +static void demux_seek_ty( demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags ) { demux_stream_t *d_audio = demuxer->audio; demux_stream_t *d_video = demuxer->video;
--- a/libmpdemux/demux_vqf.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_vqf.c Fri Feb 17 01:57:41 2006 +0000 @@ -179,7 +179,7 @@ return 1; } -static void demux_seek_vqf(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_seek_vqf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ #if 0 stream_t* s = demuxer->stream; sh_audio_t* sh_audio = demuxer->audio->sh;
--- a/libmpdemux/demux_xmms.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_xmms.c Fri Feb 17 01:57:41 2006 +0000 @@ -297,7 +297,7 @@ return 1; } -static void demux_xmms_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ +static void demux_xmms_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ stream_t* s = demuxer->stream; sh_audio_t* sh_audio = demuxer->audio->sh; xmms_priv_t *priv=demuxer->priv;
--- a/libmpdemux/demux_y4m.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demux_y4m.c Fri Feb 17 01:57:41 2006 +0000 @@ -231,7 +231,7 @@ return demuxer; } -static void demux_seek_y4m(demuxer_t *demuxer, float rel_seek_secs, int flags) { +static void demux_seek_y4m(demuxer_t *demuxer, float rel_seek_secs, float audio_delay, int flags) { sh_video_t* sh = demuxer->video->sh; y4m_priv_t* priv = demuxer->priv; int rel_seek_frames = sh->fps*rel_seek_secs;
--- a/libmpdemux/demuxer.c Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demuxer.c Fri Feb 17 01:57:41 2006 +0000 @@ -859,7 +859,7 @@ } -int demux_seek(demuxer_t *demuxer,float rel_seek_secs,int flags){ +int demux_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ demux_stream_t *d_audio=demuxer->audio; demux_stream_t *d_video=demuxer->video; sh_audio_t *sh_audio=d_audio->sh; @@ -893,7 +893,7 @@ #endif if (demuxer->desc->seek) - demuxer->desc->seek(demuxer,rel_seek_secs,flags); + demuxer->desc->seek(demuxer,rel_seek_secs,audio_delay,flags); if (sh_audio) resync_audio_stream(sh_audio);
--- a/libmpdemux/demuxer.h Thu Feb 16 22:43:42 2006 +0000 +++ b/libmpdemux/demuxer.h Fri Feb 17 01:57:41 2006 +0000 @@ -151,7 +151,7 @@ /// Close the demuxer void (*close)(struct demuxer_st *demuxer); ///< Optional // Seek - void (*seek)(struct demuxer_st *demuxer, float rel_seek_secs, int flags); ///< Optional + void (*seek)(struct demuxer_st *demuxer, float rel_seek_secs, float audio_delay, int flags); ///< Optional // Control int (*control)(struct demuxer_st *demuxer, int cmd, void *arg); ///< Optional } demuxer_desc_t; @@ -306,7 +306,7 @@ } demuxer_t* demux_open(stream_t *stream,int file_format,int aid,int vid,int sid,char* filename); -int demux_seek(demuxer_t *demuxer,float rel_seek_secs,int flags); +int demux_seek(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags); demuxer_t* new_demuxers_demuxer(demuxer_t* vd, demuxer_t* ad, demuxer_t* sd); // AVI demuxer params:
--- a/mencoder.c Thu Feb 16 22:43:42 2006 +0000 +++ b/mencoder.c Fri Feb 17 01:57:41 2006 +0000 @@ -1037,12 +1037,12 @@ else sscanf(seek_to_sec, "%f", &d); - demux_seek(demuxer, d, 1); + demux_seek(demuxer, d, audio_delay, 1); // there is 2 way to handle the -ss option in 3-pass mode: // > 1. do the first pass for the whole file, and use -ss for 2nd/3rd pases only // > 2. do all the 3 passes with the same -ss value // this line enables behaviour 1. (and kills 2. at the same time): -// if(demuxer2) demux_seek(demuxer2, d, 1); +// if(demuxer2) demux_seek(demuxer2, d, audio_delay, 1); } if (out_file_format == MUXER_TYPE_MPEG) @@ -1770,7 +1770,7 @@ if (sh_video->pts >= next_edl_record->stop_sec) return 1; // nothing to do... if (!edl_seek_type) { - if(demux_seek(demuxer, next_edl_record->stop_sec - sh_video->pts, 0)){ + if(demux_seek(demuxer, next_edl_record->stop_sec - sh_video->pts, audio_delay, 0)){ sh_video->pts = demuxer->video->pts; //if (vo_vobsub) vobsub_seek(vo_vobsub,sh_video->pts); resync_video_stream(sh_video);
--- a/mplayer.c Thu Feb 16 22:43:42 2006 +0000 +++ b/mplayer.c Fri Feb 17 01:57:41 2006 +0000 @@ -4185,7 +4185,7 @@ if(rel_seek_secs || abs_seek_pos){ current_module="seek"; - if(demux_seek(demuxer,rel_seek_secs,abs_seek_pos)){ + if(demux_seek(demuxer,rel_seek_secs,audio_delay,abs_seek_pos)){ // success: /* FIXME there should be real seeking for vobsub */ if(sh_video) sh_video->pts=d_video->pts;