History

lavc/ffv1dec: move the bitreader to stack

There is no reason to place it in persistent state.

Anton Khirnov committed 2 years ago

Commit 889faed1 parent 19e9f3d3 files · +27 −25Browse files

Unified · Split

3 files
  1. libavcodec/ffv1.h +0 −1
  2. libavcodec/ffv1dec.c +15 −13
  3. libavcodec/ffv1dec_template.c +12 −11
libavcodec/ffv1.h+0−1
@@ -85,7 +85,6 @@ typedef struct FFV1Context { · 84 unmodified lines
8585 AVClass *class;
8686 AVCodecContext *avctx;
8787 RangeCoder c;
88− GetBitContext gb;
8988 PutBitContext pb;
9089 uint64_t rc_stat[256][2];
9190 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
libavcodec/ffv1dec.c+15−13
@@ -94,14 +94,14 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state, · 93 unmodified lines
9494 return ret;
9595 }
9696
97−static int is_input_end(FFV1Context *s)
97+static int is_input_end(FFV1Context *s, GetBitContext *gb)
9898 {
9999 if (s->ac != AC_GOLOMB_RICE) {
100100 RangeCoder *const c = &s->c;
101101 if (c->overread > MAX_OVERREAD)
102102 return AVERROR_INVALIDDATA;
103103 } else {
104− if (get_bits_left(&s->gb) < 1)
104+ if (get_bits_left(gb) < 1)
105105 return AVERROR_INVALIDDATA;
106106 }
107107 return 0;
@@ -118,6 +118,7 @@ static int is_input_end(FFV1Context *s) · 10 unmodified lines
118118 #include "ffv1dec_template.c"
119119
120120 static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
121+ GetBitContext *gb,
121122 uint8_t *src, int w, int h, int stride, int plane_index,
122123 int pixel_stride)
123124 {
@@ -140,13 +141,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, · 16 unmodified lines
140141 sample[0][w] = sample[0][w - 1];
141142
142143 if (s->avctx->bits_per_raw_sample <= 8) {
143− int ret = decode_line(s, sc, w, sample, plane_index, 8);
144+ int ret = decode_line(s, sc, gb, w, sample, plane_index, 8);
144145 if (ret < 0)
145146 return ret;
146147 for (x = 0; x < w; x++)
147148 src[x*pixel_stride + stride * y] = sample[1][x];
148149 } else {
149− int ret = decode_line(s, sc, w, sample, plane_index, s->avctx->bits_per_raw_sample);
150+ int ret = decode_line(s, sc, gb, w, sample, plane_index, s->avctx->bits_per_raw_sample);
150151 if (ret < 0)
151152 return ret;
152153 if (s->packed_at_lsb) {
@@ -262,6 +263,7 @@ static int decode_slice(AVCodecContext *c, void *arg) · 109 unmodified lines
262263 AVFrame * const p = f->picture.f;
263264 const int si = (FFV1Context**)arg - f->slice_context;
264265 FFV1SliceContext *sc = &f->slices[si];
266+ GetBitContext gb;
265267
266268 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
267269 ff_progress_frame_await(&f->last_picture, si);
@@ -322,7 +324,7 @@ static int decode_slice(AVCodecContext *c, void *arg) · 54 unmodified lines
322324 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
323325 get_rac(&fs->c, (uint8_t[]) { 129 });
324326 fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0;
325− init_get_bits(&fs->gb,
327+ init_get_bits(&gb,
326328 fs->c.bytestream_start + fs->ac_byte_count,
327329 (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8);
328330 }
@@ -333,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg) · 4 unmodified lines
333335 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
334336 const int cx = x >> f->chroma_h_shift;
335337 const int cy = y >> f->chroma_v_shift;
336− decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1);
338+ decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1);
337339
338340 if (f->chroma_planes) {
339− decode_plane(fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
340− decode_plane(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
341+ decode_plane(fs, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
342+ decode_plane(fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
341343 }
342344 if (fs->transparency)
343− decode_plane(fs, sc, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1);
345+ decode_plane(fs, sc, &gb, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 1);
344346 } else if (f->colorspace == 0) {
345− decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2);
346− decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2);
347+ decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2);
348+ decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2);
347349 } else if (f->use32bit) {
348350 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
349351 p->data[1] + ps * x + y * p->linesize[1],
350352 p->data[2] + ps * x + y * p->linesize[2],
351353 p->data[3] + ps * x + y * p->linesize[3] };
352− decode_rgb_frame32(fs, sc, planes, width, height, p->linesize);
354+ decode_rgb_frame32(fs, sc, &gb, planes, width, height, p->linesize);
353355 } else {
354356 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
355357 p->data[1] + ps * x + y * p->linesize[1],
356358 p->data[2] + ps * x + y * p->linesize[2],
357359 p->data[3] + ps * x + y * p->linesize[3] };
358− decode_rgb_frame(fs, sc, planes, width, height, p->linesize);
360+ decode_rgb_frame(fs, sc, &gb, planes, width, height, p->linesize);
359361 }
360362 if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {
361363 int v;
libavcodec/ffv1dec_template.c+12−11
@@ -23,8 +23,8 @@ · 22 unmodified lines
2323 #include "ffv1_template.c"
2424
2525 static av_always_inline int
26−RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w,
27− TYPE *sample[2], int plane_index, int bits)
26+RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb,
27+ int w, TYPE *sample[2], int plane_index, int bits)
2828 {
2929 PlaneContext *const p = &s->plane[plane_index];
3030 RangeCoder *const c = &s->c;
@@ -33,7 +33,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 2 unmodified lines
3333 int run_mode = 0;
3434 int run_index = sc->run_index;
3535
36− if (is_input_end(s))
36+ if (is_input_end(s, gb))
3737 return AVERROR_INVALIDDATA;
3838
3939 if (s->slice_coding_mode == 1) {
@@ -53,7 +53,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 13 unmodified lines
5353 int diff, context, sign;
5454
5555 if (!(x & 1023)) {
56− if (is_input_end(s))
56+ if (is_input_end(s, gb))
5757 return AVERROR_INVALIDDATA;
5858 }
5959
@@ -74,13 +74,13 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 14 unmodified lines
7474
7575 if (run_mode) {
7676 if (run_count == 0 && run_mode == 1) {
77− if (get_bits1(&s->gb)) {
77+ if (get_bits1(gb)) {
7878 run_count = 1 << ff_log2_run[run_index];
7979 if (x + run_count <= w)
8080 run_index++;
8181 } else {
8282 if (ff_log2_run[run_index])
83− run_count = get_bits(&s->gb, ff_log2_run[run_index]);
83+ run_count = get_bits(gb, ff_log2_run[run_index]);
8484 else
8585 run_count = 0;
8686 if (run_index)
@@ -105,17 +105,17 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 18 unmodified lines
105105 if (run_count < 0) {
106106 run_mode = 0;
107107 run_count = 0;
108− diff = get_vlc_symbol(&s->gb, &p->vlc_state[context],
108+ diff = get_vlc_symbol(gb, &p->vlc_state[context],
109109 bits);
110110 if (diff >= 0)
111111 diff++;
112112 } else
113113 diff = 0;
114114 } else
115− diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);
115+ diff = get_vlc_symbol(gb, &p->vlc_state[context], bits);
116116
117117 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
118− run_count, run_index, run_mode, x, get_bits_count(&s->gb));
118+ run_count, run_index, run_mode, x, get_bits_count(gb));
119119 }
120120
121121 if (sign)
@@ -128,6 +128,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 6 unmodified lines
128128 }
129129
130130 static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc,
131+ GetBitContext *gb,
131132 uint8_t *src[4], int w, int h, int stride[4])
132133 {
133134 int x, y, p;
@@ -157,9 +158,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, · 23 unmodified lines
157158 sample[p][1][-1]= sample[p][0][0 ];
158159 sample[p][0][ w]= sample[p][0][w-1];
159160 if (lbd && s->slice_coding_mode == 0)
160− ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, 9);
161+ ret = RENAME(decode_line)(s, sc, gb, w, sample[p], (p + 1)/2, 9);
161162 else
162− ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
163+ ret = RENAME(decode_line)(s, sc, gb, w, sample[p], (p + 1)/2, bits + (s->slice_coding_mode != 1));
163164 if (ret < 0)
164165 return ret;
165166 }

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