FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/proresdec2.c
Date: 2022-01-22 23:30:28
Exec Total Coverage
Lines: 361 458 78.8%
Branches: 185 275 67.3%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2010-2011 Maxim Poliakovski
3 * Copyright (c) 2010-2011 Elvis Presley
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Known FOURCCs: 'apch' (HQ), 'apcn' (SD), 'apcs' (LT), 'acpo' (Proxy), 'ap4h' (4444)
25 */
26
27 //#define DEBUG
28
29 #define LONG_BITSTREAM_READER
30
31 #include "libavutil/internal.h"
32 #include "libavutil/mem_internal.h"
33
34 #include "avcodec.h"
35 #include "get_bits.h"
36 #include "hwconfig.h"
37 #include "idctdsp.h"
38 #include "internal.h"
39 #include "profiles.h"
40 #include "simple_idct.h"
41 #include "proresdec.h"
42 #include "proresdata.h"
43 #include "thread.h"
44
45 2254 static void permute(uint8_t *dst, const uint8_t *src, const uint8_t permutation[64])
46 {
47 int i;
48
2/2
✓ Branch 0 taken 144256 times.
✓ Branch 1 taken 2254 times.
146510 for (i = 0; i < 64; i++)
49 144256 dst[i] = permutation[src[i]];
50 2254 }
51
52 #define ALPHA_SHIFT_16_TO_10(alpha_val) (alpha_val >> 6)
53 #define ALPHA_SHIFT_8_TO_10(alpha_val) ((alpha_val << 2) | (alpha_val >> 6))
54 #define ALPHA_SHIFT_16_TO_12(alpha_val) (alpha_val >> 4)
55 #define ALPHA_SHIFT_8_TO_12(alpha_val) ((alpha_val << 4) | (alpha_val >> 4))
56
57 5100 static void inline unpack_alpha(GetBitContext *gb, uint16_t *dst, int num_coeffs,
58 const int num_bits, const int decode_precision) {
59 5100 const int mask = (1 << num_bits) - 1;
60 int i, idx, val, alpha_val;
61
62 5100 idx = 0;
63 5100 alpha_val = mask;
64 do {
65 do {
66
2/2
✓ Branch 1 taken 43404 times.
✓ Branch 2 taken 14996 times.
58400 if (get_bits1(gb)) {
67 43404 val = get_bits(gb, num_bits);
68 } else {
69 int sign;
70
1/2
✓ Branch 0 taken 14996 times.
✗ Branch 1 not taken.
14996 val = get_bits(gb, num_bits == 16 ? 7 : 4);
71 14996 sign = val & 1;
72 14996 val = (val + 2) >> 1;
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14996 times.
14996 if (sign)
74 val = -val;
75 }
76 58400 alpha_val = (alpha_val + val) & mask;
77
1/2
✓ Branch 0 taken 58400 times.
✗ Branch 1 not taken.
58400 if (num_bits == 16) {
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 58400 times.
58400 if (decode_precision == 10) {
79 dst[idx++] = ALPHA_SHIFT_16_TO_10(alpha_val);
80 } else { /* 12b */
81 58400 dst[idx++] = ALPHA_SHIFT_16_TO_12(alpha_val);
82 }
83 } else {
84 if (decode_precision == 10) {
85 dst[idx++] = ALPHA_SHIFT_8_TO_10(alpha_val);
86 } else { /* 12b */
87 dst[idx++] = ALPHA_SHIFT_8_TO_12(alpha_val);
88 }
89 }
90
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 58364 times.
58400 if (idx >= num_coeffs)
91 36 break;
92
4/4
✓ Branch 1 taken 45296 times.
✓ Branch 2 taken 13068 times.
✓ Branch 4 taken 20848 times.
✓ Branch 5 taken 24448 times.
58364 } while (get_bits_left(gb)>0 && get_bits1(gb));
93 37552 val = get_bits(gb, 4);
94
2/2
✓ Branch 0 taken 35779 times.
✓ Branch 1 taken 1773 times.
37552 if (!val)
95 35779 val = get_bits(gb, 11);
96
2/2
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 37412 times.
37552 if (idx + val > num_coeffs)
97 140 val = num_coeffs - idx;
98
1/2
✓ Branch 0 taken 37552 times.
✗ Branch 1 not taken.
37552 if (num_bits == 16) {
99
2/2
✓ Branch 0 taken 10386400 times.
✓ Branch 1 taken 37552 times.
10423952 for (i = 0; i < val; i++) {
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10386400 times.
10386400 if (decode_precision == 10) {
101 dst[idx++] = ALPHA_SHIFT_16_TO_10(alpha_val);
102 } else { /* 12b */
103 10386400 dst[idx++] = ALPHA_SHIFT_16_TO_12(alpha_val);
104 }
105 }
106 } else {
107 for (i = 0; i < val; i++) {
108 if (decode_precision == 10) {
109 dst[idx++] = ALPHA_SHIFT_8_TO_10(alpha_val);
110 } else { /* 12b */
111 dst[idx++] = ALPHA_SHIFT_8_TO_12(alpha_val);
112 }
113 }
114 }
115
2/2
✓ Branch 0 taken 32452 times.
✓ Branch 1 taken 5100 times.
37552 } while (idx < num_coeffs);
116 5100 }
117
118 static void unpack_alpha_10(GetBitContext *gb, uint16_t *dst, int num_coeffs,
119 const int num_bits)
120 {
121 if (num_bits == 16) {
122 unpack_alpha(gb, dst, num_coeffs, 16, 10);
123 } else { /* 8 bits alpha */
124 unpack_alpha(gb, dst, num_coeffs, 8, 10);
125 }
126 }
127
128 5100 static void unpack_alpha_12(GetBitContext *gb, uint16_t *dst, int num_coeffs,
129 const int num_bits)
130 {
131
1/2
✓ Branch 0 taken 5100 times.
✗ Branch 1 not taken.
5100 if (num_bits == 16) {
132 5100 unpack_alpha(gb, dst, num_coeffs, 16, 12);
133 } else { /* 8 bits alpha */
134 unpack_alpha(gb, dst, num_coeffs, 8, 12);
135 }
136 5100 }
137
138 69 static av_cold int decode_init(AVCodecContext *avctx)
139 {
140 69 int ret = 0;
141 69 ProresContext *ctx = avctx->priv_data;
142 uint8_t idct_permutation[64];
143
144 69 avctx->bits_per_raw_sample = 10;
145
146
5/7
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
69 switch (avctx->codec_tag) {
147 10 case MKTAG('a','p','c','o'):
148 10 avctx->profile = FF_PROFILE_PRORES_PROXY;
149 10 break;
150 2 case MKTAG('a','p','c','s'):
151 2 avctx->profile = FF_PROFILE_PRORES_LT;
152 2 break;
153 21 case MKTAG('a','p','c','n'):
154 21 avctx->profile = FF_PROFILE_PRORES_STANDARD;
155 21 break;
156 12 case MKTAG('a','p','c','h'):
157 12 avctx->profile = FF_PROFILE_PRORES_HQ;
158 12 break;
159 24 case MKTAG('a','p','4','h'):
160 24 avctx->profile = FF_PROFILE_PRORES_4444;
161 24 avctx->bits_per_raw_sample = 12;
162 24 break;
163 case MKTAG('a','p','4','x'):
164 avctx->profile = FF_PROFILE_PRORES_XQ;
165 avctx->bits_per_raw_sample = 12;
166 break;
167 default:
168 avctx->profile = FF_PROFILE_UNKNOWN;
169 av_log(avctx, AV_LOG_WARNING, "Unknown prores profile %d\n", avctx->codec_tag);
170 }
171
172
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 24 times.
69 if (avctx->bits_per_raw_sample == 10) {
173 45 av_log(avctx, AV_LOG_DEBUG, "Auto bitdepth precision. Use 10b decoding based on codec tag.\n");
174 } else { /* 12b */
175 24 av_log(avctx, AV_LOG_DEBUG, "Auto bitdepth precision. Use 12b decoding based on codec tag.\n");
176 }
177
178 69 ff_blockdsp_init(&ctx->bdsp, avctx);
179 69 ret = ff_proresdsp_init(&ctx->prodsp, avctx);
180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
69 if (ret < 0) {
181 av_log(avctx, AV_LOG_ERROR, "Fail to init proresdsp for bits per raw sample %d\n", avctx->bits_per_raw_sample);
182 return ret;
183 }
184
185 69 ff_init_scantable_permutation(idct_permutation,
186 69 ctx->prodsp.idct_permutation_type);
187
188 69 permute(ctx->progressive_scan, ff_prores_progressive_scan, idct_permutation);
189 69 permute(ctx->interlaced_scan, ff_prores_interlaced_scan, idct_permutation);
190
191 69 ctx->pix_fmt = AV_PIX_FMT_NONE;
192
193
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 24 times.
69 if (avctx->bits_per_raw_sample == 10){
194 45 ctx->unpack_alpha = unpack_alpha_10;
195
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 } else if (avctx->bits_per_raw_sample == 12){
196 24 ctx->unpack_alpha = unpack_alpha_12;
197 } else {
198 av_log(avctx, AV_LOG_ERROR, "Fail to set unpack_alpha for bits per raw sample %d\n", avctx->bits_per_raw_sample);
199 return AVERROR_BUG;
200 }
201 69 return ret;
202 }
203
204 1058 static int decode_frame_header(ProresContext *ctx, const uint8_t *buf,
205 const int data_size, AVCodecContext *avctx)
206 {
207 int hdr_size, width, height, flags;
208 int version;
209 const uint8_t *ptr;
210 enum AVPixelFormat pix_fmt;
211
212 1058 hdr_size = AV_RB16(buf);
213 ff_dlog(avctx, "header size %d\n", hdr_size);
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 if (hdr_size > data_size) {
215 av_log(avctx, AV_LOG_ERROR, "error, wrong header size\n");
216 return AVERROR_INVALIDDATA;
217 }
218
219 1058 version = AV_RB16(buf + 2);
220 ff_dlog(avctx, "%.4s version %d\n", buf+4, version);
221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 if (version > 1) {
222 av_log(avctx, AV_LOG_ERROR, "unsupported version: %d\n", version);
223 return AVERROR_PATCHWELCOME;
224 }
225
226 1058 width = AV_RB16(buf + 8);
227 1058 height = AV_RB16(buf + 10);
228
229
2/4
✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1058 times.
1058 if (width != avctx->width || height != avctx->height) {
230 int ret;
231
232 av_log(avctx, AV_LOG_WARNING, "picture resolution change: %dx%d -> %dx%d\n",
233 avctx->width, avctx->height, width, height);
234 if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
235 return ret;
236 }
237
238 1058 ctx->frame_type = (buf[12] >> 2) & 3;
239 1058 ctx->alpha_info = buf[17] & 0xf;
240
241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 if (ctx->alpha_info > 2) {
242 av_log(avctx, AV_LOG_ERROR, "Invalid alpha mode %d\n", ctx->alpha_info);
243 return AVERROR_INVALIDDATA;
244 }
245
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1053 times.
1058 if (avctx->skip_alpha) ctx->alpha_info = 0;
246
247 ff_dlog(avctx, "frame type %d\n", ctx->frame_type);
248
249
2/2
✓ Branch 0 taken 630 times.
✓ Branch 1 taken 428 times.
1058 if (ctx->frame_type == 0) {
250 630 ctx->scan = ctx->progressive_scan; // permuted
251 } else {
252 428 ctx->scan = ctx->interlaced_scan; // permuted
253 428 ctx->frame->interlaced_frame = 1;
254 428 ctx->frame->top_field_first = ctx->frame_type == 1;
255 }
256
257
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1053 times.
1058 if (ctx->alpha_info) {
258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (avctx->bits_per_raw_sample == 10) {
259 pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUVA444P10 : AV_PIX_FMT_YUVA422P10;
260 } else { /* 12b */
261
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUVA444P12 : AV_PIX_FMT_YUVA422P12;
262 }
263 } else {
264
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 413 times.
1053 if (avctx->bits_per_raw_sample == 10) {
265
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 640 times.
640 pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P10 : AV_PIX_FMT_YUV422P10;
266 } else { /* 12b */
267
1/2
✓ Branch 0 taken 413 times.
✗ Branch 1 not taken.
413 pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P12 : AV_PIX_FMT_YUV422P12;
268 }
269 }
270
271
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 991 times.
1058 if (pix_fmt != ctx->pix_fmt) {
272 #define HWACCEL_MAX (CONFIG_PRORES_VIDEOTOOLBOX_HWACCEL)
273 67 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts;
274 int ret;
275
276 67 ctx->pix_fmt = pix_fmt;
277
278 #if CONFIG_PRORES_VIDEOTOOLBOX_HWACCEL
279 *fmtp++ = AV_PIX_FMT_VIDEOTOOLBOX;
280 #endif
281 67 *fmtp++ = ctx->pix_fmt;
282 67 *fmtp = AV_PIX_FMT_NONE;
283
284
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
67 if ((ret = ff_thread_get_format(avctx, pix_fmts)) < 0)
285 return ret;
286
287 67 avctx->pix_fmt = ret;
288 }
289
290 1058 avctx->color_primaries = buf[14];
291 1058 avctx->color_trc = buf[15];
292 1058 avctx->colorspace = buf[16];
293 1058 avctx->color_range = AVCOL_RANGE_MPEG;
294
295 1058 ptr = buf + 20;
296 1058 flags = buf[19];
297 ff_dlog(avctx, "flags %x\n", flags);
298
299
1/2
✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
1058 if (flags & 2) {
300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 if(buf + data_size - ptr < 64) {
301 av_log(avctx, AV_LOG_ERROR, "Header truncated\n");
302 return AVERROR_INVALIDDATA;
303 }
304 1058 permute(ctx->qmat_luma, ctx->prodsp.idct_permutation, ptr);
305 1058 ptr += 64;
306 } else {
307 memset(ctx->qmat_luma, 4, 64);
308 }
309
310
1/2
✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
1058 if (flags & 1) {
311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 if(buf + data_size - ptr < 64) {
312 av_log(avctx, AV_LOG_ERROR, "Header truncated\n");
313 return AVERROR_INVALIDDATA;
314 }
315 1058 permute(ctx->qmat_chroma, ctx->prodsp.idct_permutation, ptr);
316 } else {
317 memcpy(ctx->qmat_chroma, ctx->qmat_luma, 64);
318 }
319
320 1058 return hdr_size;
321 }
322
323 1486 static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, const int buf_size)
324 {
325 1486 ProresContext *ctx = avctx->priv_data;
326 int i, hdr_size, slice_count;
327 unsigned pic_data_size;
328 int log2_slice_mb_width, log2_slice_mb_height;
329 int slice_mb_count, mb_x, mb_y;
330 const uint8_t *data_ptr, *index_ptr;
331
332 1486 hdr_size = buf[0] >> 3;
333
2/4
✓ Branch 0 taken 1486 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1486 times.
1486 if (hdr_size < 8 || hdr_size > buf_size) {
334 av_log(avctx, AV_LOG_ERROR, "error, wrong picture header size\n");
335 return AVERROR_INVALIDDATA;
336 }
337
338 1486 pic_data_size = AV_RB32(buf + 1);
339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1486 times.
1486 if (pic_data_size > buf_size) {
340 av_log(avctx, AV_LOG_ERROR, "error, wrong picture data size\n");
341 return AVERROR_INVALIDDATA;
342 }
343
344 1486 log2_slice_mb_width = buf[7] >> 4;
345 1486 log2_slice_mb_height = buf[7] & 0xF;
346
2/4
✓ Branch 0 taken 1486 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1486 times.
1486 if (log2_slice_mb_width > 3 || log2_slice_mb_height) {
347 av_log(avctx, AV_LOG_ERROR, "unsupported slice resolution: %dx%d\n",
348 1 << log2_slice_mb_width, 1 << log2_slice_mb_height);
349 return AVERROR_INVALIDDATA;
350 }
351
352 1486 ctx->mb_width = (avctx->width + 15) >> 4;
353
2/2
✓ Branch 0 taken 856 times.
✓ Branch 1 taken 630 times.
1486 if (ctx->frame_type)
354 856 ctx->mb_height = (avctx->height + 31) >> 5;
355 else
356 630 ctx->mb_height = (avctx->height + 15) >> 4;
357
358 // QT ignores the written value
359 // slice_count = AV_RB16(buf + 5);
360 1486 slice_count = ctx->mb_height * ((ctx->mb_width >> log2_slice_mb_width) +
361 1486 av_popcount(ctx->mb_width & (1 << log2_slice_mb_width) - 1));
362
363
3/4
✓ Branch 0 taken 1419 times.
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1419 times.
1486 if (ctx->slice_count != slice_count || !ctx->slices) {
364 67 av_freep(&ctx->slices);
365 67 ctx->slice_count = 0;
366 67 ctx->slices = av_calloc(slice_count, sizeof(*ctx->slices));
367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
67 if (!ctx->slices)
368 return AVERROR(ENOMEM);
369 67 ctx->slice_count = slice_count;
370 }
371
372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1486 times.
1486 if (!slice_count)
373 return AVERROR(EINVAL);
374
375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1486 times.
1486 if (hdr_size + slice_count*2 > buf_size) {
376 av_log(avctx, AV_LOG_ERROR, "error, wrong slice count\n");
377 return AVERROR_INVALIDDATA;
378 }
379
380 // parse slice information
381 1486 index_ptr = buf + hdr_size;
382 1486 data_ptr = index_ptr + slice_count*2;
383
384 1486 slice_mb_count = 1 << log2_slice_mb_width;
385 1486 mb_x = 0;
386 1486 mb_y = 0;
387
388
2/2
✓ Branch 0 taken 86520 times.
✓ Branch 1 taken 1486 times.
88006 for (i = 0; i < slice_count; i++) {
389 86520 SliceContext *slice = &ctx->slices[i];
390
391 86520 slice->data = data_ptr;
392 86520 data_ptr += AV_RB16(index_ptr + i*2);
393
394
2/2
✓ Branch 0 taken 30645 times.
✓ Branch 1 taken 86520 times.
117165 while (ctx->mb_width - mb_x < slice_mb_count)
395 30645 slice_mb_count >>= 1;
396
397 86520 slice->mb_x = mb_x;
398 86520 slice->mb_y = mb_y;
399 86520 slice->mb_count = slice_mb_count;
400 86520 slice->data_size = data_ptr - slice->data;
401
402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86520 times.
86520 if (slice->data_size < 6) {
403 av_log(avctx, AV_LOG_ERROR, "error, wrong slice data size\n");
404 return AVERROR_INVALIDDATA;
405 }
406
407 86520 mb_x += slice_mb_count;
408
2/2
✓ Branch 0 taken 16842 times.
✓ Branch 1 taken 69678 times.
86520 if (mb_x == ctx->mb_width) {
409 16842 slice_mb_count = 1 << log2_slice_mb_width;
410 16842 mb_x = 0;
411 16842 mb_y++;
412 }
413
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86520 times.
86520 if (data_ptr > buf + buf_size) {
414 av_log(avctx, AV_LOG_ERROR, "error, slice out of bounds\n");
415 return AVERROR_INVALIDDATA;
416 }
417 }
418
419
2/4
✓ Branch 0 taken 1486 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1486 times.
1486 if (mb_x || mb_y != ctx->mb_height) {
420 av_log(avctx, AV_LOG_ERROR, "error wrong mb count y %d h %d\n",
421 mb_y, ctx->mb_height);
422 return AVERROR_INVALIDDATA;
423 }
424
425 1486 return pic_data_size;
426 }
427
428 #define DECODE_CODEWORD(val, codebook, SKIP) \
429 do { \
430 unsigned int rice_order, exp_order, switch_bits; \
431 unsigned int q, buf, bits; \
432 \
433 UPDATE_CACHE(re, gb); \
434 buf = GET_CACHE(re, gb); \
435 \
436 /* number of bits to switch between rice and exp golomb */ \
437 switch_bits = codebook & 3; \
438 rice_order = codebook >> 5; \
439 exp_order = (codebook >> 2) & 7; \
440 \
441 q = 31 - av_log2(buf); \
442 \
443 if (q > switch_bits) { /* exp golomb */ \
444 bits = exp_order - switch_bits + (q<<1); \
445 if (bits > FFMIN(MIN_CACHE_BITS, 31)) \
446 return AVERROR_INVALIDDATA; \
447 val = SHOW_UBITS(re, gb, bits) - (1 << exp_order) + \
448 ((switch_bits + 1) << rice_order); \
449 SKIP(re, gb, bits); \
450 } else if (rice_order) { \
451 SKIP_BITS(re, gb, q+1); \
452 val = (q << rice_order) + SHOW_UBITS(re, gb, rice_order); \
453 SKIP(re, gb, rice_order); \
454 } else { \
455 val = q; \
456 SKIP(re, gb, q+1); \
457 } \
458 } while (0)
459
460 #define TOSIGNED(x) (((x) >> 1) ^ (-((x) & 1)))
461
462 #define FIRST_DC_CB 0xB8
463
464 static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70};
465
466 258048 static av_always_inline int decode_dc_coeffs(GetBitContext *gb, int16_t *out,
467 int blocks_per_slice)
468 {
469 int16_t prev_dc;
470 int code, i, sign;
471
472 258048 OPEN_READER(re, gb);
473
474
4/6
✓ Branch 0 taken 217613 times.
✓ Branch 1 taken 40435 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 217613 times.
✓ Branch 5 taken 40435 times.
✗ Branch 6 not taken.
258048 DECODE_CODEWORD(code, FIRST_DC_CB, LAST_SKIP_BITS);
475 258048 prev_dc = TOSIGNED(code);
476 258048 out[0] = prev_dc;
477
478 258048 out += 64; // dc coeff for the next block
479
480 258048 code = 5;
481 258048 sign = 0;
482
2/2
✓ Branch 0 taken 4868628 times.
✓ Branch 1 taken 258048 times.
5126676 for (i = 1; i < blocks_per_slice; i++, out += 64) {
483
5/6
✓ Branch 0 taken 2835783 times.
✓ Branch 1 taken 2032845 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2835783 times.
✓ Branch 5 taken 389333 times.
✓ Branch 6 taken 1643512 times.
4868628 DECODE_CODEWORD(code, dc_codebook[FFMIN(code, 6U)], LAST_SKIP_BITS);
484
2/2
✓ Branch 0 taken 3042047 times.
✓ Branch 1 taken 1826581 times.
4868628 if(code) sign ^= -(code & 1);
485 1826581 else sign = 0;
486 4868628 prev_dc += (((code + 1) >> 1) ^ sign) - sign;
487 4868628 out[0] = prev_dc;
488 }
489 258048 CLOSE_READER(re, gb);
490 258048 return 0;
491 }
492
493 // adaptive codebook switching lut according to previous run/level values
494 static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };
495 static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };
496
497 258048 static av_always_inline int decode_ac_coeffs(AVCodecContext *avctx, GetBitContext *gb,
498 int16_t *out, int blocks_per_slice)
499 {
500 258048 ProresContext *ctx = avctx->priv_data;
501 int block_mask, sign;
502 unsigned pos, run, level;
503 int max_coeffs, i, bits_left;
504 258048 int log2_block_count = av_log2(blocks_per_slice);
505
506 258048 OPEN_READER(re, gb);
507 258048 UPDATE_CACHE(re, gb); \
508 258048 run = 4;
509 258048 level = 2;
510
511 258048 max_coeffs = 64 << log2_block_count;
512 258048 block_mask = blocks_per_slice - 1;
513
514 258048 for (pos = block_mask;;) {
515 84797339 bits_left = gb->size_in_bits - re_index;
516
6/6
✓ Branch 0 taken 84746918 times.
✓ Branch 1 taken 50421 times.
✓ Branch 2 taken 827928 times.
✓ Branch 3 taken 83918990 times.
✓ Branch 5 taken 620301 times.
✓ Branch 6 taken 207627 times.
84797339 if (!bits_left || (bits_left < 32 && !SHOW_UBITS(re, gb, bits_left)))
517 break;
518
519
5/6
✓ Branch 0 taken 8031769 times.
✓ Branch 1 taken 76507522 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8031769 times.
✓ Branch 5 taken 2448285 times.
✓ Branch 6 taken 74059237 times.
84539291 DECODE_CODEWORD(run, run_to_cb[FFMIN(run, 15)], LAST_SKIP_BITS);
520 84539291 pos += run + 1;
521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84539291 times.
84539291 if (pos >= max_coeffs) {
522 av_log(avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", pos, max_coeffs);
523 return AVERROR_INVALIDDATA;
524 }
525
526
5/6
✓ Branch 0 taken 45624958 times.
✓ Branch 1 taken 38914333 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45624958 times.
✓ Branch 5 taken 9483940 times.
✓ Branch 6 taken 29430393 times.
84539291 DECODE_CODEWORD(level, lev_to_cb[FFMIN(level, 9)], SKIP_BITS);
527 84539291 level += 1;
528
529 84539291 i = pos >> log2_block_count;
530
531 84539291 sign = SHOW_SBITS(re, gb, 1);
532 84539291 SKIP_BITS(re, gb, 1);
533 84539291 out[((pos & block_mask) << 6) + ctx->scan[i]] = ((level ^ sign) - sign);
534 }
535
536 258048 CLOSE_READER(re, gb);
537 258048 return 0;
538 }
539
540 86520 static int decode_slice_luma(AVCodecContext *avctx, SliceContext *slice,
541 uint16_t *dst, int dst_stride,
542 const uint8_t *buf, unsigned buf_size,
543 const int16_t *qmat)
544 {
545 86520 ProresContext *ctx = avctx->priv_data;
546 86520 LOCAL_ALIGNED_32(int16_t, blocks, [8*4*64]);
547 int16_t *block;
548 GetBitContext gb;
549 86520 int i, blocks_per_slice = slice->mb_count<<2;
550 int ret;
551
552
2/2
✓ Branch 0 taken 2165364 times.
✓ Branch 1 taken 86520 times.
2251884 for (i = 0; i < blocks_per_slice; i++)
553 2165364 ctx->bdsp.clear_block(blocks+(i<<6));
554
555 86520 init_get_bits(&gb, buf, buf_size << 3);
556
557
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 86520 times.
86520 if ((ret = decode_dc_coeffs(&gb, blocks, blocks_per_slice)) < 0)
558 return ret;
559
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 86520 times.
86520 if ((ret = decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice)) < 0)
560 return ret;
561
562 86520 block = blocks;
563
2/2
✓ Branch 0 taken 541341 times.
✓ Branch 1 taken 86520 times.
627861 for (i = 0; i < slice->mb_count; i++) {
564 541341 ctx->prodsp.idct_put(dst, dst_stride, block+(0<<6), qmat);
565 541341 ctx->prodsp.idct_put(dst +8, dst_stride, block+(1<<6), qmat);
566 541341 ctx->prodsp.idct_put(dst+4*dst_stride , dst_stride, block+(2<<6), qmat);
567 541341 ctx->prodsp.idct_put(dst+4*dst_stride+8, dst_stride, block+(3<<6), qmat);
568 541341 block += 4*64;
569 541341 dst += 16;
570 }
571 86520 return 0;
572 }
573
574 171528 static int decode_slice_chroma(AVCodecContext *avctx, SliceContext *slice,
575 uint16_t *dst, int dst_stride,
576 const uint8_t *buf, unsigned buf_size,
577 const int16_t *qmat, int log2_blocks_per_mb)
578 {
579 171528 ProresContext *ctx = avctx->priv_data;
580 171528 LOCAL_ALIGNED_32(int16_t, blocks, [8*4*64]);
581 int16_t *block;
582 GetBitContext gb;
583 171528 int i, j, blocks_per_slice = slice->mb_count << log2_blocks_per_mb;
584 int ret;
585
586
2/2
✓ Branch 0 taken 2961312 times.
✓ Branch 1 taken 171528 times.
3132840 for (i = 0; i < blocks_per_slice; i++)
587 2961312 ctx->bdsp.clear_block(blocks+(i<<6));
588
589 171528 init_get_bits(&gb, buf, buf_size << 3);
590
591
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 171528 times.
171528 if ((ret = decode_dc_coeffs(&gb, blocks, blocks_per_slice)) < 0)
592 return ret;
593
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 171528 times.
171528 if ((ret = decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice)) < 0)
594 return ret;
595
596 171528 block = blocks;
597
2/2
✓ Branch 0 taken 1072962 times.
✓ Branch 1 taken 171528 times.
1244490 for (i = 0; i < slice->mb_count; i++) {
598
2/2
✓ Branch 0 taken 1480656 times.
✓ Branch 1 taken 1072962 times.
2553618 for (j = 0; j < log2_blocks_per_mb; j++) {
599 1480656 ctx->prodsp.idct_put(dst, dst_stride, block+(0<<6), qmat);
600 1480656 ctx->prodsp.idct_put(dst+4*dst_stride, dst_stride, block+(1<<6), qmat);
601 1480656 block += 2*64;
602 1480656 dst += 8;
603 }
604 }
605 171528 return 0;
606 }
607
608 /**
609 * Decode alpha slice plane.
610 */
611 5100 static void decode_slice_alpha(ProresContext *ctx,
612 uint16_t *dst, int dst_stride,
613 const uint8_t *buf, int buf_size,
614 int blocks_per_slice)
615 {
616 GetBitContext gb;
617 int i;
618 5100 LOCAL_ALIGNED_32(int16_t, blocks, [8*4*64]);
619 int16_t *block;
620
621
2/2
✓ Branch 0 taken 163200 times.
✓ Branch 1 taken 5100 times.
168300 for (i = 0; i < blocks_per_slice<<2; i++)
622 163200 ctx->bdsp.clear_block(blocks+(i<<6));
623
624 5100 init_get_bits(&gb, buf, buf_size << 3);
625
626
1/2
✓ Branch 0 taken 5100 times.
✗ Branch 1 not taken.
5100 if (ctx->alpha_info == 2) {
627 5100 ctx->unpack_alpha(&gb, blocks, blocks_per_slice * 4 * 64, 16);
628 } else {
629 ctx->unpack_alpha(&gb, blocks, blocks_per_slice * 4 * 64, 8);
630 }
631
632 5100 block = blocks;
633
634
2/2
✓ Branch 0 taken 81600 times.
✓ Branch 1 taken 5100 times.
86700 for (i = 0; i < 16; i++) {
635 81600 memcpy(dst, block, 16 * blocks_per_slice * sizeof(*dst));
636 81600 dst += dst_stride >> 1;
637 81600 block += 16 * blocks_per_slice;
638 }
639 5100 }
640
641 86520 static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
642 {
643 86520 ProresContext *ctx = avctx->priv_data;
644 86520 SliceContext *slice = &ctx->slices[jobnr];
645 86520 const uint8_t *buf = slice->data;
646 86520 AVFrame *pic = ctx->frame;
647 int i, hdr_size, qscale, log2_chroma_blocks_per_mb;
648 int luma_stride, chroma_stride;
649 int y_data_size, u_data_size, v_data_size, a_data_size, offset;
650 uint8_t *dest_y, *dest_u, *dest_v;
651 86520 LOCAL_ALIGNED_16(int16_t, qmat_luma_scaled, [64]);
652 86520 LOCAL_ALIGNED_16(int16_t, qmat_chroma_scaled,[64]);
653 int mb_x_shift;
654 int ret;
655 uint16_t val_no_chroma;
656
657 86520 slice->ret = -1;
658 //av_log(avctx, AV_LOG_INFO, "slice %d mb width %d mb x %d y %d\n",
659 // jobnr, slice->mb_count, slice->mb_x, slice->mb_y);
660
661 // slice header
662 86520 hdr_size = buf[0] >> 3;
663 86520 qscale = av_clip(buf[1], 1, 224);
664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86520 times.
86520 qscale = qscale > 128 ? qscale - 96 << 2: qscale;
665 86520 y_data_size = AV_RB16(buf + 2);
666 86520 u_data_size = AV_RB16(buf + 4);
667 86520 v_data_size = slice->data_size - y_data_size - u_data_size - hdr_size;
668
2/2
✓ Branch 0 taken 10200 times.
✓ Branch 1 taken 76320 times.
86520 if (hdr_size > 7) v_data_size = AV_RB16(buf + 6);
669 86520 a_data_size = slice->data_size - y_data_size - u_data_size -
670 86520 v_data_size - hdr_size;
671
672
3/6
✓ Branch 0 taken 86520 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 86520 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 86520 times.
✗ Branch 5 not taken.
86520 if (y_data_size < 0 || u_data_size < 0 || v_data_size < 0
673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86520 times.
86520 || hdr_size+y_data_size+u_data_size+v_data_size > slice->data_size){
674 av_log(avctx, AV_LOG_ERROR, "invalid plane data size\n");
675 return AVERROR_INVALIDDATA;
676 }
677
678 86520 buf += hdr_size;
679
680
2/2
✓ Branch 0 taken 5537280 times.
✓ Branch 1 taken 86520 times.
5623800 for (i = 0; i < 64; i++) {
681 5537280 qmat_luma_scaled [i] = ctx->qmat_luma [i] * qscale;
682 5537280 qmat_chroma_scaled[i] = ctx->qmat_chroma[i] * qscale;
683 }
684
685
2/2
✓ Branch 0 taken 43272 times.
✓ Branch 1 taken 43248 times.
86520 if (ctx->frame_type == 0) {
686 43272 luma_stride = pic->linesize[0];
687 43272 chroma_stride = pic->linesize[1];
688 } else {
689 43248 luma_stride = pic->linesize[0] << 1;
690 43248 chroma_stride = pic->linesize[1] << 1;
691 }
692
693
2/4
✓ Branch 0 taken 86520 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 86520 times.
✗ Branch 3 not taken.
86520 if (avctx->pix_fmt == AV_PIX_FMT_YUV444P10 || avctx->pix_fmt == AV_PIX_FMT_YUVA444P10 ||
694
4/4
✓ Branch 0 taken 58674 times.
✓ Branch 1 taken 27846 times.
✓ Branch 2 taken 5100 times.
✓ Branch 3 taken 53574 times.
86520 avctx->pix_fmt == AV_PIX_FMT_YUV444P12 || avctx->pix_fmt == AV_PIX_FMT_YUVA444P12) {
695 32946 mb_x_shift = 5;
696 32946 log2_chroma_blocks_per_mb = 2;
697 } else {
698 53574 mb_x_shift = 4;
699 53574 log2_chroma_blocks_per_mb = 1;
700 }
701
702 86520 offset = (slice->mb_y << 4) * luma_stride + (slice->mb_x << 5);
703 86520 dest_y = pic->data[0] + offset;
704 86520 dest_u = pic->data[1] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << mb_x_shift);
705 86520 dest_v = pic->data[2] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << mb_x_shift);
706
707
4/4
✓ Branch 0 taken 43248 times.
✓ Branch 1 taken 43272 times.
✓ Branch 2 taken 21624 times.
✓ Branch 3 taken 21624 times.
86520 if (ctx->frame_type && ctx->first_field ^ ctx->frame->top_field_first) {
708 21624 dest_y += pic->linesize[0];
709 21624 dest_u += pic->linesize[1];
710 21624 dest_v += pic->linesize[2];
711 21624 offset += pic->linesize[3];
712 }
713
714 86520 ret = decode_slice_luma(avctx, slice, (uint16_t*)dest_y, luma_stride,
715 buf, y_data_size, qmat_luma_scaled);
716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 86520 times.
86520 if (ret < 0)
717 return ret;
718
719
3/4
✓ Branch 0 taken 86520 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85764 times.
✓ Branch 3 taken 756 times.
86520 if (!(avctx->flags & AV_CODEC_FLAG_GRAY) && (u_data_size + v_data_size) > 0) {
720 85764 ret = decode_slice_chroma(avctx, slice, (uint16_t*)dest_u, chroma_stride,
721 buf + y_data_size, u_data_size,
722 qmat_chroma_scaled, log2_chroma_blocks_per_mb);
723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 85764 times.
85764 if (ret < 0)
724 return ret;
725
726 85764 ret = decode_slice_chroma(avctx, slice, (uint16_t*)dest_v, chroma_stride,
727 85764 buf + y_data_size + u_data_size, v_data_size,
728 qmat_chroma_scaled, log2_chroma_blocks_per_mb);
729
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 85764 times.
85764 if (ret < 0)
730 return ret;
731 }
732 else {
733 756 size_t mb_max_x = slice->mb_count << (mb_x_shift - 1);
734 size_t i, j;
735
1/2
✓ Branch 0 taken 756 times.
✗ Branch 1 not taken.
756 if (avctx->bits_per_raw_sample == 10) {
736 756 val_no_chroma = 511;
737 } else { /* 12b */
738 val_no_chroma = 511 * 4;
739 }
740
2/2
✓ Branch 0 taken 12096 times.
✓ Branch 1 taken 756 times.
12852 for (i = 0; i < 16; ++i)
741
2/2
✓ Branch 0 taken 622080 times.
✓ Branch 1 taken 12096 times.
634176 for (j = 0; j < mb_max_x; ++j) {
742 622080 *(uint16_t*)(dest_u + (i * chroma_stride) + (j << 1)) = val_no_chroma;
743 622080 *(uint16_t*)(dest_v + (i * chroma_stride) + (j << 1)) = val_no_chroma;
744 }
745 }
746
747 /* decode alpha plane if available */
748
4/6
✓ Branch 0 taken 5100 times.
✓ Branch 1 taken 81420 times.
✓ Branch 2 taken 5100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5100 times.
✗ Branch 5 not taken.
86520 if (ctx->alpha_info && pic->data[3] && a_data_size) {
749 5100 uint8_t *dest_a = pic->data[3] + offset;
750 5100 decode_slice_alpha(ctx, (uint16_t*)dest_a, luma_stride,
751 5100 buf + y_data_size + u_data_size + v_data_size,
752 5100 a_data_size, slice->mb_count);
753 }
754
755 86520 slice->ret = 0;
756 86520 return 0;
757 }
758
759 1486 static int decode_picture(AVCodecContext *avctx)
760 {
761 1486 ProresContext *ctx = avctx->priv_data;
762 int i;
763 1486 int error = 0;
764
765 1486 avctx->execute2(avctx, decode_slice_thread, NULL, NULL, ctx->slice_count);
766
767
2/2
✓ Branch 0 taken 86520 times.
✓ Branch 1 taken 1486 times.
88006 for (i = 0; i < ctx->slice_count; i++)
768 86520 error += ctx->slices[i].ret < 0;
769
770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1486 times.
1486 if (error)
771 ctx->frame->decode_error_flags = FF_DECODE_ERROR_INVALID_BITSTREAM;
772
1/2
✓ Branch 0 taken 1486 times.
✗ Branch 1 not taken.
1486 if (error < ctx->slice_count)
773 1486 return 0;
774
775 return ctx->slices[0].ret;
776 }
777
778 1058 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
779 AVPacket *avpkt)
780 {
781 1058 ProresContext *ctx = avctx->priv_data;
782 1058 ThreadFrame tframe = { .f = data };
783 1058 AVFrame *frame = data;
784 1058 const uint8_t *buf = avpkt->data;
785 1058 int buf_size = avpkt->size;
786 int frame_hdr_size, pic_size, ret;
787
788
2/4
✓ Branch 0 taken 1058 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1058 times.
1058 if (buf_size < 28 || AV_RL32(buf + 4) != AV_RL32("icpf")) {
789 av_log(avctx, AV_LOG_ERROR, "invalid frame header\n");
790 return AVERROR_INVALIDDATA;
791 }
792
793 1058 ctx->frame = frame;
794 1058 ctx->frame->pict_type = AV_PICTURE_TYPE_I;
795 1058 ctx->frame->key_frame = 1;
796 1058 ctx->first_field = 1;
797
798 1058 buf += 8;
799 1058 buf_size -= 8;
800
801 1058 frame_hdr_size = decode_frame_header(ctx, buf, buf_size, avctx);
802
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 if (frame_hdr_size < 0)
803 return frame_hdr_size;
804
805 1058 buf += frame_hdr_size;
806 1058 buf_size -= frame_hdr_size;
807
808
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1058 times.
1058 if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0)
809 return ret;
810 1058 ff_thread_finish_setup(avctx);
811
812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 if (avctx->hwaccel) {
813 ret = avctx->hwaccel->start_frame(avctx, NULL, 0);
814 if (ret < 0)
815 return ret;
816 ret = avctx->hwaccel->decode_slice(avctx, avpkt->data, avpkt->size);
817 if (ret < 0)
818 return ret;
819 ret = avctx->hwaccel->end_frame(avctx);
820 if (ret < 0)
821 return ret;
822 goto finish;
823 }
824
825 1058 decode_picture:
826 1486 pic_size = decode_picture_header(avctx, buf, buf_size);
827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1486 times.
1486 if (pic_size < 0) {
828 av_log(avctx, AV_LOG_ERROR, "error decoding picture header\n");
829 return pic_size;
830 }
831
832
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1486 times.
1486 if ((ret = decode_picture(avctx)) < 0) {
833 av_log(avctx, AV_LOG_ERROR, "error decoding picture\n");
834 return ret;
835 }
836
837 1486 buf += pic_size;
838 1486 buf_size -= pic_size;
839
840
6/6
✓ Branch 0 taken 856 times.
✓ Branch 1 taken 630 times.
✓ Branch 2 taken 408 times.
✓ Branch 3 taken 448 times.
✓ Branch 4 taken 20 times.
✓ Branch 5 taken 428 times.
1486 if (ctx->frame_type && buf_size > 0 && ctx->first_field) {
841 428 ctx->first_field = 0;
842 428 goto decode_picture;
843 }
844
845 1058 finish:
846 1058 *got_frame = 1;
847
848 1058 return avpkt->size;
849 }
850
851 69 static av_cold int decode_close(AVCodecContext *avctx)
852 {
853 69 ProresContext *ctx = avctx->priv_data;
854
855 69 av_freep(&ctx->slices);
856
857 69 return 0;
858 }
859
860 #if HAVE_THREADS
861 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
862 {
863 ProresContext *csrc = src->priv_data;
864 ProresContext *cdst = dst->priv_data;
865
866 cdst->pix_fmt = csrc->pix_fmt;
867
868 return 0;
869 }
870 #endif
871
872 const AVCodec ff_prores_decoder = {
873 .name = "prores",
874 .long_name = NULL_IF_CONFIG_SMALL("Apple ProRes (iCodec Pro)"),
875 .type = AVMEDIA_TYPE_VIDEO,
876 .id = AV_CODEC_ID_PRORES,
877 .priv_data_size = sizeof(ProresContext),
878 .init = decode_init,
879 .close = decode_close,
880 .decode = decode_frame,
881 .update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
882 .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
883 .profiles = NULL_IF_CONFIG_SMALL(ff_prores_profiles),
884 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
885 .hw_configs = (const AVCodecHWConfigInternal *const []) {
886 #if CONFIG_PRORES_VIDEOTOOLBOX_HWACCEL
887 HWACCEL_VIDEOTOOLBOX(prores),
888 #endif
889 NULL
890 },
891 };
892