libobs: Implement and use better scaling function for 64-bit integers

As os_gettime_ns() gets large the current scaling methods, mostly by casting
to uint64_t, may lead to numerical overflows. Sweep the code and use
util_mul_div64() where applicable.

Signed-off-by: Hans Petter Selasky <hps@selasky.org>
This commit is contained in:
Hans Petter Selasky 2020-03-21 10:55:12 +01:00
commit 0e4ea14ba1
22 changed files with 97 additions and 57 deletions

View file

@ -2,6 +2,7 @@
#include <util/bmem.h>
#include <util/threading.h>
#include <util/platform.h>
#include <util/util_uint64.h>
#include <obs.h>
struct sync_pair_aud {
@ -54,7 +55,8 @@ static void *sync_pair_aud_thread(void *pdata)
for (uint64_t i = 0; i < frames; i++) {
uint64_t ts =
last_time + i * 1000000000ULL / sample_rate;
last_time +
util_mul_div64(i, 1000000000ULL, sample_rate);
if (whitelist_time(ts, interval, fps_num, fps_den)) {
cos_val += rate * M_PI_X2;