diff options
author | Max <msuraev@sysmocom.de> | 2016-09-28 16:25:13 +0200 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2016-09-30 16:50:47 +0200 |
commit | 7dffd553df0ca48f52d6faca70aa3e9cf2760840 (patch) | |
tree | ead12cc877a81d613320fc1f74a5ef319d821f72 /src/common/msg_utils.c | |
parent | 94fa25295f090cc6190ae7c96df946a3979f05cc (diff) |
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
Diffstat (limited to 'src/common/msg_utils.c')
-rw-r--r-- | src/common/msg_utils.c | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/src/common/msg_utils.c b/src/common/msg_utils.c index 967b10d9..f5a48a3d 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. |