FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ffv1dec.c
Date: 2023-10-02 11:06:47
Exec Total Coverage
Lines: 405 702 57.7%
Functions: 14 16 87.5%
Branches: 270 606 44.6%

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