aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2016-09-30 19:09:04 +0200
committerMax <msuraev@sysmocom.de>2016-09-30 19:09:04 +0200
commit067ef3f1ce1b7474a553bb8e54ff1543c4012828 (patch)
treedd96bd6d72a529de7fb27956f4d5e38008a25ceb
parent9959f45d90166331dc8196c603184888bbe7f1e8 (diff)
DTX: move ONSET detection into separate function
Move code from tch.c (lc15, sysmo) into generic function which: - check if talkspurt is happening - cache SID if necessary or invalidate cache - fill in CMR & CMI prefix This also fixes the problem when SID FIRST was cached without sending just like SID UPDATE instead of being sent right away. Change-Id: I6c7016a54749abadeef4fd4f5b6f750b256fb916
-rw-r--r--include/osmo-bts/msg_utils.h3
-rw-r--r--src/common/msg_utils.c57
-rw-r--r--src/osmo-bts-litecell15/tch.c55
-rw-r--r--src/osmo-bts-sysmo/tch.c55
4 files changed, 96 insertions, 74 deletions
diff --git a/include/osmo-bts/msg_utils.h b/include/osmo-bts/msg_utils.h
index f07623d5..f99f3c40 100644
--- a/include/osmo-bts/msg_utils.h
+++ b/include/osmo-bts/msg_utils.h
@@ -29,6 +29,9 @@ void lchan_set_marker(bool t, struct gsm_lchan *lchan);
void save_last_sid(struct gsm_lchan *lchan, const uint8_t *l1_payload,
size_t length, uint32_t fn, int update, uint8_t cmr,
int8_t cmi);
+int dtx_amr_check_onset(struct gsm_lchan *lchan, const uint8_t *rtp_pl,
+ size_t rtp_pl_len, uint32_t fn, uint8_t *l1_payload,
+ uint8_t *ft_out);
uint8_t repeat_last_sid(struct gsm_lchan *lchan, uint8_t *dst, 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 5c6bbbea..99a211fd 100644
--- a/src/common/msg_utils.c
+++ b/src/common/msg_utils.c
@@ -29,7 +29,7 @@
#include <osmocom/trau/osmo_ortp.h>
#include <arpa/inet.h>
-
+#include <errno.h>
static int check_fom(struct abis_om_hdr *omh, size_t len)
{
@@ -99,7 +99,7 @@ void lchan_set_marker(bool t, struct gsm_lchan *lchan)
}
}
-/* store the last SID frame in lchan context */
+
/*! \brief Store the last SID frame in lchan context
* \param[in] lchan Logical channel on which we check scheduling
* \param[in] l1_payload buffer with SID data
@@ -126,6 +126,59 @@ void save_last_sid(struct gsm_lchan *lchan, const uint8_t *l1_payload,
memcpy(lchan->tch.last_sid.buf + amr, l1_payload, copy_len);
}
+/*! \brief Check current and cached SID to decide if talkspurt takes place
+ * \param[in] lchan Logical channel on which we check scheduling
+ * \param[in] rtp_pl buffer with RTP data
+ * \param[in] rtp_pl_len length of rtp_pl
+ * \param[in] fn Frame Number for which we check scheduling
+ * \param[in] l1_payload buffer where CMR and CMI prefix should be added
+ * \param[out] ft_out Frame Type to be populated after decoding
+ * \returns 0 if frame should be send immediately (2 byte CMR,CMI prefix added:
+ * caller must adjust length as necessary),
+ * 1 if ONSET event is detected
+ * negative if no sending is necessary (either error or cached SID
+ * UPDATE)
+ */
+int dtx_amr_check_onset(struct gsm_lchan *lchan, const uint8_t *rtp_pl,
+ size_t rtp_pl_len, uint32_t fn, uint8_t *l1_payload,
+ uint8_t *ft_out)
+{
+ uint8_t cmr;
+ enum osmo_amr_type ft;
+ enum osmo_amr_quality bfi;
+ int8_t sti, cmi;
+ osmo_amr_rtp_dec(rtp_pl, rtp_pl_len, &cmr, &cmi, &ft, &bfi, &sti);
+ *ft_out = ft; /* only needed for old sysmo firmware */
+
+ if (ft == AMR_SID) {
+ save_last_sid(lchan, rtp_pl, rtp_pl_len, fn, sti, cmr, cmi);
+ if (sti) /* SID_UPDATE should be cached and send later */
+ return -EAGAIN;
+ else { /* SID_FIRST - cached and send right away */
+ amr_set_mode_pref(l1_payload, &lchan->tch.amr_mr, cmi,
+ cmr);
+ return 0;
+ }
+ }
+
+ if (ft != AMR_NO_DATA && !osmo_amr_is_speech(ft)) {
+ LOGP(DRTP, LOGL_ERROR, "unsupported AMR FT 0x%02x\n", ft);
+ return -ENOTSUP;
+ }
+
+ if (osmo_amr_is_speech(ft)) {
+ if (lchan->tch.last_sid.len) { /* force ONSET */
+ lchan->tch.last_sid.len = 0;
+ return 1;
+ }
+ /* We received AMR SPEECH frame - invalidate saved SID */
+ lchan->tch.last_sid.len = 0;
+ amr_set_mode_pref(l1_payload, &lchan->tch.amr_mr, cmi, cmr);
+ }
+
+ 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
diff --git a/src/osmo-bts-litecell15/tch.c b/src/osmo-bts-litecell15/tch.c
index 5b5a375d..bcb1edda 100644
--- a/src/osmo-bts-litecell15/tch.c
+++ b/src/osmo-bts-litecell15/tch.c
@@ -199,13 +199,10 @@ static struct msgb *l1_to_rtppayload_amr(uint8_t *l1_payload, uint8_t payload_le
*/
static int rtppayload_to_l1_amr(uint8_t *l1_payload, const uint8_t *rtp_payload,
uint8_t payload_len,
- struct gsm_lchan *lchan, uint8_t cmr, int8_t cmi,
- uint8_t ft)
+ struct gsm_lchan *lchan, uint8_t ft)
{
- memcpy(l1_payload+2, rtp_payload, payload_len);
- amr_set_mode_pref(l1_payload, &lchan->tch.amr_mr, cmi, cmr);
-
- return payload_len + 2;
+ memcpy(l1_payload, rtp_payload, payload_len);
+ return payload_len;
}
#define RTP_MSGB_ALLOC_SIZE 512
@@ -227,11 +224,8 @@ bool l1if_tch_encode(struct gsm_lchan *lchan, uint8_t *data, uint8_t *len,
const uint8_t *rtp_pl, unsigned int rtp_pl_len, uint32_t fn, bool marker)
{
uint8_t *payload_type;
- uint8_t *l1_payload, cmr;
- enum osmo_amr_type ft;
- enum osmo_amr_quality bfi;
- int8_t sti, cmi;
- int rc;
+ uint8_t *l1_payload, ft;
+ int rc = 0;
bool is_sid = false;
DEBUGP(DRTP, "%s RTP IN: %s\n", gsm_lchan_name(lchan),
@@ -265,36 +259,25 @@ bool l1if_tch_encode(struct gsm_lchan *lchan, uint8_t *data, uint8_t *len,
/* FIXME: detect and save EFR SID */
break;
case GSM48_CMODE_SPEECH_AMR:
- osmo_amr_rtp_dec(rtp_pl, rtp_pl_len, &cmr, &cmi, &ft, &bfi,
- &sti);
- if (ft == AMR_SID) {
- save_last_sid(lchan, rtp_pl, rtp_pl_len, fn, sti, cmr,
- cmi);
- return false;
- }
- if (ft != AMR_NO_DATA && !osmo_amr_is_speech(ft)) {
- LOGP(DRTP, LOGL_ERROR, "unsupported AMR FT 0x%02x\n",
- ft);
- return false;
- }
- if (osmo_amr_is_speech(ft)) {
- if (lchan->tch.last_sid.len) { /* FIXME: force ONSET */
- marker = true;
- }
- /* We received AMR SPEECH frame - invalidate saved SID */
- lchan->tch.last_sid.len = 0;
- }
- if (marker) {
+ rc = dtx_amr_check_onset(lchan, rtp_pl, rtp_pl_len, fn,
+ l1_payload, &ft);
+
+ if (marker || rc > 0) {
*payload_type = GsmL1_TchPlType_Amr_Onset;
- rc = 0;
- LOGP(DRTP, LOGL_ERROR, "Marker SPEECH frame AMR %s\n",
+ *len = 1;
+ if (rc != 0) {
+ LOGP(DRTP, LOGL_NOTICE, "%s SPEECH frame without"
+ " Marker: ONSET forced\n",
+ get_value_string(osmo_amr_type_names, ft));
+ return true;
+ }
+ LOGP(DRTP, LOGL_DEBUG, "%s SPEECH frame with Marker\n",
get_value_string(osmo_amr_type_names, ft));
}
else {
*payload_type = GsmL1_TchPlType_Amr;
- rc = rtppayload_to_l1_amr(l1_payload, rtp_pl,
- rtp_pl_len, lchan, cmr, cmi,
- ft);
+ rc = 2 + rtppayload_to_l1_amr(l1_payload + 2, rtp_pl,
+ rtp_pl_len, lchan, ft);
}
break;
default:
diff --git a/src/osmo-bts-sysmo/tch.c b/src/osmo-bts-sysmo/tch.c
index 655884d2..9be86599 100644
--- a/src/osmo-bts-sysmo/tch.c
+++ b/src/osmo-bts-sysmo/tch.c
@@ -282,11 +282,10 @@ static struct msgb *l1_to_rtppayload_amr(uint8_t *l1_payload, uint8_t payload_le
*/
static int rtppayload_to_l1_amr(uint8_t *l1_payload, const uint8_t *rtp_payload,
uint8_t payload_len,
- struct gsm_lchan *lchan, uint8_t cmr, int8_t cmi,
- uint8_t ft)
+ struct gsm_lchan *lchan, uint8_t ft)
{
#ifdef USE_L1_RTP_MODE
- memcpy(l1_payload+2, rtp_payload, payload_len);
+ memcpy(l1_payload, rtp_payload, payload_len);
#else
uint8_t amr_if2_core_len = payload_len - 2;
@@ -299,9 +298,7 @@ static int rtppayload_to_l1_amr(uint8_t *l1_payload, const uint8_t *rtp_payload,
/* lower 4 bit of first FR2 byte contains FT */
l1_payload[2] |= ft;
#endif /* USE_L1_RTP_MODE */
- amr_set_mode_pref(l1_payload, &lchan->tch.amr_mr, cmi, cmr);
-
- return payload_len + 2;
+ return payload_len;
}
#define RTP_MSGB_ALLOC_SIZE 512
@@ -323,11 +320,8 @@ bool l1if_tch_encode(struct gsm_lchan *lchan, uint8_t *data, uint8_t *len,
const uint8_t *rtp_pl, unsigned int rtp_pl_len, uint32_t fn, bool marker)
{
uint8_t *payload_type;
- uint8_t *l1_payload, cmr;
- enum osmo_amr_type ft;
- enum osmo_amr_quality bfi;
- int8_t sti, cmi;
- int rc;
+ uint8_t *l1_payload, ft;
+ int rc = 0;
bool is_sid = false;
DEBUGP(DRTP, "%s RTP IN: %s\n", gsm_lchan_name(lchan),
@@ -363,36 +357,25 @@ bool l1if_tch_encode(struct gsm_lchan *lchan, uint8_t *data, uint8_t *len,
break;
#endif
case GSM48_CMODE_SPEECH_AMR:
- osmo_amr_rtp_dec(rtp_pl, rtp_pl_len, &cmr, &cmi, &ft, &bfi,
- &sti);
- if (ft == AMR_SID) {
- save_last_sid(lchan, rtp_pl, rtp_pl_len, fn, sti, cmr,
- cmi);
- return false;
- }
- if (ft != AMR_NO_DATA && !osmo_amr_is_speech(ft)) {
- LOGP(DRTP, LOGL_ERROR, "unsupported AMR FT 0x%02x\n",
- ft);
- return false;
- }
- if (osmo_amr_is_speech(ft)) {
- if (lchan->tch.last_sid.len) { /* FIXME: force ONSET */
- marker = true;
- }
- /* We received AMR SPEECH frame - invalidate saved SID */
- lchan->tch.last_sid.len = 0;
- }
- if (marker) {
+ rc = dtx_amr_check_onset(lchan, rtp_pl, rtp_pl_len, fn,
+ l1_payload, &ft);
+
+ if (marker || rc > 0) {
*payload_type = GsmL1_TchPlType_Amr_Onset;
- rc = 0;
- LOGP(DRTP, LOGL_ERROR, "Marker SPEECH frame AMR %s\n",
+ *len = 1;
+ if (rc != 0) {
+ LOGP(DRTP, LOGL_NOTICE, "%s SPEECH frame without"
+ " Marker: ONSET forced\n",
+ get_value_string(osmo_amr_type_names, ft));
+ return true;
+ }
+ LOGP(DRTP, LOGL_DEBUG, "%s SPEECH frame with Marker\n",
get_value_string(osmo_amr_type_names, ft));
}
else {
*payload_type = GsmL1_TchPlType_Amr;
- rc = rtppayload_to_l1_amr(l1_payload, rtp_pl,
- rtp_pl_len, lchan, cmr, cmi,
- ft);
+ rc = 2 + rtppayload_to_l1_amr(l1_payload + 2, rtp_pl,
+ rtp_pl_len, lchan, ft);
}
break;
default: