comparison libgsmfr2/tfo_main.c @ 531:c7b1e796e91b

libgsmfr2 TFO: implement main entry point function
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Sep 2024 20:35:10 +0000
parents libgsmfr2/full_dec_wrap.c@f681fb758041
children
comparison
equal deleted inserted replaced
530:96c4ed5529bf 531:c7b1e796e91b
1 /*
2 * This module implements a wrapper around the main processing functions
3 * of our Rx DTX or TFO preprocessor, handling RTP input per TW-TS-001.
4 */
5
6 #include <stdint.h>
7 #include <string.h>
8 #include "tw_gsmfr.h"
9
10 int gsmfr_tfo_xfrm_main(struct gsmfr_preproc_state *st, const uint8_t *rtp_pl,
11 unsigned rtp_pl_len, uint8_t *out)
12 {
13 switch (rtp_pl_len) {
14 case 0:
15 /* BFI-no-data, but not an invalid RTP input per se */
16 gsmfr_preproc_bfi(st, 0, out);
17 return 0;
18 case 1:
19 if ((rtp_pl[0] & 0xF6) != 0xE6)
20 goto bad_rtp_input;
21 /* TW-TS-001 No_Data frame */
22 gsmfr_preproc_bfi(st, rtp_pl[0] & 1, out);
23 return 0;
24 case GSMFR_RTP_FRAME_LEN:
25 if ((rtp_pl[0] & 0xF0) != 0xD0)
26 goto bad_rtp_input;
27 /* basic RTP format */
28 memcpy(out, rtp_pl, GSMFR_RTP_FRAME_LEN);
29 gsmfr_preproc_good_frame_hm(st, out);
30 return 0;
31 case GSMFR_RTP_FRAME_LEN+1:
32 if ((rtp_pl[0] & 0xF4) != 0xE0)
33 goto bad_rtp_input;
34 if ((rtp_pl[1] & 0xF0) != 0xD0)
35 goto bad_rtp_input;
36 /* extended RTP format (TW-TS-001) */
37 if (rtp_pl[0] & 0x02)
38 gsmfr_preproc_bfi_bits(st, rtp_pl + 1, rtp_pl[0] & 1,
39 out);
40 else {
41 memcpy(out, rtp_pl + 1, GSMFR_RTP_FRAME_LEN);
42 gsmfr_preproc_good_frame_hm(st, out);
43 }
44 return 0;
45 default:
46 bad_rtp_input:
47 /*
48 * Treat it like BFI-no-data, and tell the caller
49 * that we received an invalid RTP payload.
50 */
51 gsmfr_preproc_bfi(st, 0, out);
52 return -1;
53 }
54 }