FreeCalypso > hg > gsm-codec-lib
annotate libgsmhr1/rtp_in_direct.c @ 587:7bce90c844c2 default tip
tw5b-dump: support verbose invalid SID per TW-TS-002 v1.2.0
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Mar 2025 20:38:23 +0000 |
parents | b21ea4ab586d |
children |
rev | line source |
---|---|
510
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The function implemented in this module takes whatever HRv1 payload format |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * came in from RTP (can be RFC 5993 with or without TW-TS-002 extensions, |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * can be bare TS 101 318, can be zero-length or missing payload) and turns it |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * into the internal input form for the HRv1 decoder. It is logically |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * equivalent to calling gsmhr_rtp_in_preen() followed by |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * gsmhr_decoder_twts002_in(), but is more efficient by avoiding the extra |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * intermediate buffer and copying. |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdint.h> |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <string.h> |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "tw_gsmhr.h" |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static void emit_bfi_nodata(int16_t *params) |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 memset(params, 0, sizeof(int16_t) * GSMHR_NUM_PARAMS); |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 params[18] = 2; /* BFI with no data */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 params[19] = 0; /* UFI */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 params[20] = 0; /* SID */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 params[21] = 0; /* TAF */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 } |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 int gsmhr_rtp_in_direct(const uint8_t *rtp_in, unsigned rtp_in_len, |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int16_t *params) |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 int ft; |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 switch (rtp_in_len) { |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 case 0: |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 /* BFI-no-data, but not an invalid RTP input per se */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 emit_bfi_nodata(params); |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return 0; |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 case 1: |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 /* |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 * This length is valid only if the payload is in |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 * RFC 5993 or TW-TS-002 format with FT=1 or FT=7. |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (rtp_in[0] & 0x80) |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 goto bad_rtp_input; |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 ft = rtp_in[0] >> 4; |
586
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
42 switch (ft) { |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
43 case 1: |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
44 if (rtp_in[0] & 0x04) |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
45 goto bad_rtp_input; |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
46 /* FALL THRU */ |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
47 case 7: |
510
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 gsmhr_decoder_twts002_in(rtp_in, params); |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return 0; |
586
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
50 default: |
510
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 goto bad_rtp_input; |
586
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
52 } |
510
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 case GSMHR_FRAME_LEN_RPF: |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 /* |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 * The length is that of a TS 101 318 payload. |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 * No further checks can be done: every possible |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 * bit pattern is a valid payload in this format. |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 * But we do need to check for a perfect SID |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 * (the only kind of SID this format allows) |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 * and mark it accordingly in the output. |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 gsmhr_unpack_ts101318(rtp_in, params); |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 params[18] = 0; /* BFI */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 params[19] = 0; /* UFI */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 params[20] = gsmhr_ts101318_is_perfect_sid(rtp_in); |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 params[21] = 0; /* TAF */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 return 0; |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 case GSMHR_FRAME_LEN_5993: |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 /* |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 * This length is valid only if the payload is in |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 * RFC 5993 or TW-TS-002 format with FT=0, FT=2 or FT=6. |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (rtp_in[0] & 0x80) |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 goto bad_rtp_input; |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 ft = rtp_in[0] >> 4; |
586
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
76 switch (ft) { |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
77 case 1: |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
78 if (!(rtp_in[0] & 0x04)) |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
79 goto bad_rtp_input; |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
80 /* FALL THRU */ |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
81 case 0: |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
82 case 2: |
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
83 case 6: |
510
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 gsmhr_decoder_twts002_in(rtp_in, params); |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 return 0; |
586
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
86 default: |
510
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 goto bad_rtp_input; |
586
b21ea4ab586d
libgsmhr1: update for TW-TS-002 version 1.2.0
Mychaela Falconia <falcon@freecalypso.org>
parents:
510
diff
changeset
|
88 } |
510
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 default: |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 bad_rtp_input: |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 /* |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 * Treat it like BFI-no-data, and tell the caller |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 * that we received an invalid RTP payload. |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 */ |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 emit_bfi_nodata(params); |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 return -1; |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
5bf71b091323
libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |