laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-bts/+/15027


Change subject: osmo-bts-trx: migrate to new generic ECU abstraction
......................................................................

osmo-bts-trx: migrate to new generic ECU abstraction

libosmocodec has recently introduced a generic ECU abstraction layer
which supports (pluggable) Error Concealment Units for not only the
FR codec, but potentially any other codec, too.

Change-Id: I001005aae6de76d4e045b8dc572239f057bb150d
Depends: libosmocore I4d33c9c7c2d4c7462ff38a49c178b65accae1915
---
M include/osmo-bts/gsm_data_shared.h
M src/common/gsm_data_shared.c
M src/osmo-bts-trx/l1_if.c
M src/osmo-bts-trx/scheduler_trx.c
4 files changed, 56 insertions(+), 19 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/27/15027/1

diff --git a/include/osmo-bts/gsm_data_shared.h 
b/include/osmo-bts/gsm_data_shared.h
index dd2a14c..d1d9522 100644
--- a/include/osmo-bts/gsm_data_shared.h
+++ b/include/osmo-bts/gsm_data_shared.h
@@ -329,9 +329,7 @@
        struct msgb *pending_rel_ind_msg;

        /* ECU (Error Concealment Unit) state */
-       union {
-               struct osmo_ecu_fr_state fr;
-       } ecu_state;
+       struct osmo_ecu_state *ecu_state;
 };

 static inline uint8_t lchan_get_ta(const struct gsm_lchan *lchan)
@@ -869,4 +867,6 @@
 bool ts_is_tch(struct gsm_bts_trx_ts *ts);
 const char *gsm_trx_unit_id(struct gsm_bts_trx *trx);

+int lchan2ecu_codec(const struct gsm_lchan *lchan);
+
 #endif
diff --git a/src/common/gsm_data_shared.c b/src/common/gsm_data_shared.c
index b1785b8..ce6dd2b 100644
--- a/src/common/gsm_data_shared.c
+++ b/src/common/gsm_data_shared.c
@@ -31,6 +31,7 @@
 #include <osmocom/gsm/gsm_utils.h>
 #include <osmocom/gsm/abis_nm.h>
 #include <osmocom/core/statistics.h>
+#include <osmocom/codec/ecu.h>

 #include <osmo-bts/gsm_data.h>

@@ -806,3 +807,24 @@
        { LCHAN_CIPH_RXTX_CONF, "RXTX_CONF" },
        { 0, NULL }
 };
+
+/* determine the ECU codec constant for the codec used by given lchan */
+int lchan2ecu_codec(const struct gsm_lchan *lchan)
+{
+       struct gsm_bts_trx_ts *ts = lchan->ts;
+
+       switch (lchan->tch_mode) {
+       case GSM48_CMODE_SPEECH_V1:
+               if (ts_pchan(ts) == GSM_PCHAN_TCH_H)
+                       return OSMO_ECU_CODEC_HR;
+               else
+                       return OSMO_ECU_CODEC_FR;
+               break;
+       case GSM48_CMODE_SPEECH_EFR:
+               return OSMO_ECU_CODEC_EFR;
+       case GSM48_CMODE_SPEECH_AMR:
+               return OSMO_ECU_CODEC_AMR;
+       default:
+               return -1;
+       }
+}
diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c
index 22ef2d7..db53d4c 100644
--- a/src/osmo-bts-trx/l1_if.c
+++ b/src/osmo-bts-trx/l1_if.c
@@ -29,6 +29,7 @@

 #include <osmocom/core/talloc.h>
 #include <osmocom/core/bits.h>
+#include <osmocom/codec/ecu.h>
 #include <osmocom/gsm/abis_nm.h>

 #include <osmo-bts/logging.h>
@@ -626,6 +627,9 @@
                                        break;
                                }

