FFmpeg coverage


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