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