FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1dec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 415 674 61.6%
Functions: 14 16 87.5%
Branches: 290 598 48.5%

Line Branch Exec Source
1 /*
2 * FFV1 decoder
3 *
4 * Copyright (c) 2003-2013 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * FF Video Codec 1 (a lossless codec) decoder
26 */
27
28 #include "libavutil/avassert.h"
29 #include "libavutil/crc.h"
30 #include "libavutil/mem.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/pixdesc.h"
33 #include "avcodec.h"
34 #include "codec_internal.h"
35 #include "get_bits.h"
36 #include "rangecoder.h"
37 #include "golomb.h"
38 #include "mathops.h"
39 #include "ffv1.h"
40 #include "progressframe.h"
41 #include "refstruct.h"
42 #include "thread.h"
43
44 186054274 static inline av_flatten int get_symbol_inline(RangeCoder *c, uint8_t *state,
45 int is_signed)
46 {
47
2/2
✓ Branch 1 taken 73471470 times.
✓ Branch 2 taken 112582804 times.
186054274 if (get_rac(c, state + 0))
48 73471470 return 0;
49 else {
50 int e;
51 unsigned a;
52 112582804 e = 0;
53
4/4
✓ Branch 0 taken 679792725 times.
✓ Branch 1 taken 45940109 times.
✓ Branch 3 taken 613150030 times.
✓ Branch 4 taken 112582804 times.
725732834 while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10
54 613150030 e++;
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 613150030 times.
613150030 if (e > 31)
56 return AVERROR_INVALIDDATA;
57 }
58
59 112582804 a = 1;
60
2/2
✓ Branch 0 taken 613150030 times.
✓ Branch 1 taken 112582804 times.
725732834 for (int i = e - 1; i >= 0; i--)
61
2/2
✓ Branch 0 taken 592636133 times.
✓ Branch 1 taken 20513897 times.
613150030 a += a + get_rac(c, state + 22 + FFMIN(i, 9)); // 22..31
62
63
6/6
✓ Branch 0 taken 112555754 times.
✓ Branch 1 taken 27050 times.
✓ Branch 2 taken 101153362 times.
✓ Branch 3 taken 11402392 times.
✓ Branch 5 taken 61676531 times.
✓ Branch 6 taken 50879223 times.
112582804 e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21
64 112582804 return (a ^ e) - e;
65 }
66 }
67
68 3308302 static av_noinline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed)
69 {
70 3308302 return get_symbol_inline(c, state, is_signed);
71 }
72
73 167385877 static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state,
74 int bits)
75 {
76 int k, i, v, ret;
77
78 167385877 i = state->count;
79 167385877 k = 0;
80
2/2
✓ Branch 0 taken 280052558 times.
✓ Branch 1 taken 167385877 times.
447438435 while (i < state->error_sum) { // FIXME: optimize
81 280052558 k++;
82 280052558 i += i;
83 }
84
85 167385877 v = get_sr_golomb(gb, k, 12, bits);
86 ff_dlog(NULL, "v:%d bias:%d error:%d drift:%d count:%d k:%d",
87 v, state->bias, state->error_sum, state->drift, state->count, k);
88
89 167385877 v ^= ((2 * state->drift + state->count) >> 31);
90
91 167385877 ret = fold(v + state->bias, bits);
92
93 167385877 update_vlc_state(state, v);
94
95 167385877 return ret;
96 }
97
98 4596384 static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac)
99 {
100
2/2
✓ Branch 0 taken 2582376 times.
✓ Branch 1 taken 2014008 times.
4596384 if (ac != AC_GOLOMB_RICE) {
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2582376 times.
2582376 if (c->overread > MAX_OVERREAD)
102 return AVERROR_INVALIDDATA;
103 } else {
104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2014008 times.
2014008 if (get_bits_left(gb) < 1)
105 return AVERROR_INVALIDDATA;
106 }
107 4596384 return 0;
108 }
109
110 #define TYPE int16_t
111 #define RENAME(name) name
112 #include "ffv1dec_template.c"
113 #undef TYPE
114 #undef RENAME
115
116 #define TYPE int32_t
117 #define RENAME(name) name ## 32
118 #include "ffv1dec_template.c"
119
120 18249 static int decode_plane(FFV1Context *f, FFV1SliceContext *sc,
121 GetBitContext *gb,
122 uint8_t *src, int w, int h, int stride, int plane_index,
123 int pixel_stride, int ac)
124 {
125 int x, y;
126 int16_t *sample[2];
127 18249 sample[0] = sc->sample_buffer + 3;
128 18249 sample[1] = sc->sample_buffer + w + 6 + 3;
129
130 18249 sc->run_index = 0;
131
132 18249 memset(sc->sample_buffer, 0, 2 * (w + 6) * sizeof(*sc->sample_buffer));
133
134
2/2
✓ Branch 0 taken 1748616 times.
✓ Branch 1 taken 18249 times.
1766865 for (y = 0; y < h; y++) {
135 1748616 int16_t *temp = sample[0]; // FIXME: try a normal buffer
136
137 1748616 sample[0] = sample[1];
138 1748616 sample[1] = temp;
139
140 1748616 sample[1][-1] = sample[0][0];
141 1748616 sample[0][w] = sample[0][w - 1];
142
143
2/2
✓ Branch 0 taken 915612 times.
✓ Branch 1 taken 833004 times.
1748616 if (f->avctx->bits_per_raw_sample <= 8) {
144 915612 int ret = decode_line(f, sc, gb, w, sample, plane_index, 8, ac);
145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 915612 times.
915612 if (ret < 0)
146 return ret;
147
2/2
✓ Branch 0 taken 148622082 times.
✓ Branch 1 taken 915612 times.
149537694 for (x = 0; x < w; x++)
148 148622082 src[x*pixel_stride + stride * y] = sample[1][x];
149 } else {
150 833004 int ret = decode_line(f, sc, gb, w, sample, plane_index, f->avctx->bits_per_raw_sample, ac);
151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 833004 times.
833004 if (ret < 0)
152 return ret;
153
1/2
✓ Branch 0 taken 833004 times.
✗ Branch 1 not taken.
833004 if (f->packed_at_lsb) {
154
2/2
✓ Branch 0 taken 112679724 times.
✓ Branch 1 taken 833004 times.
113512728 for (x = 0; x < w; x++) {
155 112679724 ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x];
156 }
157 } else {
158 for (x = 0; x < w; x++) {
159 ((uint16_t*)(src + stride*y))[x*pixel_stride] = sample[1][x] << (16 - f->avctx->bits_per_raw_sample) | ((uint16_t **)sample)[1][x] >> (2 * f->avctx->bits_per_raw_sample - 16);
160 }
161 }
162 }
163 }
164 18249 return 0;
165 }
166
167 6644 static int decode_slice_header(const FFV1Context *f,
168 FFV1SliceContext *sc, AVFrame *frame)
169 {
170 6644 RangeCoder *c = &sc->c;
171 uint8_t state[CONTEXT_SIZE];
172 unsigned ps, context_count;
173 int sx, sy, sw, sh;
174
175 6644 memset(state, 128, sizeof(state));
176 6644 sx = get_symbol(c, state, 0);
177 6644 sy = get_symbol(c, state, 0);
178 6644 sw = get_symbol(c, state, 0) + 1U;
179 6644 sh = get_symbol(c, state, 0) + 1U;
180
181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6644 times.
6644 av_assert0(f->version > 2);
182
183
184
4/8
✓ Branch 0 taken 6644 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6644 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6644 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6644 times.
6644 if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0)
185 return AVERROR_INVALIDDATA;
186
2/4
✓ Branch 0 taken 6644 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6644 times.
6644 if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh)
187 return AVERROR_INVALIDDATA;
188
189 6644 sc->slice_x = ff_slice_coord(f, f->width , sx , f->num_h_slices, f->chroma_h_shift);
190 6644 sc->slice_y = ff_slice_coord(f, f->height, sy , f->num_v_slices, f->chroma_v_shift);
191 6644 sc->slice_width = ff_slice_coord(f, f->width , sx + sw, f->num_h_slices, f->chroma_h_shift) - sc->slice_x;
192 6644 sc->slice_height = ff_slice_coord(f, f->height, sy + sh, f->num_v_slices, f->chroma_v_shift) - sc->slice_y;
193
194
2/4
✓ Branch 0 taken 6644 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6644 times.
6644 av_assert0((unsigned)sc->slice_width <= f->width &&
195 (unsigned)sc->slice_height <= f->height);
196
2/4
✓ Branch 0 taken 6644 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6644 times.
6644 av_assert0 ( (unsigned)sc->slice_x + (uint64_t)sc->slice_width <= f->width
197 && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height);
198
199
3/4
✓ Branch 0 taken 2556 times.
✓ Branch 1 taken 4088 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2556 times.
6644 if (f->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23))
200 return AVERROR_INVALIDDATA;
201
202
2/2
✓ Branch 0 taken 13288 times.
✓ Branch 1 taken 6644 times.
19932 for (unsigned i = 0; i < f->plane_count; i++) {
203 13288 PlaneContext * const p = &sc->plane[i];
204 13288 int idx = get_symbol(c, state, 0);
205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13288 times.
13288 if (idx >= (unsigned)f->quant_table_count) {
206 av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");
207 return -1;
208 }
209 13288 p->quant_table_index = idx;
210 13288 context_count = f->context_count[idx];
211
212
2/2
✓ Branch 0 taken 1592 times.
✓ Branch 1 taken 11696 times.
13288 if (p->context_count < context_count) {
213 1592 av_freep(&p->state);
214 1592 av_freep(&p->vlc_state);
215 }
216 13288 p->context_count = context_count;
217 }
218
219 6644 ps = get_symbol(c, state, 0);
220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6644 times.
6644 if (ps == 1) {
221 frame->flags |= AV_FRAME_FLAG_INTERLACED;
222 frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
223
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6644 times.
6644 } else if (ps == 2) {
224 frame->flags |= AV_FRAME_FLAG_INTERLACED;
225 frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
226
1/2
✓ Branch 0 taken 6644 times.
✗ Branch 1 not taken.
6644 } else if (ps == 3) {
227 6644 frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
228 }
229 6644 frame->sample_aspect_ratio.num = get_symbol(c, state, 0);
230 6644 frame->sample_aspect_ratio.den = get_symbol(c, state, 0);
231
232
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6644 times.
6644 if (av_image_check_sar(f->width, f->height,
233 frame->sample_aspect_ratio) < 0) {
234 av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
235 frame->sample_aspect_ratio.num,
236 frame->sample_aspect_ratio.den);
237 frame->sample_aspect_ratio = (AVRational){ 0, 1 };
238 }
239
240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6644 times.
6644 if (f->version > 3) {
241 sc->slice_reset_contexts = get_rac(c, state);
242 sc->slice_coding_mode = get_symbol(c, state, 0);
243 if (sc->slice_coding_mode != 1 && f->colorspace == 1) {
244 sc->slice_rct_by_coef = get_symbol(c, state, 0);
245 sc->slice_rct_ry_coef = get_symbol(c, state, 0);
246 if ((uint64_t)sc->slice_rct_by_coef + (uint64_t)sc->slice_rct_ry_coef > 4) {
247 av_log(f->avctx, AV_LOG_ERROR, "slice_rct_y_coef out of range\n");
248 return AVERROR_INVALIDDATA;
249 }
250 }
251 }
252
253 6644 return 0;
254 }
255
256 static void slice_set_damaged(FFV1Context *f, FFV1SliceContext *sc)
257 {
258 sc->slice_damaged = 1;
259
260 // only set this for frame threading, as for slice threading its value is
261 // not used and setting it would be a race
262 if (f->avctx->active_thread_type & FF_THREAD_FRAME)
263 f->frame_damaged = 1;
264 }
265
266 7715 static int decode_slice(AVCodecContext *c, void *arg)
267 {
268 7715 FFV1Context *f = c->priv_data;
269 7715 FFV1SliceContext *sc = arg;
270 int width, height, x, y, ret;
271 7715 const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
272 7715 AVFrame * const p = f->picture.f;
273 7715 const int si = sc - f->slices;
274 GetBitContext gb;
275
3/4
✓ Branch 0 taken 3627 times.
✓ Branch 1 taken 4088 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3627 times.
7715 int ac = f->ac || sc->slice_coding_mode == 1;
276
277
3/4
✓ Branch 0 taken 6793 times.
✓ Branch 1 taken 922 times.
✓ Branch 2 taken 6793 times.
✗ Branch 3 not taken.
7715 if (!(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
278 6793 ff_progress_frame_await(&f->last_picture, si);
279
280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7715 times.
7715 if (f->slice_damaged[si])
281 slice_set_damaged(f, sc);
282
283 7715 sc->slice_rct_by_coef = 1;
284 7715 sc->slice_rct_ry_coef = 1;
285
286
2/2
✓ Branch 0 taken 6644 times.
✓ Branch 1 taken 1071 times.
7715 if (f->version > 2) {
287
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6644 times.
6644 if (ff_ffv1_init_slice_state(f, sc) < 0)
288 return AVERROR(ENOMEM);
289
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6644 times.
6644 if (decode_slice_header(f, sc, p) < 0) {
290 sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0;
291 slice_set_damaged(f, sc);
292 return AVERROR_INVALIDDATA;
293 }
294 }
295
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7715 times.
7715 if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0)
296 return ret;
297
3/4
✓ Branch 0 taken 6793 times.
✓ Branch 1 taken 922 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6793 times.
7715 if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
298 922 ff_ffv1_clear_slice_state(f, sc);
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6793 times.
6793 } else if (sc->slice_damaged) {
300 return AVERROR_INVALIDDATA;
301 }
302
303 7715 width = sc->slice_width;
304 7715 height = sc->slice_height;
305 7715 x = sc->slice_x;
306 7715 y = sc->slice_y;
307
308
2/2
✓ Branch 0 taken 3627 times.
✓ Branch 1 taken 4088 times.
7715 if (ac == AC_GOLOMB_RICE) {
309
4/6
✓ Branch 0 taken 2556 times.
✓ Branch 1 taken 1071 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2556 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1071 times.
3627 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
310 2556 get_rac(&sc->c, (uint8_t[]) { 129 });
311
6/6
✓ Branch 0 taken 1071 times.
✓ Branch 1 taken 2556 times.
✓ Branch 2 taken 663 times.
✓ Branch 3 taken 408 times.
✓ Branch 4 taken 459 times.
✓ Branch 5 taken 204 times.
3627 sc->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0;
312 3627 init_get_bits(&gb,
313 3627 sc->c.bytestream_start + sc->ac_byte_count,
314 3627 (sc->c.bytestream_end - sc->c.bytestream_start - sc->ac_byte_count) * 8);
315 }
316
317 av_assert1(width && height);
318
3/6
✓ Branch 0 taken 6083 times.
✓ Branch 1 taken 1632 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6083 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
13798 if (f->colorspace == 0 && (f->chroma_planes || !f->transparency)) {
319 6083 const int chroma_width = AV_CEIL_RSHIFT(width, f->chroma_h_shift);
320 6083 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
321 6083 const int cx = x >> f->chroma_h_shift;
322 6083 const int cy = y >> f->chroma_v_shift;
323 6083 decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0, 1, ac);
324
325
1/2
✓ Branch 0 taken 6083 times.
✗ Branch 1 not taken.
6083 if (f->chroma_planes) {
326 6083 decode_plane(f, sc, &gb, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1, ac);
327 6083 decode_plane(f, sc, &gb, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1, ac);
328 }
329
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6083 times.
6083 if (f->transparency)
330 decode_plane(f, 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, ac);
331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1632 times.
1632 } else if (f->colorspace == 0) {
332 decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] , width, height, p->linesize[0], 0, 2, ac);
333 decode_plane(f, sc, &gb, p->data[0] + ps*x + y*p->linesize[0] + 1, width, height, p->linesize[0], 1, 2, ac);
334
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 816 times.
1632 } else if (f->use32bit) {
335 816 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
336 816 p->data[1] + ps * x + y * p->linesize[1],
337 816 p->data[2] + ps * x + y * p->linesize[2],
338 816 p->data[3] + ps * x + y * p->linesize[3] };
339 816 decode_rgb_frame32(f, sc, &gb, planes, width, height, p->linesize);
340 } else {
341 816 uint8_t *planes[4] = { p->data[0] + ps * x + y * p->linesize[0],
342 816 p->data[1] + ps * x + y * p->linesize[1],
343 816 p->data[2] + ps * x + y * p->linesize[2],
344 816 p->data[3] + ps * x + y * p->linesize[3] };
345 816 decode_rgb_frame(f, sc, &gb, planes, width, height, p->linesize);
346 }
347
3/4
✓ Branch 0 taken 4088 times.
✓ Branch 1 taken 3627 times.
✓ Branch 2 taken 4088 times.
✗ Branch 3 not taken.
7715 if (ac != AC_GOLOMB_RICE && f->version > 2) {
348 int v;
349 4088 get_rac(&sc->c, (uint8_t[]) { 129 });
350
1/2
✓ Branch 0 taken 4088 times.
✗ Branch 1 not taken.
4088 v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*!!f->ec;
351
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4088 times.
4088 if (v) {
352 av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v);
353 slice_set_damaged(f, sc);
354 }
355 }
356
357
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7715 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7715 if (sc->slice_damaged && (f->avctx->err_recognition & AV_EF_EXPLODE))
358 return AVERROR_INVALIDDATA;
359
360
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7715 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7715 if ((c->active_thread_type & FF_THREAD_FRAME) && !f->frame_damaged)
361 ff_progress_frame_report(&f->picture, si);
362
363 7715 return 0;
364 }
365
366 930 static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale)
367 {
368 int v;
369 930 int i = 0;
370 uint8_t state[CONTEXT_SIZE];
371
372 930 memset(state, 128, sizeof(state));
373
374
2/2
✓ Branch 0 taken 3623 times.
✓ Branch 1 taken 930 times.
4553 for (v = 0; i < 128; v++) {
375 3623 unsigned len = get_symbol(c, state, 0) + 1U;
376
377
2/4
✓ Branch 0 taken 3623 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3623 times.
3623 if (len > 128 - i || !len)
378 return AVERROR_INVALIDDATA;
379
380
2/2
✓ Branch 0 taken 119040 times.
✓ Branch 1 taken 3623 times.
122663 while (len--) {
381 119040 quant_table[i] = scale * v;
382 119040 i++;
383 }
384 }
385
386
2/2
✓ Branch 0 taken 118110 times.
✓ Branch 1 taken 930 times.
119040 for (i = 1; i < 128; i++)
387 118110 quant_table[256 - i] = -quant_table[i];
388 930 quant_table[128] = -quant_table[127];
389
390 930 return 2 * v - 1;
391 }
392
393 186 static int read_quant_tables(RangeCoder *c,
394 int16_t quant_table[MAX_CONTEXT_INPUTS][256])
395 {
396 int i;
397 186 int context_count = 1;
398
399
2/2
✓ Branch 0 taken 930 times.
✓ Branch 1 taken 186 times.
1116 for (i = 0; i < 5; i++) {
400 930 int ret = read_quant_table(c, quant_table[i], context_count);
401
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
930 if (ret < 0)
402 return ret;
403 930 context_count *= ret;
404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 930 times.
930 if (context_count > 32768U) {
405 return AVERROR_INVALIDDATA;
406 }
407 }
408 186 return (context_count + 1) / 2;
409 }
410
411 78 static int read_extra_header(FFV1Context *f)
412 {
413 RangeCoder c;
414 uint8_t state[CONTEXT_SIZE];
415 int ret;
416 uint8_t state2[32][CONTEXT_SIZE];
417 78 unsigned crc = 0;
418
419 78 memset(state2, 128, sizeof(state2));
420 78 memset(state, 128, sizeof(state));
421
422 78 ff_init_range_decoder(&c, f->avctx->extradata, f->avctx->extradata_size);
423 78 ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8);
424
425 78 f->version = get_symbol(&c, state, 0);
426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if (f->version < 2) {
427 av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n");
428 return AVERROR_INVALIDDATA;
429 }
430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if (f->version > 4) {
431 av_log(f->avctx, AV_LOG_ERROR, "unsupported version %d\n",
432 f->version);
433 return AVERROR_PATCHWELCOME;
434 }
435
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 8 times.
78 if (f->version > 2) {
436 70 c.bytestream_end -= 4;
437 70 f->micro_version = get_symbol(&c, state, 0);
438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (f->micro_version < 0)
439 return AVERROR_INVALIDDATA;
440 }
441 78 f->ac = get_symbol(&c, state, 0);
442
443
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 35 times.
78 if (f->ac == AC_RANGE_CUSTOM_TAB) {
444
2/2
✓ Branch 0 taken 10965 times.
✓ Branch 1 taken 43 times.
11008 for (int i = 1; i < 256; i++)
445 10965 f->state_transition[i] = get_symbol(&c, state, 1) + c.one_state[i];
446 }
447
448 78 f->colorspace = get_symbol(&c, state, 0); //YUV cs type
449 78 f->avctx->bits_per_raw_sample = get_symbol(&c, state, 0);
450 78 f->chroma_planes = get_rac(&c, state);
451 78 f->chroma_h_shift = get_symbol(&c, state, 0);
452 78 f->chroma_v_shift = get_symbol(&c, state, 0);
453 78 f->transparency = get_rac(&c, state);
454
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
78 f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency;
455 78 f->num_h_slices = 1 + get_symbol(&c, state, 0);
456 78 f->num_v_slices = 1 + get_symbol(&c, state, 0);
457
458
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 78 times.
78 if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) {
459 av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n",
460 f->chroma_h_shift, f->chroma_v_shift);
461 return AVERROR_INVALIDDATA;
462 }
463
464
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
✗ Branch 3 not taken.
78 if (f->num_h_slices > (unsigned)f->width || !f->num_h_slices ||
465
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 78 times.
78 f->num_v_slices > (unsigned)f->height || !f->num_v_slices
466 ) {
467 av_log(f->avctx, AV_LOG_ERROR, "slice count invalid\n");
468 return AVERROR_INVALIDDATA;
469 }
470
471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if (f->num_h_slices > MAX_SLICES / f->num_v_slices) {
472 av_log(f->avctx, AV_LOG_ERROR, "slice count unsupported\n");
473 return AVERROR_PATCHWELCOME;
474 }
475
476 78 f->quant_table_count = get_symbol(&c, state, 0);
477
2/4
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 78 times.
78 if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) {
478 av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count);
479 f->quant_table_count = 0;
480 return AVERROR_INVALIDDATA;
481 }
482
483
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 78 times.
234 for (int i = 0; i < f->quant_table_count; i++) {
484 156 f->context_count[i] = read_quant_tables(&c, f->quant_tables[i]);
485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 156 times.
156 if (f->context_count[i] < 0) {
486 av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
487 return AVERROR_INVALIDDATA;
488 }
489 }
490
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 78 times.
78 if ((ret = ff_ffv1_allocate_initial_states(f)) < 0)
491 return ret;
492
493
2/2
✓ Branch 0 taken 156 times.
✓ Branch 1 taken 78 times.
234 for (int i = 0; i < f->quant_table_count; i++)
494
2/2
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 140 times.
156 if (get_rac(&c, state)) {
495
2/2
✓ Branch 0 taken 101008 times.
✓ Branch 1 taken 16 times.
101024 for (int j = 0; j < f->context_count[i]; j++)
496
2/2
✓ Branch 0 taken 3232256 times.
✓ Branch 1 taken 101008 times.
3333264 for (int k = 0; k < CONTEXT_SIZE; k++) {
497
2/2
✓ Branch 0 taken 3231744 times.
✓ Branch 1 taken 512 times.
3232256 int pred = j ? f->initial_states[i][j - 1][k] : 128;
498 3232256 f->initial_states[i][j][k] =
499 3232256 (pred + get_symbol(&c, state2[k], 1)) & 0xFF;
500 }
501 }
502
503
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 8 times.
78 if (f->version > 2) {
504 70 f->ec = get_symbol(&c, state, 0);
505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (f->ec >= 2)
506 f->crcref = 0x7a8c4079;
507
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
70 if (f->micro_version > 2)
508 70 f->intra = get_symbol(&c, state, 0);
509 }
510
511
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 8 times.
78 if (f->version > 2) {
512 unsigned v;
513 140 v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref,
514 70 f->avctx->extradata, f->avctx->extradata_size);
515
2/4
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 70 times.
70 if (v != f->crcref || f->avctx->extradata_size < 4) {
516 av_log(f->avctx, AV_LOG_ERROR, "CRC mismatch %X!\n", v);
517 return AVERROR_INVALIDDATA;
518 }
519 70 crc = AV_RB32(f->avctx->extradata + f->avctx->extradata_size - 4);
520 }
521
522
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if (f->avctx->debug & FF_DEBUG_PICT_INFO)
523 av_log(f->avctx, AV_LOG_DEBUG,
524 "global: ver:%d.%d, coder:%d, colorspace: %d bpr:%d chroma:%d(%d:%d), alpha:%d slices:%dx%d qtabs:%d ec:%d intra:%d CRC:0x%08X\n",
525 f->version, f->micro_version,
526 f->ac,
527 f->colorspace,
528 f->avctx->bits_per_raw_sample,
529 f->chroma_planes, f->chroma_h_shift, f->chroma_v_shift,
530 f->transparency,
531 f->num_h_slices, f->num_v_slices,
532 f->quant_table_count,
533 f->ec,
534 f->intra,
535 crc
536 );
537 78 return 0;
538 }
539
540 253 static int read_header(FFV1Context *f)
541 {
542 uint8_t state[CONTEXT_SIZE];
543 253 int context_count = -1; //-1 to avoid warning
544 253 RangeCoder *const c = &f->slices[0].c;
545
546 253 memset(state, 128, sizeof(state));
547
548
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 223 times.
253 if (f->version < 2) {
549 int chroma_planes, chroma_h_shift, chroma_v_shift, transparency, colorspace, bits_per_raw_sample;
550 30 unsigned v= get_symbol(c, state, 0);
551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (v >= 2) {
552 av_log(f->avctx, AV_LOG_ERROR, "invalid version %d in ver01 header\n", v);
553 return AVERROR_INVALIDDATA;
554 }
555 30 f->version = v;
556 30 f->ac = get_symbol(c, state, 0);
557
558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (f->ac == AC_RANGE_CUSTOM_TAB) {
559 for (int i = 1; i < 256; i++) {
560 int st = get_symbol(c, state, 1) + c->one_state[i];
561 if (st < 1 || st > 255) {
562 av_log(f->avctx, AV_LOG_ERROR, "invalid state transition %d\n", st);
563 return AVERROR_INVALIDDATA;
564 }
565 f->state_transition[i] = st;
566 }
567 }
568
569 30 colorspace = get_symbol(c, state, 0); //YUV cs type
570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 bits_per_raw_sample = f->version > 0 ? get_symbol(c, state, 0) : f->avctx->bits_per_raw_sample;
571 30 chroma_planes = get_rac(c, state);
572 30 chroma_h_shift = get_symbol(c, state, 0);
573 30 chroma_v_shift = get_symbol(c, state, 0);
574 30 transparency = get_rac(c, state);
575
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
30 if (colorspace == 0 && f->avctx->skip_alpha)
576 transparency = 0;
577
578
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 10 times.
30 if (f->plane_count) {
579
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (colorspace != f->colorspace ||
580
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 bits_per_raw_sample != f->avctx->bits_per_raw_sample ||
581
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 chroma_planes != f->chroma_planes ||
582
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 chroma_h_shift != f->chroma_h_shift ||
583
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 chroma_v_shift != f->chroma_v_shift ||
584
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 transparency != f->transparency) {
585 av_log(f->avctx, AV_LOG_ERROR, "Invalid change of global parameters\n");
586 return AVERROR_INVALIDDATA;
587 }
588 }
589
590
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
30 if (chroma_h_shift > 4U || chroma_v_shift > 4U) {
591 av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n",
592 chroma_h_shift, chroma_v_shift);
593 return AVERROR_INVALIDDATA;
594 }
595
596 30 f->colorspace = colorspace;
597 30 f->avctx->bits_per_raw_sample = bits_per_raw_sample;
598 30 f->chroma_planes = chroma_planes;
599 30 f->chroma_h_shift = chroma_h_shift;
600 30 f->chroma_v_shift = chroma_v_shift;
601 30 f->transparency = transparency;
602
603 30 f->plane_count = 2 + f->transparency;
604 }
605
606
2/2
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 48 times.
253 if (f->colorspace == 0) {
607
2/4
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 205 times.
205 if (!f->transparency && !f->chroma_planes) {
608 if (f->avctx->bits_per_raw_sample <= 8)
609 f->avctx->pix_fmt = AV_PIX_FMT_GRAY8;
610 else if (f->avctx->bits_per_raw_sample == 9) {
611 f->packed_at_lsb = 1;
612 f->avctx->pix_fmt = AV_PIX_FMT_GRAY9;
613 } else if (f->avctx->bits_per_raw_sample == 10) {
614 f->packed_at_lsb = 1;
615 f->avctx->pix_fmt = AV_PIX_FMT_GRAY10;
616 } else if (f->avctx->bits_per_raw_sample == 12) {
617 f->packed_at_lsb = 1;
618 f->avctx->pix_fmt = AV_PIX_FMT_GRAY12;
619 } else if (f->avctx->bits_per_raw_sample == 14) {
620 f->packed_at_lsb = 1;
621 f->avctx->pix_fmt = AV_PIX_FMT_GRAY14;
622 } else if (f->avctx->bits_per_raw_sample == 16) {
623 f->packed_at_lsb = 1;
624 f->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
625 } else if (f->avctx->bits_per_raw_sample < 16) {
626 f->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
627 } else
628 return AVERROR(ENOSYS);
629
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 205 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
205 } else if (f->transparency && !f->chroma_planes) {
630 if (f->avctx->bits_per_raw_sample <= 8)
631 f->avctx->pix_fmt = AV_PIX_FMT_YA8;
632 else
633 return AVERROR(ENOSYS);
634
3/4
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 131 times.
✗ Branch 3 not taken.
205 } else if (f->avctx->bits_per_raw_sample<=8 && !f->transparency) {
635
1/7
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 131 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
131 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
636 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P; break;
637 case 0x01: f->avctx->pix_fmt = AV_PIX_FMT_YUV440P; break;
638 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P; break;
639 131 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P; break;
640 case 0x20: f->avctx->pix_fmt = AV_PIX_FMT_YUV411P; break;
641 case 0x22: f->avctx->pix_fmt = AV_PIX_FMT_YUV410P; break;
642 }
643
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
74 } else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency) {
644 switch(16*f->chroma_h_shift + f->chroma_v_shift) {
645 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P; break;
646 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P; break;
647 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P; break;
648 }
649
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
74 } else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency) {
650 f->packed_at_lsb = 1;
651 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
652 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P9; break;
653 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P9; break;
654 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P9; break;
655 }
656
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 74 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
74 } else if (f->avctx->bits_per_raw_sample == 9 && f->transparency) {
657 f->packed_at_lsb = 1;
658 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
659 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P9; break;
660 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P9; break;
661 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P9; break;
662 }
663
3/4
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
74 } else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency) {
664 50 f->packed_at_lsb = 1;
665
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
50 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
666 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P10; break;
667 case 0x01: f->avctx->pix_fmt = AV_PIX_FMT_YUV440P10; break;
668 50 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P10; break;
669 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P10; break;
670 }
671
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 } else if (f->avctx->bits_per_raw_sample == 10 && f->transparency) {
672 f->packed_at_lsb = 1;
673 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
674 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P10; break;
675 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P10; break;
676 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P10; break;
677 }
678
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 } else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency) {
679 f->packed_at_lsb = 1;
680 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
681 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P12; break;
682 case 0x01: f->avctx->pix_fmt = AV_PIX_FMT_YUV440P12; break;
683 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P12; break;
684 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P12; break;
685 }
686
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 } else if (f->avctx->bits_per_raw_sample == 12 && f->transparency) {
687 f->packed_at_lsb = 1;
688 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
689 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P12; break;
690 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P12; break;
691 }
692
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 } else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency) {
693 f->packed_at_lsb = 1;
694 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
695 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P14; break;
696 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P14; break;
697 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P14; break;
698 }
699
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 } else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency){
700 24 f->packed_at_lsb = 1;
701
1/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
702 24 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUV444P16; break;
703 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUV422P16; break;
704 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUV420P16; break;
705 }
706 } else if (f->avctx->bits_per_raw_sample == 16 && f->transparency){
707 f->packed_at_lsb = 1;
708 switch(16 * f->chroma_h_shift + f->chroma_v_shift) {
709 case 0x00: f->avctx->pix_fmt = AV_PIX_FMT_YUVA444P16; break;
710 case 0x10: f->avctx->pix_fmt = AV_PIX_FMT_YUVA422P16; break;
711 case 0x11: f->avctx->pix_fmt = AV_PIX_FMT_YUVA420P16; break;
712 }
713 }
714
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 } else if (f->colorspace == 1) {
715
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48 times.
48 if (f->chroma_h_shift || f->chroma_v_shift) {
716 av_log(f->avctx, AV_LOG_ERROR,
717 "chroma subsampling not supported in this colorspace\n");
718 return AVERROR(ENOSYS);
719 }
720
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
48 if ( f->avctx->bits_per_raw_sample <= 8 && !f->transparency)
721 24 f->avctx->pix_fmt = AV_PIX_FMT_0RGB32;
722
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample <= 8 && f->transparency)
723 f->avctx->pix_fmt = AV_PIX_FMT_RGB32;
724
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample == 9 && !f->transparency)
725 f->avctx->pix_fmt = AV_PIX_FMT_GBRP9;
726
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample == 10 && !f->transparency)
727 f->avctx->pix_fmt = AV_PIX_FMT_GBRP10;
728
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample == 10 && f->transparency)
729 f->avctx->pix_fmt = AV_PIX_FMT_GBRAP10;
730
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample == 12 && !f->transparency)
731 f->avctx->pix_fmt = AV_PIX_FMT_GBRP12;
732
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample == 12 && f->transparency)
733 f->avctx->pix_fmt = AV_PIX_FMT_GBRAP12;
734
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample == 14 && !f->transparency)
735 f->avctx->pix_fmt = AV_PIX_FMT_GBRP14;
736
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample == 14 && f->transparency)
737 f->avctx->pix_fmt = AV_PIX_FMT_GBRAP14;
738
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
24 else if (f->avctx->bits_per_raw_sample == 16 && !f->transparency) {
739 24 f->avctx->pix_fmt = AV_PIX_FMT_GBRP16;
740 24 f->use32bit = 1;
741 }
742 else if (f->avctx->bits_per_raw_sample == 16 && f->transparency) {
743 f->avctx->pix_fmt = AV_PIX_FMT_GBRAP16;
744 f->use32bit = 1;
745 }
746 } else {
747 av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n");
748 return AVERROR(ENOSYS);
749 }
750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 253 times.
253 if (f->avctx->pix_fmt == AV_PIX_FMT_NONE) {
751 av_log(f->avctx, AV_LOG_ERROR, "format not supported\n");
752 return AVERROR(ENOSYS);
753 }
754
755 ff_dlog(f->avctx, "%d %d %d\n",
756 f->chroma_h_shift, f->chroma_v_shift, f->avctx->pix_fmt);
757
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 223 times.
253 if (f->version < 2) {
758 30 context_count = read_quant_tables(c, f->quant_tables[0]);
759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (context_count < 0) {
760 av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
761 return AVERROR_INVALIDDATA;
762 }
763 30 f->slice_count = f->max_slice_count;
764
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 199 times.
223 } else if (f->version < 3) {
765 24 f->slice_count = get_symbol(c, state, 0);
766 } else {
767 199 const uint8_t *p = c->bytestream_end;
768 199 for (f->slice_count = 0;
769
4/6
✓ Branch 0 taken 995 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 995 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 796 times.
✓ Branch 5 taken 199 times.
995 f->slice_count < MAX_SLICES && 3 + 5*!!f->ec < p - c->bytestream_start;
770 796 f->slice_count++) {
771
1/2
✓ Branch 0 taken 796 times.
✗ Branch 1 not taken.
796 int trailer = 3 + 5*!!f->ec;
772 796 int size = AV_RB24(p-trailer);
773
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 796 times.
796 if (size + trailer > p - c->bytestream_start)
774 break;
775 796 p -= size + trailer;
776 }
777 }
778
3/6
✓ Branch 0 taken 253 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 253 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 253 times.
253 if (f->slice_count > (unsigned)MAX_SLICES || f->slice_count <= 0 || f->slice_count > f->max_slice_count) {
779 av_log(f->avctx, AV_LOG_ERROR, "slice count %d is invalid (max=%d)\n", f->slice_count, f->max_slice_count);
780 return AVERROR_INVALIDDATA;
781 }
782
783 253 ff_refstruct_unref(&f->slice_damaged);
784 253 f->slice_damaged = ff_refstruct_allocz(f->slice_count * sizeof(*f->slice_damaged));
785
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 253 times.
253 if (!f->slice_damaged)
786 return AVERROR(ENOMEM);
787
788
2/2
✓ Branch 0 taken 922 times.
✓ Branch 1 taken 253 times.
1175 for (int j = 0; j < f->slice_count; j++) {
789 922 FFV1SliceContext *sc = &f->slices[j];
790
791
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 826 times.
922 if (f->version == 2) {
792 96 int sx = get_symbol(c, state, 0);
793 96 int sy = get_symbol(c, state, 0);
794 96 int sw = get_symbol(c, state, 0) + 1U;
795 96 int sh = get_symbol(c, state, 0) + 1U;
796
797
4/8
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 96 times.
96 if (sx < 0 || sy < 0 || sw <= 0 || sh <= 0)
798 return AVERROR_INVALIDDATA;
799
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
96 if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh)
800 return AVERROR_INVALIDDATA;
801
802 96 sc->slice_x = sx * (int64_t)f->width / f->num_h_slices;
803 96 sc->slice_y = sy * (int64_t)f->height / f->num_v_slices;
804 96 sc->slice_width = (sx + sw) * (int64_t)f->width / f->num_h_slices - sc->slice_x;
805 96 sc->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - sc->slice_y;
806
807
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
96 av_assert0((unsigned)sc->slice_width <= f->width &&
808 (unsigned)sc->slice_height <= f->height);
809
2/4
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 96 times.
96 av_assert0 ( (unsigned)sc->slice_x + (uint64_t)sc->slice_width <= f->width
810 && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= f->height);
811 }
812
813 922 ff_refstruct_unref(&sc->plane);
814 922 sc->plane = ff_ffv1_planes_alloc();
815
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 922 times.
922 if (!sc->plane)
816 return AVERROR(ENOMEM);
817
818
2/2
✓ Branch 0 taken 1844 times.
✓ Branch 1 taken 922 times.
2766 for (int i = 0; i < f->plane_count; i++) {
819 1844 PlaneContext *const p = &sc->plane[i];
820
821
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 1652 times.
1844 if (f->version == 2) {
822 192 int idx = get_symbol(c, state, 0);
823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 192 times.
192 if (idx >= (unsigned)f->quant_table_count) {
824 av_log(f->avctx, AV_LOG_ERROR,
825 "quant_table_index out of range\n");
826 return AVERROR_INVALIDDATA;
827 }
828 192 p->quant_table_index = idx;
829 192 context_count = f->context_count[idx];
830 }
831
832
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 1592 times.
1844 if (f->version <= 2) {
833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 av_assert0(context_count >= 0);
834 252 p->context_count = context_count;
835 }
836 }
837 }
838 253 return 0;
839 }
840
841 88 static av_cold int decode_init(AVCodecContext *avctx)
842 {
843 88 FFV1Context *f = avctx->priv_data;
844 int ret;
845
846
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
88 if ((ret = ff_ffv1_common_init(avctx)) < 0)
847 return ret;
848
849
3/4
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 78 times.
88 if (avctx->extradata_size > 0 && (ret = read_extra_header(f)) < 0)
850 return ret;
851
852
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
88 if ((ret = ff_ffv1_init_slice_contexts(f)) < 0)
853 return ret;
854
855 88 return 0;
856 }
857
858 2120 static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
859 int *got_frame, AVPacket *avpkt)
860 {
861 2120 uint8_t *buf = avpkt->data;
862 2120 int buf_size = avpkt->size;
863 2120 FFV1Context *f = avctx->priv_data;
864 2120 RangeCoder *const c = &f->slices[0].c;
865 int ret, key_frame;
866 2120 uint8_t keystate = 128;
867 uint8_t *buf_p;
868 AVFrame *p;
869
870 2120 ff_progress_frame_unref(&f->last_picture);
871 2120 FFSWAP(ProgressFrame, f->picture, f->last_picture);
872
873
874 2120 f->avctx = avctx;
875 2120 f->frame_damaged = 0;
876 2120 ff_init_range_decoder(c, buf, buf_size);
877 2120 ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);
878
879
2/2
✓ Branch 1 taken 253 times.
✓ Branch 2 taken 1867 times.
2120 if (get_rac(c, &keystate)) {
880 253 key_frame = AV_FRAME_FLAG_KEY;
881 253 f->key_frame_ok = 0;
882
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 253 times.
253 if ((ret = read_header(f)) < 0)
883 return ret;
884 253 f->key_frame_ok = 1;
885 } else {
886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1867 times.
1867 if (!f->key_frame_ok) {
887 av_log(avctx, AV_LOG_ERROR,
888 "Cannot decode non-keyframe without valid keyframe\n");
889 return AVERROR_INVALIDDATA;
890 }
891 1867 key_frame = 0;
892 }
893
894
2/2
✓ Branch 0 taken 1022 times.
✓ Branch 1 taken 1098 times.
2120 if (f->ac != AC_GOLOMB_RICE) {
895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1022 times.
1022 if (buf_size < avctx->width * avctx->height / (128*8))
896 return AVERROR_INVALIDDATA;
897 } else {
898 1098 int w = avctx->width;
899 1098 int s = 1 + w / (1<<23);
900 int i;
901
902 1098 w /= s;
903
904
2/2
✓ Branch 0 taken 25232 times.
✓ Branch 1 taken 1098 times.
26330 for (i = 0; w > (1<<ff_log2_run[i]); i++)
905 25232 w -= ff_log2_run[i];
906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1098 times.
1098 if (buf_size < (avctx->height + i + 6) / 8 * s)
907 return AVERROR_INVALIDDATA;
908 }
909
910 2120 ret = ff_progress_frame_get_buffer(avctx, &f->picture,
911 AV_GET_BUFFER_FLAG_REF);
912
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2120 times.
2120 if (ret < 0)
913 return ret;
914
915 2120 p = f->picture.f;
916
917 2120 p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P
918 2120 p->flags = (p->flags & ~AV_FRAME_FLAG_KEY) | key_frame;
919
920
3/4
✓ Branch 0 taken 459 times.
✓ Branch 1 taken 1661 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 459 times.
2120 if (f->version < 3 && avctx->field_order > AV_FIELD_PROGRESSIVE) {
921 /* we have interlaced material flagged in container */
922 p->flags |= AV_FRAME_FLAG_INTERLACED;
923 if (avctx->field_order == AV_FIELD_TT || avctx->field_order == AV_FIELD_TB)
924 p->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
925 }
926
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2120 times.
2120 if (avctx->debug & FF_DEBUG_PICT_INFO)
928 av_log(avctx, AV_LOG_DEBUG, "ver:%d keyframe:%d coder:%d ec:%d slices:%d bps:%d\n",
929 f->version, !!(p->flags & AV_FRAME_FLAG_KEY), f->ac, f->ec, f->slice_count, f->avctx->bits_per_raw_sample);
930
931 2120 ff_thread_finish_setup(avctx);
932
933 2120 buf_p = buf + buf_size;
934
2/2
✓ Branch 0 taken 7715 times.
✓ Branch 1 taken 2120 times.
9835 for (int i = f->slice_count - 1; i >= 0; i--) {
935 7715 FFV1SliceContext *sc = &f->slices[i];
936
2/2
✓ Branch 0 taken 6644 times.
✓ Branch 1 taken 1071 times.
7715 int trailer = 3 + 5*!!f->ec;
937 int v;
938
939 7715 sc->slice_damaged = 0;
940
941
4/4
✓ Branch 0 taken 2120 times.
✓ Branch 1 taken 5595 times.
✓ Branch 2 taken 1661 times.
✓ Branch 3 taken 459 times.
7715 if (i || f->version > 2) {
942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7256 times.
7256 if (trailer > buf_p - buf) v = INT_MAX;
943 7256 else v = AV_RB24(buf_p-trailer) + trailer;
944 459 } else v = buf_p - c->bytestream_start;
945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7715 times.
7715 if (buf_p - c->bytestream_start < v) {
946 av_log(avctx, AV_LOG_ERROR, "Slice pointer chain broken\n");
947 ff_progress_frame_report(&f->picture, INT_MAX);
948 return AVERROR_INVALIDDATA;
949 }
950 7715 buf_p -= v;
951
952
2/2
✓ Branch 0 taken 6644 times.
✓ Branch 1 taken 1071 times.
7715 if (f->ec) {
953 6644 unsigned crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), f->crcref, buf_p, v);
954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6644 times.
6644 if (crc != f->crcref) {
955 int64_t ts = avpkt->pts != AV_NOPTS_VALUE ? avpkt->pts : avpkt->dts;
956 av_log(f->avctx, AV_LOG_ERROR, "slice CRC mismatch %X!", crc);
957 if (ts != AV_NOPTS_VALUE && avctx->pkt_timebase.num) {
958 av_log(f->avctx, AV_LOG_ERROR, "at %f seconds\n", ts*av_q2d(avctx->pkt_timebase));
959 } else if (ts != AV_NOPTS_VALUE) {
960 av_log(f->avctx, AV_LOG_ERROR, "at %"PRId64"\n", ts);
961 } else {
962 av_log(f->avctx, AV_LOG_ERROR, "\n");
963 }
964 slice_set_damaged(f, sc);
965 }
966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6644 times.
6644 if (avctx->debug & FF_DEBUG_PICT_INFO) {
967 av_log(avctx, AV_LOG_DEBUG, "slice %d, CRC: 0x%08"PRIX32"\n", i, AV_RB32(buf_p + v - 4));
968 }
969 }
970
971
2/2
✓ Branch 0 taken 5595 times.
✓ Branch 1 taken 2120 times.
7715 if (i) {
972 5595 ff_init_range_decoder(&sc->c, buf_p, v);
973 5595 ff_build_rac_states(&sc->c, 0.05 * (1LL << 32), 256 - 8);
974 } else
975 2120 sc->c.bytestream_end = buf_p + v;
976
977 }
978
979 2120 avctx->execute(avctx,
980 decode_slice,
981 2120 f->slices,
982 NULL,
983 f->slice_count,
984 sizeof(*f->slices));
985
986
2/2
✓ Branch 0 taken 7715 times.
✓ Branch 1 taken 2120 times.
9835 for (int i = f->slice_count - 1; i >= 0; i--) {
987 7715 FFV1SliceContext *sc = &f->slices[i];
988
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7715 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7715 if (sc->slice_damaged && f->last_picture.f) {
989 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
990 const uint8_t *src[4];
991 uint8_t *dst[4];
992 ff_progress_frame_await(&f->last_picture, INT_MAX);
993 for (int j = 0; j < desc->nb_components; j++) {
994 int pixshift = desc->comp[j].depth > 8;
995 int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0;
996 int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0;
997 dst[j] = p->data[j] + p->linesize[j] *
998 (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift);
999 src[j] = f->last_picture.f->data[j] + f->last_picture.f->linesize[j] *
1000 (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift);
1001
1002 }
1003
1004 av_image_copy(dst, p->linesize, src,
1005 f->last_picture.f->linesize,
1006 avctx->pix_fmt,
1007 sc->slice_width,
1008 sc->slice_height);
1009
1010 f->slice_damaged[i] = 1;
1011 }
1012 }
1013 2120 ff_progress_frame_report(&f->picture, INT_MAX);
1014
1015 2120 ff_progress_frame_unref(&f->last_picture);
1016
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2120 times.
2120 if ((ret = av_frame_ref(rframe, f->picture.f)) < 0)
1017 return ret;
1018
1019 2120 *got_frame = 1;
1020
1021 2120 return buf_size;
1022 }
1023
1024 #if HAVE_THREADS
1025 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1026 {
1027 FFV1Context *fsrc = src->priv_data;
1028 FFV1Context *fdst = dst->priv_data;
1029
1030 if (dst == src)
1031 return 0;
1032
1033 fdst->version = fsrc->version;
1034 fdst->micro_version = fsrc->micro_version;
1035 fdst->chroma_planes = fsrc->chroma_planes;
1036 fdst->chroma_h_shift = fsrc->chroma_h_shift;
1037 fdst->chroma_v_shift = fsrc->chroma_v_shift;
1038 fdst->transparency = fsrc->transparency;
1039 fdst->plane_count = fsrc->plane_count;
1040 fdst->ac = fsrc->ac;
1041 fdst->colorspace = fsrc->colorspace;
1042
1043 fdst->ec = fsrc->ec;
1044 fdst->intra = fsrc->intra;
1045 fdst->key_frame_ok = fsrc->key_frame_ok;
1046
1047 fdst->packed_at_lsb = fsrc->packed_at_lsb;
1048 fdst->slice_count = fsrc->slice_count;
1049 fdst->use32bit = fsrc->use32bit;
1050 memcpy(fdst->state_transition, fsrc->state_transition,
1051 sizeof(fdst->state_transition));
1052
1053 // in version 1 there is a single per-keyframe quant table, so
1054 // we need to propagate it between threads
1055 if (fsrc->version < 2)
1056 memcpy(fdst->quant_tables[0], fsrc->quant_tables[0], sizeof(fsrc->quant_tables[0]));
1057
1058 for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) {
1059 FFV1SliceContext *sc = &fdst->slices[i];
1060 const FFV1SliceContext *sc0 = &fsrc->slices[i];
1061
1062 ff_refstruct_replace(&sc->plane, sc0->plane);
1063
1064 if (fsrc->version < 3) {
1065 sc->slice_x = sc0->slice_x;
1066 sc->slice_y = sc0->slice_y;
1067 sc->slice_width = sc0->slice_width;
1068 sc->slice_height = sc0->slice_height;
1069 }
1070 }
1071
1072 ff_refstruct_replace(&fdst->slice_damaged, fsrc->slice_damaged);
1073
1074 av_assert1(fdst->max_slice_count == fsrc->max_slice_count);
1075
1076 ff_progress_frame_replace(&fdst->picture, &fsrc->picture);
1077
1078 return 0;
1079 }
1080 #endif
1081
1082 88 static av_cold int ffv1_decode_close(AVCodecContext *avctx)
1083 {
1084 88 FFV1Context *const s = avctx->priv_data;
1085
1086 88 ff_progress_frame_unref(&s->picture);
1087 88 ff_progress_frame_unref(&s->last_picture);
1088
1089 88 return ff_ffv1_close(avctx);
1090 }
1091
1092 const FFCodec ff_ffv1_decoder = {
1093 .p.name = "ffv1",
1094 CODEC_LONG_NAME("FFmpeg video codec #1"),
1095 .p.type = AVMEDIA_TYPE_VIDEO,
1096 .p.id = AV_CODEC_ID_FFV1,
1097 .priv_data_size = sizeof(FFV1Context),
1098 .init = decode_init,
1099 .close = ffv1_decode_close,
1100 FF_CODEC_DECODE_CB(decode_frame),
1101 UPDATE_THREAD_CONTEXT(update_thread_context),
1102 .p.capabilities = AV_CODEC_CAP_DR1 |
1103 AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
1104 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1105 FF_CODEC_CAP_USES_PROGRESSFRAMES,
1106 };
1107