aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2022-03-10 01:43:03 +0300
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2022-03-10 13:57:39 +0300
commit7ec19de720873defc3a1f02cc57638e351ab264e (patch)
tree668b20d047904418a3a4a22ff0aa620dd601062c
parentb54229d2ecefc3b56169c55f723fad4801a570be (diff)
libosmocodec: osmo_hr_check_sid(): simplify the logic
According to TS 101 318, section 5.2.2, a SID frame is identified by a SID codeword consisting of 79 bits (r34..r112) which are all 1. Given that there are no gaps in the codeword, we don't really need to use bitvec_get_bit_pos() and check each field individually. This brings additional complexity and negatively affects performance. Instead, let's use bitvec_get_bit_pos() to check all bits in a row. Change-Id: I678f8ff92317fe87f1aca511a3a062ad898e55cc Related: SYS#5853
-rw-r--r--src/codec/gsm620.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/codec/gsm620.c b/src/codec/gsm620.c
index cf7cfd75..4eae514e 100644
--- a/src/codec/gsm620.c
+++ b/src/codec/gsm620.c
@@ -264,12 +264,6 @@ const uint16_t gsm620_voiced_bitorder[112] = {
81, /* Code 3:7 */
};
-static inline uint16_t mask(const uint8_t msb)
-{
- const uint16_t m = (uint16_t)1 << (msb - 1);
- return (m - 1) ^ m;
-}
-
/*! Check whether RTP frame contains HR SID code word according to
* TS 101 318 ยง5.2.2
* \param[in] rtp_payload Buffer with RTP payload
@@ -278,15 +272,15 @@ static inline uint16_t mask(const uint8_t msb)
*/
bool osmo_hr_check_sid(const uint8_t *rtp_payload, size_t payload_len)
{
- uint8_t i, bits[] = { 1, 2, 8, 9, 5, 4, 9, 5, 4, 9, 5, 4, 9, 5 };
- struct bitvec bv;
- bv.data = (uint8_t *) rtp_payload;
- bv.data_len = payload_len;
- bv.cur_bit = 33;
+ struct bitvec bv = {
+ .data = (uint8_t *)rtp_payload,
+ .data_len = payload_len,
+ };
- /* code word is all 1 at given bits, numbered from 1, MODE is always 3 */
- for (i = 0; i < ARRAY_SIZE(bits); i++)
- if (bitvec_get_uint(&bv, bits[i]) != mask(bits[i]))
+ /* A SID frame is identified by a SID codeword consisting of 79 bits which are all 1,
+ * so we basically check if all bits in range r34..r112 (inclusive) are 1. */
+ for (bv.cur_bit = 33; bv.cur_bit < bv.data_len * 8; bv.cur_bit++)
+ if (bitvec_get_bit_pos(&bv, bv.cur_bit) != ONE)
return false;
return true;