summaryrefslogtreecommitdiffstats
path: root/player/video.c
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2022-08-06 03:45:59 +0200
committerDudemanguy <random342@airmail.cc>2023-01-09 15:03:30 +0000
commit67321b14402838eade127fa1d788a41906129b70 (patch)
tree288884e51794cce4d4ad4267ae61b2a5617f2dc1 /player/video.c
parentde9f375a23645091c25a850cc67eb5521e903731 (diff)
downloadmpv-67321b14402838eade127fa1d788a41906129b70.tar.bz2
mpv-67321b14402838eade127fa1d788a41906129b70.tar.xz
player: choose speed of smallest acceptable factor for display sync
Instead of choosing based on smallest deviation from set speed, use the speed change from the smallest factor that does not exceed `video-sync-max-video-change`.
Diffstat (limited to 'player/video.c')
-rw-r--r--player/video.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/player/video.c b/player/video.c
index f7a31efd7a..1ea68f92df 100644
--- a/player/video.c
+++ b/player/video.c
@@ -666,20 +666,16 @@ double calc_average_frame_duration(struct MPContext *mpctx)
// effective video FPS. If this is not possible, try to do it for multiples,
// which still leads to an improved end result.
// Both parameters are durations in seconds.
-static double calc_best_speed(double vsync, double frame, int max_factor)
+static double calc_best_speed(double vsync, double frame,
+ double max_change, int max_factor)
{
double ratio = frame / vsync;
- double best_scale = -1;
- double best_dev = INFINITY;
for (int factor = 1; factor <= max_factor; factor++) {
double scale = ratio * factor / rint(ratio * factor);
- double dev = fabs(scale - 1);
- if (dev < best_dev) {
- best_scale = scale;
- best_dev = dev;
- }
+ if (fabs(scale - 1) <= max_change)
+ return scale;
}
- return best_scale;
+ return -1;
}
static double find_best_speed(struct MPContext *mpctx, double vsync)
@@ -690,10 +686,15 @@ static double find_best_speed(struct MPContext *mpctx, double vsync)
double dur = mpctx->past_frames[n].approx_duration;
if (dur <= 0)
continue;
- total += calc_best_speed(vsync, dur / mpctx->opts->playback_speed,
+ double best = calc_best_speed(vsync, dur / mpctx->opts->playback_speed,
+ mpctx->opts->sync_max_video_change / 100,
mpctx->opts->sync_max_factor);
+ if (best <= 0)
+ continue;
+ total += best;
num++;
}
+ // If it doesn't work, play at normal speed.
return num > 0 ? total / num : 1;
}
@@ -828,12 +829,8 @@ static void handle_display_sync_frame(struct MPContext *mpctx,
return;
mpctx->speed_factor_v = 1.0;
- if (mode != VS_DISP_VDROP) {
- double best = find_best_speed(mpctx, vsync);
- // If it doesn't work, play at normal speed.
- if (fabs(best - 1.0) <= opts->sync_max_video_change / 100)
- mpctx->speed_factor_v = best;
- }
+ if (mode != VS_DISP_VDROP)
+ mpctx->speed_factor_v = find_best_speed(mpctx, vsync);
// Determine for how many vsyncs a frame should be displayed. This can be
// e.g. 2 for 30hz on a 60hz display. It can also be 0 if the video