From 067ef3f1ce1b7474a553bb8e54ff1543c4012828 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 30 Sep 2016 19:09:04 +0200 Subject: DTX: move ONSET detection into separate function Move code from tch.c (lc15, sysmo) into generic function which: - check if talkspurt is happening - cache SID if necessary or invalidate cache - fill in CMR & CMI prefix This also fixes the problem when SID FIRST was cached without sending just like SID UPDATE instead of being sent right away. Change-Id: I6c7016a54749abadeef4fd4f5b6f750b256fb916 --- src/osmo-bts-litecell15/tch.c | 55 +++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 36 deletions(-) (limited to 'src/osmo-bts-litecell15/tch.c') diff --git a/src/osmo-bts-litecell15/tch.c b/src/osmo-bts-litecell15/tch.c index 5b5a375d..bcb1edda 100644 --- a/src/osmo-bts-litecell15/tch.c +++ b/src/osmo-bts-litecell15/tch.c @@ -199,13 +199,10 @@ static struct msgb *l1_to_rtppayload_amr(uint8_t *l1_payload, uint8_t payload_le */ static int rtppayload_to_l1_amr(uint8_t *l1_payload, const uint8_t *rtp_payload, uint8_t payload_len, - struct gsm_lchan *lchan, uint8_t cmr, int8_t cmi, - uint8_t ft) + struct gsm_lchan *lchan, uint8_t ft) { - memcpy(l1_payload+2, rtp_payload, payload_len); - amr_set_mode_pref(l1_payload, &lchan->tch.amr_mr, cmi, cmr); - - return payload_len + 2; + memcpy(l1_payload, rtp_payload, payload_len); + return payload_len; } #define RTP_MSGB_ALLOC_SIZE 512 @@ -227,11 +224,8 @@ bool l1if_tch_encode(struct gsm_lchan *lchan, uint8_t *data, uint8_t *len, const uint8_t *rtp_pl, unsigned int rtp_pl_len, uint32_t fn, bool marker) { uint8_t *payload_type; - uint8_t *l1_payload, cmr; - enum osmo_amr_type ft; - enum osmo_amr_quality bfi; - int8_t sti, cmi; - int rc; + uint8_t *l1_payload, ft; + int rc = 0; bool is_sid = false; DEBUGP(DRTP, "%s RTP IN: %s\n", gsm_lchan_name(lchan), @@ -265,36 +259,25 @@ bool l1if_tch_encode(struct gsm_lchan *lchan, uint8_t *data, uint8_t *len, /* FIXME: detect and save EFR SID */ break; case GSM48_CMODE_SPEECH_AMR: - osmo_amr_rtp_dec(rtp_pl, rtp_pl_len, &cmr, &cmi, &ft, &bfi, - &sti); - if (ft == AMR_SID) { - save_last_sid(lchan, rtp_pl, rtp_pl_len, fn, sti, cmr, - cmi); - return false; - } - if (ft != AMR_NO_DATA && !osmo_amr_is_speech(ft)) { - LOGP(DRTP, LOGL_ERROR, "unsupported AMR FT 0x%02x\n", - ft); - return false; - } - if (osmo_amr_is_speech(ft)) { - if (lchan->tch.last_sid.len) { /* FIXME: force ONSET */ - marker = true; - } - /* We received AMR SPEECH frame - invalidate saved SID */ - lchan->tch.last_sid.len = 0; - } - if (marker) { + rc = dtx_amr_check_onset(lchan, rtp_pl, rtp_pl_len, fn, + l1_payload, &ft); + + if (marker || rc > 0) { *payload_type = GsmL1_TchPlType_Amr_Onset; - rc = 0; - LOGP(DRTP, LOGL_ERROR, "Marker SPEECH frame AMR %s\n", + *len = 1; + if (rc != 0) { + LOGP(DRTP, LOGL_NOTICE, "%s SPEECH frame without" + " Marker: ONSET forced\n", + get_value_string(osmo_amr_type_names, ft)); + return true; + } + LOGP(DRTP, LOGL_DEBUG, "%s SPEECH frame with Marker\n", get_value_string(osmo_amr_type_names, ft)); } else { *payload_type = GsmL1_TchPlType_Amr; - rc = rtppayload_to_l1_amr(l1_payload, rtp_pl, - rtp_pl_len, lchan, cmr, cmi, - ft); + rc = 2 + rtppayload_to_l1_amr(l1_payload + 2, rtp_pl, + rtp_pl_len, lchan, ft); } break; default: -- cgit v1.2.3