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
parent 47058d9b69
commit 0e4ea14ba1
22 changed files with 97 additions and 57 deletions

View File

@@ -6,6 +6,7 @@
#include <util/platform.h>
#include <util/threading.h>
#include <util/util_uint64.h>
#include <sstream>
#include <algorithm>
@@ -90,8 +91,8 @@ void DeckLinkDeviceInstance::HandleAudioPacket(
if (decklink && !static_cast<DeckLinkInput *>(decklink)->buffering) {
currentPacket.timestamp = os_gettime_ns();
currentPacket.timestamp -=
(uint64_t)frameCount * 1000000000ULL /
(uint64_t)currentPacket.samples_per_sec;
util_mul_div64(frameCount, 1000000000ULL,
currentPacket.samples_per_sec);
}
int maxdevicechannel = device->GetMaxChannel();
@@ -113,7 +114,7 @@ void DeckLinkDeviceInstance::HandleAudioPacket(
}
nextAudioTS = timestamp +
((uint64_t)frameCount * 1000000000ULL / 48000ULL) + 1;
util_mul_div64(frameCount, 1000000000ULL, 48000ULL) + 1;
obs_source_output_audio(
static_cast<DeckLinkInput *>(decklink)->GetSource(),