From 1cb59f0b0f7bb38c446d40ae68cad91ec33cca25 Mon Sep 17 00:00:00 2001 From: Martijn van Beurden Date: Wed, 16 Nov 2022 20:42:17 +0100 Subject: [PATCH] Move bitreader_dump and bitwriter_dump functions to test_libFLAC --- src/libFLAC/bitreader.c | 30 ---------------------- src/libFLAC/bitwriter.c | 24 ------------------ src/libFLAC/include/private/bitreader.h | 1 - src/libFLAC/include/private/bitwriter.h | 1 - src/test_libFLAC/bitreader.c | 33 +++++++++++++++++++++++++ src/test_libFLAC/bitwriter.c | 23 +++++++++++++++++ 6 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/libFLAC/bitreader.c b/src/libFLAC/bitreader.c index 9a8a5f02..56f992e4 100644 --- a/src/libFLAC/bitreader.c +++ b/src/libFLAC/bitreader.c @@ -346,36 +346,6 @@ FLAC__bool FLAC__bitreader_rewind_to_after_last_seen_framesync(FLAC__BitReader * } } -void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out) -{ - uint32_t i, j; - if(br == 0) { - fprintf(out, "bitreader is NULL\n"); - } - else { - fprintf(out, "bitreader: capacity=%u words=%u bytes=%u consumed: words=%u, bits=%u\n", br->capacity, br->words, br->bytes, br->consumed_words, br->consumed_bits); - - for(i = 0; i < br->words; i++) { - fprintf(out, "%08X: ", i); - for(j = 0; j < FLAC__BITS_PER_WORD; j++) - if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits)) - fprintf(out, "."); - else - fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0); - fprintf(out, "\n"); - } - if(br->bytes > 0) { - fprintf(out, "%08X: ", i); - for(j = 0; j < br->bytes*8; j++) - if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits)) - fprintf(out, "."); - else - fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (br->bytes*8-j-1)) ? 1:0); - fprintf(out, "\n"); - } - } -} - void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed) { FLAC__ASSERT(0 != br); diff --git a/src/libFLAC/bitwriter.c b/src/libFLAC/bitwriter.c index 66a7e616..d6c6c76c 100644 --- a/src/libFLAC/bitwriter.c +++ b/src/libFLAC/bitwriter.c @@ -198,30 +198,6 @@ void FLAC__bitwriter_clear(FLAC__BitWriter *bw) bw->words = bw->bits = 0; } -void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out) -{ - uint32_t i, j; - if(bw == 0) { - fprintf(out, "bitwriter is NULL\n"); - } - else { - fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw)); - - for(i = 0; i < bw->words; i++) { - fprintf(out, "%08X: ", i); - for(j = 0; j < FLAC__BITS_PER_WORD; j++) - fprintf(out, "%01d", bw->buffer[i] & ((bwword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0); - fprintf(out, "\n"); - } - if(bw->bits > 0) { - fprintf(out, "%08X: ", i); - for(j = 0; j < bw->bits; j++) - fprintf(out, "%01d", bw->accum & ((bwword)1 << (bw->bits-j-1)) ? 1:0); - fprintf(out, "\n"); - } - } -} - FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc) { const FLAC__byte *buffer; diff --git a/src/libFLAC/include/private/bitreader.h b/src/libFLAC/include/private/bitreader.h index 694cefc6..2943a955 100644 --- a/src/libFLAC/include/private/bitreader.h +++ b/src/libFLAC/include/private/bitreader.h @@ -55,7 +55,6 @@ void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */ FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br); void FLAC__bitreader_set_framesync_location(FLAC__BitReader *br); FLAC__bool FLAC__bitreader_rewind_to_after_last_seen_framesync(FLAC__BitReader *br); -void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out); /* * CRC functions diff --git a/src/libFLAC/include/private/bitwriter.h b/src/libFLAC/include/private/bitwriter.h index 38f68b04..bb2c5c11 100644 --- a/src/libFLAC/include/private/bitwriter.h +++ b/src/libFLAC/include/private/bitwriter.h @@ -50,7 +50,6 @@ void FLAC__bitwriter_delete(FLAC__BitWriter *bw); FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw); void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */ void FLAC__bitwriter_clear(FLAC__BitWriter *bw); -void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out); /* * CRC functions diff --git a/src/test_libFLAC/bitreader.c b/src/test_libFLAC/bitreader.c index 49af1caa..bae98675 100644 --- a/src/test_libFLAC/bitreader.c +++ b/src/test_libFLAC/bitreader.c @@ -59,12 +59,45 @@ struct FLAC__BitReader { uint32_t read_crc16; /* the running frame CRC */ uint32_t crc16_offset; /* the number of words in the current buffer that should not be CRC'd */ uint32_t crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */ + FLAC__bool read_limit_set; /* whether reads are limited */ + uint32_t read_limit; /* the remaining size of what can be read */ + uint32_t last_seen_framesync; /* the location of the last seen framesync, if it is in the buffer, in bits from front of buffer */ FLAC__BitReaderReadCallback read_callback; void *client_data; }; static FLAC__bool read_callback(FLAC__byte buffer[], size_t *bytes, void *data); +static void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out) +{ + uint32_t i, j; + if(br == 0) { + fprintf(out, "bitreader is NULL\n"); + } + else { + fprintf(out, "bitreader: capacity=%u words=%u bytes=%u consumed: words=%u, bits=%u\n", br->capacity, br->words, br->bytes, br->consumed_words, br->consumed_bits); + + for(i = 0; i < br->words; i++) { + fprintf(out, "%08X: ", i); + for(j = 0; j < FLAC__BITS_PER_WORD; j++) + if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits)) + fprintf(out, "."); + else + fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0); + fprintf(out, "\n"); + } + if(br->bytes > 0) { + fprintf(out, "%08X: ", i); + for(j = 0; j < br->bytes*8; j++) + if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits)) + fprintf(out, "."); + else + fprintf(out, "%01d", br->buffer[i] & ((brword)1 << (br->bytes*8-j-1)) ? 1:0); + fprintf(out, "\n"); + } + } +} + FLAC__bool test_bitreader(void) { FLAC__BitReader *br; diff --git a/src/test_libFLAC/bitwriter.c b/src/test_libFLAC/bitwriter.c index 1bda5e02..f3466139 100644 --- a/src/test_libFLAC/bitwriter.c +++ b/src/test_libFLAC/bitwriter.c @@ -60,6 +60,29 @@ struct FLAC__BitWriter { #define WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD) #define TOTAL_BITS(bw) (WORDS_TO_BITS((bw)->words) + (bw)->bits) +static void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out) +{ + uint32_t i, j; + if(bw == 0) { + fprintf(out, "bitwriter is NULL\n"); + } + else { + fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, TOTAL_BITS(bw)); + + for(i = 0; i < bw->words; i++) { + fprintf(out, "%08X: ", i); + for(j = 0; j < FLAC__BITS_PER_WORD; j++) + fprintf(out, "%01d", bw->buffer[i] & ((bwword)1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0); + fprintf(out, "\n"); + } + if(bw->bits > 0) { + fprintf(out, "%08X: ", i); + for(j = 0; j < bw->bits; j++) + fprintf(out, "%01d", bw->accum & ((bwword)1 << (bw->bits-j-1)) ? 1:0); + fprintf(out, "\n"); + } + } +} FLAC__bool test_bitwriter(void) {