Skip to content

Commit

Permalink
vo_opengl: add a smoothmotion threshold
Browse files Browse the repository at this point in the history
This allows to skip blending if the if there's a frame close enough to the
next vsync. A value of 0.2 will skip blending for frames that are within 20%
time distance of the vsync.
  • Loading branch information
pigoz committed Dec 14, 2014
1 parent 376b0fb commit adc236c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions video/out/gl_video.c
Expand Up @@ -372,6 +372,9 @@ const struct m_sub_options gl_video_conf = {
{"blend", 2})),
OPT_FLAG("rectangle-textures", use_rectangle, 0),
OPT_COLOR("background", background, 0),
OPT_FLAG("smoothmotion", smoothmotion, 0),
OPT_FLOAT("smoothmotion-threshold", smoothmotion_threshold,
CONF_RANGE, .min = 0, .max = 0.5),
{0}
},
.size = sizeof(struct gl_video_opts),
Expand Down Expand Up @@ -1800,7 +1803,10 @@ void gl_video_render_frame(struct gl_video *p, int fbo, struct frame_timing *t)
double N = t->next_vsync - prev_pts;
double P = t->pts - prev_pts;
double prev_pts_component = N / P;
float ts = p->opts.smoothmotion_threshold;
inter_coeff = 1 - prev_pts_component;
inter_coeff = inter_coeff < 0.0 + ts ? 0.0 : inter_coeff;
inter_coeff = inter_coeff > 1.0 - ts ? 1.0 : inter_coeff;
MP_DBG(p, "inter frame ppts: %lld, pts: %lld, "
"vsync: %lld, mix: %f\n",
(long long)prev_pts, (long long)t->pts,
Expand Down
2 changes: 2 additions & 0 deletions video/out/gl_video.h
Expand Up @@ -52,6 +52,8 @@ struct gl_video_opts {
int chroma_location;
int use_rectangle;
struct m_color background;
int smoothmotion;
float smoothmotion_threshold;
};

extern const struct m_sub_options gl_video_conf;
Expand Down
4 changes: 1 addition & 3 deletions video/out/vo_opengl.c
Expand Up @@ -71,7 +71,6 @@ struct gl_priv {
int use_gl_debug;
int allow_sw;
int swap_interval;
int smoothmotion;
char *backend;

int vo_flipped;
Expand Down Expand Up @@ -402,7 +401,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
return reparse_cmdline(p, arg);
}
case VOCTRL_GET_VSYNC_TIMED:
*(bool *)data = p->smoothmotion;
*(bool *)data = p->renderer_opts->smoothmotion;
return VO_TRUE;
}

Expand Down Expand Up @@ -485,7 +484,6 @@ static int preinit(struct vo *vo)
static const struct m_option options[] = {
OPT_FLAG("glfinish", use_glFinish, 0),
OPT_FLAG("waitvsync", waitvsync, 0),
OPT_FLAG("smoothmotion", smoothmotion, 0),
OPT_INT("swapinterval", swap_interval, 0, OPTDEF_INT(1)),
OPT_FLAG("debug", use_gl_debug, 0),
OPT_STRING_VALIDATE("backend", backend, 0, mpgl_validate_backend_opt),
Expand Down

0 comments on commit adc236c

Please sign in to comment.