There is no reason to place it in persistent state.
Showing the changes to libavcodec (3 of 3 files). Show all
Unified · Split
| @@ -85,7 +85,6 @@ typedef struct FFV1Context { · 84 unmodified lines | ||
| 85 | 85 | AVClass *class; |
| 86 | 86 | AVCodecContext *avctx; |
| 87 | 87 | RangeCoder c; |
| 88 | − GetBitContext gb; | |
| 89 | 88 | PutBitContext pb; |
| 90 | 89 | uint64_t rc_stat[256][2]; |
| 91 | 90 | uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; |
| @@ -94,14 +94,14 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state, · 93 unmodified lines | ||
| 94 | 94 | return ret; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | −static int is_input_end(FFV1Context *s) | |
| 97 | +static int is_input_end(FFV1Context *s, GetBitContext *gb) | |
| 98 | 98 | { |
| 99 | 99 | if (s->ac != AC_GOLOMB_RICE) { |
| 100 | 100 | RangeCoder *const c = &s->c; |
| 101 | 101 | if (c->overread > MAX_OVERREAD) |
| 102 | 102 | return AVERROR_INVALIDDATA; |
| 103 | 103 | } else { |
| 104 | − if (get_bits_left(&s->gb) < 1) | |
| 104 | + if (get_bits_left(gb) < 1) | |
| 105 | 105 | return AVERROR_INVALIDDATA; |
| 106 | 106 | } |
| 107 | 107 | return 0; |
| @@ -118,6 +118,7 @@ static int is_input_end(FFV1Context *s) · 10 unmodified lines | ||
| 118 | 118 | #include "ffv1dec_template.c" |
| 119 | 119 | |
| 120 | 120 | static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, |
| 121 | + GetBitContext *gb, | |
| 121 | 122 | uint8_t *src, int w, int h, int stride, int plane_index, |
| 122 | 123 | int pixel_stride) |
| 123 | 124 | { |
| @@ -140,13 +141,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext *sc, · 16 unmodified lines | ||
| 140 | 141 | sample[0][w] = sample[0][w - 1]; |
| 141 | 142 | |
| 142 | 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 | 145 | if (ret < 0) |
| 145 | 146 | return ret; |
| 146 | 147 | for (x = 0; x < w; x++) |
| 147 | 148 | src[x*pixel_stride + stride * y] = sample[1][x]; |
| 148 | 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 | 151 | if (ret < 0) |
| 151 | 152 | return ret; |
| 152 | 153 | if (s->packed_at_lsb) { |
| @@ -262,6 +263,7 @@ static int decode_slice(AVCodecContext *c, void *arg) · 109 unmodified lines | ||
| 262 | 263 | AVFrame * const p = f->picture.f; |
| 263 | 264 | const int si = (FFV1Context**)arg - f->slice_context; |
| 264 | 265 | FFV1SliceContext *sc = &f->slices[si]; |
| 266 | + GetBitContext gb; | |
| 265 | 267 | |
| 266 | 268 | if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f) |
| 267 | 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 | 324 | if (f->version == 3 && f->micro_version > 1 || f->version > 3) |
| 323 | 325 | get_rac(&fs->c, (uint8_t[]) { 129 }); |
| 324 | 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 | 328 | fs->c.bytestream_start + fs->ac_byte_count, |
| 327 | 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 | 335 | const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift); |
| 334 | 336 | const int cx = x >> f->chroma_h_shift; |
| 335 | 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 | 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); | |
| 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); | |
| 341 | 343 | } |
| 342 | 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 | 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); | |
| 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); | |
| 347 | 349 | } else if (f->use32bit) { |
| 348 | 350 | uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], |
| 349 | 351 | p->data[1] + ps * x + y * p->linesize[1], |
| 350 | 352 | p->data[2] + ps * x + y * p->linesize[2], |
| 351 | 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 | 355 | } else { |
| 354 | 356 | uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0], |
| 355 | 357 | p->data[1] + ps * x + y * p->linesize[1], |
| 356 | 358 | p->data[2] + ps * x + y * p->linesize[2], |
| 357 | 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 | 362 | if (fs->ac != AC_GOLOMB_RICE && f->version > 2) { |
| 361 | 363 | int v; |
| @@ -23,8 +23,8 @@ · 22 unmodified lines | ||
| 23 | 23 | #include "ffv1_template.c" |
| 24 | 24 | |
| 25 | 25 | 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) | |
| 28 | 28 | { |
| 29 | 29 | PlaneContext *const p = &s->plane[plane_index]; |
| 30 | 30 | RangeCoder *const c = &s->c; |
| @@ -33,7 +33,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 2 unmodified lines | ||
| 33 | 33 | int run_mode = 0; |
| 34 | 34 | int run_index = sc->run_index; |
| 35 | 35 | |
| 36 | − if (is_input_end(s)) | |
| 36 | + if (is_input_end(s, gb)) | |
| 37 | 37 | return AVERROR_INVALIDDATA; |
| 38 | 38 | |
| 39 | 39 | if (s->slice_coding_mode == 1) { |
| @@ -53,7 +53,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 13 unmodified lines | ||
| 53 | 53 | int diff, context, sign; |
| 54 | 54 | |
| 55 | 55 | if (!(x & 1023)) { |
| 56 | − if (is_input_end(s)) | |
| 56 | + if (is_input_end(s, gb)) | |
| 57 | 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 | 75 | if (run_mode) { |
| 76 | 76 | if (run_count == 0 && run_mode == 1) { |
| 77 | − if (get_bits1(&s->gb)) { | |
| 77 | + if (get_bits1(gb)) { | |
| 78 | 78 | run_count = 1 << ff_log2_run[run_index]; |
| 79 | 79 | if (x + run_count <= w) |
| 80 | 80 | run_index++; |
| 81 | 81 | } else { |
| 82 | 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 | 84 | else |
| 85 | 85 | run_count = 0; |
| 86 | 86 | if (run_index) |
| @@ -105,17 +105,17 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 18 unmodified lines | ||
| 105 | 105 | if (run_count < 0) { |
| 106 | 106 | run_mode = 0; |
| 107 | 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 | 109 | bits); |
| 110 | 110 | if (diff >= 0) |
| 111 | 111 | diff++; |
| 112 | 112 | } else |
| 113 | 113 | diff = 0; |
| 114 | 114 | } 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 | 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 | 121 | if (sign) |
| @@ -128,6 +128,7 @@ RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w, · 6 unmodified lines | ||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, |
| 131 | + GetBitContext *gb, | |
| 131 | 132 | uint8_t *src[4], int w, int h, int stride[4]) |
| 132 | 133 | { |
| 133 | 134 | int x, y, p; |
| @@ -157,9 +158,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, FFV1SliceContext *sc, · 23 unmodified lines | ||
| 157 | 158 | sample[p][1][-1]= sample[p][0][0 ]; |
| 158 | 159 | sample[p][0][ w]= sample[p][0][w-1]; |
| 159 | 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 | 162 | 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 | 164 | if (ret < 0) |
| 164 | 165 | return ret; |
| 165 | 166 | } |