1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-15 14:13:16 +02:00

avcodec/dcahuff: Replace DCAVLC by ordinary VLCs

This is possible now that the offsets are already applied
when creating the VLC.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2022-09-06 16:53:48 +02:00
parent 3652114596
commit 465e27e0f2
3 changed files with 12 additions and 20 deletions

View File

@@ -67,9 +67,9 @@ static const uint8_t block_code_nbits[7] = {
7, 10, 12, 13, 15, 17, 19 7, 10, 12, 13, 15, 17, 19
}; };
static int dca_get_vlc(GetBitContext *s, DCAVLC *v, int i) static int dca_get_vlc(GetBitContext *s, const VLC *vlc)
{ {
return get_vlc2(s, v->vlc[i].table, v->vlc[i].bits, 2); return get_vlc2(s, vlc->table, vlc->bits, 2);
} }
static void get_array(GetBitContext *s, int32_t *array, int size, int n) static void get_array(GetBitContext *s, int32_t *array, int size, int n)
@@ -435,7 +435,7 @@ static int parse_subframe_header(DCACoreDecoder *s, int sf,
int abits; int abits;
if (sel < 5) if (sel < 5)
abits = dca_get_vlc(&s->gb, &ff_dca_vlc_bit_allocation, sel); abits = dca_get_vlc(&s->gb, &ff_dca_vlc_bit_allocation[sel]);
else else
abits = get_bits(&s->gb, sel - 1); abits = get_bits(&s->gb, sel - 1);
@@ -570,7 +570,7 @@ static inline int parse_huffman_codes(DCACoreDecoder *s, int32_t *audio, int abi
// Extract Huffman codes from the bit stream // Extract Huffman codes from the bit stream
for (i = 0; i < DCA_SUBBAND_SAMPLES; i++) for (i = 0; i < DCA_SUBBAND_SAMPLES; i++)
audio[i] = dca_get_vlc(&s->gb, &ff_dca_vlc_quant_index[abits - 1], sel); audio[i] = dca_get_vlc(&s->gb, &ff_dca_vlc_quant_index[abits - 1][sel]);
return 1; return 1;
} }
@@ -1340,7 +1340,7 @@ static int parse_x96_subframe_header(DCACoreDecoder *s, int xch_base)
for (band = s->x96_subband_start; band < s->nsubbands[ch]; band++) { for (band = s->x96_subband_start; band < s->nsubbands[ch]; band++) {
// If Huffman code was used, the difference of abits was encoded // If Huffman code was used, the difference of abits was encoded
if (sel < 7) if (sel < 7)
abits += dca_get_vlc(&s->gb, &ff_dca_vlc_quant_index[5 + 2 * s->x96_high_res], sel); abits += dca_get_vlc(&s->gb, &ff_dca_vlc_quant_index[5 + 2 * s->x96_high_res][sel]);
else else
abits = get_bits(&s->gb, 3 + s->x96_high_res); abits = get_bits(&s->gb, 3 + s->x96_high_res);

View File

@@ -768,10 +768,10 @@ const uint8_t ff_dca_vlc_src_tables[][2] = {
{ 4, 3 }, { 0, 3 }, { 2, 2 }, { 3, 2 }, { 4, 3 }, { 0, 3 }, { 2, 2 }, { 3, 2 },
}; };
DCAVLC ff_dca_vlc_bit_allocation; VLC ff_dca_vlc_bit_allocation[5];
VLC ff_dca_vlc_transition_mode[4]; VLC ff_dca_vlc_transition_mode[4];
VLC ff_dca_vlc_scale_factor[5]; VLC ff_dca_vlc_scale_factor[5];
DCAVLC ff_dca_vlc_quant_index[DCA_CODE_BOOKS]; VLC ff_dca_vlc_quant_index[DCA_CODE_BOOKS][7];
VLC ff_dca_vlc_tnl_grp[5]; VLC ff_dca_vlc_tnl_grp[5];
VLC ff_dca_vlc_tnl_scf; VLC ff_dca_vlc_tnl_scf;
@@ -791,7 +791,6 @@ av_cold void ff_dca_init_vlcs(void)
static VLCElem dca_table[30218]; static VLCElem dca_table[30218];
const uint8_t (*src_table)[2] = ff_dca_vlc_src_tables; const uint8_t (*src_table)[2] = ff_dca_vlc_src_tables;
unsigned offset = 0; unsigned offset = 0;
int i;
#define DCA_INIT_VLC(vlc, nb_bits, nb_codes, entry_offset) \ #define DCA_INIT_VLC(vlc, nb_bits, nb_codes, entry_offset) \
do { \ do { \
@@ -805,15 +804,13 @@ av_cold void ff_dca_init_vlcs(void)
} while (0) } while (0)
for (unsigned i = 0; i < DCA_CODE_BOOKS; i++) { for (unsigned i = 0; i < DCA_CODE_BOOKS; i++) {
ff_dca_vlc_quant_index[i].max_depth = 1 + (i > 4);
for (unsigned j = 0; j < ff_dca_quant_index_group_size[i]; j++) for (unsigned j = 0; j < ff_dca_quant_index_group_size[i]; j++)
DCA_INIT_VLC(ff_dca_vlc_quant_index[i].vlc[j], bitalloc_maxbits[i][j], DCA_INIT_VLC(ff_dca_vlc_quant_index[i][j], bitalloc_maxbits[i][j],
ff_dca_bitalloc_sizes[i], ff_dca_bitalloc_offsets[i]); ff_dca_bitalloc_sizes[i], ff_dca_bitalloc_offsets[i]);
} }
ff_dca_vlc_bit_allocation.max_depth = 2; for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_bit_allocation); i++)
for (i = 0; i < 5; i++) DCA_INIT_VLC(ff_dca_vlc_bit_allocation[i], bitalloc_12_vlc_bits[i], 12, 1);
DCA_INIT_VLC(ff_dca_vlc_bit_allocation.vlc[i], bitalloc_12_vlc_bits[i], 12, 1);
for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_scale_factor); i++) for (unsigned i = 0; i < FF_ARRAY_ELEMS(ff_dca_vlc_scale_factor); i++)
DCA_INIT_VLC(ff_dca_vlc_scale_factor[i], DCA_SCALES_VLC_BITS, 129, -64); DCA_INIT_VLC(ff_dca_vlc_scale_factor[i], DCA_SCALES_VLC_BITS, 129, -64);

