mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-24 23:31:36 +08:00
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:
@@ -9,6 +9,7 @@
|
||||
#include "decklink-devices.hpp"
|
||||
|
||||
#include "../../libobs/media-io/video-scaler.h"
|
||||
#include "../../libobs/util/util_uint64.h"
|
||||
|
||||
static void decklink_output_destroy(void *data)
|
||||
{
|
||||
@@ -127,8 +128,8 @@ static bool prepare_audio(DeckLinkOutput *decklink,
|
||||
*output = *frame;
|
||||
|
||||
if (frame->timestamp < decklink->start_timestamp) {
|
||||
uint64_t duration = (uint64_t)frame->frames * 1000000000 /
|
||||
(uint64_t)decklink->audio_samplerate;
|
||||
uint64_t duration = util_mul_div64(frame->frames, 1000000000ULL,
|
||||
decklink->audio_samplerate);
|
||||
uint64_t end_ts = frame->timestamp + duration;
|
||||
uint64_t cutoff;
|
||||
|
||||
@@ -138,7 +139,8 @@ static bool prepare_audio(DeckLinkOutput *decklink,
|
||||
cutoff = decklink->start_timestamp - frame->timestamp;
|
||||
output->timestamp += cutoff;
|
||||
|
||||
cutoff *= (uint64_t)decklink->audio_samplerate / 1000000000;
|
||||
cutoff = util_mul_div64(cutoff, decklink->audio_samplerate,
|
||||
1000000000ULL);
|
||||
|
||||
for (size_t i = 0; i < decklink->audio_planes; i++)
|
||||
output->data[i] +=
|
||||
|
||||
Reference in New Issue
Block a user