1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 08:12:17 +00:00

player: add function to compute past frame durations

And use it for the estimated-vf-fps property (it should be doing the
same as before).
This commit is contained in:
wm4 2015-05-24 18:00:34 +02:00
parent 0d0444fed0
commit 58e7d0a30b
3 changed files with 28 additions and 17 deletions

View File

@ -2595,25 +2595,14 @@ static int mp_property_vf_fps(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
if (!mpctx->d_video)
return M_PROPERTY_UNAVAILABLE;
double next_pts = mpctx->vo_pts_history_pts[0];
if (mpctx->vo_pts_history_seek[0] != mpctx->vo_pts_history_seek_ts)
double durations[10];
int num = get_past_frame_durations(mpctx, durations, MP_ARRAY_SIZE(durations));
if (num < MP_ARRAY_SIZE(durations))
return M_PROPERTY_UNAVAILABLE;
if (next_pts == MP_NOPTS_VALUE)
return M_PROPERTY_UNAVAILABLE;
int num_samples = 10;
assert(num_samples + 1 <= MAX_NUM_VO_PTS);
double duration = 0;
for (int n = 1; n < 1 + num_samples; n++) {
double frame_pts = mpctx->vo_pts_history_pts[n];
// Discontinuity -> refuse to return a value.
if (mpctx->vo_pts_history_seek[n] != mpctx->vo_pts_history_seek_ts)
return M_PROPERTY_UNAVAILABLE;
if (frame_pts == MP_NOPTS_VALUE)
return M_PROPERTY_UNAVAILABLE;
duration += next_pts - frame_pts;
next_pts = frame_pts;
}
return m_property_double_ro(action, arg, num_samples / duration);
for (int n = 0; n < num; n++)
duration += durations[n];
return m_property_double_ro(action, arg, num / duration);
}
/// Video aspect (RO)

View File

@ -466,6 +466,7 @@ void mp_idle(struct MPContext *mpctx);
void idle_loop(struct MPContext *mpctx);
void handle_force_window(struct MPContext *mpctx, bool reconfig);
void add_frame_pts(struct MPContext *mpctx, double pts);
int get_past_frame_durations(struct MPContext *mpctx, double *fd, int num);
void seek_to_last_frame(struct MPContext *mpctx);
// scripting.c

View File

@ -691,6 +691,27 @@ void add_frame_pts(struct MPContext *mpctx, double pts)
mpctx->vo_pts_history_pts[0] = pts;
}
// Return the last (at most num) frame duration in fd[]. Return the number of
// entries written to fd[] (range [0, num]). fd[0] is the most recent frame.
int get_past_frame_durations(struct MPContext *mpctx, double *fd, int num)
{
double next_pts = mpctx->vo_pts_history_pts[0];
if (mpctx->vo_pts_history_seek[0] != mpctx->vo_pts_history_seek_ts ||
next_pts == MP_NOPTS_VALUE)
return 0;
int num_ret = 0;
for (int n = 1; n < MAX_NUM_VO_PTS && num_ret < num; n++) {
double frame_pts = mpctx->vo_pts_history_pts[n];
// Discontinuity -> refuse to return a value.
if (mpctx->vo_pts_history_seek[n] != mpctx->vo_pts_history_seek_ts ||
next_pts <= frame_pts || frame_pts == MP_NOPTS_VALUE)
break;
fd[num_ret++] = next_pts - frame_pts;
next_pts = frame_pts;
}
return num_ret;
}
static double find_previous_pts(struct MPContext *mpctx, double pts)
{
for (int n = 0; n < MAX_NUM_VO_PTS - 1; n++) {