From 22cca3eb48fa83ac3fe492bc500ec171bfbf67d0 Mon Sep 17 00:00:00 2001 From: Bostjan Meglic Date: Mon, 29 May 2023 12:42:48 +0000 Subject: [PATCH] [NAS] Improve algorithm for conversion of bitrate to NAS The improved algorithm better handles some odd bitrates. With the current version, the bitrates 63 Kbps and 65 Kbps would get converted into 48 Kbps (unit 16 Kbps x 3) and 64 Kbps (unit 64 Kbps x 1). Especially in the first case, the conversion error is quite signicant. Current version tries to find the biggest 'unit', while the 'value' is still above 0. With the updated version, the algorithm tries to find the 'unit' low enough, that the resulting 'value' can still fit into the 16-bit space without overflow. --- lib/nas/common/types.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nas/common/types.c b/lib/nas/common/types.c index 80cf63f81..a11ab22e1 100644 --- a/lib/nas/common/types.c +++ b/lib/nas/common/types.c @@ -436,7 +436,7 @@ void ogs_nas_bitrate_from_uint64(ogs_nas_bitrate_t *nas, uint64_t bitrate) for (nas->unit = OGS_NAS_BR_UNIT_1K; nas->unit < OGS_NAS_BR_UNIT_256P; nas->unit++) { - if ((bitrate >> 2) == 0) { + if (bitrate <= 0xFFFFUL) { break; } bitrate >>= 2;