View File

@@ -35,17 +35,12 @@
3 * (5 + 7 + 9 + 13) \ 3 * (5 + 7 + 9 + 13) \
+ 7 * (17 + 25 + 33 + 65 + 129)) + 7 * (17 + 25 + 33 + 65 + 129))
typedef struct DCAVLC { extern VLC ff_dca_vlc_bit_allocation[5];
int max_depth; ///< Parameter for get_vlc2()
VLC vlc[7]; ///< Actual codes
} DCAVLC;
extern DCAVLC ff_dca_vlc_bit_allocation;
#define DCA_TMODE_VLC_BITS 3 #define DCA_TMODE_VLC_BITS 3
extern VLC ff_dca_vlc_transition_mode[4]; extern VLC ff_dca_vlc_transition_mode[4];
#define DCA_SCALES_VLC_BITS 9 #define DCA_SCALES_VLC_BITS 9
extern VLC ff_dca_vlc_scale_factor[5]; extern VLC ff_dca_vlc_scale_factor[5];
extern DCAVLC ff_dca_vlc_quant_index[DCA_CODE_BOOKS]; extern VLC ff_dca_vlc_quant_index[DCA_CODE_BOOKS][7];
extern VLC ff_dca_vlc_tnl_grp[5]; extern VLC ff_dca_vlc_tnl_grp[5];
extern VLC ff_dca_vlc_tnl_scf; extern VLC ff_dca_vlc_tnl_scf;