diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2022-12-21 21:32:25 +0100 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2022-12-21 21:32:25 +0100 |
commit | 99e5470ecebd755108125e0337364852f1e8ab91 (patch) | |
tree | 4911b6f343d09d3415f417fd94d3a1bad15fccaa | |
parent | 550aaa28dcea55a528ef7c190411caa7dc90fa4d (diff) |
amr: Clarify size of AMR BWE header and ToC
Change-Id: I34c76b18ee45e12dba92864715e8ef91e6de3b01
-rw-r--r-- | include/osmocom/netif/amr.h | 3 | ||||
-rw-r--r-- | src/amr.c | 9 |
2 files changed, 8 insertions, 4 deletions
diff --git a/include/osmocom/netif/amr.h b/include/osmocom/netif/amr.h index e8f08d4..9b8fb79 100644 --- a/include/osmocom/netif/amr.h +++ b/include/osmocom/netif/amr.h @@ -43,6 +43,9 @@ struct amr_hdr_bwe { uint8_t data[0]; } __attribute__((packed)); +/* See diagram above: CMR (4) + F (1) + FT (4) + Q (1) = 10 */ +#define AMR_HDR_BWE_LEN_BITS 10 + /* * 4.4. Octet-aligned Mode: * @@ -188,7 +188,7 @@ int osmo_amr_oa_to_bwe(uint8_t *payload, unsigned int payload_len) } /* Calculate new payload length */ - bwe_payload_len = (10 + osmo_amr_bits(ft) + 7) / 8; + bwe_payload_len = (AMR_HDR_BWE_LEN_BITS + osmo_amr_bits(ft) + 7) / 8; return bwe_payload_len; } @@ -266,7 +266,8 @@ int osmo_amr_bwe_to_iuup(uint8_t *payload, unsigned int payload_len) amr_speech_len_bits = osmo_amr_bits(ft); amr_speech_len_bytes = osmo_amr_bytes(ft); - required_len_bits = amr_speech_len_bits + 10; /* shift of 10 bits */ + /* shift of AMR_HDR_BWE_LEN_BITS (10) bits, aka remove BWE Hdr + ToC: */ + required_len_bits = AMR_HDR_BWE_LEN_BITS + amr_speech_len_bits; if (payload_len < (required_len_bits + 7)/8) return -1; @@ -288,7 +289,7 @@ int osmo_amr_bwe_to_iuup(uint8_t *payload, unsigned int payload_len) int osmo_amr_iuup_to_bwe(uint8_t *payload, unsigned int payload_len, unsigned int payload_maxlen) { - /* shift all bits by 10 */ + /* shift all bits by AMR_HDR_BWE_LEN_BITS (10) */ unsigned int i, required_len_bits, required_len_bytes; int ft = osmo_amr_bytes_to_ft(payload_len); @@ -303,7 +304,7 @@ int osmo_amr_iuup_to_bwe(uint8_t *payload, unsigned int payload_len, i = payload_len + 1; payload[i] = (payload[i - 2] << 6); for (i = payload_len; i >= 2; i--) { - /* we have to shift the payload by 10 bits to get only the Class A, B, C bits */ + /* we have to shift the payload by AMR_HDR_BWE_LEN_BITS (10) bits to prepend BWE Hdr + ToC */ payload[i] = (payload[i - 1] >> 2) | (payload[i - 2] << 6); } payload[i] = (payload[i - 1] >> 2); |