annotate libgsmhr1/rtp_in_direct.c @ 522:4d2cccaeb4a7

libtest: implement TW-TS-005 reader function Spec reference: https://www.freecalypso.org/specs/tw-ts-005-v010002.txt
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Sep 2024 03:08:47 +0000
parents 5bf71b091323
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (ft == 1 || ft == 7) {
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 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
44 return 0;
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 } else
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 goto bad_rtp_input;
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 case GSMHR_FRAME_LEN_RPF:
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 /*
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 * 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
50 * 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
51 * 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
52 * 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
53 * (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
54 * 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
55 */
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 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
57 params[18] = 0; /* BFI */
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 params[19] = 0; /* UFI */
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 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
60 params[21] = 0; /* TAF */
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return 0;
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 case GSMHR_FRAME_LEN_5993:
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 /*
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 * 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
65 * 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
66 */
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (rtp_in[0] & 0x80)
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 goto bad_rtp_input;
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 ft = rtp_in[0] >> 4;
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (ft == 0 || ft == 2 || ft == 6) {
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 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
72 return 0;
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 } else
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 default:
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 bad_rtp_input:
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 /*
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 * 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
79 * 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
80 */
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 emit_bfi_nodata(params);
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 return -1;
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
5bf71b091323 libgsmhr1: add direct conversion from RTP input to decoder params
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }