annotate hrutil/read-cod.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 bb36ef735f25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
515
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement the utility function for reading ETSI
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * GSM-HR *.cod files in either LE or BE format.
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../libgsmhr1/tw_gsmhr.h"
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 read_cod_frame(inf, big_endian, params, filename_for_errs, frame_no)
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 FILE *inf;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int16_t *params;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char *filename_for_errs;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 unsigned frame_no;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 uint8_t file_bytes[GSMHR_NUM_PARAMS_ENC * 2], *sp;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int cc;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 unsigned n;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 uint16_t val;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cc = fread(file_bytes, 2, GSMHR_NUM_PARAMS_ENC, inf);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (cc == 0)
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return 0;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (cc != GSMHR_NUM_PARAMS_ENC) {
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 fprintf(stderr, "error: short read from %s\n",
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 filename_for_errs);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 sp = file_bytes;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 for (n = 0; n < GSMHR_NUM_PARAMS_ENC; n++) {
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (big_endian)
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 val = ((uint16_t) sp[0] << 8) | ((uint16_t) sp[1]);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 else
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 val = ((uint16_t) sp[1] << 8) | ((uint16_t) sp[0]);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 params[n] = val;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 sp += 2;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (gsmhr_check_encoder_params(params) < 0) {
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 fprintf(stderr,
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 "error in %s frame #%u: wrong format or wrong endian\n",
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 filename_for_errs, frame_no);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return 1;
bb36ef735f25 hrutil: starting with gsmhr-cod-parse
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }