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:
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "media-io-defs.h"
|
||||
#include "../util/c99defs.h"
|
||||
#include "../util/util_uint128.h"
|
||||
#include "../util/util_uint64.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -195,18 +195,12 @@ static inline size_t get_audio_size(enum audio_format format,
|
||||
|
||||
static inline uint64_t audio_frames_to_ns(size_t sample_rate, uint64_t frames)
|
||||
{
|
||||
util_uint128_t val;
|
||||
val = util_mul64_64(frames, 1000000000ULL);
|
||||
val = util_div128_32(val, (uint32_t)sample_rate);
|
||||
return val.low;
|
||||
return util_mul_div64(frames, 1000000000ULL, sample_rate);
|
||||
}
|
||||
|
||||
static inline uint64_t ns_to_audio_frames(size_t sample_rate, uint64_t frames)
|
||||
{
|
||||
util_uint128_t val;
|
||||
val = util_mul64_64(frames, sample_rate);
|
||||
val = util_div128_32(val, 1000000000);
|
||||
return val.low;
|
||||
return util_mul_div64(frames, sample_rate, 1000000000ULL);
|
||||
}
|
||||
|
||||
#define AUDIO_OUTPUT_SUCCESS 0
|
||||
|
Reference in New Issue
Block a user