FreeCalypso > hg > gsm-codec-lib
annotate hrutil/cod2hex.c @ 585:3c6bf0d26ee7 default tip
TW-TS-005 reader: fix maximum line length bug
TW-TS-005 section 4.1 states:
The maximum allowed length of each line is 80 characters, not
including the OS-specific newline encoding.
The implementation of this line length limit in the TW-TS-005 hex file
reader function in the present suite was wrong, such that lines of
the full maximum length could not be read. Fix it.
Note that this bug affects comment lines too, not just actual RTP
payloads. Neither Annex A nor Annex B features an RTP payload format
that goes to the maximum of 40 bytes, but if a comment line goes to
the maximum allowed length of 80 characters not including the
terminating newline, the bug will be triggered, necessitating
the present fix.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 25 Feb 2025 07:49:28 +0000 |
parents | cf62fe9fac3a |
children |
rev | line source |
---|---|
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads an HRv1 *.cod file in ETSI test sequence format |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * (encoder output format) and converts it into TW-TS-005 Annex B |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * hexadecimal format. |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <unistd.h> |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../libgsmhr1/tw_gsmhr.h" |
561
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
14 #include "../libtest/local_endian.h" |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 main(argc, argv) |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char **argv; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char *infname, *outfname; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 FILE *inf, *outf; |
561
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
21 int opt, rc, big_endian, emit_5993 = 0; |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 unsigned frame_no; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int16_t params[GSMHR_NUM_PARAMS_ENC]; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 extern int optind; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
561
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
26 big_endian = is_native_big_endian(); |
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
27 while ((opt = getopt(argc, argv, "blx")) != EOF) { |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 switch (opt) { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 case 'b': |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 big_endian = 1; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 continue; |
561
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
32 case 'l': |
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
33 big_endian = 0; |
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
34 continue; |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 case 'x': |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 emit_5993 = 1; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 continue; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 default: |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 usage: |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 fprintf(stderr, |
561
cf62fe9fac3a
gsmhr-cod2hex: read native endian by default
Mychaela Falconia <falcon@freecalypso.org>
parents:
557
diff
changeset
|
41 "usage: %s [-b|-l] [-x] input.cod output.hex\n", |
557
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 argv[0]); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 exit(1); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (argc != optind + 2) |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 goto usage; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 infname = argv[optind]; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 outfname = argv[optind+1]; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 inf = fopen(infname, "r"); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!inf) { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 perror(infname); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 outf = fopen(outfname, "w"); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (!outf) { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 perror(outfname); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 exit(1); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 for (frame_no = 0; ; frame_no++) { |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 rc = read_cod_frame(inf, big_endian, params, infname, frame_no); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (!rc) |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 break; |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 emit_cod_to_tw5b(outf, params, emit_5993); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 exit(0); |
129c895a0564
hrutil: new program gsmhr-cod2hex
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |