FFmpeg coverage


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