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
This commit is contained in:
Max 2016-09-28 16:25:13 +02:00
parent 94fa25295f
commit 7dffd553df
7 changed files with 61 additions and 79 deletions

View File

@ -6,6 +6,8 @@
#include <osmo-bts/gsm_data.h>
#include <osmocom/codec/codec.h>
#include <stdbool.h>
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);

View File

@ -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 \

View File

@ -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.

View File

@ -35,7 +35,6 @@
#include <osmocom/core/select.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/bits.h>
#include <osmocom/codec/codec.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/trau/osmo_ortp.h>
@ -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;
}

View File

@ -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)

View File

@ -32,7 +32,6 @@
#include <osmocom/core/select.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/bits.h>
#include <osmocom/codec/codec.h>
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/trau/osmo_ortp.h>
@ -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;
}

View File

@ -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