diff options
author | Max <msuraev@sysmocom.de> | 2016-06-21 13:14:27 +0200 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2016-06-21 17:24:50 +0200 |
commit | dd084e6e57ee31ae260e8fc16d33e55cff0feeec (patch) | |
tree | 68def22fd8437ac0f8d677493be38724bdd23bd8 /src/osmo-bts-trx | |
parent | 61372a20de695a151611753689ee9a3018b101f6 (diff) |
Use libosmocodec functions for AMR
Switch to using libosmocodec functions as a preparation step for DTX
support as they expose necessary bits.
Change-Id: Ie7423032fd06779d78876182ee63538d98906328
Related: OS#1750
Diffstat (limited to 'src/osmo-bts-trx')
-rw-r--r-- | src/osmo-bts-trx/Makefile.am | 4 | ||||
-rw-r--r-- | src/osmo-bts-trx/amr.c | 81 | ||||
-rw-r--r-- | src/osmo-bts-trx/amr.h | 8 | ||||
-rw-r--r-- | src/osmo-bts-trx/scheduler_trx.c | 35 |
4 files changed, 21 insertions, 107 deletions
diff --git a/src/osmo-bts-trx/Makefile.am b/src/osmo-bts-trx/Makefile.am index e31b57f5..96b080ef 100644 --- a/src/osmo-bts-trx/Makefile.am +++ b/src/osmo-bts-trx/Makefile.am @@ -2,10 +2,10 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) AM_CFLAGS = -Wall -fno-strict-aliasing $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOABIS_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(ORTP_CFLAGS) LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOCTRL_LIBS) $(ORTP_LIBS) -EXTRA_DIST = trx_if.h l1_if.h gsm0503_parity.h gsm0503_conv.h gsm0503_interleaving.h gsm0503_mapping.h gsm0503_coding.h gsm0503_tables.h loops.h amr.h +EXTRA_DIST = trx_if.h l1_if.h gsm0503_parity.h gsm0503_conv.h gsm0503_interleaving.h gsm0503_mapping.h gsm0503_coding.h gsm0503_tables.h loops.h bin_PROGRAMS = osmo-bts-trx -osmo_bts_trx_SOURCES = main.c trx_if.c l1_if.c scheduler_trx.c trx_vty.c gsm0503_parity.c gsm0503_conv.c gsm0503_interleaving.c gsm0503_mapping.c gsm0503_coding.c gsm0503_tables.c loops.c amr.c +osmo_bts_trx_SOURCES = main.c trx_if.c l1_if.c scheduler_trx.c trx_vty.c gsm0503_parity.c gsm0503_conv.c gsm0503_interleaving.c gsm0503_mapping.c gsm0503_coding.c gsm0503_tables.c loops.c osmo_bts_trx_LDADD = $(top_builddir)/src/common/libbts.a $(top_builddir)/src/common/libl1sched.a $(LDADD) diff --git a/src/osmo-bts-trx/amr.c b/src/osmo-bts-trx/amr.c deleted file mode 100644 index 70d94ca9..00000000 --- a/src/osmo-bts-trx/amr.c +++ /dev/null @@ -1,81 +0,0 @@ -/* AMR support for OsmoBTS-TRX */ - -/* (C) 2013 by Andreas Eversberg <jolly@eversberg.eu> - * - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <errno.h> -#include <stdint.h> - -static int amr_len_by_ft[16] = { - 12, 13, 15, 17, 19, 20, 26, 31, - 0, 0, 0, 0, 0, 0, 0, 0 -}; - -int amr_decompose_payload(uint8_t *payload, int payload_len, uint8_t *_cmr, - uint8_t *_ft, uint8_t *_bfi) -{ - uint8_t cmr, f, ft, q; - - if (payload_len < 2) - return -EINVAL; - - cmr = payload[0] >> 4; - if (_cmr) - *_cmr = cmr; - - f = payload[1] >> 7; - - ft = (payload[1] >> 3) & 0xf; - if (_ft) - *_ft = ft; - - q = (payload[1] >> 2) & 0x1; - if (_bfi) - *_bfi = !q; - - if (f) { - fprintf(stderr, "%s: multiple payloads not supported\n", - __func__); - return -ENOTSUP; - } - - if (payload_len - 2 < amr_len_by_ft[ft]) - return -EINVAL; - - return 2 + amr_len_by_ft[ft]; -} - -int amr_compose_payload(uint8_t *payload, uint8_t cmr, uint8_t ft, uint8_t bfi) -{ - if (cmr >= 16) - return -EINVAL; - - if (ft >= 16) - return -EINVAL; - - payload[0] = cmr << 4; - - payload[1] = (ft << 3) | ((!bfi) << 2); /* F = 0 */ - - return 2 + amr_len_by_ft[ft]; -} - diff --git a/src/osmo-bts-trx/amr.h b/src/osmo-bts-trx/amr.h deleted file mode 100644 index 17eb5f04..00000000 --- a/src/osmo-bts-trx/amr.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _TRX_AMR_H -#define _TRX_AMR_H - -int amr_decompose_payload(uint8_t *payload, int payload_len, uint8_t *_cmr, - uint8_t *_ft, uint8_t *_bfi); -int amr_compose_payload(uint8_t *payload, uint8_t cmr, uint8_t ft, uint8_t bfi); - -#endif /* _TRX_AMR_H */ diff --git a/src/osmo-bts-trx/scheduler_trx.c b/src/osmo-bts-trx/scheduler_trx.c index d92d8db6..96ea828d 100644 --- a/src/osmo-bts-trx/scheduler_trx.c +++ b/src/osmo-bts-trx/scheduler_trx.c @@ -28,6 +28,7 @@ #include <osmocom/core/msgb.h> #include <osmocom/core/talloc.h> +#include <osmocom/codec/codec.h> #include <osmocom/core/bits.h> #include <osmocom/gsm/a5.h> @@ -45,7 +46,6 @@ #include "gsm0503_coding.h" #include "trx_if.h" #include "loops.h" -#include "amr.h" extern void *tall_bts_ctx; @@ -335,9 +335,9 @@ static void tx_tch_common(struct l1sched_trx *l1t, uint8_t tn, uint32_t fn, len = GSM_EFR_BYTES; break; case GSM48_CMODE_SPEECH_AMR: /* AMR */ - len = amr_compose_payload(tch_data, + len = osmo_amr_rtp_enc(tch_data, chan_state->codec[chan_state->dl_cmr], - chan_state->codec[chan_state->dl_ft], 1); + chan_state->codec[chan_state->dl_ft], AMR_BAD); if (len < 2) break; memset(tch_data + 2, 0, len - 2); @@ -401,8 +401,11 @@ inval_mode1: /* check validity of message, get AMR ft and cmr */ if (!msg_facch && msg_tch) { int len; - uint8_t bfi, cmr_codec, ft_codec; + uint8_t cmr_codec; int cmr, ft, i; + enum osmo_amr_type ft_codec; + enum osmo_amr_quality bfi; + int8_t sti, cmi; if (rsl_cmode != RSL_CMOD_SPD_SPEECH) { LOGP(DL1C, LOGL_NOTICE, "%s Dropping speech frame, " @@ -452,9 +455,9 @@ inval_mode1: } break; case GSM48_CMODE_SPEECH_AMR: /* AMR */ - len = amr_decompose_payload(msg_tch->l2h, - msgb_l2len(msg_tch), &cmr_codec, &ft_codec, - &bfi); + len = osmo_amr_rtp_dec(msg_tch->l2h, msgb_l2len(msg_tch), + &cmr_codec, &cmi, &ft_codec, + &bfi, &sti); cmr = -1; ft = -1; for (i = 0; i < chan_state->codecs; i++) { @@ -488,7 +491,7 @@ inval_mode1: goto free_bad_msg; } chan_state->dl_ft = ft; - if (bfi) { + if (bfi == AMR_BAD) { LOGP(DL1C, LOGL_NOTICE, "%s Transmitting 'bad " "AMR frame' trx=%u ts=%u at fn=%u.\n", trx_chan_desc[chan].name, @@ -1004,9 +1007,9 @@ int rx_tchf_fn(struct l1sched_trx *l1t, uint8_t tn, uint32_t fn, amr = 2; /* we store tch_data + 2 header bytes */ /* only good speech frames get rtp header */ if (rc != GSM_MACBLOCK_LEN && rc >= 4) { - rc = amr_compose_payload(tch_data, + rc = osmo_amr_rtp_enc(tch_data, chan_state->codec[chan_state->ul_cmr], - chan_state->codec[chan_state->ul_ft], 0); + chan_state->codec[chan_state->ul_ft], AMR_GOOD); } break; default: @@ -1050,10 +1053,10 @@ bfi: rc = GSM_EFR_BYTES; break; case GSM48_CMODE_SPEECH_AMR: /* AMR */ - rc = amr_compose_payload(tch_data, + rc = osmo_amr_rtp_enc(tch_data, chan_state->codec[chan_state->dl_cmr], chan_state->codec[chan_state->dl_ft], - 1); + AMR_BAD); if (rc < 2) break; memset(tch_data + 2, 0, rc - 2); @@ -1167,9 +1170,9 @@ int rx_tchh_fn(struct l1sched_trx *l1t, uint8_t tn, uint32_t fn, amr = 2; /* we store tch_data + 2 two */ /* only good speech frames get rtp header */ if (rc != GSM_MACBLOCK_LEN && rc >= 4) { - rc = amr_compose_payload(tch_data, + rc = osmo_amr_rtp_enc(tch_data, chan_state->codec[chan_state->ul_cmr], - chan_state->codec[chan_state->ul_ft], 0); + chan_state->codec[chan_state->ul_ft], AMR_GOOD); } break; default: @@ -1213,10 +1216,10 @@ bfi: rc = 15; break; case GSM48_CMODE_SPEECH_AMR: /* AMR */ - rc = amr_compose_payload(tch_data, + rc = osmo_amr_rtp_enc(tch_data, chan_state->codec[chan_state->dl_cmr], chan_state->codec[chan_state->dl_ft], - 1); + AMR_BAD); if (rc < 2) break; memset(tch_data + 2, 0, rc - 2); |