<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmo-abis/+/18382">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">WIP: TRAU frame RTP conversion<br><br>This adds code that converts codec frames between (decoded) TRAU format<br>and RTP payload format.  The FR + EFR functions have been lifted from<br>OsmoNITB.<br><br>Change-Id: I7f6993cce2b95318203043e2e14952e581941b79<br>---<br>M src/Makefile.am<br>A src/trau/trau_rtp_conv.c<br>2 files changed, 483 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmo-abis refs/changes/82/18382/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/Makefile.am b/src/Makefile.am</span><br><span>index 0134b00..4254428 100644</span><br><span>--- a/src/Makefile.am</span><br><span>+++ b/src/Makefile.am</span><br><span>@@ -37,6 +37,7 @@</span><br><span> libosmotrau_la_LIBADD = $(COMMONLIBS) $(ORTP_LIBS)</span><br><span> libosmotrau_la_SOURCES = trau/osmo_ortp.c \</span><br><span>                       trau/trau_frame.c \</span><br><span style="color: hsl(0, 100%, 40%);">-                     trau/trau_sync.c</span><br><span style="color: hsl(120, 100%, 40%);">+                      trau/trau_sync.c \</span><br><span style="color: hsl(120, 100%, 40%);">+                    trau/trau_rtp_conv.c</span><br><span> </span><br><span> noinst_HEADERS = trau/ubit_buf.h</span><br><span>diff --git a/src/trau/trau_rtp_conv.c b/src/trau/trau_rtp_conv.c</span><br><span>new file mode 100644</span><br><span>index 0000000..c3007ad</span><br><span>--- /dev/null</span><br><span>+++ b/src/trau/trau_rtp_conv.c</span><br><span>@@ -0,0 +1,481 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* TRAU frame to RTP conversion */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* (C) 2009,2020 by Harald Welte <laforge@gnumonks.org></span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * SPDX-License-Identifier: GPL-2.0+</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 2 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <errno.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdlib.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <string.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/crc8gen.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/codec/codec.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/trau/trau_frame.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* this corresponds to the bit-lengths of the individual codec</span><br><span style="color: hsl(120, 100%, 40%);">+ * parameters as indicated in Table 1.1 of TS 46.010 */</span><br><span style="color: hsl(120, 100%, 40%);">+static const uint8_t gsm_fr_map[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+        6, 6, 5, 5, 4, 4, 3, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       7, 2, 2, 6, 3, 3, 3, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       3, 3, 3, 3, 3, 3, 3, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       3, 7, 2, 2, 6, 3, 3, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       3, 3, 3, 3, 3, 3, 3, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       3, 3, 7, 2, 2, 6, 3, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       3, 3, 3, 3, 3, 3, 3, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       3, 3, 3, 7, 2, 2, 6, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       3, 3, 3, 3, 3, 3, 3, 3,</span><br><span style="color: hsl(120, 100%, 40%);">+       3, 3, 3, 3</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * EFR TRAU parity</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * g(x) = x^3 + x^1 + 1</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static const struct osmo_crc8gen_code gsm0860_efr_crc3 = {</span><br><span style="color: hsl(120, 100%, 40%);">+      .bits = 3,</span><br><span style="color: hsl(120, 100%, 40%);">+    .poly = 0x3,</span><br><span style="color: hsl(120, 100%, 40%);">+  .init = 0x0,</span><br><span style="color: hsl(120, 100%, 40%);">+  .remainder = 0x7,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* re-combine EFR parity bits */</span><br><span style="color: hsl(120, 100%, 40%);">+static inline void efr_parity_bits_1(ubit_t *check_bits, const ubit_t *d_bits)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  memcpy(check_bits + 0 , d_bits + 0, 22);</span><br><span style="color: hsl(120, 100%, 40%);">+      memcpy(check_bits + 22 , d_bits + 24, 3);</span><br><span style="color: hsl(120, 100%, 40%);">+     check_bits[25] = d_bits[28];</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static inline void efr_parity_bits_2(ubit_t *check_bits, const ubit_t *d_bits)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  memcpy(check_bits + 0 , d_bits + 42, 10);</span><br><span style="color: hsl(120, 100%, 40%);">+     memcpy(check_bits + 10 , d_bits + 90, 2);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static inline void efr_parity_bits_3(ubit_t *check_bits, const ubit_t *d_bits)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     memcpy(check_bits + 0 , d_bits + 98, 5);</span><br><span style="color: hsl(120, 100%, 40%);">+      check_bits[5] = d_bits[104];</span><br><span style="color: hsl(120, 100%, 40%);">+  memcpy(check_bits + 6 , d_bits + 143, 2);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static inline void efr_parity_bits_4(ubit_t *check_bits, const ubit_t *d_bits)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     memcpy(check_bits + 0 , d_bits + 151, 10);</span><br><span style="color: hsl(120, 100%, 40%);">+    memcpy(check_bits + 10 , d_bits + 199, 2);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static inline void efr_parity_bits_5(ubit_t *check_bits, const ubit_t *d_bits)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    memcpy(check_bits + 0 , d_bits + 207, 5);</span><br><span style="color: hsl(120, 100%, 40%);">+     check_bits[5] = d_bits[213];</span><br><span style="color: hsl(120, 100%, 40%);">+  memcpy(check_bits + 6 , d_bits + 252, 2);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+//static const uint8_t c_bits_check_fr[] = { 0, 0, 0, 1, 0 };</span><br><span style="color: hsl(120, 100%, 40%);">+//static const uint8_t c_bits_check_efr[] = { 1, 1, 0, 1, 0 };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Generate the 33 bytes RTP payload for GSM-FR from a decoded TRAU frame.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[out] out caller-provided output buffer</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] out_len length of out buffer in bytes</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] fr input TRAU frame in decoded form</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns number of bytes generated in 'out'; negative on error. */</span><br><span style="color: hsl(120, 100%, 40%);">+int trau2rtp_fr(uint8_t *out, size_t out_len, const struct osmo_trau_frame *tf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i, j, k, l, o;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  if (tf->type != OSMO_TRAU16_FT_FR)</span><br><span style="color: hsl(120, 100%, 40%);">+         return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* FR Data Bits according to TS 48.060 Section 5.5.1.1.2 */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (tf->c_bits[11]) /* BFI */</span><br><span style="color: hsl(120, 100%, 40%);">+              return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (out_len < GSM_FR_BYTES)</span><br><span style="color: hsl(120, 100%, 40%);">+                return -ENOSPC;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     out[0] = 0xd << 4;</span><br><span style="color: hsl(120, 100%, 40%);">+      /* reassemble d-bits */</span><br><span style="color: hsl(120, 100%, 40%);">+       i = 0; /* counts bits */</span><br><span style="color: hsl(120, 100%, 40%);">+      j = 4; /* counts output bits */</span><br><span style="color: hsl(120, 100%, 40%);">+       k = gsm_fr_map[0]-1; /* current number bit in element */</span><br><span style="color: hsl(120, 100%, 40%);">+      l = 0; /* counts element bits */</span><br><span style="color: hsl(120, 100%, 40%);">+      o = 0; /* offset input bits */</span><br><span style="color: hsl(120, 100%, 40%);">+        while (i < 260) {</span><br><span style="color: hsl(120, 100%, 40%);">+          out[j/8] |= (tf->d_bits[k+o] << (7-(j%8)));</span><br><span style="color: hsl(120, 100%, 40%);">+          /* to avoid out-of-bounds access in gsm_fr_map[++l] */</span><br><span style="color: hsl(120, 100%, 40%);">+                if (i == 259)</span><br><span style="color: hsl(120, 100%, 40%);">+                 break;</span><br><span style="color: hsl(120, 100%, 40%);">+                if (--k < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     o += gsm_fr_map[l];</span><br><span style="color: hsl(120, 100%, 40%);">+                   k = gsm_fr_map[++l]-1;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             i++;</span><br><span style="color: hsl(120, 100%, 40%);">+          j++;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return GSM_FR_BYTES;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! Generate the 31 bytes RTP payload for GSM-EFR from a decoded TRAU frame.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[out] out caller-provided output buffer</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] out_len length of out buffer in bytes</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param[in] fr input TRAU frame in decoded form</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns number of bytes generated in 'out'; negative on error. */</span><br><span style="color: hsl(120, 100%, 40%);">+int trau2rtp_efr(uint8_t *out, size_t out_len, const struct osmo_trau_frame *tf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     int i, j, rc;</span><br><span style="color: hsl(120, 100%, 40%);">+ ubit_t check_bits[26];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      if (tf->type != OSMO_TRAU16_FT_EFR)</span><br><span style="color: hsl(120, 100%, 40%);">+                return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* FR Data Bits according to TS 48.060 Section 5.5.1.1.2 */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (tf->c_bits[11]) /* BFI */</span><br><span style="color: hsl(120, 100%, 40%);">+              return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   if (out_len < GSM_EFR_BYTES)</span><br><span style="color: hsl(120, 100%, 40%);">+               return -ENOSPC;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (tf->c_bits[11]) /* BFI */</span><br><span style="color: hsl(120, 100%, 40%);">+              goto bad_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     out[0] = 0xc << 4;</span><br><span style="color: hsl(120, 100%, 40%);">+      /* reassemble d-bits */</span><br><span style="color: hsl(120, 100%, 40%);">+       for (i = 1, j = 4; i < 39; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+               out[j/8] |= (tf->d_bits[i] << (7-(j%8)));</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_1(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 26,</span><br><span style="color: hsl(120, 100%, 40%);">+                   tf->d_bits + 39);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (rc)</span><br><span style="color: hsl(120, 100%, 40%);">+               goto bad_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+       for (i = 42, j = 42; i < 95; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+             out[j/8] |= (tf->d_bits[i] << (7-(j%8)));</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_2(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 12,</span><br><span style="color: hsl(120, 100%, 40%);">+                   tf->d_bits + 95);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (rc)</span><br><span style="color: hsl(120, 100%, 40%);">+               goto bad_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+       for (i = 98, j = 95; i < 148; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+            out[j/8] |= (tf->d_bits[i] << (7-(j%8)));</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_3(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 8,</span><br><span style="color: hsl(120, 100%, 40%);">+                    tf->d_bits + 148);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc)</span><br><span style="color: hsl(120, 100%, 40%);">+               goto bad_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+       for (i = 151, j = 145; i < 204; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+          out[j/8] |= (tf->d_bits[i] << (7-(j%8)));</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_4(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 12,</span><br><span style="color: hsl(120, 100%, 40%);">+                   tf->d_bits + 204);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc)</span><br><span style="color: hsl(120, 100%, 40%);">+               goto bad_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+       for (i = 207, j = 198; i < 257; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+          out[j/8] |= (tf->d_bits[i] << (7-(j%8)));</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_5(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ rc = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 8,</span><br><span style="color: hsl(120, 100%, 40%);">+                    tf->d_bits + 257);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc)</span><br><span style="color: hsl(120, 100%, 40%);">+               goto bad_frame;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     return GSM_EFR_BYTES;</span><br><span style="color: hsl(120, 100%, 40%);">+bad_frame:</span><br><span style="color: hsl(120, 100%, 40%);">+     return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* TS 48.060 Section 5.5.1.1.2 */</span><br><span style="color: hsl(120, 100%, 40%);">+int rtp2trau_fr(struct osmo_trau_frame *tf, const uint8_t *data, size_t data_len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       int i, j, k, l, o;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* TODO: consider data_len == 0 for SID frame? */</span><br><span style="color: hsl(120, 100%, 40%);">+     if (data_len < GSM_FR_BYTES)</span><br><span style="color: hsl(120, 100%, 40%);">+               return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (data[0] >> 4 != 0xd)</span><br><span style="color: hsl(120, 100%, 40%);">+                return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     tf->type = OSMO_TRAU16_FT_FR;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    /* FR Data Bits according to TS 48.060 Section 5.5.1.1.2 */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* FIXME: Generate SID frames? */</span><br><span style="color: hsl(120, 100%, 40%);">+     /* FIXME: Generate BFI frames? */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* set c-bits and t-bits */</span><br><span style="color: hsl(120, 100%, 40%);">+   tf->c_bits[0] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ tf->c_bits[1] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ tf->c_bits[2] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ tf->c_bits[3] = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ tf->c_bits[4] = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ memset(&tf->c_bits[5], 0, 6);</span><br><span style="color: hsl(120, 100%, 40%);">+  memset(&tf->c_bits[11], 1, 10);</span><br><span style="color: hsl(120, 100%, 40%);">+        memset(&tf->t_bits[0], 1, 4);</span><br><span style="color: hsl(120, 100%, 40%);">+  /* reassemble d-bits */</span><br><span style="color: hsl(120, 100%, 40%);">+       i = 0; /* counts bits */</span><br><span style="color: hsl(120, 100%, 40%);">+      j = 4; /* counts input bits */</span><br><span style="color: hsl(120, 100%, 40%);">+        k = gsm_fr_map[0]-1; /* current number bit in element */</span><br><span style="color: hsl(120, 100%, 40%);">+      l = 0; /* counts element bits */</span><br><span style="color: hsl(120, 100%, 40%);">+      o = 0; /* offset output bits */</span><br><span style="color: hsl(120, 100%, 40%);">+       while (i < 260) {</span><br><span style="color: hsl(120, 100%, 40%);">+          tf->d_bits[k+o] = (data[j/8] >> (7-(j%8))) & 1;</span><br><span style="color: hsl(120, 100%, 40%);">+          /* to avoid out-of-bounds access in gsm_fr_map[++l] */</span><br><span style="color: hsl(120, 100%, 40%);">+                if (i == 259)</span><br><span style="color: hsl(120, 100%, 40%);">+                 break;</span><br><span style="color: hsl(120, 100%, 40%);">+                if (--k < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     o += gsm_fr_map[l];</span><br><span style="color: hsl(120, 100%, 40%);">+                   k = gsm_fr_map[++l]-1;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             i++;</span><br><span style="color: hsl(120, 100%, 40%);">+          j++;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* TS 48.060 Section 5.5.1.1.2 */</span><br><span style="color: hsl(120, 100%, 40%);">+int rtp2trau_efr(struct osmo_trau_frame *tf, const uint8_t *data, size_t data_len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      int i, j;</span><br><span style="color: hsl(120, 100%, 40%);">+     ubit_t check_bits[26];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* TODO: consider data_len == 0 for SID frame? */</span><br><span style="color: hsl(120, 100%, 40%);">+     if (data_len < GSM_EFR_BYTES)</span><br><span style="color: hsl(120, 100%, 40%);">+              return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (data[0] >> 4 != 0xc)</span><br><span style="color: hsl(120, 100%, 40%);">+                return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     tf->type = OSMO_TRAU16_FT_EFR;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* FR Data Bits according to TS 48.060 Section 5.5.1.1.2 */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* FIXME: Generate SID frames? */</span><br><span style="color: hsl(120, 100%, 40%);">+     /* FIXME: Generate BFI frames? */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   /* set c-bits and t-bits */</span><br><span style="color: hsl(120, 100%, 40%);">+   tf->c_bits[0] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ tf->c_bits[1] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ tf->c_bits[2] = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ tf->c_bits[3] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ tf->c_bits[4] = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ memset(&tf->c_bits[5], 0, 6);</span><br><span style="color: hsl(120, 100%, 40%);">+  memset(&tf->c_bits[11], 1, 10);</span><br><span style="color: hsl(120, 100%, 40%);">+        memset(&tf->t_bits[0], 1, 4);</span><br><span style="color: hsl(120, 100%, 40%);">+  /* reassemble d-bits */</span><br><span style="color: hsl(120, 100%, 40%);">+       tf->d_bits[0] = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 1, j = 4; i < 39; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+               tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1;</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_1(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 26,</span><br><span style="color: hsl(120, 100%, 40%);">+                  tf->d_bits + 39);</span><br><span style="color: hsl(120, 100%, 40%);">+  for (i = 42, j = 42; i < 95; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+             tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1;</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_2(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 12,</span><br><span style="color: hsl(120, 100%, 40%);">+                  tf->d_bits + 95);</span><br><span style="color: hsl(120, 100%, 40%);">+  for (i = 98, j = 95; i < 148; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+            tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1;</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_3(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 8,</span><br><span style="color: hsl(120, 100%, 40%);">+                   tf->d_bits + 148);</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 151, j = 145; i < 204; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+          tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1;</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_4(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 12,</span><br><span style="color: hsl(120, 100%, 40%);">+                  tf->d_bits + 204);</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 207, j = 198; i < 257; i++, j++)</span><br><span style="color: hsl(120, 100%, 40%);">+          tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1;</span><br><span style="color: hsl(120, 100%, 40%);">+    efr_parity_bits_5(check_bits, tf->d_bits);</span><br><span style="color: hsl(120, 100%, 40%);">+ osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 8,</span><br><span style="color: hsl(120, 100%, 40%);">+                   tf->d_bits + 257);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#if 0</span><br><span style="color: hsl(120, 100%, 40%);">+static inline memcpy_inc(uint8_t *out, const uint8_t *in, size_t len, unsigned int *idx)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+    memcpy_inc(out, in, len);</span><br><span style="color: hsl(120, 100%, 40%);">+     *idx += len;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int amr_speech_extract_sbits(ubit_t *s_bits, const struct osmo_trau_frame *tf,</span><br><span style="color: hsl(120, 100%, 40%);">+                                  enum osmo_amr_mode mode)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+       unsigned int s_idx = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (mode) {</span><br><span style="color: hsl(120, 100%, 40%);">+       case AMR_4_75:</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 44, 67 - 44, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 67, 92 - 67, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 95, 108 - 95, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy_inc(s_bits + s_idx, tf->d_bits + 111, 132 - 111, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 135, 148 - 135, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case AMR_5_15:</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 46, 96 - 46, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 69, 92 - 69, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 95, 114 - 95, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy_inc(s_bits + s_idx, tf->d_bits + 117, 136 - 117, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 139, 158 - 139, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case AMR_5_90:</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 41, 67 - 41, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 67, 92 - 67, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 95, 116 - 95, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy_inc(s_bits + s_idx, tf->d_bits + 119, 144 - 119, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 147, 168 - 147, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case AMR_6_70:</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 37, 63 - 37, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 63, 92 - 63, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 95, 120 - 95, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy_inc(s_bits + s_idx, tf->d_bits + 123, 152 - 123, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 155, 180 - 155, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case AMR_7_40:</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 34, 60 - 34, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 60, 92 - 60, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 95, 124 - 95, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy_inc(s_bits + s_idx, tf->d_bits + 127, 159 - 127, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 162, 191 - 162, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case AMR_7_95:</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 31, 58 - 31, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 58, 92 - 58, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 95, 127 - 95, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy_inc(s_bits + s_idx, tf->d_bits + 130, 164 - 130, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 167, 199 - 167, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case AMR_10_2:</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 20, 46 - 20, &s_idx);    /* D21..D46 */</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 46, 92 - 46, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+          memcpy_inc(s_bits + s_idx, tf->d_bits + 95, 138 - 95, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy_inc(s_bits + s_idx, tf->d_bits + 141, 187 - 141, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 190, 233 - 190, &s_idx);</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case AMR_12_2:</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 0, 38 - 0, &s_idx);      /* D1..D38 */</span><br><span style="color: hsl(120, 100%, 40%);">+         memcpy_inc(s_bits + s_idx, tf->d_bits + 38, 91 - 38, &s_idx);    /* D39..D91 */</span><br><span style="color: hsl(120, 100%, 40%);">+                memcpy_inc(s_bits + s_idx, tf->d_bits + 94, 144 - 94, &s_idx);   /* D95..D144 */</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 147, 200 - 147, &s_idx);/* D148..D200 */</span><br><span style="color: hsl(120, 100%, 40%);">+               memcpy_inc(s_bits + s_idx, tf->d_bits + 203, 253 - 203, &s_idx);/* D204..D253 */</span><br><span style="color: hsl(120, 100%, 40%);">+               break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   return s_idx;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* TS 48.060 Section 5.5.1.2.2 */</span><br><span style="color: hsl(120, 100%, 40%);">+static int trau2rtp_16(uint8_t *out, const struct osmo_trau_frame *tf, enum osmo_amr_mode last_cmi)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ enum osmo_amr_mode mode = last_cmi;</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t frame_class = tf->c_bits[21] << 1 | tf->c_bits[20];</span><br><span style="color: hsl(120, 100%, 40%);">+       uint8_t cmr_cmi = tf->c_bits[23] << 2 | tf->c_bits[24] << 1 | tf->cb_bits[25];</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t no_speech_cls;</span><br><span style="color: hsl(120, 100%, 40%);">+        uint8_t s_bits[242];</span><br><span style="color: hsl(120, 100%, 40%);">+  uint8_t d_bits[242];</span><br><span style="color: hsl(120, 100%, 40%);">+  unsigned int s_idx = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+       ubit_t rif = FIXME;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (tf->type != OSMO_TRAU16_FT_AMR)</span><br><span style="color: hsl(120, 100%, 40%);">+                return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (rif == 0)</span><br><span style="color: hsl(120, 100%, 40%);">+         mode = cmr_cmi;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (frame_class) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case 0: // no speech</span><br><span style="color: hsl(120, 100%, 40%);">+          no_speech_cls = tf->d_bits[32] << 2 | tf->d_bits[33] << 1 | tf->d_bits[34];</span><br><span style="color: hsl(120, 100%, 40%);">+              cmi_abs = tf->d_bits[35] << 2 | tf->d_bits[36] < 1 || tf->d_bits[37];</span><br><span style="color: hsl(120, 100%, 40%);">+               cmr_abs = tf->d_bits[38] << 2 | tf->d_bits[39] < 1 || tf->d_bits[40];</span><br><span style="color: hsl(120, 100%, 40%);">+               switch (no_speech_cls) {</span><br><span style="color: hsl(120, 100%, 40%);">+              case 7: // sid first</span><br><span style="color: hsl(120, 100%, 40%);">+                  break;</span><br><span style="color: hsl(120, 100%, 40%);">+                case 6: // onset</span><br><span style="color: hsl(120, 100%, 40%);">+                      break;</span><br><span style="color: hsl(120, 100%, 40%);">+                case 5: // sid_update</span><br><span style="color: hsl(120, 100%, 40%);">+                 break;</span><br><span style="color: hsl(120, 100%, 40%);">+                case 4: // sid_bad</span><br><span style="color: hsl(120, 100%, 40%);">+                    break;</span><br><span style="color: hsl(120, 100%, 40%);">+                case 0: // no_data</span><br><span style="color: hsl(120, 100%, 40%);">+                    break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+             break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case 1: // speech bad</span><br><span style="color: hsl(120, 100%, 40%);">+         break;</span><br><span style="color: hsl(120, 100%, 40%);">+        case 2:</span><br><span style="color: hsl(120, 100%, 40%);">+       case 3:</span><br><span style="color: hsl(120, 100%, 40%);">+               /* Extract the s-bits from the TRAU frame */</span><br><span style="color: hsl(120, 100%, 40%);">+          amr_speech_extract_sbits(s_bits, tf, mode);</span><br><span style="color: hsl(120, 100%, 40%);">+           /* Convert the s-bits to d-bits */</span><br><span style="color: hsl(120, 100%, 40%);">+            osmo_amr_s_to_d(d_bits, s_bits, mode);</span><br><span style="color: hsl(120, 100%, 40%);">+                break;</span><br><span style="color: hsl(120, 100%, 40%);">+        }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int trau2rtp_amr(uint8_t *out, const struct osmo_trau_frame *tf, enum osmo_amr_mode last_cmi))</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+     switch (tf->type) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case OSMO_TRAU16_FT_AMR:</span><br><span style="color: hsl(120, 100%, 40%);">+              return trau2rtp_16(out, tf, last_cmi);</span><br><span style="color: hsl(120, 100%, 40%);">+        case OSMO_TRAU8_AMR_LOW:</span><br><span style="color: hsl(120, 100%, 40%);">+      case OSMO_TRAU8_AMR_6k7:</span><br><span style="color: hsl(120, 100%, 40%);">+      case OSMO_TRAU8_AMR_7k4:</span><br><span style="color: hsl(120, 100%, 40%);">+      default:</span><br><span style="color: hsl(120, 100%, 40%);">+              return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct osmo_trau2rtp_state {</span><br><span style="color: hsl(120, 100%, 40%);">+  enum osmo_trau_frame_type type;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_trau2rtp(uint8_t *out, size_t out_len, const struct osmo_trau_frame *tf,</span><br><span style="color: hsl(120, 100%, 40%);">+                struct osmo_trau2rtp_state *st)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  switch (tf->type) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case OSMO_TRAU16_FT_FR:</span><br><span style="color: hsl(120, 100%, 40%);">+               return trau2rtp_fr(out, out_len, tf);</span><br><span style="color: hsl(120, 100%, 40%);">+ case OSMO_TRAU16_FT_EFR:</span><br><span style="color: hsl(120, 100%, 40%);">+              return trau2rtp_efr(out, out_len, tf);</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int osmo_rtp2trau(struct osmo_trau_frame *tf, const uint8_t *rtp, size_t rtp_len,</span><br><span style="color: hsl(120, 100%, 40%);">+               struct osmo_trau2rtp_state *st)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  switch (st->type) {</span><br><span style="color: hsl(120, 100%, 40%);">+        case OSMO_TRAU16_FT_FR:</span><br><span style="color: hsl(120, 100%, 40%);">+               return rtp2trau_fr(tf, rtp, rtp_len);</span><br><span style="color: hsl(120, 100%, 40%);">+ case OSMO_TRAU16_FT_EFR:</span><br><span style="color: hsl(120, 100%, 40%);">+              return rtp2trau_efr(tf, rtp, rtp_len);</span><br><span style="color: hsl(120, 100%, 40%);">+        default:</span><br><span style="color: hsl(120, 100%, 40%);">+              return -EINVAL;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmo-abis/+/18382">change 18382</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmo-abis/+/18382"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmo-abis </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I7f6993cce2b95318203043e2e14952e581941b79 </div>
<div style="display:none"> Gerrit-Change-Number: 18382 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>