diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-02-17 20:16:12 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-02-17 20:16:12 +0100 |
commit | ce5773ca73462a9319c16d0afc692eb38e35af8d (patch) | |
tree | 5725cb73db488bcc82ef287b388f169df02224a8 /libtoolame-dab/bitstream.c | |
parent | 5671aa4f0f5536de2fc58b6f89f01947f4f8f1c1 (diff) | |
download | fdk-aac-ce5773ca73462a9319c16d0afc692eb38e35af8d.tar.gz fdk-aac-ce5773ca73462a9319c16d0afc692eb38e35af8d.tar.bz2 fdk-aac-ce5773ca73462a9319c16d0afc692eb38e35af8d.zip |
Many libtoolame-dab fixes, at least filesize is right now
Diffstat (limited to 'libtoolame-dab/bitstream.c')
-rw-r--r-- | libtoolame-dab/bitstream.c | 79 |
1 files changed, 12 insertions, 67 deletions
diff --git a/libtoolame-dab/bitstream.c b/libtoolame-dab/bitstream.c index 410ef5b..d426ffc 100644 --- a/libtoolame-dab/bitstream.c +++ b/libtoolame-dab/bitstream.c @@ -42,89 +42,35 @@ /* in conformity of the norme ETS 300 401 http://www.etsi.org */ /* see toollame.c */ int minimum = MINIMUM; -int refill_buffer (Bit_stream_struc * bs) -{ - register int i = bs->buf_size - 2 - bs->buf_byte_idx; - register unsigned long n = 1; - register int index = 0; - char val[2]; - - while ((i >= 0) && (!bs->eob)) { - - if (bs->format == BINARY) - n = fread (&bs->buf[i--], sizeof (unsigned char), 1, bs->pt); - - else { - while ((index < 2) && n) { - n = fread (&val[index], sizeof (char), 1, bs->pt); - switch (val[index]) { - case 0x30: - case 0x31: - case 0x32: - case 0x33: - case 0x34: - case 0x35: - case 0x36: - case 0x37: - case 0x38: - case 0x39: - case 0x41: - case 0x42: - case 0x43: - case 0x44: - case 0x45: - case 0x46: - index++; - break; - default: - break; - } - } - - if (val[0] <= 0x39) - bs->buf[i] = (val[0] - 0x30) << 4; - else - bs->buf[i] = (val[0] - 0x37) << 4; - if (val[1] <= 0x39) - bs->buf[i--] |= (val[1] - 0x30); - else - bs->buf[i--] |= (val[1] - 0x37); - index = 0; - } - - if (!n) { - bs->eob = i + 1; - } - - } - return 0; -} /* empty the buffer to the output device when the buffer becomes full */ void empty_buffer (Bit_stream_struc * bs, int minimum) { - int i; - - if (bs->pt) { - for (i = bs->buf_size - 1; i >= minimum; i--) - fwrite (&bs->buf[i], sizeof (unsigned char), 1, bs->pt); + int j = 0; + for (int i = bs->buf_size - 1; i >= minimum; i--) { + if (j >= bs->output_buffer_size) { + fprintf(stderr, "Warning: libtoolame output buffer too small (%d vs %d)!\n", + bs->output_buffer_size, bs->buf_size - minimum); + break; + } - fflush (bs->pt); /* NEW SS to assist in debugging */ + bs->output_buffer[j] = bs->buf[i]; + j++; } + bs->output_buffer_written = j; - for (i = minimum - 1; i >= 0; i--) + for (int i = minimum - 1; i >= 0; i--) { bs->buf[bs->buf_size - minimum + i] = bs->buf[i]; + } bs->buf_byte_idx = bs->buf_size - 1 - minimum; bs->buf_bit_idx = 8; - } /* open the device to write the bit stream into it */ void open_bit_stream_w (Bit_stream_struc * bs, int size) { - bs->pt = NULL; // we're not using file output alloc_buffer (bs, size); bs->buf_byte_idx = size - 1; bs->buf_bit_idx = 8; @@ -139,7 +85,6 @@ void close_bit_stream_w (Bit_stream_struc * bs) { putbits (bs, 0, 7); empty_buffer (bs, bs->buf_byte_idx + 1); - if (bs->pt) fclose(bs->pt); desalloc_buffer (bs); } |