From e123c1dfcd8dd39565fc08c3db67b935c8fcf0f2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 30 Jan 2015 21:18:30 +0100 Subject: [PATCH] player: rearrange some A/V-sync related code Move the update_avsync_before_frame() call further down. Moving it closer to where the time_frame value is used (and which the function updates) should make the code more readable. With this change, there's no need anymore to reset the time_frame value on the video reconfig path. Move the update_avsync_after_frame() up. Now no meaningful amount of time passes since the previous get_relative_time() call anymore, and the second one can be removed. --- player/video.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/player/video.c b/player/video.c index 9d89fdf1ed..f8b1888ad4 100644 --- a/player/video.c +++ b/player/video.c @@ -706,7 +706,6 @@ static void update_avsync_after_frame(struct MPContext *mpctx) { struct MPOpts *opts = mpctx->opts; - mpctx->time_frame -= get_relative_time(mpctx); mpctx->last_av_difference = 0; if (mpctx->audio_status != STATUS_PLAYING || @@ -783,9 +782,6 @@ void write_video(struct MPContext *mpctx, double endpts) if (mpctx->video_status > STATUS_PLAYING) mpctx->video_status = STATUS_PLAYING; - mpctx->time_frame -= get_relative_time(mpctx); - update_avsync_before_frame(mpctx); - if (r != VD_NEW_FRAME) { mpctx->sleeptime = 0; // Decode more in next iteration. return; @@ -812,9 +808,11 @@ void write_video(struct MPContext *mpctx, double endpts) goto error; } init_vo(mpctx); - mpctx->time_frame = 0; // display immediately } + mpctx->time_frame -= get_relative_time(mpctx); + update_avsync_before_frame(mpctx); + double time_frame = MPMAX(mpctx->time_frame, -1); int64_t pts = mp_time_us() + (int64_t)(time_frame * 1e6); @@ -847,6 +845,8 @@ void write_video(struct MPContext *mpctx, double endpts) mpctx->last_vo_pts = mpctx->video_pts; mpctx->playback_pts = mpctx->video_pts; + update_avsync_after_frame(mpctx); + mpctx->osd_force_update = true; update_osd_msg(mpctx); update_subtitles(mpctx); @@ -860,7 +860,6 @@ void write_video(struct MPContext *mpctx, double endpts) // After a seek, make sure to wait until the first frame is visible. vo_wait_frame(vo); } - update_avsync_after_frame(mpctx); screenshot_flip(mpctx); mp_notify(mpctx, MPV_EVENT_TICK, NULL);