+                               /* attempt to allocate an Error Concealment 
Unit instance, if available */
+                               lchan->ecu_state = osmo_ecu_init(trx, 
lchan2ecu_codec(lchan));
+
                                /* trx_chan_desc[] in scheduler.c uses the 
RSL_CHAN_OSMO_PDCH cbits
                                 * (0xc0) to indicate the need for PDTCH and 
PTCCH SAPI activation.
                                 * However, 0xc0 is a cbits pattern exclusively 
used for Osmocom style
@@ -671,6 +675,10 @@
                                break;
                        }
                        if (l1sap->u.info.type == PRIM_INFO_MODIFY) {
+                               /* ECU for possibly new codec */
+                               if (lchan->ecu_state)
+                                       osmo_ecu_destroy(lchan->ecu_state);
+                               lchan->ecu_state = osmo_ecu_init(trx, 
lchan2ecu_codec(lchan));
                                /* change mode */
                                trx_sched_set_mode(&l1h->l1s, chan_nr,
                                        lchan->rsl_cmode, lchan->tch_mode,
@@ -689,6 +697,11 @@
                                        "chan_nr 0x%02x\n", chan_nr);
                                break;
                        }
+                       /* clear ECU state (if any) */
+                       if (lchan->ecu_state) {
+                               osmo_ecu_destroy(lchan->ecu_state);
+                               lchan->ecu_state = NULL;
+                       }
                        /* deactivate associated channel */
                        bts_model_lchan_deactivate_sacch(lchan);
                        if (!l1sap->u.info.u.act_req.sacch_only) {
diff --git a/src/osmo-bts-trx/scheduler_trx.c b/src/osmo-bts-trx/scheduler_trx.c
index 532eca5..742f1c8 100644
--- a/src/osmo-bts-trx/scheduler_trx.c
+++ b/src/osmo-bts-trx/scheduler_trx.c
@@ -1256,22 +1256,24 @@
                        ber10k, PRES_INFO_UNKNOWN);
 bfi:
                if (rsl_cmode == RSL_CMOD_SPD_SPEECH) {
+
                        /* indicate bad frame */
+                       if (lchan->tch.dtx.ul_sid) {
+                               /* DTXu: pause in progress. Push empty payload 
to upper layers */
+                               rc = 0;
+                               goto compose_l1sap;
+                       }
+
+                       /* If there is an ECU active on this channel, use its 
output */
+                       if (lchan->ecu_state) {
+                               rc = osmo_ecu_frame_out(lchan->ecu_state, 
tch_data);
+                               goto compose_l1sap;
+                       }
+
                        switch (tch_mode) {
                        case GSM48_CMODE_SPEECH_V1: /* FR */
-                               if (lchan->tch.dtx.ul_sid) {
-                                       /* DTXu: pause in progress. Push empty 
payload to upper layers */
-                                       rc = 0;
-                                       goto compose_l1sap;
-                               }
-
-                               /* Perform error concealment if possible */
-                               rc = osmo_ecu_fr_conceal(&lchan->ecu_state.fr, 
tch_data);
-                               if (rc) {
-                                       memset(tch_data, 0, GSM_FR_BYTES);
-                                       tch_data[0] = 0xd0;
-                               }
-
+                               memset(tch_data, 0, GSM_FR_BYTES);
+                               tch_data[0] = 0xd0;
                                rc = GSM_FR_BYTES;
                                break;
                        case GSM48_CMODE_SPEECH_EFR: /* EFR */
@@ -1299,9 +1301,9 @@
        if (rsl_cmode != RSL_CMOD_SPD_SPEECH)
                return 0;

-       /* Reset ECU with a good frame */
-       if (!bfi_flag && tch_mode == GSM48_CMODE_SPEECH_V1)
-               osmo_ecu_fr_reset(&lchan->ecu_state.fr, tch_data);
+       /* Feed frame into ECU */
+       if (lchan->ecu_state)
+               osmo_ecu_frame_in(lchan->ecu_state, bfi_flag, tch_data, rc);

        /* TCH or BFI */
 compose_l1sap:

--
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/15027
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I001005aae6de76d4e045b8dc572239f057bb150d
Gerrit-Change-Number: 15027
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <lafo...@gnumonks.org>
Gerrit-MessageType: newchange

Reply via email to