FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpeg12dec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 1160 1572 73.8%
Functions: 29 33 87.9%
Branches: 669 1099 60.9%

Line Branch Exec Source
1 /*
2 * MPEG-1/2 decoder
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2002-2013 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * MPEG-1/2 decoder
26 */
27
28 #include "config_components.h"
29
30 #define UNCHECKED_BITSTREAM_READER 1
31 #include <inttypes.h>
32
33 #include "libavutil/attributes.h"
34 #include "libavutil/emms.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/internal.h"
37 #include "libavutil/mem_internal.h"
38 #include "libavutil/reverse.h"
39 #include "libavutil/stereo3d.h"
40 #include "libavutil/timecode.h"
41
42 #include "avcodec.h"
43 #include "codec_internal.h"
44 #include "decode.h"
45 #include "error_resilience.h"
46 #include "hwaccel_internal.h"
47 #include "hwconfig.h"
48 #include "idctdsp.h"
49 #include "internal.h"
50 #include "mpeg_er.h"
51 #include "mpeg12.h"
52 #include "mpeg12codecs.h"
53 #include "mpeg12data.h"
54 #include "mpeg12dec.h"
55 #include "mpegutils.h"
56 #include "mpegvideo.h"
57 #include "mpegvideodata.h"
58 #include "mpegvideodec.h"
59 #include "profiles.h"
60 #include "startcode.h"
61 #include "thread.h"
62
63 #define A53_MAX_CC_COUNT 2000
64
65 enum Mpeg2ClosedCaptionsFormat {
66 CC_FORMAT_AUTO,
67 CC_FORMAT_A53_PART4,
68 CC_FORMAT_SCTE20,
69 CC_FORMAT_DVD
70 };
71
72 typedef struct Mpeg1Context {
73 MpegEncContext mpeg_enc_ctx;
74 int repeat_field; /* true if we must repeat the field */
75 AVPanScan pan_scan; /* some temporary storage for the panscan */
76 enum AVStereo3DType stereo3d_type;
77 int has_stereo3d;
78 AVBufferRef *a53_buf_ref;
79 enum Mpeg2ClosedCaptionsFormat cc_format;
80 uint8_t afd;
81 int has_afd;
82 int slice_count;
83 unsigned aspect_ratio_info;
84 AVRational save_aspect;
85 int save_width, save_height, save_progressive_seq;
86 AVRational frame_rate_ext; /* MPEG-2 specific framerate modificator */
87 unsigned frame_rate_index;
88 int sync; /* Did we reach a sync point like a GOP/SEQ/KEYFrame? */
89 int closed_gop;
90 int tmpgexs;
91 int first_slice;
92 int extradata_decoded;
93 int64_t timecode_frame_start; /*< GOP timecode frame start number, in non drop frame format */
94 } Mpeg1Context;
95
96 /* as H.263, but only 17 codes */
97 5415428 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
98 {
99 int code, sign, val, shift;
100
101 5415428 code = get_vlc2(&s->gb, ff_mv_vlc, MV_VLC_BITS, 2);
102
2/2
✓ Branch 0 taken 2013514 times.
✓ Branch 1 taken 3401914 times.
5415428 if (code == 0)
103 2013514 return pred;
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3401914 times.
3401914 if (code < 0)
105 return 0xffff;
106
107 3401914 sign = get_bits1(&s->gb);
108 3401914 shift = fcode - 1;
109 3401914 val = code;
110
2/2
✓ Branch 0 taken 3062188 times.
✓ Branch 1 taken 339726 times.
3401914 if (shift) {
111 3062188 val = (val - 1) << shift;
112 3062188 val |= get_bits(&s->gb, shift);
113 3062188 val++;
114 }
115
2/2
✓ Branch 0 taken 1759124 times.
✓ Branch 1 taken 1642790 times.
3401914 if (sign)
116 1759124 val = -val;
117 3401914 val += pred;
118
119 /* modulo decoding */
120 3401914 return sign_extend(val, 5 + shift);
121 }
122
123 #define MAX_INDEX (64 - 1)
124 #define check_scantable_index(ctx, x) \
125 do { \
126 if ((x) > MAX_INDEX) { \
127 av_log(ctx->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", \
128 ctx->mb_x, ctx->mb_y); \
129 return AVERROR_INVALIDDATA; \
130 } \
131 } while (0)
132
133 403182 static inline int mpeg1_decode_block_inter(MpegEncContext *s,
134 int16_t *block, int n)
135 {
136 int level, i, j, run;
137 403182 const uint8_t *const scantable = s->intra_scantable.permutated;
138 403182 const uint16_t *quant_matrix = s->inter_matrix;
139 403182 const int qscale = s->qscale;
140
141 {
142 403182 OPEN_READER(re, &s->gb);
143 403182 i = -1;
144 // special case for first coefficient, no need to add second VLC table
145 403182 UPDATE_CACHE(re, &s->gb);
146
2/2
✓ Branch 0 taken 301257 times.
✓ Branch 1 taken 101925 times.
403182 if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
147 101925 level = (3 * qscale * quant_matrix[0]) >> 5;
148 101925 level = (level - 1) | 1;
149
2/2
✓ Branch 0 taken 57008 times.
✓ Branch 1 taken 44917 times.
101925 if (GET_CACHE(re, &s->gb) & 0x40000000)
150 57008 level = -level;
151 101925 block[0] = level;
152 101925 i++;
153 101925 SKIP_BITS(re, &s->gb, 2);
154
2/2
✓ Branch 0 taken 67516 times.
✓ Branch 1 taken 34409 times.
101925 if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
155 34409 goto end;
156 }
157 /* now quantify & encode AC coefficients */
158 for (;;) {
159
2/2
✓ Branch 1 taken 335978 times.
✓ Branch 2 taken 2584676 times.
2920654 GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc,
160 TEX_VLC_BITS, 2, 0);
161
162
2/2
✓ Branch 0 taken 2841520 times.
✓ Branch 1 taken 79134 times.
2920654 if (level != 0) {
163 2841520 i += run;
164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2841520 times.
2841520 if (i > MAX_INDEX)
165 break;
166 2841520 j = scantable[i];
167 2841520 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
168 2841520 level = (level - 1) | 1;
169 2841520 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
170 2841520 SHOW_SBITS(re, &s->gb, 1);
171 2841520 SKIP_BITS(re, &s->gb, 1);
172 } else {
173 /* escape */
174 79134 run = SHOW_UBITS(re, &s->gb, 6) + 1;
175 79134 LAST_SKIP_BITS(re, &s->gb, 6);
176 79134 UPDATE_CACHE(re, &s->gb);
177 79134 level = SHOW_SBITS(re, &s->gb, 8);
178 79134 SKIP_BITS(re, &s->gb, 8);
179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79134 times.
79134 if (level == -128) {
180 level = SHOW_UBITS(re, &s->gb, 8) - 256;
181 SKIP_BITS(re, &s->gb, 8);
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79134 times.
79134 } else if (level == 0) {
183 level = SHOW_UBITS(re, &s->gb, 8);
184 SKIP_BITS(re, &s->gb, 8);
185 }
186 79134 i += run;
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 79134 times.
79134 if (i > MAX_INDEX)
188 break;
189 79134 j = scantable[i];
190
2/2
✓ Branch 0 taken 38931 times.
✓ Branch 1 taken 40203 times.
79134 if (level < 0) {
191 38931 level = -level;
192 38931 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
193 38931 level = (level - 1) | 1;
194 38931 level = -level;
195 } else {
196 40203 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
197 40203 level = (level - 1) | 1;
198 }
199 }
200
201 2920654 block[j] = level;
202
2/2
✓ Branch 0 taken 368773 times.
✓ Branch 1 taken 2551881 times.
2920654 if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
203 368773 break;
204 2551881 UPDATE_CACHE(re, &s->gb);
205 }
206 403182 end:
207 403182 LAST_SKIP_BITS(re, &s->gb, 2);
208 403182 CLOSE_READER(re, &s->gb);
209 }
210
211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 403182 times.
403182 check_scantable_index(s, i);
212
213 403182 s->block_last_index[n] = i;
214 403182 return 0;
215 }
216
217 5147603 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
218 int16_t *block, int n)
219 {
220 int level, i, j, run;
221 5147603 const uint8_t *const scantable = s->intra_scantable.permutated;
222 const uint16_t *quant_matrix;
223 5147603 const int qscale = s->qscale;
224 int mismatch;
225
226 5147603 mismatch = 1;
227
228 {
229 5147603 OPEN_READER(re, &s->gb);
230 5147603 i = -1;
231
2/2
✓ Branch 0 taken 3855888 times.
✓ Branch 1 taken 1291715 times.
5147603 if (n < 4)
232 3855888 quant_matrix = s->inter_matrix;
233 else
234 1291715 quant_matrix = s->chroma_inter_matrix;
235
236 // Special case for first coefficient, no need to add second VLC table.
237 5147603 UPDATE_CACHE(re, &s->gb);
238
2/2
✓ Branch 0 taken 3265406 times.
✓ Branch 1 taken 1882197 times.
5147603 if (((int32_t) GET_CACHE(re, &s->gb)) < 0) {
239 1882197 level = (3 * qscale * quant_matrix[0]) >> 5;
240
2/2
✓ Branch 0 taken 1189743 times.
✓ Branch 1 taken 692454 times.
1882197 if (GET_CACHE(re, &s->gb) & 0x40000000)
241 1189743 level = -level;
242 1882197 block[0] = level;
243 1882197 mismatch ^= level;
244 1882197 i++;
245 1882197 SKIP_BITS(re, &s->gb, 2);
246
2/2
✓ Branch 0 taken 987049 times.
✓ Branch 1 taken 895148 times.
1882197 if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
247 895148 goto end;
248 }
249
250 /* now quantify & encode AC coefficients */
251 for (;;) {
252
2/2
✓ Branch 1 taken 1622033 times.
✓ Branch 2 taken 16700504 times.
18322537 GET_RL_VLC(level, run, re, &s->gb, ff_mpeg1_rl_vlc,
253 TEX_VLC_BITS, 2, 0);
254
255
2/2
✓ Branch 0 taken 18051793 times.
✓ Branch 1 taken 270744 times.
18322537 if (level != 0) {
256 18051793 i += run;
257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18051793 times.
18051793 if (i > MAX_INDEX)
258 break;
259 18051793 j = scantable[i];
260 18051793 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
261 18051793 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
262 18051793 SHOW_SBITS(re, &s->gb, 1);
263 18051793 SKIP_BITS(re, &s->gb, 1);
264 } else {
265 /* escape */
266 270744 run = SHOW_UBITS(re, &s->gb, 6) + 1;
267 270744 LAST_SKIP_BITS(re, &s->gb, 6);
268 270744 UPDATE_CACHE(re, &s->gb);
269 270744 level = SHOW_SBITS(re, &s->gb, 12);
270 270744 SKIP_BITS(re, &s->gb, 12);
271
272 270744 i += run;
273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 270744 times.
270744 if (i > MAX_INDEX)
274 break;
275 270744 j = scantable[i];
276
2/2
✓ Branch 0 taken 131519 times.
✓ Branch 1 taken 139225 times.
270744 if (level < 0) {
277 131519 level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
278 131519 level = -level;
279 } else {
280 139225 level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5;
281 }
282 }
283
284 18322537 mismatch ^= level;
285 18322537 block[j] = level;
286
2/2
✓ Branch 0 taken 4252455 times.
✓ Branch 1 taken 14070082 times.
18322537 if (((int32_t) GET_CACHE(re, &s->gb)) <= (int32_t) 0xBFFFFFFF)
287 4252455 break;
288 14070082 UPDATE_CACHE(re, &s->gb);
289 }
290 5147603 end:
291 5147603 LAST_SKIP_BITS(re, &s->gb, 2);
292 5147603 CLOSE_READER(re, &s->gb);
293 }
294 5147603 block[63] ^= (mismatch & 1);
295
296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5147603 times.
5147603 check_scantable_index(s, i);
297
298 5147603 s->block_last_index[n] = i;
299 5147603 return 0;
300 }
301
302 1923962 static inline int mpeg2_decode_block_intra(MpegEncContext *s,
303 int16_t *block, int n)
304 {
305 int level, dc, diff, i, j, run;
306 int component;
307 const RL_VLC_ELEM *rl_vlc;
308 1923962 const uint8_t *const scantable = s->intra_scantable.permutated;
309 const uint16_t *quant_matrix;
310 1923962 const int qscale = s->qscale;
311 int mismatch;
312
313 /* DC coefficient */
314
2/2
✓ Branch 0 taken 1210436 times.
✓ Branch 1 taken 713526 times.
1923962 if (n < 4) {
315 1210436 quant_matrix = s->intra_matrix;
316 1210436 component = 0;
317 } else {
318 713526 quant_matrix = s->chroma_intra_matrix;
319 713526 component = (n & 1) + 1;
320 }
321 1923962 diff = decode_dc(&s->gb, component);
322 1923962 dc = s->last_dc[component];
323 1923962 dc += diff;
324 1923962 s->last_dc[component] = dc;
325 1923962 block[0] = dc * (1 << (3 - s->intra_dc_precision));
326 ff_tlog(s->avctx, "dc=%d\n", block[0]);
327 1923962 mismatch = block[0] ^ 1;
328 1923962 i = 0;
329
2/2
✓ Branch 0 taken 1342046 times.
✓ Branch 1 taken 581916 times.
1923962 if (s->intra_vlc_format)
330 1342046 rl_vlc = ff_mpeg2_rl_vlc;
331 else
332 581916 rl_vlc = ff_mpeg1_rl_vlc;
333
334 {
335 1923962 OPEN_READER(re, &s->gb);
336 /* now quantify & encode AC coefficients */
337 for (;;) {
338 26644554 UPDATE_CACHE(re, &s->gb);
339
2/2
✓ Branch 1 taken 730141 times.
✓ Branch 2 taken 13554117 times.
14284258 GET_RL_VLC(level, run, re, &s->gb, rl_vlc,
340 TEX_VLC_BITS, 2, 0);
341
342
2/2
✓ Branch 0 taken 1923952 times.
✓ Branch 1 taken 12360306 times.
14284258 if (level == 127) {
343 1923952 break;
344
2/2
✓ Branch 0 taken 12228740 times.
✓ Branch 1 taken 131566 times.
12360306 } else if (level != 0) {
345 12228740 i += run;
346
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 12228730 times.
12228740 if (i > MAX_INDEX)
347 10 break;
348 12228730 j = scantable[i];
349 12228730 level = (level * qscale * quant_matrix[j]) >> 4;
350 12228730 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) -
351 12228730 SHOW_SBITS(re, &s->gb, 1);
352 12228730 LAST_SKIP_BITS(re, &s->gb, 1);
353 } else {
354 /* escape */
355 131566 run = SHOW_UBITS(re, &s->gb, 6) + 1;
356 131566 SKIP_BITS(re, &s->gb, 6);
357 131566 level = SHOW_SBITS(re, &s->gb, 12);
358 131566 LAST_SKIP_BITS(re, &s->gb, 12);
359 131566 i += run;
360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 131566 times.
131566 if (i > MAX_INDEX)
361 break;
362 131566 j = scantable[i];
363
2/2
✓ Branch 0 taken 58721 times.
✓ Branch 1 taken 72845 times.
131566 if (level < 0) {
364 58721 level = (-level * qscale * quant_matrix[j]) >> 4;
365 58721 level = -level;
366 } else {
367 72845 level = (level * qscale * quant_matrix[j]) >> 4;
368 }
369 }
370
371 12360296 mismatch ^= level;
372 12360296 block[j] = level;
373 }
374 1923962 CLOSE_READER(re, &s->gb);
375 }
376 1923962 block[63] ^= mismatch & 1;
377
378
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1923952 times.
1923962 check_scantable_index(s, i);
379
380 1923952 s->block_last_index[n] = i;
381 1923952 return 0;
382 }
383
384 /******************************************/
385 /* decoding */
386
387 43840 static inline int get_dmv(MpegEncContext *s)
388 {
389
2/2
✓ Branch 1 taken 40876 times.
✓ Branch 2 taken 2964 times.
43840 if (get_bits1(&s->gb))
390 40876 return 1 - (get_bits1(&s->gb) << 1);
391 else
392 2964 return 0;
393 }
394
395 /* motion type (for MPEG-2) */
396 #define MT_FIELD 1
397 #define MT_FRAME 2
398 #define MT_16X8 2
399 #define MT_DMV 3
400
401 2616520 static int mpeg_decode_mb(MpegEncContext *s, int16_t block[12][64])
402 {
403 int i, j, k, cbp, val, mb_type, motion_type;
404 2616520 const int mb_block_count = 4 + (1 << s->chroma_format);
405 int ret;
406
407 ff_tlog(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
408
409 av_assert2(s->mb_skipped == 0);
410
411
2/2
✓ Branch 0 taken 165557 times.
✓ Branch 1 taken 2450963 times.
2616520 if (s->mb_skip_run-- != 0) {
412
2/2
✓ Branch 0 taken 57490 times.
✓ Branch 1 taken 108067 times.
165557 if (s->pict_type == AV_PICTURE_TYPE_P) {
413 57490 s->mb_skipped = 1;
414 57490 s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
415 MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
416 } else {
417 int mb_type;
418
419
1/2
✓ Branch 0 taken 108067 times.
✗ Branch 1 not taken.
108067 if (s->mb_x)
420 108067 mb_type = s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride - 1];
421 else
422 // FIXME not sure if this is allowed in MPEG at all
423 mb_type = s->cur_pic.mb_type[s->mb_width + (s->mb_y - 1) * s->mb_stride - 1];
424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108067 times.
108067 if (IS_INTRA(mb_type)) {
425 av_log(s->avctx, AV_LOG_ERROR, "skip with previntra\n");
426 return AVERROR_INVALIDDATA;
427 }
428 108067 s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride] =
429 108067 mb_type | MB_TYPE_SKIP;
430
431
2/2
✓ Branch 0 taken 75586 times.
✓ Branch 1 taken 32481 times.
108067 if ((s->mv[0][0][0] | s->mv[0][0][1] | s->mv[1][0][0] | s->mv[1][0][1]) == 0)
432 75586 s->mb_skipped = 1;
433 }
434
435 165557 return 0;
436 }
437
438
3/3
✓ Branch 0 taken 240810 times.
✓ Branch 1 taken 1348860 times.
✓ Branch 2 taken 861293 times.
2450963 switch (s->pict_type) {
439 240810 default:
440 case AV_PICTURE_TYPE_I:
441
2/2
✓ Branch 1 taken 18603 times.
✓ Branch 2 taken 222207 times.
240810 if (get_bits1(&s->gb) == 0) {
442
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18603 times.
18603 if (get_bits1(&s->gb) == 0) {
443 av_log(s->avctx, AV_LOG_ERROR,
444 "Invalid mb type in I-frame at %d %d\n",
445 s->mb_x, s->mb_y);
446 return AVERROR_INVALIDDATA;
447 }
448 18603 mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA;
449 } else {
450 222207 mb_type = MB_TYPE_INTRA;
451 }
452 240810 break;
453 1348860 case AV_PICTURE_TYPE_P:
454 1348860 mb_type = get_vlc2(&s->gb, ff_mb_ptype_vlc, MB_PTYPE_VLC_BITS, 1);
455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1348860 times.
1348860 if (mb_type < 0) {
456 av_log(s->avctx, AV_LOG_ERROR,
457 "Invalid mb type in P-frame at %d %d\n", s->mb_x, s->mb_y);
458 return AVERROR_INVALIDDATA;
459 }
460 1348860 break;
461 861293 case AV_PICTURE_TYPE_B:
462 861293 mb_type = get_vlc2(&s->gb, ff_mb_btype_vlc, MB_BTYPE_VLC_BITS, 1);
463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 861293 times.
861293 if (mb_type < 0) {
464 av_log(s->avctx, AV_LOG_ERROR,
465 "Invalid mb type in B-frame at %d %d\n", s->mb_x, s->mb_y);
466 return AVERROR_INVALIDDATA;
467 }
468 861293 break;
469 }
470 ff_tlog(s->avctx, "mb_type=%x\n", mb_type);
471 // motion_type = 0; /* avoid warning */
472
2/2
✓ Branch 0 taken 323618 times.
✓ Branch 1 taken 2127345 times.
2450963 if (IS_INTRA(mb_type)) {
473 323618 s->bdsp.clear_blocks(s->block[0]);
474
475
2/2
✓ Branch 0 taken 54159 times.
✓ Branch 1 taken 269459 times.
323618 if (!s->chroma_y_shift)
476 54159 s->bdsp.clear_blocks(s->block[6]);
477
478 /* compute DCT type */
479 // FIXME: add an interlaced_dct coded var?
480
2/2
✓ Branch 0 taken 263887 times.
✓ Branch 1 taken 59731 times.
323618 if (s->picture_structure == PICT_FRAME &&
481
2/2
✓ Branch 0 taken 112469 times.
✓ Branch 1 taken 151418 times.
263887 !s->frame_pred_frame_dct)
482 112469 s->interlaced_dct = get_bits1(&s->gb);
483
484
2/2
✓ Branch 0 taken 26872 times.
✓ Branch 1 taken 296746 times.
323618 if (IS_QUANT(mb_type))
485 26872 s->qscale = mpeg_get_qscale(s);
486
487
2/2
✓ Branch 0 taken 1356 times.
✓ Branch 1 taken 322262 times.
323618 if (s->concealment_motion_vectors) {
488 /* just parse them */
489
2/2
✓ Branch 0 taken 1350 times.
✓ Branch 1 taken 6 times.
1356 if (s->picture_structure != PICT_FRAME)
490 1350 skip_bits1(&s->gb); /* field select */
491
492 1356 s->mv[0][0][0] =
493 1356 s->last_mv[0][0][0] =
494 1356 s->last_mv[0][1][0] = mpeg_decode_motion(s, s->mpeg_f_code[0][0],
495 s->last_mv[0][0][0]);
496 1356 s->mv[0][0][1] =
497 1356 s->last_mv[0][0][1] =
498 1356 s->last_mv[0][1][1] = mpeg_decode_motion(s, s->mpeg_f_code[0][1],
499 s->last_mv[0][0][1]);
500
501 1356 check_marker(s->avctx, &s->gb, "after concealment_motion_vectors");
502 } else {
503 /* reset mv prediction */
504 322262 memset(s->last_mv, 0, sizeof(s->last_mv));
505 }
506 323618 s->mb_intra = 1;
507
508
2/2
✓ Branch 0 taken 302614 times.
✓ Branch 1 taken 21004 times.
323618 if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
509
2/2
✓ Branch 0 taken 1923962 times.
✓ Branch 1 taken 302604 times.
2226566 for (i = 0; i < mb_block_count; i++)
510
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 1923952 times.
1923962 if ((ret = mpeg2_decode_block_intra(s, s->block[i], i)) < 0)
511 10 return ret;
512 } else {
513
2/2
✓ Branch 0 taken 126024 times.
✓ Branch 1 taken 21004 times.
147028 for (i = 0; i < 6; i++) {
514 126024 ret = ff_mpeg1_decode_block_intra(&s->gb,
515 126024 s->intra_matrix,
516 126024 s->intra_scantable.permutated,
517 126024 s->last_dc, s->block[i],
518 i, s->qscale);
519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 126024 times.
126024 if (ret < 0) {
520 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
521 s->mb_x, s->mb_y);
522 return ret;
523 }
524
525 126024 s->block_last_index[i] = ret;
526 }
527 }
528 } else {
529
2/2
✓ Branch 0 taken 214216 times.
✓ Branch 1 taken 1913129 times.
2127345 if (mb_type & MB_TYPE_ZERO_MV) {
530 av_assert2(mb_type & MB_TYPE_CBP);
531
532 214216 s->mv_dir = MV_DIR_FORWARD;
533
2/2
✓ Branch 0 taken 87903 times.
✓ Branch 1 taken 126313 times.
214216 if (s->picture_structure == PICT_FRAME) {
534
1/2
✓ Branch 0 taken 87903 times.
✗ Branch 1 not taken.
87903 if (s->picture_structure == PICT_FRAME
535
2/2
✓ Branch 0 taken 52116 times.
✓ Branch 1 taken 35787 times.
87903 && !s->frame_pred_frame_dct)
536 52116 s->interlaced_dct = get_bits1(&s->gb);
537 87903 s->mv_type = MV_TYPE_16X16;
538 } else {
539 126313 s->mv_type = MV_TYPE_FIELD;
540 126313 mb_type |= MB_TYPE_INTERLACED;
541 126313 s->field_select[0][0] = s->picture_structure - 1;
542 }
543
544
2/2
✓ Branch 0 taken 52680 times.
✓ Branch 1 taken 161536 times.
214216 if (IS_QUANT(mb_type))
545 52680 s->qscale = mpeg_get_qscale(s);
546
547 214216 s->last_mv[0][0][0] = 0;
548 214216 s->last_mv[0][0][1] = 0;
549 214216 s->last_mv[0][1][0] = 0;
550 214216 s->last_mv[0][1][1] = 0;
551 214216 s->mv[0][0][0] = 0;
552 214216 s->mv[0][0][1] = 0;
553 } else {
554 av_assert2(mb_type & MB_TYPE_BIDIR_MV);
555 // FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED
556 /* get additional motion vector type */
557
4/4
✓ Branch 0 taken 1402702 times.
✓ Branch 1 taken 510427 times.
✓ Branch 2 taken 750644 times.
✓ Branch 3 taken 652058 times.
1913129 if (s->picture_structure == PICT_FRAME && s->frame_pred_frame_dct) {
558 750644 motion_type = MT_FRAME;
559 } else {
560 1162485 motion_type = get_bits(&s->gb, 2);
561
4/4
✓ Branch 0 taken 652058 times.
✓ Branch 1 taken 510427 times.
✓ Branch 2 taken 472842 times.
✓ Branch 3 taken 179216 times.
1162485 if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type))
562 472842 s->interlaced_dct = get_bits1(&s->gb);
563 }
564
565
2/2
✓ Branch 0 taken 176983 times.
✓ Branch 1 taken 1736146 times.
1913129 if (IS_QUANT(mb_type))
566 176983 s->qscale = mpeg_get_qscale(s);
567
568 /* motion vectors */
569 1913129 s->mv_dir = MB_TYPE_MV_2_MV_DIR(mb_type);
570 ff_tlog(s->avctx, "motion_type=%d\n", motion_type);
571
3/4
✓ Branch 0 taken 1626591 times.
✓ Branch 1 taken 264618 times.
✓ Branch 2 taken 21920 times.
✗ Branch 3 not taken.
1913129 switch (motion_type) {
572 1626591 case MT_FRAME: /* or MT_16X8 */
573
2/2
✓ Branch 0 taken 1332143 times.
✓ Branch 1 taken 294448 times.
1626591 if (s->picture_structure == PICT_FRAME) {
574 1332143 mb_type |= MB_TYPE_16x16;
575 1332143 s->mv_type = MV_TYPE_16X16;
576
2/2
✓ Branch 0 taken 2664286 times.
✓ Branch 1 taken 1332143 times.
3996429 for (i = 0; i < 2; i++) {
577
2/2
✓ Branch 0 taken 1716653 times.
✓ Branch 1 taken 947633 times.
2664286 if (HAS_MV(mb_type, i)) {
578 /* MT_FRAME */
579 1716653 s->mv[i][0][0] =
580 1716653 s->last_mv[i][0][0] =
581 1716653 s->last_mv[i][1][0] =
582 1716653 mpeg_decode_motion(s, s->mpeg_f_code[i][0],
583 s->last_mv[i][0][0]);
584 1716653 s->mv[i][0][1] =
585 1716653 s->last_mv[i][0][1] =
586 1716653 s->last_mv[i][1][1] =
587 1716653 mpeg_decode_motion(s, s->mpeg_f_code[i][1],
588 s->last_mv[i][0][1]);
589 /* full_pel: only for MPEG-1 */
590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1716653 times.
1716653 if (s->full_pel[i]) {
591 s->mv[i][0][0] *= 2;
592 s->mv[i][0][1] *= 2;
593 }
594 }
595 }
596 } else {
597 294448 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
598 294448 s->mv_type = MV_TYPE_16X8;
599
2/2
✓ Branch 0 taken 588896 times.
✓ Branch 1 taken 294448 times.
883344 for (i = 0; i < 2; i++) {
600
2/2
✓ Branch 0 taken 295810 times.
✓ Branch 1 taken 293086 times.
588896 if (HAS_MV(mb_type, i)) {
601 /* MT_16X8 */
602
2/2
✓ Branch 0 taken 591620 times.
✓ Branch 1 taken 295810 times.
887430 for (j = 0; j < 2; j++) {
603 591620 s->field_select[i][j] = get_bits1(&s->gb);
604
2/2
✓ Branch 0 taken 1183240 times.
✓ Branch 1 taken 591620 times.
1774860 for (k = 0; k < 2; k++) {
605 1183240 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
606 s->last_mv[i][j][k]);
607 1183240 s->last_mv[i][j][k] = val;
608 1183240 s->mv[i][j][k] = val;
609 }
610 }
611 }
612 }
613 }
614 1626591 break;
615 264618 case MT_FIELD:
616 264618 s->mv_type = MV_TYPE_FIELD;
617
2/2
✓ Branch 0 taken 70559 times.
✓ Branch 1 taken 194059 times.
264618 if (s->picture_structure == PICT_FRAME) {
618 70559 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
619
2/2
✓ Branch 0 taken 141118 times.
✓ Branch 1 taken 70559 times.
211677 for (i = 0; i < 2; i++) {
620
2/2
✓ Branch 0 taken 88716 times.
✓ Branch 1 taken 52402 times.
141118 if (HAS_MV(mb_type, i)) {
621
2/2
✓ Branch 0 taken 177432 times.
✓ Branch 1 taken 88716 times.
266148 for (j = 0; j < 2; j++) {
622 177432 s->field_select[i][j] = get_bits1(&s->gb);
623 177432 val = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
624 s->last_mv[i][j][0]);
625 177432 s->last_mv[i][j][0] = val;
626 177432 s->mv[i][j][0] = val;
627 ff_tlog(s->avctx, "fmx=%d\n", val);
628 177432 val = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
629 177432 s->last_mv[i][j][1] >> 1);
630 177432 s->last_mv[i][j][1] = 2 * val;
631 177432 s->mv[i][j][1] = val;
632 ff_tlog(s->avctx, "fmy=%d\n", val);
633 }
634 }
635 }
636 } else {
637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 194059 times.
194059 av_assert0(!s->progressive_sequence);
638 194059 mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
639
2/2
✓ Branch 0 taken 388118 times.
✓ Branch 1 taken 194059 times.
582177 for (i = 0; i < 2; i++) {
640
2/2
✓ Branch 0 taken 198733 times.
✓ Branch 1 taken 189385 times.
388118 if (HAS_MV(mb_type, i)) {
641 198733 s->field_select[i][0] = get_bits1(&s->gb);
642
2/2
✓ Branch 0 taken 397466 times.
✓ Branch 1 taken 198733 times.
596199 for (k = 0; k < 2; k++) {
643 397466 val = mpeg_decode_motion(s, s->mpeg_f_code[i][k],
644 s->last_mv[i][0][k]);
645 397466 s->last_mv[i][0][k] = val;
646 397466 s->last_mv[i][1][k] = val;
647 397466 s->mv[i][0][k] = val;
648 }
649 }
650 }
651 }
652 264618 break;
653 21920 case MT_DMV:
654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21920 times.
21920 if (s->progressive_sequence){
655 av_log(s->avctx, AV_LOG_ERROR, "MT_DMV in progressive_sequence\n");
656 return AVERROR_INVALIDDATA;
657 }
658 21920 s->mv_type = MV_TYPE_DMV;
659
2/2
✓ Branch 0 taken 43840 times.
✓ Branch 1 taken 21920 times.
65760 for (i = 0; i < 2; i++) {
660
2/2
✓ Branch 0 taken 21920 times.
✓ Branch 1 taken 21920 times.
43840 if (HAS_MV(mb_type, i)) {
661 int dmx, dmy, mx, my, m;
662 21920 const int my_shift = s->picture_structure == PICT_FRAME;
663
664 21920 mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0],
665 s->last_mv[i][0][0]);
666 21920 s->last_mv[i][0][0] = mx;
667 21920 s->last_mv[i][1][0] = mx;
668 21920 dmx = get_dmv(s);
669 21920 my = mpeg_decode_motion(s, s->mpeg_f_code[i][1],
670 21920 s->last_mv[i][0][1] >> my_shift);
671 21920 dmy = get_dmv(s);
672
673
674 21920 s->last_mv[i][0][1] = my * (1 << my_shift);
675 21920 s->last_mv[i][1][1] = my * (1 << my_shift);
676
677 21920 s->mv[i][0][0] = mx;
678 21920 s->mv[i][0][1] = my;
679 21920 s->mv[i][1][0] = mx; // not used
680 21920 s->mv[i][1][1] = my; // not used
681
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21920 times.
21920 if (s->picture_structure == PICT_FRAME) {
683 mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
684
685 // m = 1 + 2 * s->top_field_first;
686 m = s->top_field_first ? 1 : 3;
687
688 /* top -> top pred */
689 s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
690 s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1;
691 m = 4 - m;
692 s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx;
693 s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1;
694 } else {
695 21920 mb_type |= MB_TYPE_16x16;
696
697 21920 s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx;
698 21920 s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy;
699
2/2
✓ Branch 0 taken 18786 times.
✓ Branch 1 taken 3134 times.
21920 if (s->picture_structure == PICT_TOP_FIELD)
700 18786 s->mv[i][2][1]--;
701 else
702 3134 s->mv[i][2][1]++;
703 }
704 }
705 }
706 21920 break;
707 default:
708 av_log(s->avctx, AV_LOG_ERROR,
709 "00 motion_type at %d %d\n", s->mb_x, s->mb_y);
710 return AVERROR_INVALIDDATA;
711 }
712 }
713
714 2127345 s->mb_intra = 0;
715
2/2
✓ Branch 0 taken 1705187 times.
✓ Branch 1 taken 422158 times.
2127345 if (HAS_CBP(mb_type)) {
716 1705187 s->bdsp.clear_blocks(s->block[0]);
717
718 1705187 cbp = get_vlc2(&s->gb, ff_mb_pat_vlc, MB_PAT_VLC_BITS, 1);
719
2/2
✓ Branch 0 taken 43689 times.
✓ Branch 1 taken 1661498 times.
1705187 if (mb_block_count > 6) {
720 43689 cbp *= 1 << mb_block_count - 6;
721 43689 cbp |= get_bits(&s->gb, mb_block_count - 6);
722 43689 s->bdsp.clear_blocks(s->block[6]);
723 }
724
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1705187 times.
1705187 if (cbp <= 0) {
725 av_log(s->avctx, AV_LOG_ERROR,
726 "invalid cbp %d at %d %d\n", cbp, s->mb_x, s->mb_y);
727 return AVERROR_INVALIDDATA;
728 }
729
730
2/2
✓ Branch 0 taken 1593451 times.
✓ Branch 1 taken 111736 times.
1705187 if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
731 1593451 cbp <<= 12 - mb_block_count;
732
733
2/2
✓ Branch 0 taken 9648084 times.
✓ Branch 1 taken 1593451 times.
11241535 for (i = 0; i < mb_block_count; i++) {
734
2/2
✓ Branch 0 taken 5147603 times.
✓ Branch 1 taken 4500481 times.
9648084 if (cbp & (1 << 11)) {
735
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5147603 times.
5147603 if ((ret = mpeg2_decode_block_non_intra(s, s->block[i], i)) < 0)
736 return ret;
737 } else {
738 4500481 s->block_last_index[i] = -1;
739 }
740 9648084 cbp += cbp;
741 }
742 } else {
743
2/2
✓ Branch 0 taken 670416 times.
✓ Branch 1 taken 111736 times.
782152 for (i = 0; i < 6; i++) {
744
2/2
✓ Branch 0 taken 403182 times.
✓ Branch 1 taken 267234 times.
670416 if (cbp & 32) {
745
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 403182 times.
403182 if ((ret = mpeg1_decode_block_inter(s, s->block[i], i)) < 0)
746 return ret;
747 } else {
748 267234 s->block_last_index[i] = -1;
749 }
750 670416 cbp += cbp;
751 }
752 }
753 } else {
754
2/2
✓ Branch 0 taken 5065896 times.
✓ Branch 1 taken 422158 times.
5488054 for (i = 0; i < 12; i++)
755 5065896 s->block_last_index[i] = -1;
756 }
757 }
758
759 2450953 s->cur_pic.mb_type[s->mb_x + s->mb_y * s->mb_stride] = mb_type;
760
761 2450953 return 0;
762 }
763
764 288 static av_cold int mpeg_decode_init(AVCodecContext *avctx)
765 {
766 288 Mpeg1Context *s = avctx->priv_data;
767 288 MpegEncContext *s2 = &s->mpeg_enc_ctx;
768 int ret;
769
770 288 s2->out_format = FMT_MPEG1;
771
772
2/2
✓ Branch 0 taken 286 times.
✓ Branch 1 taken 2 times.
288 if ( avctx->codec_tag != AV_RL32("VCR2")
773
1/2
✓ Branch 0 taken 286 times.
✗ Branch 1 not taken.
286 && avctx->codec_tag != AV_RL32("BW10"))
774 286 avctx->coded_width = avctx->coded_height = 0; // do not trust dimensions from input
775 288 ret = ff_mpv_decode_init(s2, avctx);
776
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 288 times.
288 if (ret < 0)
777 return ret;
778
779 288 ff_mpeg12_init_vlcs();
780
781 288 s2->chroma_format = 1;
782 288 s->repeat_field = 0;
783 288 avctx->color_range = AVCOL_RANGE_MPEG;
784 288 return 0;
785 }
786
787 #if HAVE_THREADS
788 static int mpeg_decode_update_thread_context(AVCodecContext *avctx,
789 const AVCodecContext *avctx_from)
790 {
791 Mpeg1Context *ctx = avctx->priv_data, *ctx_from = avctx_from->priv_data;
792 MpegEncContext *s = &ctx->mpeg_enc_ctx, *s1 = &ctx_from->mpeg_enc_ctx;
793 int err;
794
795 if (avctx == avctx_from || !s1->context_initialized)
796 return 0;
797
798 err = ff_mpeg_update_thread_context(avctx, avctx_from);
799 if (err)
800 return err;
801
802 if (!s->context_initialized)
803 memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext));
804
805 return 0;
806 }
807 #endif
808
809 static const enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {
810 #if CONFIG_MPEG1_NVDEC_HWACCEL
811 AV_PIX_FMT_CUDA,
812 #endif
813 #if CONFIG_MPEG1_VDPAU_HWACCEL
814 AV_PIX_FMT_VDPAU,
815 #endif
816 AV_PIX_FMT_YUV420P,
817 AV_PIX_FMT_NONE
818 };
819
820 static const enum AVPixelFormat mpeg2_hwaccel_pixfmt_list_420[] = {
821 #if CONFIG_MPEG2_NVDEC_HWACCEL
822 AV_PIX_FMT_CUDA,
823 #endif
824 #if CONFIG_MPEG2_VDPAU_HWACCEL
825 AV_PIX_FMT_VDPAU,
826 #endif
827 #if CONFIG_MPEG2_DXVA2_HWACCEL
828 AV_PIX_FMT_DXVA2_VLD,
829 #endif
830 #if CONFIG_MPEG2_D3D11VA_HWACCEL
831 AV_PIX_FMT_D3D11VA_VLD,
832 AV_PIX_FMT_D3D11,
833 #endif
834 #if CONFIG_MPEG2_D3D12VA_HWACCEL
835 AV_PIX_FMT_D3D12,
836 #endif
837 #if CONFIG_MPEG2_VAAPI_HWACCEL
838 AV_PIX_FMT_VAAPI,
839 #endif
840 #if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
841 AV_PIX_FMT_VIDEOTOOLBOX,
842 #endif
843 AV_PIX_FMT_YUV420P,
844 AV_PIX_FMT_NONE
845 };
846
847 static const enum AVPixelFormat mpeg12_pixfmt_list_422[] = {
848 AV_PIX_FMT_YUV422P,
849 AV_PIX_FMT_NONE
850 };
851
852 static const enum AVPixelFormat mpeg12_pixfmt_list_444[] = {
853 AV_PIX_FMT_YUV444P,
854 AV_PIX_FMT_NONE
855 };
856
857 263 static enum AVPixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
858 {
859 263 Mpeg1Context *s1 = avctx->priv_data;
860 263 MpegEncContext *s = &s1->mpeg_enc_ctx;
861 const enum AVPixelFormat *pix_fmts;
862
863 if (CONFIG_GRAY && (avctx->flags & AV_CODEC_FLAG_GRAY))
864 return AV_PIX_FMT_GRAY8;
865
866
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 61 times.
263 if (s->chroma_format < 2)
867 202 pix_fmts = avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO ?
868
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 177 times.
202 mpeg1_hwaccel_pixfmt_list_420 :
869 mpeg2_hwaccel_pixfmt_list_420;
870
1/2
✓ Branch 0 taken 61 times.
✗ Branch 1 not taken.
61 else if (s->chroma_format == 2)
871 61 pix_fmts = mpeg12_pixfmt_list_422;
872 else
873 pix_fmts = mpeg12_pixfmt_list_444;
874
875 263 return ff_get_format(avctx, pix_fmts);
876 }
877
878 /* Call this function when we know all parameters.
879 * It may be called in different places for MPEG-1 and MPEG-2. */
880 5072 static int mpeg_decode_postinit(AVCodecContext *avctx)
881 {
882 5072 Mpeg1Context *s1 = avctx->priv_data;
883 5072 MpegEncContext *s = &s1->mpeg_enc_ctx;
884 int ret;
885
886
2/2
✓ Branch 0 taken 494 times.
✓ Branch 1 taken 4578 times.
5072 if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
887 // MPEG-1 aspect
888 494 AVRational aspect_inv = av_d2q(ff_mpeg1_aspect[s1->aspect_ratio_info], 255);
889 494 avctx->sample_aspect_ratio = (AVRational) { aspect_inv.den, aspect_inv.num };
890 } else { // MPEG-2
891 // MPEG-2 aspect
892
2/2
✓ Branch 0 taken 2538 times.
✓ Branch 1 taken 2040 times.
4578 if (s1->aspect_ratio_info > 1) {
893 AVRational dar =
894 2538 av_mul_q(av_div_q(ff_mpeg2_aspect[s1->aspect_ratio_info],
895 2538 (AVRational) { s1->pan_scan.width,
896 2538 s1->pan_scan.height }),
897 2538 (AVRational) { s->width, s->height });
898
899 /* We ignore the spec here and guess a bit as reality does not
900 * match the spec, see for example res_change_ffmpeg_aspect.ts
901 * and sequence-display-aspect.mpg.
902 * issue1613, 621, 562 */
903
5/6
✓ Branch 0 taken 583 times.
✓ Branch 1 taken 1955 times.
✓ Branch 2 taken 583 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27 times.
✓ Branch 5 taken 556 times.
3121 if ((s1->pan_scan.width == 0) || (s1->pan_scan.height == 0) ||
904
2/2
✓ Branch 1 taken 26 times.
✓ Branch 2 taken 1 times.
610 (av_cmp_q(dar, (AVRational) { 4, 3 }) &&
905 27 av_cmp_q(dar, (AVRational) { 16, 9 }))) {
906 1981 s->avctx->sample_aspect_ratio =
907 1981 av_div_q(ff_mpeg2_aspect[s1->aspect_ratio_info],
908 1981 (AVRational) { s->width, s->height });
909 } else {
910 557 s->avctx->sample_aspect_ratio =
911 557 av_div_q(ff_mpeg2_aspect[s1->aspect_ratio_info],
912 557 (AVRational) { s1->pan_scan.width, s1->pan_scan.height });
913 // issue1613 4/3 16/9 -> 16/9
914 // res_change_ffmpeg_aspect.ts 4/3 225/44 ->4/3
915 // widescreen-issue562.mpg 4/3 16/9 -> 16/9
916 // s->avctx->sample_aspect_ratio = av_mul_q(s->avctx->sample_aspect_ratio, (AVRational) {s->width, s->height});
917 ff_dlog(avctx, "aspect A %d/%d\n",
918 ff_mpeg2_aspect[s1->aspect_ratio_info].num,
919 ff_mpeg2_aspect[s1->aspect_ratio_info].den);
920 ff_dlog(avctx, "aspect B %d/%d\n", s->avctx->sample_aspect_ratio.num,
921 s->avctx->sample_aspect_ratio.den);
922 }
923 } else {
924 2040 s->avctx->sample_aspect_ratio =
925 2040 ff_mpeg2_aspect[s1->aspect_ratio_info];
926 }
927 } // MPEG-2
928
929
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5072 times.
5072 if (av_image_check_sar(s->width, s->height,
930 avctx->sample_aspect_ratio) < 0) {
931 av_log(avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
932 avctx->sample_aspect_ratio.num,
933 avctx->sample_aspect_ratio.den);
934 avctx->sample_aspect_ratio = (AVRational){ 0, 1 };
935 }
936
937
2/2
✓ Branch 0 taken 4813 times.
✓ Branch 1 taken 259 times.
5072 if (!s->context_initialized ||
938
1/2
✓ Branch 0 taken 4813 times.
✗ Branch 1 not taken.
4813 avctx->coded_width != s->width ||
939
1/2
✓ Branch 0 taken 4813 times.
✗ Branch 1 not taken.
4813 avctx->coded_height != s->height ||
940
1/2
✓ Branch 0 taken 4813 times.
✗ Branch 1 not taken.
4813 s1->save_width != s->width ||
941
3/4
✓ Branch 0 taken 4813 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4811 times.
✓ Branch 3 taken 2 times.
9626 s1->save_height != s->height ||
942 4813 av_cmp_q(s1->save_aspect, s->avctx->sample_aspect_ratio) ||
943
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4811 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4811 (s1->save_progressive_seq != s->progressive_sequence && FFALIGN(s->height, 16) != FFALIGN(s->height, 32)) ||
944 0) {
945
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 259 times.
261 if (s->context_initialized)
946 2 ff_mpv_common_end(s);
947
948 261 ret = ff_set_dimensions(avctx, s->width, s->height);
949
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 261 times.
261 if (ret < 0)
950 return ret;
951
952
4/4
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 25 times.
✓ Branch 2 taken 234 times.
✓ Branch 3 taken 2 times.
261 if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->bit_rate &&
953
2/2
✓ Branch 0 taken 99 times.
✓ Branch 1 taken 135 times.
234 (s->bit_rate != 0x3FFFF*400)) {
954 99 avctx->rc_max_rate = s->bit_rate;
955
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 137 times.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
162 } else if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && s->bit_rate &&
956
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
25 (s->bit_rate != 0x3FFFF*400 || s->vbv_delay != 0xFFFF)) {
957 25 avctx->bit_rate = s->bit_rate;
958 }
959 261 s1->save_aspect = s->avctx->sample_aspect_ratio;
960 261 s1->save_width = s->width;
961 261 s1->save_height = s->height;
962 261 s1->save_progressive_seq = s->progressive_sequence;
963
964 /* low_delay may be forced, in this case we will have B-frames
965 * that behave like P-frames. */
966 261 avctx->has_b_frames = !s->low_delay;
967
968
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 236 times.
261 if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
969 // MPEG-1 fps
970 25 avctx->framerate = ff_mpeg12_frame_rate_tab[s1->frame_rate_index];
971 #if FF_API_TICKS_PER_FRAME
972 FF_DISABLE_DEPRECATION_WARNINGS
973 25 avctx->ticks_per_frame = 1;
974 FF_ENABLE_DEPRECATION_WARNINGS
975 #endif
976
977 25 avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
978 } else { // MPEG-2
979 // MPEG-2 fps
980 236 av_reduce(&s->avctx->framerate.num,
981 236 &s->avctx->framerate.den,
982 236 ff_mpeg12_frame_rate_tab[s1->frame_rate_index].num * s1->frame_rate_ext.num,
983 236 ff_mpeg12_frame_rate_tab[s1->frame_rate_index].den * s1->frame_rate_ext.den,
984 1 << 30);
985 #if FF_API_TICKS_PER_FRAME
986 FF_DISABLE_DEPRECATION_WARNINGS
987 236 avctx->ticks_per_frame = 2;
988 FF_ENABLE_DEPRECATION_WARNINGS
989 #endif
990
991
2/3
✓ Branch 0 taken 175 times.
✓ Branch 1 taken 61 times.
✗ Branch 2 not taken.
236 switch (s->chroma_format) {
992 175 case 1: avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; break;
993 61 case 2:
994 61 case 3: avctx->chroma_sample_location = AVCHROMA_LOC_TOPLEFT; break;
995 default: av_assert0(0);
996 }
997 } // MPEG-2
998
999 261 avctx->pix_fmt = mpeg_get_pixelformat(avctx);
1000
1001
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 261 times.
261 if ((ret = ff_mpv_common_init(s)) < 0)
1002 return ret;
1003
1/2
✓ Branch 0 taken 261 times.
✗ Branch 1 not taken.
261 if (!s->avctx->lowres)
1004 261 ff_mpv_framesize_disable(&s->sc);
1005 }
1006 5072 return 0;
1007 }
1008
1009 5072 static int mpeg1_decode_picture(AVCodecContext *avctx, const uint8_t *buf,
1010 int buf_size)
1011 {
1012 5072 Mpeg1Context *s1 = avctx->priv_data;
1013 5072 MpegEncContext *s = &s1->mpeg_enc_ctx;
1014 int ref, f_code, vbv_delay, ret;
1015
1016 5072 ret = init_get_bits8(&s->gb, buf, buf_size);
1017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5072 times.
5072 if (ret < 0)
1018 return ret;
1019
1020 5072 ref = get_bits(&s->gb, 10); /* temporal ref */
1021 5072 s->pict_type = get_bits(&s->gb, 3);
1022
2/4
✓ Branch 0 taken 5072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5072 times.
5072 if (s->pict_type == 0 || s->pict_type > 3)
1023 return AVERROR_INVALIDDATA;
1024
1025 5072 vbv_delay = get_bits(&s->gb, 16);
1026 5072 s->vbv_delay = vbv_delay;
1027
2/2
✓ Branch 0 taken 2332 times.
✓ Branch 1 taken 2740 times.
5072 if (s->pict_type == AV_PICTURE_TYPE_P ||
1028
2/2
✓ Branch 0 taken 1618 times.
✓ Branch 1 taken 714 times.
2332 s->pict_type == AV_PICTURE_TYPE_B) {
1029 4358 s->full_pel[0] = get_bits1(&s->gb);
1030 4358 f_code = get_bits(&s->gb, 3);
1031
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4358 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4358 if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)))
1032 return AVERROR_INVALIDDATA;
1033 4358 f_code += !f_code;
1034 4358 s->mpeg_f_code[0][0] = f_code;
1035 4358 s->mpeg_f_code[0][1] = f_code;
1036 }
1037
2/2
✓ Branch 0 taken 1618 times.
✓ Branch 1 taken 3454 times.
5072 if (s->pict_type == AV_PICTURE_TYPE_B) {
1038 1618 s->full_pel[1] = get_bits1(&s->gb);
1039 1618 f_code = get_bits(&s->gb, 3);
1040
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1618 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1618 if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)))
1041 return AVERROR_INVALIDDATA;
1042 1618 f_code += !f_code;
1043 1618 s->mpeg_f_code[1][0] = f_code;
1044 1618 s->mpeg_f_code[1][1] = f_code;
1045 }
1046
1047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5072 times.
5072 if (avctx->debug & FF_DEBUG_PICT_INFO)
1048 av_log(avctx, AV_LOG_DEBUG,
1049 "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->pict_type);
1050
1051 5072 s->y_dc_scale = 8;
1052 5072 s->c_dc_scale = 8;
1053 5072 return 0;
1054 }
1055
1056 720 static void mpeg_decode_sequence_extension(Mpeg1Context *s1)
1057 {
1058 720 MpegEncContext *s = &s1->mpeg_enc_ctx;
1059 int horiz_size_ext, vert_size_ext;
1060 int bit_rate_ext;
1061
1062 720 skip_bits(&s->gb, 1); /* profile and level esc*/
1063 720 s->avctx->profile = get_bits(&s->gb, 3);
1064 720 s->avctx->level = get_bits(&s->gb, 4);
1065 720 s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */
1066 720 s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */
1067
1068
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 720 times.
720 if (!s->chroma_format) {
1069 s->chroma_format = 1;
1070 av_log(s->avctx, AV_LOG_WARNING, "Chroma format invalid\n");
1071 }
1072
1073 720 horiz_size_ext = get_bits(&s->gb, 2);
1074 720 vert_size_ext = get_bits(&s->gb, 2);
1075 720 s->width |= (horiz_size_ext << 12);
1076 720 s->height |= (vert_size_ext << 12);
1077 720 bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */
1078 720 s->bit_rate += (bit_rate_ext << 18) * 400LL;
1079 720 check_marker(s->avctx, &s->gb, "after bit rate extension");
1080 720 s->avctx->rc_buffer_size += get_bits(&s->gb, 8) * 1024 * 16 << 10;
1081
1082 720 s->low_delay = get_bits1(&s->gb);
1083
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 720 times.
720 if (s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
1084 s->low_delay = 1;
1085
1086 720 s1->frame_rate_ext.num = get_bits(&s->gb, 2) + 1;
1087 720 s1->frame_rate_ext.den = get_bits(&s->gb, 5) + 1;
1088
1089 ff_dlog(s->avctx, "sequence extension\n");
1090 720 s->codec_id = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
1091
1092
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 720 times.
720 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1093 av_log(s->avctx, AV_LOG_DEBUG,
1094 "profile: %d, level: %d ps: %d cf:%d vbv buffer: %d, bitrate:%"PRId64"\n",
1095 s->avctx->profile, s->avctx->level, s->progressive_sequence, s->chroma_format,
1096 s->avctx->rc_buffer_size, s->bit_rate);
1097 720 }
1098
1099 95 static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1)
1100 {
1101 95 MpegEncContext *s = &s1->mpeg_enc_ctx;
1102 int color_description, w, h;
1103
1104 95 skip_bits(&s->gb, 3); /* video format */
1105 95 color_description = get_bits1(&s->gb);
1106
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 62 times.
95 if (color_description) {
1107 33 s->avctx->color_primaries = get_bits(&s->gb, 8);
1108 33 s->avctx->color_trc = get_bits(&s->gb, 8);
1109 33 s->avctx->colorspace = get_bits(&s->gb, 8);
1110 }
1111 95 w = get_bits(&s->gb, 14);
1112 95 skip_bits(&s->gb, 1); // marker
1113 95 h = get_bits(&s->gb, 14);
1114 // remaining 3 bits are zero padding
1115
1116 95 s1->pan_scan.width = 16 * w;
1117 95 s1->pan_scan.height = 16 * h;
1118
1119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 95 times.
95 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1120 av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h);
1121 95 }
1122
1123 27 static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
1124 {
1125 27 MpegEncContext *s = &s1->mpeg_enc_ctx;
1126 int i, nofco;
1127
1128 27 nofco = 1;
1129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (s->progressive_sequence) {
1130 if (s->repeat_first_field) {
1131 nofco++;
1132 if (s->top_field_first)
1133 nofco++;
1134 }
1135 } else {
1136
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 if (s->picture_structure == PICT_FRAME) {
1137 9 nofco++;
1138
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 if (s->repeat_first_field)
1139 6 nofco++;
1140 }
1141 }
1142
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 27 times.
69 for (i = 0; i < nofco; i++) {
1143 42 s1->pan_scan.position[i][0] = get_sbits(&s->gb, 16);
1144 42 skip_bits(&s->gb, 1); // marker
1145 42 s1->pan_scan.position[i][1] = get_sbits(&s->gb, 16);
1146 42 skip_bits(&s->gb, 1); // marker
1147 }
1148
1149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1150 av_log(s->avctx, AV_LOG_DEBUG,
1151 "pde (%"PRId16",%"PRId16") (%"PRId16",%"PRId16") (%"PRId16",%"PRId16")\n",
1152 s1->pan_scan.position[0][0], s1->pan_scan.position[0][1],
1153 s1->pan_scan.position[1][0], s1->pan_scan.position[1][1],
1154 s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]);
1155 27 }
1156
1157 225 static int load_matrix(MpegEncContext *s, uint16_t matrix0[64],
1158 uint16_t matrix1[64], int intra)
1159 {
1160 int i;
1161
1162
2/2
✓ Branch 0 taken 14400 times.
✓ Branch 1 taken 225 times.
14625 for (i = 0; i < 64; i++) {
1163 14400 int j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
1164 14400 int v = get_bits(&s->gb, 8);
1165
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14400 times.
14400 if (v == 0) {
1166 av_log(s->avctx, AV_LOG_ERROR, "matrix damaged\n");
1167 return AVERROR_INVALIDDATA;
1168 }
1169
5/6
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 10240 times.
✓ Branch 2 taken 65 times.
✓ Branch 3 taken 4095 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 65 times.
14400 if (intra && i == 0 && v != 8) {
1170 av_log(s->avctx, AV_LOG_DEBUG, "intra matrix specifies invalid DC quantizer %d, ignoring\n", v);
1171 v = 8; // needed by pink.mpg / issue1046
1172 }
1173 14400 matrix0[j] = v;
1174
2/2
✓ Branch 0 taken 13760 times.
✓ Branch 1 taken 640 times.
14400 if (matrix1)
1175 13760 matrix1[j] = v;
1176 }
1177 225 return 0;
1178 }
1179
1180 995 static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
1181 {
1182 ff_dlog(s->avctx, "matrix extension\n");
1183
1184
2/2
✓ Branch 1 taken 34 times.
✓ Branch 2 taken 961 times.
995 if (get_bits1(&s->gb))
1185 34 load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
1186
2/2
✓ Branch 1 taken 75 times.
✓ Branch 2 taken 920 times.
995 if (get_bits1(&s->gb))
1187 75 load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
1188
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 986 times.
995 if (get_bits1(&s->gb))
1189 9 load_matrix(s, s->chroma_intra_matrix, NULL, 1);
1190
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 994 times.
995 if (get_bits1(&s->gb))
1191 1 load_matrix(s, s->chroma_inter_matrix, NULL, 0);
1192 995 }
1193
1194 4578 static int mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
1195 {
1196 4578 MpegEncContext *s = &s1->mpeg_enc_ctx;
1197
1198 4578 s->full_pel[0] = s->full_pel[1] = 0;
1199 4578 s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
1200 4578 s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
1201 4578 s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
1202 4578 s->mpeg_f_code[1][1] = get_bits(&s->gb, 4);
1203 4578 s->mpeg_f_code[0][0] += !s->mpeg_f_code[0][0];
1204 4578 s->mpeg_f_code[0][1] += !s->mpeg_f_code[0][1];
1205 4578 s->mpeg_f_code[1][0] += !s->mpeg_f_code[1][0];
1206 4578 s->mpeg_f_code[1][1] += !s->mpeg_f_code[1][1];
1207
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4578 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4578 if (!s->pict_type && s->context_initialized) {
1208 av_log(s->avctx, AV_LOG_ERROR, "Missing picture start code\n");
1209 if (s->avctx->err_recognition & AV_EF_EXPLODE)
1210 return AVERROR_INVALIDDATA;
1211 av_log(s->avctx, AV_LOG_WARNING, "Guessing pict_type from mpeg_f_code\n");
1212 if (s->mpeg_f_code[1][0] == 15 && s->mpeg_f_code[1][1] == 15) {
1213 if (s->mpeg_f_code[0][0] == 15 && s->mpeg_f_code[0][1] == 15)
1214 s->pict_type = AV_PICTURE_TYPE_I;
1215 else
1216 s->pict_type = AV_PICTURE_TYPE_P;
1217 } else
1218 s->pict_type = AV_PICTURE_TYPE_B;
1219 }
1220
1221 4578 s->intra_dc_precision = get_bits(&s->gb, 2);
1222 4578 s->picture_structure = get_bits(&s->gb, 2);
1223 4578 s->top_field_first = get_bits1(&s->gb);
1224 4578 s->frame_pred_frame_dct = get_bits1(&s->gb);
1225 4578 s->concealment_motion_vectors = get_bits1(&s->gb);
1226 4578 s->q_scale_type = get_bits1(&s->gb);
1227 4578 s->intra_vlc_format = get_bits1(&s->gb);
1228 4578 s->alternate_scan = get_bits1(&s->gb);
1229 4578 s->repeat_first_field = get_bits1(&s->gb);
1230 4578 s->chroma_420_type = get_bits1(&s->gb);
1231 4578 s->progressive_frame = get_bits1(&s->gb);
1232
1233 // We only initialize intra_scantable, as both scantables always coincide
1234 // and all code therefore only uses the intra one.
1235 4578 ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable,
1236
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 3282 times.
4578 s->alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct);
1237
1238 /* composite display not parsed */
1239 ff_dlog(s->avctx, "intra_dc_precision=%d\n", s->intra_dc_precision);
1240 ff_dlog(s->avctx, "picture_structure=%d\n", s->picture_structure);
1241 ff_dlog(s->avctx, "top field first=%d\n", s->top_field_first);
1242 ff_dlog(s->avctx, "repeat first field=%d\n", s->repeat_first_field);
1243 ff_dlog(s->avctx, "conceal=%d\n", s->concealment_motion_vectors);
1244 ff_dlog(s->avctx, "intra_vlc_format=%d\n", s->intra_vlc_format);
1245 ff_dlog(s->avctx, "alternate_scan=%d\n", s->alternate_scan);
1246 ff_dlog(s->avctx, "frame_pred_frame_dct=%d\n", s->frame_pred_frame_dct);
1247 ff_dlog(s->avctx, "progressive_frame=%d\n", s->progressive_frame);
1248
1249 4578 return 0;
1250 }
1251
1252 4627 static int mpeg_field_start(Mpeg1Context *s1, const uint8_t *buf, int buf_size)
1253 {
1254 4627 MpegEncContext *s = &s1->mpeg_enc_ctx;
1255 4627 AVCodecContext *avctx = s->avctx;
1256 4627 int second_field = 0;
1257 int ret;
1258
1259
1/2
✓ Branch 0 taken 4627 times.
✗ Branch 1 not taken.
4627 if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
1260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4627 times.
4627 if (s->mb_width * s->mb_height * 11LL / (33 * 2 * 8) > buf_size)
1261 return AVERROR_INVALIDDATA;
1262 }
1263
1264 /* start frame decoding */
1265
4/4
✓ Branch 0 taken 3908 times.
✓ Branch 1 taken 719 times.
✓ Branch 2 taken 3189 times.
✓ Branch 3 taken 719 times.
8535 if (s->first_field || s->picture_structure == PICT_FRAME) {
1266 AVFrameSideData *pan_scan;
1267
1268
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3908 times.
3908 if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
1269 return ret;
1270
1271
2/2
✓ Branch 0 taken 719 times.
✓ Branch 1 taken 3189 times.
3908 if (s->picture_structure != PICT_FRAME) {
1272 719 s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST *
1273
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 717 times.
719 (s->picture_structure == PICT_TOP_FIELD);
1274
1275
2/2
✓ Branch 0 taken 2157 times.
✓ Branch 1 taken 719 times.
2876 for (int i = 0; i < 3; i++) {
1276
2/2
✓ Branch 0 taken 2151 times.
✓ Branch 1 taken 6 times.
2157 if (s->picture_structure == PICT_BOTTOM_FIELD) {
1277
1/2
✓ Branch 0 taken 2151 times.
✗ Branch 1 not taken.
2151 s->cur_pic.data[i] = FF_PTR_ADD(s->cur_pic.data[i],
1278 s->cur_pic.linesize[i]);
1279 }
1280 2157 s->cur_pic.linesize[i] *= 2;
1281 }
1282 }
1283
1284 3908 ff_mpeg_er_frame_start(s);
1285
1286 /* first check if we must repeat the frame */
1287 3908 s->cur_pic.ptr->f->repeat_pict = 0;
1288
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3902 times.
3908 if (s->repeat_first_field) {
1289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (s->progressive_sequence) {
1290 if (s->top_field_first)
1291 s->cur_pic.ptr->f->repeat_pict = 4;
1292 else
1293 s->cur_pic.ptr->f->repeat_pict = 2;
1294
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 } else if (s->progressive_frame) {
1295 6 s->cur_pic.ptr->f->repeat_pict = 1;
1296 }
1297 }
1298
1299 3908 ret = ff_frame_new_side_data(s->avctx, s->cur_pic.ptr->f,
1300 AV_FRAME_DATA_PANSCAN, sizeof(s1->pan_scan),
1301 &pan_scan);
1302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3908 times.
3908 if (ret < 0)
1303 return ret;
1304
1/2
✓ Branch 0 taken 3908 times.
✗ Branch 1 not taken.
3908 if (pan_scan)
1305 3908 memcpy(pan_scan->data, &s1->pan_scan, sizeof(s1->pan_scan));
1306
1307
2/2
✓ Branch 0 taken 742 times.
✓ Branch 1 taken 3166 times.
3908 if (s1->a53_buf_ref) {
1308 742 ret = ff_frame_new_side_data_from_buf(
1309 742 s->avctx, s->cur_pic.ptr->f, AV_FRAME_DATA_A53_CC,
1310 &s1->a53_buf_ref);
1311
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 742 times.
742 if (ret < 0)
1312 return ret;
1313 }
1314
1315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3908 times.
3908 if (s1->has_stereo3d) {
1316 AVStereo3D *stereo = av_stereo3d_create_side_data(s->cur_pic.ptr->f);
1317 if (!stereo)
1318 return AVERROR(ENOMEM);
1319
1320 stereo->type = s1->stereo3d_type;
1321 s1->has_stereo3d = 0;
1322 }
1323
1324
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 3706 times.
3908 if (s1->has_afd) {
1325 AVFrameSideData *sd;
1326 202 ret = ff_frame_new_side_data(s->avctx, s->cur_pic.ptr->f,
1327 AV_FRAME_DATA_AFD, 1, &sd);
1328
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 202 times.
202 if (ret < 0)
1329 return ret;
1330
1/2
✓ Branch 0 taken 202 times.
✗ Branch 1 not taken.
202 if (sd)
1331 202 *sd->data = s1->afd;
1332 202 s1->has_afd = 0;
1333 }
1334
1335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3908 times.
3908 if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME))
1336 ff_thread_finish_setup(avctx);
1337 } else { // second field
1338 719 second_field = 1;
1339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 719 times.
719 if (!s->cur_pic.ptr) {
1340 av_log(s->avctx, AV_LOG_ERROR, "first field missing\n");
1341 return AVERROR_INVALIDDATA;
1342 }
1343
1344
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 719 times.
719 if (s->avctx->hwaccel) {
1345 if ((ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame)) < 0) {
1346 av_log(avctx, AV_LOG_ERROR,
1347 "hardware accelerator failed to decode first field\n");
1348 return ret;
1349 }
1350 }
1351 719 ret = ff_mpv_alloc_dummy_frames(s);
1352
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 719 times.
719 if (ret < 0)
1353 return ret;
1354
1355
2/2
✓ Branch 0 taken 2157 times.
✓ Branch 1 taken 719 times.
2876 for (int i = 0; i < 3; i++) {
1356 2157 s->cur_pic.data[i] = s->cur_pic.ptr->f->data[i];
1357
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2151 times.
2157 if (s->picture_structure == PICT_BOTTOM_FIELD)
1358 6 s->cur_pic.data[i] +=
1359 6 s->cur_pic.ptr->f->linesize[i];
1360 }
1361 }
1362
1363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4627 times.
4627 if (avctx->hwaccel) {
1364 if ((ret = FF_HW_CALL(avctx, start_frame, buf, buf_size)) < 0)
1365 return ret;
1366
2/2
✓ Branch 0 taken 157 times.
✓ Branch 1 taken 4470 times.
4627 } else if (s->codec_tag == MKTAG('V', 'C', 'R', '2')) {
1367 // Exchange UV
1368 157 FFSWAP(uint8_t*, s->cur_pic.data[1], s->cur_pic.data[2]);
1369 157 FFSWAP(ptrdiff_t, s->cur_pic.linesize[1], s->cur_pic.linesize[2]);
1370
1/2
✓ Branch 0 taken 157 times.
✗ Branch 1 not taken.
157 if (!second_field) {
1371 157 FFSWAP(uint8_t*, s->next_pic.data[1], s->next_pic.data[2]);
1372 157 FFSWAP(ptrdiff_t, s->next_pic.linesize[1], s->next_pic.linesize[2]);
1373 157 FFSWAP(uint8_t*, s->last_pic.data[1], s->last_pic.data[2]);
1374 157 FFSWAP(ptrdiff_t, s->last_pic.linesize[1], s->last_pic.linesize[2]);
1375 }
1376 }
1377
1378 4627 return 0;
1379 }
1380
1381 #define DECODE_SLICE_ERROR -1
1382 #define DECODE_SLICE_OK 0
1383
1384 /**
1385 * Decode a slice.
1386 * MpegEncContext.mb_y must be set to the MB row from the startcode.
1387 * @return DECODE_SLICE_ERROR if the slice is damaged,
1388 * DECODE_SLICE_OK if this slice is OK
1389 */
1390 127381 static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
1391 const uint8_t **buf, int buf_size)
1392 {
1393 127381 AVCodecContext *avctx = s->avctx;
1394 127381 const int lowres = s->avctx->lowres;
1395 127381 const int field_pic = s->picture_structure != PICT_FRAME;
1396 int ret;
1397
1398 127381 s->resync_mb_x =
1399 127381 s->resync_mb_y = -1;
1400
1401
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127381 times.
127381 av_assert0(mb_y < s->mb_height);
1402
1403 127381 ret = init_get_bits8(&s->gb, *buf, buf_size);
1404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127381 times.
127381 if (ret < 0)
1405 return ret;
1406
1407
3/4
✓ Branch 0 taken 120108 times.
✓ Branch 1 taken 7273 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 120108 times.
127381 if (s->codec_id != AV_CODEC_ID_MPEG1VIDEO && s->mb_height > 2800/16)
1408 skip_bits(&s->gb, 3);
1409
1410 127381 ff_mpeg1_clean_buffers(s);
1411 127381 s->interlaced_dct = 0;
1412
1413 127381 s->qscale = mpeg_get_qscale(s);
1414
1415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127381 times.
127381 if (s->qscale == 0) {
1416 av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
1417 return AVERROR_INVALIDDATA;
1418 }
1419
1420 /* extra slice info */
1421
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 127381 times.
127381 if (skip_1stop_8data_bits(&s->gb) < 0)
1422 return AVERROR_INVALIDDATA;
1423
1424 127381 s->mb_x = 0;
1425
1426
3/4
✓ Branch 0 taken 5403 times.
✓ Branch 1 taken 121978 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5403 times.
127381 if (mb_y == 0 && s->codec_tag == AV_RL32("SLIF")) {
1427 skip_bits1(&s->gb);
1428 } else {
1429
1/2
✓ Branch 1 taken 140379 times.
✗ Branch 2 not taken.
267760 while (get_bits_left(&s->gb) > 0) {
1430 140379 int code = get_vlc2(&s->gb, ff_mbincr_vlc,
1431 MBINCR_VLC_BITS, 2);
1432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 140379 times.
140379 if (code < 0) {
1433 av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
1434 return AVERROR_INVALIDDATA;
1435 }
1436
2/2
✓ Branch 0 taken 12998 times.
✓ Branch 1 taken 127381 times.
140379 if (code >= 33) {
1437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12998 times.
12998 if (code == 33)
1438 12998 s->mb_x += 33;
1439 /* otherwise, stuffing, nothing to do */
1440 } else {
1441 127381 s->mb_x += code;
1442 127381 break;
1443 }
1444 }
1445 }
1446
1447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127381 times.
127381 if (s->mb_x >= (unsigned) s->mb_width) {
1448 av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n");
1449 return AVERROR_INVALIDDATA;
1450 }
1451
1452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127381 times.
127381 if (avctx->hwaccel) {
1453 const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */
1454 int start_code = -1;
1455 buf_end = avpriv_find_start_code(buf_start + 2, *buf + buf_size, &start_code);
1456 if (buf_end < *buf + buf_size)
1457 buf_end -= 4;
1458 s->mb_y = mb_y;
1459 if (FF_HW_CALL(avctx, decode_slice, buf_start, buf_end - buf_start) < 0)
1460 return DECODE_SLICE_ERROR;
1461 *buf = buf_end;
1462 return DECODE_SLICE_OK;
1463 }
1464
1465 127381 s->resync_mb_x = s->mb_x;
1466 127381 s->resync_mb_y = s->mb_y = mb_y;
1467 127381 s->mb_skip_run = 0;
1468 127381 ff_init_block_index(s);
1469
1470
8/8
✓ Branch 0 taken 5403 times.
✓ Branch 1 taken 121978 times.
✓ Branch 2 taken 3908 times.
✓ Branch 3 taken 1495 times.
✓ Branch 4 taken 3906 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 3189 times.
✓ Branch 7 taken 717 times.
127381 if (s->mb_y == 0 && s->mb_x == 0 && (s->first_field || s->picture_structure == PICT_FRAME)) {
1471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3191 times.
3191 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
1472 av_log(s->avctx, AV_LOG_DEBUG,
1473 "qp:%d fc:%2d%2d%2d%2d %c %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n",
1474 s->qscale,
1475 s->mpeg_f_code[0][0], s->mpeg_f_code[0][1],
1476 s->mpeg_f_code[1][0], s->mpeg_f_code[1][1],
1477 s->pict_type == AV_PICTURE_TYPE_I ? 'I' :
1478 (s->pict_type == AV_PICTURE_TYPE_P ? 'P' :
1479 (s->pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')),
1480 s->progressive_sequence ? "ps" : "",
1481 s->progressive_frame ? "pf" : "",
1482 s->alternate_scan ? "alt" : "",
1483 s->top_field_first ? "top" : "",
1484 s->intra_dc_precision, s->picture_structure,
1485 s->frame_pred_frame_dct, s->concealment_motion_vectors,
1486 s->q_scale_type, s->intra_vlc_format,
1487 s->repeat_first_field, s->chroma_420_type ? "420" : "");
1488 }
1489 }
1490
1491 for (;;) {
1492
2/2
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 2616510 times.
2616520 if ((ret = mpeg_decode_mb(s, s->block)) < 0)
1493 10 return ret;
1494
1495 // Note motion_val is normally NULL unless we want to extract the MVs.
1496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2616510 times.
2616510 if (s->cur_pic.motion_val[0]) {
1497 const int wrap = s->b8_stride;
1498 int xy = s->mb_x * 2 + s->mb_y * 2 * wrap;
1499 int b8_xy = 4 * (s->mb_x + s->mb_y * s->mb_stride);
1500 int motion_x, motion_y, dir, i;
1501
1502 for (i = 0; i < 2; i++) {
1503 for (dir = 0; dir < 2; dir++) {
1504 if (s->mb_intra ||
1505 (dir == 1 && s->pict_type != AV_PICTURE_TYPE_B)) {
1506 motion_x = motion_y = 0;
1507 } else if (s->mv_type == MV_TYPE_16X16 ||
1508 (s->mv_type == MV_TYPE_FIELD && field_pic)) {
1509 motion_x = s->mv[dir][0][0];
1510 motion_y = s->mv[dir][0][1];
1511 } else { /* if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8)) */
1512 motion_x = s->mv[dir][i][0];
1513 motion_y = s->mv[dir][i][1];
1514 }
1515
1516 s->cur_pic.motion_val[dir][xy][0] = motion_x;
1517 s->cur_pic.motion_val[dir][xy][1] = motion_y;
1518 s->cur_pic.motion_val[dir][xy + 1][0] = motion_x;
1519 s->cur_pic.motion_val[dir][xy + 1][1] = motion_y;
1520 s->cur_pic.ref_index [dir][b8_xy] =
1521 s->cur_pic.ref_index [dir][b8_xy + 1] = s->field_select[dir][i];
1522 av_assert2(s->field_select[dir][i] == 0 ||
1523 s->field_select[dir][i] == 1);
1524 }
1525 xy += wrap;
1526 b8_xy += 2;
1527 }
1528 }
1529
1530 2616510 s->dest[0] += 16 >> lowres;
1531 2616510 s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift;
1532 2616510 s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
1533
1534 2616510 ff_mpv_reconstruct_mb(s, s->block);
1535
1536
2/2
✓ Branch 0 taken 79470 times.
✓ Branch 1 taken 2537040 times.
2616510 if (++s->mb_x >= s->mb_width) {
1537 79470 const int mb_size = 16 >> s->avctx->lowres;
1538 int left;
1539
1540 79470 ff_mpeg_draw_horiz_band(s, mb_size * (s->mb_y >> field_pic), mb_size);
1541 79470 ff_mpv_report_decode_progress(s);
1542
1543 79470 s->mb_x = 0;
1544 79470 s->mb_y += 1 << field_pic;
1545
1546
2/2
✓ Branch 0 taken 4617 times.
✓ Branch 1 taken 74853 times.
79470 if (s->mb_y >= s->mb_height) {
1547 4617 int left = get_bits_left(&s->gb);
1548 9495 int is_d10 = s->chroma_format == 2 &&
1549
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 212 times.
261 s->pict_type == AV_PICTURE_TYPE_I &&
1550
2/4
✓ Branch 0 taken 49 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
49 avctx->profile == 0 && avctx->level == 5 &&
1551
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 24 times.
49 s->intra_dc_precision == 2 &&
1552
4/6
✓ Branch 0 taken 261 times.
✓ Branch 1 taken 4356 times.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
4903 s->q_scale_type == 1 && s->alternate_scan == 0 &&
1553
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 s->progressive_frame == 0
1554 /* vbv_delay == 0xBBB || 0xE10 */;
1555
1556
4/4
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 3133 times.
✓ Branch 2 taken 1459 times.
✓ Branch 3 taken 25 times.
4617 if (left >= 32 && !is_d10) {
1557 1459 GetBitContext gb = s->gb;
1558 1459 align_get_bits(&gb);
1559
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1459 times.
1459 if (show_bits(&gb, 24) == 0x060E2B) {
1560 av_log(avctx, AV_LOG_DEBUG, "Invalid MXF data found in video stream\n");
1561 is_d10 = 1;
1562 }
1563
3/4
✓ Branch 0 taken 1458 times.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1458 times.
1459 if (left > 32 && show_bits_long(&gb, 32) == 0x201) {
1564 av_log(avctx, AV_LOG_DEBUG, "skipping m704 alpha (unsupported)\n");
1565 goto eos;
1566 }
1567 }
1568
1569
3/4
✓ Branch 0 taken 4617 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4315 times.
✓ Branch 3 taken 302 times.
4617 if (left < 0 ||
1570
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 4315 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
4315 (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10) ||
1571
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4617 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4617 ((avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) && left > 8)) {
1572 av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X at %d %d\n",
1573 left, left>0 ? show_bits(&s->gb, FFMIN(left, 23)) : 0, s->mb_x, s->mb_y);
1574 return AVERROR_INVALIDDATA;
1575 } else
1576 4617 goto eos;
1577 }
1578 // There are some files out there which are missing the last slice
1579 // in cases where the slice is completely outside the visible
1580 // area, we detect this here instead of running into the end expecting
1581 // more data
1582 74853 left = get_bits_left(&s->gb);
1583
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 74653 times.
74853 if (s->mb_y >= ((s->height + 15) >> 4) &&
1584
2/4
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 200 times.
200 !s->progressive_sequence &&
1585 left <= 25 &&
1586 left >= 0 &&
1587 s->mb_skip_run == -1 &&
1588 (!left || show_bits(&s->gb, left) == 0))
1589 goto eos;
1590
1591 74853 ff_init_block_index(s);
1592 }
1593
1594 /* skip mb handling */
1595
2/2
✓ Branch 0 taken 2446336 times.
✓ Branch 1 taken 165557 times.
2611893 if (s->mb_skip_run == -1) {
1596 /* read increment again */
1597 2446336 s->mb_skip_run = 0;
1598 1230 for (;;) {
1599 2447566 int code = get_vlc2(&s->gb, ff_mbincr_vlc,
1600 MBINCR_VLC_BITS, 2);
1601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2447566 times.
2447566 if (code < 0) {
1602 av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n");
1603 return AVERROR_INVALIDDATA;
1604 }
1605
2/2
✓ Branch 0 taken 123984 times.
✓ Branch 1 taken 2323582 times.
2447566 if (code >= 33) {
1606
2/2
✓ Branch 0 taken 1230 times.
✓ Branch 1 taken 122754 times.
123984 if (code == 33) {
1607 1230 s->mb_skip_run += 33;
1608
1/2
✓ Branch 0 taken 122754 times.
✗ Branch 1 not taken.
122754 } else if (code == 35) {
1609
2/4
✓ Branch 0 taken 122754 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 122754 times.
122754 if (s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
1610 av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
1611 return AVERROR_INVALIDDATA;
1612 }
1613 122754 goto eos; /* end of slice */
1614 }
1615 /* otherwise, stuffing, nothing to do */
1616 } else {
1617 2323582 s->mb_skip_run += code;
1618 2323582 break;
1619 }
1620 }
1621
2/2
✓ Branch 0 taken 62055 times.
✓ Branch 1 taken 2261527 times.
2323582 if (s->mb_skip_run) {
1622 int i;
1623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62055 times.
62055 if (s->pict_type == AV_PICTURE_TYPE_I) {
1624 av_log(s->avctx, AV_LOG_ERROR,
1625 "skipped MB in I-frame at %d %d\n", s->mb_x, s->mb_y);
1626 return AVERROR_INVALIDDATA;
1627 }
1628
1629 /* skip mb */
1630 62055 s->mb_intra = 0;
1631
2/2
✓ Branch 0 taken 744660 times.
✓ Branch 1 taken 62055 times.
806715 for (i = 0; i < 12; i++)
1632 744660 s->block_last_index[i] = -1;
1633
2/2
✓ Branch 0 taken 42242 times.
✓ Branch 1 taken 19813 times.
62055 if (s->picture_structure == PICT_FRAME)
1634 42242 s->mv_type = MV_TYPE_16X16;
1635 else
1636 19813 s->mv_type = MV_TYPE_FIELD;
1637
2/2
✓ Branch 0 taken 23857 times.
✓ Branch 1 taken 38198 times.
62055 if (s->pict_type == AV_PICTURE_TYPE_P) {
1638 /* if P type, zero motion vector is implied */
1639 23857 s->mv_dir = MV_DIR_FORWARD;
1640 23857 s->mv[0][0][0] = s->mv[0][0][1] = 0;
1641 23857 s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0;
1642 23857 s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0;
1643 23857 s->field_select[0][0] = (s->picture_structure - 1) & 1;
1644 } else {
1645 /* if B type, reuse previous vectors and directions */
1646 38198 s->mv[0][0][0] = s->last_mv[0][0][0];
1647 38198 s->mv[0][0][1] = s->last_mv[0][0][1];
1648 38198 s->mv[1][0][0] = s->last_mv[1][0][0];
1649 38198 s->mv[1][0][1] = s->last_mv[1][0][1];
1650 38198 s->field_select[0][0] = (s->picture_structure - 1) & 1;
1651 38198 s->field_select[1][0] = (s->picture_structure - 1) & 1;
1652 }
1653 }
1654 }
1655 }
1656 127371 eos: // end of slice
1657
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 127371 times.
127371 if (get_bits_left(&s->gb) < 0) {
1658 av_log(s, AV_LOG_ERROR, "overread %d\n", -get_bits_left(&s->gb));
1659 return AVERROR_INVALIDDATA;
1660 }
1661 127371 *buf += (get_bits_count(&s->gb) - 1) / 8;
1662 ff_dlog(s, "Slice start:%d %d end:%d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y);
1663 127371 return 0;
1664 }
1665
1666 6678 static int slice_decode_thread(AVCodecContext *c, void *arg)
1667 {
1668 6678 MpegEncContext *s = *(void **) arg;
1669 6678 const uint8_t *buf = s->gb.buffer;
1670 6678 int mb_y = s->start_mb_y;
1671 6678 const int field_pic = s->picture_structure != PICT_FRAME;
1672
1673 6678 s->er.error_count = (3 * (s->end_mb_y - s->start_mb_y) * s->mb_width) >> field_pic;
1674
1675 15582 for (;;) {
1676 uint32_t start_code;
1677 int ret;
1678
1679 22260 ret = mpeg_decode_slice(s, mb_y, &buf, s->gb.buffer_end - buf);
1680 22260 emms_c();
1681 ff_dlog(c, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
1682 ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y,
1683 s->start_mb_y, s->end_mb_y, s->er.error_count);
1684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22260 times.
22260 if (ret < 0) {
1685 if (c->err_recognition & AV_EF_EXPLODE)
1686 6678 return ret;
1687 if (s->resync_mb_x >= 0 && s->resync_mb_y >= 0)
1688 ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
1689 s->mb_x, s->mb_y,
1690 ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR);
1691 } else {
1692 22260 ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
1693 22260 s->mb_x - 1, s->mb_y,
1694 ER_AC_END | ER_DC_END | ER_MV_END);
1695 }
1696
1697
2/2
✓ Branch 0 taken 6678 times.
✓ Branch 1 taken 15582 times.
22260 if (s->mb_y == s->end_mb_y)
1698 6678 return 0;
1699
1700 15582 start_code = -1;
1701 15582 buf = avpriv_find_start_code(buf, s->gb.buffer_end, &start_code);
1702
2/4
✓ Branch 0 taken 15582 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15582 times.
15582 if (start_code < SLICE_MIN_START_CODE || start_code > SLICE_MAX_START_CODE)
1703 return AVERROR_INVALIDDATA;
1704 15582 mb_y = start_code - SLICE_MIN_START_CODE;
1705
2/4
✓ Branch 0 taken 15582 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15582 times.
15582 if (s->codec_id != AV_CODEC_ID_MPEG1VIDEO && s->mb_height > 2800/16)
1706 mb_y += (*buf&0xE0)<<2;
1707 15582 mb_y <<= field_pic;
1708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15582 times.
15582 if (s->picture_structure == PICT_BOTTOM_FIELD)
1709 mb_y++;
1710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15582 times.
15582 if (mb_y >= s->end_mb_y)
1711 return AVERROR_INVALIDDATA;
1712 }
1713 }
1714
1715 /**
1716 * Handle slice ends.
1717 * @return 1 if it seems to be the last slice
1718 */
1719 4195 static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
1720 {
1721 4195 Mpeg1Context *s1 = avctx->priv_data;
1722 4195 MpegEncContext *s = &s1->mpeg_enc_ctx;
1723
1724
3/4
✓ Branch 0 taken 3909 times.
✓ Branch 1 taken 286 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3909 times.
4195 if (!s->context_initialized || !s->cur_pic.ptr)
1725 286 return 0;
1726
1727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3909 times.
3909 if (s->avctx->hwaccel) {
1728 int ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
1729 if (ret < 0) {
1730 av_log(avctx, AV_LOG_ERROR,
1731 "hardware accelerator failed to decode picture\n");
1732 return ret;
1733 }
1734 }
1735
1736 /* end of slice reached */
1737
3/4
✓ Branch 0 taken 3908 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3908 times.
✗ Branch 3 not taken.
3909 if (/* s->mb_y << field_pic == s->mb_height && */ !s->first_field && !s1->first_slice) {
1738 /* end of image */
1739
1740 3908 ff_er_frame_end(&s->er, NULL);
1741
1742 3908 ff_mpv_frame_end(s);
1743
1744
4/4
✓ Branch 0 taken 2490 times.
✓ Branch 1 taken 1418 times.
✓ Branch 2 taken 542 times.
✓ Branch 3 taken 1948 times.
3908 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
1745 1960 int ret = av_frame_ref(pict, s->cur_pic.ptr->f);
1746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1960 times.
1960 if (ret < 0)
1747 return ret;
1748 1960 ff_print_debug_info(s, s->cur_pic.ptr, pict);
1749 1960 ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG2);
1750 1960 *got_output = 1;
1751 } else {
1752 /* latency of 1 frame for I- and P-frames */
1753
4/4
✓ Branch 0 taken 1889 times.
✓ Branch 1 taken 59 times.
✓ Branch 2 taken 1886 times.
✓ Branch 3 taken 3 times.
1948 if (s->last_pic.ptr && !s->last_pic.ptr->dummy) {
1754 1886 int ret = av_frame_ref(pict, s->last_pic.ptr->f);
1755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1886 times.
1886 if (ret < 0)
1756 return ret;
1757 1886 ff_print_debug_info(s, s->last_pic.ptr, pict);
1758 1886 ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG2);
1759 1886 *got_output = 1;
1760 }
1761 }
1762
1763 3908 return 1;
1764 } else {
1765 1 return 0;
1766 }
1767 }
1768
1769 812 static int mpeg1_decode_sequence(AVCodecContext *avctx,
1770 const uint8_t *buf, int buf_size)
1771 {
1772 812 Mpeg1Context *s1 = avctx->priv_data;
1773 812 MpegEncContext *s = &s1->mpeg_enc_ctx;
1774 int width, height;
1775 int i, v, j;
1776
1777 812 int ret = init_get_bits8(&s->gb, buf, buf_size);
1778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812 times.
812 if (ret < 0)
1779 return ret;
1780
1781 812 width = get_bits(&s->gb, 12);
1782 812 height = get_bits(&s->gb, 12);
1783
2/4
✓ Branch 0 taken 812 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 812 times.
812 if (width == 0 || height == 0) {
1784 av_log(avctx, AV_LOG_WARNING,
1785 "Invalid horizontal or vertical size value.\n");
1786 if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
1787 return AVERROR_INVALIDDATA;
1788 }
1789 812 s1->aspect_ratio_info = get_bits(&s->gb, 4);
1790
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812 times.
812 if (s1->aspect_ratio_info == 0) {
1791 av_log(avctx, AV_LOG_ERROR, "aspect ratio has forbidden 0 value\n");
1792 if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
1793 return AVERROR_INVALIDDATA;
1794 }
1795 812 s1->frame_rate_index = get_bits(&s->gb, 4);
1796
2/4
✓ Branch 0 taken 812 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 812 times.
812 if (s1->frame_rate_index == 0 || s1->frame_rate_index > 13) {
1797 av_log(avctx, AV_LOG_WARNING,
1798 "frame_rate_index %d is invalid\n", s1->frame_rate_index);
1799 s1->frame_rate_index = 1;
1800 }
1801 812 s->bit_rate = get_bits(&s->gb, 18) * 400LL;
1802
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 812 times.
812 if (check_marker(s->avctx, &s->gb, "in sequence header") == 0) {
1803 return AVERROR_INVALIDDATA;
1804 }
1805
1806 812 s->avctx->rc_buffer_size = get_bits(&s->gb, 10) * 1024 * 16;
1807 812 skip_bits(&s->gb, 1);
1808
1809 /* get matrix */
1810
2/2
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 790 times.
812 if (get_bits1(&s->gb)) {
1811 22 load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
1812 } else {
1813
2/2
✓ Branch 0 taken 50560 times.
✓ Branch 1 taken 790 times.
51350 for (i = 0; i < 64; i++) {
1814 50560 j = s->idsp.idct_permutation[i];
1815 50560 v = ff_mpeg1_default_intra_matrix[i];
1816 50560 s->intra_matrix[j] = v;
1817 50560 s->chroma_intra_matrix[j] = v;
1818 }
1819 }
1820
2/2
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 728 times.
812 if (get_bits1(&s->gb)) {
1821 84 load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
1822 } else {
1823
2/2
✓ Branch 0 taken 46592 times.
✓ Branch 1 taken 728 times.
47320 for (i = 0; i < 64; i++) {
1824 46592 int j = s->idsp.idct_permutation[i];
1825 46592 v = ff_mpeg1_default_non_intra_matrix[i];
1826 46592 s->inter_matrix[j] = v;
1827 46592 s->chroma_inter_matrix[j] = v;
1828 }
1829 }
1830
1831
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 812 times.
812 if (show_bits(&s->gb, 23) != 0) {
1832 av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n");
1833 return AVERROR_INVALIDDATA;
1834 }
1835
1836 812 s->width = width;
1837 812 s->height = height;
1838
1839 /* We set MPEG-2 parameters so that it emulates MPEG-1. */
1840 812 s->progressive_sequence = 1;
1841 812 s->progressive_frame = 1;
1842 812 s->picture_structure = PICT_FRAME;
1843 812 s->first_field = 0;
1844 812 s->frame_pred_frame_dct = 1;
1845 812 s->chroma_format = 1;
1846 812 s->codec_id =
1847 812 s->avctx->codec_id = AV_CODEC_ID_MPEG1VIDEO;
1848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812 times.
812 if (s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
1849 s->low_delay = 1;
1850
1851
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 812 times.
812 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
1852 av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%"PRId64", aspect_ratio_info: %d \n",
1853 s->avctx->rc_buffer_size, s->bit_rate, s1->aspect_ratio_info);
1854
1855 812 return 0;
1856 }
1857
1858 2 static int vcr2_init_sequence(AVCodecContext *avctx)
1859 {
1860 2 Mpeg1Context *s1 = avctx->priv_data;
1861 2 MpegEncContext *s = &s1->mpeg_enc_ctx;
1862 int i, v, ret;
1863
1864 /* start new MPEG-1 context decoding */
1865
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->context_initialized)
1866 ff_mpv_common_end(s);
1867
1868 2 s->width = avctx->coded_width;
1869 2 s->height = avctx->coded_height;
1870 2 avctx->has_b_frames = 0; // true?
1871 2 s->low_delay = 1;
1872
1873 2 avctx->pix_fmt = mpeg_get_pixelformat(avctx);
1874
1875
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
2 if ((ret = ff_mpv_common_init(s)) < 0)
1876 return ret;
1877
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!s->avctx->lowres)
1878 2 ff_mpv_framesize_disable(&s->sc);
1879
1880
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 2 times.
130 for (i = 0; i < 64; i++) {
1881 128 int j = s->idsp.idct_permutation[i];
1882 128 v = ff_mpeg1_default_intra_matrix[i];
1883 128 s->intra_matrix[j] = v;
1884 128 s->chroma_intra_matrix[j] = v;
1885
1886 128 v = ff_mpeg1_default_non_intra_matrix[i];
1887 128 s->inter_matrix[j] = v;
1888 128 s->chroma_inter_matrix[j] = v;
1889 }
1890
1891 2 s->progressive_sequence = 1;
1892 2 s->progressive_frame = 1;
1893 2 s->picture_structure = PICT_FRAME;
1894 2 s->first_field = 0;
1895 2 s->frame_pred_frame_dct = 1;
1896 2 s->chroma_format = 1;
1897
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (s->codec_tag == AV_RL32("BW10")) {
1898 s->codec_id = s->avctx->codec_id = AV_CODEC_ID_MPEG1VIDEO;
1899 } else {
1900 2 s->codec_id = s->avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
1901 }
1902 2 s1->save_width = s->width;
1903 2 s1->save_height = s->height;
1904 2 s1->save_progressive_seq = s->progressive_sequence;
1905 2 return 0;
1906 }
1907
1908 758 static void mpeg_set_cc_format(AVCodecContext *avctx, enum Mpeg2ClosedCaptionsFormat format,
1909 const char *label)
1910 {
1911 758 Mpeg1Context *s1 = avctx->priv_data;
1912
1913 av_assert2(format != CC_FORMAT_AUTO);
1914
1915
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 747 times.
758 if (!s1->cc_format) {
1916 11 s1->cc_format = format;
1917
1918 11 av_log(avctx, AV_LOG_DEBUG, "CC: first seen substream is %s format\n", label);
1919 }
1920
1921 758 avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
1922 758 }
1923
1924 830 static int mpeg_decode_a53_cc(AVCodecContext *avctx,
1925 const uint8_t *p, int buf_size)
1926 {
1927 830 Mpeg1Context *s1 = avctx->priv_data;
1928
1929
5/6
✓ Branch 0 taken 747 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 544 times.
✓ Branch 3 taken 203 times.
✓ Branch 4 taken 627 times.
✗ Branch 5 not taken.
830 if ((!s1->cc_format || s1->cc_format == CC_FORMAT_A53_PART4) &&
1930 627 buf_size >= 6 &&
1931
5/8
✓ Branch 0 taken 553 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 553 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 553 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 553 times.
✗ Branch 7 not taken.
627 p[0] == 'G' && p[1] == 'A' && p[2] == '9' && p[3] == '4' &&
1932
2/4
✓ Branch 0 taken 553 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 553 times.
✗ Branch 3 not taken.
553 p[4] == 3 && (p[5] & 0x40)) {
1933 /* extract A53 Part 4 CC data */
1934 553 int cc_count = p[5] & 0x1f;
1935
2/4
✓ Branch 0 taken 553 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 553 times.
✗ Branch 3 not taken.
553 if (cc_count > 0 && buf_size >= 7 + cc_count * 3) {
1936
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 545 times.
553 int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0;
1937 553 const uint64_t new_size = (old_size + cc_count
1938 553 * UINT64_C(3));
1939 int ret;
1940
1941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 553 times.
553 if (new_size > 3*A53_MAX_CC_COUNT)
1942 return AVERROR(EINVAL);
1943
1944 553 ret = av_buffer_realloc(&s1->a53_buf_ref, new_size);
1945
1/2
✓ Branch 0 taken 553 times.
✗ Branch 1 not taken.
553 if (ret >= 0)
1946 553 memcpy(s1->a53_buf_ref->data + old_size, p + 7, cc_count * UINT64_C(3));
1947
1948 553 mpeg_set_cc_format(avctx, CC_FORMAT_A53_PART4, "A/53 Part 4");
1949 }
1950 553 return 1;
1951
4/6
✓ Branch 0 taken 203 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 203 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 277 times.
✗ Branch 5 not taken.
277 } else if ((!s1->cc_format || s1->cc_format == CC_FORMAT_SCTE20) &&
1952 277 buf_size >= 2 &&
1953
3/4
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 205 times.
✗ Branch 3 not taken.
277 p[0] == 0x03 && (p[1]&0x7f) == 0x01) {
1954 /* extract SCTE-20 CC data */
1955 GetBitContext gb;
1956 205 int cc_count = 0;
1957 int i, ret;
1958
1959 205 ret = init_get_bits8(&gb, p + 2, buf_size - 2);
1960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205 times.
205 if (ret < 0)
1961 return ret;
1962 205 cc_count = get_bits(&gb, 5);
1963
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 if (cc_count > 0) {
1964
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 203 times.
205 int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0;
1965 205 const uint64_t new_size = (old_size + cc_count
1966 205 * UINT64_C(3));
1967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205 times.
205 if (new_size > 3*A53_MAX_CC_COUNT)
1968 return AVERROR(EINVAL);
1969
1970 205 ret = av_buffer_realloc(&s1->a53_buf_ref, new_size);
1971
1/2
✓ Branch 0 taken 205 times.
✗ Branch 1 not taken.
205 if (ret >= 0) {
1972 uint8_t field, cc1, cc2;
1973 205 uint8_t *cap = s1->a53_buf_ref->data;
1974
1975 205 memset(s1->a53_buf_ref->data + old_size, 0, cc_count * 3);
1976
3/4
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 205 times.
✓ Branch 3 taken 410 times.
✗ Branch 4 not taken.
615 for (i = 0; i < cc_count && get_bits_left(&gb) >= 26; i++) {
1977 410 skip_bits(&gb, 2); // priority
1978 410 field = get_bits(&gb, 2);
1979 410 skip_bits(&gb, 5); // line_offset
1980 410 cc1 = get_bits(&gb, 8);
1981 410 cc2 = get_bits(&gb, 8);
1982 410 skip_bits(&gb, 1); // marker
1983
1984
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 410 times.
410 if (!field) { // forbidden
1985 cap[0] = cap[1] = cap[2] = 0x00;
1986 } else {
1987 410 field = (field == 2 ? 1 : 0);
1988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 410 times.
410 if (!s1->mpeg_enc_ctx.top_field_first) field = !field;
1989 410 cap[0] = 0x04 | field;
1990 410 cap[1] = ff_reverse[cc1];
1991 410 cap[2] = ff_reverse[cc2];
1992 }
1993 410 cap += 3;
1994 }
1995 }
1996
1997 205 mpeg_set_cc_format(avctx, CC_FORMAT_SCTE20, "SCTE-20");
1998 }
1999 205 return 1;
2000
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
72 } else if ((!s1->cc_format || s1->cc_format == CC_FORMAT_DVD) &&
2001 72 buf_size >= 11 &&
2002
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
72 p[0] == 'C' && p[1] == 'C' && p[2] == 0x01 && p[3] == 0xf8) {
2003 /* extract DVD CC data
2004 *
2005 * uint32_t user_data_start_code 0x000001B2 (big endian)
2006 * uint16_t user_identifier 0x4343 "CC"
2007 * uint8_t user_data_type_code 0x01
2008 * uint8_t caption_block_size 0xF8
2009 * uint8_t
2010 * bit 7 caption_odd_field_first 1=odd field (CC1/CC2) first 0=even field (CC3/CC4) first
2011 * bit 6 caption_filler 0
2012 * bit 5:1 caption_block_count number of caption blocks (pairs of caption words = frames). Most DVDs use 15 per start of GOP.
2013 * bit 0 caption_extra_field_added 1=one additional caption word
2014 *
2015 * struct caption_field_block {
2016 * uint8_t
2017 * bit 7:1 caption_filler 0x7F (all 1s)
2018 * bit 0 caption_field_odd 1=odd field (this is CC1/CC2) 0=even field (this is CC3/CC4)
2019 * uint8_t caption_first_byte
2020 * uint8_t caption_second_byte
2021 * } caption_block[(caption_block_count * 2) + caption_extra_field_added];
2022 *
2023 * Some DVDs encode caption data for both fields with caption_field_odd=1. The only way to decode the fields
2024 * correctly is to start on the field indicated by caption_odd_field_first and count between odd/even fields.
2025 * Don't assume that the first caption word is the odd field. There do exist MPEG files in the wild that start
2026 * on the even field. There also exist DVDs in the wild that encode an odd field count and the
2027 * caption_extra_field_added/caption_odd_field_first bits change per packet to allow that. */
2028 int cc_count = 0;
2029 int i, ret;
2030 // There is a caption count field in the data, but it is often
2031 // incorrect. So count the number of captions present.
2032 for (i = 5; i + 6 <= buf_size && ((p[i] & 0xfe) == 0xfe); i += 6)
2033 cc_count++;
2034 // Transform the DVD format into A53 Part 4 format
2035 if (cc_count > 0) {
2036 int old_size = s1->a53_buf_ref ? s1->a53_buf_ref->size : 0;
2037 const uint64_t new_size = (old_size + cc_count
2038 * UINT64_C(6));
2039 if (new_size > 3*A53_MAX_CC_COUNT)
2040 return AVERROR(EINVAL);
2041
2042 ret = av_buffer_realloc(&s1->a53_buf_ref, new_size);
2043 if (ret >= 0) {
2044 uint8_t field1 = !!(p[4] & 0x80);
2045 uint8_t *cap = s1->a53_buf_ref->data;
2046 p += 5;
2047 for (i = 0; i < cc_count; i++) {
2048 cap[0] = (p[0] == 0xff && field1) ? 0xfc : 0xfd;
2049 cap[1] = p[1];
2050 cap[2] = p[2];
2051 cap[3] = (p[3] == 0xff && !field1) ? 0xfc : 0xfd;
2052 cap[4] = p[4];
2053 cap[5] = p[5];
2054 cap += 6;
2055 p += 6;
2056 }
2057 }
2058
2059 mpeg_set_cc_format(avctx, CC_FORMAT_DVD, "DVD");
2060 }
2061 return 1;
2062 }
2063 72 return 0;
2064 }
2065
2066 1037 static void mpeg_decode_user_data(AVCodecContext *avctx,
2067 const uint8_t *p, int buf_size)
2068 {
2069 1037 Mpeg1Context *s = avctx->priv_data;
2070 1037 const uint8_t *buf_end = p + buf_size;
2071 1037 Mpeg1Context *s1 = avctx->priv_data;
2072
2073 #if 0
2074 int i;
2075 for(i=0; !(!p[i-2] && !p[i-1] && p[i]==1) && i<buf_size; i++){
2076 av_log(avctx, AV_LOG_ERROR, "%c", p[i]);
2077 }
2078 av_log(avctx, AV_LOG_ERROR, "\n");
2079 #endif
2080
2081
1/2
✓ Branch 0 taken 1037 times.
✗ Branch 1 not taken.
1037 if (buf_size > 29){
2082 int i;
2083
2/2
✓ Branch 0 taken 20740 times.
✓ Branch 1 taken 1037 times.
21777 for(i=0; i<20; i++)
2084
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20740 times.
20740 if (!memcmp(p+i, "\0TMPGEXS\0", 9)){
2085 s->tmpgexs= 1;
2086 }
2087 }
2088 /* we parse the DTG active format information */
2089
1/2
✓ Branch 0 taken 1037 times.
✗ Branch 1 not taken.
1037 if (buf_end - p >= 5 &&
2090
5/8
✓ Branch 0 taken 207 times.
✓ Branch 1 taken 830 times.
✓ Branch 2 taken 207 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 207 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 207 times.
✗ Branch 7 not taken.
1244 p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
2091 207 int flags = p[4];
2092 207 p += 5;
2093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 207 times.
207 if (flags & 0x80) {
2094 /* skip event id */
2095 p += 2;
2096 }
2097
1/2
✓ Branch 0 taken 207 times.
✗ Branch 1 not taken.
207 if (flags & 0x40) {
2098
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 207 times.
207 if (buf_end - p < 1)
2099 return;
2100 207 s1->has_afd = 1;
2101 207 s1->afd = p[0] & 0x0f;
2102 }
2103
1/2
✓ Branch 0 taken 830 times.
✗ Branch 1 not taken.
830 } else if (buf_end - p >= 6 &&
2104
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 830 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
830 p[0] == 'J' && p[1] == 'P' && p[2] == '3' && p[3] == 'D' &&
2105 p[4] == 0x03) { // S3D_video_format_length
2106 // the 0x7F mask ignores the reserved_bit value
2107 const uint8_t S3D_video_format_type = p[5] & 0x7F;
2108
2109 if (S3D_video_format_type == 0x03 ||
2110 S3D_video_format_type == 0x04 ||
2111 S3D_video_format_type == 0x08 ||
2112 S3D_video_format_type == 0x23) {
2113
2114 s1->has_stereo3d = 1;
2115
2116 switch (S3D_video_format_type) {
2117 case 0x03:
2118 s1->stereo3d_type = AV_STEREO3D_SIDEBYSIDE;
2119 break;
2120 case 0x04:
2121 s1->stereo3d_type = AV_STEREO3D_TOPBOTTOM;
2122 break;
2123 case 0x08:
2124 s1->stereo3d_type = AV_STEREO3D_2D;
2125 break;
2126 case 0x23:
2127 s1->stereo3d_type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
2128 break;
2129 }
2130 }
2131
2/2
✓ Branch 1 taken 758 times.
✓ Branch 2 taken 72 times.
830 } else if (mpeg_decode_a53_cc(avctx, p, buf_size)) {
2132 758 return;
2133 }
2134 }
2135
2136 563 static int mpeg_decode_gop(AVCodecContext *avctx,
2137 const uint8_t *buf, int buf_size)
2138 {
2139 563 Mpeg1Context *s1 = avctx->priv_data;
2140 563 MpegEncContext *s = &s1->mpeg_enc_ctx;
2141 int broken_link;
2142 int64_t tc;
2143
2144 563 int ret = init_get_bits8(&s->gb, buf, buf_size);
2145
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 563 times.
563 if (ret < 0)
2146 return ret;
2147
2148 563 tc = s1->timecode_frame_start = get_bits(&s->gb, 25);
2149
2150 563 s1->closed_gop = get_bits1(&s->gb);
2151 /* broken_link indicates that after editing the
2152 * reference frames of the first B-Frames after GOP I-Frame
2153 * are missing (open gop) */
2154 563 broken_link = get_bits1(&s->gb);
2155
2156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 563 times.
563 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
2157 char tcbuf[AV_TIMECODE_STR_SIZE];
2158 av_timecode_make_mpeg_tc_string(tcbuf, tc);
2159 av_log(s->avctx, AV_LOG_DEBUG,
2160 "GOP (%s) closed_gop=%d broken_link=%d\n",
2161 tcbuf, s1->closed_gop, broken_link);
2162 }
2163
2164 563 return 0;
2165 }
2166
2167 4684 static int decode_chunks(AVCodecContext *avctx, AVFrame *picture,
2168 int *got_output, const uint8_t *buf, int buf_size)
2169 {
2170 4684 Mpeg1Context *s = avctx->priv_data;
2171 4684 MpegEncContext *s2 = &s->mpeg_enc_ctx;
2172 4684 const uint8_t *buf_ptr = buf;
2173 4684 const uint8_t *buf_end = buf + buf_size;
2174 int ret, input_size;
2175 4684 int last_code = 0, skip_frame = 0;
2176 4684 int picture_start_code_seen = 0;
2177
2178 224614 for (;;) {
2179 /* find next start code */
2180 229298 uint32_t start_code = -1;
2181 229298 buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &start_code);
2182
2/2
✓ Branch 0 taken 4514 times.
✓ Branch 1 taken 224784 times.
229298 if (start_code > 0x1ff) {
2183
2/2
✓ Branch 0 taken 4195 times.
✓ Branch 1 taken 319 times.
4514 if (!skip_frame) {
2184 4195 if (HAVE_THREADS &&
2185
2/2
✓ Branch 0 taken 747 times.
✓ Branch 1 taken 3448 times.
4195 (avctx->active_thread_type & FF_THREAD_SLICE) &&
2186
1/2
✓ Branch 0 taken 747 times.
✗ Branch 1 not taken.
747 !avctx->hwaccel) {
2187 int i;
2188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 747 times.
747 av_assert0(avctx->thread_count > 1);
2189
2190 747 avctx->execute(avctx, slice_decode_thread,
2191 747 &s2->thread_context[0], NULL,
2192 s->slice_count, sizeof(void *));
2193
2/2
✓ Branch 0 taken 6678 times.
✓ Branch 1 taken 747 times.
7425 for (i = 0; i < s->slice_count; i++)
2194 6678 s2->er.error_count += s2->thread_context[i]->er.error_count;
2195 }
2196
2197 4195 ret = slice_end(avctx, picture, got_output);
2198
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4195 times.
4195 if (ret < 0)
2199 4684 return ret;
2200 }
2201 4514 s2->pict_type = 0;
2202
2203
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4514 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4514 if (avctx->err_recognition & AV_EF_EXPLODE && s2->er.error_count)
2204 return AVERROR_INVALIDDATA;
2205
2206 4514 return FFMAX(0, buf_ptr - buf);
2207 }
2208
2209 224784 input_size = buf_end - buf_ptr;
2210
2211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 224784 times.
224784 if (avctx->debug & FF_DEBUG_STARTCODE)
2212 av_log(avctx, AV_LOG_DEBUG, "%3"PRIX32" at %"PTRDIFF_SPECIFIER" left %d\n",
2213 start_code, buf_ptr - buf, input_size);
2214
2215 /* prepare data for next start code */
2216
6/6
✓ Branch 0 taken 812 times.
✓ Branch 1 taken 5242 times.
✓ Branch 2 taken 6415 times.
✓ Branch 3 taken 1037 times.
✓ Branch 4 taken 563 times.
✓ Branch 5 taken 210715 times.
224784 switch (start_code) {
2217 812 case SEQ_START_CODE:
2218
1/2
✓ Branch 0 taken 812 times.
✗ Branch 1 not taken.
812 if (last_code == 0) {
2219 812 mpeg1_decode_sequence(avctx, buf_ptr, input_size);
2220
2/2
✓ Branch 0 taken 554 times.
✓ Branch 1 taken 258 times.
812 if (buf != avctx->extradata)
2221 554 s->sync = 1;
2222 } else {
2223 av_log(avctx, AV_LOG_ERROR,
2224 "ignoring SEQ_START_CODE after %X\n", last_code);
2225 if (avctx->err_recognition & AV_EF_EXPLODE)
2226 return AVERROR_INVALIDDATA;
2227 }
2228 812 break;
2229
2230 5242 case PICTURE_START_CODE:
2231
3/4
✓ Branch 0 taken 844 times.
✓ Branch 1 taken 4398 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 844 times.
5242 if (picture_start_code_seen && s2->picture_structure == PICT_FRAME) {
2232 /* If it's a frame picture, there can't be more than one picture header.
2233 Yet, it does happen and we need to handle it. */
2234 av_log(avctx, AV_LOG_WARNING, "ignoring extra picture following a frame-picture\n");
2235 break;
2236 }
2237 5242 picture_start_code_seen = 1;
2238
2239
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5242 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5242 if (buf == avctx->extradata && avctx->codec_tag == AV_RL32("AVmp")) {
2240 av_log(avctx, AV_LOG_WARNING, "ignoring picture start code in AVmp extradata\n");
2241 break;
2242 }
2243
2244
3/4
✓ Branch 0 taken 5072 times.
✓ Branch 1 taken 170 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5072 times.
5242 if (s2->width <= 0 || s2->height <= 0) {
2245 170 av_log(avctx, AV_LOG_ERROR, "Invalid frame dimensions %dx%d.\n",
2246 s2->width, s2->height);
2247 170 return AVERROR_INVALIDDATA;
2248 }
2249
2250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5072 times.
5072 if (s->tmpgexs){
2251 s2->intra_dc_precision= 3;
2252 s2->intra_matrix[0]= 1;
2253 }
2254
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 4320 times.
5072 if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) &&
2255
2/4
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 752 times.
752 !avctx->hwaccel && s->slice_count) {
2256 int i;
2257
2258 avctx->execute(avctx, slice_decode_thread,
2259 s2->thread_context, NULL,
2260 s->slice_count, sizeof(void *));
2261 for (i = 0; i < s->slice_count; i++)
2262 s2->er.error_count += s2->thread_context[i]->er.error_count;
2263 s->slice_count = 0;
2264 }
2265
3/4
✓ Branch 0 taken 844 times.
✓ Branch 1 taken 4228 times.
✓ Branch 2 taken 844 times.
✗ Branch 3 not taken.
5072 if (last_code == 0 || last_code == SLICE_MIN_START_CODE) {
2266 5072 ret = mpeg_decode_postinit(avctx);
2267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5072 times.
5072 if (ret < 0) {
2268 av_log(avctx, AV_LOG_ERROR,
2269 "mpeg_decode_postinit() failure\n");
2270 return ret;
2271 }
2272
2273 /* We have a complete image: we try to decompress it. */
2274
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5072 times.
5072 if (mpeg1_decode_picture(avctx, buf_ptr, input_size) < 0)
2275 s2->pict_type = 0;
2276 5072 s->first_slice = 1;
2277 5072 last_code = PICTURE_START_CODE;
2278 } else {
2279 av_log(avctx, AV_LOG_ERROR,
2280 "ignoring pic after %X\n", last_code);
2281 if (avctx->err_recognition & AV_EF_EXPLODE)
2282 return AVERROR_INVALIDDATA;
2283 }
2284 5072 break;
2285 6415 case EXT_START_CODE:
2286 6415 ret = init_get_bits8(&s2->gb, buf_ptr, input_size);
2287
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6415 times.
6415 if (ret < 0)
2288 return ret;
2289
2290
5/6
✓ Branch 1 taken 720 times.
✓ Branch 2 taken 95 times.
✓ Branch 3 taken 995 times.
✓ Branch 4 taken 27 times.
✓ Branch 5 taken 4578 times.
✗ Branch 6 not taken.
6415 switch (get_bits(&s2->gb, 4)) {
2291 720 case 0x1:
2292
1/2
✓ Branch 0 taken 720 times.
✗ Branch 1 not taken.
720 if (last_code == 0) {
2293 720 mpeg_decode_sequence_extension(s);
2294 } else {
2295 av_log(avctx, AV_LOG_ERROR,
2296 "ignoring seq ext after %X\n", last_code);
2297 if (avctx->err_recognition & AV_EF_EXPLODE)
2298 return AVERROR_INVALIDDATA;
2299 }
2300 720 break;
2301 95 case 0x2:
2302 95 mpeg_decode_sequence_display_extension(s);
2303 95 break;
2304 995 case 0x3:
2305 995 mpeg_decode_quant_matrix_extension(s2);
2306 995 break;
2307 27 case 0x7:
2308 27 mpeg_decode_picture_display_extension(s);
2309 27 break;
2310 4578 case 0x8:
2311
1/2
✓ Branch 0 taken 4578 times.
✗ Branch 1 not taken.
4578 if (last_code == PICTURE_START_CODE) {
2312 4578 int ret = mpeg_decode_picture_coding_extension(s);
2313
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4578 times.
4578 if (ret < 0)
2314 return ret;
2315 } else {
2316 av_log(avctx, AV_LOG_ERROR,
2317 "ignoring pic cod ext after %X\n", last_code);
2318 if (avctx->err_recognition & AV_EF_EXPLODE)
2319 return AVERROR_INVALIDDATA;
2320 }
2321 4578 break;
2322 }
2323 6415 break;
2324 1037 case USER_START_CODE:
2325 1037 mpeg_decode_user_data(avctx, buf_ptr, input_size);
2326 1037 break;
2327 563 case GOP_START_CODE:
2328
1/2
✓ Branch 0 taken 563 times.
✗ Branch 1 not taken.
563 if (last_code == 0) {
2329 563 s2->first_field = 0;
2330 563 ret = mpeg_decode_gop(avctx, buf_ptr, input_size);
2331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 563 times.
563 if (ret < 0)
2332 return ret;
2333 563 s->sync = 1;
2334 } else {
2335 av_log(avctx, AV_LOG_ERROR,
2336 "ignoring GOP_START_CODE after %X\n", last_code);
2337 if (avctx->err_recognition & AV_EF_EXPLODE)
2338 return AVERROR_INVALIDDATA;
2339 }
2340 563 break;
2341 210715 default:
2342
2/2
✓ Branch 0 taken 209804 times.
✓ Branch 1 taken 911 times.
210715 if (start_code >= SLICE_MIN_START_CODE &&
2343
4/4
✓ Branch 0 taken 209799 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5072 times.
✓ Branch 3 taken 204727 times.
209804 start_code <= SLICE_MAX_START_CODE && last_code == PICTURE_START_CODE) {
2344
3/4
✓ Branch 0 taken 1701 times.
✓ Branch 1 taken 3371 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1701 times.
5072 if (s2->progressive_sequence && !s2->progressive_frame) {
2345 s2->progressive_frame = 1;
2346 av_log(s2->avctx, AV_LOG_ERROR,
2347 "interlaced frame in progressive sequence, ignoring\n");
2348 }
2349
2350
1/2
✓ Branch 0 taken 5072 times.
✗ Branch 1 not taken.
5072 if (s2->picture_structure == 0 ||
2351
3/4
✓ Branch 0 taken 1708 times.
✓ Branch 1 taken 3364 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1708 times.
5072 (s2->progressive_frame && s2->picture_structure != PICT_FRAME)) {
2352 av_log(s2->avctx, AV_LOG_ERROR,
2353 "picture_structure %d invalid, ignoring\n",
2354 s2->picture_structure);
2355 s2->picture_structure = PICT_FRAME;
2356 }
2357
2358
3/4
✓ Branch 0 taken 1701 times.
✓ Branch 1 taken 3371 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1701 times.
5072 if (s2->progressive_sequence && !s2->frame_pred_frame_dct)
2359 av_log(s2->avctx, AV_LOG_WARNING, "invalid frame_pred_frame_dct\n");
2360
2361
2/2
✓ Branch 0 taken 3382 times.
✓ Branch 1 taken 1690 times.
5072 if (s2->picture_structure == PICT_FRAME) {
2362 3382 s2->first_field = 0;
2363 3382 s2->v_edge_pos = 16 * s2->mb_height;
2364 } else {
2365 1690 s2->first_field ^= 1;
2366 1690 s2->v_edge_pos = 8 * s2->mb_height;
2367 1690 memset(s2->mbskip_table, 0, s2->mb_stride * s2->mb_height);
2368 }
2369 }
2370
2/2
✓ Branch 0 taken 209804 times.
✓ Branch 1 taken 911 times.
210715 if (start_code >= SLICE_MIN_START_CODE &&
2371
4/4
✓ Branch 0 taken 209799 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 209629 times.
✓ Branch 3 taken 170 times.
209804 start_code <= SLICE_MAX_START_CODE && last_code != 0) {
2372 209629 const int field_pic = s2->picture_structure != PICT_FRAME;
2373 209629 int mb_y = start_code - SLICE_MIN_START_CODE;
2374 209629 last_code = SLICE_MIN_START_CODE;
2375
3/4
✓ Branch 0 taken 202041 times.
✓ Branch 1 taken 7588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 202041 times.
209629 if (s2->codec_id != AV_CODEC_ID_MPEG1VIDEO && s2->mb_height > 2800/16)
2376 mb_y += (*buf_ptr&0xE0)<<2;
2377
2378 209629 mb_y <<= field_pic;
2379
2/2
✓ Branch 0 taken 13835 times.
✓ Branch 1 taken 195794 times.
209629 if (s2->picture_structure == PICT_BOTTOM_FIELD)
2380 13835 mb_y++;
2381
2382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 209629 times.
209629 if (buf_end - buf_ptr < 2) {
2383 av_log(s2->avctx, AV_LOG_ERROR, "slice too small\n");
2384 return AVERROR_INVALIDDATA;
2385 }
2386
2387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 209629 times.
209629 if (mb_y >= s2->mb_height) {
2388 av_log(s2->avctx, AV_LOG_ERROR,
2389 "slice below image (%d >= %d)\n", mb_y, s2->mb_height);
2390 return AVERROR_INVALIDDATA;
2391 }
2392
2393
2/2
✓ Branch 0 taken 85818 times.
✓ Branch 1 taken 123811 times.
209629 if (!s2->last_pic.ptr) {
2394 /* Skip B-frames if we do not have reference frames and
2395 * GOP is not closed. */
2396
2/2
✓ Branch 0 taken 732 times.
✓ Branch 1 taken 85086 times.
85818 if (s2->pict_type == AV_PICTURE_TYPE_B) {
2397
1/2
✓ Branch 0 taken 732 times.
✗ Branch 1 not taken.
732 if (!s->closed_gop) {
2398 732 skip_frame = 1;
2399 732 av_log(s2->avctx, AV_LOG_DEBUG,
2400 "Skipping B slice due to open GOP\n");
2401 732 break;
2402 }
2403 }
2404 }
2405
3/4
✓ Branch 0 taken 81147 times.
✓ Branch 1 taken 127750 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 81147 times.
208897 if (s2->pict_type == AV_PICTURE_TYPE_I || (s2->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL))
2406 127750 s->sync = 1;
2407
2/2
✓ Branch 0 taken 81592 times.
✓ Branch 1 taken 127305 times.
208897 if (!s2->next_pic.ptr) {
2408 /* Skip P-frames if we do not have a reference frame or
2409 * we have an invalid header. */
2410
4/4
✓ Branch 0 taken 4944 times.
✓ Branch 1 taken 76648 times.
✓ Branch 2 taken 4032 times.
✓ Branch 3 taken 912 times.
81592 if (s2->pict_type == AV_PICTURE_TYPE_P && !s->sync) {
2411 4032 skip_frame = 1;
2412 4032 av_log(s2->avctx, AV_LOG_DEBUG,
2413 "Skipping P slice due to !sync\n");
2414 4032 break;
2415 }
2416 }
2417
2/2
✓ Branch 0 taken 77484 times.
✓ Branch 1 taken 127381 times.
204865 if ((avctx->skip_frame >= AVDISCARD_NONREF &&
2418
1/2
✓ Branch 0 taken 77484 times.
✗ Branch 1 not taken.
77484 s2->pict_type == AV_PICTURE_TYPE_B) ||
2419
2/2
✓ Branch 0 taken 77484 times.
✓ Branch 1 taken 127381 times.
204865 (avctx->skip_frame >= AVDISCARD_NONKEY &&
2420
2/2
✓ Branch 0 taken 76572 times.
✓ Branch 1 taken 912 times.
77484 s2->pict_type != AV_PICTURE_TYPE_I) ||
2421
2/2
✓ Branch 0 taken 76572 times.
✓ Branch 1 taken 127381 times.
203953 avctx->skip_frame >= AVDISCARD_ALL) {
2422 77484 skip_frame = 1;
2423 77484 break;
2424 }
2425
2426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127381 times.
127381 if (!s2->context_initialized)
2427 break;
2428
2429
2/2
✓ Branch 0 taken 120108 times.
✓ Branch 1 taken 7273 times.
127381 if (s2->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
2430
1/2
✓ Branch 0 taken 120108 times.
✗ Branch 1 not taken.
120108 if (mb_y < avctx->skip_top ||
2431
1/2
✓ Branch 0 taken 120108 times.
✗ Branch 1 not taken.
120108 mb_y >= s2->mb_height - avctx->skip_bottom)
2432 break;
2433 }
2434
2435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127381 times.
127381 if (!s2->pict_type) {
2436 av_log(avctx, AV_LOG_ERROR, "Missing picture start code\n");
2437 if (avctx->err_recognition & AV_EF_EXPLODE)
2438 return AVERROR_INVALIDDATA;
2439 break;
2440 }
2441
2442
2/2
✓ Branch 0 taken 4627 times.
✓ Branch 1 taken 122754 times.
127381 if (s->first_slice) {
2443 4627 skip_frame = 0;
2444 4627 s->first_slice = 0;
2445
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4627 times.
4627 if ((ret = mpeg_field_start(s, buf, buf_size)) < 0)
2446 return ret;
2447 }
2448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127381 times.
127381 if (!s2->cur_pic.ptr) {
2449 av_log(avctx, AV_LOG_ERROR,
2450 "current_picture not initialized\n");
2451 return AVERROR_INVALIDDATA;
2452 }
2453
2454 127381 if (HAVE_THREADS &&
2455
2/2
✓ Branch 0 taken 22260 times.
✓ Branch 1 taken 105121 times.
127381 (avctx->active_thread_type & FF_THREAD_SLICE) &&
2456
1/2
✓ Branch 0 taken 22260 times.
✗ Branch 1 not taken.
22260 !avctx->hwaccel) {
2457 22260 int threshold = (s2->mb_height * s->slice_count +
2458 22260 s2->slice_context_count / 2) /
2459 22260 s2->slice_context_count;
2460
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22260 times.
22260 av_assert0(avctx->thread_count > 1);
2461
2/2
✓ Branch 0 taken 6678 times.
✓ Branch 1 taken 15582 times.
22260 if (threshold <= mb_y) {
2462 6678 MpegEncContext *thread_context = s2->thread_context[s->slice_count];
2463
2464 6678 thread_context->start_mb_y = mb_y;
2465 6678 thread_context->end_mb_y = s2->mb_height;
2466
2/2
✓ Branch 0 taken 5936 times.
✓ Branch 1 taken 742 times.
6678 if (s->slice_count) {
2467 5936 s2->thread_context[s->slice_count - 1]->end_mb_y = mb_y;
2468 5936 ret = ff_update_duplicate_context(thread_context, s2);
2469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5936 times.
5936 if (ret < 0)
2470 return ret;
2471 }
2472 6678 ret = init_get_bits8(&thread_context->gb, buf_ptr, input_size);
2473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6678 times.
6678 if (ret < 0)
2474 return ret;
2475 6678 s->slice_count++;
2476 }
2477 22260 buf_ptr += 2; // FIXME add minimum number of bytes per slice
2478 } else {
2479 105121 ret = mpeg_decode_slice(s2, mb_y, &buf_ptr, input_size);
2480 105121 emms_c();
2481
2482
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 105111 times.
105121 if (ret < 0) {
2483
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (avctx->err_recognition & AV_EF_EXPLODE)
2484 return ret;
2485
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
10 if (s2->resync_mb_x >= 0 && s2->resync_mb_y >= 0)
2486 10 ff_er_add_slice(&s2->er, s2->resync_mb_x,
2487 s2->resync_mb_y, s2->mb_x, s2->mb_y,
2488 ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR);
2489 } else {
2490 105111 ff_er_add_slice(&s2->er, s2->resync_mb_x,
2491 105111 s2->resync_mb_y, s2->mb_x - 1, s2->mb_y,
2492 ER_AC_END | ER_DC_END | ER_MV_END);
2493 }
2494 }
2495 }
2496 128467 break;
2497 }
2498 }
2499 }
2500
2501 4566 static int mpeg_decode_frame(AVCodecContext *avctx, AVFrame *picture,
2502 int *got_output, AVPacket *avpkt)
2503 {
2504 4566 const uint8_t *buf = avpkt->data;
2505 int ret;
2506 4566 int buf_size = avpkt->size;
2507 4566 Mpeg1Context *s = avctx->priv_data;
2508 4566 MpegEncContext *s2 = &s->mpeg_enc_ctx;
2509
2510
3/6
✓ Branch 0 taken 4426 times.
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4426 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4566 if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
2511 /* special case for last picture */
2512
4/4
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 61 times.
✓ Branch 3 taken 68 times.
140 if (s2->low_delay == 0 && s2->next_pic.ptr) {
2513 61 int ret = av_frame_ref(picture, s2->next_pic.ptr->f);
2514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 61 times.
61 if (ret < 0)
2515 return ret;
2516
2517 61 ff_mpv_unref_picture(&s2->next_pic);
2518
2519 61 *got_output = 1;
2520 }
2521 140 return buf_size;
2522 }
2523
2524
2/2
✓ Branch 0 taken 459 times.
✓ Branch 1 taken 3967 times.
4426 if (!s2->context_initialized &&
2525
3/4
✓ Branch 0 taken 457 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 457 times.
459 (s2->codec_tag == AV_RL32("VCR2") || s2->codec_tag == AV_RL32("BW10")))
2526 2 vcr2_init_sequence(avctx);
2527
2528 4426 s->slice_count = 0;
2529
2530
4/4
✓ Branch 0 taken 4033 times.
✓ Branch 1 taken 393 times.
✓ Branch 2 taken 258 times.
✓ Branch 3 taken 3775 times.
4426 if (avctx->extradata && !s->extradata_decoded) {
2531 258 ret = decode_chunks(avctx, picture, got_output,
2532 258 avctx->extradata, avctx->extradata_size);
2533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258 times.
258 if (*got_output) {
2534 av_log(avctx, AV_LOG_ERROR, "picture in extradata\n");
2535 av_frame_unref(picture);
2536 *got_output = 0;
2537 }
2538 258 s->extradata_decoded = 1;
2539
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 258 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258 if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) {
2540 ff_mpv_unref_picture(&s2->cur_pic);
2541 return ret;
2542 }
2543 }
2544
2545 4426 ret = decode_chunks(avctx, picture, got_output, buf, buf_size);
2546
4/4
✓ Branch 0 taken 4256 times.
✓ Branch 1 taken 170 times.
✓ Branch 2 taken 3846 times.
✓ Branch 3 taken 410 times.
4426 if (ret<0 || *got_output) {
2547 4016 ff_mpv_unref_picture(&s2->cur_pic);
2548
2549
4/4
✓ Branch 0 taken 547 times.
✓ Branch 1 taken 3469 times.
✓ Branch 2 taken 377 times.
✓ Branch 3 taken 170 times.
4016 if (s->timecode_frame_start != -1 && *got_output) {
2550 char tcbuf[AV_TIMECODE_STR_SIZE];
2551 377 AVFrameSideData *tcside = av_frame_new_side_data(picture,
2552 AV_FRAME_DATA_GOP_TIMECODE,
2553 sizeof(int64_t));
2554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 377 times.
377 if (!tcside)
2555 return AVERROR(ENOMEM);
2556 377 memcpy(tcside->data, &s->timecode_frame_start, sizeof(int64_t));
2557
2558 377 av_timecode_make_mpeg_tc_string(tcbuf, s->timecode_frame_start);
2559 377 av_dict_set(&picture->metadata, "timecode", tcbuf, 0);
2560
2561 377 s->timecode_frame_start = -1;
2562 }
2563 }
2564
2565 4426 return ret;
2566 }
2567
2568 static void flush(AVCodecContext *avctx)
2569 {
2570 Mpeg1Context *s = avctx->priv_data;
2571
2572 s->sync = 0;
2573 s->closed_gop = 0;
2574
2575 av_buffer_unref(&s->a53_buf_ref);
2576 ff_mpeg_flush(avctx);
2577 }
2578
2579 288 static av_cold int mpeg_decode_end(AVCodecContext *avctx)
2580 {
2581 288 Mpeg1Context *s = avctx->priv_data;
2582
2583 288 av_buffer_unref(&s->a53_buf_ref);
2584 288 return ff_mpv_decode_close(avctx);
2585 }
2586
2587 const FFCodec ff_mpeg1video_decoder = {
2588 .p.name = "mpeg1video",
2589 CODEC_LONG_NAME("MPEG-1 video"),
2590 .p.type = AVMEDIA_TYPE_VIDEO,
2591 .p.id = AV_CODEC_ID_MPEG1VIDEO,
2592 .priv_data_size = sizeof(Mpeg1Context),
2593 .init = mpeg_decode_init,
2594 .close = mpeg_decode_end,
2595 FF_CODEC_DECODE_CB(mpeg_decode_frame),
2596 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
2597 AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
2598 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
2599 .flush = flush,
2600 .p.max_lowres = 3,
2601 UPDATE_THREAD_CONTEXT(mpeg_decode_update_thread_context),
2602 .hw_configs = (const AVCodecHWConfigInternal *const []) {
2603 #if CONFIG_MPEG1_NVDEC_HWACCEL
2604 HWACCEL_NVDEC(mpeg1),
2605 #endif
2606 #if CONFIG_MPEG1_VDPAU_HWACCEL
2607 HWACCEL_VDPAU(mpeg1),
2608 #endif
2609 #if CONFIG_MPEG1_VIDEOTOOLBOX_HWACCEL
2610 HWACCEL_VIDEOTOOLBOX(mpeg1),
2611 #endif
2612 NULL
2613 },
2614 };
2615
2616 #define M2V_OFFSET(x) offsetof(Mpeg1Context, x)
2617 #define M2V_PARAM AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
2618
2619 static const AVOption mpeg2video_options[] = {
2620 { "cc_format", "extract a specific Closed Captions format",
2621 M2V_OFFSET(cc_format), AV_OPT_TYPE_INT, { .i64 = CC_FORMAT_AUTO },
2622 CC_FORMAT_AUTO, CC_FORMAT_DVD, M2V_PARAM, .unit = "cc_format" },
2623
2624 { "auto", "pick first seen CC substream", 0, AV_OPT_TYPE_CONST,
2625 { .i64 = CC_FORMAT_AUTO }, .flags = M2V_PARAM, .unit = "cc_format" },
2626 { "a53", "pick A/53 Part 4 CC substream", 0, AV_OPT_TYPE_CONST,
2627 { .i64 = CC_FORMAT_A53_PART4 }, .flags = M2V_PARAM, .unit = "cc_format" },
2628 { "scte20", "pick SCTE-20 CC substream", 0, AV_OPT_TYPE_CONST,
2629 { .i64 = CC_FORMAT_SCTE20 }, .flags = M2V_PARAM, .unit = "cc_format" },
2630 { "dvd", "pick DVD CC substream", 0, AV_OPT_TYPE_CONST,
2631 { .i64 = CC_FORMAT_DVD }, .flags = M2V_PARAM, .unit = "cc_format" },
2632 { NULL }
2633 };
2634
2635 static const AVClass mpeg2video_class = {
2636 .class_name = "MPEG-2 video",
2637 .item_name = av_default_item_name,
2638 .option = mpeg2video_options,
2639 .version = LIBAVUTIL_VERSION_INT,
2640 .category = AV_CLASS_CATEGORY_DECODER,
2641 };
2642
2643 const FFCodec ff_mpeg2video_decoder = {
2644 .p.name = "mpeg2video",
2645 CODEC_LONG_NAME("MPEG-2 video"),
2646 .p.type = AVMEDIA_TYPE_VIDEO,
2647 .p.id = AV_CODEC_ID_MPEG2VIDEO,
2648 .p.priv_class = &mpeg2video_class,
2649 .priv_data_size = sizeof(Mpeg1Context),
2650 .init = mpeg_decode_init,
2651 .close = mpeg_decode_end,
2652 FF_CODEC_DECODE_CB(mpeg_decode_frame),
2653 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
2654 AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
2655 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
2656 .flush = flush,
2657 .p.max_lowres = 3,
2658 .p.profiles = NULL_IF_CONFIG_SMALL(ff_mpeg2_video_profiles),
2659 .hw_configs = (const AVCodecHWConfigInternal *const []) {
2660 #if CONFIG_MPEG2_DXVA2_HWACCEL
2661 HWACCEL_DXVA2(mpeg2),
2662 #endif
2663 #if CONFIG_MPEG2_D3D11VA_HWACCEL
2664 HWACCEL_D3D11VA(mpeg2),
2665 #endif
2666 #if CONFIG_MPEG2_D3D11VA2_HWACCEL
2667 HWACCEL_D3D11VA2(mpeg2),
2668 #endif
2669 #if CONFIG_MPEG2_D3D12VA_HWACCEL
2670 HWACCEL_D3D12VA(mpeg2),
2671 #endif
2672 #if CONFIG_MPEG2_NVDEC_HWACCEL
2673 HWACCEL_NVDEC(mpeg2),
2674 #endif
2675 #if CONFIG_MPEG2_VAAPI_HWACCEL
2676 HWACCEL_VAAPI(mpeg2),
2677 #endif
2678 #if CONFIG_MPEG2_VDPAU_HWACCEL
2679 HWACCEL_VDPAU(mpeg2),
2680 #endif
2681 #if CONFIG_MPEG2_VIDEOTOOLBOX_HWACCEL
2682 HWACCEL_VIDEOTOOLBOX(mpeg2),
2683 #endif
2684 NULL
2685 },
2686 };
2687
2688 //legacy decoder
2689 const FFCodec ff_mpegvideo_decoder = {
2690 .p.name = "mpegvideo",
2691 CODEC_LONG_NAME("MPEG-1 video"),
2692 .p.type = AVMEDIA_TYPE_VIDEO,
2693 .p.id = AV_CODEC_ID_MPEG2VIDEO,
2694 .priv_data_size = sizeof(Mpeg1Context),
2695 .init = mpeg_decode_init,
2696 .close = mpeg_decode_end,
2697 FF_CODEC_DECODE_CB(mpeg_decode_frame),
2698 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
2699 AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS,
2700 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
2701 .flush = flush,
2702 .p.max_lowres = 3,
2703 };
2704
2705 typedef struct IPUContext {
2706 MpegEncContext m;
2707
2708 int flags;
2709 DECLARE_ALIGNED(32, int16_t, block)[6][64];
2710 } IPUContext;
2711
2712 static int ipu_decode_frame(AVCodecContext *avctx, AVFrame *frame,
2713 int *got_frame, AVPacket *avpkt)
2714 {
2715 IPUContext *s = avctx->priv_data;
2716 MpegEncContext *m = &s->m;
2717 GetBitContext *gb = &m->gb;
2718 int ret;
2719
2720 // Check for minimal intra MB size (considering mb header, luma & chroma dc VLC, ac EOB VLC)
2721 if (avpkt->size*8LL < (avctx->width+15)/16 * ((avctx->height+15)/16) * (2LL + 3*4 + 2*2 + 2*6))
2722 return AVERROR_INVALIDDATA;
2723
2724 ret = ff_get_buffer(avctx, frame, 0);
2725 if (ret < 0)
2726 return ret;
2727
2728 ret = init_get_bits8(gb, avpkt->data, avpkt->size);
2729 if (ret < 0)
2730 return ret;
2731
2732 s->flags = get_bits(gb, 8);
2733 m->intra_dc_precision = s->flags & 3;
2734 m->q_scale_type = !!(s->flags & 0x40);
2735 m->intra_vlc_format = !!(s->flags & 0x20);
2736 m->alternate_scan = !!(s->flags & 0x10);
2737
2738 ff_init_scantable(m->idsp.idct_permutation, &m->intra_scantable,
2739 s->flags & 0x10 ? ff_alternate_vertical_scan : ff_zigzag_direct);
2740
2741 m->last_dc[0] = m->last_dc[1] = m->last_dc[2] = 1 << (7 + (s->flags & 3));
2742 m->qscale = 1;
2743
2744 for (int y = 0; y < avctx->height; y += 16) {
2745 int intraquant;
2746
2747 for (int x = 0; x < avctx->width; x += 16) {
2748 if (x || y) {
2749 if (!get_bits1(gb))
2750 return AVERROR_INVALIDDATA;
2751 }
2752 if (get_bits1(gb)) {
2753 intraquant = 0;
2754 } else {
2755 if (!get_bits1(gb))
2756 return AVERROR_INVALIDDATA;
2757 intraquant = 1;
2758 }
2759
2760 if (s->flags & 4)
2761 skip_bits1(gb);
2762
2763 if (intraquant)
2764 m->qscale = mpeg_get_qscale(m);
2765
2766 memset(s->block, 0, sizeof(s->block));
2767
2768 for (int n = 0; n < 6; n++) {
2769 if (s->flags & 0x80) {
2770 ret = ff_mpeg1_decode_block_intra(&m->gb,
2771 m->intra_matrix,
2772 m->intra_scantable.permutated,
2773 m->last_dc, s->block[n],
2774 n, m->qscale);
2775 } else {
2776 ret = mpeg2_decode_block_intra(m, s->block[n], n);
2777 }
2778
2779 if (ret < 0)
2780 return ret;
2781 }
2782
2783 m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x,
2784 frame->linesize[0], s->block[0]);
2785 m->idsp.idct_put(frame->data[0] + y * frame->linesize[0] + x + 8,
2786 frame->linesize[0], s->block[1]);
2787 m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x,
2788 frame->linesize[0], s->block[2]);
2789 m->idsp.idct_put(frame->data[0] + (y + 8) * frame->linesize[0] + x + 8,
2790 frame->linesize[0], s->block[3]);
2791 m->idsp.idct_put(frame->data[1] + (y >> 1) * frame->linesize[1] + (x >> 1),
2792 frame->linesize[1], s->block[4]);
2793 m->idsp.idct_put(frame->data[2] + (y >> 1) * frame->linesize[2] + (x >> 1),
2794 frame->linesize[2], s->block[5]);
2795 }
2796 }
2797
2798 align_get_bits(gb);
2799 if (get_bits_left(gb) != 32)
2800 return AVERROR_INVALIDDATA;
2801
2802 *got_frame = 1;
2803
2804 return avpkt->size;
2805 }
2806
2807 static av_cold int ipu_decode_init(AVCodecContext *avctx)
2808 {
2809 IPUContext *s = avctx->priv_data;
2810 MpegEncContext *m = &s->m;
2811
2812 avctx->pix_fmt = AV_PIX_FMT_YUV420P;
2813 m->avctx = avctx;
2814
2815 ff_idctdsp_init(&m->idsp, avctx);
2816 ff_mpeg12_init_vlcs();
2817
2818 for (int i = 0; i < 64; i++) {
2819 int j = m->idsp.idct_permutation[i];
2820 int v = ff_mpeg1_default_intra_matrix[i];
2821 m->intra_matrix[j] = v;
2822 m->chroma_intra_matrix[j] = v;
2823 }
2824
2825 return 0;
2826 }
2827
2828 const FFCodec ff_ipu_decoder = {
2829 .p.name = "ipu",
2830 CODEC_LONG_NAME("IPU Video"),
2831 .p.type = AVMEDIA_TYPE_VIDEO,
2832 .p.id = AV_CODEC_ID_IPU,
2833 .priv_data_size = sizeof(IPUContext),
2834 .init = ipu_decode_init,
2835 FF_CODEC_DECODE_CB(ipu_decode_frame),
2836 .p.capabilities = AV_CODEC_CAP_DR1,
2837 };
2838