ref: 29f38986701109e9da9972e7d6bba9f7df8ef7cd
parent: 7af9c20656f528fe2329d91197d4f83094d7715a
author: menno <menno>
date: Wed Aug 7 04:14:31 EDT 2002
RVLC ER tool finished
--- a/libfaad/bits.c
+++ b/libfaad/bits.c
@@ -16,10 +16,11 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: bits.c,v 1.6 2002/08/05 20:33:38 menno Exp $
+** $Id: bits.c,v 1.7 2002/08/07 08:14:31 menno Exp $
**/
#include "common.h"
+#include <stdlib.h>
#include "bits.h"
/* initialize buffer, call once before first getbits or showbits */
@@ -62,20 +63,26 @@
return 0;
}
-void faad_getbitbuffer(bitfile *ld, void *buffer, uint16_t bits
+uint8_t *faad_getbitbuffer(bitfile *ld, uint16_t bits
DEBUGDEC)
{
uint16_t i, temp;
uint16_t bytes = bits / 8;
uint8_t remainder = bits % 8;
- uint8_t *b_buffer = (uint8_t*)buffer;
+ uint8_t *buffer = (uint8_t*)malloc((bytes+1)*sizeof(uint8_t));
+
for (i = 0; i < bytes; i++)
{
- b_buffer[i] = faad_getbits(ld, 8 DEBUGVAR(print,var,dbg));
+ buffer[i] = faad_getbits(ld, 8 DEBUGVAR(print,var,dbg));
}
- temp = faad_getbits(ld, remainder DEBUGVAR(print,var,dbg)) << (8-remainder);
+ if (remainder)
+ {
+ temp = faad_getbits(ld, remainder DEBUGVAR(print,var,dbg)) << (8-remainder);
- b_buffer[bytes] = temp;
-}
\ No newline at end of file
+ buffer[bytes] = temp;
+ }
+
+ return buffer;
+}
--- a/libfaad/bits.h
+++ b/libfaad/bits.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: bits.h,v 1.6 2002/08/05 20:33:38 menno Exp $
+** $Id: bits.h,v 1.7 2002/08/07 08:14:31 menno Exp $
**/
#ifndef __BITS_H__
@@ -58,7 +58,7 @@
void faad_initbits(bitfile *ld, void *buffer);
uint8_t faad_byte_align(bitfile *ld);
uint32_t faad_get_processed_bits(bitfile *ld);
-void faad_getbitbuffer(bitfile *ld, void *buffer, uint16_t bits
+uint8_t *faad_getbitbuffer(bitfile *ld, uint16_t bits
DEBUGDEC);
@@ -96,7 +96,12 @@
/* return next n bits (right adjusted) */
static INLINE uint32_t faad_getbits(bitfile *ld, uint8_t n DEBUGDEC)
{
- uint32_t ret = faad_showbits(ld, n);
+ uint32_t ret;
+
+ if (n == 0)
+ return 0;
+
+ ret = faad_showbits(ld, n);
faad_flushbits(ld, n);
#ifdef ANALYSIS
--- a/libfaad/rvlc_scale_factors.c
+++ b/libfaad/rvlc_scale_factors.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: rvlc_scale_factors.c,v 1.1 2002/08/05 20:33:38 menno Exp $
+** $Id: rvlc_scale_factors.c,v 1.2 2002/08/07 08:14:31 menno Exp $
**/
#include "common.h"
@@ -28,82 +28,6 @@
#ifdef ERROR_RESILIENCE
-#if 0
- uint32_t bits_used, length_of_rvlc_sf;
- uint8_t bits = 11;
-
- sf_concealment = faad_get1bit(ld
- DEBUGVAR(1,149,"scale_factor_data(): sf_concealment"));
- rev_global_gain = faad_getbits(ld, 8
- DEBUGVAR(1,150,"scale_factor_data(): rev_global_gain"));
-
- if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
- bits = 9;
-
- /* the number of bits used for the huffman codewords */
- length_of_rvlc_sf = faad_getbits(ld, bits
- DEBUGVAR(1,151,"scale_factor_data(): length_of_rvlc_sf"));
-
- /* check how many bits are used in decoding the scalefactors
- A better solution would be to read length_of_rvlc_sf ahead
- in a buffer and use that to decode the scale factors
- */
- bits_used = faad_get_processed_bits(ld);
- decode_scale_factors(ics, ld);
- bits_used = faad_get_processed_bits(ld) - bits_used;
-
- /* return an error if the number of decoded bits is not correct
- FAAD should be able to recover from this, for example by
- setting all scalefactors to 0 (e.g. muting the frame)
- */
- if (bits_used != length_of_rvlc_sf)
- return 8;
-
- sf_escapes_present; 1 uimsbf
-
- if (sf_escapes_present)
- {
- length_of_rvlc_escapes; 8 uimsbf
-
- for (g = 0; g < num_window_groups; g++)
- {
- for (sfb = 0; sfb < max_sfb; sfb++)
- {
- if (sect_cb[g][sfb] != ZERO_HCB)
- {
- if (is_intensity(g, sfb) &&
- dpcm_is_position[g][sfb] == ESC_FLAG)
- {
- rvlc_esc_sf[dpcm_is_position[g][sfb]]; 2..20 vlclbf
- } else {
- if (is_noise(g, sfb) &&
- dpcm_noise_nrg[g][sfb] == ESC_FLAG)
- {
- rvlc_esc_sf[dpcm_noise_nrg[g][sfb]]; 2..20 vlclbf
- } else {
- if (dpcm_sf[g][sfb] == ESC_FLAG)
- {
- rvlc_esc_sf[dpcm_sf[g][sfb]]; 2..20 vlclbf
- }
- }
- }
- }
- }
- }
-
- if (intensity_used &&
- dpcm_is_position[g][sfb] == ESC_FLAG)
- {
- rvlc_esc_sf[dpcm_is_last_position]; 2..20 vlclbf
- }
- }
-
- if (noise_used)
- {
- dpcm_noise_last_position; 9 uimsbf
- }
-#endif
-
uint8_t rvlc_scale_factor_data(ic_stream *ics, bitfile *ld)
{
uint8_t bits = 9;
@@ -148,35 +72,268 @@
uint8_t rvlc_decode_scale_factors(ic_stream *ics, bitfile *ld)
{
- void *rvlc_buffer = NULL;
- void *rvlc_esc_buffer = NULL;
+ uint8_t result;
+ uint8_t *rvlc_sf_buffer = NULL;
+ uint8_t *rvlc_esc_buffer = NULL;
+ bitfile ld_rvlc_sf;
+ bitfile ld_rvlc_esc;
if (ics->length_of_rvlc_sf > 0)
{
- rvlc_buffer = malloc((bit2byte(ics->length_of_rvlc_sf)+1)*sizeof(uint8_t));
-
/* We read length_of_rvlc_sf bits here to put it in a
seperate bitfile.
*/
- faad_getbitbuffer(ld, rvlc_buffer, ics->length_of_rvlc_sf
+ rvlc_sf_buffer = faad_getbitbuffer(ld, ics->length_of_rvlc_sf
DEBUGVAR(1,156,"rvlc_decode_scale_factors(): bitbuffer: length_of_rvlc_sf"));
+
+ faad_initbits(&ld_rvlc_sf, (void*)rvlc_sf_buffer);
}
if (ics->sf_escapes_present)
{
- rvlc_esc_buffer = malloc((bit2byte(ics->length_of_rvlc_escapes)+1)*sizeof(uint8_t));
-
/* We read length_of_rvlc_escapes bits here to put it in a
seperate bitfile.
*/
- faad_getbitbuffer(ld, rvlc_esc_buffer, ics->length_of_rvlc_escapes
+ rvlc_esc_buffer = faad_getbitbuffer(ld, ics->length_of_rvlc_escapes
DEBUGVAR(1,157,"rvlc_decode_scale_factors(): bitbuffer: length_of_rvlc_escapes"));
+
+ faad_initbits(&ld_rvlc_esc, (void*)rvlc_esc_buffer);
}
+ /* decode the rvlc scale factors and escapes */
+ result = rvlc_decode_sf_forward(ics, &ld_rvlc_sf, &ld_rvlc_esc);
+
+
if (rvlc_esc_buffer) free(rvlc_esc_buffer);
- if (rvlc_buffer) free(rvlc_buffer);
+ if (rvlc_sf_buffer) free(rvlc_sf_buffer);
+ return result;
+}
+
+static uint8_t rvlc_decode_sf_forward(ic_stream *ics, bitfile *ld_sf, bitfile *ld_esc)
+{
+ uint8_t g, sfb;
+ int8_t t = 0;
+ int8_t error = 0;
+ int8_t noise_pcm_flag = 1;
+
+ int16_t scale_factor = ics->global_gain;
+ int16_t is_position = 0;
+ int16_t noise_energy = ics->global_gain - 90;
+
+ for (g = 0; g < ics->num_window_groups; g++)
+ {
+ for (sfb = 0; sfb < ics->max_sfb; sfb++)
+ {
+ if (error)
+ {
+ ics->scale_factors[g][sfb] = 0;
+ } else {
+ switch (ics->sfb_cb[g][sfb])
+ {
+ case ZERO_HCB: /* zero book */
+ ics->scale_factors[g][sfb] = 0;
+ break;
+ case INTENSITY_HCB: /* intensity books */
+ case INTENSITY_HCB2:
+
+ /* decode intensity position */
+ t = rvlc_huffman_sf(ld_sf, ld_esc);
+
+ is_position += t;
+ ics->scale_factors[g][sfb] = is_position;
+
+ break;
+ case NOISE_HCB: /* noise books */
+
+ /* decode noise energy */
+ if (noise_pcm_flag)
+ {
+ int8_t n = ics->dpcm_noise_nrg;
+ noise_pcm_flag = 0;
+ noise_energy += n;
+ } else {
+ t = rvlc_huffman_sf(ld_sf, ld_esc);
+ noise_energy += t;
+ }
+
+ ics->scale_factors[g][sfb] = noise_energy;
+
+ break;
+ case BOOKSCL: /* invalid books */
+ return 3;
+ default: /* spectral books */
+
+ /* decode scale factor */
+ t = rvlc_huffman_sf(ld_sf, ld_esc);
+
+ scale_factor += t;
+ if (scale_factor < 0)
+ return 4;
+
+ ics->scale_factors[g][sfb] = scale_factor;
+
+ break;
+ }
+ if (t == 99)
+ {
+ error = 1;
+ }
+ }
+ }
+ }
+
return 0;
+}
+
+/* index == 99 means not allowed codeword */
+static rvlc_huff_table book_rvlc[] = {
+ /*index length codeword */
+ { 0, 1, 0 }, /* 0 */
+ { -1, 3, 5 }, /* 101 */
+ { 1, 3, 7 }, /* 111 */
+ { -2, 4, 9 }, /* 1001 */
+ { -3, 5, 17 }, /* 10001 */
+ { 2, 5, 27 }, /* 11011 */
+ { -4, 6, 33 }, /* 100001 */
+ { 99, 6, 50 }, /* 110010 */
+ { 3, 6, 51 }, /* 110011 */
+ { 99, 6, 52 }, /* 110100 */
+ { -7, 7, 65 }, /* 1000001 */
+ { 99, 7, 96 }, /* 1100000 */
+ { 99, 7, 98 }, /* 1100010 */
+ { 7, 7, 99 }, /* 1100011 */
+ { 4, 7, 107 }, /* 1101011 */
+ { -5, 8, 129 }, /* 10000001 */
+ { 99, 8, 194 }, /* 11000010 */
+ { 5, 8, 195 }, /* 11000011 */
+ { 99, 8, 212 }, /* 11010100 */
+ { 99, 9, 256 }, /* 100000000 */
+ { -6, 9, 257 }, /* 100000001 */
+ { 99, 9, 426 }, /* 110101010 */
+ { 6, 9, 427 }, /* 110101011 */
+ { 99, 10, 0 } /* Shouldn't come this far */
+};
+
+static rvlc_huff_table book_escape[] = {
+ /*index length codeword */
+ { 1, 2, 0 },
+ { 0, 2, 2 },
+ { 3, 3, 2 },
+ { 2, 3, 6 },
+ { 4, 4, 14 },
+ { 7, 5, 13 },
+ { 6, 5, 15 },
+ { 5, 5, 31 },
+ { 11, 6, 24 },
+ { 10, 6, 25 },
+ { 9, 6, 29 },
+ { 8, 6, 61 },
+ { 13, 7, 56 },
+ { 12, 7, 120 },
+ { 15, 8, 114 },
+ { 14, 8, 242 },
+ { 17, 9, 230 },
+ { 16, 9, 486 },
+ { 19, 10, 463 },
+ { 18, 10, 974 },
+ { 22, 11, 925 },
+ { 20, 11, 1950 },
+ { 21, 11, 1951 },
+ { 23, 12, 1848 },
+ { 25, 13, 3698 },
+ { 24, 14, 7399 },
+ { 26, 15, 14797 },
+ { 49, 19, 236736 },
+ { 50, 19, 236737 },
+ { 51, 19, 236738 },
+ { 52, 19, 236739 },
+ { 53, 19, 236740 },
+ { 27, 20, 473482 },
+ { 28, 20, 473483 },
+ { 29, 20, 473484 },
+ { 30, 20, 473485 },
+ { 31, 20, 473486 },
+ { 32, 20, 473487 },
+ { 33, 20, 473488 },
+ { 34, 20, 473489 },
+ { 35, 20, 473490 },
+ { 36, 20, 473491 },
+ { 37, 20, 473492 },
+ { 38, 20, 473493 },
+ { 39, 20, 473494 },
+ { 40, 20, 473495 },
+ { 41, 20, 473496 },
+ { 42, 20, 473497 },
+ { 43, 20, 473498 },
+ { 44, 20, 473499 },
+ { 45, 20, 473500 },
+ { 46, 20, 473501 },
+ { 47, 20, 473502 },
+ { 48, 20, 473503 },
+ { 99, 21, 0 } /* Shouldn't come this far */
+};
+
+static int8_t rvlc_huffman_sf(bitfile *ld_sf, bitfile *ld_esc)
+{
+ uint8_t i, j;
+ int8_t index;
+ uint32_t cw;
+ rvlc_huff_table *h = book_rvlc;
+
+ i = h->len;
+ cw = faad_getbits(ld_sf, i);
+
+ while ((cw != h->cw)
+ && (i < 10))
+ {
+ h++;
+ j = h->len-i;
+ i += j;
+ cw <<= j;
+ cw |= faad_getbits(ld_sf, j);
+ }
+
+ index = h->index;
+
+ if (index == +ESC_VAL)
+ {
+ int8_t esc = rvlc_huffman_esc(ld_esc);
+ if (esc == 99)
+ return 99;
+ index += esc;
+ }
+ if (index == -ESC_VAL)
+ {
+ int8_t esc = rvlc_huffman_esc(ld_esc);
+ if (esc == 99)
+ return 99;
+ index -= esc;
+ }
+
+ return index;
+}
+
+static int8_t rvlc_huffman_esc(bitfile *ld)
+{
+ uint8_t i, j;
+ uint32_t cw;
+ rvlc_huff_table *h = book_escape;
+
+ i = h->len;
+ cw = faad_getbits(ld, i);
+
+ while ((cw != h->cw)
+ && (i < 21))
+ {
+ h++;
+ j = h->len-i;
+ i += j;
+ cw <<= j;
+ cw |= faad_getbits(ld, j);
+ }
+
+ return h->index;
}
#endif
\ No newline at end of file
--- a/libfaad/rvlc_scale_factors.h
+++ b/libfaad/rvlc_scale_factors.h
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: rvlc_scale_factors.h,v 1.1 2002/08/05 20:33:38 menno Exp $
+** $Id: rvlc_scale_factors.h,v 1.2 2002/08/07 08:14:31 menno Exp $
**/
#ifndef __RVLC_SCF_H__
@@ -26,9 +26,26 @@
extern "C" {
#endif
+typedef struct
+{
+ int8_t index;
+ uint8_t len;
+ uint32_t cw;
+} rvlc_huff_table;
+
+#define ESC_VAL 7
+
+
uint8_t rvlc_scale_factor_data(ic_stream *ics, bitfile *ld);
uint8_t rvlc_decode_scale_factors(ic_stream *ics, bitfile *ld);
+
+static uint8_t rvlc_decode_sf_forward(ic_stream *ics,
+ bitfile *ld_sf,
+ bitfile *ld_esc);
+static int8_t rvlc_huffman_sf(bitfile *ld_sf,
+ bitfile *ld_esc);
+static int8_t rvlc_huffman_esc(bitfile *ld_esc);
#ifdef __cplusplus
--- a/plugins/in_mp4/in_mp4.c
+++ b/plugins/in_mp4/in_mp4.c
@@ -16,7 +16,7 @@
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
-** $Id: in_mp4.c,v 1.11 2002/07/25 15:59:43 menno Exp $
+** $Id: in_mp4.c,v 1.12 2002/08/07 08:14:31 menno Exp $
**/
#define WIN32_LEAN_AND_MEAN
@@ -121,14 +121,15 @@
{
unsigned char *buff = NULL;
int buff_size = 0;
- unsigned char dummy8;
- unsigned int dummy32;
+ unsigned char dummy2_8, dummy3_8, dummy4_8, dummy5_8, dummy6_8,
+ dummy7_8, dummy8_8;
+ unsigned int dummy1_32;
MP4GetTrackESConfiguration(infile, trackId, &buff, &buff_size);
if (buff)
{
- rc = AudioSpecificConfig(buff, &dummy32, &dummy8, &dummy8, &dummy8,
- &dummy8, &dummy8, &dummy8, &dummy8);
+ rc = AudioSpecificConfig(buff, &dummy1_32, &dummy2_8, &dummy3_8, &dummy4_8,
+ &dummy5_8, &dummy6_8, &dummy7_8, &dummy8_8);
free(buff);
if (rc < 0)