annotate libtwamr/ietf_in.c @ 477:4c9222d95647

libtwamr encoder: always emit frame->mode = mode; In the original implementation of amr_encode_frame(), the 'mode' member of the output struct was set to 0xFF if the output frame type is TX_NO_DATA. This design was made to mimic the mode field (16-bit word) being set to 0xFFFF (or -1) in 3GPP test sequence format - but nothing actually depends on this struct member being set in any way, and amr_frame_to_tseq() generates the needed 0xFFFF on its own, based on frame->type being equal to TX_NO_DATA. It is simpler and more efficient to always set frame->mode to the actual encoding mode in amr_encode_frame(), and this new behavior has already been documented in doc/AMR-library-API description in anticipation of the present change.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 18 May 2024 22:30:42 +0000
parents ebe499058c63
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }