changeset 542:f2d0f2f15d5f

libgsmefr: add wrapper for TW-TS-001 RTP input
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 28 Sep 2024 06:38:08 +0000
parents 23656d874524
children 53d3f48af107
files libgsmefr/Makefile libgsmefr/dec_rtp_in.c libgsmefr/gsm_efr.h
diffstat 3 files changed, 57 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libgsmefr/Makefile	Sat Sep 28 06:00:34 2024 +0000
+++ b/libgsmefr/Makefile	Sat Sep 28 06:38:08 2024 +0000
@@ -1,13 +1,13 @@
 OBJS=	agc.o autocorr.o az_lsp.o basicops.o bfi_nodata.o c1035pf.o cod_12k2.o \
 	convolve.o d1035pf.o d_gains.o d_homing.o d_plsf_5.o dec_12k2.o \
-	dec_create.o dec_lag6.o dec_main.o dec_wrap.o dhf.o dtx_common.o \
-	dtx_dec.o dtx_enc.o e_homing.o enc_create.o enc_lag6.o enc_main.o \
-	enc_wrap.o frame2params.o g_code.o g_pitch.o int_lpc.o inter_6.o \
-	inv_sqrt.o lag_wind.o levinson.o log2.o lsp_az.o lsp_lsf.o oper_32b.o \
-	params2frame.o pitch_f6.o pitch_ol.o pow2.o pre_proc.o pred_lt6.o \
-	preemph.o pstfilt2.o q_gains.o q_plsf5_tab.o q_plsf_5.o reorder.o \
-	residu.o sid_class.o sid_insert.o syn_filt.o tls_flags.o vad.o \
-	weight_a.o
+	dec_create.o dec_lag6.o dec_main.o dec_rtp_in.o dec_wrap.o dhf.o \
+	dtx_common.o dtx_dec.o dtx_enc.o e_homing.o enc_create.o enc_lag6.o \
+	enc_main.o enc_wrap.o frame2params.o g_code.o g_pitch.o int_lpc.o \
+	inter_6.o inv_sqrt.o lag_wind.o levinson.o log2.o lsp_az.o lsp_lsf.o \
+	oper_32b.o params2frame.o pitch_f6.o pitch_ol.o pow2.o pre_proc.o \
+	pred_lt6.o preemph.o pstfilt2.o q_gains.o q_plsf5_tab.o q_plsf_5.o \
+	reorder.o residu.o sid_class.o sid_insert.o syn_filt.o tls_flags.o \
+	vad.o weight_a.o
 HDRS=	basic_op.h cnst.h codec.h d_homing.h dec_state.h dtx.h dtx_defs.h \
 	e_homing.h enc_state.h gains_tb.h gsm_efr.h memops.h namespace.h \
 	no_count.h oper_32b.h q_plsf5_tab.h sig_proc.h typedef.h vad.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmefr/dec_rtp_in.c	Sat Sep 28 06:38:08 2024 +0000
@@ -0,0 +1,47 @@
+/*
+ * This module implements a wrapper around the main processing functions
+ * of our full decoder, handling RTP input per TW-TS-001.
+ */
+
+#include <stdint.h>
+#include "gsm_efr.h"
+
+int EFR_decode_rtp(struct EFR_decoder_state *st, const uint8_t *rtp_pl,
+		   unsigned rtp_pl_len, int16_t *pcm)
+{
+	switch (rtp_pl_len) {
+	case 0:
+		/* BFI-no-data, but not an invalid RTP input per se */
+		EFR_decode_bfi_nodata(st, 0, pcm);
+		return 0;
+	case 1:
+		if ((rtp_pl[0] & 0xF6) != 0xE6)
+			goto bad_rtp_input;
+		/* TW-TS-001 No_Data frame */
+		EFR_decode_bfi_nodata(st, rtp_pl[0] & 1, pcm);
+		return 0;
+	case EFR_RTP_FRAME_LEN:
+		if ((rtp_pl[0] & 0xF0) != 0xC0)
+			goto bad_rtp_input;
+		/* basic RTP format */
+		EFR_decode_frame(st, rtp_pl, 0, 0, pcm);
+		return 0;
+	case EFR_RTP_FRAME_LEN+1:
+		if ((rtp_pl[0] & 0xF4) != 0xE0)
+			goto bad_rtp_input;
+		if ((rtp_pl[1] & 0xF0) != 0xC0)
+			goto bad_rtp_input;
+		/* extended RTP format (TW-TS-001) */
+		EFR_decode_frame(st, rtp_pl + 1, (rtp_pl[0] & 2) >> 1,
+				 rtp_pl[0] & 1, pcm);
+		return 0;
+	default:
+	bad_rtp_input:
+		/*
+		 * Treat it like BFI-no-data, and tell the caller
+		 * that we received an invalid RTP payload.
+		 */
+		EFR_decode_bfi_nodata(st, 0, pcm);
+		return -1;
+	}
+}
--- a/libgsmefr/gsm_efr.h	Sat Sep 28 06:00:34 2024 +0000
+++ b/libgsmefr/gsm_efr.h	Sat Sep 28 06:38:08 2024 +0000
@@ -43,6 +43,8 @@
 			     int bfi, int taf, int16_t *pcm);
 extern void EFR_decode_bfi_nodata(struct EFR_decoder_state *st, int taf,
 				  int16_t *pcm);
+extern int EFR_decode_rtp(struct EFR_decoder_state *st, const uint8_t *rtp_pl,
+			  unsigned rtp_pl_len, int16_t *pcm);
 
 /* stateless utility functions */