# HG changeset patch # User Mychaela Falconia # Date 1668902262 0 # Node ID 820d88b979249a089ce51a5bb06c10965f271c82 # Parent 4229247843c0bf4c24ba4e4f63960066691076d3 libtest: implement binary file reader diff -r 4229247843c0 -r 820d88b97924 doc/Binary-file-format --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/Binary-file-format Sat Nov 19 23:57:42 2022 +0000 @@ -0,0 +1,21 @@ +We (Themyscira Wireless) define our own binary file format for testing of GSM +06.10 (FR) and EFR codec functions; this format of ours is an extension of +classic .gsm format from libgsm/toast. The original libgsm file format is a +directly abutted sequence of 33-byte libgsm frames, equivalent to RTP frames +for GSM FR, with the upper nibble of the first byte in each frame equal to 0xD, +serving as a signature. We simply extend this idea: our version is still a +directly abutted sequence of binary records, but each record is now one of 3 +possibilities: + +- a 33-byte GSM FR frame in libgsm/RTP format, 0xD signature +- a 31-byte GSM EFR frame in RTP format (ETSI TS 101 318), 0xC signature +- a 2-byte Themyscira-extension BFI marker, 0xBF signature + +File reading functions begin by reading only one byte; this byte, once decoded, +tells us how many more bytes need to be read, and frame synchronization is thus +maintained. + +FR and EFR frames are not expected to be mixed in the same stream recording; +our low-level binary file reading function will grok such mixing just fine, but +each higher-level test program is expected to be written for only one codec, +either FR or EFR. diff -r 4229247843c0 -r 820d88b97924 libtest/Makefile --- a/libtest/Makefile Sat Nov 19 23:09:44 2022 +0000 +++ b/libtest/Makefile Sat Nov 19 23:57:42 2022 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= wavreader.o wavwriter.o +OBJS= binreader.o wavreader.o wavwriter.o LIB= libtest.a all: ${LIB} diff -r 4229247843c0 -r 820d88b97924 libtest/binreader.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtest/binreader.c Sat Nov 19 23:57:42 2022 +0000 @@ -0,0 +1,29 @@ +/* + * Here we implement our binfile_read_frame() function. + */ + +#include +#include +#include "binreader.h" + +int binfile_read_frame(FILE *binf, uint8_t *frame) +{ + int cc, morelen; + + cc = fread(frame, 1, 1, binf); + if (cc != 1) + return 0; + if (frame[0] == 0xBF) + morelen = 1; + else if ((frame[0] & 0xF0) == 0xC0) + morelen = 30; + else if ((frame[0] & 0xF0) == 0xD0) + morelen = 32; + else + return -1; + cc = fread(frame+1, 1, morelen, binf); + if (cc == morelen) + return 1; + else + return -2; +} diff -r 4229247843c0 -r 820d88b97924 libtest/binreader.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtest/binreader.h Sat Nov 19 23:57:42 2022 +0000 @@ -0,0 +1,14 @@ +/* + * This header file defines the interface to our reader function for binary + * files recording GSM FR or EFR streams, see ../doc/Binary-file-format. + * + * binfile_read_frame() return values are: + * 1 = successfully read valid frame + * 0 = normal EOF + * -1 = unrecognized header byte + * -2 = EOF in the middle of a frame + */ + +#define BINFILE_MAX_FRAME 33 + +extern int binfile_read_frame(FILE *binf, uint8_t *frame);