History

avcodec/svq1dec: Avoid superfluous VLC structures

Of all these VLCs here, only VLC.table was really used after init, so use the ff_vlc_init_tables API to get rid of them.

Andreas Rheinhardt committed 3 years ago

Commit 7d542e21 parent 7902c0d1 file · +38 −44Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/svq1dec.c+38−44
@@ -45,12 +45,12 @@ · 44 unmodified lines
4545 #include "svq1.h"
4646
4747 #define SVQ1_BLOCK_TYPE_VLC_BITS 3
48−static VLC svq1_block_type;
49−static VLC svq1_motion_component;
50−static VLC svq1_intra_multistage[6];
51−static VLC svq1_inter_multistage[6];
52−static VLC svq1_intra_mean;
53−static VLC svq1_inter_mean;
48+static VLCElem svq1_block_type[8];
49+static VLCElem svq1_motion_component[176];
50+static const VLCElem *svq1_intra_multistage[6];
51+static const VLCElem *svq1_inter_multistage[6];
52+static VLCElem svq1_intra_mean[632];
53+static VLCElem svq1_inter_mean[1434];
5454
5555 /* motion vector (prediction) */
5656 typedef struct svq1_pmv_s {
@@ -190,7 +190,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels, · 133 unmodified lines
190190 height = 1 << ((3 + level) / 2);
191191
192192 /* get number of stages (-1 skips vector, 0 for mean only) */
193− stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1;
193+ stages = get_vlc2(bitbuf, svq1_intra_multistage[level], 3, 3) - 1;
194194
195195 if (stages == -1) {
196196 for (y = 0; y < height; y++)
@@ -206,7 +206,7 @@ static int svq1_decode_block_intra(GetBitContext *bitbuf, uint8_t *pixels, · 9 unmodified lines
206206 }
207207 av_assert0(stages >= 0);
208208
209− mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3);
209+ mean = get_vlc2(bitbuf, svq1_intra_mean, 8, 3);
210210
211211 if (stages == 0) {
212212 for (y = 0; y < height; y++)
@@ -257,7 +257,7 @@ static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels, · 44 unmodified lines
257257 height = 1 << ((3 + level) / 2);
258258
259259 /* get number of stages (-1 skips vector, 0 for mean only) */
260− stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1;
260+ stages = get_vlc2(bitbuf, svq1_inter_multistage[level], 3, 2) - 1;
261261
262262 if (stages == -1)
263263 continue; /* skip vector */
@@ -270,7 +270,7 @@ static int svq1_decode_block_non_intra(GetBitContext *bitbuf, uint8_t *pixels, · 6 unmodified lines
270270 }
271271 av_assert0(stages >= 0);
272272
273− mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256;
273+ mean = get_vlc2(bitbuf, svq1_inter_mean, 9, 3) - 256;
274274
275275 if (buggy) {
276276 if (mean == -128)
@@ -307,7 +307,7 @@ static int svq1_decode_motion_vector(GetBitContext *bitbuf, svq1_pmv *mv, · 30 unmodified lines
307307
308308 for (i = 0; i < 2; i++) {
309309 /* get motion code */
310− diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2);
310+ diff = get_vlc2(bitbuf, svq1_motion_component, 7, 2);
311311 if (diff < 0)
312312 return AVERROR_INVALIDDATA;
313313 else if (diff) {
@@ -472,7 +472,7 @@ static int svq1_decode_delta_block(AVCodecContext *avctx, HpelDSPContext *hdsp, · 158 unmodified lines
472472 int result = 0;
473473
474474 /* get block type */
475− block_type = get_vlc2(bitbuf, svq1_block_type.table,
475+ block_type = get_vlc2(bitbuf, svq1_block_type,
476476 SVQ1_BLOCK_TYPE_VLC_BITS, 1);
477477
478478 /* reset motion vectors */
@@ -779,41 +779,35 @@ static int svq1_decode_frame(AVCodecContext *avctx, AVFrame *cur, · 300 unmodified lines
779779
780780 static av_cold void svq1_static_init(void)
781781 {
782− VLC_INIT_STATIC(&svq1_block_type, SVQ1_BLOCK_TYPE_VLC_BITS, 4,
783− &ff_svq1_block_type_vlc[0][1], 2, 1,
784− &ff_svq1_block_type_vlc[0][0], 2, 1, 8);
785−
786− VLC_INIT_STATIC(&svq1_motion_component, 7, 33,
787− &ff_mvtab[0][1], 2, 1,
788− &ff_mvtab[0][0], 2, 1, 176);
789−
790− for (int i = 0, offset = 0; i < 6; i++) {
791− static const uint8_t sizes[2][6] = { { 14, 10, 14, 18, 16, 18 },
792− { 10, 10, 14, 14, 14, 16 } };
793− static VLCElem table[168];
794− svq1_intra_multistage[i].table = &table[offset];
795− svq1_intra_multistage[i].table_allocated = sizes[0][i];
796− offset += sizes[0][i];
797− vlc_init(&svq1_intra_multistage[i], 3, 8,
798− &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1,
799− &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1,
800− VLC_INIT_USE_STATIC);
801− svq1_inter_multistage[i].table = &table[offset];
802− svq1_inter_multistage[i].table_allocated = sizes[1][i];
803− offset += sizes[1][i];
804− vlc_init(&svq1_inter_multistage[i], 3, 8,
805− &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1,
806− &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1,
807− VLC_INIT_USE_STATIC);
782+ static VLCElem table[168];
783+ VLCInitState state = VLC_INIT_STATE(table);
784+
785+ VLC_INIT_STATIC_TABLE(svq1_block_type, SVQ1_BLOCK_TYPE_VLC_BITS, 4,
786+ &ff_svq1_block_type_vlc[0][1], 2, 1,
787+ &ff_svq1_block_type_vlc[0][0], 2, 1, 0);
788+
789+ VLC_INIT_STATIC_TABLE(svq1_motion_component, 7, 33,
790+ &ff_mvtab[0][1], 2, 1,
791+ &ff_mvtab[0][0], 2, 1, 0);
792+
793+ for (int i = 0; i < 6; i++) {
794+ svq1_intra_multistage[i] =
795+ ff_vlc_init_tables(&state, 3, 8,
796+ &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1,
797+ &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, 0);
798+ svq1_inter_multistage[i] =
799+ ff_vlc_init_tables(&state, 3, 8,
800+ &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1,
801+ &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, 0);
808802 }
809803
810− VLC_INIT_STATIC(&svq1_intra_mean, 8, 256,
811− &ff_svq1_intra_mean_vlc[0][1], 4, 2,
812− &ff_svq1_intra_mean_vlc[0][0], 4, 2, 632);
804+ VLC_INIT_STATIC_TABLE(svq1_intra_mean, 8, 256,
805+ &ff_svq1_intra_mean_vlc[0][1], 4, 2,
806+ &ff_svq1_intra_mean_vlc[0][0], 4, 2, 0);
813807
814− VLC_INIT_STATIC(&svq1_inter_mean, 9, 512,
815− &ff_svq1_inter_mean_vlc[0][1], 4, 2,
816− &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1434);
808+ VLC_INIT_STATIC_TABLE(svq1_inter_mean, 9, 512,
809+ &ff_svq1_inter_mean_vlc[0][1], 4, 2,
810+ &ff_svq1_inter_mean_vlc[0][0], 4, 2, 0);
817811 }
818812
819813 static av_cold int svq1_decode_init(AVCodecContext *avctx)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t