falconia has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-bts/+/41048?usp=email )
Change subject: FR/HR/EFR: centralize TCH UL SID classification
......................................................................
FR/HR/EFR: centralize TCH UL SID classification
In any environment where GSM MS may exercise DTXu on TCH/FS, TCH/HS or
TCH/EFS, the BTS receiving this TCH UL has to classify each received
traffic frame as valid SID, invalid SID or non-SID speech. For E1 BTS
this SID classification requirement is explicit as there are dedicated
bits in TRAU-UL frames carrying the SID code. For an IP BTS the need
for this classification is less obvious as most RTP payload formats
omit SID indicator bits - however:
* For HR codec, RTP output in RFC 5993 and TW-TS-002 formats does
include explicit SID classification;
* Also for HR output in both TS 101 318 and RFC 5993 formats
(but not TW-TS-002), SID classification must be considered in order
to turn valid SID with some bit errors into perfect SID codeword;
* OsmoBTS already had logic for all 3 of FR/HR/EFR whereby if a frame
is received that is an accepted SID frame in GSM 06.31/06.41/06.81
definition, a flag is set so that the next good speech frame will
be emitted in RTP with marker bit set. This logic implies SID
classification in TCH UL path.
Prior to this patch, OsmoBTS performed limited, non-consolidated
SID classification:
* For FR and EFR, the only SID classification in TCH UL path was done
for RTP marker purposes by way of osmo_{fr,efr}_is_any_sid() Boolean
result fed to lchan_set_marker();
* For the same RTP marker logic with HR codec, only perfect, error-free
SID frames were detected;
* The same limitation applied to SID classification for RFC 5993 output.
Centralize this SID classification by moving it from BTS model to common
l1sap code and unifying it across all 3 codecs. Immediate functional
effects from this change are:
* On TCH/HS we now detect imperfect (partially corrupted) SID frames
and classify them as valid or invalid SID as intended by ETSI,
like we already did for TCH/FS and TCH/EFS;
* When emitting TS 101 318 or RFC 5993, we apply the inherent limitations
of those RTP formats to valid and invalid SID;
* With all 3 codecs, the check for a good speech frame as exit criterion
from DTXu state now happens after the link quality check in l1sap,
rather than before.
AMR speech mode is not affected at all by these changes: AMR DTX model
is completely different from that of FR/HR/EFR.
Related: OS#6036
Change-Id: Id6c8c146962de2f173760889eb232693bb4229d3
---
M include/osmo-bts/msg_utils.h
M src/common/l1sap.c
M src/osmo-bts-lc15/tch.c
M src/osmo-bts-oc2g/tch.c
M src/osmo-bts-sysmo/tch.c
M src/osmo-bts-trx/sched_lchan_tchf.c
M src/osmo-bts-trx/sched_lchan_tchh.c
7 files changed, 123 insertions(+), 50 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/48/41048/1
diff --git a/include/osmo-bts/msg_utils.h b/include/osmo-bts/msg_utils.h
index 7363bcf..e82dc44 100644
--- a/include/osmo-bts/msg_utils.h
+++ b/include/osmo-bts/msg_utils.h
@@ -22,6 +22,9 @@
* 2) In TCH UL direction, we provide an ability for BTS models to indicate
* BFI along with payload bits, and the same BFI flag can then be set
* by model-independent functions for higher-level BFI conditions.
+ * Additionally for HRv1 codec, we use a control buffer word to pass
+ * SID classification from the function that makes the initial determination
+ * to TS 101 318, RFC 5993 and TW-TS-002 output functions.
*/
/* Accessor macros for control buffer words in RTP input path */
@@ -37,6 +40,7 @@
/* Accessor macros for control buffer words in TCH UL path */
#define tch_ul_msg_bfi(x) ((x)->cb[0])
+#define tch_ul_msg_sid(x) ((x)->cb[1])
/**
* Classification of OML message. ETSI for plain GSM 12.21
diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index f4dea35..8226648 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -2200,24 +2200,6 @@
handle_tch_ind_csd_hr(lchan, tch_ind, data, data_len);
}
-/* a helper function for emitting HR1 UL in RFC 5993 format */
-static void send_rtp_rfc5993(struct gsm_lchan *lchan, uint32_t fn,
- struct msgb *msg)
-{
- uint8_t toc;
-
- OSMO_ASSERT(msg->len == GSM_HR_BYTES);
- /* FIXME: implement proper SID classification per GSM 06.41 section
- * 6.1.1; see OS#6036. Until then, detect error-free SID frames
- * using our existing osmo_hr_check_sid() function. */
- if (osmo_hr_check_sid(msg->data, msg->len))
- toc = 0x20;
- else
- toc = 0x00;
- msgb_push_u8(msg, toc);
- send_ul_rtp_packet(lchan, fn, msg->data, msg->len);
-}
-
/* a helper function for emitting FR/EFR UL in TW-TS-001 format */
static void send_rtp_twts001(struct gsm_lchan *lchan, uint32_t fn,
struct msgb *msg)
@@ -2303,6 +2285,117 @@
lchan->rtp_tx_marker = true;
}
+/* Helper function for l1sap_tch_ind(): RTP output for GSM-HR in either
+ * of the two standard, non-ThemWi-extended payload formats, with restrictions
+ * inherent to these non-TRAU-UL-like formats. */
+static void send_gsmhr_std_rtp(struct gsm_lchan *lchan,
+ const struct gsm_time *g_time, struct msgb *msg,
+ bool emit_rfc5993)
+{
+ uint32_t fn = g_time->fn;
+
+ OSMO_ASSERT(msg->len == GSM_HR_BYTES);
+
+ switch (tch_ul_msg_sid(msg)) {
+ case OSMO_GSM631_SID_CLASS_SPEECH:
+ break;
+ case OSMO_GSM631_SID_CLASS_INVALID:
+ /* neither of these RTP formats allows invalid SID */
+ tch_ul_bfi_handler(lchan, g_time, msg);
+ return;
+ case OSMO_GSM631_SID_CLASS_VALID:
+ /* both formats require perfect, error-free SID output */
+ osmo_hr_sid_reset(msg->data);
+ break;
+ default:
+ OSMO_ASSERT(0);
+ }
+
+ /* Are we emitting "bare" TS 101 318 or "decorated" RFC 5993? */
+ if (emit_rfc5993) {
+ uint8_t toc = tch_ul_msg_sid(msg) << 4;
+ msgb_push_u8(msg, toc);
+ }
+
+ send_ul_rtp_packet(lchan, fn, msg->data, msg->len);
+}
+
+/* Helper function for l1sap_tch_ind(): SID classification and related logic
+ * for FR, HR and EFR speech codecs. */
+static void tch_ul_fr_hr_efr(struct gsm_lchan *lchan, uint32_t fn, struct msgb *msg)
+{
+ enum osmo_gsm631_sid_class sidc;
+
+ /* If we got no payload (BFI without data), there is nothing
+ * for us to do here. */
+ if (msg->len == 0)
+ return;
+
+ /* GSM 06.31, 06.41 and 06.81 are DTX specs for FR, HR and EFR,
+ * respectively. Section 6.1.1 in each of these specs defines a
+ * ternary SID classification whereby each channel-decoded traffic
+ * frame is valid SID, invalid SID or non-SID speech. Perform
+ * this classification. */
+ switch (lchan->tch_mode) {
+ case GSM48_CMODE_SPEECH_V1:
+ if (lchan->type == GSM_LCHAN_TCH_F) {
+ sidc = osmo_fr_sid_classify(msg->data);
+ } else {
+ /* None of our current BTS models has UFI or BCI
+ * error flags for TCH/HS UL Rx, hence we have to
+ * perform SID classification without BCI. */
+ sidc = osmo_hr_sid_classify(msg->data, false, NULL);
+ /* Pass it to RTP output functions */
+ tch_ul_msg_sid(msg) = sidc;
+ }
+ break;
+ case GSM48_CMODE_SPEECH_EFR:
+ sidc = osmo_efr_sid_classify(msg->data);
+ break;
+ default:
+ /* This static function should never be called except for
+ * V1 and EFR speech modes. */
+ OSMO_ASSERT(0);
+ }
+
+ /* We use this SID classification for three purposes:
+ *
+ * 1) For those users who desire to have RTP marker bit set in the
+ * output packet corresponding to the first speech frame after
+ * a DTX pause, the logic of lchan_set_marker() is driven by
+ * the determination of whether or not each received traffic frame
+ * is an accepted SID frame in the definition of GSM 06.31
+ * and its HR & EFR counterparts.
+ *
+ * 2) Next patch in the series will introduce logic that sets BFI
+ * under certain conditions dependent on SID classification and
+ * previous state, in order to suppress false indications of
+ * "valid" SID to the Rx DTX handler on the RTP receiving end
+ * during "half-block" conditions.
+ *
+ * 3) For HR codec only, RTP output format functions need to know
+ * both BFI flag and SID classification.
+ */
+ switch (sidc) {
+ case OSMO_GSM631_SID_CLASS_SPEECH:
+ /* Only a good speech frame, not an unusable frame,
+ * using GSM 06.31 definitions, marks exit from a DTX pause. */
+ if (!tch_ul_msg_bfi(msg))
+ lchan_set_marker(false, lchan);
+ break;
+ case OSMO_GSM631_SID_CLASS_INVALID:
+ case OSMO_GSM631_SID_CLASS_VALID:
+ lchan_set_marker(true, lchan);
+ break;
+ default:
+ /* There are only 3 possible SID classifications per
+ * section 6.1.1 of each of the three DTX specs,
+ * and correspondingly only 3 possible output values
+ * from osmo_*_sid_classify() functions. */
+ OSMO_ASSERT(0);
+ }
+}
+
/* TCH received from bts model */
static int l1sap_tch_ind(struct gsm_bts_trx *trx, struct osmo_phsap_prim *l1sap,
struct ph_tch_param *tch_ind)
@@ -2361,8 +2454,12 @@
(tch_ind->lqual_cb < bts->min_qual_norm))
tch_ul_msg_bfi(msg) = true;
- /* FR/HR/EFR SID classification, with potential effects on BFI flag,
- * will go here - further patches in the series. */
+ /* For FR, HR or EFR speech we also have to perform SID classification
+ * and apply logic that results from such. This logic can also set
+ * BFI that wasn't set before! */
+ if (lchan->tch_mode == GSM48_CMODE_SPEECH_V1 ||
+ lchan->tch_mode == GSM48_CMODE_SPEECH_EFR)
+ tch_ul_fr_hr_efr(lchan, fn, msg);
/* Good RTP output happens when we got some payload AND it is not
* marked as BFI. */
@@ -2386,10 +2483,8 @@
lchan->tch_mode == GSM48_CMODE_SPEECH_V1) {
/* HR codec: TS 101 318 or RFC 5993,
* will also support TW-TS-002 in the future. */
- if (bts->emit_hr_rfc5993)
- send_rtp_rfc5993(lchan, fn, msg);
- else
- send_ul_rtp_packet(lchan, fn, msg->data, msg->len);
+ send_gsmhr_std_rtp(lchan, &g_time, msg,
+ bts->emit_hr_rfc5993);
} else {
/* generic case, no RTP alterations */
send_ul_rtp_packet(lchan, fn, msg->data, msg->len);
diff --git a/src/osmo-bts-lc15/tch.c b/src/osmo-bts-lc15/tch.c
index afd5b53..048b6d3 100644
--- a/src/osmo-bts-lc15/tch.c
+++ b/src/osmo-bts-lc15/tch.c
@@ -68,8 +68,6 @@
cur = msgb_put(msg, GSM_FR_BYTES);
memcpy(cur, l1_payload, GSM_FR_BYTES);
- lchan_set_marker(osmo_fr_is_any_sid(l1_payload), lchan);
-
return msg;
}
@@ -102,8 +100,6 @@
cur = msgb_put(msg, GSM_EFR_BYTES);
memcpy(cur, l1_payload, GSM_EFR_BYTES);
- lchan_set_marker(osmo_efr_is_any_sid(l1_payload), lchan);
-
return msg;
}
@@ -134,8 +130,6 @@
cur = msgb_put(msg, GSM_HR_BYTES);
memcpy(cur, l1_payload, GSM_HR_BYTES);
- lchan_set_marker(osmo_hr_check_sid(l1_payload, payload_len), lchan);
-
return msg;
}
diff --git a/src/osmo-bts-oc2g/tch.c b/src/osmo-bts-oc2g/tch.c
index 4ea1eb6..c3f0417 100644
--- a/src/osmo-bts-oc2g/tch.c
+++ b/src/osmo-bts-oc2g/tch.c
@@ -68,8 +68,6 @@
cur = msgb_put(msg, GSM_FR_BYTES);
memcpy(cur, l1_payload, GSM_FR_BYTES);
- lchan_set_marker(osmo_fr_is_any_sid(l1_payload), lchan);
-
return msg;
}
@@ -102,8 +100,6 @@
cur = msgb_put(msg, GSM_EFR_BYTES);
memcpy(cur, l1_payload, GSM_EFR_BYTES);
- lchan_set_marker(osmo_efr_is_any_sid(l1_payload), lchan);
-
return msg;
}
@@ -134,8 +130,6 @@
cur = msgb_put(msg, GSM_HR_BYTES);
memcpy(cur, l1_payload, GSM_HR_BYTES);
- lchan_set_marker(osmo_hr_check_sid(l1_payload, payload_len), lchan);
-
return msg;
}
diff --git a/src/osmo-bts-sysmo/tch.c b/src/osmo-bts-sysmo/tch.c
index 2cf784e..b5bf04b 100644
--- a/src/osmo-bts-sysmo/tch.c
+++ b/src/osmo-bts-sysmo/tch.c
@@ -77,8 +77,6 @@
cur[0] |= 0xD0;
#endif /* USE_L1_RTP_MODE */
- lchan_set_marker(osmo_fr_is_any_sid(l1_payload), lchan);
-
return msg;
}
@@ -132,8 +130,6 @@
cur[0] |= 0xC0;
#endif /* USE_L1_RTP_MODE */
- lchan_set_marker(osmo_efr_is_any_sid(l1_payload), lchan);
-
return msg;
}
@@ -218,8 +214,6 @@
osmo_revbytebits_buf(cur, GSM_HR_BYTES);
#endif /* USE_L1_RTP_MODE */
- lchan_set_marker(osmo_hr_check_sid(l1_payload, payload_len), lchan);
-
return msg;
}
diff --git a/src/osmo-bts-trx/sched_lchan_tchf.c b/src/osmo-bts-trx/sched_lchan_tchf.c
index 5a3e80a..2403392 100644
--- a/src/osmo-bts-trx/sched_lchan_tchf.c
+++ b/src/osmo-bts-trx/sched_lchan_tchf.c
@@ -166,14 +166,10 @@
case GSM48_CMODE_SPEECH_V1: /* FR */
rc = gsm0503_tch_fr_decode(tch_data, BUFTAIL8(bursts_p),
1, 0, &n_errors, &n_bits_total);
- if (rc == GSM_FR_BYTES) /* only for valid *speech* frames */
- lchan_set_marker(osmo_fr_is_any_sid(tch_data), lchan); /* DTXu */
break;
case GSM48_CMODE_SPEECH_EFR: /* EFR */
rc = gsm0503_tch_fr_decode(tch_data, BUFTAIL8(bursts_p),
1, 1, &n_errors, &n_bits_total);
- if (rc == GSM_EFR_BYTES) /* only for valid *speech* frames */
- lchan_set_marker(osmo_efr_is_any_sid(tch_data), lchan); /* DTXu */
break;
case GSM48_CMODE_SPEECH_AMR: /* AMR */
/* the first FN 0,8,17 defines that CMI is included in frame,
diff --git a/src/osmo-bts-trx/sched_lchan_tchh.c b/src/osmo-bts-trx/sched_lchan_tchh.c
index 01ac155..5d5f246 100644
--- a/src/osmo-bts-trx/sched_lchan_tchh.c
+++ b/src/osmo-bts-trx/sched_lchan_tchh.c
@@ -232,10 +232,6 @@
rc = gsm0503_tch_hr_decode2(tch_data, BUFTAIL8(bursts_p),
!sched_tchh_ul_facch_map[bi->fn % 26],
&n_errors, &n_bits_total);
- if (rc == GSM_HR_BYTES) { /* only for valid *speech* frames */
- bool is_sid = osmo_hr_check_sid(tch_data, GSM_HR_BYTES);
- lchan_set_marker(is_sid, lchan); /* DTXu */
- }
break;
case GSM48_CMODE_SPEECH_AMR: /* AMR */
/* the first FN 0,8,17 or 1,9,18 defines that CMI is included
--
To view, visit
https://gerrit.osmocom.org/c/osmo-bts/+/41048?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: Id6c8c146962de2f173760889eb232693bb4229d3
Gerrit-Change-Number: 41048
Gerrit-PatchSet: 1
Gerrit-Owner: falconia <falcon(a)freecalypso.org>