From 7dffd553df0ca48f52d6faca70aa3e9cf2760840 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 28 Sep 2016 16:25:13 +0200 Subject: [PATCH] DTX: move scheduling check inside repeat_last_sid Note: this also require changes to properly link against libosmocodec - see 2bb65be159dfdabf664fec569b343320301701b0 in libosmocore. Change-Id: I96594cf3aa1013d505bd20069d5bf261d9a2aefb --- include/osmo-bts/msg_utils.h | 4 +-- src/common/Makefile.am | 4 +-- src/common/msg_utils.c | 58 +++++++++++++++++++++------------- src/osmo-bts-litecell15/tch.c | 34 ++++++-------------- src/osmo-bts-sysmo/Makefile.am | 2 +- src/osmo-bts-sysmo/tch.c | 34 ++++++-------------- tests/misc/Makefile.am | 4 +-- 7 files changed, 61 insertions(+), 79 deletions(-) diff --git a/include/osmo-bts/msg_utils.h b/include/osmo-bts/msg_utils.h index f03eb438a..14c23205b 100644 --- a/include/osmo-bts/msg_utils.h +++ b/include/osmo-bts/msg_utils.h @@ -6,6 +6,8 @@ #include +#include + #include struct msgb; @@ -27,7 +29,5 @@ 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/Makefile.am b/src/common/Makefile.am index fbb657292..856f74122 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) -AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOTRAU_CFLAGS) -LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOTRAU_LIBS) +AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOTRAU_CFLAGS) $(LIBOSMOCODEC_CFLAGS) +LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOCODEC_LIBS) noinst_LIBRARIES = libbts.a libl1sched.a libbts_a_SOURCES = gsm_data_shared.c sysinfo.c logging.c abis.c oml.c bts.c \ diff --git a/src/common/msg_utils.c b/src/common/msg_utils.c index 967b10d93..f5a48a3d6 100644 --- a/src/common/msg_utils.c +++ b/src/common/msg_utils.c @@ -112,32 +112,13 @@ 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) +static inline 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); @@ -169,7 +150,7 @@ static inline bool fn_chk(const uint8_t *t, uint32_t fn) * \param[in] fn Frame Number for which we check scheduling * \returns true if transmission can be omitted, false otherwise */ -bool dtx_sched_optional(struct gsm_lchan *lchan, uint32_t fn) +static inline bool dtx_sched_optional(struct gsm_lchan *lchan, uint32_t fn) { /* According to 3GPP TS 45.008 ยง 8.3: */ static const uint8_t f[] = { 52, 53, 54, 55, 56, 57, 58, 59 }, @@ -184,6 +165,39 @@ bool dtx_sched_optional(struct gsm_lchan *lchan, uint32_t fn) return false; } +/* 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), 0 if there's nothing to copy + */ +uint8_t repeat_last_sid(struct gsm_lchan *lchan, uint8_t *dst, uint32_t fn) +{ + /* FIXME: add EFR support */ + if (lchan->tch_mode == GSM48_CMODE_SPEECH_EFR) + return 0; + + if (lchan->tch_mode != GSM48_CMODE_SPEECH_AMR) { + if (dtx_sched_optional(lchan, fn)) + return 0; + } else + if (dtx_amr_sid_optional(lchan, fn)) + return 0; + + 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_DEBUG, "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; +} + /** * Return 0 in case the IPA structure is okay and in this * case the l2h will be set to the beginning of the data. diff --git a/src/osmo-bts-litecell15/tch.c b/src/osmo-bts-litecell15/tch.c index bcf981e42..5ec1ee743 100644 --- a/src/osmo-bts-litecell15/tch.c +++ b/src/osmo-bts-litecell15/tch.c @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -492,6 +491,7 @@ struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t fn) GsmL1_MsgUnitParam_t *msu_param; uint8_t *payload_type; uint8_t *l1_payload; + int rc; msg = l1p_msgb_alloc(); if (!msg) @@ -506,43 +506,27 @@ 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; - 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) *payload_type = GsmL1_TchPlType_Fr; else *payload_type = GsmL1_TchPlType_Hr; - /* unlike AMR, FR & HR schedued based on absolute FN value */ - if (dtx_sched_optional(lchan, fn)) { - msgb_free(msg); - return NULL; - } - 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; - if (dtx_sched_optional(lchan, fn)) { - msgb_free(msg); - return NULL; - } - msu_param->u8Size = repeat_last_sid(lchan, l1_payload, fn); - if (!msu_param->u8Size) - return NULL; break; default: msgb_free(msg); - msg = NULL; - break; + return NULL; } + rc = repeat_last_sid(lchan, l1_payload, fn); + if (!rc) { + msgb_free(msg); + return NULL; + } + msu_param->u8Size = rc; + return msg; } diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 34f4bb0dd..8e39a3a2f 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -29,7 +29,7 @@ sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr_temp.c \ misc/sysmobts_mgr_calib.c \ eeprom.c -sysmobts_mgr_LDADD = $(LIBGPS_LIBS) $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCTRL_LIBS) $(top_builddir)/src/common/libbts.a +sysmobts_mgr_LDADD = $(LIBGPS_LIBS) $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCTRL_LIBS) $(top_builddir)/src/common/libbts.a $(COMMON_LDADD) sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c eeprom.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/tch.c b/src/osmo-bts-sysmo/tch.c index f35039827..0e4b2dab0 100644 --- a/src/osmo-bts-sysmo/tch.c +++ b/src/osmo-bts-sysmo/tch.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -595,6 +594,7 @@ struct msgb *gen_empty_tch_msg(struct gsm_lchan *lchan, uint32_t fn) GsmL1_MsgUnitParam_t *msu_param; uint8_t *payload_type; uint8_t *l1_payload; + int rc; msg = l1p_msgb_alloc(); if (!msg) @@ -609,43 +609,27 @@ 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; - 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) *payload_type = GsmL1_TchPlType_Fr; else *payload_type = GsmL1_TchPlType_Hr; - /* unlike AMR, FR & HR schedued based on absolute FN value */ - if (dtx_sched_optional(lchan, fn)) { - msgb_free(msg); - return NULL; - } - 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; - if (dtx_sched_optional(lchan, fn)) { - msgb_free(msg); - return NULL; - } - msu_param->u8Size = repeat_last_sid(lchan, l1_payload, fn); - if (!msu_param->u8Size) - return NULL; break; default: msgb_free(msg); - msg = NULL; - break; + return NULL; } + rc = repeat_last_sid(lchan, l1_payload, fn); + if (!rc) { + msgb_free(msg); + return NULL; + } + msu_param->u8Size = rc; + return msg; } diff --git a/tests/misc/Makefile.am b/tests/misc/Makefile.am index f60325b01..d5acb18a3 100644 --- a/tests/misc/Makefile.am +++ b/tests/misc/Makefile.am @@ -1,6 +1,6 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR) -AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) -LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) +AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOCODEC_CFLAGS) +LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCODEC_LIBS) noinst_PROGRAMS = misc_test EXTRA_DIST = misc_test.ok