Change in libosmo-netif[master]: amr: Fix OA to BWE conversion for SID frames.

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

ipse gerrit-no-reply at lists.osmocom.org
Sat May 2 15:11:03 UTC 2020


ipse has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/17997 )


Change subject: amr: Fix OA to BWE conversion for SID frames.
......................................................................

amr: Fix OA to BWE conversion for SID frames.

Size of a single AMR SID frame doesn't reduce by a byte when converted
from octet-aligned to bandwidth-efficient mode. So old code generated
truncated SID frames which are 1 byte short. This patch fixes
the length calculation by properly counting bits.

Proper bit counting is also bringing us one small step closer to
properly handlig multi-frame AMR packets.

Change-Id: I9fc5fb92e9bada22a47a82fcfb0925e892e50ced
---
M include/osmocom/netif/amr.h
M src/amr.c
2 files changed, 33 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/97/17997/1

diff --git a/include/osmocom/netif/amr.h b/include/osmocom/netif/amr.h
index 6e37c99..ab7b10d 100644
--- a/include/osmocom/netif/amr.h
+++ b/include/osmocom/netif/amr.h
@@ -93,6 +93,16 @@
 /* NOTE: the above constant refers to the length of one AMR speech frame-block,
  * not counting CMR, TOC. */
 
+#define AMR_FT_0_LEN_BITS	95	/* 4.75 */
+#define AMR_FT_1_LEN_BITS	103	/* 5.15 */
+#define AMR_FT_2_LEN_BITS	118	/* 5.90 */
+#define AMR_FT_3_LEN_BITS	134	/* 6.70 */
+#define AMR_FT_4_LEN_BITS	148	/* 7.40 */
+#define AMR_FT_5_LEN_BITS	159	/* 7.95 */
+#define AMR_FT_6_LEN_BITS	204	/* 10.2 */
+#define AMR_FT_7_LEN_BITS	244	/* 12.2 */
+#define AMR_FT_SID_LEN_BITS	39	/* SID */
+
 int osmo_amr_ft_valid(uint8_t amr_ft);
 size_t osmo_amr_bytes(uint8_t amr_cmr);
 
diff --git a/src/amr.c b/src/amr.c
index 5609c46..c69aaff 100644
--- a/src/amr.c
+++ b/src/amr.c
@@ -29,6 +29,18 @@
  *      7         12.20      244    31
  */
 
+static size_t amr_ft_to_bits[AMR_FT_MAX] = {
+	[AMR_FT_0]	= AMR_FT_0_LEN_BITS,
+	[AMR_FT_1]	= AMR_FT_1_LEN_BITS,
+	[AMR_FT_2]	= AMR_FT_2_LEN_BITS,
+	[AMR_FT_3]	= AMR_FT_3_LEN_BITS,
+	[AMR_FT_4]	= AMR_FT_4_LEN_BITS,
+	[AMR_FT_5]	= AMR_FT_5_LEN_BITS,
+	[AMR_FT_6]	= AMR_FT_6_LEN_BITS,
+	[AMR_FT_7]	= AMR_FT_7_LEN_BITS,
+	[AMR_FT_SID]	= AMR_FT_SID_LEN_BITS,
+};
+
 static size_t amr_ft_to_bytes[AMR_FT_MAX] = {
 	[AMR_FT_0]	= AMR_FT_0_LEN,
 	[AMR_FT_1]	= AMR_FT_1_LEN,
@@ -41,6 +53,11 @@
 	[AMR_FT_SID]	= AMR_FT_SID_LEN,
 };
 
+size_t osmo_amr_bits(uint8_t amr_ft)
+{
+	return amr_ft_to_bits[amr_ft];
+}
+
 size_t osmo_amr_bytes(uint8_t amr_ft)
 {
 	return amr_ft_to_bytes[amr_ft];
@@ -119,8 +136,10 @@
 int osmo_amr_oa_to_bwe(uint8_t *payload, unsigned int payload_len)
 {
 	struct amr_hdr *oa_hdr = (struct amr_hdr *)payload;
+	unsigned int ft = oa_hdr->ft;
 	unsigned int frame_len = payload_len - sizeof(struct amr_hdr);
 	unsigned int i;
+	int bwe_payload_len;
 
 	/* This implementation is not capable to handle multi-frame
 	 * packets, so we need to make sure that the frame we operate on
@@ -137,8 +156,10 @@
 		payload[i + 2] = payload[i + 2] << 6;
 	}
 
-	/* The overall saving is one byte! */
-	return payload_len - 1;
+	/* Calculate new payload length */
+	bwe_payload_len = (10 + osmo_amr_bits(ft) + 7) / 8;
+
+	return bwe_payload_len;
 }
 
 /*! Convert an AMR frame from bandwith-efficient mode to octet-aligned mode.

-- 
To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/17997
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Change-Id: I9fc5fb92e9bada22a47a82fcfb0925e892e50ced
Gerrit-Change-Number: 17997
Gerrit-PatchSet: 1
Gerrit-Owner: ipse <Alexander.Chemeris at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200502/ceab847d/attachment.htm>


More information about the gerrit-log mailing list