FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/ietf_in.c @ 550:de333989a12b
document gsm[e]fr-decode-tw5[-r] utilities
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Oct 2024 02:16:48 +0000 |
parents | ebe499058c63 |
children |
rev | line source |
---|---|
441
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The function implemented in this module is responsible for parsing |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * an incoming RFC 4867 payload and turning it into struct amr_param_frame |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * for decoding. |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "tw_amr.h" |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "typedef.h" |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "namespace.h" |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "cnst.h" |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "int_defs.h" |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "if1_func.h" |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int amr_frame_from_ietf(const uint8_t *bytes, struct amr_param_frame *frame) |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 Word16 ft, q, sti; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 Word16 serial[MAX_SERIAL_SIZE]; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 ft = (bytes[0] & 0x78) >> 3; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 q = (bytes[0] & 0x04) >> 2; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (ft == AMR_FT_NODATA) { |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 frame->type = RX_NO_DATA; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 frame->mode = 0xFF; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return 0; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (ft > MRDTX) |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return -1; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if1_unpack_bytes(ft, bytes + 1, serial); |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 Bits2prm(ft, serial, frame->param); |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (ft != MRDTX) { |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 frame->type = q ? RX_SPEECH_GOOD : RX_SPEECH_BAD; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 frame->mode = ft; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } else { |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 sti = (bytes[5] & 0x10) >> 4; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 frame->mode = 0; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (bytes[5] & 0x08) |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 frame->mode |= 1; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (bytes[5] & 0x04) |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 frame->mode |= 2; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (bytes[5] & 0x02) |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 frame->mode |= 4; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (q) |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 frame->type = sti ? RX_SID_UPDATE : RX_SID_FIRST; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 else |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 frame->type = RX_SID_BAD; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return 0; |
ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |