laforge has submitted this change. ( https://gerrit.osmocom.org/c/gapk/+/32094 )
Change subject: fmt_rtp_amr,fmt_rtp_efr: replace damaged packets with silence ......................................................................
fmt_rtp_amr,fmt_rtp_efr: replace damaged packets with silence
Change-Id: I7245aa0bc0955cc8b94d5401a15e694f50498093 --- M src/fmt_rtp_amr.c M src/fmt_rtp_efr.c 2 files changed, 32 insertions(+), 0 deletions(-)
Approvals: Jenkins Builder: Verified pespin: Looks good to me, but someone else must approve laforge: Looks good to me, approved
diff --git a/src/fmt_rtp_amr.c b/src/fmt_rtp_amr.c index a6a3c9f..4982c83 100644 --- a/src/fmt_rtp_amr.c +++ b/src/fmt_rtp_amr.c @@ -27,6 +27,9 @@ #include <osmocom/gapk/formats.h> #include <osmocom/gapk/utils.h>
+/* AMR SID frame is according to TS 126 101 4.2.3 */ +static const uint8_t SILENCE[] = {0x80, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}; + /* conversion function: RTP payload -> canonical format */ static int rtp_amr_from_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len) @@ -42,6 +45,12 @@ static int rtp_amr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len) { + /* Detect severely damaged frames according to RFC4867 4.3.2 */ + if ((src[1] & 0x04) == 0) { + src = SILENCE; + src_len = sizeof(SILENCE); + } + /* skip Payload Header according to RFC4867 4.4.1 */ memcpy(dst, src+1, src_len-1);
diff --git a/src/fmt_rtp_efr.c b/src/fmt_rtp_efr.c index 7afb1a3..214010e 100644 --- a/src/fmt_rtp_efr.c +++ b/src/fmt_rtp_efr.c @@ -30,6 +30,17 @@ #define EFR_LEN 31 #define EFR_MAGIC 0xc
+/* EFR encoding starts with 0xc, if all other bits are 0 the packet is probably damaged */ +static const uint8_t DAMAGED_PACKET[EFR_LEN] = { + 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +/* EFR SID frame is according to TS 101 318 5.3.2 */ +static const uint8_t SILENCE[EFR_LEN] = { + 0xcf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + /* conversion function: RTP payload -> canonical format */ static int rtp_efr_from_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len) @@ -58,6 +69,9 @@ return EFR_CANON_LEN; }
+ if (!memcmp(DAMAGED_PACKET, src, EFR_LEN)) + src = SILENCE; + for (i=0; i<(EFR_LEN-1); i++) dst[i] = (src[i] << 4) | (src[i+1] >> 4); dst[EFR_LEN-1] = src[EFR_LEN-1] << 4;