summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-08-19 14:11:32 +0200
committerwm4 <wm4@nowhere>2016-08-19 14:11:32 +0200
commit4aaa83339ca9515113e936af79bc3d860d67cb4b (patch)
treeb6fe7dfef464d72c97d71922808c7c1ca4c3a671
parent5d2dfbdfca04d6b130af63527bb3a8a432205448 (diff)
downloadmpv-4aaa83339ca9515113e936af79bc3d860d67cb4b.tar.bz2
mpv-4aaa83339ca9515113e936af79bc3d860d67cb4b.tar.xz
av_common: improve rounding for float->int timestamp conversions
-rw-r--r--common/av_common.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/common/av_common.c b/common/av_common.c
index e40c751e9f..6856a27d93 100644
--- a/common/av_common.c
+++ b/common/av_common.c
@@ -97,8 +97,10 @@ union pts { int64_t i; double d; };
int64_t mp_pts_to_av(double mp_pts, AVRational *tb)
{
assert(sizeof(int64_t) >= sizeof(double));
- if (tb && tb->num > 0 && tb->den > 0)
- return mp_pts == MP_NOPTS_VALUE ? AV_NOPTS_VALUE : mp_pts / av_q2d(*tb);
+ if (tb && tb->num > 0 && tb->den > 0) {
+ return mp_pts == MP_NOPTS_VALUE ?
+ AV_NOPTS_VALUE : llrint(mp_pts / av_q2d(*tb));
+ }
// The + 0.0 is to squash possible negative zero mp_pts, which would
// happen to end up as AV_NOPTS_VALUE.
return (union pts){.d = mp_pts + 0.0}.i;