diff options
author | Max <msuraev@sysmocom.de> | 2016-06-10 15:33:42 +0200 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2016-06-10 15:49:18 +0200 |
commit | 725f2283861dcd495eb2ea87784022cdc04ea02a (patch) | |
tree | aa5aefc31b449ebf0bffdcc4853b6d49a5887d30 /src/common/tch.c | |
parent | f43d24598d5c8769ed94d86e57e7deec8075c93c (diff) |
DTXd: store/repeat last SID
Store last SID received over RTP and repeat is if necessary (no new SID
or SPEECH frames) according to codec-specific scheduling rules.
Change-Id: I42c417ec2e66d58edf790c73fc0518f2c0860c28
Related: OS#1563
Diffstat (limited to 'src/common/tch.c')
-rw-r--r-- | src/common/tch.c | 124 |
1 files changed, 105 insertions, 19 deletions
diff --git a/src/common/tch.c b/src/common/tch.c index 03db563c..597cb951 100644 --- a/src/common/tch.c +++ b/src/common/tch.c @@ -19,6 +19,9 @@ * */ +#include <stdbool.h> + +#include <osmocom/codec/codec.h> #include <osmo-bts/gsm_data.h> #include <osmo-bts/logging.h> #include <osmo-bts/l1sap.h> @@ -48,35 +51,118 @@ int add_l1sap_header(struct gsm_lchan *lchan, struct msgb *rmsg, return l1sap_up(trx, l1sap); } -struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan) +static inline bool fn_chk(uint8_t *t, uint32_t fn) +{ + uint8_t i; + for (i = 0; i < ARRAY_SIZE(t); i++) + if (fn % 104 == t[i]) + return false; + return true; +} + +static bool dtx_sched_optional(struct gsm_lchan *lchan, uint32_t fn) +{ + /* 3GPP TS 45.008 ยง 8.3 */ + uint8_t f[] = { 52, 53, 54, 55, 56, 57, 58, 59 }, + h0[] = { 0, 2, 4, 6, 52, 54, 56, 58 }, + h1[] = { 14, 16, 18, 20, 66, 68, 70, 72 }; + if (lchan->tch_mode == GSM48_CMODE_SPEECH_V1) { + if (lchan->type == GSM_LCHAN_TCH_F) + return fn_chk(f, fn); + else + return fn_chk(lchan->nr ? h1 : h0, fn); + } + return false; +} + +static bool repeat_last_sid(struct gsm_lchan *lchan, struct msgb *msg) +{ + uint8_t *l1_payload = get_payload_addr(msg); + if (lchan->tch.last_sid.len) { + memcpy(l1_payload, lchan->tch.last_sid.buf, + lchan->tch.last_sid.len); + set_payload_size(msg, lchan->tch.last_sid.len + 1); + return true; + } + return false; +} + +/* store the last SID frame in lchan context */ +void save_last_sid(struct gsm_lchan *lchan, uint8_t *l1_payload, size_t length, + uint32_t fn, bool update) +{ + size_t copy_len = OSMO_MIN(length + 1, + ARRAY_SIZE(lchan->tch.last_sid.buf)); + + lchan->tch.last_sid.len = copy_len; + lchan->tch.last_sid.fn = fn; + lchan->tch.last_sid.is_update = update; + + memcpy(lchan->tch.last_sid.buf, l1_payload, copy_len); +} + +struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t fn) { struct msgb *msg; - uint8_t *l1_payload; msg = l1p_msgb_alloc(); if (!msg) return NULL; - l1_payload = get_payload_addr(msg); - switch (lchan->tch_mode) { case GSM48_CMODE_SPEECH_AMR: - set_payload_type(msg, lchan); - if (lchan->tch.last_sid.len) { - memcpy(l1_payload, lchan->tch.last_sid.buf, - lchan->tch.last_sid.len); - set_payload_size(msg, lchan->tch.last_sid.len + 1); + /* according to 3GPP TS 26.093 A.5.1.1: */ + if (lchan->tch.last_sid.is_update) { + /* SID UPDATE should be repeated every 8th frame */ + if (fn - lchan->tch.last_sid.fn < 7) { + msgb_free(msg); + return NULL; + } } else { - /* FIXME: decide if we should send SPEECH_BAD or - * SID_BAD */ -#if 0 - *payload_type = GsmL1_TchPlType_Amr_SidBad; - memset(l1_payload, 0xFF, 5); - msu_param->u8Size = 5 + 3; -#else - /* send an all-zero SID */ - set_payload_size(msg, 8); -#endif + /* 3rd frame after SID FIRST should be SID UPDATE */ + if (fn - lchan->tch.last_sid.fn < 3) { + msgb_free(msg); + return NULL; + } + } + if (repeat_last_sid(lchan, msg)) + return msg; + else { + LOGP(DL1C, LOGL_NOTICE, "Have to send AMR frame on TCH " + "(FN=%u) but SID buffer is empty - sent NO_DATA\n", + fn); + osmo_amr_rtp_enc(get_payload_addr(msg), 0, AMR_NO_DATA, + AMR_GOOD); + return msg; + } + break; + case GSM48_CMODE_SPEECH_V1: + /* unlike AMR, FR & HR schedued based on absolute FN value */ + if (dtx_sched_optional(lchan, fn)) { + msgb_free(msg); + return NULL; + } + if (repeat_last_sid(lchan, msg)) + return msg; + else { + LOGP(DL1C, LOGL_NOTICE, "Have to send V1 frame on TCH " + "(FN=%u) but SID buffer is empty - sent nothing\n", + fn); + return NULL; + } + break; + case GSM48_CMODE_SPEECH_EFR: + if (dtx_sched_optional(lchan, fn)) { + msgb_free(msg); + return NULL; + } + if (repeat_last_sid(lchan, msg)) + return msg; + else { + LOGP(DL1C, LOGL_NOTICE, "Have to send EFR frame on TCH " + "(FN=%u) but SID buffer is empty - sent nothing\n", + fn); + return NULL; } break; default: |