From 3ee6d7db4e2e61465d18db05a8346086ffa0884b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20P=C3=B6schel?= Date: Sat, 19 Jan 2019 22:51:38 +0100 Subject: command: fix bitrate rounding error When the (float) bitrate is returned, it is implicitely converted to an int64 value, merely discarding the fractional part. However the bitrate of a CBR track can vary a bit due to timestamp precision loss after clock conversion (this can affect MPEG-TS audio tracks). So a bitrate like 191999.999... results in 191999 when being returned - instead of 192000. To fix this, apply proper rounding, as already done for the "old" case. Hereby refactoring the "old" case to also use `llrint`. --- player/command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/player/command.c b/player/command.c index d30c84d82d..f97f699259 100644 --- a/player/command.c +++ b/player/command.c @@ -3107,7 +3107,7 @@ static int mp_property_packet_bitrate(void *ctx, struct m_property *prop, // Same story, but used kilobits for some reason. if (old) - return m_property_int64_ro(action, arg, rate / 1000.0 + 0.5); + return m_property_int64_ro(action, arg, llrint(rate / 1000.0)); if (action == M_PROPERTY_PRINT) { rate /= 1000; @@ -3118,7 +3118,7 @@ static int mp_property_packet_bitrate(void *ctx, struct m_property *prop, } return M_PROPERTY_OK; } - return m_property_int64_ro(action, arg, rate); + return m_property_int64_ro(action, arg, llrint(rate)); } static int mp_property_cwd(void *ctx, struct m_property *prop, -- cgit v1.2.3