1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-20 06:11:10 +00:00

Move the resync-related code into more consistent places instead of having it

scattered all over the place with half of it forgotten in some places.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30420 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2010-01-24 15:16:39 +00:00
parent 213092c8dc
commit 71dcc053fe
5 changed files with 28 additions and 42 deletions

View File

@ -455,6 +455,8 @@ int decode_audio(sh_audio_t *sh_audio, int minlen)
void resync_audio_stream(sh_audio_t *sh_audio)
{
sh_audio->a_buffer_len = 0;
sh_audio->a_out_buffer_len = 0;
sh_audio->a_in_buffer_len = 0; // clear audio input buffer
if (!sh_audio->initialized)
return;

View File

@ -133,6 +133,10 @@ int set_rectangle(sh_video_t *sh_video,int param,int value)
void resync_video_stream(sh_video_t *sh_video)
{
sh_video->timer = 0;
sh_video->next_frame_time = 0;
sh_video->num_buffered_pts = 0;
sh_video->last_pts = MP_NOPTS_VALUE;
if(mpvdec) mpvdec->control(sh_video, VDCTRL_RESYNC_STREAM, NULL);
}

View File

@ -1183,6 +1183,20 @@ demuxer_t *demux_open(stream_t *vs, int file_format, int audio_id,
return res;
}
static void demux_resync(demuxer_t *demuxer)
{
sh_video_t *sh_video = demuxer->video->sh;
sh_audio_t *sh_audio = demuxer->audio->sh;
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
if (sh_video) {
ds_fill_buffer(demuxer->video);
resync_video_stream(sh_video);
}
if (sh_audio) {
ds_fill_buffer(demuxer->audio);
resync_audio_stream(sh_audio);
}
}
void demux_flush(demuxer_t *demuxer)
{
@ -1196,8 +1210,6 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
{
demux_stream_t *d_audio = demuxer->audio;
demux_stream_t *d_video = demuxer->video;
sh_audio_t *sh_audio = d_audio->sh;
sh_video_t *sh_video = d_video->sh;
double tmp = 0;
double pts;
@ -1214,17 +1226,11 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
}
demux_flush(demuxer);
// clear demux buffers:
if (sh_audio)
sh_audio->a_buffer_len = 0;
demuxer->stream->eof = 0;
demuxer->video->eof = 0;
demuxer->audio->eof = 0;
if (sh_video)
sh_video->timer = 0; // !!!!!!
if (flags & SEEK_ABSOLUTE)
pts = 0.0f;
else {
@ -1243,7 +1249,7 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
if (stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_TIME, &pts) !=
STREAM_UNSUPPORTED) {
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
demux_resync(demuxer);
return 1;
}
@ -1251,8 +1257,7 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
if (demuxer->desc->seek)
demuxer->desc->seek(demuxer, rel_seek_secs, audio_delay, flags);
if (sh_audio)
resync_audio_stream(sh_audio);
demux_resync(demuxer);
return 1;
}
@ -1475,8 +1480,6 @@ int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode,
{
int ris;
int current, total;
sh_video_t *sh_video = demuxer->video->sh;
sh_audio_t *sh_audio = demuxer->audio->sh;
if (!demuxer->num_chapters || !demuxer->chapters) {
if (!mode) {
@ -1491,17 +1494,9 @@ int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode,
ris = stream_control(demuxer->stream, STREAM_CTRL_SEEK_TO_CHAPTER,
&chapter);
if (ris != STREAM_UNSUPPORTED)
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
if (sh_video) {
ds_fill_buffer(demuxer->video);
resync_video_stream(sh_video);
}
if (sh_audio) {
ds_fill_buffer(demuxer->audio);
resync_audio_stream(sh_audio);
}
demux_resync(demuxer);
// exit status may be ok, but main() doesn't have to seek itself
// (because e.g. dvds depend on sectors, not on pts)
*seek_pts = -1.0;
@ -1525,6 +1520,9 @@ int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, int mode,
return ris != STREAM_UNSUPPORTED ? chapter : -1;
} else { // chapters structure is set in the demuxer
sh_video_t *sh_video = demuxer->video->sh;
sh_audio_t *sh_audio = demuxer->audio->sh;
total = demuxer->num_chapters;
if (mode == 1) //absolute seeking
@ -1659,8 +1657,6 @@ int demuxer_get_current_angle(demuxer_t *demuxer)
int demuxer_set_angle(demuxer_t *demuxer, int angle)
{
int ris, angles = -1;
sh_video_t *sh_video = demuxer->video->sh;
sh_audio_t *sh_audio = demuxer->audio->sh;
angles = demuxer_angles_count(demuxer);
if ((angles < 1) || (angle > angles))
@ -1672,16 +1668,7 @@ int demuxer_set_angle(demuxer_t *demuxer, int angle)
if (ris == STREAM_UNSUPPORTED)
return -1;
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
if (sh_video) {
ds_fill_buffer(demuxer->video);
resync_video_stream(sh_video);
}
if (sh_audio) {
ds_fill_buffer(demuxer->audio);
resync_audio_stream(sh_audio);
}
demux_resync(demuxer);
return angle;
}

View File

@ -1708,7 +1708,6 @@ static int edl_seek(edl_record_ptr next_edl_record, demuxer_t* demuxer, demux_st
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);
//if(vo_spudec) spudec_reset(vo_spudec);
if (audio_delay != 0.0) fixdelay(demuxer->video, d_audio, mux_a, frame_data, framecopy);
return 1;

View File

@ -2543,12 +2543,8 @@ static int seek(MPContext *mpctx, double amount, int style)
mpctx->startup_decode_retry = DEFAULT_STARTUP_DECODE_RETRY;
if (mpctx->sh_video) {
current_module = "seek_video_reset";
resync_video_stream(mpctx->sh_video);
if (vo_config_count)
mpctx->video_out->control(VOCTRL_RESET, NULL);
mpctx->sh_video->next_frame_time = 0;
mpctx->sh_video->num_buffered_pts = 0;
mpctx->sh_video->last_pts = MP_NOPTS_VALUE;
mpctx->num_buffered_frames = 0;
mpctx->delay = 0;
mpctx->time_frame = 0;
@ -2563,8 +2559,6 @@ static int seek(MPContext *mpctx, double amount, int style)
if (mpctx->sh_audio) {
current_module = "seek_audio_reset";
mpctx->audio_out->reset(); // stop audio, throwing away buffered data
mpctx->sh_audio->a_buffer_len = 0;
mpctx->sh_audio->a_out_buffer_len = 0;
if (!mpctx->sh_video)
update_subtitles(NULL, mpctx->sh_audio->pts, mpctx->d_sub, 1);
}