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

Showing the changes to libavcodec (3 of 3 files). Show all

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
85 AVClass *class;85 AVClass *class;
86 AVCodecContext *avctx;86 AVCodecContext *avctx;
87 RangeCoder c;87 RangeCoder c;
88 GetBitContext gb;
89 PutBitContext pb;88 PutBitContext pb;
90 uint64_t rc_stat[256][2];89 uint64_t rc_stat[256][2];
91 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];90 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
94 return ret;94 return ret;
95}95}
96 96
97static int is_input_end(FFV1Context *s)97static int is_input_end(FFV1Context *s, GetBitContext *gb)
98{98{
99 if (s->ac != AC_GOLOMB_RICE) {99 if (s->ac != AC_GOLOMB_RICE) {
100 RangeCoder *const c = &s->c;100 RangeCoder *const c = &s->c;
101 if (c->overread > MAX_OVERREAD)101 if (c->overread > MAX_OVERREAD)
102 return AVERROR_INVALIDDATA;102 return AVERROR_INVALIDDATA;
103 } else {103 } else {
104 if (get_bits_left(&s->gb) < 1)104 if (get_bits_left(gb) < 1)
105 return AVERROR_INVALIDDATA;105 return AVERROR_INVALIDDATA;
106 }106 }
107 return 0;107 return 0;
@@ -118,6 +118,7 @@ static int is_input_end(FFV1Context *s) · 10 unmodified lines
118#include "ffv1dec_template.c"118#include "ffv1dec_template.c"
119 119
120static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,120static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
121 GetBitContext *gb,
121 uint8_t *src, int w, int h, int stride, int plane_index,122 uint8_t *src, int w, int h, int stride, int plane_index,
122 int pixel_stride)123 int pixel_stride)
123{124{
@@ -140,13 +141,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, · 16 unmodified lines
140 sample[0][w] = sample[0][w - 1];141 sample[0][w] = sample[0][w - 1];
141 142
142 if (s->avctx->bits_per_raw_sample <= 8) {143 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);
144 if (ret < 0)145 if (ret < 0)
145 return ret;146 return ret;
146 for (x = 0; x < w; x++)147 for (x = 0; x < w; x++)
147 src[x*pixel_stride + stride * y] = sample[1][x];148 src[x*pixel_stride + stride * y] = sample[1][x];
148 } else {149 } 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);
150 if (ret < 0)151 if (ret < 0)
151 return ret;152 return ret;
152 if (s->packed_at_lsb) {153 if (s->packed_at_lsb) {
@@ -262,6 +263,7 @@ static int decode_slice(AVCodecContext *c, void *arg) · 109 unmodified lines
262 AVFrame * const p = f->picture.f;263 AVFrame * const p = f->picture.f;
263 const int si = (FFV1Context**)arg - f->slice_context;264 const int si = (FFV1Context**)arg - f->slice_context;
264 FFV1SliceContext *sc = &f->slices[si];265 FFV1SliceContext *sc = &f->slices[si];
266 GetBitContext gb;
265 267
266 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)268 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
267 ff_progress_frame_await(&f->last_picture, si);269 ff_progress_frame_await(&f->last_picture, si);
@@ -322,7 +324,7 @@ static int decode_slice(AVCodecContext *c, void *arg) · 54 unmodified lines
322 if (f->version == 3 && f->micro_version > 1 || f->version > 3)324 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
323 get_rac(&fs->c, (uint8_t[]) { 129 });325 get_rac(&fs->c, (uint8_t[]) { 129 });
324 fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0;326 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,
326 fs->c.bytestream_start + fs->ac_byte_count,328 fs->c.bytestream_start + fs->ac_byte_count,
327 (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8);329 (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8);
328 }330 }
@@ -333,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg) · 4 unmodified lines
333 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);335 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
334 const int cx = x >> f->chroma_h_shift;336 const int cx = x >> f->chroma_h_shift;
335 const int cy = y >> f->chroma_v_shift;337 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);
337 339
338 if (f->chroma_planes) {340 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);341 decode_plane(fs, sc, &gb, 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);342 decode_plane(fs, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
341 }343 }
342 if (fs->transparency)344 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);
344 } else if (f->colorspace == 0) {346 } 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);347 decode_plane(fs, sc, &gb, 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);348 decode_plane(fs, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2);
347 } else if (f->use32bit) {349 } else if (f->use32bit) {
348 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],350 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
349 p->data[1] + ps * x + y * p->linesize[1],351 p->data[1] + ps * x + y * p->linesize[1],
350 p->data[2] + ps * x + y * p->linesize[2],352 p->data[2] + ps * x + y * p->linesize[2],
351 p->data[3] + ps * x + y * p->linesize[3] };353 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);
353 } else {355 } else {
354 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],356 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
355 p->data[1] + ps * x + y * p->linesize[1],357 p->data[1] + ps * x + y * p->linesize[1],
356 p->data[2] + ps * x + y * p->linesize[2],358 p->data[2] + ps * x + y * p->linesize[2],
357 p->data[3] + ps * x + y * p->linesize[3] };359 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);
359 }361 }
360 if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {362 if (fs->ac != AC_GOLOMB_RICE && f->version > 2) {
361 int v;363 int v;
libavcodec/ffv1dec_template.c+12−11
@@ -23,8 +23,8 @@ · 22 unmodified lines
23#include "ffv1_template.c"23#include "ffv1_template.c"
24 24
25static av_always_inline int25static av_always_inline int
26RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w,26RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, GetBitContext *gb,
27 TYPE *sample[2], int plane_index, int bits)27 int w, TYPE *sample[2], int plane_index, int bits)
28{28{
29 PlaneContext *const p = &s->plane[plane_index];29 PlaneContext *const p = &s->plane[plane_index];
30 RangeCoder *const c = &s->c;30 RangeCoder *const c = &s->c;
@@ -33,7 +33,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 2 unmodified lines
33 int run_mode = 0;33 int run_mode = 0;
34 int run_index = sc->run_index;34 int run_index = sc->run_index;
35 35
36 if (is_input_end(s))36 if (is_input_end(s, gb))
37 return AVERROR_INVALIDDATA;37 return AVERROR_INVALIDDATA;
38 38
39 if (s->slice_coding_mode == 1) {39 if (s->slice_coding_mode == 1) {
@@ -53,7 +53,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 13 unmodified lines
53 int diff, context, sign;53 int diff, context, sign;
54 54
55 if (!(x & 1023)) {55 if (!(x & 1023)) {
56 if (is_input_end(s))56 if (is_input_end(s, gb))
57 return AVERROR_INVALIDDATA;57 return AVERROR_INVALIDDATA;
58 }58 }
59 59
@@ -74,13 +74,13 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 14 unmodified lines
74 74
75 if (run_mode) {75 if (run_mode) {
76 if (run_count == 0 && run_mode == 1) {76 if (run_count == 0 && run_mode == 1) {
77 if (get_bits1(&s->gb)) {77 if (get_bits1(gb)) {
78 run_count = 1 << ff_log2_run[run_index];78 run_count = 1 << ff_log2_run[run_index];
79 if (x + run_count <= w)79 if (x + run_count <= w)
80 run_index++;80 run_index++;
81 } else {81 } else {
82 if (ff_log2_run[run_index])82 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]);
84 else84 else
85 run_count = 0;85 run_count = 0;
86 if (run_index)86 if (run_index)
@@ -105,17 +105,17 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 18 unmodified lines
105 if (run_count < 0) {105 if (run_count < 0) {
106 run_mode = 0;106 run_mode = 0;
107 run_count = 0;107 run_count = 0;
108 diff = get_vlc_symbol(&s->gb, &p->vlc_state[context],108 diff = get_vlc_symbol(gb, &p->vlc_state[context],
109 bits);109 bits);
110 if (diff >= 0)110 if (diff >= 0)
111 diff++;111 diff++;
112 } else112 } else
113 diff = 0;113 diff = 0;
114 } else114 } else
115 diff = get_vlc_symbol(&s->gb, &p->vlc_state[context], bits);115 diff = get_vlc_symbol(gb, &p->vlc_state[context], bits);
116 116
117 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",117 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));
119 }119 }
120 120
121 if (sign)121 if (sign)
@@ -128,6 +128,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 6 unmodified lines
128}128}
129 129
130static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc,130static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc,
131 GetBitContext *gb,
131 uint8_t *src[4], int w, int h, int stride[4])132 uint8_t *src[4], int w, int h, int stride[4])
132{133{
133 int x, y, p;134 int x, y, p;
@@ -157,9 +158,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, · 23 unmodified lines
157 sample[p][1][-1]= sample[p][0][0 ];158 sample[p][1][-1]= sample[p][0][0 ];
158 sample[p][0][ w]= sample[p][0][w-1];159 sample[p][0][ w]= sample[p][0][w-1];
159 if (lbd && s->slice_coding_mode == 0)160 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);
161 else162 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));
163 if (ret < 0)164 if (ret < 0)
164 return ret;165 return ret;
165 }166 }

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