[FFmpeg-cvslog] avcodec/vp3: Unify initializing and freeing VLC tables
Andreas Rheinhardt
git at videolan.org
Wed Oct 21 07:58:33 EEST 2020
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Mon Oct 19 21:25:47 2020 +0200| [289e9648734a3b8fd7241c9e3b4e9e5b3daf3200] | committer: Andreas Rheinhardt
avcodec/vp3: Unify initializing and freeing VLC tables
Reviewed-by: Peter Ross <pross at xvid.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=289e9648734a3b8fd7241c9e3b4e9e5b3daf3200
---
libavcodec/vp3.c | 163 ++++++++++++++-------------------------------------
libavcodec/vp3data.h | 22 ++-----
libavcodec/vp4data.h | 22 ++-----
3 files changed, 55 insertions(+), 152 deletions(-)
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 7ee65c8062..576bd8848d 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -257,11 +257,9 @@ typedef struct Vp3DecodeContext {
int *nkf_coded_fragment_list;
int num_kf_coded_fragment[3];
- VLC dc_vlc[16];
- VLC ac_vlc_1[16];
- VLC ac_vlc_2[16];
- VLC ac_vlc_3[16];
- VLC ac_vlc_4[16];
+ /* The first 16 of the following VLCs are for the dc coefficients;
+ the others are four groups of 16 VLCs each for ac coefficients. */
+ VLC coeff_vlc[5 * 16];
VLC superblock_run_length_vlc; /* version < 2 */
VLC fragment_run_length_vlc; /* version < 2 */
@@ -347,13 +345,8 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx)
av_frame_free(&s->last_frame.f);
av_frame_free(&s->golden_frame.f);
- for (i = 0; i < 16; i++) {
- ff_free_vlc(&s->dc_vlc[i]);
- ff_free_vlc(&s->ac_vlc_1[i]);
- ff_free_vlc(&s->ac_vlc_2[i]);
- ff_free_vlc(&s->ac_vlc_3[i]);
- ff_free_vlc(&s->ac_vlc_4[i]);
- }
+ for (i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++)
+ ff_free_vlc(&s->coeff_vlc[i]);
ff_free_vlc(&s->superblock_run_length_vlc);
ff_free_vlc(&s->fragment_run_length_vlc);
@@ -1314,7 +1307,7 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
dc_c_table = get_bits(gb, 4);
/* unpack the Y plane DC coefficients */
- residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, &s->coeff_vlc[dc_y_table], 0,
0, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
@@ -1325,11 +1318,11 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]);
/* unpack the C plane DC coefficients */
- residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, &s->coeff_vlc[dc_c_table], 0,
1, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
- residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0,
+ residual_eob_run = unpack_vlcs(s, gb, &s->coeff_vlc[dc_c_table], 0,
2, residual_eob_run);
if (residual_eob_run < 0)
return residual_eob_run;
@@ -1350,20 +1343,24 @@ static int unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
/* build tables of AC VLC tables */
for (i = 1; i <= 5; i++) {
- y_tables[i] = &s->ac_vlc_1[ac_y_table];
- c_tables[i] = &s->ac_vlc_1[ac_c_table];
+ /* AC VLC table group 1 */
+ y_tables[i] = &s->coeff_vlc[ac_y_table + 16];
+ c_tables[i] = &s->coeff_vlc[ac_c_table + 16];
}
for (i = 6; i <= 14; i++) {
- y_tables[i] = &s->ac_vlc_2[ac_y_table];
- c_tables[i] = &s->ac_vlc_2[ac_c_table];
+ /* AC VLC table group 2 */
+ y_tables[i] = &s->coeff_vlc[ac_y_table + 32];
+ c_tables[i] = &s->coeff_vlc[ac_c_table + 32];
}
for (i = 15; i <= 27; i++) {
- y_tables[i] = &s->ac_vlc_3[ac_y_table];
- c_tables[i] = &s->ac_vlc_3[ac_c_table];
+ /* AC VLC table group 3 */
+ y_tables[i] = &s->coeff_vlc[ac_y_table + 48];
+ c_tables[i] = &s->coeff_vlc[ac_c_table + 48];
}
for (i = 28; i <= 63; i++) {
- y_tables[i] = &s->ac_vlc_4[ac_y_table];
- c_tables[i] = &s->ac_vlc_4[ac_c_table];
+ /* AC VLC table group 4 */
+ y_tables[i] = &s->coeff_vlc[ac_y_table + 64];
+ c_tables[i] = &s->coeff_vlc[ac_c_table + 64];
}
/* decode all AC coefficients */
@@ -1542,23 +1539,28 @@ static int vp4_unpack_dct_coeffs(Vp3DecodeContext *s, GetBitContext *gb)
/* build tables of DC/AC VLC tables */
- tables[0][0] = &s->dc_vlc[dc_y_table];
- tables[1][0] = &s->dc_vlc[dc_c_table];
+ /* DC table group */
+ tables[0][0] = &s->coeff_vlc[dc_y_table];
+ tables[1][0] = &s->coeff_vlc[dc_c_table];
for (i = 1; i <= 5; i++) {
- tables[0][i] = &s->ac_vlc_1[ac_y_table];
- tables[1][i] = &s->ac_vlc_1[ac_c_table];
+ /* AC VLC table group 1 */
+ tables[0][i] = &s->coeff_vlc[ac_y_table + 16];
+ tables[1][i] = &s->coeff_vlc[ac_c_table + 16];
}
for (i = 6; i <= 14; i++) {
- tables[0][i] = &s->ac_vlc_2[ac_y_table];
- tables[1][i] = &s->ac_vlc_2[ac_c_table];
+ /* AC VLC table group 2 */
+ tables[0][i] = &s->coeff_vlc[ac_y_table + 32];
+ tables[1][i] = &s->coeff_vlc[ac_c_table + 32];
}
for (i = 15; i <= 27; i++) {
- tables[0][i] = &s->ac_vlc_3[ac_y_table];
- tables[1][i] = &s->ac_vlc_3[ac_c_table];
+ /* AC VLC table group 3 */
+ tables[0][i] = &s->coeff_vlc[ac_y_table + 48];
+ tables[1][i] = &s->coeff_vlc[ac_c_table + 48];
}
for (i = 28; i <= 63; i++) {
- tables[0][i] = &s->ac_vlc_4[ac_y_table];
- tables[1][i] = &s->ac_vlc_4[ac_c_table];
+ /* AC VLC table group 4 */
+ tables[0][i] = &s->coeff_vlc[ac_y_table + 64];
+ tables[1][i] = &s->coeff_vlc[ac_c_table + 64];
}
vp4_set_tokens_base(s);
@@ -2412,103 +2414,28 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
/* init VLC tables */
if (s->version < 2) {
- for (i = 0; i < 16; i++) {
- /* DC histograms */
- if ((ret = init_vlc(&s->dc_vlc[i], 11, 32,
- &dc_bias[i][0][1], 4, 2,
- &dc_bias[i][0][0], 4, 2, 0)) < 0)
- return ret;
-
- /* group 1 AC histograms */
- if ((ret = init_vlc(&s->ac_vlc_1[i], 11, 32,
- &ac_bias_0[i][0][1], 4, 2,
- &ac_bias_0[i][0][0], 4, 2, 0)) < 0)
- return ret;
-
- /* group 2 AC histograms */
- if ((ret = init_vlc(&s->ac_vlc_2[i], 11, 32,
- &ac_bias_1[i][0][1], 4, 2,
- &ac_bias_1[i][0][0], 4, 2, 0)) < 0)
- return ret;
-
- /* group 3 AC histograms */
- if ((ret = init_vlc(&s->ac_vlc_3[i], 11, 32,
- &ac_bias_2[i][0][1], 4, 2,
- &ac_bias_2[i][0][0], 4, 2, 0)) < 0)
- return ret;
-
- /* group 4 AC histograms */
- if ((ret = init_vlc(&s->ac_vlc_4[i], 11, 32,
- &ac_bias_3[i][0][1], 4, 2,
- &ac_bias_3[i][0][0], 4, 2, 0)) < 0)
+ for (i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++) {
+ if ((ret = init_vlc(&s->coeff_vlc[i], 11, 32,
+ &vp3_bias[i][0][1], 4, 2,
+ &vp3_bias[i][0][0], 4, 2, 0)) < 0)
return ret;
}
#if CONFIG_VP4_DECODER
} else { /* version >= 2 */
- for (i = 0; i < 16; i++) {
- /* DC histograms */
- if ((ret = init_vlc(&s->dc_vlc[i], 11, 32,
- &vp4_dc_bias[i][0][1], 4, 2,
- &vp4_dc_bias[i][0][0], 4, 2, 0)) < 0)
- return ret;
-
- /* group 1 AC histograms */
- if ((ret = init_vlc(&s->ac_vlc_1[i], 11, 32,
- &vp4_ac_bias_0[i][0][1], 4, 2,
- &vp4_ac_bias_0[i][0][0], 4, 2, 0)) < 0)
- return ret;
-
- /* group 2 AC histograms */
- if ((ret = init_vlc(&s->ac_vlc_2[i], 11, 32,
- &vp4_ac_bias_1[i][0][1], 4, 2,
- &vp4_ac_bias_1[i][0][0], 4, 2, 0)) < 0)
- return ret;
-
- /* group 3 AC histograms */
- if ((ret = init_vlc(&s->ac_vlc_3[i], 11, 32,
- &vp4_ac_bias_2[i][0][1], 4, 2,
- &vp4_ac_bias_2[i][0][0], 4, 2, 0)) < 0)
- return ret;
-
- /* group 4 AC histograms */
- if ((ret = init_vlc(&s->ac_vlc_4[i], 11, 32,
- &vp4_ac_bias_3[i][0][1], 4, 2,
- &vp4_ac_bias_3[i][0][0], 4, 2, 0)) < 0)
+ for (i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++) {
+ if ((ret = init_vlc(&s->coeff_vlc[i], 11, 32,
+ &vp4_bias[i][0][1], 4, 2,
+ &vp4_bias[i][0][0], 4, 2, 0)) < 0)
return ret;
}
#endif
}
} else {
- for (i = 0; i < 16; i++) {
- /* DC histograms */
- if (init_vlc(&s->dc_vlc[i], 11, 32,
+ for (i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++) {
+ if (init_vlc(&s->coeff_vlc[i], 11, 32,
&s->huffman_table[i][0][1], 8, 4,
&s->huffman_table[i][0][0], 8, 4, 0) < 0)
goto vlc_fail;
-
- /* group 1 AC histograms */
- if (init_vlc(&s->ac_vlc_1[i], 11, 32,
- &s->huffman_table[i + 16][0][1], 8, 4,
- &s->huffman_table[i + 16][0][0], 8, 4, 0) < 0)
- goto vlc_fail;
-
- /* group 2 AC histograms */
- if (init_vlc(&s->ac_vlc_2[i], 11, 32,
- &s->huffman_table[i + 16 * 2][0][1], 8, 4,
- &s->huffman_table[i + 16 * 2][0][0], 8, 4, 0) < 0)
- goto vlc_fail;
-
- /* group 3 AC histograms */
- if (init_vlc(&s->ac_vlc_3[i], 11, 32,
- &s->huffman_table[i + 16 * 3][0][1], 8, 4,
- &s->huffman_table[i + 16 * 3][0][0], 8, 4, 0) < 0)
- goto vlc_fail;
-
- /* group 4 AC histograms */
- if (init_vlc(&s->ac_vlc_4[i], 11, 32,
- &s->huffman_table[i + 16 * 4][0][1], 8, 4,
- &s->huffman_table[i + 16 * 4][0][0], 8, 4, 0) < 0)
- goto vlc_fail;
}
}
diff --git a/libavcodec/vp3data.h b/libavcodec/vp3data.h
index 3f24d5f7f6..a1366788c5 100644
--- a/libavcodec/vp3data.h
+++ b/libavcodec/vp3data.h
@@ -442,7 +442,7 @@ static const int16_t *const coeff_tables[32] = {
coeff_table_token_31
};
-static const uint16_t dc_bias[16][32][2] = {
+static const uint16_t vp3_bias[5 * 16][32][2] = {
{ /* DC bias table 0 */
{ 0x2D, 6 },
{ 0x26, 7 },
@@ -986,10 +986,7 @@ static const uint16_t dc_bias[16][32][2] = {
{ 0x151, 9 },
{ 0x150, 9 },
{ 0x2A9, 10 }
- }
-};
-
-static const uint16_t ac_bias_0[16][32][2] = {
+ },
{ /* AC bias group 1, table 0 */
{ 0x8, 5 },
{ 0x25, 7 },
@@ -1533,10 +1530,7 @@ static const uint16_t ac_bias_0[16][32][2] = {
{ 0x38, 7 },
{ 0x3D, 6 },
{ 0x79, 7 }
- }
-};
-
-static const uint16_t ac_bias_1[16][32][2] = {
+ },
{ /* AC bias group 2, table 0 */
{ 0xB, 5 },
{ 0x2B, 7 },
@@ -2080,10 +2074,7 @@ static const uint16_t ac_bias_1[16][32][2] = {
{ 0xB, 6 },
{ 0x5F, 7 },
{ 0xBD, 8 }
- }
-};
-
-static const uint16_t ac_bias_2[16][32][2] = {
+ },
{ /* AC bias group 3, table 0 */
{ 0x3, 4 },
{ 0x9, 6 },
@@ -2627,10 +2618,7 @@ static const uint16_t ac_bias_2[16][32][2] = {
{ 0x1B, 5 },
{ 0x35B7, 14 },
{ 0x35B6, 14 }
- }
-};
-
-static const uint16_t ac_bias_3[16][32][2] = {
+ },
{ /* AC bias group 4, table 0 */
{ 0x0, 3 },
{ 0x10, 5 },
diff --git a/libavcodec/vp4data.h b/libavcodec/vp4data.h
index 69a009eff1..f711d16240 100644
--- a/libavcodec/vp4data.h
+++ b/libavcodec/vp4data.h
@@ -368,7 +368,7 @@ static const uint16_t vp4_mv_vlc[2][7][63][2] = {
}
};
-static const uint16_t vp4_dc_bias[16][32][2] = {
+static const uint16_t vp4_bias[5 * 16][32][2] = {
{ /* DC bias table 0 */
{ 0xC, 5 }, { 0x70, 7 }, { 0x1CA, 9 }, { 0x1CB, 9 },
{ 0x391, 10 }, { 0x1C9B, 13 }, { 0x3935, 14 }, { 0x71, 7 },
@@ -528,10 +528,7 @@ static const uint16_t vp4_dc_bias[16][32][2] = {
{ 0xC4, 8 }, { 0x5B9, 11 }, { 0x5B8, 11 }, { 0x11, 5 },
{ 0x36, 6 }, { 0x5F, 7 }, { 0x1E, 7 }, { 0x63, 7 },
{ 0x6F, 7 }, { 0x1F, 7 }, { 0xB6, 8 }, { 0x16F, 9 }
- }
-};
-
-static const uint16_t vp4_ac_bias_0[16][32][2] = {
+ },
{ /* AC bias group 1, table 0 */
{ 0x6, 5 }, { 0x1E, 7 }, { 0x1CC, 9 }, { 0x1CE, 9 },
{ 0x734, 11 }, { 0x1CD5, 13 }, { 0x1CD4, 13 }, { 0x18, 5 },
@@ -691,10 +688,7 @@ static const uint16_t vp4_ac_bias_0[16][32][2] = {
{ 0x3A0, 12 }, { 0x3A3, 12 }, { 0x3A2, 12 }, { 0x5, 3 },
{ 0x2, 4 }, { 0x1F, 5 }, { 0x1D, 5 }, { 0x3C, 6 },
{ 0x18, 5 }, { 0xF, 6 }, { 0x6, 5 }, { 0x5, 6 }
- }
-};
-
-static const uint16_t vp4_ac_bias_1[16][32][2] = {
+ },
{ /* AC bias group 2, table 0 */
{ 0x4, 5 }, { 0xF5, 8 }, { 0x182, 9 }, { 0x60F, 11 },
{ 0x1839, 13 }, { 0x1838, 13 }, { 0x183B, 13 }, { 0x13, 5 },
@@ -854,10 +848,7 @@ static const uint16_t vp4_ac_bias_1[16][32][2] = {
{ 0x288, 13 }, { 0x28B, 13 }, { 0x28A, 13 }, { 0xF, 4 },
{ 0x1D, 5 }, { 0x13, 5 }, { 0x1, 5 }, { 0x0, 5 },
{ 0x3, 3 }, { 0x1A, 5 }, { 0x72, 7 }, { 0xE7, 8 }
- }
-};
-
-static const uint16_t vp4_ac_bias_2[16][32][2] = {
+ },
{ /* AC bias group 3, table 0 */
{ 0x9, 5 }, { 0x15, 7 }, { 0x28, 8 }, { 0x52, 9 },
{ 0x29A, 12 }, { 0x537, 13 }, { 0x536, 13 }, { 0xA, 5 },
@@ -1017,10 +1008,7 @@ static const uint16_t vp4_ac_bias_2[16][32][2] = {
{ 0x3872, 14 }, { 0x3879, 14 }, { 0x3878, 14 }, { 0x3C, 6 },
{ 0x73, 7 }, { 0x2A, 6 }, { 0x3D, 6 }, { 0x2B, 6 },
{ 0x1F, 5 }, { 0xD, 4 }, { 0x1C3E, 13 }, { 0x1C3D, 13 }
- }
-};
-
-static const uint16_t vp4_ac_bias_3[16][32][2] = {
+ },
{ /* AC bias group 4, table 0 */
{ 0x7, 4 }, { 0xF, 6 }, { 0xBB, 8 }, { 0xBA, 8 },
{ 0x5CF, 11 }, { 0x173A, 13 }, { 0x2E77, 14 }, { 0x29, 6 },
More information about the ffmpeg-cvslog
mailing list