fmt_rtp_amr,fmt_rtp_efr: replace damaged packets with silence

Change-Id: I7245aa0bc0955cc8b94d5401a15e694f50498093
This commit is contained in:
Matan Perelman 2023-03-28 08:32:17 +03:00
parent 166a189c4f
commit e00ac3b227
2 changed files with 23 additions and 0 deletions

View File

@ -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 @@ rtp_amr_from_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
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);

View File

@ -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 @@ rtp_efr_to_canon(uint8_t *dst, const uint8_t *src, unsigned int src_len)
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;