FreeCalypso > hg > gsm-codec-lib
view amrtest/tseq-enc.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 | cf90077b753c |
children |
line wrap: on
line source
/* * twamr-tseq-enc is a test program for our AMR encoder: it reads raw * 16-bit PCM (matching 3GPP *.inp) as input and writes 3GPP *.cod * format as output, allowing libtwamr encoder to be tested with the * official test sequences. * * Both input and output are read/written in the host machine's * native byte order. */ #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <unistd.h> #include "../libtwamr/tw_amr.h" static int read_input(inf, pcm, filename_for_errs) FILE *inf; int16_t *pcm; char *filename_for_errs; { int cc; cc = fread(pcm, 2, 160, inf); if (cc == 0) return 0; if (cc < 160) { fprintf(stderr, "warning: incomplete frame at the end of %s\n", filename_for_errs); return 0; } return 1; } main(argc, argv) char **argv; { char *infname, *outfname, *mode_arg; FILE *inf, *outf; struct amr_encoder_state *state; enum Mode mode_val; int16_t pcm[160]; struct amr_param_frame frame; uint16_t cod_words[AMR_COD_WORDS]; int opt, dtx = 0, vad2 = 0, use_mode_file = 0, rc; extern int optind; while ((opt = getopt(argc, argv, "d2")) != EOF) { switch (opt) { case 'd': dtx = 1; continue; case '2': vad2 = 1; continue; default: usage: fprintf(stderr, "usage: %s [-d] [-2] input.inp mode output.cod\n", argv[0]); exit(1); } } if (argc != optind + 3) goto usage; infname = argv[optind]; mode_arg = argv[optind+1]; outfname = argv[optind+2]; inf = fopen(infname, "r"); if (!inf) { perror(infname); exit(1); } if (!strncmp(mode_arg, "file:", 5)) { open_mode_file(mode_arg + 5); use_mode_file = 1; } else { rc = grok_mode_name(mode_arg, &mode_val); if (rc < 0) { fprintf(stderr, "error: invalid mode argument \"%s\"\n", mode_arg); exit(1); } } outf = fopen(outfname, "w"); if (!outf) { perror(outfname); exit(1); } state = amr_encoder_create(dtx, vad2); if (!state) { perror("amr_encoder_create()"); exit(1); } for (;;) { rc = read_input(inf, pcm, infname); if (!rc) break; if (use_mode_file) read_mode_file_line(&mode_val); amr_encode_frame(state, mode_val, pcm, &frame); amr_frame_to_tseq(&frame, cod_words); fwrite(cod_words, 2, AMR_COD_WORDS, outf); } fclose(outf); exit(0); }