annotate amrtest/mode_file.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 1ceda5586d01
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The functions in this module implement reading per-frame encoder mode
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * instructions from a file, as in 3GPP test sequences and code.
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "../libtwamr/tw_amr.h"
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static FILE *mode_file;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 static int lineno;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 static char *filename_for_errs;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 void
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 open_mode_file(filename)
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *filename;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 mode_file = fopen(filename, "r");
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (!mode_file) {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 perror(filename);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 exit(1);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 void
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 read_mode_file_line(mode_out)
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 enum Mode *mode_out;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 char linebuf[16], *cp;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int rc;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (!fgets(linebuf, sizeof linebuf, mode_file)) {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fprintf(stderr, "error: %s ends before speech input\n",
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 filename_for_errs);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 lineno++;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 cp = index(linebuf, '\n');
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (!cp) {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(stderr, "%s line %d: too long or missing newline\n",
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 filename_for_errs, lineno);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 exit(1);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (cp > linebuf && cp[-1] == '\r')
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 cp--;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *cp = '\0';
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 rc = grok_mode_name(linebuf, mode_out);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (rc < 0) {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 fprintf(stderr, "%s line %d: invalid mode setting\n",
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 filename_for_errs, lineno);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 exit(1);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }