summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2017-09-11 02:28:15 +0200
committerNiklas Haas <git@haasn.xyz>2017-09-11 02:42:50 +0200
commit71c25df5e66154e6b8b72ebc0f8ef5ae0c40d7f6 (patch)
tree50729638e102cf5c9ce23bba0b5dcbaeeb85b0d4 /video
parent8a4f2f0ac001703f0fcb921067d97584df20e2fc (diff)
downloadmpv-71c25df5e66154e6b8b72ebc0f8ef5ae0c40d7f6.tar.bz2
mpv-71c25df5e66154e6b8b72ebc0f8ef5ae0c40d7f6.tar.xz
vo_opengl: refactor timer_pool_measure (again)
Instead of relying on power-of-two buffer sizes and unsigned overflow, make this code more robust (and also cleaner). Why can't C get a real modulo operator?
Diffstat (limited to 'video')
-rw-r--r--video/out/opengl/utils.c10
-rw-r--r--video/out/vo.h2
2 files changed, 7 insertions, 5 deletions
diff --git a/video/out/opengl/utils.c b/video/out/opengl/utils.c
index e71c01de04..b13035697c 100644
--- a/video/out/opengl/utils.c
+++ b/video/out/opengl/utils.c
@@ -293,20 +293,22 @@ struct mp_pass_perf timer_pool_measure(struct timer_pool *pool)
if (!pool)
return (struct mp_pass_perf){0};
- int last = (pool->sample_idx ? pool->sample_idx : VO_PERF_SAMPLE_COUNT) - 1;
struct mp_pass_perf res = {
- .last = pool->samples[last],
- .avg = pool->sample_count > 0 ? pool->sum / pool->sample_count : 0,
.peak = pool->peak,
.count = pool->sample_count,
};
- int idx = (pool->sample_idx - pool->sample_count);
+ int idx = pool->sample_idx - pool->sample_count + VO_PERF_SAMPLE_COUNT;
for (int i = 0; i < res.count; i++) {
idx %= VO_PERF_SAMPLE_COUNT;
res.samples[i] = pool->samples[idx++];
}
+ if (res.count > 0) {
+ res.last = res.samples[res.count - 1];
+ res.avg = pool->sum / res.count;
+ }
+
return res;
}
diff --git a/video/out/vo.h b/video/out/vo.h
index 36591cb00d..50fdab6db4 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -143,7 +143,7 @@ struct voctrl_playback_state {
};
// VOCTRL_PERFORMANCE_DATA
-#define VO_PERF_SAMPLE_COUNT 256u
+#define VO_PERF_SAMPLE_COUNT 256
struct mp_pass_perf {
// times are all in nanoseconds