aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2016-09-16 18:48:33 +0200
committerMax <msuraev@sysmocom.de>2016-09-23 16:57:05 +0200
commit527dd402c714c3ee0832fa2057b219075f8f7646 (patch)
tree2fe0bcb356dae2aae81f7823fb9d429bb1ed60e8
parent80473a113d012321fa1faec24794f0b048cb1a58 (diff)
DTX: fix SID repeat scheduling
Previously SID retransmission was scheduled incorrectly based on GSM frames instead of voice frames. Fix this by using GSM Fn only as elapsed time estimation: * move saved SID retransmission into generic function from lc15 and sysmo specific code * split retransmission time check into separate generic function * compute estimation for elapsed time since last retransmission using GSM Fn Change-Id: Ib054b458a7345d9ba40dba53754ca59ab099c8e8 Fixes: OS#1799
-rw-r--r--include/osmo-bts/msg_utils.h2
-rw-r--r--src/common/msg_utils.c44
-rw-r--r--src/osmo-bts-litecell15/tch.c68
-rw-r--r--src/osmo-bts-sysmo/tch.c68
4 files changed, 66 insertions, 116 deletions
diff --git a/include/osmo-bts/msg_utils.h b/include/osmo-bts/msg_utils.h
index 591d1942..cde7a93b 100644
--- a/include/osmo-bts/msg_utils.h
+++ b/include/osmo-bts/msg_utils.h
@@ -23,6 +23,8 @@ enum {
void lchan_set_marker(bool t, struct gsm_lchan *lchan);
void save_last_sid(struct gsm_lchan *lchan, uint8_t *l1_payload, size_t length,
uint32_t fn, bool update);
+uint8_t repeat_last_sid(struct gsm_lchan *lchan, uint8_t *dst, uint32_t fn);
+bool dtx_amr_sid_optional(const struct gsm_lchan *lchan, uint32_t fn);
bool dtx_sched_optional(struct gsm_lchan *lchan, uint32_t fn);
int msg_verify_ipa_structure(struct msgb *msg);
int msg_verify_oml_structure(struct msgb *msg);
diff --git a/src/common/msg_utils.c b/src/common/msg_utils.c
index f12c6534..967b10d9 100644
--- a/src/common/msg_utils.c
+++ b/src/common/msg_utils.c
@@ -25,6 +25,7 @@
#include <osmocom/gsm/protocol/gsm_12_21.h>
#include <osmocom/gsm/abis_nm.h>
#include <osmocom/core/msgb.h>
+#include <osmocom/trau/osmo_ortp.h>
#include <arpa/inet.h>
@@ -111,6 +112,49 @@ void save_last_sid(struct gsm_lchan *lchan, uint8_t *l1_payload, size_t length,
memcpy(lchan->tch.last_sid.buf, l1_payload, copy_len);
}
+/* repeat last SID if possible, returns SID length + 1 or 0 */
+/*! \brief Repeat last SID if possible in case of DTX
+ * \param[in] lchan Logical channel on which we check scheduling
+ * \param[in] dst Buffer to copy last SID into
+ * \returns Number of bytes copied + 1 (to accommodate for extra byte with
+ * payload type) or 0 if there's nothing to copy
+ */
+uint8_t repeat_last_sid(struct gsm_lchan *lchan, uint8_t *dst, uint32_t fn)
+{
+ if (lchan->tch.last_sid.len) {
+ memcpy(dst, lchan->tch.last_sid.buf, lchan->tch.last_sid.len);
+ lchan->tch.last_sid.fn = fn;
+ return lchan->tch.last_sid.len + 1;
+ }
+ LOGP(DL1C, LOGL_NOTICE, "Have to send %s frame on TCH but SID buffer "
+ "is empty - sent nothing\n",
+ get_value_string(gsm48_chan_mode_names, lchan->tch_mode));
+ return 0;
+}
+
+/*! \brief Check if enough time has passed since last SID (if any) to repeat it
+ * \param[in] lchan Logical channel on which we check scheduling
+ * \param[in] fn Frame Number for which we check scheduling
+ * \returns true if transmission can be omitted, false otherwise
+ */
+bool dtx_amr_sid_optional(const struct gsm_lchan *lchan, uint32_t fn)
+{
+ /* Compute approx. time delta based on Fn duration */
+ uint32_t delta = GSM_FN_TO_MS(fn - lchan->tch.last_sid.fn);
+
+ /* according to 3GPP TS 26.093 A.5.1.1: */
+ if (lchan->tch.last_sid.is_update) {
+ /* SID UPDATE should be repeated every 8th RTP frame */
+ if (delta < GSM_RTP_FRAME_DURATION_MS * 8)
+ return true;
+ return false;
+ }
+ /* 3rd frame after SID FIRST should be SID UPDATE */
+ if (delta < GSM_RTP_FRAME_DURATION_MS * 3)
+ return true;
+ return false;
+}
+
static inline bool fn_chk(const uint8_t *t, uint32_t fn)
{
uint8_t i;
diff --git a/src/osmo-bts-litecell15/tch.c b/src/osmo-bts-litecell15/tch.c
index 5badc4d7..4fdf6a65 100644
--- a/src/osmo-bts-litecell15/tch.c
+++ b/src/osmo-bts-litecell15/tch.c
@@ -463,27 +463,6 @@ err_payload_match:
return -EINVAL;
}
-static bool repeat_last_sid(struct gsm_lchan *lchan, struct msgb *msg)
-{
- GsmL1_Prim_t *l1p;
- GsmL1_PhDataReq_t *data_req;
- GsmL1_MsgUnitParam_t *msu_param;
- uint8_t *l1_payload;
-
- l1p = msgb_l1prim(msg);
- data_req = &l1p->u.phDataReq;
- msu_param = &data_req->msgUnitParam;
- l1_payload = &msu_param->u8Buffer[1];
-
- if (lchan->tch.last_sid.len) {
- memcpy(l1_payload, lchan->tch.last_sid.buf,
- lchan->tch.last_sid.len);
- msu_param->u8Size = lchan->tch.last_sid.len + 1;
- return true;
- }
- return false;
-}
-
struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t fn)
{
struct msgb *msg;
@@ -506,30 +485,13 @@ struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t fn)
switch (lchan->tch_mode) {
case GSM48_CMODE_SPEECH_AMR:
*payload_type = GsmL1_TchPlType_Amr;
- /* 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 {
- /* 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(l1_payload, 0, AMR_NO_DATA,
- AMR_GOOD);
- return msg;
+ if (dtx_amr_sid_optional(lchan, fn)) {
+ msgb_free(msg);
+ return NULL;
}
+ msu_param->u8Size = repeat_last_sid(lchan, l1_payload, fn);
+ if (!msu_param->u8Size)
+ osmo_amr_rtp_enc(l1_payload, 0, AMR_NO_DATA, AMR_GOOD);
break;
case GSM48_CMODE_SPEECH_V1:
if (lchan->type == GSM_LCHAN_TCH_F)
@@ -541,14 +503,9 @@ struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t 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);
+ msu_param->u8Size = repeat_last_sid(lchan, l1_payload, fn);
+ if (!msu_param->u8Size)
return NULL;
- }
break;
case GSM48_CMODE_SPEECH_EFR:
*payload_type = GsmL1_TchPlType_Efr;
@@ -556,14 +513,9 @@ struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t 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);
+ msu_param->u8Size = repeat_last_sid(lchan, l1_payload, fn);
+ if (!msu_param->u8Size)
return NULL;
- }
break;
default:
msgb_free(msg);
diff --git a/src/osmo-bts-sysmo/tch.c b/src/osmo-bts-sysmo/tch.c
index 6c78ceb0..ee72e535 100644
--- a/src/osmo-bts-sysmo/tch.c
+++ b/src/osmo-bts-sysmo/tch.c
@@ -566,27 +566,6 @@ err_payload_match:
return -EINVAL;
}
-static bool repeat_last_sid(struct gsm_lchan *lchan, struct msgb *msg)
-{
- GsmL1_Prim_t *l1p;
- GsmL1_PhDataReq_t *data_req;
- GsmL1_MsgUnitParam_t *msu_param;
- uint8_t *l1_payload;
-
- l1p = msgb_l1prim(msg);
- data_req = &l1p->u.phDataReq;
- msu_param = &data_req->msgUnitParam;
- l1_payload = &msu_param->u8Buffer[1];
-
- if (lchan->tch.last_sid.len) {
- memcpy(l1_payload, lchan->tch.last_sid.buf,
- lchan->tch.last_sid.len);
- msu_param->u8Size = lchan->tch.last_sid.len + 1;
- return true;
- }
- return false;
-}
-
struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t fn)
{
struct msgb *msg;
@@ -609,30 +588,13 @@ struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t fn)
switch (lchan->tch_mode) {
case GSM48_CMODE_SPEECH_AMR:
*payload_type = GsmL1_TchPlType_Amr;
- /* 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 {
- /* 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(l1_payload, 0, AMR_NO_DATA,
- AMR_GOOD);
- return msg;
+ if (dtx_amr_sid_optional(lchan, fn)) {
+ msgb_free(msg);
+ return NULL;
}
+ msu_param->u8Size = repeat_last_sid(lchan, l1_payload, fn);
+ if (!msu_param->u8Size)
+ osmo_amr_rtp_enc(l1_payload, 0, AMR_NO_DATA, AMR_GOOD);
break;
case GSM48_CMODE_SPEECH_V1:
if (lchan->type == GSM_LCHAN_TCH_F)
@@ -644,14 +606,9 @@ struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t 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);
+ msu_param->u8Size = repeat_last_sid(lchan, l1_payload, fn);
+ if (!msu_param->u8Size)
return NULL;
- }
break;
case GSM48_CMODE_SPEECH_EFR:
*payload_type = GsmL1_TchPlType_Efr;
@@ -659,14 +616,9 @@ struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t 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);
+ msu_param->u8Size = repeat_last_sid(lchan, l1_payload, fn);
+ if (!msu_param->u8Size)
return NULL;
- }
break;
default:
msgb_free(msg);