../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
1451 / 2437
59.5%
Branches:
795 / 1597
49.8%
Functions:
44 / 53
83.0%

libavcodec/mpeg4videodec.c
Line Branch Exec Source
1 /*
2 * MPEG-4 decoder
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 * Copyright (c) 2002-2010 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 #define UNCHECKED_BITSTREAM_READER 1
24
25 #include "config_components.h"
26
27 #include "libavutil/avassert.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/thread.h"
32 #include "codec_internal.h"
33 #include "error_resilience.h"
34 #include "hwconfig.h"
35 #include "idctdsp.h"
36 #include "mpegutils.h"
37 #include "mpegvideo.h"
38 #include "mpegvideodata.h"
39 #include "mpegvideodec.h"
40 #include "mpegvideo_unquantize.h"
41 #include "mpeg4video.h"
42 #include "mpeg4videodata.h"
43 #include "mpeg4videodec.h"
44 #include "mpeg4videodefs.h"
45 #include "h263.h"
46 #include "h263data.h"
47 #include "h263dec.h"
48 #include "internal.h"
49 #include "profiles.h"
50 #include "qpeldsp.h"
51 #include "threadprogress.h"
52 #include "unary.h"
53
54 #if 0 //3IV1 is quite rare and it slows things down a tiny bit
55 #define IS_3IV1 (s->codec_tag == AV_RL32("3IV1"))
56 #else
57 #define IS_3IV1 0
58 #endif
59
60 /* The defines below define the number of bits that are read at once for
61 * reading vlc values. Changing these may improve speed and data cache needs
62 * be aware though that decreasing them may need the number of stages that is
63 * passed to get_vlc* to be increased. */
64 #define SPRITE_TRAJ_VLC_BITS 6
65 #define DC_VLC_BITS 9
66 #define MB_TYPE_B_VLC_BITS 4
67 #define STUDIO_INTRA_BITS 9
68
69 static VLCElem dc_lum[512], dc_chrom[512];
70 static VLCElem sprite_trajectory[128];
71 static VLCElem mb_type_b_vlc[16];
72 static const VLCElem *studio_intra_tab[12];
73 static VLCElem studio_luma_dc[528];
74 static VLCElem studio_chroma_dc[528];
75
76 static const uint8_t mpeg4_block_count[4] = { 0, 6, 8, 12 };
77
78 static const int16_t mb_type_b_map[4] = {
79 MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV,
80 MB_TYPE_BIDIR_MV | MB_TYPE_16x16,
81 MB_TYPE_BACKWARD_MV | MB_TYPE_16x16,
82 MB_TYPE_FORWARD_MV | MB_TYPE_16x16,
83 };
84
85 1618776 static inline Mpeg4DecContext *h263_to_mpeg4(H263DecContext *h)
86 {
87 av_assert2(h->c.codec_id == AV_CODEC_ID_MPEG4 && h->c.avctx->priv_data == h);
88 1618776 return (Mpeg4DecContext*)h;
89 }
90
91 ✗ static void gmc1_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
92 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
93 uint8_t *const *ref_picture)
94 {
95 const uint8_t *ptr;
96 int src_x, src_y, motion_x, motion_y;
97 ptrdiff_t offset, linesize, uvlinesize;
98 ✗ int emu = 0;
99
100 ✗ motion_x = ctx->sprite_offset[0][0];
101 ✗ motion_y = ctx->sprite_offset[0][1];
102 ✗ src_x = s->mb_x * 16 + (motion_x >> (ctx->sprite_warping_accuracy + 1));
103 ✗ src_y = s->mb_y * 16 + (motion_y >> (ctx->sprite_warping_accuracy + 1));
104 ✗ motion_x *= 1 << (3 - ctx->sprite_warping_accuracy);
105 ✗ motion_y *= 1 << (3 - ctx->sprite_warping_accuracy);
106 ✗ src_x = av_clip(src_x, -16, s->width);
107
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (src_x == s->width)
108 ✗ motion_x = 0;
109 ✗ src_y = av_clip(src_y, -16, s->height);
110
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (src_y == s->height)
111 ✗ motion_y = 0;
112
113 ✗ linesize = s->linesize;
114 ✗ uvlinesize = s->uvlinesize;
115
116 ✗ ptr = ref_picture[0] + src_y * linesize + src_x;
117
118
0/4
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 14 not taken.
✗ if ((unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ||
119
0/4
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 16 not taken.
✗ (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)) {
120 ✗ s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
121 linesize, linesize,
122 17, 17,
123 src_x, src_y,
124 s->h_edge_pos, s->v_edge_pos);
125 ✗ ptr = s->sc.edge_emu_buffer;
126 }
127
128
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 19 not taken.
✗ if ((motion_x | motion_y) & 7) {
129 ✗ ctx->mdsp.gmc1(dest_y, ptr, linesize, 16,
130 ✗ motion_x & 15, motion_y & 15, 128 - s->no_rounding);
131 ✗ ctx->mdsp.gmc1(dest_y + 8, ptr + 8, linesize, 16,
132 ✗ motion_x & 15, motion_y & 15, 128 - s->no_rounding);
133 } else {
134 int dxy;
135
136 ✗ dxy = ((motion_x >> 3) & 1) | ((motion_y >> 2) & 2);
137
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ if (s->no_rounding) {
138 ✗ s->hdsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
139 } else {
140 ✗ s->hdsp.put_pixels_tab[0][dxy](dest_y, ptr, linesize, 16);
141 }
142 }
143
144 if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
145 return;
146
147 ✗ motion_x = ctx->sprite_offset[1][0];
148 ✗ motion_y = ctx->sprite_offset[1][1];
149 ✗ src_x = s->mb_x * 8 + (motion_x >> (ctx->sprite_warping_accuracy + 1));
150 ✗ src_y = s->mb_y * 8 + (motion_y >> (ctx->sprite_warping_accuracy + 1));
151 ✗ motion_x *= 1 << (3 - ctx->sprite_warping_accuracy);
152 ✗ motion_y *= 1 << (3 - ctx->sprite_warping_accuracy);
153 ✗ src_x = av_clip(src_x, -8, s->width >> 1);
154
0/2
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ if (src_x == s->width >> 1)
155 ✗ motion_x = 0;
156 ✗ src_y = av_clip(src_y, -8, s->height >> 1);
157
0/2
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ if (src_y == s->height >> 1)
158 ✗ motion_y = 0;
159
160 ✗ offset = (src_y * uvlinesize) + src_x;
161 ✗ ptr = ref_picture[1] + offset;
162
0/4
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 34 not taken.
✗ if ((unsigned)src_x >= FFMAX((s->h_edge_pos >> 1) - 9, 0) ||
163
0/4
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 36 not taken.
✗ (unsigned)src_y >= FFMAX((s->v_edge_pos >> 1) - 9, 0)) {
164 ✗ s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
165 uvlinesize, uvlinesize,
166 9, 9,
167 src_x, src_y,
168 ✗ s->h_edge_pos >> 1, s->v_edge_pos >> 1);
169 ✗ ptr = s->sc.edge_emu_buffer;
170 ✗ emu = 1;
171 }
172 ✗ ctx->mdsp.gmc1(dest_cb, ptr, uvlinesize, 8,
173 ✗ motion_x & 15, motion_y & 15, 128 - s->no_rounding);
174
175 ✗ ptr = ref_picture[2] + offset;
176
0/2
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 40 not taken.
✗ if (emu) {
177 ✗ s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr,
178 uvlinesize, uvlinesize,
179 9, 9,
180 src_x, src_y,
181 ✗ s->h_edge_pos >> 1, s->v_edge_pos >> 1);
182 ✗ ptr = s->sc.edge_emu_buffer;
183 }
184 ✗ ctx->mdsp.gmc1(dest_cr, ptr, uvlinesize, 8,
185 ✗ motion_x & 15, motion_y & 15, 128 - s->no_rounding);
186 }
187
188 ✗ static void gmc_motion(MpegEncContext *s, const Mpeg4DecContext *ctx,
189 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
190 uint8_t *const *ref_picture)
191 {
192 const uint8_t *ptr;
193 int linesize, uvlinesize;
194 ✗ const int a = ctx->sprite_warping_accuracy;
195 int ox, oy;
196
197 ✗ linesize = s->linesize;
198 ✗ uvlinesize = s->uvlinesize;
199
200 ✗ ptr = ref_picture[0];
201
202 ✗ ox = ctx->sprite_offset[0][0] + ctx->sprite_delta[0][0] * s->mb_x * 16 +
203 ✗ ctx->sprite_delta[0][1] * s->mb_y * 16;
204 ✗ oy = ctx->sprite_offset[0][1] + ctx->sprite_delta[1][0] * s->mb_x * 16 +
205 ✗ ctx->sprite_delta[1][1] * s->mb_y * 16;
206
207 ✗ ctx->mdsp.gmc(dest_y, ptr, linesize, 16,
208 ox, oy,
209 ✗ ctx->sprite_delta[0][0], ctx->sprite_delta[0][1],
210 ✗ ctx->sprite_delta[1][0], ctx->sprite_delta[1][1],
211 ✗ a + 1, (1 << (2 * a + 1)) - s->no_rounding,
212 s->h_edge_pos, s->v_edge_pos);
213 ✗ ctx->mdsp.gmc(dest_y + 8, ptr, linesize, 16,
214 ✗ ox + ctx->sprite_delta[0][0] * 8,
215 ✗ oy + ctx->sprite_delta[1][0] * 8,
216 ✗ ctx->sprite_delta[0][0], ctx->sprite_delta[0][1],
217 ✗ ctx->sprite_delta[1][0], ctx->sprite_delta[1][1],
218 ✗ a + 1, (1 << (2 * a + 1)) - s->no_rounding,
219 s->h_edge_pos, s->v_edge_pos);
220
221 if (CONFIG_GRAY && s->avctx->flags & AV_CODEC_FLAG_GRAY)
222 return;
223
224 ✗ ox = ctx->sprite_offset[1][0] + ctx->sprite_delta[0][0] * s->mb_x * 8 +
225 ✗ ctx->sprite_delta[0][1] * s->mb_y * 8;
226 ✗ oy = ctx->sprite_offset[1][1] + ctx->sprite_delta[1][0] * s->mb_x * 8 +
227 ✗ ctx->sprite_delta[1][1] * s->mb_y * 8;
228
229 ✗ ptr = ref_picture[1];
230 ✗ ctx->mdsp.gmc(dest_cb, ptr, uvlinesize, 8,
231 ox, oy,
232 ✗ ctx->sprite_delta[0][0], ctx->sprite_delta[0][1],
233 ✗ ctx->sprite_delta[1][0], ctx->sprite_delta[1][1],
234 ✗ a + 1, (1 << (2 * a + 1)) - s->no_rounding,
235 ✗ (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
236
237 ✗ ptr = ref_picture[2];
238 ✗ ctx->mdsp.gmc(dest_cr, ptr, uvlinesize, 8,
239 ox, oy,
240 ✗ ctx->sprite_delta[0][0], ctx->sprite_delta[0][1],
241 ✗ ctx->sprite_delta[1][0], ctx->sprite_delta[1][1],
242 ✗ a + 1, (1 << (2 * a + 1)) - s->no_rounding,
243 ✗ (s->h_edge_pos + 1) >> 1, (s->v_edge_pos + 1) >> 1);
244 }
245
246 ✗ void ff_mpeg4_mcsel_motion(MpegEncContext *s,
247 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
248 uint8_t *const *ref_picture)
249 {
250 ✗ const Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
251
252
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (ctx->real_sprite_warping_points == 1) {
253 ✗ gmc1_motion(s, ctx, dest_y, dest_cb, dest_cr,
254 ref_picture);
255 } else {
256 ✗ gmc_motion(s, ctx, dest_y, dest_cb, dest_cr,
257 ref_picture);
258 }
259 ✗ }
260
261 1350 void ff_mpeg4_decode_studio(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb,
262 uint8_t *dest_cr, int block_size, int uvlinesize,
263 int dct_linesize, int dct_offset)
264 {
265 1350 Mpeg4DecContext *const ctx = (Mpeg4DecContext*)s;
266 1350 const int act_block_size = block_size * 2;
267
268
2/2
✓ Branch 2 → 3 taken 667 times.
✓ Branch 2 → 19 taken 683 times.
1350 if (ctx->dpcm_direction == 0) {
269 667 s->idsp.idct_put(dest_y, dct_linesize, (int16_t*)ctx->block32[0]);
270 667 s->idsp.idct_put(dest_y + act_block_size, dct_linesize, (int16_t*)ctx->block32[1]);
271 667 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, (int16_t*)ctx->block32[2]);
272 667 s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)ctx->block32[3]);
273
274 667 dct_linesize = uvlinesize << s->interlaced_dct;
275
1/2
✓ Branch 7 → 8 taken 667 times.
✗ Branch 7 → 9 not taken.
667 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
276
277 667 s->idsp.idct_put(dest_cb, dct_linesize, (int16_t*)ctx->block32[4]);
278 667 s->idsp.idct_put(dest_cr, dct_linesize, (int16_t*)ctx->block32[5]);
279 667 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)ctx->block32[6]);
280 667 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)ctx->block32[7]);
281
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 52 taken 667 times.
667 if (!s->chroma_x_shift){ //Chroma444
282 ✗ s->idsp.idct_put(dest_cb + act_block_size, dct_linesize, (int16_t*)ctx->block32[8]);
283 ✗ s->idsp.idct_put(dest_cr + act_block_size, dct_linesize, (int16_t*)ctx->block32[9]);
284 ✗ s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)ctx->block32[10]);
285 ✗ s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)ctx->block32[11]);
286 }
287
1/2
✓ Branch 19 → 20 taken 683 times.
✗ Branch 19 → 36 not taken.
683 } else if (ctx->dpcm_direction == 1) {
288 683 uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
289 683 int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
290
2/2
✓ Branch 34 → 21 taken 2049 times.
✓ Branch 34 → 35 taken 683 times.
2732 for (int i = 0; i < 3; i++) {
291 2049 const uint16_t *src = ctx->dpcm_macroblock[i];
292
2/2
✓ Branch 21 → 22 taken 1366 times.
✓ Branch 21 → 23 taken 683 times.
2049 int vsub = i ? s->chroma_y_shift : 0;
293
2/2
✓ Branch 24 → 25 taken 1366 times.
✓ Branch 24 → 26 taken 683 times.
2049 int hsub = i ? s->chroma_x_shift : 0;
294 2049 int lowres = s->avctx->lowres;
295 2049 int step = 1 << lowres;
296
2/2
✓ Branch 32 → 28 taken 32784 times.
✓ Branch 32 → 33 taken 2049 times.
34833 for (int h = 0; h < (16 >> (vsub + lowres)); h++){
297
2/2
✓ Branch 30 → 29 taken 349696 times.
✓ Branch 30 → 31 taken 32784 times.
382480 for (int w = 0, idx = 0; w < (16 >> (hsub + lowres)); w++, idx += step)
298 349696 dest_pcm[i][w] = src[idx];
299 32784 dest_pcm[i] += linesize[i] / 2;
300 32784 src += (16 >> hsub) * step;
301 }
302 }
303 } else {
304 ✗ uint16_t *dest_pcm[3] = {(uint16_t*)dest_y, (uint16_t*)dest_cb, (uint16_t*)dest_cr};
305 ✗ int linesize[3] = {dct_linesize, uvlinesize, uvlinesize};
306 av_assert2(ctx->dpcm_direction == -1);
307
0/2
✗ Branch 50 → 37 not taken.
✗ Branch 50 → 51 not taken.
✗ for (int i = 0; i < 3; i++) {
308 ✗ const uint16_t *src = ctx->dpcm_macroblock[i];
309
0/2
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 39 not taken.
✗ int vsub = i ? s->chroma_y_shift : 0;
310
0/2
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ int hsub = i ? s->chroma_x_shift : 0;
311 ✗ int lowres = s->avctx->lowres;
312 ✗ int step = 1 << lowres;
313 ✗ dest_pcm[i] += (linesize[i] / 2) * ((16 >> vsub + lowres) - 1);
314
0/2
✗ Branch 48 → 44 not taken.
✗ Branch 48 → 49 not taken.
✗ for (int h = (16 >> (vsub + lowres)) - 1; h >= 0; h--){
315
0/2
✗ Branch 46 → 45 not taken.
✗ Branch 46 → 47 not taken.
✗ for (int w = (16 >> (hsub + lowres)) - 1, idx = 0; w >= 0; w--, idx += step)
316 ✗ dest_pcm[i][w] = src[idx];
317 ✗ src += step * (16 >> hsub);
318 ✗ dest_pcm[i] -= linesize[i] / 2;
319 }
320 }
321 }
322 1350 }
323
324 /**
325 * Predict the ac.
326 * @param n block index (0-3 are luma, 4-5 are chroma)
327 * @param dir the ac prediction direction
328 */
329 1392912 void ff_mpeg4_pred_ac(H263DecContext *const h, int16_t *block, int n, int dir)
330 {
331 int i;
332 int16_t *ac_val, *ac_val1;
333 1392912 int8_t *const qscale_table = h->c.cur_pic.qscale_table;
334
335 /* find prediction */
336 1392912 ac_val = &h->c.ac_val[0][0] + h->c.block_index[n] * 16;
337 1392912 ac_val1 = ac_val;
338
2/2
✓ Branch 2 → 3 taken 30132 times.
✓ Branch 2 → 33 taken 1362780 times.
1392912 if (h->c.ac_pred) {
339
2/2
✓ Branch 3 → 4 taken 20809 times.
✓ Branch 3 → 19 taken 9323 times.
30132 if (dir == 0) {
340 20809 const int xy = h->c.mb_x - 1 + h->c.mb_y * h->c.mb_stride;
341 /* left prediction */
342 20809 ac_val -= 16;
343
344
3/6
✓ Branch 4 → 5 taken 20347 times.
✓ Branch 4 → 8 taken 462 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 20347 times.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
20809 if (h->c.mb_x == 0 || h->c.qscale == qscale_table[xy] ||
345
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 12 not taken.
✗ n == 1 || n == 3) {
346 /* same qscale */
347
2/2
✓ Branch 10 → 9 taken 145663 times.
✓ Branch 10 → 11 taken 20809 times.
166472 for (i = 1; i < 8; i++)
348 145663 block[h->c.idsp.idct_permutation[i << 3]] += ac_val[i];
349 } else {
350 /* different qscale, we must rescale */
351
0/2
✗ Branch 17 → 13 not taken.
✗ Branch 17 → 18 not taken.
✗ for (i = 1; i < 8; i++)
352
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ block[h->c.idsp.idct_permutation[i << 3]] += ROUNDED_DIV(ac_val[i] * qscale_table[xy], h->c.qscale);
353 }
354 } else {
355 9323 const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride - h->c.mb_stride;
356 /* top prediction */
357 9323 ac_val -= 16 * h->c.block_wrap[n];
358
359
6/6
✓ Branch 19 → 20 taken 9123 times.
✓ Branch 19 → 23 taken 200 times.
✓ Branch 20 → 21 taken 2 times.
✓ Branch 20 → 23 taken 9121 times.
✓ Branch 21 → 22 taken 1 time.
✓ Branch 21 → 23 taken 1 time.
9323 if (h->c.mb_y == 0 || h->c.qscale == qscale_table[xy] ||
360
1/2
✓ Branch 22 → 23 taken 1 time.
✗ Branch 22 → 27 not taken.
1 n == 2 || n == 3) {
361 /* same qscale */
362
2/2
✓ Branch 25 → 24 taken 65261 times.
✓ Branch 25 → 26 taken 9323 times.
74584 for (i = 1; i < 8; i++)
363 65261 block[h->c.idsp.idct_permutation[i]] += ac_val[i + 8];
364 } else {
365 /* different qscale, we must rescale */
366
0/2
✗ Branch 32 → 28 not taken.
✗ Branch 32 → 33 not taken.
✗ for (i = 1; i < 8; i++)
367
0/2
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ block[h->c.idsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8] * qscale_table[xy], h->c.qscale);
368 }
369 }
370 }
371 /* left copy */
372
2/2
✓ Branch 35 → 34 taken 9750384 times.
✓ Branch 35 → 36 taken 1392912 times.
11143296 for (i = 1; i < 8; i++)
373 9750384 ac_val1[i] = block[h->c.idsp.idct_permutation[i << 3]];
374
375 /* top copy */
376
2/2
✓ Branch 38 → 37 taken 9750384 times.
✓ Branch 38 → 39 taken 1392912 times.
11143296 for (i = 1; i < 8; i++)
377 9750384 ac_val1[8 + i] = block[h->c.idsp.idct_permutation[i]];
378 1392912 }
379
380 /**
381 * check if the next stuff is a resync marker or the end.
382 * @return 0 if not
383 */
384 1599116 static inline int mpeg4_is_resync(Mpeg4DecContext *ctx)
385 {
386 1599116 H263DecContext *const h = &ctx->h;
387 1599116 int bits_count = get_bits_count(&h->gb);
388 1599116 int v = show_bits(&h->gb, 16);
389
390
1/4
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 1599116 times.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
1599116 if (h->c.workaround_bugs & FF_BUG_NO_PADDING && !ctx->resync_marker)
391 ✗ return 0;
392
393
2/2
✓ Branch 14 → 8 taken 5423 times.
✓ Branch 14 → 15 taken 1593693 times.
1599116 while (v <= 0xFF) {
394
2/2
✓ Branch 8 → 9 taken 4448 times.
✓ Branch 8 → 15 taken 975 times.
5423 if (h->c.pict_type == AV_PICTURE_TYPE_B ||
395
3/4
✓ Branch 9 → 10 taken 172 times.
✓ Branch 9 → 15 taken 4276 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 15 taken 172 times.
4448 (v >> (8 - h->c.pict_type) != 1) || h->partitioned_frame)
396 break;
397 ✗ skip_bits(&h->gb, 8 + h->c.pict_type);
398 ✗ bits_count += 8 + h->c.pict_type;
399 ✗ v = show_bits(&h->gb, 16);
400 }
401
402
2/2
✓ Branch 15 → 16 taken 16660 times.
✓ Branch 15 → 18 taken 1582456 times.
1599116 if (bits_count + 8 >= h->gb.size_in_bits) {
403 16660 v >>= 8;
404 16660 v |= 0x7F >> (7 - (bits_count & 7));
405
406
2/2
✓ Branch 16 → 17 taken 13264 times.
✓ Branch 16 → 37 taken 3396 times.
16660 if (v == 0x7F)
407 13264 return h->c.mb_num;
408 } else {
409 static const uint16_t mpeg4_resync_prefix[8] = {
410 0x7F00, 0x7E00, 0x7C00, 0x7800, 0x7000, 0x6000, 0x4000, 0x0000
411 };
412
413
2/2
✓ Branch 18 → 19 taken 11338 times.
✓ Branch 18 → 37 taken 1571118 times.
1582456 if (v == mpeg4_resync_prefix[bits_count & 7]) {
414 int len, mb_num;
415 11338 int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;
416 11338 GetBitContext gb = h->gb;
417
418 11338 skip_bits(&h->gb, 1);
419 11338 align_get_bits(&h->gb);
420
421
1/2
✓ Branch 26 → 22 taken 195291 times.
✗ Branch 26 → 27 not taken.
195291 for (len = 0; len < 32; len++)
422
2/2
✓ Branch 23 → 24 taken 11338 times.
✓ Branch 23 → 25 taken 183953 times.
195291 if (get_bits1(&h->gb))
423 11338 break;
424
425 11338 mb_num = get_bits(&h->gb, mb_num_bits);
426
3/6
✓ Branch 28 → 29 taken 11338 times.
✗ Branch 28 → 32 not taken.
✓ Branch 29 → 30 taken 11338 times.
✗ Branch 29 → 32 not taken.
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 11338 times.
11338 if (!mb_num || mb_num > h->c.mb_num || get_bits_count(&h->gb) + 6 > h->gb.size_in_bits)
427 ✗ mb_num= -1;
428
429 11338 h->gb = gb;
430
431
2/2
✓ Branch 34 → 35 taken 11337 times.
✓ Branch 34 → 36 taken 1 time.
11338 if (len >= ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code))
432 11337 return mb_num;
433 }
434 }
435 1574515 return 0;
436 }
437
438 ✗ static int mpeg4_decode_sprite_trajectory(Mpeg4DecContext *ctx, GetBitContext *gb)
439 {
440 ✗ MpegEncContext *s = &ctx->h.c;
441 ✗ int a = 2 << ctx->sprite_warping_accuracy;
442 ✗ int rho = 3 - ctx->sprite_warping_accuracy;
443 ✗ int r = 16 / a;
444 ✗ int alpha = 1;
445 ✗ int beta = 0;
446 ✗ int w = s->width;
447 ✗ int h = s->height;
448 int min_ab, i, w2, h2, w3, h3;
449 int sprite_ref[4][2];
450 int virtual_ref[2][2];
451 int64_t sprite_offset[2][2];
452 int64_t sprite_delta[2][2];
453
454 // only true for rectangle shapes
455 ✗ const int vop_ref[4][2] = { { 0, 0 }, { s->width, 0 },
456 ✗ { 0, s->height }, { s->width, s->height } };
457 ✗ int d[4][2] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
458
459
0/4
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (w <= 0 || h <= 0)
460 ✗ return AVERROR_INVALIDDATA;
461
462
0/2
✗ Branch 17 → 6 not taken.
✗ Branch 17 → 18 not taken.
✗ for (i = 0; i < ctx->num_sprite_warping_points; i++) {
463 int length;
464 ✗ int x = 0, y = 0;
465
466 ✗ length = get_vlc2(gb, sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 2);
467
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (length > 0)
468 ✗ x = get_xbits(gb, length);
469
470
0/4
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
✗ if (!(ctx->divx_version == 500 && ctx->divx_build == 413))
471 ✗ check_marker(s->avctx, gb, "before sprite_trajectory");
472
473 ✗ length = get_vlc2(gb, sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 2);
474
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ if (length > 0)
475 ✗ y = get_xbits(gb, length);
476
477 ✗ check_marker(s->avctx, gb, "after sprite_trajectory");
478 ✗ ctx->sprite_traj[i][0] = d[i][0] = x;
479 ✗ ctx->sprite_traj[i][1] = d[i][1] = y;
480 }
481
0/2
✗ Branch 20 → 19 not taken.
✗ Branch 20 → 21 not taken.
✗ for (; i < 4; i++)
482 ✗ ctx->sprite_traj[i][0] = ctx->sprite_traj[i][1] = 0;
483
484
0/2
✗ Branch 23 → 22 not taken.
✗ Branch 23 → 24 not taken.
✗ while ((1 << alpha) < w)
485 ✗ alpha++;
486
0/2
✗ Branch 26 → 25 not taken.
✗ Branch 26 → 27 not taken.
✗ while ((1 << beta) < h)
487 ✗ beta++; /* typo in the MPEG-4 std for the definition of w' and h' */
488 ✗ w2 = 1 << alpha;
489 ✗ h2 = 1 << beta;
490
491 // Note, the 4th point isn't used for GMC
492
0/4
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 30 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
✗ if (ctx->divx_version == 500 && ctx->divx_build == 413) {
493 ✗ sprite_ref[0][0] = a * vop_ref[0][0] + d[0][0];
494 ✗ sprite_ref[0][1] = a * vop_ref[0][1] + d[0][1];
495 ✗ sprite_ref[1][0] = a * vop_ref[1][0] + d[0][0] + d[1][0];
496 ✗ sprite_ref[1][1] = a * vop_ref[1][1] + d[0][1] + d[1][1];
497 ✗ sprite_ref[2][0] = a * vop_ref[2][0] + d[0][0] + d[2][0];
498 ✗ sprite_ref[2][1] = a * vop_ref[2][1] + d[0][1] + d[2][1];
499 } else {
500 ✗ sprite_ref[0][0] = (a >> 1) * (2 * vop_ref[0][0] + d[0][0]);
501 ✗ sprite_ref[0][1] = (a >> 1) * (2 * vop_ref[0][1] + d[0][1]);
502 ✗ sprite_ref[1][0] = (a >> 1) * (2 * vop_ref[1][0] + d[0][0] + d[1][0]);
503 ✗ sprite_ref[1][1] = (a >> 1) * (2 * vop_ref[1][1] + d[0][1] + d[1][1]);
504 ✗ sprite_ref[2][0] = (a >> 1) * (2 * vop_ref[2][0] + d[0][0] + d[2][0]);
505 ✗ sprite_ref[2][1] = (a >> 1) * (2 * vop_ref[2][1] + d[0][1] + d[2][1]);
506 }
507 /* sprite_ref[3][0] = (a >> 1) * (2 * vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]);
508 * sprite_ref[3][1] = (a >> 1) * (2 * vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */
509
510 /* This is mostly identical to the MPEG-4 std (and is totally unreadable
511 * because of that...). Perhaps it should be reordered to be more readable.
512 * The idea behind this virtual_ref mess is to be able to use shifts later
513 * per pixel instead of divides so the distance between points is converted
514 * from w&h based to w2&h2 based which are of the 2^x form. */
515 ✗ virtual_ref[0][0] = 16 * (vop_ref[0][0] + w2) +
516
0/2
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
✗ ROUNDED_DIV(((w - w2) *
517 (r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
518 w2 * (r * sprite_ref[1][0] - 16LL * vop_ref[1][0])), w);
519 ✗ virtual_ref[0][1] = 16 * vop_ref[0][1] +
520
0/2
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 36 not taken.
✗ ROUNDED_DIV(((w - w2) *
521 (r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
522 w2 * (r * sprite_ref[1][1] - 16LL * vop_ref[1][1])), w);
523 ✗ virtual_ref[1][0] = 16 * vop_ref[0][0] +
524
0/2
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 39 not taken.
✗ ROUNDED_DIV(((h - h2) * (r * sprite_ref[0][0] - 16LL * vop_ref[0][0]) +
525 h2 * (r * sprite_ref[2][0] - 16LL * vop_ref[2][0])), h);
526 ✗ virtual_ref[1][1] = 16 * (vop_ref[0][1] + h2) +
527
0/2
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ ROUNDED_DIV(((h - h2) * (r * sprite_ref[0][1] - 16LL * vop_ref[0][1]) +
528 h2 * (r * sprite_ref[2][1] - 16LL * vop_ref[2][1])), h);
529
530
0/5
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 45 not taken.
✗ Branch 43 → 46 not taken.
✗ Branch 43 → 47 not taken.
✗ Branch 43 → 48 not taken.
✗ switch (ctx->num_sprite_warping_points) {
531 ✗ case 0:
532 ✗ sprite_offset[0][0] =
533 ✗ sprite_offset[0][1] =
534 ✗ sprite_offset[1][0] =
535 ✗ sprite_offset[1][1] = 0;
536 ✗ sprite_delta[0][0] = a;
537 ✗ sprite_delta[0][1] =
538 ✗ sprite_delta[1][0] = 0;
539 ✗ sprite_delta[1][1] = a;
540 ✗ ctx->sprite_shift[0] =
541 ✗ ctx->sprite_shift[1] = 0;
542 ✗ break;
543 ✗ case 1: // GMC only
544 ✗ sprite_offset[0][0] = sprite_ref[0][0] - a * vop_ref[0][0];
545 ✗ sprite_offset[0][1] = sprite_ref[0][1] - a * vop_ref[0][1];
546 ✗ sprite_offset[1][0] = ((sprite_ref[0][0] >> 1) | (sprite_ref[0][0] & 1)) -
547 ✗ a * (vop_ref[0][0] / 2);
548 ✗ sprite_offset[1][1] = ((sprite_ref[0][1] >> 1) | (sprite_ref[0][1] & 1)) -
549 ✗ a * (vop_ref[0][1] / 2);
550 ✗ sprite_delta[0][0] = a;
551 ✗ sprite_delta[0][1] =
552 ✗ sprite_delta[1][0] = 0;
553 ✗ sprite_delta[1][1] = a;
554 ✗ ctx->sprite_shift[0] =
555 ✗ ctx->sprite_shift[1] = 0;
556 ✗ break;
557 ✗ case 2:
558 ✗ sprite_offset[0][0] = ((int64_t) sprite_ref[0][0] * (1 << alpha + rho)) +
559 ✗ ((int64_t) -r * sprite_ref[0][0] + virtual_ref[0][0]) *
560 ✗ ((int64_t) -vop_ref[0][0]) +
561 ✗ ((int64_t) r * sprite_ref[0][1] - virtual_ref[0][1]) *
562 ✗ ((int64_t) -vop_ref[0][1]) + (1 << (alpha + rho - 1));
563 ✗ sprite_offset[0][1] = ((int64_t) sprite_ref[0][1] * (1 << alpha + rho)) +
564 ✗ ((int64_t) -r * sprite_ref[0][1] + virtual_ref[0][1]) *
565 ✗ ((int64_t) -vop_ref[0][0]) +
566 ✗ ((int64_t) -r * sprite_ref[0][0] + virtual_ref[0][0]) *
567 ✗ ((int64_t) -vop_ref[0][1]) + (1 << (alpha + rho - 1));
568 ✗ sprite_offset[1][0] = (((int64_t)-r * sprite_ref[0][0] + virtual_ref[0][0]) *
569 ✗ ((int64_t)-2 * vop_ref[0][0] + 1) +
570 ✗ ((int64_t) r * sprite_ref[0][1] - virtual_ref[0][1]) *
571 ✗ ((int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 * r *
572 ✗ (int64_t) sprite_ref[0][0] - 16 * w2 + (1 << (alpha + rho + 1)));
573 ✗ sprite_offset[1][1] = (((int64_t)-r * sprite_ref[0][1] + virtual_ref[0][1]) *
574 ✗ ((int64_t)-2 * vop_ref[0][0] + 1) +
575 ✗ ((int64_t)-r * sprite_ref[0][0] + virtual_ref[0][0]) *
576 ✗ ((int64_t)-2 * vop_ref[0][1] + 1) + 2 * w2 * r *
577 ✗ (int64_t) sprite_ref[0][1] - 16 * w2 + (1 << (alpha + rho + 1)));
578 ✗ sprite_delta[0][0] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
579 ✗ sprite_delta[0][1] = (+r * sprite_ref[0][1] - virtual_ref[0][1]);
580 ✗ sprite_delta[1][0] = (-r * sprite_ref[0][1] + virtual_ref[0][1]);
581 ✗ sprite_delta[1][1] = (-r * sprite_ref[0][0] + virtual_ref[0][0]);
582
583 ✗ ctx->sprite_shift[0] = alpha + rho;
584 ✗ ctx->sprite_shift[1] = alpha + rho + 2;
585 ✗ break;
586 ✗ case 3:
587 ✗ min_ab = FFMIN(alpha, beta);
588 ✗ w3 = w2 >> min_ab;
589 ✗ h3 = h2 >> min_ab;
590 ✗ sprite_offset[0][0] = ((int64_t)sprite_ref[0][0] * (1 << (alpha + beta + rho - min_ab))) +
591 ✗ ((int64_t)-r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-vop_ref[0][0]) +
592 ✗ ((int64_t)-r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-vop_ref[0][1]) +
593 ✗ ((int64_t)1 << (alpha + beta + rho - min_ab - 1));
594 ✗ sprite_offset[0][1] = ((int64_t)sprite_ref[0][1] * (1 << (alpha + beta + rho - min_ab))) +
595 ✗ ((int64_t)-r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-vop_ref[0][0]) +
596 ✗ ((int64_t)-r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-vop_ref[0][1]) +
597 ✗ ((int64_t)1 << (alpha + beta + rho - min_ab - 1));
598 ✗ sprite_offset[1][0] = ((int64_t)-r * sprite_ref[0][0] + virtual_ref[0][0]) * h3 * (-2 * vop_ref[0][0] + 1) +
599 ✗ ((int64_t)-r * sprite_ref[0][0] + virtual_ref[1][0]) * w3 * (-2 * vop_ref[0][1] + 1) +
600 ✗ (int64_t)2 * w2 * h3 * r * sprite_ref[0][0] - 16 * w2 * h3 +
601 ✗ ((int64_t)1 << (alpha + beta + rho - min_ab + 1));
602 ✗ sprite_offset[1][1] = ((int64_t)-r * sprite_ref[0][1] + virtual_ref[0][1]) * h3 * (-2 * vop_ref[0][0] + 1) +
603 ✗ ((int64_t)-r * sprite_ref[0][1] + virtual_ref[1][1]) * w3 * (-2 * vop_ref[0][1] + 1) +
604 ✗ (int64_t)2 * w2 * h3 * r * sprite_ref[0][1] - 16 * w2 * h3 +
605 ✗ ((int64_t)1 << (alpha + beta + rho - min_ab + 1));
606 ✗ sprite_delta[0][0] = (-r * (int64_t)sprite_ref[0][0] + virtual_ref[0][0]) * h3;
607 ✗ sprite_delta[0][1] = (-r * (int64_t)sprite_ref[0][0] + virtual_ref[1][0]) * w3;
608 ✗ sprite_delta[1][0] = (-r * (int64_t)sprite_ref[0][1] + virtual_ref[0][1]) * h3;
609 ✗ sprite_delta[1][1] = (-r * (int64_t)sprite_ref[0][1] + virtual_ref[1][1]) * w3;
610
611 ✗ ctx->sprite_shift[0] = alpha + beta + rho - min_ab;
612 ✗ ctx->sprite_shift[1] = alpha + beta + rho - min_ab + 2;
613 ✗ break;
614 ✗ default:
615 ✗ av_unreachable("num_sprite_warping_points outside of 0..3 results in an error"
616 "in which num_sprite_warping_points is reset to zero");
617 }
618 /* try to simplify the situation */
619
0/2
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 54 not taken.
✗ if (sprite_delta[0][0] == a << ctx->sprite_shift[0] &&
620
0/2
✗ Branch 50 → 51 not taken.
✗ Branch 50 → 54 not taken.
✗ sprite_delta[0][1] == 0 &&
621
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 54 not taken.
✗ sprite_delta[1][0] == 0 &&
622
0/2
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 54 not taken.
✗ sprite_delta[1][1] == a << ctx->sprite_shift[0]) {
623 ✗ sprite_offset[0][0] >>= ctx->sprite_shift[0];
624 ✗ sprite_offset[0][1] >>= ctx->sprite_shift[0];
625 ✗ sprite_offset[1][0] >>= ctx->sprite_shift[1];
626 ✗ sprite_offset[1][1] >>= ctx->sprite_shift[1];
627 ✗ sprite_delta[0][0] = a;
628 ✗ sprite_delta[0][1] = 0;
629 ✗ sprite_delta[1][0] = 0;
630 ✗ sprite_delta[1][1] = a;
631 ✗ ctx->sprite_shift[0] = 0;
632 ✗ ctx->sprite_shift[1] = 0;
633 ✗ ctx->real_sprite_warping_points = 1;
634 } else {
635 ✗ int shift_y = 16 - ctx->sprite_shift[0];
636 ✗ int shift_c = 16 - ctx->sprite_shift[1];
637
638
0/2
✗ Branch 64 → 55 not taken.
✗ Branch 64 → 65 not taken.
✗ for (i = 0; i < 2; i++) {
639
0/4
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 61 not taken.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 61 not taken.
✗ if (shift_c < 0 || shift_y < 0 ||
640
0/2
✗ Branch 57 → 58 not taken.
✗ Branch 57 → 61 not taken.
✗ FFABS( sprite_offset[0][i]) >= INT_MAX >> shift_y ||
641
0/2
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 61 not taken.
✗ FFABS( sprite_offset[1][i]) >= INT_MAX >> shift_c ||
642
0/2
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
✗ FFABS( sprite_delta[0][i]) >= INT_MAX >> shift_y ||
643
0/2
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 63 not taken.
✗ FFABS( sprite_delta[1][i]) >= INT_MAX >> shift_y
644 ) {
645 ✗ avpriv_request_sample(s->avctx, "Too large sprite shift, delta or offset");
646 ✗ goto overflow;
647 }
648 }
649
650
0/2
✗ Branch 67 → 66 not taken.
✗ Branch 67 → 68 not taken.
✗ for (i = 0; i < 2; i++) {
651 ✗ sprite_offset[0][i] *= 1 << shift_y;
652 ✗ sprite_offset[1][i] *= 1 << shift_c;
653 ✗ sprite_delta[0][i] *= 1 << shift_y;
654 ✗ sprite_delta[1][i] *= 1 << shift_y;
655 ✗ ctx->sprite_shift[i] = 16;
656
657 }
658
0/2
✗ Branch 82 → 69 not taken.
✗ Branch 82 → 83 not taken.
✗ for (i = 0; i < 2; i++) {
659 ✗ int64_t sd[2] = {
660 ✗ sprite_delta[i][0] - a * (1LL<<16),
661 ✗ sprite_delta[i][1] - a * (1LL<<16)
662 };
663
664
0/2
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 79 not taken.
✗ if (llabs(sprite_offset[0][i] + sprite_delta[i][0] * (w+16LL)) >= INT_MAX ||
665
0/2
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 79 not taken.
✗ llabs(sprite_offset[0][i] + sprite_delta[i][1] * (h+16LL)) >= INT_MAX ||
666
0/2
✗ Branch 71 → 72 not taken.
✗ Branch 71 → 79 not taken.
✗ llabs(sprite_offset[0][i] + sprite_delta[i][0] * (w+16LL) + sprite_delta[i][1] * (h+16LL)) >= INT_MAX ||
667
0/2
✗ Branch 72 → 73 not taken.
✗ Branch 72 → 79 not taken.
✗ llabs(sprite_delta[i][0] * (w+16LL)) >= INT_MAX ||
668
0/2
✗ Branch 73 → 74 not taken.
✗ Branch 73 → 79 not taken.
✗ llabs(sprite_delta[i][1] * (h+16LL)) >= INT_MAX ||
669
0/2
✗ Branch 74 → 75 not taken.
✗ Branch 74 → 79 not taken.
✗ llabs(sd[0]) >= INT_MAX ||
670
0/2
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 79 not taken.
✗ llabs(sd[1]) >= INT_MAX ||
671
0/2
✗ Branch 76 → 77 not taken.
✗ Branch 76 → 79 not taken.
✗ llabs(sprite_offset[0][i] + sd[0] * (w+16LL)) >= INT_MAX ||
672
0/2
✗ Branch 77 → 78 not taken.
✗ Branch 77 → 79 not taken.
✗ llabs(sprite_offset[0][i] + sd[1] * (h+16LL)) >= INT_MAX ||
673
0/2
✗ Branch 78 → 79 not taken.
✗ Branch 78 → 81 not taken.
✗ llabs(sprite_offset[0][i] + sd[0] * (w+16LL) + sd[1] * (h+16LL)) >= INT_MAX
674 ) {
675 ✗ avpriv_request_sample(s->avctx, "Overflow on sprite points");
676 ✗ goto overflow;
677 }
678 }
679 ✗ ctx->real_sprite_warping_points = ctx->num_sprite_warping_points;
680 }
681
682
0/2
✗ Branch 86 → 85 not taken.
✗ Branch 86 → 87 not taken.
✗ for (i = 0; i < 4; i++) {
683 ✗ ctx->sprite_offset[i&1][i>>1] = sprite_offset[i&1][i>>1];
684 ✗ ctx->sprite_delta [i&1][i>>1] = sprite_delta [i&1][i>>1];
685 }
686
687 ✗ return 0;
688 ✗ overflow:
689 ✗ memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset));
690 ✗ memset(ctx->sprite_delta, 0, sizeof(ctx->sprite_delta));
691 ✗ return AVERROR_PATCHWELCOME;
692 }
693
694 ✗ static int decode_new_pred(Mpeg4DecContext *ctx, GetBitContext *gb) {
695 ✗ int len = FFMIN(ctx->time_increment_bits + 3, 15);
696
697 ✗ get_bits(gb, len);
698
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (get_bits1(gb))
699 ✗ get_bits(gb, len);
700 ✗ check_marker(ctx->h.c.avctx, gb, "after new_pred");
701
702 ✗ return 0;
703 }
704
705 /**
706 * Decode the next video packet.
707 * @return <0 if something went wrong
708 */
709 11140 int ff_mpeg4_decode_video_packet_header(H263DecContext *const h)
710 {
711 11140 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
712
713 11140 int mb_num_bits = av_log2(h->c.mb_num - 1) + 1;
714 11140 int header_extension = 0, mb_num, len;
715
716 /* is there enough space left for a video packet + header */
717
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 11140 times.
11140 if (get_bits_count(&h->gb) > h->gb.size_in_bits - 20)
718 ✗ return AVERROR_INVALIDDATA;
719
720
1/2
✓ Branch 11 → 7 taken 191886 times.
✗ Branch 11 → 12 not taken.
191886 for (len = 0; len < 32; len++)
721
2/2
✓ Branch 8 → 9 taken 11140 times.
✓ Branch 8 → 10 taken 180746 times.
191886 if (get_bits1(&h->gb))
722 11140 break;
723
724
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 11140 times.
11140 if (len != ff_mpeg4_get_video_packet_prefix_length(h->c.pict_type, ctx->f_code, ctx->b_code)) {
725 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "marker does not match f_code\n");
726 ✗ return AVERROR_INVALIDDATA;
727 }
728
729
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 11140 times.
11140 if (ctx->shape != RECT_SHAPE) {
730 ✗ header_extension = get_bits1(&h->gb);
731 // FIXME more stuff here
732 }
733
734 11140 mb_num = get_bits(&h->gb, mb_num_bits);
735
2/4
✓ Branch 20 → 21 taken 11140 times.
✗ Branch 20 → 22 not taken.
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 24 taken 11140 times.
11140 if (mb_num >= h->c.mb_num || !mb_num) {
736 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
737 "illegal mb_num in video packet (%d %d) \n", mb_num, h->c.mb_num);
738 ✗ return AVERROR_INVALIDDATA;
739 }
740
741 11140 h->c.mb_x = mb_num % h->c.mb_width;
742 11140 h->c.mb_y = mb_num / h->c.mb_width;
743
744
1/2
✓ Branch 24 → 25 taken 11140 times.
✗ Branch 24 → 28 not taken.
11140 if (ctx->shape != BIN_ONLY_SHAPE) {
745 11140 int qscale = get_bits(&h->gb, ctx->quant_precision);
746
1/2
✓ Branch 26 → 27 taken 11140 times.
✗ Branch 26 → 28 not taken.
11140 if (qscale)
747 11140 h->c.chroma_qscale = h->c.qscale = qscale;
748 }
749
750
1/2
✓ Branch 28 → 29 taken 11140 times.
✗ Branch 28 → 31 not taken.
11140 if (ctx->shape == RECT_SHAPE)
751 11140 header_extension = get_bits1(&h->gb);
752
753
1/2
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 55 taken 11140 times.
11140 if (header_extension) {
754
0/2
✗ Branch 34 → 33 not taken.
✗ Branch 34 → 35 not taken.
✗ while (get_bits1(&h->gb) != 0)
755 ;
756
757 ✗ check_marker(h->c.avctx, &h->gb, "before time_increment in video packed header");
758 ✗ skip_bits(&h->gb, ctx->time_increment_bits); /* time_increment */
759 ✗ check_marker(h->c.avctx, &h->gb, "before vop_coding_type in video packed header");
760
761 ✗ skip_bits(&h->gb, 2); /* vop coding type */
762 // FIXME not rect stuff here
763
764
0/2
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 55 not taken.
✗ if (ctx->shape != BIN_ONLY_SHAPE) {
765 ✗ skip_bits(&h->gb, 3); /* intra dc vlc threshold */
766 // FIXME don't just ignore everything
767
0/2
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 47 not taken.
✗ if (h->c.pict_type == AV_PICTURE_TYPE_S &&
768
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 47 not taken.
✗ ctx->vol_sprite_usage == GMC_SPRITE) {
769
0/2
✗ Branch 44 → 45 not taken.
✗ Branch 44 → 46 not taken.
✗ if (mpeg4_decode_sprite_trajectory(ctx, &h->gb) < 0)
770 ✗ return AVERROR_INVALIDDATA;
771 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "untested\n");
772 }
773
774 // FIXME reduced res stuff here
775
776
0/2
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 51 not taken.
✗ if (h->c.pict_type != AV_PICTURE_TYPE_I) {
777 ✗ int f_code = get_bits(&h->gb, 3); /* fcode_for */
778
0/2
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 51 not taken.
✗ if (f_code == 0)
779 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
780 "Error, video packet header damaged (f_code=0)\n");
781 }
782
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 55 not taken.
✗ if (h->c.pict_type == AV_PICTURE_TYPE_B) {
783 ✗ int b_code = get_bits(&h->gb, 3);
784
0/2
✗ Branch 53 → 54 not taken.
✗ Branch 53 → 55 not taken.
✗ if (b_code == 0)
785 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
786 "Error, video packet header damaged (b_code=0)\n");
787 }
788 }
789 }
790
1/2
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 57 taken 11140 times.
11140 if (ctx->new_pred)
791 ✗ decode_new_pred(ctx, &h->gb);
792
793 11140 return 0;
794 }
795
796 30 static void reset_studio_dc_predictors(Mpeg4DecContext *const ctx)
797 {
798 30 H263DecContext *const h = &ctx->h;
799 /* Reset DC Predictors */
800 30 h->last_dc[0] =
801 30 h->last_dc[1] =
802 30 h->last_dc[2] = 1 << (h->c.avctx->bits_per_raw_sample + ctx->dct_precision + h->c.intra_dc_precision - 1);
803 30 }
804
805 /**
806 * Decode the next video packet.
807 * @return <0 if something went wrong
808 */
809 30 int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
810 {
811 30 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
812 30 GetBitContext *gb = &h->gb;
813 unsigned vlc_len;
814 uint16_t mb_num;
815
816
2/4
✓ Branch 4 → 5 taken 30 times.
✗ Branch 4 → 23 not taken.
✓ Branch 6 → 7 taken 30 times.
✗ Branch 6 → 23 not taken.
30 if (get_bits_left(gb) >= 32 && get_bits_long(gb, 32) == SLICE_STARTCODE) {
817 30 vlc_len = av_log2(h->c.mb_width * h->c.mb_height) + 1;
818 30 mb_num = get_bits(gb, vlc_len);
819
820
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 30 times.
30 if (mb_num >= h->c.mb_num)
821 ✗ return AVERROR_INVALIDDATA;
822
823 30 h->c.mb_x = mb_num % h->c.mb_width;
824 30 h->c.mb_y = mb_num / h->c.mb_width;
825
826
1/2
✓ Branch 10 → 11 taken 30 times.
✗ Branch 10 → 13 not taken.
30 if (ctx->shape != BIN_ONLY_SHAPE)
827 30 h->c.qscale = mpeg_get_qscale(&h->gb, h->c.q_scale_type);
828
829
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 22 taken 30 times.
30 if (get_bits1(gb)) { /* slice_extension_flag */
830 ✗ skip_bits1(gb); /* intra_slice */
831 ✗ skip_bits1(gb); /* slice_VOP_id_enable */
832 ✗ skip_bits(gb, 6); /* slice_VOP_id */
833
0/2
✗ Branch 21 → 19 not taken.
✗ Branch 21 → 22 not taken.
✗ while (get_bits1(gb)) /* extra_bit_slice */
834 ✗ skip_bits(gb, 8); /* extra_information_slice */
835 }
836
837 30 reset_studio_dc_predictors(ctx);
838 }
839 else {
840 ✗ return AVERROR_INVALIDDATA;
841 }
842
843 30 return 0;
844 }
845
846 /**
847 * Get the average motion vector for a GMC MB.
848 * @param n either 0 for the x component or 1 for y
849 * @return the average MV for a GMC MB
850 */
851 ✗ static inline int get_amv(Mpeg4DecContext *ctx, int n)
852 {
853 ✗ MPVContext *const s = &ctx->h.c;
854 int x, y, mb_v, sum, dx, dy, shift;
855 ✗ int len = 1 << (ctx->f_code + 4);
856 ✗ const int a = ctx->sprite_warping_accuracy;
857
858
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (s->workaround_bugs & FF_BUG_AMV)
859 ✗ len >>= s->quarter_sample;
860
861
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 13 not taken.
✗ if (ctx->real_sprite_warping_points == 1) {
862
0/6
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 9 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 9 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 9 not taken.
✗ if (ctx->divx_version == 500 && ctx->divx_build == 413 && a >= s->quarter_sample)
863 ✗ sum = ctx->sprite_offset[0][n] / (1 << (a - s->quarter_sample));
864 else
865
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ sum = RSHIFT(ctx->sprite_offset[0][n] * (1 << s->quarter_sample), a);
866 } else {
867 ✗ dx = ctx->sprite_delta[n][0];
868 ✗ dy = ctx->sprite_delta[n][1];
869 ✗ shift = ctx->sprite_shift[0];
870
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ if (n)
871 ✗ dy -= 1 << (shift + a + 1);
872 else
873 ✗ dx -= 1 << (shift + a + 1);
874 ✗ mb_v = ctx->sprite_offset[0][n] + dx * s->mb_x * 16U + dy * s->mb_y * 16U;
875
876 ✗ sum = 0;
877
0/2
✗ Branch 21 → 17 not taken.
✗ Branch 21 → 22 not taken.
✗ for (y = 0; y < 16; y++) {
878 int v;
879
880 ✗ v = mb_v + (unsigned)dy * y;
881 // FIXME optimize
882
0/2
✗ Branch 19 → 18 not taken.
✗ Branch 19 → 20 not taken.
✗ for (x = 0; x < 16; x++) {
883 ✗ sum += v >> shift;
884 ✗ v += dx;
885 }
886 }
887
0/2
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ sum = RSHIFT(sum, a + 8 - s->quarter_sample);
888 }
889
890
0/2
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 27 not taken.
✗ if (sum < -len)
891 ✗ sum = -len;
892
0/2
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
✗ else if (sum >= len)
893 ✗ sum = len - 1;
894
895 ✗ return sum;
896 }
897
898 /**
899 * Predict the dc.
900 * @param n block index (0-3 are luma, 4-5 are chroma)
901 * @param dir_ptr pointer to an integer where the prediction direction will be stored
902 */
903 1162200 static inline int mpeg4_pred_dc(MpegEncContext *s, int n, int *dir_ptr)
904 {
905 1162200 const int16_t *const dc_val = s->dc_val + s->block_index[n];
906 1162200 const int wrap = s->block_wrap[n];
907 int pred;
908
909 /* find prediction */
910
911 /* B C
912 * A X
913 */
914 1162200 int a = dc_val[-1];
915 1162200 int b = dc_val[-1 - wrap];
916 1162200 int c = dc_val[-wrap];
917
918 /* outside slice handling (we can't do that by memset as we need the
919 * dc for error resilience) */
920
4/4
✓ Branch 2 → 3 taken 152580 times.
✓ Branch 2 → 9 taken 1009620 times.
✓ Branch 3 → 4 taken 127150 times.
✓ Branch 3 → 9 taken 25430 times.
1162200 if (s->first_slice_line && n != 3) {
921
2/2
✓ Branch 4 → 5 taken 101720 times.
✓ Branch 4 → 6 taken 25430 times.
127150 if (n != 2)
922 101720 b = c = 1024;
923
4/4
✓ Branch 6 → 7 taken 101720 times.
✓ Branch 6 → 9 taken 25430 times.
✓ Branch 7 → 8 taken 6828 times.
✓ Branch 7 → 9 taken 94892 times.
127150 if (n != 1 && s->mb_x == s->resync_mb_x)
924 6828 b = a = 1024;
925 }
926
4/4
✓ Branch 9 → 10 taken 49920 times.
✓ Branch 9 → 15 taken 1112280 times.
✓ Branch 10 → 11 taken 6336 times.
✓ Branch 10 → 15 taken 43584 times.
1162200 if (s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y + 1) {
927
6/6
✓ Branch 11 → 12 taken 5280 times.
✓ Branch 11 → 14 taken 1056 times.
✓ Branch 12 → 13 taken 4224 times.
✓ Branch 12 → 14 taken 1056 times.
✓ Branch 13 → 14 taken 1056 times.
✓ Branch 13 → 15 taken 3168 times.
6336 if (n == 0 || n == 4 || n == 5)
928 3168 b = 1024;
929 }
930
931
2/2
✓ Branch 15 → 16 taken 441889 times.
✓ Branch 15 → 17 taken 720311 times.
1162200 if (abs(a - b) < abs(b - c)) {
932 441889 pred = c;
933 441889 *dir_ptr = 1; /* top */
934 } else {
935 720311 pred = a;
936 720311 *dir_ptr = 0; /* left */
937 }
938 1162200 return pred;
939 }
940
941 1162200 static inline int mpeg4_get_level_dc(MpegEncContext *s, int n, int pred, int level)
942 {
943
2/2
✓ Branch 2 → 3 taken 774800 times.
✓ Branch 2 → 4 taken 387400 times.
1162200 int scale = n < 4 ? s->y_dc_scale : s->c_dc_scale;
944 int ret;
945
946 if (IS_3IV1)
947 scale = 8;
948
949 /* we assume pred is positive */
950 1162200 pred = FASTDIV((pred + (scale >> 1)), scale);
951
952 1162200 level += pred;
953 1162200 ret = level;
954 1162200 level *= scale;
955
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 17 taken 1162200 times.
1162200 if (level & (~2047)) {
956
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 13 not taken.
✗ if (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) {
957
0/2
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 10 not taken.
✗ if (level < 0) {
958 ✗ av_log(s->avctx, AV_LOG_ERROR,
959 "dc<0 at %dx%d\n", s->mb_x, s->mb_y);
960 ✗ return AVERROR_INVALIDDATA;
961 }
962
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 13 not taken.
✗ if (level > 2048 + scale) {
963 ✗ av_log(s->avctx, AV_LOG_ERROR,
964 "dc overflow at %dx%d\n", s->mb_x, s->mb_y);
965 ✗ return AVERROR_INVALIDDATA;
966 }
967 }
968
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ if (level < 0)
969 ✗ level = 0;
970
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
✗ else if (!(s->workaround_bugs & FF_BUG_DC_CLIP))
971 ✗ level = 2047;
972 }
973 1162200 s->dc_val[s->block_index[n]] = level;
974
975 1162200 return ret;
976 }
977
978 /**
979 * Decode the dc value.
980 * @param n block index (0-3 are luma, 4-5 are chroma)
981 * @param dir_ptr the prediction direction will be stored here
982 * @return the quantized dc
983 */
984 1162200 static inline int mpeg4_decode_dc(H263DecContext *const h, int n, int *dir_ptr)
985 {
986 int level, code, pred;
987
988
2/2
✓ Branch 2 → 3 taken 774800 times.
✓ Branch 2 → 4 taken 387400 times.
1162200 if (n < 4)
989 774800 code = get_vlc2(&h->gb, dc_lum, DC_VLC_BITS, 1);
990 else
991 387400 code = get_vlc2(&h->gb, dc_chrom, DC_VLC_BITS, 1);
992
993
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 1162200 times.
1162200 if (code < 0) {
994 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
995 ✗ return AVERROR_INVALIDDATA;
996 }
997
998
2/2
✓ Branch 8 → 9 taken 192419 times.
✓ Branch 8 → 10 taken 969781 times.
1162200 if (code == 0) {
999 192419 level = 0;
1000 } else {
1001 if (IS_3IV1) {
1002 if (code == 1)
1003 level = 2 * get_bits1(&h->gb) - 1;
1004 else {
1005 if (get_bits1(&h->gb))
1006 level = get_bits(&h->gb, code - 1) + (1 << (code - 1));
1007 else
1008 level = -get_bits(&h->gb, code - 1) - (1 << (code - 1));
1009 }
1010 } else {
1011 969781 level = get_xbits(&h->gb, code);
1012 }
1013
1014
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 17 taken 969781 times.
969781 if (code > 8) {
1015
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 17 not taken.
✗ if (get_bits1(&h->gb) == 0) { /* marker */
1016
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 17 not taken.
✗ if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {
1017 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "dc marker bit missing\n");
1018 ✗ return AVERROR_INVALIDDATA;
1019 }
1020 }
1021 }
1022 }
1023
1024 1162200 pred = mpeg4_pred_dc(&h->c, n, dir_ptr);
1025 1162200 return mpeg4_get_level_dc(&h->c, n, pred, level);
1026 }
1027
1028 /**
1029 * Decode first partition.
1030 * @return number of MBs decoded or <0 if an error occurred
1031 */
1032 1729 static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
1033 {
1034 1729 H263DecContext *const h = &ctx->h;
1035 1729 int mb_num = 0;
1036 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1037
1038 /* decode first partition */
1039 1729 h->c.first_slice_line = 1;
1040
2/2
✓ Branch 91 → 3 taken 7873 times.
✓ Branch 91 → 92 taken 472 times.
8345 for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) {
1041 7873 ff_init_block_index(&h->c);
1042
2/2
✓ Branch 89 → 5 taken 140029 times.
✓ Branch 89 → 90 taken 6616 times.
146645 for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
1043 140029 const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
1044 int cbpc;
1045 140029 int dir = 0;
1046
1047 140029 mb_num++;
1048 140029 ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
1049
4/4
✓ Branch 6 → 7 taken 7424 times.
✓ Branch 6 → 9 taken 132605 times.
✓ Branch 7 → 8 taken 1618 times.
✓ Branch 7 → 9 taken 5806 times.
140029 if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1)
1050 1618 h->c.first_slice_line = 0;
1051
1052
2/2
✓ Branch 9 → 10 taken 17860 times.
✓ Branch 9 → 33 taken 122169 times.
140029 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
1053 int i;
1054
1055 do {
1056
2/2
✓ Branch 12 → 13 taken 439 times.
✓ Branch 12 → 14 taken 17421 times.
17860 if (show_bits(&h->gb, 19) == DC_MARKER)
1057 439 return mb_num - 1;
1058
1059 17421 cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
1060
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 18 taken 17421 times.
17421 if (cbpc < 0) {
1061 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1062 "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
1063 ✗ return AVERROR_INVALIDDATA;
1064 }
1065
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 17421 times.
17421 } while (cbpc == 8);
1066
1067 17421 h->c.cbp_table[xy] = cbpc & 3;
1068 17421 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1069 17421 h->c.mb_intra = 1;
1070
1071
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 23 taken 17421 times.
17421 if (cbpc & 4)
1072 ✗ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
1073
1074 17421 h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1075
1076 17421 h->c.mbintra_table[xy] = 1;
1077
2/2
✓ Branch 31 → 24 taken 104526 times.
✓ Branch 31 → 32 taken 17421 times.
121947 for (i = 0; i < 6; i++) {
1078 int dc_pred_dir;
1079 104526 int dc = mpeg4_decode_dc(h, i, &dc_pred_dir);
1080
1/2
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 28 taken 104526 times.
104526 if (dc < 0) {
1081 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1082 "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
1083 ✗ return dc;
1084 }
1085 104526 dir <<= 1;
1086
2/2
✓ Branch 28 → 29 taken 30362 times.
✓ Branch 28 → 30 taken 74164 times.
104526 if (dc_pred_dir)
1087 30362 dir |= 1;
1088 }
1089 17421 h->c.pred_dir_table[xy] = dir;
1090 } else { /* P/S_TYPE */
1091 int mx, my, pred_x, pred_y, bits;
1092 122169 int16_t *const mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
1093 122169 const int stride = h->c.b8_stride * 2;
1094
1095 122169 try_again:
1096 122169 bits = show_bits(&h->gb, 17);
1097
2/2
✓ Branch 35 → 36 taken 818 times.
✓ Branch 35 → 37 taken 121351 times.
122169 if (bits == MOTION_MARKER)
1098 818 return mb_num - 1;
1099
1100 121351 skip_bits1(&h->gb);
1101
2/2
✓ Branch 38 → 39 taken 1001 times.
✓ Branch 38 → 46 taken 120350 times.
121351 if (bits & 0x10000) {
1102 /* skip mb */
1103
1/2
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 43 taken 1001 times.
1001 if (h->c.pict_type == AV_PICTURE_TYPE_S &&
1104
0/2
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 43 not taken.
✗ ctx->vol_sprite_usage == GMC_SPRITE) {
1105 ✗ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
1106 MB_TYPE_16x16 |
1107 MB_TYPE_GMC |
1108 MB_TYPE_FORWARD_MV;
1109 ✗ mx = get_amv(ctx, 0);
1110 ✗ my = get_amv(ctx, 1);
1111 } else {
1112 1001 h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
1113 MB_TYPE_16x16 |
1114 MB_TYPE_FORWARD_MV;
1115 1001 mx = my = 0;
1116 }
1117 1001 mot_val[0] =
1118 1001 mot_val[2] =
1119 1001 mot_val[0 + stride] =
1120 1001 mot_val[2 + stride] = mx;
1121 1001 mot_val[1] =
1122 1001 mot_val[3] =
1123 1001 mot_val[1 + stride] =
1124 1001 mot_val[3 + stride] = my;
1125
1126 1001 ff_h263_clean_intra_table_entries(&h->c, xy);
1127 1001 continue;
1128 }
1129
1130 120350 cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
1131
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 50 taken 120350 times.
120350 if (cbpc < 0) {
1132 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1133 "mcbpc corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
1134 ✗ return AVERROR_INVALIDDATA;
1135 }
1136
1/2
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 52 taken 120350 times.
120350 if (cbpc == 20)
1137 ✗ goto try_again;
1138
1139 120350 h->c.cbp_table[xy] = cbpc & (8 + 3); // 8 is dquant
1140
1141 120350 h->c.mb_intra = ((cbpc & 4) != 0);
1142
1143
2/2
✓ Branch 52 → 53 taken 6371 times.
✓ Branch 52 → 54 taken 113979 times.
120350 if (h->c.mb_intra) {
1144 6371 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1145 6371 h->c.mbintra_table[xy] = 1;
1146 6371 mot_val[0] =
1147 6371 mot_val[2] =
1148 6371 mot_val[0 + stride] =
1149 6371 mot_val[2 + stride] = 0;
1150 6371 mot_val[1] =
1151 6371 mot_val[3] =
1152 6371 mot_val[1 + stride] =
1153 6371 mot_val[3 + stride] = 0;
1154 } else {
1155 113979 ff_h263_clean_intra_table_entries(&h->c, xy);
1156
1157
1/2
✗ Branch 55 → 56 not taken.
✓ Branch 55 → 60 taken 113979 times.
113979 if (h->c.pict_type == AV_PICTURE_TYPE_S &&
1158
0/2
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 60 not taken.
✗ ctx->vol_sprite_usage == GMC_SPRITE &&
1159
0/2
✗ Branch 57 → 58 not taken.
✗ Branch 57 → 60 not taken.
✗ (cbpc & 16) == 0)
1160 ✗ h->c.mcsel = get_bits1(&h->gb);
1161 else
1162 113979 h->c.mcsel = 0;
1163
1164
2/2
✓ Branch 61 → 62 taken 81941 times.
✓ Branch 61 → 75 taken 32038 times.
113979 if ((cbpc & 16) == 0) {
1165 /* 16x16 motion prediction */
1166
1167 81941 ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
1168
1/2
✓ Branch 63 → 64 taken 81941 times.
✗ Branch 63 → 71 not taken.
81941 if (!h->c.mcsel) {
1169 81941 mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
1170
1/2
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 67 taken 81941 times.
81941 if (mx >= 0xffff)
1171 ✗ return AVERROR_INVALIDDATA;
1172
1173 81941 my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
1174
1/2
✗ Branch 68 → 69 not taken.
✓ Branch 68 → 70 taken 81941 times.
81941 if (my >= 0xffff)
1175 ✗ return AVERROR_INVALIDDATA;
1176 81941 h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 |
1177 MB_TYPE_FORWARD_MV;
1178 } else {
1179 ✗ mx = get_amv(ctx, 0);
1180 ✗ my = get_amv(ctx, 1);
1181 ✗ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 |
1182 MB_TYPE_GMC |
1183 MB_TYPE_FORWARD_MV;
1184 }
1185
1186 81941 mot_val[0] =
1187 81941 mot_val[2] =
1188 81941 mot_val[0 + stride] =
1189 81941 mot_val[2 + stride] = mx;
1190 81941 mot_val[1] =
1191 81941 mot_val[3] =
1192 81941 mot_val[1 + stride] =
1193 81941 mot_val[3 + stride] = my;
1194 } else {
1195 int i;
1196 32038 h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 |
1197 MB_TYPE_FORWARD_MV;
1198
2/2
✓ Branch 84 → 76 taken 128152 times.
✓ Branch 84 → 85 taken 32038 times.
160190 for (i = 0; i < 4; i++) {
1199 128152 int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
1200 128152 mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
1201
1/2
✗ Branch 78 → 79 not taken.
✓ Branch 78 → 80 taken 128152 times.
128152 if (mx >= 0xffff)
1202 ✗ return AVERROR_INVALIDDATA;
1203
1204 128152 my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
1205
1/2
✗ Branch 81 → 82 not taken.
✓ Branch 81 → 83 taken 128152 times.
128152 if (my >= 0xffff)
1206 ✗ return AVERROR_INVALIDDATA;
1207 128152 mot_val[0] = mx;
1208 128152 mot_val[1] = my;
1209 }
1210 }
1211 }
1212 }
1213 }
1214 6616 h->c.mb_x = 0;
1215 }
1216
1217 472 return mb_num;
1218 }
1219
1220 /**
1221 * decode second partition.
1222 * @return <0 if an error occurred
1223 */
1224 1729 static int mpeg4_decode_partition_b(H263DecContext *const h, int mb_count)
1225 {
1226 1729 int mb_num = 0;
1227 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1228
1229 1729 h->c.mb_x = h->c.resync_mb_x;
1230 1729 h->c.first_slice_line = 1;
1231
1/2
✓ Branch 51 → 3 taken 7754 times.
✗ Branch 51 → 52 not taken.
7754 for (h->c.mb_y = h->c.resync_mb_y; mb_num < mb_count; h->c.mb_y++) {
1232 7754 ff_init_block_index(&h->c);
1233
4/4
✓ Branch 46 → 47 taken 144797 times.
✓ Branch 46 → 48 taken 1729 times.
✓ Branch 47 → 5 taken 138772 times.
✓ Branch 47 → 48 taken 6025 times.
146526 for (; mb_num < mb_count && h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
1234 138772 const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
1235
1236 138772 mb_num++;
1237 138772 ff_update_block_index(&h->c, 8, h->c.avctx->lowres, 1);
1238
4/4
✓ Branch 6 → 7 taken 7358 times.
✓ Branch 6 → 9 taken 131414 times.
✓ Branch 7 → 8 taken 1617 times.
✓ Branch 7 → 9 taken 5741 times.
138772 if (h->c.mb_x == h->c.resync_mb_x && h->c.mb_y == h->c.resync_mb_y + 1)
1239 1617 h->c.first_slice_line = 0;
1240
1241
2/2
✓ Branch 9 → 10 taken 17421 times.
✓ Branch 9 → 16 taken 121351 times.
138772 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
1242 17421 int ac_pred = get_bits1(&h->gb);
1243 17421 int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1244
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 15 taken 17421 times.
17421 if (cbpy < 0) {
1245 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1246 "cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
1247 ✗ return AVERROR_INVALIDDATA;
1248 }
1249
1250 17421 h->c.cbp_table[xy] |= cbpy << 2;
1251 17421 h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
1252 } else { /* P || S_TYPE */
1253
2/2
✓ Branch 16 → 17 taken 6371 times.
✓ Branch 16 → 35 taken 114980 times.
121351 if (IS_INTRA(h->c.cur_pic.mb_type[xy])) {
1254 int i;
1255 6371 int dir = 0;
1256 6371 int ac_pred = get_bits1(&h->gb);
1257 6371 int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1258
1259
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 6371 times.
6371 if (cbpy < 0) {
1260 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1261 "I cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
1262 ✗ return AVERROR_INVALIDDATA;
1263 }
1264
1265
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 25 taken 6371 times.
6371 if (h->c.cbp_table[xy] & 8)
1266 ✗ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
1267 6371 h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1268
1269
2/2
✓ Branch 33 → 26 taken 38226 times.
✓ Branch 33 → 34 taken 6371 times.
44597 for (i = 0; i < 6; i++) {
1270 int dc_pred_dir;
1271 38226 int dc = mpeg4_decode_dc(h, i, &dc_pred_dir);
1272
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 30 taken 38226 times.
38226 if (dc < 0) {
1273 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1274 "DC corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
1275 ✗ return dc;
1276 }
1277 38226 dir <<= 1;
1278
2/2
✓ Branch 30 → 31 taken 12086 times.
✓ Branch 30 → 32 taken 26140 times.
38226 if (dc_pred_dir)
1279 12086 dir |= 1;
1280 }
1281 6371 h->c.cbp_table[xy] &= 3; // remove dquant
1282 6371 h->c.cbp_table[xy] |= cbpy << 2;
1283 6371 h->c.cur_pic.mb_type[xy] |= ac_pred * MB_TYPE_ACPRED;
1284 6371 h->c.pred_dir_table[xy] = dir;
1285
2/2
✓ Branch 35 → 36 taken 1001 times.
✓ Branch 35 → 37 taken 113979 times.
114980 } else if (IS_SKIP(h->c.cur_pic.mb_type[xy])) {
1286 1001 h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1287 1001 h->c.cbp_table[xy] = 0;
1288 } else {
1289 113979 int cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1290
1291
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 41 taken 113979 times.
113979 if (cbpy < 0) {
1292 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1293 "P cbpy corrupted at %d %d\n", h->c.mb_x, h->c.mb_y);
1294 ✗ return AVERROR_INVALIDDATA;
1295 }
1296
1297
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 44 taken 113979 times.
113979 if (h->c.cbp_table[xy] & 8)
1298 ✗ ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
1299 113979 h->c.cur_pic.qscale_table[xy] = h->c.qscale;
1300
1301 113979 h->c.cbp_table[xy] &= 3; // remove dquant
1302 113979 h->c.cbp_table[xy] |= (cbpy ^ 0xf) << 2;
1303 }
1304 }
1305 }
1306
2/2
✓ Branch 48 → 49 taken 1729 times.
✓ Branch 48 → 50 taken 6025 times.
7754 if (mb_num >= mb_count)
1307 1729 return 0;
1308 6025 h->c.mb_x = 0;
1309 }
1310 ✗ return 0;
1311 }
1312
1313 /**
1314 * Decode the first and second partition.
1315 * @return <0 if error (and sets error type in the error_status_table)
1316 */
1317 1729 int ff_mpeg4_decode_partitions(H263DecContext *const h)
1318 {
1319 1729 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
1320 int mb_num;
1321 int ret;
1322
2/2
✓ Branch 3 → 4 taken 499 times.
✓ Branch 3 → 5 taken 1230 times.
1729 const int part_a_error = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_ERROR | ER_MV_ERROR) : ER_MV_ERROR;
1323
2/2
✓ Branch 6 → 7 taken 499 times.
✓ Branch 6 → 8 taken 1230 times.
1729 const int part_a_end = h->c.pict_type == AV_PICTURE_TYPE_I ? (ER_DC_END | ER_MV_END) : ER_MV_END;
1324
1325 1729 mb_num = mpeg4_decode_partition_a(ctx);
1326
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 16 taken 1729 times.
1729 if (mb_num <= 0) {
1327 ✗ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1328 h->c.mb_x, h->c.mb_y, part_a_error);
1329
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ return mb_num ? mb_num : AVERROR_INVALIDDATA;
1330 }
1331
1332
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 20 taken 1729 times.
1729 if (h->c.resync_mb_x + h->c.resync_mb_y * h->c.mb_width + mb_num > h->c.mb_num) {
1333 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "slice below monitor ...\n");
1334 ✗ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1335 h->c.mb_x, h->c.mb_y, part_a_error);
1336 ✗ return AVERROR_INVALIDDATA;
1337 }
1338
1339 1729 h->mb_num_left = mb_num;
1340
1341
2/2
✓ Branch 20 → 21 taken 499 times.
✓ Branch 20 → 29 taken 1230 times.
1729 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
1342
1/2
✗ Branch 24 → 22 not taken.
✓ Branch 24 → 25 taken 499 times.
499 while (show_bits(&h->gb, 9) == 1)
1343 ✗ skip_bits(&h->gb, 9);
1344
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 37 taken 499 times.
499 if (get_bits(&h->gb, 19) != DC_MARKER) {
1345 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1346 "marker missing after first I partition at %d %d\n",
1347 h->c.mb_x, h->c.mb_y);
1348 ✗ return AVERROR_INVALIDDATA;
1349 }
1350 } else {
1351
1/2
✗ Branch 32 → 30 not taken.
✓ Branch 32 → 33 taken 1230 times.
1230 while (show_bits(&h->gb, 10) == 1)
1352 ✗ skip_bits(&h->gb, 10);
1353
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 37 taken 1230 times.
1230 if (get_bits(&h->gb, 17) != MOTION_MARKER) {
1354 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1355 "marker missing after first P partition at %d %d\n",
1356 h->c.mb_x, h->c.mb_y);
1357 ✗ return AVERROR_INVALIDDATA;
1358 }
1359 }
1360 1729 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1361 1729 h->c.mb_x - 1, h->c.mb_y, part_a_end);
1362
1363 1729 ret = mpeg4_decode_partition_b(h, mb_num);
1364
1/2
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 43 taken 1729 times.
1729 if (ret < 0) {
1365
0/2
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 42 not taken.
✗ if (h->c.pict_type == AV_PICTURE_TYPE_P)
1366 ✗ ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1367 h->c.mb_x, h->c.mb_y, ER_DC_ERROR);
1368 ✗ return ret;
1369 } else {
1370
2/2
✓ Branch 43 → 44 taken 1230 times.
✓ Branch 43 → 45 taken 499 times.
1729 if (h->c.pict_type == AV_PICTURE_TYPE_P)
1371 1230 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
1372 1230 h->c.mb_x - 1, h->c.mb_y, ER_DC_END);
1373 }
1374
1375 1729 return 0;
1376 }
1377
1378 /**
1379 * Decode a block.
1380 * @return <0 if an error occurred
1381 */
1382 8400924 static inline int mpeg4_decode_block(Mpeg4DecContext *ctx, int16_t *block,
1383 int n, int coded, int intra,
1384 int use_intra_dc_vlc, int rvlc)
1385 {
1386 8400924 H263DecContext *const h = &ctx->h;
1387 int level, i, last, run, qmul, qadd, pred;
1388 8400924 int av_uninit(dc_pred_dir);
1389 const RLTable *rl;
1390 const RL_VLC_ELEM *rl_vlc;
1391 const uint8_t *scan_table;
1392
1393 // Note intra & rvlc should be optimized away if this is inlined
1394
1395
2/2
✓ Branch 2 → 3 taken 1162200 times.
✓ Branch 2 → 25 taken 7238724 times.
8400924 if (intra) {
1396 // FIXME add short header support
1397
1/2
✓ Branch 3 → 4 taken 1162200 times.
✗ Branch 3 → 13 not taken.
1162200 if (use_intra_dc_vlc) {
1398 /* DC coef */
1399
2/2
✓ Branch 4 → 5 taken 142752 times.
✓ Branch 4 → 9 taken 1019448 times.
1162200 if (h->partitioned_frame) {
1400 142752 level = h->c.dc_val[h->c.block_index[n]];
1401
2/2
✓ Branch 5 → 6 taken 95168 times.
✓ Branch 5 → 7 taken 47584 times.
142752 if (n < 4)
1402 95168 level = FASTDIV((level + (h->c.y_dc_scale >> 1)), h->c.y_dc_scale);
1403 else
1404 47584 level = FASTDIV((level + (h->c.c_dc_scale >> 1)), h->c.c_dc_scale);
1405 142752 dc_pred_dir = (h->c.pred_dir_table[h->c.mb_x + h->c.mb_y * h->c.mb_stride] << n) & 32;
1406 } else {
1407 1019448 level = mpeg4_decode_dc(h, n, &dc_pred_dir);
1408
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 1019448 times.
1019448 if (level < 0)
1409 ✗ return level;
1410 }
1411 1162200 block[0] = level;
1412 1162200 i = 0;
1413 } else {
1414 ✗ i = -1;
1415 ✗ pred = mpeg4_pred_dc(&h->c, n, &dc_pred_dir);
1416 }
1417
2/2
✓ Branch 14 → 15 taken 258786 times.
✓ Branch 14 → 16 taken 903414 times.
1162200 if (!coded)
1418 258786 goto not_coded;
1419
1420
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 903414 times.
903414 if (rvlc) {
1421 ✗ rl = &ff_rvlc_rl_intra;
1422 ✗ rl_vlc = ff_rvlc_rl_intra.rl_vlc[0];
1423 } else {
1424 903414 rl = &ff_mpeg4_rl_intra;
1425 903414 rl_vlc = ff_mpeg4_rl_intra.rl_vlc[0];
1426 }
1427
2/2
✓ Branch 19 → 20 taken 22006 times.
✓ Branch 19 → 23 taken 881408 times.
903414 if (h->c.ac_pred) {
1428
2/2
✓ Branch 20 → 21 taken 15508 times.
✓ Branch 20 → 22 taken 6498 times.
22006 if (dc_pred_dir == 0)
1429 15508 scan_table = h->permutated_intra_v_scantable; /* left */
1430 else
1431 6498 scan_table = h->permutated_intra_h_scantable; /* top */
1432 } else {
1433 881408 scan_table = h->c.intra_scantable.permutated;
1434 }
1435 903414 qmul = 1;
1436 903414 qadd = 0;
1437 } else {
1438 7238724 i = -1;
1439
2/2
✓ Branch 25 → 26 taken 4847616 times.
✓ Branch 25 → 27 taken 2391108 times.
7238724 if (!coded) {
1440 4847616 h->c.block_last_index[n] = i;
1441 4847616 return 0;
1442 }
1443
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 2391108 times.
2391108 if (rvlc)
1444 ✗ rl = &ff_rvlc_rl_inter;
1445 else
1446 2391108 rl = &ff_h263_rl_inter;
1447
1448 2391108 scan_table = h->c.intra_scantable.permutated;
1449
1450
2/2
✓ Branch 30 → 31 taken 113069 times.
✓ Branch 30 → 34 taken 2278039 times.
2391108 if (ctx->mpeg_quant) {
1451 113069 qmul = 1;
1452 113069 qadd = 0;
1453
1/2
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 113069 times.
113069 if (rvlc)
1454 ✗ rl_vlc = ff_rvlc_rl_inter.rl_vlc[0];
1455 else
1456 113069 rl_vlc = ff_h263_rl_inter.rl_vlc[0];
1457 } else {
1458 2278039 qmul = h->c.qscale << 1;
1459 2278039 qadd = (h->c.qscale - 1) | 1;
1460
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 2278039 times.
2278039 if (rvlc)
1461 ✗ rl_vlc = ff_rvlc_rl_inter.rl_vlc[h->c.qscale];
1462 else
1463 2278039 rl_vlc = ff_h263_rl_inter.rl_vlc[h->c.qscale];
1464 }
1465 }
1466 {
1467 3294522 OPEN_READER(re, &h->gb);
1468 for (;;) {
1469 28930476 UPDATE_CACHE(re, &h->gb);
1470
2/2
✓ Branch 39 → 40 taken 1243173 times.
✓ Branch 39 → 42 taken 27687303 times.
28930476 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
1471
2/2
✓ Branch 42 → 43 taken 801569 times.
✓ Branch 42 → 110 taken 28128907 times.
28930476 if (level == 0) {
1472 /* escape */
1473
1/2
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 63 taken 801569 times.
801569 if (rvlc) {
1474
0/2
✗ Branch 45 → 46 not taken.
✗ Branch 45 → 48 not taken.
✗ if (SHOW_UBITS(re, &h->gb, 1) == 0) {
1475 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1476 "1. marker bit missing in rvlc esc\n");
1477 ✗ return AVERROR_INVALIDDATA;
1478 }
1479 ✗ SKIP_CACHE(re, &h->gb, 1);
1480
1481 ✗ last = SHOW_UBITS(re, &h->gb, 1);
1482 ✗ SKIP_CACHE(re, &h->gb, 1);
1483 ✗ run = SHOW_UBITS(re, &h->gb, 6);
1484 ✗ SKIP_COUNTER(re, &h->gb, 1 + 1 + 6);
1485 ✗ UPDATE_CACHE(re, &h->gb);
1486
1487
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 54 not taken.
✗ if (SHOW_UBITS(re, &h->gb, 1) == 0) {
1488 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1489 "2. marker bit missing in rvlc esc\n");
1490 ✗ return AVERROR_INVALIDDATA;
1491 }
1492 ✗ SKIP_CACHE(re, &h->gb, 1);
1493
1494 ✗ level = SHOW_UBITS(re, &h->gb, 11);
1495 ✗ SKIP_CACHE(re, &h->gb, 11);
1496
1497
0/2
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 59 not taken.
✗ if (SHOW_UBITS(re, &h->gb, 5) != 0x10) {
1498 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "reverse esc missing\n");
1499 ✗ return AVERROR_INVALIDDATA;
1500 }
1501 ✗ SKIP_CACHE(re, &h->gb, 5);
1502
1503 ✗ level = level * qmul + qadd;
1504 ✗ level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
1505 ✗ SKIP_COUNTER(re, &h->gb, 1 + 11 + 5 + 1);
1506
1507 ✗ i += run + 1;
1508
0/2
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 113 not taken.
✗ if (last)
1509 ✗ i += 192;
1510 } else {
1511 int cache;
1512 801569 cache = GET_CACHE(re, &h->gb);
1513
1514 if (IS_3IV1)
1515 cache ^= 0xC0000000;
1516
1517
2/2
✓ Branch 63 → 64 taken 359306 times.
✓ Branch 63 → 103 taken 442263 times.
801569 if (cache & 0x80000000) {
1518
2/2
✓ Branch 64 → 65 taken 141165 times.
✓ Branch 64 → 96 taken 218141 times.
359306 if (cache & 0x40000000) {
1519 /* third escape */
1520 141165 SKIP_CACHE(re, &h->gb, 2);
1521 141165 last = SHOW_UBITS(re, &h->gb, 1);
1522 141165 SKIP_CACHE(re, &h->gb, 1);
1523 141165 run = SHOW_UBITS(re, &h->gb, 6);
1524 141165 SKIP_COUNTER(re, &h->gb, 2 + 1 + 6);
1525 141165 UPDATE_CACHE(re, &h->gb);
1526
1527 if (IS_3IV1) {
1528 level = SHOW_SBITS(re, &h->gb, 12);
1529 LAST_SKIP_BITS(re, &h->gb, 12);
1530 } else {
1531
1/2
✗ Branch 68 → 69 not taken.
✓ Branch 68 → 74 taken 141165 times.
141165 if (SHOW_UBITS(re, &h->gb, 1) == 0) {
1532 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1533 "1. marker bit missing in 3. esc\n");
1534
0/4
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 73 not taken.
✗ Branch 72 → 73 not taken.
✗ Branch 72 → 74 not taken.
✗ if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->gb) <= 0)
1535 ✗ return AVERROR_INVALIDDATA;
1536 }
1537 141165 SKIP_CACHE(re, &h->gb, 1);
1538
1539 141165 level = SHOW_SBITS(re, &h->gb, 12);
1540 141165 SKIP_CACHE(re, &h->gb, 12);
1541
1542
1/2
✗ Branch 76 → 77 not taken.
✓ Branch 76 → 82 taken 141165 times.
141165 if (SHOW_UBITS(re, &h->gb, 1) == 0) {
1543 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1544 "2. marker bit missing in 3. esc\n");
1545
0/4
✗ Branch 78 → 79 not taken.
✗ Branch 78 → 81 not taken.
✗ Branch 80 → 81 not taken.
✗ Branch 80 → 82 not taken.
✗ if (!(h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) || get_bits_left(&h->gb) <= 0)
1546 ✗ return AVERROR_INVALIDDATA;
1547 }
1548
1549 141165 SKIP_COUNTER(re, &h->gb, 1 + 12 + 1);
1550 }
1551
1552 #if 0
1553 if (h->c.error_recognition >= FF_ER_COMPLIANT) {
1554 const int abs_level= FFABS(level);
1555 if (abs_level<=MAX_LEVEL && run<=MAX_RUN) {
1556 const int run1= run - rl->max_run[last][abs_level] - 1;
1557 if (abs_level <= rl->max_level[last][run]) {
1558 av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
1559 return AVERROR_INVALIDDATA;
1560 }
1561 if (h->c.error_recognition > FF_ER_COMPLIANT) {
1562 if (abs_level <= rl->max_level[last][run]*2) {
1563 av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
1564 return AVERROR_INVALIDDATA;
1565 }
1566 if (run1 >= 0 && abs_level <= rl->max_level[last][run1]) {
1567 av_log(h->c.avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
1568 return AVERROR_INVALIDDATA;
1569 }
1570 }
1571 }
1572 }
1573 #endif
1574
2/2
✓ Branch 82 → 83 taken 71207 times.
✓ Branch 82 → 84 taken 69958 times.
141165 if (level > 0)
1575 71207 level = level * qmul + qadd;
1576 else
1577 69958 level = level * qmul - qadd;
1578
1579
1/2
✗ Branch 85 → 86 not taken.
✓ Branch 85 → 94 taken 141165 times.
141165 if ((unsigned)(level + 2048) > 4095) {
1580
0/2
✗ Branch 86 → 87 not taken.
✗ Branch 86 → 91 not taken.
✗ if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)) {
1581
0/4
✗ Branch 87 → 88 not taken.
✗ Branch 87 → 89 not taken.
✗ Branch 88 → 89 not taken.
✗ Branch 88 → 91 not taken.
✗ if (level > 2560 || level < -2560) {
1582 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1583 "|level| overflow in 3. esc, qp=%d\n",
1584 h->c.qscale);
1585 ✗ return AVERROR_INVALIDDATA;
1586 }
1587 }
1588
0/2
✗ Branch 91 → 92 not taken.
✗ Branch 91 → 93 not taken.
✗ level = level < 0 ? -2048 : 2047;
1589 }
1590
1591 141165 i += run + 1;
1592
2/2
✓ Branch 94 → 95 taken 45255 times.
✓ Branch 94 → 113 taken 95910 times.
141165 if (last)
1593 45255 i += 192;
1594 } else {
1595 /* second escape */
1596 218141 SKIP_BITS(re, &h->gb, 2);
1597
2/2
✓ Branch 97 → 98 taken 24474 times.
✓ Branch 97 → 100 taken 193667 times.
218141 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
1598 218141 i += run + rl->max_run[run >> 7][level / qmul] + 1; // FIXME opt indexing
1599 218141 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
1600 218141 LAST_SKIP_BITS(re, &h->gb, 1);
1601 }
1602 } else {
1603 /* first escape */
1604 442263 SKIP_BITS(re, &h->gb, 1);
1605
2/2
✓ Branch 104 → 105 taken 68613 times.
✓ Branch 104 → 107 taken 373650 times.
442263 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
1606 442263 i += run;
1607 442263 level = level + rl->max_level[run >> 7][(run - 1) & 63] * qmul; // FIXME opt indexing
1608 442263 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
1609 442263 LAST_SKIP_BITS(re, &h->gb, 1);
1610 }
1611 }
1612 } else {
1613 28128907 i += run;
1614 28128907 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
1615 28128907 LAST_SKIP_BITS(re, &h->gb, 1);
1616 }
1617 ff_tlog(h->c.avctx, "dct[%d][%d] = %- 4d end?:%d\n", scan_table[i&63]&7, scan_table[i&63] >> 3, level, i>62);
1618
2/2
✓ Branch 113 → 114 taken 3294522 times.
✓ Branch 113 → 118 taken 25635954 times.
28930476 if (i > 62) {
1619 3294522 i -= 192;
1620
1/2
✗ Branch 114 → 115 not taken.
✓ Branch 114 → 117 taken 3294522 times.
3294522 if (i & (~63)) {
1621 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1622 "ac-tex damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
1623 ✗ return AVERROR_INVALIDDATA;
1624 }
1625
1626 3294522 block[scan_table[i]] = level;
1627 3294522 break;
1628 }
1629
1630 25635954 block[scan_table[i]] = level;
1631 }
1632 3294522 CLOSE_READER(re, &h->gb);
1633 }
1634
1635 3553308 not_coded:
1636
2/2
✓ Branch 120 → 121 taken 1162200 times.
✓ Branch 120 → 127 taken 2391108 times.
3553308 if (intra) {
1637
1/2
✗ Branch 121 → 122 not taken.
✓ Branch 121 → 124 taken 1162200 times.
1162200 if (!use_intra_dc_vlc) {
1638 ✗ block[0] = mpeg4_get_level_dc(&h->c, n, pred, block[0]);
1639
1640 ✗ i -= i >> 31; // if (i == -1) i = 0;
1641 }
1642
1643 1162200 ff_mpeg4_pred_ac(h, block, n, dc_pred_dir);
1644
2/2
✓ Branch 125 → 126 taken 25938 times.
✓ Branch 125 → 127 taken 1136262 times.
1162200 if (h->c.ac_pred)
1645 25938 i = 63; // FIXME not optimal
1646 }
1647 3553308 h->c.block_last_index[n] = i;
1648 3553308 return 0;
1649 }
1650
1651 /**
1652 * decode partition C of one MB.
1653 * @return <0 if an error occurred
1654 */
1655 138772 static int mpeg4_decode_partitioned_mb(H263DecContext *const h)
1656 {
1657 138772 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
1658 138772 const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
1659
1660 138772 const int mb_type = h->c.cur_pic.mb_type[xy];
1661 138772 int cbp = h->c.cbp_table[xy];
1662
1663 138772 const int use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;
1664
1665
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 138772 times.
138772 if (h->c.cur_pic.qscale_table[xy] != h->c.qscale)
1666 ✗ ff_set_qscale(&h->c, h->c.cur_pic.qscale_table[xy]);
1667
1668
2/2
✓ Branch 5 → 6 taken 17421 times.
✓ Branch 5 → 7 taken 121351 times.
138772 if (h->c.pict_type == AV_PICTURE_TYPE_P ||
1669
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 26 taken 17421 times.
138772 h->c.pict_type == AV_PICTURE_TYPE_S) {
1670 int i;
1671
2/2
✓ Branch 9 → 8 taken 485404 times.
✓ Branch 9 → 10 taken 121351 times.
606755 for (i = 0; i < 4; i++) {
1672 485404 h->c.mv[0][i][0] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][0];
1673 485404 h->c.mv[0][i][1] = h->c.cur_pic.motion_val[0][h->c.block_index[i]][1];
1674 }
1675 121351 h->c.mb_intra = IS_INTRA(mb_type);
1676
1677
2/2
✓ Branch 10 → 11 taken 1001 times.
✓ Branch 10 → 19 taken 120350 times.
121351 if (IS_SKIP(mb_type)) {
1678 /* skip mb */
1679
2/2
✓ Branch 13 → 12 taken 6006 times.
✓ Branch 13 → 14 taken 1001 times.
7007 for (i = 0; i < 6; i++)
1680 6006 h->c.block_last_index[i] = -1;
1681 1001 h->c.mv_dir = MV_DIR_FORWARD;
1682 1001 h->c.mv_type = MV_TYPE_16X16;
1683
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 17 taken 1001 times.
1001 if (h->c.pict_type == AV_PICTURE_TYPE_S
1684
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
✗ && ctx->vol_sprite_usage == GMC_SPRITE) {
1685 ✗ h->c.mcsel = 1;
1686 ✗ h->c.mb_skipped = 0;
1687 ✗ h->c.cur_pic.mbskip_table[xy] = 0;
1688 } else {
1689 1001 h->c.mcsel = 0;
1690 1001 h->c.mb_skipped = 1;
1691 1001 h->c.cur_pic.mbskip_table[xy] = 1;
1692 }
1693
2/2
✓ Branch 19 → 20 taken 6371 times.
✓ Branch 19 → 21 taken 113979 times.
120350 } else if (h->c.mb_intra) {
1694 6371 h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]);
1695
1/2
✓ Branch 21 → 22 taken 113979 times.
✗ Branch 21 → 25 not taken.
113979 } else if (!h->c.mb_intra) {
1696 // h->c.mcsel = 0; // FIXME do we need to init that?
1697
1698 113979 h->c.mv_dir = MV_DIR_FORWARD;
1699
2/2
✓ Branch 22 → 23 taken 32038 times.
✓ Branch 22 → 24 taken 81941 times.
113979 if (IS_8X8(mb_type)) {
1700 32038 h->c.mv_type = MV_TYPE_8X8;
1701 } else {
1702 81941 h->c.mv_type = MV_TYPE_16X16;
1703 }
1704 }
1705 } else { /* I-Frame */
1706 17421 h->c.mb_intra = 1;
1707 17421 h->c.ac_pred = IS_ACPRED(h->c.cur_pic.mb_type[xy]);
1708 }
1709
1710
2/2
✓ Branch 27 → 28 taken 137771 times.
✓ Branch 27 → 36 taken 1001 times.
138772 if (!IS_SKIP(mb_type)) {
1711 int i;
1712 137771 h->c.bdsp.clear_blocks(h->block[0]);
1713 /* decode each block */
1714
2/2
✓ Branch 35 → 30 taken 826626 times.
✓ Branch 35 → 36 taken 137771 times.
964397 for (i = 0; i < 6; i++) {
1715
1/2
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 34 taken 826626 times.
826626 if (mpeg4_decode_block(ctx, h->block[i], i, cbp & 32, h->c.mb_intra,
1716 use_intra_dc_vlc, ctx->rvlc) < 0) {
1717 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1718 "texture corrupted at %d %d %d\n",
1719 h->c.mb_x, h->c.mb_y, h->c.mb_intra);
1720 ✗ return AVERROR_INVALIDDATA;
1721 }
1722 826626 cbp += cbp;
1723 }
1724 }
1725
1726 /* per-MB end of slice check */
1727
2/2
✓ Branch 36 → 37 taken 1729 times.
✓ Branch 36 → 41 taken 137043 times.
138772 if (--h->mb_num_left <= 0) {
1728
1/2
✓ Branch 38 → 39 taken 1729 times.
✗ Branch 38 → 40 not taken.
1729 if (mpeg4_is_resync(ctx))
1729 1729 return SLICE_END;
1730 else
1731 ✗ return SLICE_NOEND;
1732 } else {
1733
2/2
✓ Branch 42 → 43 taken 278 times.
✓ Branch 42 → 48 taken 136765 times.
137043 if (mpeg4_is_resync(ctx)) {
1734
2/2
✓ Branch 43 → 44 taken 4 times.
✓ Branch 43 → 45 taken 274 times.
278 const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1;
1735
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 278 times.
278 if (h->c.cbp_table[xy + delta])
1736 ✗ return SLICE_END;
1737 }
1738 137043 return SLICE_OK;
1739 }
1740 }
1741
1742 1460344 static int mpeg4_decode_mb(H263DecContext *const h)
1743 {
1744 1460344 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
1745 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
1746 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
1747 1460344 const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
1748 int next;
1749
1750 av_assert2(h->c.h263_pred);
1751
1752
2/2
✓ Branch 3 → 4 taken 371582 times.
✓ Branch 3 → 5 taken 1088762 times.
1460344 if (h->c.pict_type == AV_PICTURE_TYPE_P ||
1753
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 86 taken 371582 times.
371582 h->c.pict_type == AV_PICTURE_TYPE_S) {
1754 do {
1755
2/2
✓ Branch 7 → 8 taken 165103 times.
✓ Branch 7 → 18 taken 923659 times.
1088762 if (get_bits1(&h->gb)) {
1756 /* skip mb */
1757 165103 h->c.mb_intra = 0;
1758
2/2
✓ Branch 10 → 9 taken 990618 times.
✓ Branch 10 → 11 taken 165103 times.
1155721 for (i = 0; i < 6; i++)
1759 990618 h->c.block_last_index[i] = -1;
1760 165103 h->c.mv_dir = MV_DIR_FORWARD;
1761 165103 h->c.mv_type = MV_TYPE_16X16;
1762
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 16 taken 165103 times.
165103 if (h->c.pict_type == AV_PICTURE_TYPE_S &&
1763
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 16 not taken.
✗ ctx->vol_sprite_usage == GMC_SPRITE) {
1764 ✗ h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
1765 MB_TYPE_GMC |
1766 MB_TYPE_16x16 |
1767 MB_TYPE_FORWARD_MV;
1768 ✗ h->c.mcsel = 1;
1769 ✗ h->c.mv[0][0][0] = get_amv(ctx, 0);
1770 ✗ h->c.mv[0][0][1] = get_amv(ctx, 1);
1771 ✗ h->c.cur_pic.mbskip_table[xy] = 0;
1772 ✗ h->c.mb_skipped = 0;
1773 } else {
1774 165103 h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 |
1775 MB_TYPE_FORWARD_MV;
1776 165103 h->c.mcsel = 0;
1777 165103 h->c.mv[0][0][0] = 0;
1778 165103 h->c.mv[0][0][1] = 0;
1779 165103 h->c.cur_pic.mbskip_table[xy] = 1;
1780 165103 h->c.mb_skipped = 1;
1781 }
1782 165103 goto end;
1783 }
1784 923659 cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
1785
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 923659 times.
923659 if (cbpc < 0) {
1786 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1787 "mcbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
1788 ✗ return AVERROR_INVALIDDATA;
1789 }
1790
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 923659 times.
923659 } while (cbpc == 20);
1791
1792 923659 dquant = cbpc & 8;
1793 923659 h->c.mb_intra = ((cbpc & 4) != 0);
1794
2/2
✓ Branch 24 → 25 taken 32981 times.
✓ Branch 24 → 26 taken 890678 times.
923659 if (h->c.mb_intra)
1795 32981 goto intra;
1796 890678 h->c.bdsp.clear_blocks(h->block[0]);
1797
1798
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 32 taken 890678 times.
890678 if (h->c.pict_type == AV_PICTURE_TYPE_S &&
1799
0/4
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 32 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 32 not taken.
✗ ctx->vol_sprite_usage == GMC_SPRITE && (cbpc & 16) == 0)
1800 ✗ h->c.mcsel = get_bits1(&h->gb);
1801 else
1802 890678 h->c.mcsel = 0;
1803 890678 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1) ^ 0x0F;
1804
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 37 taken 890678 times.
890678 if (cbpy < 0) {
1805 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
1806 "P cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
1807 ✗ return AVERROR_INVALIDDATA;
1808 }
1809
1810 890678 cbp = (cbpc & 3) | (cbpy << 2);
1811
2/2
✓ Branch 37 → 38 taken 23659 times.
✓ Branch 37 → 40 taken 867019 times.
890678 if (dquant)
1812 23659 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
1813
1/4
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 45 taken 890678 times.
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 43 not taken.
890678 if ((!h->c.progressive_sequence) &&
1814
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 45 not taken.
✗ (cbp || (h->c.workaround_bugs & FF_BUG_XVID_ILACE)))
1815 ✗ h->c.interlaced_dct = get_bits1(&h->gb);
1816
1817 890678 h->c.mv_dir = MV_DIR_FORWARD;
1818
2/2
✓ Branch 45 → 46 taken 792091 times.
✓ Branch 45 → 75 taken 98587 times.
890678 if ((cbpc & 16) == 0) {
1819
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 50 taken 792091 times.
792091 if (h->c.mcsel) {
1820 ✗ h->c.cur_pic.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 |
1821 MB_TYPE_FORWARD_MV;
1822 /* 16x16 global motion prediction */
1823 ✗ h->c.mv_type = MV_TYPE_16X16;
1824 ✗ mx = get_amv(ctx, 0);
1825 ✗ my = get_amv(ctx, 1);
1826 ✗ h->c.mv[0][0][0] = mx;
1827 ✗ h->c.mv[0][0][1] = my;
1828
1/4
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 66 taken 792091 times.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 66 not taken.
792091 } else if ((!h->c.progressive_sequence) && get_bits1(&h->gb)) {
1829 ✗ h->c.cur_pic.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_FORWARD_MV |
1830 MB_TYPE_INTERLACED;
1831 /* 16x8 field motion prediction */
1832 ✗ h->c.mv_type = MV_TYPE_FIELD;
1833
1834 ✗ h->c.field_select[0][0] = get_bits1(&h->gb);
1835 ✗ h->c.field_select[0][1] = get_bits1(&h->gb);
1836
1837 ✗ ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
1838
1839
0/2
✗ Branch 64 → 57 not taken.
✗ Branch 64 → 65 not taken.
✗ for (i = 0; i < 2; i++) {
1840 ✗ mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
1841
0/2
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 60 not taken.
✗ if (mx >= 0xffff)
1842 ✗ return AVERROR_INVALIDDATA;
1843
1844 ✗ my = ff_h263_decode_motion(h, pred_y / 2, ctx->f_code);
1845
0/2
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ if (my >= 0xffff)
1846 ✗ return AVERROR_INVALIDDATA;
1847
1848 ✗ h->c.mv[0][i][0] = mx;
1849 ✗ h->c.mv[0][i][1] = my;
1850 }
1851 } else {
1852 792091 h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
1853 /* 16x16 motion prediction */
1854 792091 h->c.mv_type = MV_TYPE_16X16;
1855 792091 ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
1856 792091 mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
1857
1858
1/2
✗ Branch 68 → 69 not taken.
✓ Branch 68 → 70 taken 792091 times.
792091 if (mx >= 0xffff)
1859 ✗ return AVERROR_INVALIDDATA;
1860
1861 792091 my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
1862
1863
1/2
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 73 taken 792091 times.
792091 if (my >= 0xffff)
1864 ✗ return AVERROR_INVALIDDATA;
1865 792091 h->c.mv[0][0][0] = mx;
1866 792091 h->c.mv[0][0][1] = my;
1867 }
1868 } else {
1869 98587 h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
1870 98587 h->c.mv_type = MV_TYPE_8X8;
1871
2/2
✓ Branch 84 → 76 taken 394348 times.
✓ Branch 84 → 85 taken 98587 times.
492935 for (i = 0; i < 4; i++) {
1872 394348 int16_t *mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
1873 394348 mx = ff_h263_decode_motion(h, pred_x, ctx->f_code);
1874
1/2
✗ Branch 78 → 79 not taken.
✓ Branch 78 → 80 taken 394348 times.
394348 if (mx >= 0xffff)
1875 ✗ return AVERROR_INVALIDDATA;
1876
1877 394348 my = ff_h263_decode_motion(h, pred_y, ctx->f_code);
1878
1/2
✗ Branch 81 → 82 not taken.
✓ Branch 81 → 83 taken 394348 times.
394348 if (my >= 0xffff)
1879 ✗ return AVERROR_INVALIDDATA;
1880 394348 h->c.mv[0][i][0] = mx;
1881 394348 h->c.mv[0][i][1] = my;
1882 394348 mot_val[0] = mx;
1883 394348 mot_val[1] = my;
1884 }
1885 }
1886
2/2
✓ Branch 86 → 87 taken 234655 times.
✓ Branch 86 → 161 taken 136927 times.
371582 } else if (h->c.pict_type == AV_PICTURE_TYPE_B) {
1887 int modb1; // first bit of modb
1888 int modb2; // second bit of modb
1889 int mb_type;
1890
1891 234655 h->c.mb_intra = 0; // B-frames never contain intra blocks
1892 234655 h->c.mcsel = 0; // ... true gmc blocks
1893
1894
2/2
✓ Branch 87 → 88 taken 10039 times.
✓ Branch 87 → 92 taken 224616 times.
234655 if (h->c.mb_x == 0) {
1895
2/2
✓ Branch 90 → 89 taken 20078 times.
✓ Branch 90 → 91 taken 10039 times.
30117 for (i = 0; i < 2; i++) {
1896 20078 h->c.last_mv[i][0][0] =
1897 20078 h->c.last_mv[i][0][1] =
1898 20078 h->c.last_mv[i][1][0] =
1899 20078 h->c.last_mv[i][1][1] = 0;
1900 }
1901
1902 10039 ff_thread_progress_await(&h->c.next_pic.ptr->progress, h->c.mb_y);
1903 }
1904
1905 /* if we skipped it in the future P-frame than skip it now too */
1906 234655 h->c.mb_skipped = h->c.next_pic.mbskip_table[h->c.mb_y * h->c.mb_stride + h->c.mb_x]; // Note, skiptab=0 if last was GMC
1907
1908
2/2
✓ Branch 92 → 93 taken 32858 times.
✓ Branch 92 → 97 taken 201797 times.
234655 if (h->c.mb_skipped) {
1909 /* skip mb */
1910
2/2
✓ Branch 95 → 94 taken 197148 times.
✓ Branch 95 → 96 taken 32858 times.
230006 for (i = 0; i < 6; i++)
1911 197148 h->c.block_last_index[i] = -1;
1912
1913 32858 h->c.mv_dir = MV_DIR_FORWARD;
1914 32858 h->c.mv_type = MV_TYPE_16X16;
1915 32858 h->c.mv[0][0][0] =
1916 32858 h->c.mv[0][0][1] =
1917 32858 h->c.mv[1][0][0] =
1918 32858 h->c.mv[1][0][1] = 0;
1919 32858 h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP |
1920 MB_TYPE_16x16 |
1921 MB_TYPE_FORWARD_MV;
1922 32858 goto end;
1923 }
1924
1925 201797 modb1 = get_bits1(&h->gb);
1926
2/2
✓ Branch 98 → 99 taken 44514 times.
✓ Branch 98 → 100 taken 157283 times.
201797 if (modb1) {
1927 // like MB_TYPE_B_DIRECT but no vectors coded
1928 44514 mb_type = MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_BIDIR_MV;
1929 44514 cbp = 0;
1930 } else {
1931 157283 modb2 = get_bits1(&h->gb);
1932 157283 mb_type = get_vlc2(&h->gb, mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 1);
1933
1/2
✗ Branch 102 → 103 not taken.
✓ Branch 102 → 105 taken 157283 times.
157283 if (mb_type < 0) {
1934 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "illegal MB_type\n");
1935 ✗ return AVERROR_INVALIDDATA;
1936 }
1937
2/2
✓ Branch 105 → 106 taken 65756 times.
✓ Branch 105 → 107 taken 91527 times.
157283 if (modb2) {
1938 65756 cbp = 0;
1939 } else {
1940 91527 h->c.bdsp.clear_blocks(h->block[0]);
1941 91527 cbp = get_bits(&h->gb, 6);
1942 }
1943
1944
4/4
✓ Branch 110 → 111 taken 116195 times.
✓ Branch 110 → 116 taken 41088 times.
✓ Branch 111 → 112 taken 65999 times.
✓ Branch 111 → 116 taken 50196 times.
157283 if ((!IS_DIRECT(mb_type)) && cbp) {
1945
2/2
✓ Branch 113 → 114 taken 7480 times.
✓ Branch 113 → 116 taken 58519 times.
65999 if (get_bits1(&h->gb))
1946 7480 ff_set_qscale(&h->c, h->c.qscale + get_bits1(&h->gb) * 4 - 2);
1947 }
1948
1949
1/2
✗ Branch 116 → 117 not taken.
✓ Branch 116 → 131 taken 157283 times.
157283 if (!h->c.progressive_sequence) {
1950
0/2
✗ Branch 117 → 118 not taken.
✗ Branch 117 → 120 not taken.
✗ if (cbp)
1951 ✗ h->c.interlaced_dct = get_bits1(&h->gb);
1952
1953
0/4
✗ Branch 120 → 121 not taken.
✗ Branch 120 → 131 not taken.
✗ Branch 122 → 123 not taken.
✗ Branch 122 → 131 not taken.
✗ if (!IS_DIRECT(mb_type) && get_bits1(&h->gb)) {
1954 ✗ mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
1955 ✗ mb_type &= ~MB_TYPE_16x16;
1956
1957
0/2
✗ Branch 123 → 124 not taken.
✗ Branch 123 → 127 not taken.
✗ if (HAS_FORWARD_MV(mb_type)) {
1958 ✗ h->c.field_select[0][0] = get_bits1(&h->gb);
1959 ✗ h->c.field_select[0][1] = get_bits1(&h->gb);
1960 }
1961
0/2
✗ Branch 127 → 128 not taken.
✗ Branch 127 → 131 not taken.
✗ if (HAS_BACKWARD_MV(mb_type)) {
1962 ✗ h->c.field_select[1][0] = get_bits1(&h->gb);
1963 ✗ h->c.field_select[1][1] = get_bits1(&h->gb);
1964 }
1965 }
1966 }
1967
1968 157283 h->c.mv_dir = 0;
1969
2/2
✓ Branch 131 → 132 taken 116195 times.
✓ Branch 131 → 140 taken 41088 times.
157283 if ((mb_type & (MB_TYPE_DIRECT2 | MB_TYPE_INTERLACED)) == 0) {
1970 116195 h->c.mv_type = MV_TYPE_16X16;
1971
1972
2/2
✓ Branch 132 → 133 taken 81033 times.
✓ Branch 132 → 136 taken 35162 times.
116195 if (HAS_FORWARD_MV(mb_type)) {
1973 81033 h->c.mv_dir = MV_DIR_FORWARD;
1974
1975 81033 mx = ff_h263_decode_motion(h, h->c.last_mv[0][0][0], ctx->f_code);
1976 81033 my = ff_h263_decode_motion(h, h->c.last_mv[0][0][1], ctx->f_code);
1977 81033 h->c.last_mv[0][1][0] =
1978 81033 h->c.last_mv[0][0][0] =
1979 81033 h->c.mv[0][0][0] = mx;
1980 81033 h->c.last_mv[0][1][1] =
1981 81033 h->c.last_mv[0][0][1] =
1982 81033 h->c.mv[0][0][1] = my;
1983 }
1984
1985
2/2
✓ Branch 136 → 137 taken 92446 times.
✓ Branch 136 → 153 taken 23749 times.
116195 if (HAS_BACKWARD_MV(mb_type)) {
1986 92446 h->c.mv_dir |= MV_DIR_BACKWARD;
1987
1988 92446 mx = ff_h263_decode_motion(h, h->c.last_mv[1][0][0], ctx->b_code);
1989 92446 my = ff_h263_decode_motion(h, h->c.last_mv[1][0][1], ctx->b_code);
1990 92446 h->c.last_mv[1][1][0] =
1991 92446 h->c.last_mv[1][0][0] =
1992 92446 h->c.mv[1][0][0] = mx;
1993 92446 h->c.last_mv[1][1][1] =
1994 92446 h->c.last_mv[1][0][1] =
1995 92446 h->c.mv[1][0][1] = my;
1996 }
1997
1/2
✗ Branch 140 → 141 not taken.
✓ Branch 140 → 153 taken 41088 times.
41088 } else if (!IS_DIRECT(mb_type)) {
1998 ✗ h->c.mv_type = MV_TYPE_FIELD;
1999
2000
0/2
✗ Branch 141 → 142 not taken.
✗ Branch 141 → 147 not taken.
✗ if (HAS_FORWARD_MV(mb_type)) {
2001 ✗ h->c.mv_dir = MV_DIR_FORWARD;
2002
2003
0/2
✗ Branch 146 → 143 not taken.
✗ Branch 146 → 147 not taken.
✗ for (i = 0; i < 2; i++) {
2004 ✗ mx = ff_h263_decode_motion(h, h->c.last_mv[0][i][0], ctx->f_code);
2005 ✗ my = ff_h263_decode_motion(h, h->c.last_mv[0][i][1] / 2, ctx->f_code);
2006 ✗ h->c.last_mv[0][i][0] =
2007 ✗ h->c.mv[0][i][0] = mx;
2008 ✗ h->c.last_mv[0][i][1] = (h->c.mv[0][i][1] = my) * 2;
2009 }
2010 }
2011
2012
0/2
✗ Branch 147 → 148 not taken.
✗ Branch 147 → 153 not taken.
✗ if (HAS_BACKWARD_MV(mb_type)) {
2013 ✗ h->c.mv_dir |= MV_DIR_BACKWARD;
2014
2015
0/2
✗ Branch 152 → 149 not taken.
✗ Branch 152 → 153 not taken.
✗ for (i = 0; i < 2; i++) {
2016 ✗ mx = ff_h263_decode_motion(h, h->c.last_mv[1][i][0], ctx->b_code);
2017 ✗ my = ff_h263_decode_motion(h, h->c.last_mv[1][i][1] / 2, ctx->b_code);
2018 ✗ h->c.last_mv[1][i][0] =
2019 ✗ h->c.mv[1][i][0] = mx;
2020 ✗ h->c.last_mv[1][i][1] = (h->c.mv[1][i][1] = my) * 2;
2021 }
2022 }
2023 }
2024 }
2025
2026
2/2
✓ Branch 153 → 154 taken 85602 times.
✓ Branch 153 → 160 taken 116195 times.
201797 if (IS_DIRECT(mb_type)) {
2027
2/2
✓ Branch 154 → 155 taken 44514 times.
✓ Branch 154 → 156 taken 41088 times.
85602 if (IS_SKIP(mb_type)) {
2028 44514 mx =
2029 44514 my = 0;
2030 } else {
2031 41088 mx = ff_h263_decode_motion(h, 0, 1);
2032 41088 my = ff_h263_decode_motion(h, 0, 1);
2033 }
2034
2035 85602 h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
2036 85602 mb_type |= ff_mpeg4_set_direct_mv(&h->c, mx, my);
2037 }
2038 201797 h->c.cur_pic.mb_type[xy] = mb_type;
2039 } else { /* I-Frame */
2040 int use_intra_dc_vlc;
2041
2042 do {
2043 136927 cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
2044
1/2
✗ Branch 163 → 164 not taken.
✓ Branch 163 → 166 taken 136927 times.
136927 if (cbpc < 0) {
2045 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
2046 "I cbpc damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
2047 ✗ return AVERROR_INVALIDDATA;
2048 }
2049
1/2
✗ Branch 166 → 167 not taken.
✓ Branch 166 → 168 taken 136927 times.
136927 } while (cbpc == 8);
2050
2051 136927 dquant = cbpc & 4;
2052 136927 h->c.mb_intra = 1;
2053
2054 169908 intra:
2055 169908 h->c.ac_pred = get_bits1(&h->gb);
2056
2/2
✓ Branch 170 → 171 taken 552 times.
✓ Branch 170 → 172 taken 169356 times.
169908 if (h->c.ac_pred)
2057 552 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
2058 else
2059 169356 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
2060
2061 169908 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
2062
1/2
✗ Branch 174 → 175 not taken.
✓ Branch 174 → 177 taken 169908 times.
169908 if (cbpy < 0) {
2063 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
2064 "I cbpy damaged at %d %d\n", h->c.mb_x, h->c.mb_y);
2065 ✗ return AVERROR_INVALIDDATA;
2066 }
2067 169908 cbp = (cbpc & 3) | (cbpy << 2);
2068
2069 169908 use_intra_dc_vlc = h->c.qscale < ctx->intra_dc_threshold;
2070
2071
2/2
✓ Branch 177 → 178 taken 10733 times.
✓ Branch 177 → 180 taken 159175 times.
169908 if (dquant)
2072 10733 ff_set_qscale(&h->c, h->c.qscale + quant_tab[get_bits(&h->gb, 2)]);
2073
2074
1/2
✗ Branch 180 → 181 not taken.
✓ Branch 180 → 183 taken 169908 times.
169908 if (!h->c.progressive_sequence)
2075 ✗ h->c.interlaced_dct = get_bits1(&h->gb);
2076
2077 169908 h->c.bdsp.clear_blocks(h->block[0]);
2078 /* decode each block */
2079
2/2
✓ Branch 189 → 185 taken 1019448 times.
✓ Branch 189 → 190 taken 169908 times.
1189356 for (i = 0; i < 6; i++) {
2080
1/2
✗ Branch 186 → 187 not taken.
✓ Branch 186 → 188 taken 1019448 times.
1019448 if (mpeg4_decode_block(ctx, h->block[i], i, cbp & 32,
2081 1, use_intra_dc_vlc, 0) < 0)
2082 ✗ return AVERROR_INVALIDDATA;
2083 1019448 cbp += cbp;
2084 }
2085 169908 goto end;
2086 }
2087
2088 /* decode each block */
2089
2/2
✓ Branch 196 → 192 taken 6554850 times.
✓ Branch 196 → 197 taken 1092475 times.
7647325 for (i = 0; i < 6; i++) {
2090
1/2
✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 6554850 times.
6554850 if (mpeg4_decode_block(ctx, h->block[i], i, cbp & 32, 0, 0, 0) < 0)
2091 ✗ return AVERROR_INVALIDDATA;
2092 6554850 cbp += cbp;
2093 }
2094
2095 1092475 end:
2096 /* per-MB end of slice check */
2097 1460344 next = mpeg4_is_resync(ctx);
2098
2/2
✓ Branch 199 → 200 taken 22594 times.
✓ Branch 199 → 218 taken 1437750 times.
1460344 if (next) {
2099
3/4
✓ Branch 200 → 201 taken 5 times.
✓ Branch 200 → 203 taken 22589 times.
✗ Branch 201 → 202 not taken.
✓ Branch 201 → 203 taken 5 times.
22594 if (h->c.mb_x + h->c.mb_y*h->c.mb_width + 1 > next && (h->c.avctx->err_recognition & AV_EF_AGGRESSIVE)) {
2100 ✗ return AVERROR_INVALIDDATA;
2101
2/2
✓ Branch 203 → 204 taken 14650 times.
✓ Branch 203 → 205 taken 7944 times.
22594 } else if (h->c.mb_x + h->c.mb_y*h->c.mb_width + 1 >= next)
2102 14650 return SLICE_END;
2103
2104
1/2
✓ Branch 205 → 206 taken 7944 times.
✗ Branch 205 → 217 not taken.
7944 if (h->c.pict_type == AV_PICTURE_TYPE_B) {
2105
2/2
✓ Branch 206 → 207 taken 168 times.
✓ Branch 206 → 208 taken 7776 times.
7944 const int delta = h->c.mb_x + 1 == h->c.mb_width ? 2 : 1;
2106 7944 ff_thread_progress_await(&h->c.next_pic.ptr->progress,
2107
2/2
✓ Branch 209 → 210 taken 168 times.
✓ Branch 209 → 213 taken 7776 times.
7944 (h->c.mb_x + delta >= h->c.mb_width)
2108
1/2
✗ Branch 210 → 211 not taken.
✓ Branch 210 → 212 taken 168 times.
168 ? FFMIN(h->c.mb_y + 1, h->c.mb_height - 1)
2109 : h->c.mb_y);
2110
1/2
✓ Branch 215 → 216 taken 7944 times.
✗ Branch 215 → 217 not taken.
7944 if (h->c.next_pic.mbskip_table[xy + delta])
2111 7944 return SLICE_OK;
2112 }
2113
2114 ✗ return SLICE_END;
2115 }
2116
2117 1437750 return SLICE_OK;
2118 }
2119
2120 /* As per spec, studio start code search isn't the same as the old type of start code */
2121 34 static void next_start_code_studio(GetBitContext *gb)
2122 {
2123 34 align_get_bits(gb);
2124
2125
3/4
✓ Branch 6 → 7 taken 33 times.
✓ Branch 6 → 9 taken 1 time.
✗ Branch 8 → 4 not taken.
✓ Branch 8 → 9 taken 33 times.
34 while (get_bits_left(gb) >= 24 && show_bits(gb, 24) != 0x1) {
2126 ✗ get_bits(gb, 8);
2127 }
2128 34 }
2129
2130 /* additional_code, vlc index */
2131 static const uint8_t ac_state_tab[22][2] =
2132 {
2133 {0, 0},
2134 {0, 1},
2135 {1, 1},
2136 {2, 1},
2137 {3, 1},
2138 {4, 1},
2139 {5, 1},
2140 {1, 2},
2141 {2, 2},
2142 {3, 2},
2143 {4, 2},
2144 {5, 2},
2145 {6, 2},
2146 {1, 3},
2147 {2, 4},
2148 {3, 5},
2149 {4, 6},
2150 {5, 7},
2151 {6, 8},
2152 {7, 9},
2153 {8, 10},
2154 {0, 11}
2155 };
2156
2157 5336 static int mpeg4_decode_studio_block(Mpeg4DecContext *const ctx, int32_t block[64], int n)
2158 {
2159 5336 H263DecContext *const h = &ctx->h;
2160
2161 5336 int cc, dct_dc_size, dct_diff, code, j, idx = 1, group = 0, run = 0,
2162 additional_code_len, sign, mismatch;
2163 5336 const VLCElem *cur_vlc = studio_intra_tab[0];
2164 5336 const uint8_t *const scantable = h->c.intra_scantable.permutated;
2165 const uint16_t *quant_matrix;
2166 uint32_t flc;
2167 5336 const int min = -1 * (1 << (h->c.avctx->bits_per_raw_sample + 6));
2168 5336 const int max = ((1 << (h->c.avctx->bits_per_raw_sample + 6)) - 1);
2169 5336 int shift = 3 - ctx->dct_precision;
2170
2171 5336 mismatch = 1;
2172
2173 5336 memset(block, 0, 64 * sizeof(int32_t));
2174
2175
2/2
✓ Branch 2 → 3 taken 2668 times.
✓ Branch 2 → 5 taken 2668 times.
5336 if (n < 4) {
2176 2668 cc = 0;
2177 2668 dct_dc_size = get_vlc2(&h->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
2178 2668 quant_matrix = h->c.intra_matrix;
2179 } else {
2180 2668 cc = (n & 1) + 1;
2181
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 2668 times.
2668 if (ctx->rgb)
2182 ✗ dct_dc_size = get_vlc2(&h->gb, studio_luma_dc, STUDIO_INTRA_BITS, 2);
2183 else
2184 2668 dct_dc_size = get_vlc2(&h->gb, studio_chroma_dc, STUDIO_INTRA_BITS, 2);
2185 2668 quant_matrix = h->c.chroma_intra_matrix;
2186 }
2187
2188
2/2
✓ Branch 9 → 10 taken 242 times.
✓ Branch 9 → 11 taken 5094 times.
5336 if (dct_dc_size == 0) {
2189 242 dct_diff = 0;
2190 } else {
2191 5094 dct_diff = get_xbits(&h->gb, dct_dc_size);
2192
2193
2/2
✓ Branch 12 → 13 taken 227 times.
✓ Branch 12 → 16 taken 4867 times.
5094 if (dct_dc_size > 8) {
2194
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 227 times.
227 if(!check_marker(h->c.avctx, &h->gb, "dct_dc_size > 8"))
2195 ✗ return AVERROR_INVALIDDATA;
2196 }
2197
2198 }
2199
2200 5336 h->last_dc[cc] += dct_diff;
2201
2202
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 5336 times.
5336 if (ctx->mpeg_quant)
2203 ✗ block[0] = h->last_dc[cc] * (8 >> h->c.intra_dc_precision);
2204 else
2205 5336 block[0] = h->last_dc[cc] * (8 >> h->c.intra_dc_precision) * (8 >> ctx->dct_precision);
2206 /* TODO: support mpeg_quant for AC coefficients */
2207
2208 5336 block[0] = av_clip(block[0], min, max);
2209 5336 mismatch ^= block[0];
2210
2211 /* AC Coefficients */
2212 while (1) {
2213 33424 group = get_vlc2(&h->gb, cur_vlc, STUDIO_INTRA_BITS, 2);
2214
2215
1/2
✗ Branch 21 → 22 not taken.
✓ Branch 21 → 24 taken 33424 times.
33424 if (group < 0) {
2216 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac coefficient group vlc\n");
2217 ✗ return AVERROR_INVALIDDATA;
2218 }
2219
2220 33424 additional_code_len = ac_state_tab[group][0];
2221 33424 cur_vlc = studio_intra_tab[ac_state_tab[group][1]];
2222
2223
2/2
✓ Branch 24 → 25 taken 5336 times.
✓ Branch 24 → 26 taken 28088 times.
33424 if (group == 0) {
2224 /* End of Block */
2225 5336 break;
2226
3/4
✓ Branch 26 → 27 taken 28088 times.
✗ Branch 26 → 32 not taken.
✓ Branch 27 → 28 taken 2347 times.
✓ Branch 27 → 32 taken 25741 times.
28088 } else if (group >= 1 && group <= 6) {
2227 /* Zero run length (Table B.47) */
2228 2347 run = 1 << additional_code_len;
2229
2/2
✓ Branch 28 → 29 taken 927 times.
✓ Branch 28 → 31 taken 1420 times.
2347 if (additional_code_len)
2230 927 run += get_bits(&h->gb, additional_code_len);
2231 2347 idx += run;
2232 2347 continue;
2233
3/4
✓ Branch 32 → 33 taken 25741 times.
✗ Branch 32 → 41 not taken.
✓ Branch 33 → 34 taken 6045 times.
✓ Branch 33 → 41 taken 19696 times.
25741 } else if (group >= 7 && group <= 12) {
2234 /* Zero run length and +/-1 level (Table B.48) */
2235 6045 code = get_bits(&h->gb, additional_code_len);
2236 6045 sign = code & 1;
2237 6045 code >>= 1;
2238 6045 run = (1 << (additional_code_len - 1)) + code;
2239 6045 idx += run;
2240
1/2
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 6045 times.
6045 if (idx > 63)
2241 ✗ return AVERROR_INVALIDDATA;
2242 6045 j = scantable[idx++];
2243
2/2
✓ Branch 37 → 38 taken 3183 times.
✓ Branch 37 → 39 taken 2862 times.
6045 block[j] = sign ? 1 : -1;
2244
2/4
✓ Branch 41 → 42 taken 19696 times.
✗ Branch 41 → 47 not taken.
✓ Branch 42 → 43 taken 19696 times.
✗ Branch 42 → 47 not taken.
19696 } else if (group >= 13 && group <= 20) {
2245 /* Level value (Table B.49) */
2246
1/2
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 45 taken 19696 times.
19696 if (idx > 63)
2247 ✗ return AVERROR_INVALIDDATA;
2248 19696 j = scantable[idx++];
2249 19696 block[j] = get_xbits(&h->gb, additional_code_len);
2250
0/2
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 54 not taken.
✗ } else if (group == 21) {
2251 /* Escape */
2252
0/2
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 50 not taken.
✗ if (idx > 63)
2253 ✗ return AVERROR_INVALIDDATA;
2254 ✗ j = scantable[idx++];
2255 ✗ additional_code_len = h->c.avctx->bits_per_raw_sample + ctx->dct_precision + 4;
2256 ✗ flc = get_bits(&h->gb, additional_code_len);
2257
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 53 not taken.
✗ if (flc >> (additional_code_len-1))
2258 ✗ block[j] = -1 * (( flc ^ ((1 << additional_code_len) -1)) + 1);
2259 else
2260 ✗ block[j] = flc;
2261 }
2262 25741 block[j] = ((block[j] * quant_matrix[j] * h->c.qscale) * (1 << shift)) / 16;
2263 25741 block[j] = av_clip(block[j], min, max);
2264 25741 mismatch ^= block[j];
2265 }
2266
2267 5336 block[63] ^= mismatch & 1;
2268
2269 5336 return 0;
2270 }
2271
2272 2049 static int mpeg4_decode_dpcm_macroblock(Mpeg4DecContext *const ctx,
2273 int16_t macroblock[256], int n)
2274 {
2275 2049 H263DecContext *const h = &ctx->h;
2276 2049 int j, w, height, idx = 0;
2277 int block_mean, rice_parameter, rice_prefix_code, rice_suffix_code,
2278 dpcm_residual, left, top, topleft, min_left_top, max_left_top, p, p2, output;
2279
2/2
✓ Branch 2 → 3 taken 1366 times.
✓ Branch 2 → 4 taken 683 times.
2049 height = 16 >> (n ? h->c.chroma_y_shift : 0);
2280
2/2
✓ Branch 5 → 6 taken 1366 times.
✓ Branch 5 → 7 taken 683 times.
2049 w = 16 >> (n ? h->c.chroma_x_shift : 0);
2281
2282 2049 block_mean = get_bits(&h->gb, h->c.avctx->bits_per_raw_sample);
2283
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 12 taken 2049 times.
2049 if (block_mean == 0){
2284 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden block_mean\n");
2285 ✗ return AVERROR_INVALIDDATA;
2286 }
2287 2049 h->last_dc[n] = block_mean * (1 << (ctx->dct_precision + h->c.intra_dc_precision));
2288
2289 2049 rice_parameter = get_bits(&h->gb, 4);
2290
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 2049 times.
2049 if (rice_parameter == 0) {
2291 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
2292 ✗ return AVERROR_INVALIDDATA;
2293 }
2294
2295
2/2
✓ Branch 16 → 17 taken 329 times.
✓ Branch 16 → 18 taken 1720 times.
2049 if (rice_parameter == 15)
2296 329 rice_parameter = 0;
2297
2298
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 21 taken 2049 times.
2049 if (rice_parameter > 11) {
2299 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_parameter\n");
2300 ✗ return AVERROR_INVALIDDATA;
2301 }
2302
2303
2/2
✓ Branch 48 → 22 taken 32784 times.
✓ Branch 48 → 49 taken 2049 times.
34833 for (int i = 0; i < height; i++) {
2304 32784 output = 1 << (h->c.avctx->bits_per_raw_sample - 1);
2305 32784 top = 1 << (h->c.avctx->bits_per_raw_sample - 1);
2306
2307
2/2
✓ Branch 46 → 23 taken 349696 times.
✓ Branch 46 → 47 taken 32784 times.
382480 for (j = 0; j < w; j++) {
2308 349696 left = output;
2309 349696 topleft = top;
2310
2311 349696 rice_prefix_code = get_unary(&h->gb, 1, 12);
2312
2313 /* Escape */
2314
2/2
✓ Branch 24 → 25 taken 3815 times.
✓ Branch 24 → 27 taken 345881 times.
349696 if (rice_prefix_code == 11)
2315 3815 dpcm_residual = get_bits(&h->gb, h->c.avctx->bits_per_raw_sample);
2316 else {
2317
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 30 taken 345881 times.
345881 if (rice_prefix_code == 12) {
2318 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "Forbidden rice_prefix_code\n");
2319 ✗ return AVERROR_INVALIDDATA;
2320 }
2321 345881 rice_suffix_code = get_bitsz(&h->gb, rice_parameter);
2322 345881 dpcm_residual = (rice_prefix_code << rice_parameter) + rice_suffix_code;
2323 }
2324
2325 /* Map to a signed residual */
2326
2/2
✓ Branch 32 → 33 taken 94792 times.
✓ Branch 32 → 34 taken 254904 times.
349696 if (dpcm_residual & 1)
2327 94792 dpcm_residual = (-1 * dpcm_residual) >> 1;
2328 else
2329 254904 dpcm_residual = (dpcm_residual >> 1);
2330
2331
2/2
✓ Branch 35 → 36 taken 327840 times.
✓ Branch 35 → 37 taken 21856 times.
349696 if (i != 0)
2332 327840 top = macroblock[idx-w];
2333
2334 349696 p = left + top - topleft;
2335 349696 min_left_top = FFMIN(left, top);
2336
2/2
✓ Branch 37 → 38 taken 44503 times.
✓ Branch 37 → 39 taken 305193 times.
349696 if (p < min_left_top)
2337 44503 p = min_left_top;
2338
2339 349696 max_left_top = FFMAX(left, top);
2340
2/2
✓ Branch 39 → 40 taken 42683 times.
✓ Branch 39 → 41 taken 307013 times.
349696 if (p > max_left_top)
2341 42683 p = max_left_top;
2342
2343 349696 p2 = (FFMIN(min_left_top, topleft) + FFMAX(max_left_top, topleft)) >> 1;
2344
2/2
✓ Branch 41 → 42 taken 67194 times.
✓ Branch 41 → 43 taken 282502 times.
349696 if (p2 == p)
2345 67194 p2 = block_mean;
2346
2347
2/2
✓ Branch 43 → 44 taken 174738 times.
✓ Branch 43 → 45 taken 174958 times.
349696 if (p2 > p)
2348 174738 dpcm_residual *= -1;
2349
2350 349696 macroblock[idx++] = output = (dpcm_residual + p) & ((1 << h->c.avctx->bits_per_raw_sample) - 1);
2351 }
2352 }
2353
2354 2049 return 0;
2355 }
2356
2357 1350 static int mpeg4_decode_studio_mb(H263DecContext *const h)
2358 {
2359 1350 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
2360 int i;
2361
2362 1350 ctx->dpcm_direction = 0;
2363
2364 /* StudioMacroblock */
2365 /* Assumes I-VOP */
2366 1350 h->c.mb_intra = 1;
2367
2/2
✓ Branch 4 → 5 taken 667 times.
✓ Branch 4 → 16 taken 683 times.
1350 if (get_bits1(&h->gb)) { /* compression_mode */
2368 /* DCT */
2369 /* macroblock_type, 1 or 2-bit VLC */
2370
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 10 taken 667 times.
667 if (!get_bits1(&h->gb)) {
2371 ✗ skip_bits1(&h->gb);
2372 ✗ h->c.qscale = mpeg_get_qscale(&h->gb, h->c.q_scale_type);
2373 }
2374
2375
2/2
✓ Branch 15 → 11 taken 5336 times.
✓ Branch 15 → 27 taken 667 times.
6003 for (i = 0; i < mpeg4_block_count[h->c.chroma_format]; i++) {
2376
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 5336 times.
5336 if (mpeg4_decode_studio_block(ctx, ctx->block32[i], i) < 0)
2377 ✗ return AVERROR_INVALIDDATA;
2378 }
2379 } else {
2380 /* DPCM */
2381 683 check_marker(h->c.avctx, &h->gb, "DPCM block start");
2382
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 683 times.
683 ctx->dpcm_direction = get_bits1(&h->gb) ? -1 : 1;
2383
2/2
✓ Branch 26 → 22 taken 2049 times.
✓ Branch 26 → 27 taken 683 times.
2732 for (i = 0; i < 3; i++) {
2384
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 2049 times.
2049 if (mpeg4_decode_dpcm_macroblock(ctx, ctx->dpcm_macroblock[i], i) < 0)
2385 ✗ return AVERROR_INVALIDDATA;
2386 }
2387 }
2388
2389
4/4
✓ Branch 28 → 29 taken 1349 times.
✓ Branch 28 → 33 taken 1 time.
✓ Branch 30 → 31 taken 29 times.
✓ Branch 30 → 33 taken 1320 times.
1350 if (get_bits_left(&h->gb) >= 24 && show_bits(&h->gb, 23) == 0) {
2390 29 next_start_code_studio(&h->gb);
2391 29 return SLICE_END;
2392 }
2393
2394 //vcon-stp9L1.bits (first frame)
2395
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 1321 times.
1321 if (get_bits_left(&h->gb) == 0)
2396 ✗ return SLICE_END;
2397
2398 //vcon-stp2L1.bits, vcon-stp3L1.bits, vcon-stp6L1.bits, vcon-stp7L1.bits, vcon-stp8L1.bits, vcon-stp10L1.bits (first frame)
2399
3/4
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 42 taken 1320 times.
✓ Branch 40 → 41 taken 1 time.
✗ Branch 40 → 42 not taken.
1321 if (get_bits_left(&h->gb) < 8U && show_bits(&h->gb, get_bits_left(&h->gb)) == 0)
2400 1 return SLICE_END;
2401
2402 1320 return SLICE_OK;
2403 }
2404
2405 1023 static int mpeg4_decode_gop_header(MpegEncContext *s, GetBitContext *gb)
2406 {
2407 int hours, minutes, seconds;
2408
2409
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 1023 times.
1023 if (!show_bits(gb, 23)) {
2410 ✗ av_log(s->avctx, AV_LOG_WARNING, "GOP header invalid\n");
2411 ✗ return AVERROR_INVALIDDATA;
2412 }
2413
2414 1023 hours = get_bits(gb, 5);
2415 1023 minutes = get_bits(gb, 6);
2416 1023 check_marker(s->avctx, gb, "in gop_header");
2417 1023 seconds = get_bits(gb, 6);
2418
2419 1023 s->time_base = seconds + 60*(minutes + 60*hours);
2420
2421 1023 skip_bits1(gb);
2422 1023 skip_bits1(gb);
2423
2424 1023 return 0;
2425 }
2426
2427 1224 static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb, int *profile, int *level)
2428 {
2429
2430 1224 *profile = get_bits(gb, 4);
2431 1224 *level = get_bits(gb, 4);
2432
2433 // for Simple profile, level 0
2434
3/4
✓ Branch 4 → 5 taken 717 times.
✓ Branch 4 → 7 taken 507 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 717 times.
1224 if (*profile == 0 && *level == 8) {
2435 ✗ *level = 0;
2436 }
2437
2438 1224 return 0;
2439 }
2440
2441 1224 static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
2442 {
2443 int visual_object_type;
2444 1224 int is_visual_object_identifier = get_bits1(gb);
2445
2446
2/2
✓ Branch 3 → 4 taken 1198 times.
✓ Branch 3 → 5 taken 26 times.
1224 if (is_visual_object_identifier) {
2447 1198 skip_bits(gb, 4+3);
2448 }
2449 1224 visual_object_type = get_bits(gb, 4);
2450
2451
1/4
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 1224 times.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 34 not taken.
1224 if (visual_object_type == VOT_VIDEO_ID ||
2452 visual_object_type == VOT_STILL_TEXTURE_ID) {
2453 1224 int video_signal_type = get_bits1(gb);
2454
2/2
✓ Branch 9 → 10 taken 4 times.
✓ Branch 9 → 34 taken 1220 times.
1224 if (video_signal_type) {
2455 int video_range, color_description;
2456 4 skip_bits(gb, 3); // video_format
2457 4 video_range = get_bits1(gb);
2458 4 color_description = get_bits1(gb);
2459
2460
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 4 times.
4 s->avctx->color_range = video_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
2461
2462
1/2
✓ Branch 16 → 17 taken 4 times.
✗ Branch 16 → 34 not taken.
4 if (color_description) {
2463 4 s->avctx->color_primaries = get_bits(gb, 8);
2464 4 s->avctx->color_trc = get_bits(gb, 8);
2465 4 s->avctx->colorspace = get_bits(gb, 8);
2466
2467 // Reserved and unassigned values carry no colour information
2468
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 24 taken 4 times.
4 if (s->avctx->color_primaries == AVCOL_PRI_RESERVED0 ||
2469
0/4
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 24 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
✗ s->avctx->color_primaries == AVCOL_PRI_RESERVED ||
2470 ✗ !av_color_primaries_name(s->avctx->color_primaries))
2471 4 s->avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;
2472
1/2
✓ Branch 25 → 26 taken 4 times.
✗ Branch 25 → 29 not taken.
4 if (s->avctx->color_trc == AVCOL_TRC_RESERVED0 ||
2473
1/4
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 29 taken 4 times.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 30 not taken.
4 s->avctx->color_trc == AVCOL_TRC_RESERVED ||
2474 ✗ !av_color_transfer_name(s->avctx->color_trc))
2475 4 s->avctx->color_trc = AVCOL_TRC_UNSPECIFIED;
2476
1/4
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 33 taken 4 times.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
4 if (s->avctx->colorspace == AVCOL_SPC_RESERVED ||
2477 ✗ !av_color_space_name(s->avctx->colorspace))
2478 4 s->avctx->colorspace = AVCOL_SPC_UNSPECIFIED;
2479 }
2480 }
2481 }
2482
2483 1224 return 0;
2484 }
2485
2486 110 static void mpeg4_load_default_matrices(MpegEncContext *s)
2487 {
2488 int i, v;
2489
2490 /* load default matrices */
2491
2/2
✓ Branch 4 → 3 taken 7040 times.
✓ Branch 4 → 5 taken 110 times.
7150 for (i = 0; i < 64; i++) {
2492 7040 int j = s->idsp.idct_permutation[i];
2493 7040 v = ff_mpeg4_default_intra_matrix[i];
2494 7040 s->intra_matrix[j] = v;
2495 7040 s->chroma_intra_matrix[j] = v;
2496
2497 7040 v = ff_mpeg4_default_non_intra_matrix[i];
2498 7040 s->inter_matrix[j] = v;
2499 7040 s->chroma_inter_matrix[j] = v;
2500 }
2501 110 }
2502
2503 ✗ static int read_quant_matrix_ext(MpegEncContext *s, GetBitContext *gb)
2504 {
2505 int i, j, v;
2506
2507
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 11 not taken.
✗ if (get_bits1(gb)) {
2508
0/2
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ if (get_bits_left(gb) < 64*8)
2509 ✗ return AVERROR_INVALIDDATA;
2510 /* intra_quantiser_matrix */
2511
0/2
✗ Branch 10 → 8 not taken.
✗ Branch 10 → 11 not taken.
✗ for (i = 0; i < 64; i++) {
2512 ✗ v = get_bits(gb, 8);
2513 ✗ j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
2514 ✗ s->intra_matrix[j] = v;
2515 ✗ s->chroma_intra_matrix[j] = v;
2516 }
2517 }
2518
2519
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 20 not taken.
✗ if (get_bits1(gb)) {
2520
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 16 not taken.
✗ if (get_bits_left(gb) < 64*8)
2521 ✗ return AVERROR_INVALIDDATA;
2522 /* non_intra_quantiser_matrix */
2523
0/2
✗ Branch 19 → 17 not taken.
✗ Branch 19 → 20 not taken.
✗ for (i = 0; i < 64; i++) {
2524 ✗ get_bits(gb, 8);
2525 }
2526 }
2527
2528
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 29 not taken.
✗ if (get_bits1(gb)) {
2529
0/2
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
✗ if (get_bits_left(gb) < 64*8)
2530 ✗ return AVERROR_INVALIDDATA;
2531 /* chroma_intra_quantiser_matrix */
2532
0/2
✗ Branch 28 → 26 not taken.
✗ Branch 28 → 29 not taken.
✗ for (i = 0; i < 64; i++) {
2533 ✗ v = get_bits(gb, 8);
2534 ✗ j = s->idsp.idct_permutation[ff_zigzag_direct[i]];
2535 ✗ s->chroma_intra_matrix[j] = v;
2536 }
2537 }
2538
2539
0/2
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 38 not taken.
✗ if (get_bits1(gb)) {
2540
0/2
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
✗ if (get_bits_left(gb) < 64*8)
2541 ✗ return AVERROR_INVALIDDATA;
2542 /* chroma_non_intra_quantiser_matrix */
2543
0/2
✗ Branch 37 → 35 not taken.
✗ Branch 37 → 38 not taken.
✗ for (i = 0; i < 64; i++) {
2544 ✗ get_bits(gb, 8);
2545 }
2546 }
2547
2548 ✗ next_start_code_studio(gb);
2549 ✗ return 0;
2550 }
2551
2552 5 static void extension_and_user_data(MpegEncContext *s, GetBitContext *gb, int id)
2553 {
2554 uint32_t startcode;
2555 uint8_t extension_type;
2556
2557 5 startcode = show_bits_long(gb, 32);
2558
2/4
✓ Branch 3 → 4 taken 5 times.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 12 taken 5 times.
5 if (startcode == USER_DATA_STARTCODE || startcode == EXT_STARTCODE) {
2559
2560
0/6
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 12 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 12 not taken.
✗ if ((id == 2 || id == 4) && startcode == EXT_STARTCODE) {
2561 ✗ skip_bits_long(gb, 32);
2562 ✗ extension_type = get_bits(gb, 4);
2563
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
✗ if (extension_type == QUANT_MATRIX_EXT_ID)
2564 ✗ read_quant_matrix_ext(s, gb);
2565 }
2566 }
2567 5 }
2568
2569 3 static int decode_studio_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
2570 {
2571 3 MPVContext *const s = &ctx->h.c;
2572 int width, height, aspect_ratio_info;
2573 int bits_per_raw_sample;
2574 int rgb, chroma_format;
2575
2576 // random_accessible_vol and video_object_type_indication have already
2577 // been read by the caller decode_vol_header()
2578 3 skip_bits(gb, 4); /* video_object_layer_verid */
2579 3 ctx->shape = get_bits(gb, 2); /* video_object_layer_shape */
2580 3 skip_bits(gb, 4); /* video_object_layer_shape_extension */
2581 3 skip_bits1(gb); /* progressive_sequence */
2582
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 9 taken 3 times.
3 if (ctx->shape != RECT_SHAPE) {
2583 ✗ avpriv_request_sample(s->avctx, "MPEG-4 Studio profile non rectangular shape");
2584 ✗ return AVERROR_PATCHWELCOME;
2585 }
2586
1/2
✓ Branch 9 → 10 taken 3 times.
✗ Branch 9 → 32 not taken.
3 if (ctx->shape != BIN_ONLY_SHAPE) {
2587 3 rgb = get_bits1(gb); /* rgb_components */
2588 3 chroma_format = get_bits(gb, 2); /* chroma_format */
2589
3/8
✓ Branch 12 → 13 taken 3 times.
✗ Branch 12 → 16 not taken.
✓ Branch 13 → 14 taken 3 times.
✗ Branch 13 → 16 not taken.
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 18 taken 3 times.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 18 not taken.
3 if (!chroma_format || chroma_format == CHROMA_420 || (rgb && chroma_format == CHROMA_422)) {
2590 ✗ av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n");
2591 ✗ return AVERROR_INVALIDDATA;
2592 }
2593
2594 3 bits_per_raw_sample = get_bits(gb, 4); /* bit_depth */
2595
1/2
✓ Branch 19 → 20 taken 3 times.
✗ Branch 19 → 26 not taken.
3 if (bits_per_raw_sample == 10) {
2596
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 3 times.
3 if (rgb) {
2597 ✗ s->avctx->pix_fmt = AV_PIX_FMT_GBRP10;
2598 } else {
2599
1/2
✓ Branch 22 → 23 taken 3 times.
✗ Branch 22 → 24 not taken.
3 s->avctx->pix_fmt = chroma_format == CHROMA_422 ? AV_PIX_FMT_YUV422P10 : AV_PIX_FMT_YUV444P10;
2600 }
2601 } else {
2602 ✗ avpriv_request_sample(s->avctx, "MPEG-4 Studio profile bit-depth %u", bits_per_raw_sample);
2603 ✗ return AVERROR_PATCHWELCOME;
2604 }
2605
3/4
✓ Branch 28 → 29 taken 3 times.
✗ Branch 28 → 30 not taken.
✓ Branch 29 → 30 taken 2 times.
✓ Branch 29 → 31 taken 1 time.
3 if (rgb != ctx->rgb || s->chroma_format != chroma_format)
2606 2 s->context_reinit = 1;
2607 3 s->avctx->bits_per_raw_sample = bits_per_raw_sample;
2608 3 ctx->rgb = rgb;
2609 3 s->chroma_format = chroma_format;
2610 }
2611
1/2
✓ Branch 32 → 33 taken 3 times.
✗ Branch 32 → 46 not taken.
3 if (ctx->shape == RECT_SHAPE) {
2612 3 check_marker(s->avctx, gb, "before video_object_layer_width");
2613 3 width = get_bits(gb, 14); /* video_object_layer_width */
2614 3 check_marker(s->avctx, gb, "before video_object_layer_height");
2615 3 height = get_bits(gb, 14); /* video_object_layer_height */
2616 3 check_marker(s->avctx, gb, "after video_object_layer_height");
2617
2618 /* Do the same check as non-studio profile */
2619
2/4
✓ Branch 38 → 39 taken 3 times.
✗ Branch 38 → 46 not taken.
✓ Branch 39 → 40 taken 3 times.
✗ Branch 39 → 46 not taken.
3 if (width && height) {
2620
3/4
✓ Branch 40 → 41 taken 2 times.
✓ Branch 40 → 45 taken 1 time.
✓ Branch 41 → 42 taken 2 times.
✗ Branch 41 → 45 not taken.
3 if (s->width && s->height &&
2621
2/4
✓ Branch 42 → 43 taken 2 times.
✗ Branch 42 → 44 not taken.
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 45 taken 2 times.
2 (s->width != width || s->height != height))
2622 ✗ s->context_reinit = 1;
2623 3 s->width = width;
2624 3 s->height = height;
2625 }
2626 }
2627 3 aspect_ratio_info = get_bits(gb, 4);
2628
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 51 taken 3 times.
3 if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
2629 ✗ s->avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width
2630 ✗ s->avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height
2631 } else {
2632 3 s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[aspect_ratio_info];
2633 }
2634 3 skip_bits(gb, 4); /* frame_rate_code */
2635 3 skip_bits(gb, 15); /* first_half_bit_rate */
2636 3 check_marker(s->avctx, gb, "after first_half_bit_rate");
2637 3 skip_bits(gb, 15); /* latter_half_bit_rate */
2638 3 check_marker(s->avctx, gb, "after latter_half_bit_rate");
2639 3 skip_bits(gb, 15); /* first_half_vbv_buffer_size */
2640 3 check_marker(s->avctx, gb, "after first_half_vbv_buffer_size");
2641 3 skip_bits(gb, 3); /* latter_half_vbv_buffer_size */
2642 3 skip_bits(gb, 11); /* first_half_vbv_buffer_size */
2643 3 check_marker(s->avctx, gb, "after first_half_vbv_buffer_size");
2644 3 skip_bits(gb, 15); /* latter_half_vbv_occupancy */
2645 3 check_marker(s->avctx, gb, "after latter_half_vbv_occupancy");
2646 3 s->low_delay = get_bits1(gb);
2647 3 ctx->mpeg_quant = get_bits1(gb); /* mpeg2_stream */
2648
2649 3 next_start_code_studio(gb);
2650 3 extension_and_user_data(s, gb, 2);
2651
2652 3 return 0;
2653 }
2654
2655 1257 static int decode_vol_header(Mpeg4DecContext *ctx, GetBitContext *gb)
2656 {
2657 1257 H263DecContext *const h = &ctx->h;
2658 int width, height, vo_ver_id, aspect_ratio_info;
2659
2660 /* vol header */
2661 1257 skip_bits(gb, 1); /* random access */
2662 1257 ctx->vo_type = get_bits(gb, 8);
2663
2664 /* If we are in studio profile (per vo_type), check if its all consistent
2665 * and if so continue pass control to decode_studio_vol_header().
2666 * elIf something is inconsistent, error out
2667 * else continue with (non studio) vol header decpoding.
2668 */
2669
2/2
✓ Branch 4 → 5 taken 1254 times.
✓ Branch 4 → 6 taken 3 times.
1257 if (ctx->vo_type == CORE_STUDIO_VO_TYPE ||
2670
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 11 taken 1254 times.
1254 ctx->vo_type == SIMPLE_STUDIO_VO_TYPE) {
2671
3/4
✓ Branch 6 → 7 taken 2 times.
✓ Branch 6 → 9 taken 1 time.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 2 times.
3 if (h->c.avctx->profile != AV_PROFILE_UNKNOWN && h->c.avctx->profile != AV_PROFILE_MPEG4_SIMPLE_STUDIO)
2672 ✗ return AVERROR_INVALIDDATA;
2673 3 h->c.studio_profile = 1;
2674 3 h->c.avctx->profile = AV_PROFILE_MPEG4_SIMPLE_STUDIO;
2675 3 return decode_studio_vol_header(ctx, gb);
2676
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 1254 times.
1254 } else if (h->c.studio_profile) {
2677 ✗ return AVERROR_PATCHWELCOME;
2678 }
2679
2680
2/2
✓ Branch 14 → 15 taken 1226 times.
✓ Branch 14 → 17 taken 28 times.
1254 if (get_bits1(gb) != 0) { /* is_ol_id */
2681 1226 vo_ver_id = get_bits(gb, 4); /* vo_ver_id */
2682 1226 skip_bits(gb, 3); /* vo_priority */
2683 } else {
2684 28 vo_ver_id = 1;
2685 }
2686 1254 aspect_ratio_info = get_bits(gb, 4);
2687
2/2
✓ Branch 19 → 20 taken 2 times.
✓ Branch 19 → 23 taken 1252 times.
1254 if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
2688 2 h->c.avctx->sample_aspect_ratio.num = get_bits(gb, 8); // par_width
2689 2 h->c.avctx->sample_aspect_ratio.den = get_bits(gb, 8); // par_height
2690 } else {
2691 1252 h->c.avctx->sample_aspect_ratio = ff_h263_pixel_aspect[aspect_ratio_info];
2692 }
2693
2694
2/2
✓ Branch 25 → 26 taken 1217 times.
✓ Branch 25 → 43 taken 37 times.
1254 if ((ctx->vol_control_parameters = get_bits1(gb))) { /* vol control parameter */
2695 1217 int chroma_format = get_bits(gb, 2);
2696
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 1217 times.
1217 if (chroma_format != CHROMA_420)
2697 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "illegal chroma format\n");
2698
2699 1217 h->c.low_delay = get_bits1(gb);
2700
1/2
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 47 taken 1217 times.
1217 if (get_bits1(gb)) { /* vbv parameters */
2701 ✗ get_bits(gb, 15); /* first_half_bitrate */
2702 ✗ check_marker(h->c.avctx, gb, "after first_half_bitrate");
2703 ✗ get_bits(gb, 15); /* latter_half_bitrate */
2704 ✗ check_marker(h->c.avctx, gb, "after latter_half_bitrate");
2705 ✗ get_bits(gb, 15); /* first_half_vbv_buffer_size */
2706 ✗ check_marker(h->c.avctx, gb, "after first_half_vbv_buffer_size");
2707 ✗ get_bits(gb, 3); /* latter_half_vbv_buffer_size */
2708 ✗ get_bits(gb, 11); /* first_half_vbv_occupancy */
2709 ✗ check_marker(h->c.avctx, gb, "after first_half_vbv_occupancy");
2710 ✗ get_bits(gb, 15); /* latter_half_vbv_occupancy */
2711 ✗ check_marker(h->c.avctx, gb, "after latter_half_vbv_occupancy");
2712 }
2713 } else {
2714 /* is setting low delay flag only once the smartest thing to do?
2715 * low delay detection will not be overridden. */
2716
2/2
✓ Branch 43 → 44 taken 8 times.
✓ Branch 43 → 47 taken 29 times.
37 if (h->picture_number == 0) {
2717
2/2
✓ Branch 44 → 45 taken 4 times.
✓ Branch 44 → 46 taken 4 times.
8 switch (ctx->vo_type) {
2718 4 case SIMPLE_VO_TYPE:
2719 case ADV_SIMPLE_VO_TYPE:
2720 4 h->c.low_delay = 1;
2721 4 break;
2722 4 default:
2723 4 h->c.low_delay = 0;
2724 }
2725 }
2726 }
2727
2728 1254 ctx->shape = get_bits(gb, 2); /* vol shape */
2729
1/2
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 50 taken 1254 times.
1254 if (ctx->shape != RECT_SHAPE)
2730 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "only rectangular vol supported\n");
2731
1/4
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 54 taken 1254 times.
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 54 not taken.
1254 if (ctx->shape == GRAY_SHAPE && vo_ver_id != 1) {
2732 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "Gray shape not supported\n");
2733 ✗ skip_bits(gb, 4); /* video_object_layer_shape_extension */
2734 }
2735
2736 1254 check_marker(h->c.avctx, gb, "before time_increment_resolution");
2737
2738 1254 h->c.avctx->framerate.num = get_bits(gb, 16);
2739
1/2
✗ Branch 56 → 57 not taken.
✓ Branch 56 → 59 taken 1254 times.
1254 if (!h->c.avctx->framerate.num) {
2740 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "framerate==0\n");
2741 ✗ return AVERROR_INVALIDDATA;
2742 }
2743
2744 1254 ctx->time_increment_bits = av_log2(h->c.avctx->framerate.num - 1) + 1;
2745
1/2
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 1254 times.
1254 if (ctx->time_increment_bits < 1)
2746 ✗ ctx->time_increment_bits = 1;
2747
2748 1254 check_marker(h->c.avctx, gb, "before fixed_vop_rate");
2749
2750
2/2
✓ Branch 63 → 64 taken 19 times.
✓ Branch 63 → 66 taken 1235 times.
1254 if (get_bits1(gb) != 0) /* fixed_vop_rate */
2751 19 h->c.avctx->framerate.den = get_bits(gb, ctx->time_increment_bits);
2752 else
2753 1235 h->c.avctx->framerate.den = 1;
2754
2755 1254 ctx->t_frame = 0;
2756
2757
1/2
✓ Branch 67 → 68 taken 1254 times.
✗ Branch 67 → 254 not taken.
1254 if (ctx->shape != BIN_ONLY_SHAPE) {
2758
1/2
✓ Branch 68 → 69 taken 1254 times.
✗ Branch 68 → 84 not taken.
1254 if (ctx->shape == RECT_SHAPE) {
2759 1254 check_marker(h->c.avctx, gb, "before width");
2760 1254 width = get_bits(gb, 13);
2761 1254 check_marker(h->c.avctx, gb, "before height");
2762 1254 height = get_bits(gb, 13);
2763 1254 check_marker(h->c.avctx, gb, "after height");
2764
2/4
✓ Branch 74 → 75 taken 1254 times.
✗ Branch 74 → 84 not taken.
✓ Branch 75 → 76 taken 1254 times.
✗ Branch 75 → 84 not taken.
1254 if (width && height && /* they should be non zero but who knows */
2765
3/4
✓ Branch 76 → 77 taken 888 times.
✓ Branch 76 → 78 taken 366 times.
✓ Branch 77 → 78 taken 888 times.
✗ Branch 77 → 84 not taken.
1254 !(h->c.width && h->c.codec_tag == AV_RL32("MP4S"))) {
2766
3/4
✓ Branch 78 → 79 taken 888 times.
✓ Branch 78 → 83 taken 366 times.
✓ Branch 79 → 80 taken 888 times.
✗ Branch 79 → 83 not taken.
1254 if (h->c.width && h->c.height &&
2767
3/4
✓ Branch 80 → 81 taken 868 times.
✓ Branch 80 → 82 taken 20 times.
✗ Branch 81 → 82 not taken.
✓ Branch 81 → 83 taken 868 times.
888 (h->c.width != width || h->c.height != height))
2768 20 h->c.context_reinit = 1;
2769 1254 h->c.width = width;
2770 1254 h->c.height = height;
2771 }
2772 }
2773
2774 1254 h->c.progressive_sequence =
2775 1254 h->c.progressive_frame = get_bits1(gb) ^ 1;
2776 1254 h->c.interlaced_dct = 0;
2777
1/4
✗ Branch 86 → 87 not taken.
✓ Branch 86 → 89 taken 1254 times.
✗ Branch 87 → 88 not taken.
✗ Branch 87 → 89 not taken.
1254 if (!get_bits1(gb) && (h->c.avctx->debug & FF_DEBUG_PICT_INFO))
2778 ✗ av_log(h->c.avctx, AV_LOG_INFO, /* OBMC Disable */
2779 "MPEG-4 OBMC not supported (very likely buggy encoder)\n");
2780
2/2
✓ Branch 89 → 90 taken 763 times.
✓ Branch 89 → 92 taken 491 times.
1254 if (vo_ver_id == 1)
2781 763 ctx->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */
2782 else
2783 491 ctx->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */
2784
2785
1/2
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 1254 times.
1254 if (ctx->vol_sprite_usage == STATIC_SPRITE)
2786 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "Static Sprites not supported\n");
2787
1/2
✓ Branch 96 → 97 taken 1254 times.
✗ Branch 96 → 98 not taken.
1254 if (ctx->vol_sprite_usage == STATIC_SPRITE ||
2788
1/2
✗ Branch 97 → 98 not taken.
✓ Branch 97 → 115 taken 1254 times.
1254 ctx->vol_sprite_usage == GMC_SPRITE) {
2789
0/2
✗ Branch 98 → 99 not taken.
✗ Branch 98 → 107 not taken.
✗ if (ctx->vol_sprite_usage == STATIC_SPRITE) {
2790 ✗ skip_bits(gb, 13); // sprite_width
2791 ✗ check_marker(h->c.avctx, gb, "after sprite_width");
2792 ✗ skip_bits(gb, 13); // sprite_height
2793 ✗ check_marker(h->c.avctx, gb, "after sprite_height");
2794 ✗ skip_bits(gb, 13); // sprite_left
2795 ✗ check_marker(h->c.avctx, gb, "after sprite_left");
2796 ✗ skip_bits(gb, 13); // sprite_top
2797 ✗ check_marker(h->c.avctx, gb, "after sprite_top");
2798 }
2799 ✗ ctx->num_sprite_warping_points = get_bits(gb, 6);
2800
0/2
✗ Branch 108 → 109 not taken.
✗ Branch 108 → 111 not taken.
✗ if (ctx->num_sprite_warping_points > 3) {
2801 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
2802 "%d sprite_warping_points\n",
2803 ctx->num_sprite_warping_points);
2804 ✗ ctx->num_sprite_warping_points = 0;
2805 ✗ return AVERROR_INVALIDDATA;
2806 }
2807 ✗ ctx->sprite_warping_accuracy = get_bits(gb, 2);
2808 ✗ ctx->sprite_brightness_change = get_bits1(gb);
2809
0/2
✗ Branch 113 → 114 not taken.
✗ Branch 113 → 115 not taken.
✗ if (ctx->vol_sprite_usage == STATIC_SPRITE)
2810 ✗ skip_bits1(gb); // low_latency_sprite
2811 }
2812 // FIXME sadct disable bit if verid!=1 && shape not rect
2813
2814
1/2
✗ Branch 116 → 117 not taken.
✓ Branch 116 → 126 taken 1254 times.
1254 if (get_bits1(gb) == 1) { /* not_8_bit */
2815 ✗ ctx->quant_precision = get_bits(gb, 4); /* quant_precision */
2816
0/2
✗ Branch 119 → 120 not taken.
✗ Branch 119 → 121 not taken.
✗ if (get_bits(gb, 4) != 8) /* bits_per_pixel */
2817 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "N-bit not supported\n");
2818
0/2
✗ Branch 121 → 122 not taken.
✗ Branch 121 → 123 not taken.
✗ if (ctx->quant_precision != 5)
2819 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
2820 "quant precision %d\n", ctx->quant_precision);
2821
0/4
✗ Branch 123 → 124 not taken.
✗ Branch 123 → 125 not taken.
✗ Branch 124 → 125 not taken.
✗ Branch 124 → 127 not taken.
✗ if (ctx->quant_precision < 3 || ctx->quant_precision > 9)
2822 ✗ ctx->quant_precision = 5;
2823 } else {
2824 1254 ctx->quant_precision = 5;
2825 }
2826
2827 // FIXME a bunch of grayscale shape things
2828
2829
2/2
✓ Branch 128 → 129 taken 108 times.
✓ Branch 128 → 160 taken 1146 times.
1254 if ((ctx->mpeg_quant = get_bits1(gb))) { /* vol_quant_type */
2830 int i, v;
2831
2832 108 mpeg4_load_default_matrices(&h->c);
2833
2834 /* load custom intra matrix */
2835
2/2
✓ Branch 131 → 132 taken 8 times.
✓ Branch 131 → 145 taken 100 times.
108 if (get_bits1(gb)) {
2836 8 int last = 0;
2837
1/2
✓ Branch 141 → 133 taken 240 times.
✗ Branch 141 → 142 not taken.
240 for (i = 0; i < 64; i++) {
2838 int j;
2839
1/2
✗ Branch 134 → 135 not taken.
✓ Branch 134 → 137 taken 240 times.
240 if (get_bits_left(gb) < 8) {
2840 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
2841 ✗ return AVERROR_INVALIDDATA;
2842 }
2843 240 v = get_bits(gb, 8);
2844
2/2
✓ Branch 138 → 139 taken 8 times.
✓ Branch 138 → 140 taken 232 times.
240 if (v == 0)
2845 8 break;
2846
2847 232 last = v;
2848 232 j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
2849 232 h->c.intra_matrix[j] = last;
2850 }
2851
2852 /* replicate last value */
2853
2/2
✓ Branch 144 → 143 taken 280 times.
✓ Branch 144 → 145 taken 8 times.
288 for (; i < 64; i++) {
2854 280 int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
2855 280 h->c.intra_matrix[j] = last;
2856 }
2857 }
2858
2859 /* load custom non intra matrix */
2860
2/2
✓ Branch 146 → 147 taken 8 times.
✓ Branch 146 → 160 taken 100 times.
108 if (get_bits1(gb)) {
2861 8 int last = 0;
2862
1/2
✓ Branch 156 → 148 taken 240 times.
✗ Branch 156 → 157 not taken.
240 for (i = 0; i < 64; i++) {
2863 int j;
2864
1/2
✗ Branch 149 → 150 not taken.
✓ Branch 149 → 152 taken 240 times.
240 if (get_bits_left(gb) < 8) {
2865 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "insufficient data for custom matrix\n");
2866 ✗ return AVERROR_INVALIDDATA;
2867 }
2868 240 v = get_bits(gb, 8);
2869
2/2
✓ Branch 153 → 154 taken 8 times.
✓ Branch 153 → 155 taken 232 times.
240 if (v == 0)
2870 8 break;
2871
2872 232 last = v;
2873 232 j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
2874 232 h->c.inter_matrix[j] = v;
2875 }
2876
2877 /* replicate last value */
2878
2/2
✓ Branch 159 → 158 taken 280 times.
✓ Branch 159 → 160 taken 8 times.
288 for (; i < 64; i++) {
2879 280 int j = h->c.idsp.idct_permutation[ff_zigzag_direct[i]];
2880 280 h->c.inter_matrix[j] = last;
2881 }
2882 }
2883
2884 // FIXME a bunch of grayscale shape things
2885 }
2886
2887
2/2
✓ Branch 160 → 161 taken 491 times.
✓ Branch 160 → 163 taken 763 times.
1254 if (vo_ver_id != 1)
2888 491 h->c.quarter_sample = get_bits1(gb);
2889 else
2890 763 h->c.quarter_sample = 0;
2891
2892
1/2
✗ Branch 165 → 166 not taken.
✓ Branch 165 → 168 taken 1254 times.
1254 if (get_bits_left(gb) < 4) {
2893 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "VOL Header truncated\n");
2894 ✗ return AVERROR_INVALIDDATA;
2895 }
2896
2897
1/2
✗ Branch 169 → 170 not taken.
✓ Branch 169 → 220 taken 1254 times.
1254 if (!get_bits1(gb)) {
2898 ✗ int pos = get_bits_count(gb);
2899 ✗ int estimation_method = get_bits(gb, 2);
2900
0/2
✗ Branch 172 → 173 not taken.
✗ Branch 172 → 219 not taken.
✗ if (estimation_method < 2) {
2901
0/2
✗ Branch 174 → 175 not taken.
✗ Branch 174 → 182 not taken.
✗ if (!get_bits1(gb)) {
2902 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* opaque */
2903 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* transparent */
2904 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* intra_cae */
2905 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* inter_cae */
2906 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* no_update */
2907 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* upsampling */
2908 }
2909
0/2
✗ Branch 183 → 184 not taken.
✗ Branch 183 → 189 not taken.
✗ if (!get_bits1(gb)) {
2910 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* intra_blocks */
2911 ✗ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter_blocks */
2912 ✗ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* inter4v_blocks */
2913 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* not coded blocks */
2914 }
2915
0/2
✗ Branch 190 → 191 not taken.
✗ Branch 190 → 194 not taken.
✗ if (!check_marker(h->c.avctx, gb, "in complexity estimation part 1")) {
2916 ✗ skip_bits_long(gb, pos - get_bits_count(gb));
2917 ✗ goto no_cplx_est;
2918 }
2919
0/2
✗ Branch 195 → 196 not taken.
✗ Branch 195 → 201 not taken.
✗ if (!get_bits1(gb)) {
2920 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* dct_coeffs */
2921 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* dct_lines */
2922 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* vlc_syms */
2923 ✗ ctx->cplx_estimation_trash_i += 4 * get_bits1(gb); /* vlc_bits */
2924 }
2925
0/2
✗ Branch 202 → 203 not taken.
✗ Branch 202 → 210 not taken.
✗ if (!get_bits1(gb)) {
2926 ✗ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* apm */
2927 ✗ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* npm */
2928 ✗ ctx->cplx_estimation_trash_b += 8 * get_bits1(gb); /* interpolate_mc_q */
2929 ✗ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* forwback_mc_q */
2930 ✗ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel2 */
2931 ✗ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* halfpel4 */
2932 }
2933
0/2
✗ Branch 211 → 212 not taken.
✗ Branch 211 → 215 not taken.
✗ if (!check_marker(h->c.avctx, gb, "in complexity estimation part 2")) {
2934 ✗ skip_bits_long(gb, pos - get_bits_count(gb));
2935 ✗ goto no_cplx_est;
2936 }
2937
0/2
✗ Branch 215 → 216 not taken.
✗ Branch 215 → 222 not taken.
✗ if (estimation_method == 1) {
2938 ✗ ctx->cplx_estimation_trash_i += 8 * get_bits1(gb); /* sadct */
2939 ✗ ctx->cplx_estimation_trash_p += 8 * get_bits1(gb); /* qpel */
2940 }
2941 } else
2942 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
2943 "Invalid Complexity estimation method %d\n",
2944 estimation_method);
2945 } else {
2946
2947 1254 no_cplx_est:
2948 1254 ctx->cplx_estimation_trash_i =
2949 1254 ctx->cplx_estimation_trash_p =
2950 1254 ctx->cplx_estimation_trash_b = 0;
2951 }
2952
2953 1254 ctx->resync_marker = !get_bits1(gb); /* resync_marker_disabled */
2954
2955 1254 h->data_partitioning = get_bits1(gb);
2956
2/2
✓ Branch 224 → 225 taken 273 times.
✓ Branch 224 → 227 taken 981 times.
1254 if (h->data_partitioning)
2957 273 ctx->rvlc = get_bits1(gb);
2958
2959
2/2
✓ Branch 227 → 228 taken 491 times.
✓ Branch 227 → 236 taken 763 times.
1254 if (vo_ver_id != 1) {
2960 491 ctx->new_pred = get_bits1(gb);
2961
1/2
✗ Branch 229 → 230 not taken.
✓ Branch 229 → 233 taken 491 times.
491 if (ctx->new_pred) {
2962 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "new pred not supported\n");
2963 ✗ skip_bits(gb, 2); /* requested upstream message type */
2964 ✗ skip_bits1(gb); /* newpred segment type */
2965 }
2966
1/2
✗ Branch 234 → 235 not taken.
✓ Branch 234 → 237 taken 491 times.
491 if (get_bits1(gb)) // reduced_res_vop
2967 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
2968 "reduced resolution VOP not supported\n");
2969 } else {
2970 763 ctx->new_pred = 0;
2971 }
2972
2973 1254 ctx->scalability = get_bits1(gb);
2974
2975
1/2
✗ Branch 238 → 239 not taken.
✓ Branch 238 → 254 taken 1254 times.
1254 if (ctx->scalability) {
2976 ✗ GetBitContext bak = *gb;
2977 int h_sampling_factor_n;
2978 int h_sampling_factor_m;
2979 int v_sampling_factor_n;
2980 int v_sampling_factor_m;
2981
2982 ✗ skip_bits1(gb); // hierarchy_type
2983 ✗ skip_bits(gb, 4); /* ref_layer_id */
2984 ✗ skip_bits1(gb); /* ref_layer_sampling_dir */
2985 ✗ h_sampling_factor_n = get_bits(gb, 5);
2986 ✗ h_sampling_factor_m = get_bits(gb, 5);
2987 ✗ v_sampling_factor_n = get_bits(gb, 5);
2988 ✗ v_sampling_factor_m = get_bits(gb, 5);
2989 ✗ ctx->enhancement_type = get_bits1(gb);
2990
2991
0/6
✗ Branch 247 → 248 not taken.
✗ Branch 247 → 251 not taken.
✗ Branch 248 → 249 not taken.
✗ Branch 248 → 251 not taken.
✗ Branch 249 → 250 not taken.
✗ Branch 249 → 251 not taken.
✗ if (h_sampling_factor_n == 0 || h_sampling_factor_m == 0 ||
2992
0/2
✗ Branch 250 → 251 not taken.
✗ Branch 250 → 252 not taken.
✗ v_sampling_factor_n == 0 || v_sampling_factor_m == 0) {
2993 /* illegal scalability header (VERY broken encoder),
2994 * trying to workaround */
2995 ✗ ctx->scalability = 0;
2996 ✗ *gb = bak;
2997 } else
2998 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "scalability not supported\n");
2999
3000 // bin shape stuff FIXME
3001 }
3002 }
3003
3004
1/2
✗ Branch 254 → 255 not taken.
✓ Branch 254 → 268 taken 1254 times.
1254 if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {
3005 ✗ av_log(h->c.avctx, AV_LOG_DEBUG, "tb %d/%d, tincrbits:%d, qp_prec:%d, ps:%d, low_delay:%d %s%s%s%s\n",
3006 ✗ h->c.avctx->framerate.den, h->c.avctx->framerate.num,
3007 ctx->time_increment_bits,
3008 ctx->quant_precision,
3009 h->c.progressive_sequence,
3010 h->c.low_delay,
3011
0/2
✗ Branch 264 → 265 not taken.
✗ Branch 264 → 266 not taken.
✗ ctx->scalability ? "scalability " :"" ,
3012
0/2
✗ Branch 261 → 262 not taken.
✗ Branch 261 → 263 not taken.
✗ h->c.quarter_sample ? "qpel " : "",
3013
0/2
✗ Branch 258 → 259 not taken.
✗ Branch 258 → 260 not taken.
✗ h->data_partitioning ? "partition " : "",
3014
0/2
✗ Branch 255 → 256 not taken.
✗ Branch 255 → 257 not taken.
✗ ctx->rvlc ? "rvlc " : ""
3015 );
3016 }
3017
3018 1254 return 0;
3019 }
3020
3021 /**
3022 * Decode the user data stuff in the header.
3023 * Also initializes divx/xvid/lavc_version/build.
3024 */
3025 90 static int decode_user_data(Mpeg4DecContext *ctx, GetBitContext *gb)
3026 {
3027 90 H263DecContext *const h = &ctx->h;
3028 char buf[256];
3029 int i;
3030 int e;
3031 90 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
3032 char last;
3033
3034
3/4
✓ Branch 8 → 9 taken 980 times.
✗ Branch 8 → 11 not taken.
✓ Branch 10 → 3 taken 944 times.
✓ Branch 10 → 11 taken 36 times.
980 for (i = 0; i < 255 && get_bits_count(gb) < gb->size_in_bits; i++) {
3035
2/2
✓ Branch 4 → 5 taken 54 times.
✓ Branch 4 → 6 taken 890 times.
944 if (show_bits(gb, 23) == 0)
3036 54 break;
3037 890 buf[i] = get_bits(gb, 8);
3038 }
3039 90 buf[i] = 0;
3040
3041 /* divx detection */
3042 90 e = sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &last);
3043
1/2
✓ Branch 11 → 12 taken 90 times.
✗ Branch 11 → 13 not taken.
90 if (e < 2)
3044 90 e = sscanf(buf, "DivX%db%d%c", &ver, &build, &last);
3045
2/2
✓ Branch 13 → 14 taken 10 times.
✓ Branch 13 → 19 taken 80 times.
90 if (e >= 2) {
3046 10 ctx->divx_version = ver;
3047 10 ctx->divx_build = build;
3048
2/4
✓ Branch 14 → 15 taken 10 times.
✗ Branch 14 → 17 not taken.
✓ Branch 15 → 16 taken 10 times.
✗ Branch 15 → 17 not taken.
10 h->divx_packed = e == 3 && last == 'p';
3049 }
3050
3051 /* libavcodec detection */
3052 90 e = sscanf(buf, "FFmpe%*[^b]b%d", &build) + 3;
3053
1/2
✓ Branch 19 → 20 taken 90 times.
✗ Branch 19 → 21 not taken.
90 if (e != 4)
3054 90 e = sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
3055
1/2
✓ Branch 21 → 22 taken 90 times.
✗ Branch 21 → 28 not taken.
90 if (e != 4) {
3056 90 e = sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3) + 1;
3057
2/2
✓ Branch 22 → 23 taken 33 times.
✓ Branch 22 → 28 taken 57 times.
90 if (e > 1) {
3058
3/6
✓ Branch 23 → 24 taken 33 times.
✗ Branch 23 → 26 not taken.
✓ Branch 24 → 25 taken 33 times.
✗ Branch 24 → 26 not taken.
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 27 taken 33 times.
33 if (ver > 0xFFU || ver2 > 0xFFU || ver3 > 0xFFU) {
3059 ✗ av_log(h->c.avctx, AV_LOG_WARNING,
3060 "Unknown Lavc version string encountered, %d.%d.%d; "
3061 "clamping sub-version values to 8-bits.\n",
3062 ver, ver2, ver3);
3063 }
3064 33 build = ((ver & 0xFF) << 16) + ((ver2 & 0xFF) << 8) + (ver3 & 0xFF);
3065 }
3066 }
3067
2/2
✓ Branch 28 → 29 taken 57 times.
✓ Branch 28 → 31 taken 33 times.
90 if (e != 4) {
3068
1/2
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 57 times.
57 if (strcmp(buf, "ffmpeg") == 0)
3069 ✗ ctx->lavc_build = 4600;
3070 }
3071
2/2
✓ Branch 31 → 32 taken 33 times.
✓ Branch 31 → 33 taken 57 times.
90 if (e == 4)
3072 33 ctx->lavc_build = build;
3073
3074 /* Xvid detection */
3075 90 e = sscanf(buf, "XviD%d", &build);
3076
2/2
✓ Branch 33 → 34 taken 19 times.
✓ Branch 33 → 35 taken 71 times.
90 if (e == 1)
3077 19 ctx->xvid_build = build;
3078
3079 90 return 0;
3080 }
3081
3082 10791 static int decode_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb,
3083 int parse_only)
3084 {
3085 10791 H263DecContext *const h = &ctx->h;
3086 int time_incr, time_increment;
3087 int64_t pts;
3088
3089 10791 h->c.mcsel = 0;
3090 10791 h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */
3091
3/4
✓ Branch 3 → 4 taken 1301 times.
✓ Branch 3 → 9 taken 9490 times.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 9 taken 1301 times.
10791 if (h->c.pict_type == AV_PICTURE_TYPE_B && h->c.low_delay &&
3092
0/4
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 9 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 9 not taken.
✗ ctx->vol_control_parameters == 0 && !(h->c.avctx->flags & AV_CODEC_FLAG_LOW_DELAY)) {
3093 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "low_delay flag set incorrectly, clearing it\n");
3094 ✗ h->c.low_delay = 0;
3095 }
3096
3097
4/4
✓ Branch 9 → 10 taken 1284 times.
✓ Branch 9 → 12 taken 9507 times.
✓ Branch 10 → 11 taken 1028 times.
✓ Branch 10 → 12 taken 256 times.
10791 h->partitioned_frame = h->data_partitioning && h->c.pict_type != AV_PICTURE_TYPE_B;
3098
2/2
✓ Branch 13 → 14 taken 1028 times.
✓ Branch 13 → 15 taken 9763 times.
10791 if (h->partitioned_frame)
3099 1028 h->decode_mb = mpeg4_decode_partitioned_mb;
3100 else
3101 9763 h->decode_mb = mpeg4_decode_mb;
3102
3103 10791 time_incr = 0;
3104
2/2
✓ Branch 19 → 17 taken 393 times.
✓ Branch 19 → 20 taken 10791 times.
11184 while (get_bits1(gb) != 0)
3105 393 time_incr++;
3106
3107 10791 check_marker(h->c.avctx, gb, "before time_increment");
3108
3109
2/2
✓ Branch 21 → 22 taken 10789 times.
✓ Branch 21 → 24 taken 2 times.
10791 if (ctx->time_increment_bits == 0 ||
3110
2/2
✓ Branch 23 → 24 taken 8 times.
✓ Branch 23 → 39 taken 10781 times.
10789 !(show_bits(gb, ctx->time_increment_bits + 1) & 1)) {
3111 10 av_log(h->c.avctx, AV_LOG_WARNING,
3112 "time_increment_bits %d is invalid in relation to the current bitstream, this is likely caused by a missing VOL header\n", ctx->time_increment_bits);
3113
3114 10 for (ctx->time_increment_bits = 1;
3115
1/2
✓ Branch 37 → 26 taken 110 times.
✗ Branch 37 → 38 not taken.
110 ctx->time_increment_bits < 16;
3116 100 ctx->time_increment_bits++) {
3117
1/2
✓ Branch 26 → 27 taken 110 times.
✗ Branch 26 → 29 not taken.
110 if (h->c.pict_type == AV_PICTURE_TYPE_P ||
3118
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 33 taken 110 times.
110 (h->c.pict_type == AV_PICTURE_TYPE_S &&
3119
0/2
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 33 not taken.
✗ ctx->vol_sprite_usage == GMC_SPRITE)) {
3120
0/2
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ if ((show_bits(gb, ctx->time_increment_bits + 6) & 0x37) == 0x30)
3121 ✗ break;
3122
2/2
✓ Branch 34 → 35 taken 10 times.
✓ Branch 34 → 36 taken 100 times.
110 } else if ((show_bits(gb, ctx->time_increment_bits + 5) & 0x1F) == 0x18)
3123 10 break;
3124 }
3125
3126 10 av_log(h->c.avctx, AV_LOG_WARNING,
3127 "time_increment_bits set to %d bits, based on bitstream analysis\n", ctx->time_increment_bits);
3128 }
3129
3130 if (IS_3IV1)
3131 time_increment = get_bits1(gb); // FIXME investigate further
3132 else
3133 10791 time_increment = get_bits(gb, ctx->time_increment_bits);
3134
3135
2/2
✓ Branch 40 → 41 taken 9490 times.
✓ Branch 40 → 45 taken 1301 times.
10791 if (h->c.pict_type != AV_PICTURE_TYPE_B) {
3136 9490 h->c.last_time_base = h->c.time_base;
3137 9490 h->c.time_base += time_incr;
3138 9490 h->c.time = h->c.time_base * (int64_t)h->c.avctx->framerate.num + time_increment;
3139
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 44 taken 9490 times.
9490 if (h->c.workaround_bugs & FF_BUG_UMP4) {
3140
0/2
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ if (h->c.time < h->c.last_non_b_time) {
3141 /* header is not mpeg-4-compatible, broken encoder,
3142 * trying to workaround */
3143 ✗ h->c.time_base++;
3144 ✗ h->c.time += h->c.avctx->framerate.num;
3145 }
3146 }
3147 9490 h->c.pp_time = h->c.time - h->c.last_non_b_time;
3148 9490 h->c.last_non_b_time = h->c.time;
3149 } else {
3150 1301 h->c.time = (h->c.last_time_base + time_incr) * (int64_t)h->c.avctx->framerate.num + time_increment;
3151 1301 h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
3152
1/2
✓ Branch 45 → 46 taken 1301 times.
✗ Branch 45 → 48 not taken.
1301 if (h->c.pp_time <= h->c.pb_time ||
3153
1/2
✓ Branch 46 → 47 taken 1301 times.
✗ Branch 46 → 48 not taken.
1301 h->c.pp_time <= h->c.pp_time - h->c.pb_time ||
3154
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 49 taken 1301 times.
1301 h->c.pp_time <= 0) {
3155 /* messed up order, maybe after seeking? skipping current B-frame */
3156 ✗ return FRAME_SKIPPED;
3157 }
3158 1301 ff_mpeg4_init_direct_mv(&h->c);
3159
3160
2/2
✓ Branch 50 → 51 taken 215 times.
✓ Branch 50 → 52 taken 1086 times.
1301 if (ctx->t_frame == 0)
3161 215 ctx->t_frame = h->c.pb_time;
3162
1/2
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 54 taken 1301 times.
1301 if (ctx->t_frame == 0)
3163 ✗ ctx->t_frame = 1; // 1/0 protection
3164
1/2
✓ Branch 54 → 55 taken 1301 times.
✗ Branch 54 → 56 not taken.
1301 h->c.pp_field_time = (ROUNDED_DIV(h->c.last_non_b_time, ctx->t_frame) -
3165
1/2
✓ Branch 57 → 58 taken 1301 times.
✗ Branch 57 → 59 not taken.
1301 ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2;
3166
1/2
✓ Branch 60 → 61 taken 1301 times.
✗ Branch 60 → 62 not taken.
1301 h->c.pb_field_time = (ROUNDED_DIV(h->c.time, ctx->t_frame) -
3167
1/2
✓ Branch 63 → 64 taken 1301 times.
✗ Branch 63 → 65 not taken.
1301 ROUNDED_DIV(h->c.last_non_b_time - h->c.pp_time, ctx->t_frame)) * 2;
3168
3/4
✓ Branch 66 → 67 taken 1299 times.
✓ Branch 66 → 68 taken 2 times.
✗ Branch 67 → 68 not taken.
✓ Branch 67 → 70 taken 1299 times.
1301 if (h->c.pp_field_time <= h->c.pb_field_time || h->c.pb_field_time <= 1) {
3169 2 h->c.pb_field_time = 2;
3170 2 h->c.pp_field_time = 4;
3171
1/2
✗ Branch 68 → 69 not taken.
✓ Branch 68 → 70 taken 2 times.
2 if (!h->c.progressive_sequence)
3172 ✗ return FRAME_SKIPPED;
3173 }
3174 }
3175
3176
1/2
✓ Branch 70 → 71 taken 10791 times.
✗ Branch 70 → 75 not taken.
10791 if (h->c.avctx->framerate.den)
3177
1/2
✓ Branch 71 → 72 taken 10791 times.
✗ Branch 71 → 73 not taken.
10791 pts = ROUNDED_DIV(h->c.time, h->c.avctx->framerate.den);
3178 else
3179 ✗ pts = AV_NOPTS_VALUE;
3180 ff_dlog(h->c.avctx, "MPEG4 PTS: %"PRId64"\n", pts);
3181
3182 10791 check_marker(h->c.avctx, gb, "before vop_coded");
3183
3184 /* vop coded */
3185
2/2
✓ Branch 78 → 79 taken 8 times.
✓ Branch 78 → 82 taken 10783 times.
10791 if (get_bits1(gb) != 1) {
3186
1/2
✗ Branch 79 → 80 not taken.
✓ Branch 79 → 81 taken 8 times.
8 if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
3187 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "vop not coded\n");
3188 8 h->skipped_last_frame = 1;
3189 8 return FRAME_SKIPPED;
3190 }
3191
1/2
✗ Branch 82 → 83 not taken.
✓ Branch 82 → 84 taken 10783 times.
10783 if (ctx->new_pred)
3192 ✗ decode_new_pred(ctx, gb);
3193
3194
1/2
✓ Branch 84 → 85 taken 10783 times.
✗ Branch 84 → 90 not taken.
10783 if (ctx->shape != BIN_ONLY_SHAPE &&
3195
2/2
✓ Branch 85 → 86 taken 2377 times.
✓ Branch 85 → 88 taken 8406 times.
10783 (h->c.pict_type == AV_PICTURE_TYPE_P ||
3196
1/2
✗ Branch 86 → 87 not taken.
✓ Branch 86 → 90 taken 2377 times.
2377 (h->c.pict_type == AV_PICTURE_TYPE_S &&
3197
0/2
✗ Branch 87 → 88 not taken.
✗ Branch 87 → 90 not taken.
✗ ctx->vol_sprite_usage == GMC_SPRITE))) {
3198 /* rounding type for motion estimation */
3199 8406 h->c.no_rounding = get_bits1(gb);
3200 } else {
3201 2377 h->c.no_rounding = 0;
3202 }
3203 // FIXME reduced res stuff
3204
3205
1/2
✗ Branch 91 → 92 not taken.
✓ Branch 91 → 105 taken 10783 times.
10783 if (ctx->shape != RECT_SHAPE) {
3206
0/4
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 94 not taken.
✗ Branch 93 → 94 not taken.
✗ Branch 93 → 101 not taken.
✗ if (ctx->vol_sprite_usage != 1 || h->c.pict_type != AV_PICTURE_TYPE_I) {
3207 ✗ skip_bits(gb, 13); /* width */
3208 ✗ check_marker(h->c.avctx, gb, "after width");
3209 ✗ skip_bits(gb, 13); /* height */
3210 ✗ check_marker(h->c.avctx, gb, "after height");
3211 ✗ skip_bits(gb, 13); /* hor_spat_ref */
3212 ✗ check_marker(h->c.avctx, gb, "after hor_spat_ref");
3213 ✗ skip_bits(gb, 13); /* ver_spat_ref */
3214 }
3215 ✗ skip_bits1(gb); /* change_CR_disable */
3216
3217
0/2
✗ Branch 103 → 104 not taken.
✗ Branch 103 → 105 not taken.
✗ if (get_bits1(gb) != 0)
3218 ✗ skip_bits(gb, 8); /* constant_alpha_value */
3219 }
3220
3221 // FIXME complexity estimation stuff
3222
3223
1/2
✓ Branch 105 → 106 taken 10783 times.
✗ Branch 105 → 121 not taken.
10783 if (ctx->shape != BIN_ONLY_SHAPE) {
3224 10783 skip_bits_long(gb, ctx->cplx_estimation_trash_i);
3225
2/2
✓ Branch 107 → 108 taken 9707 times.
✓ Branch 107 → 109 taken 1076 times.
10783 if (h->c.pict_type != AV_PICTURE_TYPE_I)
3226 9707 skip_bits_long(gb, ctx->cplx_estimation_trash_p);
3227
2/2
✓ Branch 109 → 110 taken 1301 times.
✓ Branch 109 → 111 taken 9482 times.
10783 if (h->c.pict_type == AV_PICTURE_TYPE_B)
3228 1301 skip_bits_long(gb, ctx->cplx_estimation_trash_b);
3229
3230
1/2
✗ Branch 112 → 113 not taken.
✓ Branch 112 → 115 taken 10783 times.
10783 if (get_bits_left(gb) < 3) {
3231 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "Header truncated\n");
3232 ✗ return AVERROR_INVALIDDATA;
3233 }
3234 10783 ctx->intra_dc_threshold = ff_mpeg4_dc_threshold[get_bits(gb, 3)];
3235
2/2
✓ Branch 116 → 117 taken 50 times.
✓ Branch 116 → 120 taken 10733 times.
10783 if (!h->c.progressive_sequence) {
3236 50 h->c.top_field_first = get_bits1(gb);
3237 50 h->c.alternate_scan = get_bits1(gb);
3238 } else
3239 10733 h->c.alternate_scan = 0;
3240 }
3241 /* Skip at this point when only parsing since the remaining
3242 * data is not useful for a parser and requires the
3243 * sprite_trajectory VLC to be initialized. */
3244
2/2
✓ Branch 121 → 122 taken 5373 times.
✓ Branch 121 → 123 taken 5410 times.
10783 if (parse_only)
3245 5373 goto end;
3246
3247
1/2
✗ Branch 123 → 124 not taken.
✓ Branch 123 → 126 taken 5410 times.
5410 if (h->c.alternate_scan) {
3248 ✗ ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_alternate_vertical_scan);
3249 ✗ ff_permute_scantable(h->permutated_intra_h_scantable, ff_alternate_vertical_scan,
3250 ✗ h->c.idsp.idct_permutation);
3251 } else {
3252 5410 ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable, ff_zigzag_direct);
3253 5410 ff_permute_scantable(h->permutated_intra_h_scantable, ff_alternate_horizontal_scan,
3254 5410 h->c.idsp.idct_permutation);
3255 }
3256 5410 ff_permute_scantable(h->permutated_intra_v_scantable, ff_alternate_vertical_scan,
3257 5410 h->c.idsp.idct_permutation);
3258
3259
1/2
✗ Branch 129 → 130 not taken.
✓ Branch 129 → 141 taken 5410 times.
5410 if (h->c.pict_type == AV_PICTURE_TYPE_S) {
3260
0/2
✗ Branch 130 → 131 not taken.
✗ Branch 130 → 132 not taken.
✗ if((ctx->vol_sprite_usage == STATIC_SPRITE ||
3261
0/2
✗ Branch 131 → 132 not taken.
✗ Branch 131 → 140 not taken.
✗ ctx->vol_sprite_usage == GMC_SPRITE)) {
3262
0/2
✗ Branch 133 → 134 not taken.
✗ Branch 133 → 135 not taken.
✗ if (mpeg4_decode_sprite_trajectory(ctx, gb) < 0)
3263 ✗ return AVERROR_INVALIDDATA;
3264
0/2
✗ Branch 135 → 136 not taken.
✗ Branch 135 → 137 not taken.
✗ if (ctx->sprite_brightness_change)
3265 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
3266 "sprite_brightness_change not supported\n");
3267
0/2
✗ Branch 137 → 138 not taken.
✗ Branch 137 → 139 not taken.
✗ if (ctx->vol_sprite_usage == STATIC_SPRITE)
3268 ✗ av_log(h->c.avctx, AV_LOG_ERROR, "static sprite not supported\n");
3269 } else {
3270 ✗ memset(ctx->sprite_offset, 0, sizeof(ctx->sprite_offset));
3271 ✗ memset(ctx->sprite_delta, 0, sizeof(ctx->sprite_delta));
3272 }
3273 }
3274
3275 5410 ctx->f_code = 1;
3276 5410 ctx->b_code = 1;
3277
1/2
✓ Branch 141 → 142 taken 5410 times.
✗ Branch 141 → 180 not taken.
5410 if (ctx->shape != BIN_ONLY_SHAPE) {
3278 5410 h->c.chroma_qscale = h->c.qscale = get_bits(gb, ctx->quant_precision);
3279
1/2
✗ Branch 143 → 144 not taken.
✓ Branch 143 → 146 taken 5410 times.
5410 if (h->c.qscale == 0) {
3280 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
3281 "Error, header damaged or not MPEG-4 header (qscale=0)\n");
3282 ✗ return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then
3283 }
3284
3285
2/2
✓ Branch 146 → 147 taken 4923 times.
✓ Branch 146 → 151 taken 487 times.
5410 if (h->c.pict_type != AV_PICTURE_TYPE_I) {
3286 4923 ctx->f_code = get_bits(gb, 3); /* fcode_for */
3287
1/2
✗ Branch 148 → 149 not taken.
✓ Branch 148 → 151 taken 4923 times.
4923 if (ctx->f_code == 0) {
3288 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
3289 "Error, header damaged or not MPEG-4 header (f_code=0)\n");
3290 ✗ ctx->f_code = 1;
3291 ✗ return AVERROR_INVALIDDATA; // makes no sense to continue, as there is nothing left from the image then
3292 }
3293 }
3294
3295
2/2
✓ Branch 151 → 152 taken 648 times.
✓ Branch 151 → 156 taken 4762 times.
5410 if (h->c.pict_type == AV_PICTURE_TYPE_B) {
3296 648 ctx->b_code = get_bits(gb, 3);
3297
1/2
✗ Branch 153 → 154 not taken.
✓ Branch 153 → 156 taken 648 times.
648 if (ctx->b_code == 0) {
3298 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
3299 "Error, header damaged or not MPEG4 header (b_code=0)\n");
3300 ✗ ctx->b_code=1;
3301 ✗ return AVERROR_INVALIDDATA; // makes no sense to continue, as the MV decoding will break very quickly
3302 }
3303 }
3304
3305
1/2
✗ Branch 156 → 157 not taken.
✓ Branch 156 → 171 taken 5410 times.
5410 if (h->c.avctx->debug & FF_DEBUG_PICT_INFO) {
3306 ✗ av_log(h->c.avctx, AV_LOG_DEBUG,
3307 "qp:%d fc:%d,%d %c size:%d pro:%d alt:%d top:%d %cpel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d time:%"PRId64" tincr:%d\n",
3308 h->c.qscale, ctx->f_code, ctx->b_code,
3309
0/6
✗ Branch 163 → 164 not taken.
✗ Branch 163 → 169 not taken.
✗ Branch 164 → 165 not taken.
✗ Branch 164 → 168 not taken.
✗ Branch 165 → 166 not taken.
✗ Branch 165 → 167 not taken.
✗ h->c.pict_type == AV_PICTURE_TYPE_I ? 'I' : (h->c.pict_type == AV_PICTURE_TYPE_P ? 'P' : (h->c.pict_type == AV_PICTURE_TYPE_B ? 'B' : 'S')),
3310 gb->size_in_bits,h->c.progressive_sequence, h->c.alternate_scan,
3311 ✗ h->c.top_field_first, h->c.quarter_sample ? 'q' : 'h',
3312 h->data_partitioning, ctx->resync_marker,
3313 ctx->num_sprite_warping_points, ctx->sprite_warping_accuracy,
3314
0/2
✗ Branch 160 → 161 not taken.
✗ Branch 160 → 162 not taken.
✗ 1 - h->c.no_rounding, ctx->vo_type,
3315
0/2
✗ Branch 157 → 158 not taken.
✗ Branch 157 → 159 not taken.
✗ ctx->vol_control_parameters ? " VOLC" : " ", ctx->intra_dc_threshold,
3316 ctx->cplx_estimation_trash_i, ctx->cplx_estimation_trash_p,
3317 ctx->cplx_estimation_trash_b,
3318 h->c.time,
3319 time_increment
3320 );
3321 }
3322
3323
1/2
✓ Branch 171 → 172 taken 5410 times.
✗ Branch 171 → 175 not taken.
5410 if (!ctx->scalability) {
3324
1/4
✗ Branch 172 → 173 not taken.
✓ Branch 172 → 180 taken 5410 times.
✗ Branch 173 → 174 not taken.
✗ Branch 173 → 180 not taken.
5410 if (ctx->shape != RECT_SHAPE && h->c.pict_type != AV_PICTURE_TYPE_I)
3325 ✗ skip_bits1(gb); // vop shape coding type
3326 } else {
3327
0/2
✗ Branch 175 → 176 not taken.
✗ Branch 175 → 179 not taken.
✗ if (ctx->enhancement_type) {
3328 ✗ int load_backward_shape = get_bits1(gb);
3329
0/2
✗ Branch 177 → 178 not taken.
✗ Branch 177 → 179 not taken.
✗ if (load_backward_shape)
3330 ✗ av_log(h->c.avctx, AV_LOG_ERROR,
3331 "load backward shape isn't supported\n");
3332 }
3333 ✗ skip_bits(gb, 2); // ref_select_code
3334 }
3335 }
3336
3337 10820 h->c.dct_unquantize_intra = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_intra
3338
2/2
✓ Branch 180 → 181 taken 249 times.
✓ Branch 180 → 182 taken 5161 times.
5410 : ctx->dct_unquantize_h263_intra;
3339 // The following tells ff_mpv_reconstruct_mb() to unquantize iff mpeg_quant
3340
2/2
✓ Branch 183 → 184 taken 249 times.
✓ Branch 183 → 185 taken 5161 times.
5410 h->c.dct_unquantize_inter = ctx->mpeg_quant ? ctx->dct_unquantize_mpeg2_inter : NULL;
3341
3342 10783 end:
3343 /* detect buggy encoders which don't set the low_delay flag
3344 * (divx4/xvid/opendivx). Note we cannot detect divx5 without B-frames
3345 * easily (although it's buggy too) */
3346
3/4
✓ Branch 187 → 188 taken 52 times.
✓ Branch 187 → 193 taken 10731 times.
✓ Branch 188 → 189 taken 52 times.
✗ Branch 188 → 193 not taken.
10783 if (ctx->vo_type == 0 && ctx->vol_control_parameters == 0 &&
3347
3/4
✓ Branch 189 → 190 taken 2 times.
✓ Branch 189 → 193 taken 50 times.
✓ Branch 190 → 191 taken 2 times.
✗ Branch 190 → 193 not taken.
52 ctx->divx_version == -1 && h->picture_number == 0) {
3348 2 av_log(h->c.avctx, AV_LOG_WARNING,
3349 "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
3350 2 h->c.low_delay = 1;
3351 }
3352
3353 10783 h->picture_number++; // better than pic number==0 always ;)
3354
3355
1/2
✗ Branch 193 → 194 not taken.
✓ Branch 193 → 195 taken 10783 times.
10783 if (h->c.workaround_bugs & FF_BUG_EDGE) {
3356 ✗ h->c.h_edge_pos = h->c.width;
3357 ✗ h->c.v_edge_pos = h->c.height;
3358 }
3359 10783 return 0;
3360 }
3361
3362 2 static void decode_smpte_tc(Mpeg4DecContext *ctx, GetBitContext *gb)
3363 {
3364 2 AVCodecContext *const avctx = ctx->h.c.avctx;
3365
3366 2 skip_bits(gb, 16); /* Time_code[63..48] */
3367 2 check_marker(avctx, gb, "after Time_code[63..48]");
3368 2 skip_bits(gb, 16); /* Time_code[47..32] */
3369 2 check_marker(avctx, gb, "after Time_code[47..32]");
3370 2 skip_bits(gb, 16); /* Time_code[31..16] */
3371 2 check_marker(avctx, gb, "after Time_code[31..16]");
3372 2 skip_bits(gb, 16); /* Time_code[15..0] */
3373 2 check_marker(avctx, gb, "after Time_code[15..0]");
3374 2 skip_bits(gb, 4); /* reserved_bits */
3375 2 }
3376
3377 /**
3378 * Decode the next studio vop header.
3379 * @return <0 if something went wrong
3380 */
3381 2 static int decode_studio_vop_header(Mpeg4DecContext *ctx, GetBitContext *gb)
3382 {
3383 2 H263DecContext *const h = &ctx->h;
3384
3385
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 2 times.
2 if (get_bits_left(gb) <= 32)
3386 ✗ return 0;
3387
3388 2 h->partitioned_frame = 0;
3389 2 h->c.interlaced_dct = 0;
3390 2 h->decode_mb = mpeg4_decode_studio_mb;
3391
3392 2 decode_smpte_tc(ctx, gb);
3393
3394 2 skip_bits(gb, 10); /* temporal_reference */
3395 2 skip_bits(gb, 2); /* vop_structure */
3396 2 h->c.pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* vop_coding_type */
3397
1/2
✓ Branch 10 → 11 taken 2 times.
✗ Branch 10 → 15 not taken.
2 if (get_bits1(gb)) { /* vop_coded */
3398 2 skip_bits1(gb); /* top_field_first */
3399 2 skip_bits1(gb); /* repeat_first_field */
3400 2 h->c.progressive_frame = get_bits1(gb) ^ 1; /* progressive_frame */
3401 }
3402
3403
1/2
✓ Branch 15 → 16 taken 2 times.
✗ Branch 15 → 19 not taken.
2 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
3404
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 2 times.
2 if (get_bits1(gb))
3405 ✗ reset_studio_dc_predictors(ctx);
3406 }
3407
3408
1/2
✓ Branch 19 → 20 taken 2 times.
✗ Branch 19 → 26 not taken.
2 if (ctx->shape != BIN_ONLY_SHAPE) {
3409 2 h->c.alternate_scan = get_bits1(gb);
3410 2 h->c.frame_pred_frame_dct = get_bits1(gb);
3411 2 ctx->dct_precision = get_bits(gb, 2);
3412 2 h->c.intra_dc_precision = get_bits(gb, 2);
3413 2 h->c.q_scale_type = get_bits1(gb);
3414 }
3415
3416 2 ff_init_scantable(h->c.idsp.idct_permutation, &h->c.intra_scantable,
3417
1/2
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 2 times.
2 h->c.alternate_scan ? ff_alternate_vertical_scan : ff_zigzag_direct);
3418
3419 2 mpeg4_load_default_matrices(&h->c);
3420
3421 2 next_start_code_studio(gb);
3422 2 extension_and_user_data(&h->c, gb, 4);
3423
3424 2 return 0;
3425 }
3426
3427 ✗ static int decode_studiovisualobject(Mpeg4DecContext *ctx, GetBitContext *gb)
3428 {
3429 int visual_object_type;
3430
3431 ✗ skip_bits(gb, 4); /* visual_object_verid */
3432 ✗ visual_object_type = get_bits(gb, 4);
3433
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 7 not taken.
✗ if (visual_object_type != VOT_VIDEO_ID) {
3434 ✗ avpriv_request_sample(ctx->h.c.avctx, "VO type %u", visual_object_type);
3435 ✗ return AVERROR_PATCHWELCOME;
3436 }
3437
3438 ✗ next_start_code_studio(gb);
3439 ✗ extension_and_user_data(&ctx->h.c, gb, 1);
3440
3441 ✗ return 0;
3442 }
3443
3444 /**
3445 * Decode MPEG-4 headers.
3446 *
3447 * @param header If set the absence of a VOP is not treated as error; otherwise, it is treated as such.
3448 * @param parse_only If set, things only relevant to a decoder may be skipped;
3449 * furthermore, the VLC tables may be uninitialized.
3450 * @return <0 if an error occurred
3451 * FRAME_SKIPPED if a not coded VOP is found
3452 * 0 else
3453 */
3454 11295 int ff_mpeg4_parse_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb,
3455 int header, int parse_only)
3456 {
3457 11295 MPVContext *const s = &ctx->h.c;
3458 unsigned startcode, v;
3459 int ret;
3460 11295 int vol = 0;
3461
3462 /* search next start code */
3463 11295 align_get_bits(gb);
3464
3465 // If we have not switched to studio profile than we also did not switch bps
3466 // that means something else (like a previous instance) outside set bps which
3467 // would be inconsistent with the correct state, thus reset it
3468
3/4
✓ Branch 3 → 4 taken 11293 times.
✓ Branch 3 → 6 taken 2 times.
✓ Branch 4 → 5 taken 11293 times.
✗ Branch 4 → 6 not taken.
11295 if (!s->studio_profile && s->avctx->bits_per_raw_sample != 8)
3469 11293 s->avctx->bits_per_raw_sample = 0;
3470
3471
1/4
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 13 taken 11295 times.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 13 not taken.
11295 if (s->codec_tag == AV_RL32("WV1F") && show_bits(gb, 24) == 0x575630) {
3472 ✗ skip_bits(gb, 24);
3473
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (get_bits(gb, 8) == 0xF0)
3474 ✗ goto end;
3475 }
3476
3477 11295 startcode = 0xff;
3478 for (;;) {
3479
2/2
✓ Branch 15 → 16 taken 502 times.
✓ Branch 15 → 27 taken 67490 times.
67992 if (get_bits_count(gb) >= gb->size_in_bits) {
3480
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 502 times.
502 if (gb->size_in_bits == 8 &&
3481
1/6
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 20 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 22 taken 502 times.
502 (ctx->divx_version >= 0 || ctx->xvid_build >= 0) || s->codec_tag == AV_RL32("QMP4")) {
3482 ✗ av_log(s->avctx, AV_LOG_VERBOSE, "frame skip %d\n", gb->size_in_bits);
3483 ✗ return FRAME_SKIPPED; // divx bug
3484
3/4
✓ Branch 22 → 23 taken 398 times.
✓ Branch 22 → 26 taken 104 times.
✓ Branch 24 → 25 taken 398 times.
✗ Branch 24 → 26 not taken.
502 } else if (header && get_bits_count(gb) == gb->size_in_bits) {
3485 398 return 0; // ordinary return value for parsing of extradata
3486 } else
3487 104 return AVERROR_INVALIDDATA; // end of stream
3488 }
3489
3490 /* use the bits after the test */
3491 67490 v = get_bits(gb, 8);
3492 67490 startcode = ((startcode << 8) | v) & 0xffffffff;
3493
3494
2/2
✓ Branch 28 → 29 taken 50622 times.
✓ Branch 28 → 30 taken 16868 times.
67490 if ((startcode & 0xFFFFFF00) != 0x100)
3495 50622 continue; // no startcode
3496
3497
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 88 taken 16868 times.
16868 if (s->avctx->debug & FF_DEBUG_STARTCODE) {
3498 const char *name;
3499
0/2
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 33 not taken.
✗ if (startcode <= 0x11F)
3500 ✗ name = "Video Object Start";
3501
0/2
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 35 not taken.
✗ else if (startcode <= 0x12F)
3502 ✗ name = "Video Object Layer Start";
3503
0/2
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 37 not taken.
✗ else if (startcode <= 0x13F)
3504 ✗ name = "Reserved";
3505
0/2
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 39 not taken.
✗ else if (startcode <= 0x15F)
3506 ✗ name = "FGS bp start";
3507
0/2
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 41 not taken.
✗ else if (startcode <= 0x1AF)
3508 ✗ name = "Reserved";
3509
0/2
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 43 not taken.
✗ else if (startcode == 0x1B0)
3510 ✗ name = "Visual Object Seq Start";
3511
0/2
✗ Branch 43 → 44 not taken.
✗ Branch 43 → 45 not taken.
✗ else if (startcode == 0x1B1)
3512 ✗ name = "Visual Object Seq End";
3513
0/2
✗ Branch 45 → 46 not taken.
✗ Branch 45 → 47 not taken.
✗ else if (startcode == 0x1B2)
3514 ✗ name = "User Data";
3515
0/2
✗ Branch 47 → 48 not taken.
✗ Branch 47 → 49 not taken.
✗ else if (startcode == 0x1B3)
3516 ✗ name = "Group of VOP start";
3517
0/2
✗ Branch 49 → 50 not taken.
✗ Branch 49 → 51 not taken.
✗ else if (startcode == 0x1B4)
3518 ✗ name = "Video Session Error";
3519
0/2
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 53 not taken.
✗ else if (startcode == 0x1B5)
3520 ✗ name = "Visual Object Start";
3521
0/2
✗ Branch 53 → 54 not taken.
✗ Branch 53 → 55 not taken.
✗ else if (startcode == 0x1B6)
3522 ✗ name = "Video Object Plane start";
3523
0/2
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 57 not taken.
✗ else if (startcode == 0x1B7)
3524 ✗ name = "slice start";
3525
0/2
✗ Branch 57 → 58 not taken.
✗ Branch 57 → 59 not taken.
✗ else if (startcode == 0x1B8)
3526 ✗ name = "extension start";
3527
0/2
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
✗ else if (startcode == 0x1B9)
3528 ✗ name = "fgs start";
3529
0/2
✗ Branch 61 → 62 not taken.
✗ Branch 61 → 63 not taken.
✗ else if (startcode == 0x1BA)
3530 ✗ name = "FBA Object start";
3531
0/2
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 65 not taken.
✗ else if (startcode == 0x1BB)
3532 ✗ name = "FBA Object Plane start";
3533
0/2
✗ Branch 65 → 66 not taken.
✗ Branch 65 → 67 not taken.
✗ else if (startcode == 0x1BC)
3534 ✗ name = "Mesh Object start";
3535
0/2
✗ Branch 67 → 68 not taken.
✗ Branch 67 → 69 not taken.
✗ else if (startcode == 0x1BD)
3536 ✗ name = "Mesh Object Plane start";
3537
0/2
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 71 not taken.
✗ else if (startcode == 0x1BE)
3538 ✗ name = "Still Texture Object start";
3539
0/2
✗ Branch 71 → 72 not taken.
✗ Branch 71 → 73 not taken.
✗ else if (startcode == 0x1BF)
3540 ✗ name = "Texture Spatial Layer start";
3541
0/2
✗ Branch 73 → 74 not taken.
✗ Branch 73 → 75 not taken.
✗ else if (startcode == 0x1C0)
3542 ✗ name = "Texture SNR Layer start";
3543
0/2
✗ Branch 75 → 76 not taken.
✗ Branch 75 → 77 not taken.
✗ else if (startcode == 0x1C1)
3544 ✗ name = "Texture Tile start";
3545
0/2
✗ Branch 77 → 78 not taken.
✗ Branch 77 → 79 not taken.
✗ else if (startcode == 0x1C2)
3546 ✗ name = "Texture Shape Layer start";
3547
0/2
✗ Branch 79 → 80 not taken.
✗ Branch 79 → 81 not taken.
✗ else if (startcode == 0x1C3)
3548 ✗ name = "stuffing start";
3549
0/2
✗ Branch 81 → 82 not taken.
✗ Branch 81 → 83 not taken.
✗ else if (startcode <= 0x1C5)
3550 ✗ name = "Reserved";
3551
0/2
✗ Branch 83 → 84 not taken.
✗ Branch 83 → 85 not taken.
✗ else if (startcode <= 0x1FF)
3552 ✗ name = "System start";
3553 else
3554 ✗ av_unreachable("Unexpected startcode");
3555 ✗ av_log(s->avctx, AV_LOG_DEBUG, "startcode: %3X %s at %d\n",
3556 startcode, name, get_bits_count(gb));
3557 }
3558
3559
4/4
✓ Branch 88 → 89 taken 15611 times.
✓ Branch 88 → 97 taken 1257 times.
✓ Branch 89 → 90 taken 1257 times.
✓ Branch 89 → 97 taken 14354 times.
16868 if (startcode >= 0x120 && startcode <= 0x12F) {
3560
1/2
✗ Branch 90 → 91 not taken.
✓ Branch 90 → 93 taken 1257 times.
1257 if (vol) {
3561 ✗ av_log(s->avctx, AV_LOG_WARNING, "Ignoring multiple VOL headers\n");
3562 ✗ continue;
3563 }
3564 1257 vol++;
3565
1/2
✗ Branch 94 → 95 not taken.
✓ Branch 94 → 96 taken 1257 times.
1257 if ((ret = decode_vol_header(ctx, gb)) < 0)
3566 ✗ return ret;
3567
2/2
✓ Branch 97 → 98 taken 90 times.
✓ Branch 97 → 99 taken 15521 times.
15611 } else if (startcode == USER_DATA_STARTCODE) {
3568 90 decode_user_data(ctx, gb);
3569
2/2
✓ Branch 99 → 100 taken 1023 times.
✓ Branch 99 → 101 taken 14498 times.
15521 } else if (startcode == GOP_STARTCODE) {
3570 1023 mpeg4_decode_gop_header(s, gb);
3571
2/2
✓ Branch 101 → 102 taken 1224 times.
✓ Branch 101 → 112 taken 13274 times.
14498 } else if (startcode == VOS_STARTCODE) {
3572 int profile, level;
3573 1224 mpeg4_decode_profile_level(s, gb, &profile, &level);
3574
1/2
✗ Branch 103 → 104 not taken.
✓ Branch 103 → 108 taken 1224 times.
1224 if (profile == AV_PROFILE_MPEG4_SIMPLE_STUDIO &&
3575
0/4
✗ Branch 104 → 105 not taken.
✗ Branch 104 → 108 not taken.
✗ Branch 105 → 106 not taken.
✗ Branch 105 → 108 not taken.
✗ (level > 0 && level < 9)) {
3576 ✗ s->studio_profile = 1;
3577 ✗ next_start_code_studio(gb);
3578 ✗ extension_and_user_data(s, gb, 0);
3579
1/2
✗ Branch 108 → 109 not taken.
✓ Branch 108 → 111 taken 1224 times.
1224 } else if (s->studio_profile) {
3580 ✗ avpriv_request_sample(s->avctx, "Mix of studio and non studio profile");
3581 ✗ return AVERROR_PATCHWELCOME;
3582 }
3583 1224 s->avctx->profile = profile;
3584 1224 s->avctx->level = level;
3585
2/2
✓ Branch 112 → 113 taken 1224 times.
✓ Branch 112 → 118 taken 12050 times.
13274 } else if (startcode == VISUAL_OBJ_STARTCODE) {
3586
1/2
✗ Branch 113 → 114 not taken.
✓ Branch 113 → 117 taken 1224 times.
1224 if (s->studio_profile) {
3587
0/2
✗ Branch 115 → 116 not taken.
✗ Branch 115 → 120 not taken.
✗ if ((ret = decode_studiovisualobject(ctx, gb)) < 0)
3588 ✗ return ret;
3589 } else
3590 1224 mpeg4_decode_visual_object(s, gb);
3591
2/2
✓ Branch 118 → 119 taken 10793 times.
✓ Branch 118 → 120 taken 1257 times.
12050 } else if (startcode == VOP_STARTCODE) {
3592 10793 break;
3593 }
3594
3595 6075 align_get_bits(gb);
3596 6075 startcode = 0xff;
3597 }
3598
3599 10793 end:
3600
1/2
✗ Branch 123 → 124 not taken.
✓ Branch 123 → 125 taken 10793 times.
10793 if (s->avctx->flags & AV_CODEC_FLAG_LOW_DELAY)
3601 ✗ s->low_delay = 1;
3602
3603
2/2
✓ Branch 125 → 126 taken 2 times.
✓ Branch 125 → 131 taken 10791 times.
10793 if (s->studio_profile) {
3604
1/2
✗ Branch 126 → 127 not taken.
✓ Branch 126 → 129 taken 2 times.
2 if (!s->avctx->bits_per_raw_sample) {
3605 ✗ av_log(s->avctx, AV_LOG_ERROR, "Missing VOL header\n");
3606 ✗ return AVERROR_INVALIDDATA;
3607 }
3608 2 return decode_studio_vop_header(ctx, gb);
3609 } else
3610 10791 return decode_vop_header(ctx, gb, parse_only);
3611 }
3612
3613 #if CONFIG_MPEG4_DECODER
3614 8 static av_cold void permute_quant_matrix(uint16_t matrix[64],
3615 const uint8_t new_perm[64],
3616 const uint8_t old_perm[64])
3617 {
3618 uint16_t tmp[64];
3619
3620 8 memcpy(tmp, matrix, sizeof(tmp));
3621
2/2
✓ Branch 4 → 3 taken 512 times.
✓ Branch 4 → 5 taken 8 times.
520 for (int i = 0; i < 64; ++i)
3622 512 matrix[new_perm[i]] = tmp[old_perm[i]];
3623 8 }
3624
3625 4 static av_cold void switch_to_xvid_idct(AVCodecContext *const avctx,
3626 H263DecContext *const h)
3627 {
3628 uint8_t old_permutation[64];
3629
3630 4 memcpy(old_permutation, h->c.idsp.idct_permutation, sizeof(old_permutation));
3631
3632 4 avctx->idct_algo = FF_IDCT_XVID;
3633 4 ff_mpv_idct_init(&h->c);
3634 4 ff_permute_scantable(h->permutated_intra_h_scantable,
3635 4 h->c.alternate_scan ? ff_alternate_vertical_scan : ff_alternate_horizontal_scan,
3636
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 4 times.
4 h->c.idsp.idct_permutation);
3637 4 ff_permute_scantable(h->permutated_intra_v_scantable, ff_alternate_vertical_scan,
3638 4 h->c.idsp.idct_permutation);
3639
3640 // Normal (i.e. non-studio) MPEG-4 does not use the chroma matrices.
3641 4 permute_quant_matrix(h->c.inter_matrix, h->c.idsp.idct_permutation, old_permutation);
3642 4 permute_quant_matrix(h->c.intra_matrix, h->c.idsp.idct_permutation, old_permutation);
3643 4 }
3644
3645 5411 void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
3646 {
3647 5411 Mpeg4DecContext *ctx = avctx->priv_data;
3648 5411 H263DecContext *const h = &ctx->h;
3649
3650
5/6
✓ Branch 2 → 3 taken 5351 times.
✓ Branch 2 → 11 taken 60 times.
✓ Branch 3 → 4 taken 5351 times.
✗ Branch 3 → 11 not taken.
✓ Branch 4 → 5 taken 5245 times.
✓ Branch 4 → 11 taken 106 times.
5411 if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1) {
3651
1/2
✓ Branch 5 → 6 taken 5245 times.
✗ Branch 5 → 10 not taken.
5245 if (h->c.codec_tag == AV_RL32("XVID") ||
3652
1/2
✓ Branch 6 → 7 taken 5245 times.
✗ Branch 6 → 10 not taken.
5245 h->c.codec_tag == AV_RL32("XVIX") ||
3653
1/2
✓ Branch 7 → 8 taken 5245 times.
✗ Branch 7 → 10 not taken.
5245 h->c.codec_tag == AV_RL32("RMP4") ||
3654
1/2
✓ Branch 8 → 9 taken 5245 times.
✗ Branch 8 → 10 not taken.
5245 h->c.codec_tag == AV_RL32("ZMP4") ||
3655
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 5245 times.
5245 h->c.codec_tag == AV_RL32("SIPP"))
3656 ✗ ctx->xvid_build = 0;
3657 }
3658
3659
5/6
✓ Branch 11 → 12 taken 5351 times.
✓ Branch 11 → 18 taken 60 times.
✓ Branch 12 → 13 taken 5351 times.
✗ Branch 12 → 18 not taken.
✓ Branch 13 → 14 taken 5245 times.
✓ Branch 13 → 18 taken 106 times.
5411 if (ctx->xvid_build == -1 && ctx->divx_version == -1 && ctx->lavc_build == -1)
3660
1/4
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 18 taken 5245 times.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 18 not taken.
5245 if (h->c.codec_tag == AV_RL32("DIVX") && ctx->vo_type == 0 &&
3661
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ ctx->vol_control_parameters == 0)
3662 ✗ ctx->divx_version = 400; // divx 4
3663
3664
4/4
✓ Branch 18 → 19 taken 60 times.
✓ Branch 18 → 21 taken 5351 times.
✓ Branch 19 → 20 taken 3 times.
✓ Branch 19 → 21 taken 57 times.
5411 if (ctx->xvid_build >= 0 && ctx->divx_version >= 0) {
3665 3 ctx->divx_version =
3666 3 ctx->divx_build = -1;
3667 }
3668
3669
1/2
✓ Branch 21 → 22 taken 5411 times.
✗ Branch 21 → 63 not taken.
5411 if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
3670
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 5411 times.
5411 if (h->c.codec_tag == AV_RL32("XVIX"))
3671 ✗ h->c.workaround_bugs |= FF_BUG_XVID_ILACE;
3672
3673
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 5411 times.
5411 if (h->c.codec_tag == AV_RL32("UMP4"))
3674 ✗ h->c.workaround_bugs |= FF_BUG_UMP4;
3675
3676
1/4
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 29 taken 5411 times.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 29 not taken.
5411 if (ctx->divx_version >= 500 && ctx->divx_build < 1814)
3677 ✗ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA;
3678
3679
1/4
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 32 taken 5411 times.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
5411 if (ctx->divx_version > 502 && ctx->divx_build < 1814)
3680 ✗ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA2;
3681
3682
1/2
✗ Branch 32 → 33 not taken.
✓ Branch 32 → 34 taken 5411 times.
5411 if (ctx->xvid_build <= 3U)
3683 ✗ h->padding_bug_score = 256 * 256 * 256 * 64;
3684
3685
1/2
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 5411 times.
5411 if (ctx->xvid_build <= 1U)
3686 ✗ h->c.workaround_bugs |= FF_BUG_QPEL_CHROMA;
3687
3688
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 5411 times.
5411 if (ctx->xvid_build <= 12U)
3689 ✗ h->c.workaround_bugs |= FF_BUG_EDGE;
3690
3691
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 5411 times.
5411 if (ctx->xvid_build <= 32U)
3692 ✗ h->c.workaround_bugs |= FF_BUG_DC_CLIP;
3693
3694 #define SET_QPEL_FUNC(postfix1, postfix2) \
3695 h->c.qdsp.put_ ## postfix1 = ff_put_ ## postfix2; \
3696 h->c.qdsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2; \
3697 h->c.qdsp.avg_ ## postfix1 = ff_avg_ ## postfix2;
3698
3699
1/2
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 42 taken 5411 times.
5411 if (ctx->lavc_build < 4653U)
3700 ✗ h->c.workaround_bugs |= FF_BUG_STD_QPEL;
3701
3702
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 5411 times.
5411 if (ctx->lavc_build < 4655U)
3703 ✗ h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
3704
3705
1/2
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 5411 times.
5411 if (ctx->lavc_build < 4670U)
3706 ✗ h->c.workaround_bugs |= FF_BUG_EDGE;
3707
3708
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 5411 times.
5411 if (ctx->lavc_build <= 4712U)
3709 ✗ h->c.workaround_bugs |= FF_BUG_DC_CLIP;
3710
3711
1/2
✓ Branch 48 → 49 taken 5411 times.
✗ Branch 48 → 54 not taken.
5411 if ((ctx->lavc_build&0xFF) >= 100) {
3712
3/4
✓ Branch 49 → 50 taken 20 times.
✓ Branch 49 → 54 taken 5391 times.
✗ Branch 50 → 51 not taken.
✓ Branch 50 → 54 taken 20 times.
5411 if (ctx->lavc_build > 3621476 && ctx->lavc_build < 3752552 &&
3713
0/4
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 53 not taken.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 54 not taken.
✗ (ctx->lavc_build < 3752037 || ctx->lavc_build > 3752191) // 3.2.1+
3714 )
3715 ✗ h->c.workaround_bugs |= FF_BUG_IEDGE;
3716 }
3717
3718
1/2
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 56 taken 5411 times.
5411 if (ctx->divx_version >= 0)
3719 ✗ h->c.workaround_bugs |= FF_BUG_DIRECT_BLOCKSIZE;
3720
1/4
✗ Branch 56 → 57 not taken.
✓ Branch 56 → 59 taken 5411 times.
✗ Branch 57 → 58 not taken.
✗ Branch 57 → 59 not taken.
5411 if (ctx->divx_version == 501 && ctx->divx_build == 20020416)
3721 ✗ h->padding_bug_score = 256 * 256 * 256 * 64;
3722
3723
1/2
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 61 taken 5411 times.
5411 if (ctx->divx_version < 500U)
3724 ✗ h->c.workaround_bugs |= FF_BUG_EDGE;
3725
3726
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 63 taken 5411 times.
5411 if (ctx->divx_version >= 0)
3727 ✗ h->c.workaround_bugs |= FF_BUG_HPEL_CHROMA;
3728 }
3729
3730
1/2
✗ Branch 63 → 64 not taken.
✓ Branch 63 → 65 taken 5411 times.
5411 if (h->c.workaround_bugs & FF_BUG_STD_QPEL) {
3731 ✗ SET_QPEL_FUNC(qpel_pixels_tab[0][5], qpel16_mc11_old_c)
3732 ✗ SET_QPEL_FUNC(qpel_pixels_tab[0][7], qpel16_mc31_old_c)
3733 ✗ SET_QPEL_FUNC(qpel_pixels_tab[0][9], qpel16_mc12_old_c)
3734 ✗ SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)
3735 ✗ SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)
3736 ✗ SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)
3737
3738 ✗ SET_QPEL_FUNC(qpel_pixels_tab[1][5], qpel8_mc11_old_c)
3739 ✗ SET_QPEL_FUNC(qpel_pixels_tab[1][7], qpel8_mc31_old_c)
3740 ✗ SET_QPEL_FUNC(qpel_pixels_tab[1][9], qpel8_mc12_old_c)
3741 ✗ SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)
3742 ✗ SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)
3743 ✗ SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)
3744 }
3745
3746
1/2
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 70 taken 5411 times.
5411 if (avctx->debug & FF_DEBUG_BUGS)
3747 ✗ av_log(h->c.avctx, AV_LOG_DEBUG,
3748 "bugs: %X lavc_build:%d xvid_build:%d divx_version:%d divx_build:%d %s\n",
3749 h->c.workaround_bugs, ctx->lavc_build, ctx->xvid_build,
3750
0/2
✗ Branch 66 → 67 not taken.
✗ Branch 66 → 68 not taken.
✗ ctx->divx_version, ctx->divx_build, h->divx_packed ? "p" : "");
3751
3752
2/2
✓ Branch 70 → 71 taken 60 times.
✓ Branch 70 → 74 taken 5351 times.
5411 if (ctx->xvid_build >= 0 &&
3753
3/4
✓ Branch 71 → 72 taken 4 times.
✓ Branch 71 → 74 taken 56 times.
✓ Branch 72 → 73 taken 4 times.
✗ Branch 72 → 74 not taken.
60 avctx->idct_algo == FF_IDCT_AUTO && !h->c.studio_profile) {
3754 4 switch_to_xvid_idct(avctx, h);
3755 }
3756 5411 }
3757
3758 5411 static int mpeg4_decode_picture_header(H263DecContext *const h)
3759 {
3760 5411 Mpeg4DecContext *const ctx = h263_to_mpeg4(h);
3761
3762 5411 h->skipped_last_frame = 0;
3763
3764
2/2
✓ Branch 3 → 4 taken 11 times.
✓ Branch 3 → 24 taken 5400 times.
5411 if (ctx->bitstream_buffer) {
3765 11 int buf_size = get_bits_left(&h->gb) / 8U;
3766 11 int bitstream_buffer_size = ctx->bitstream_buffer->size;
3767 11 const uint8_t *buf = h->gb.buffer;
3768
3769
1/2
✓ Branch 5 → 6 taken 11 times.
✗ Branch 5 → 16 not taken.
11 if (h->divx_packed) {
3770
1/2
✓ Branch 15 → 7 taken 11 times.
✗ Branch 15 → 16 not taken.
11 for (int i = 0; i < buf_size - 3; i++) {
3771
3/6
✓ Branch 7 → 8 taken 11 times.
✗ Branch 7 → 14 not taken.
✓ Branch 8 → 9 taken 11 times.
✗ Branch 8 → 14 not taken.
✓ Branch 9 → 10 taken 11 times.
✗ Branch 9 → 14 not taken.
11 if (buf[i] == 0 && buf[i+1] == 0 && buf[i+2] == 1) {
3772
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 13 taken 11 times.
11 if (buf[i+3] == 0xB0) {
3773 ✗ av_log(h->c.avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
3774 ✗ bitstream_buffer_size = 0;
3775 }
3776 11 break;
3777 }
3778 }
3779 }
3780 11 ctx->bitstream_buffer->size = 0;
3781
3/6
✓ Branch 16 → 17 taken 7 times.
✓ Branch 16 → 23 taken 4 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 7 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 23 not taken.
18 if (bitstream_buffer_size && (h->divx_packed || buf_size <= MAX_NVOP_SIZE)) {// divx 5.01+/xvid frame reorder
3782 7 int ret = init_get_bits8(&h->gb, ctx->bitstream_buffer->data,
3783 bitstream_buffer_size);
3784
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 7 times.
7 if (ret < 0)
3785 ✗ return ret;
3786 } else
3787 4 av_buffer_unref(&ctx->bitstream_buffer);
3788 }
3789
3790 5411 return ff_mpeg4_parse_picture_header(ctx, &h->gb, 0, 0);
3791 }
3792
3793 5240 int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
3794 {
3795 5240 Mpeg4DecContext *ctx = avctx->priv_data;
3796 5240 H263DecContext *const h = &ctx->h;
3797 int ret;
3798
3799 av_assert1(!ctx->bitstream_buffer || !ctx->bitstream_buffer->size);
3800
3801 /* divx 5.01+ bitstream reorder stuff */
3802
2/2
✓ Branch 2 → 3 taken 15 times.
✓ Branch 2 → 25 taken 5225 times.
5240 if (h->divx_packed) {
3803
3/4
✓ Branch 3 → 4 taken 7 times.
✓ Branch 3 → 5 taken 8 times.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 7 times.
15 int current_pos = ctx->bitstream_buffer && h->gb.buffer == ctx->bitstream_buffer->data ? 0 : (get_bits_count(&h->gb) >> 3);
3804 15 int startcode_found = 0;
3805 15 uint8_t *buf = pkt->data;
3806 15 int buf_size = pkt->size;
3807
3808
2/2
✓ Branch 8 → 9 taken 8 times.
✓ Branch 8 → 17 taken 7 times.
15 if (buf_size - current_pos > 7) {
3809
3810 int i;
3811
1/2
✓ Branch 16 → 10 taken 13 times.
✗ Branch 16 → 17 not taken.
13 for (i = current_pos; i < buf_size - 4; i++)
3812
3813
2/2
✓ Branch 10 → 11 taken 8 times.
✓ Branch 10 → 15 taken 5 times.
13 if (buf[i] == 0 &&
3814
1/2
✓ Branch 11 → 12 taken 8 times.
✗ Branch 11 → 15 not taken.
8 buf[i + 1] == 0 &&
3815
1/2
✓ Branch 12 → 13 taken 8 times.
✗ Branch 12 → 15 not taken.
8 buf[i + 2] == 1 &&
3816
1/2
✓ Branch 13 → 14 taken 8 times.
✗ Branch 13 → 15 not taken.
8 buf[i + 3] == 0xB6) {
3817 8 startcode_found = !(buf[i + 4] & 0x40);
3818 8 break;
3819 }
3820 }
3821
3822
2/2
✓ Branch 17 → 18 taken 8 times.
✓ Branch 17 → 25 taken 7 times.
15 if (startcode_found) {
3823
2/2
✓ Branch 18 → 19 taken 1 time.
✓ Branch 18 → 21 taken 7 times.
8 if (!ctx->showed_packed_warning) {
3824 1 av_log(h->c.avctx, AV_LOG_INFO, "Video uses a non-standard and "
3825 "wasteful way to store B-frames ('packed B-frames'). "
3826 "Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it.\n");
3827 1 ctx->showed_packed_warning = 1;
3828 }
3829 8 ret = av_buffer_replace(&ctx->bitstream_buffer, pkt->buf);
3830
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 24 taken 8 times.
8 if (ret < 0)
3831 ✗ return ret;
3832
3833 8 ctx->bitstream_buffer->data = buf + current_pos;
3834 8 ctx->bitstream_buffer->size = buf_size - current_pos;
3835 }
3836 }
3837
3838 5240 return 0;
3839 }
3840
3841 #if HAVE_THREADS
3842 16 static av_cold void clear_context(MpegEncContext *s)
3843 {
3844 16 memset(&s->buffer_pools, 0, sizeof(s->buffer_pools));
3845 16 memset(&s->next_pic, 0, sizeof(s->next_pic));
3846 16 memset(&s->last_pic, 0, sizeof(s->last_pic));
3847 16 memset(&s->cur_pic, 0, sizeof(s->cur_pic));
3848
3849 16 memset(s->thread_context, 0, sizeof(s->thread_context));
3850
3851 16 s->ac_val_base = NULL;
3852 16 s->ac_val = NULL;
3853 16 memset(&s->sc, 0, sizeof(s->sc));
3854
3855 16 s->p_field_mv_table_base = NULL;
3856
2/2
✓ Branch 7 → 3 taken 32 times.
✓ Branch 7 → 8 taken 16 times.
48 for (int i = 0; i < 2; i++)
3857
2/2
✓ Branch 5 → 4 taken 64 times.
✓ Branch 5 → 6 taken 32 times.
96 for (int j = 0; j < 2; j++)
3858 64 s->p_field_mv_table[i][j] = NULL;
3859
3860 16 s->dc_val_base = NULL;
3861 16 s->coded_block_base = NULL;
3862 16 s->mbintra_table = NULL;
3863 16 s->cbp_table = NULL;
3864 16 s->pred_dir_table = NULL;
3865
3866 16 s->mbskip_table = NULL;
3867
3868 16 s->er.error_status_table = NULL;
3869 16 s->er.er_temp_buffer = NULL;
3870 16 s->mb_index2xy = NULL;
3871
3872 16 s->context_initialized = 0;
3873 16 s->context_reinit = 0;
3874 16 }
3875
3876 16 static av_cold int update_mpvctx(MpegEncContext *s, const MpegEncContext *s1)
3877 {
3878 16 AVCodecContext *avctx = s->avctx;
3879 // FIXME the following leads to a data race; instead copy only
3880 // the necessary fields.
3881 16 memcpy(s, s1, sizeof(*s));
3882 16 clear_context(s);
3883
3884 16 s->avctx = avctx;
3885
3886
1/2
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 7 not taken.
16 if (s1->context_initialized) {
3887 16 int err = ff_mpv_common_init(s);
3888
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 16 times.
16 if (err < 0)
3889 ✗ return err;
3890 }
3891 16 return 0;
3892 }
3893
3894 1846 static int mpeg4_update_thread_context(AVCodecContext *dst,
3895 const AVCodecContext *src)
3896 {
3897 1846 Mpeg4DecContext *s = dst->priv_data;
3898 1846 const Mpeg4DecContext *s1 = src->priv_data;
3899 1846 int init = s->h.c.context_initialized;
3900 int ret;
3901
3902
2/2
✓ Branch 2 → 3 taken 16 times.
✓ Branch 2 → 6 taken 1830 times.
1846 if (!init) {
3903 16 ret = update_mpvctx(&s->h.c, &s1->h.c);
3904
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 16 times.
16 if (ret < 0)
3905 ✗ return ret;
3906 }
3907
3908 1846 ret = ff_mpeg_update_thread_context(dst, src);
3909
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 1846 times.
1846 if (ret < 0)
3910 ✗ return ret;
3911
3912 // copy all the necessary fields explicitly
3913 1846 s->time_increment_bits = s1->time_increment_bits;
3914 1846 s->shape = s1->shape;
3915 1846 s->vol_sprite_usage = s1->vol_sprite_usage;
3916 1846 s->sprite_brightness_change = s1->sprite_brightness_change;
3917 1846 s->sprite_warping_accuracy = s1->sprite_warping_accuracy;
3918 1846 s->num_sprite_warping_points = s1->num_sprite_warping_points;
3919 1846 s->h.data_partitioning = s1->h.data_partitioning;
3920 1846 s->mpeg_quant = s1->mpeg_quant;
3921 1846 s->rvlc = s1->rvlc;
3922 1846 s->resync_marker = s1->resync_marker;
3923 1846 s->t_frame = s1->t_frame;
3924 1846 s->new_pred = s1->new_pred;
3925 1846 s->enhancement_type = s1->enhancement_type;
3926 1846 s->scalability = s1->scalability;
3927 1846 s->intra_dc_threshold = s1->intra_dc_threshold;
3928 1846 s->h.divx_packed = s1->h.divx_packed;
3929 1846 s->divx_version = s1->divx_version;
3930 1846 s->divx_build = s1->divx_build;
3931 1846 s->xvid_build = s1->xvid_build;
3932 1846 s->lavc_build = s1->lavc_build;
3933 1846 s->vo_type = s1->vo_type;
3934 1846 s->showed_packed_warning = s1->showed_packed_warning;
3935 1846 s->vol_control_parameters = s1->vol_control_parameters;
3936 1846 s->cplx_estimation_trash_i = s1->cplx_estimation_trash_i;
3937 1846 s->cplx_estimation_trash_p = s1->cplx_estimation_trash_p;
3938 1846 s->cplx_estimation_trash_b = s1->cplx_estimation_trash_b;
3939 1846 s->rgb = s1->rgb;
3940 1846 s->h.c.studio_profile = s1->h.c.studio_profile;
3941
3942 1846 s->h.skipped_last_frame = s1->h.skipped_last_frame;
3943 1846 s->h.padding_bug_score = s1->h.padding_bug_score; // FIXME: racy
3944
3945 1846 s->h.picture_number = s1->h.picture_number;
3946
3947 1846 memcpy(s->sprite_shift, s1->sprite_shift, sizeof(s1->sprite_shift));
3948 1846 memcpy(s->sprite_traj, s1->sprite_traj, sizeof(s1->sprite_traj));
3949
3950 1846 return av_buffer_replace(&s->bitstream_buffer, s1->bitstream_buffer);
3951 }
3952
3953 1834 static int mpeg4_update_thread_context_for_user(AVCodecContext *dst,
3954 const AVCodecContext *src)
3955 {
3956 1834 H263DecContext *const h = dst->priv_data;
3957 1834 const H263DecContext *const h1 = src->priv_data;
3958
3959 1834 h->c.quarter_sample = h1->c.quarter_sample;
3960 1834 h->divx_packed = h1->divx_packed;
3961
3962 1834 return 0;
3963 }
3964 #endif
3965
3966 124 static av_cold void mpeg4_init_static(void)
3967 {
3968 static VLCElem vlc_buf[6498];
3969 124 VLCInitState state = VLC_INIT_STATE(vlc_buf);
3970
3971 124 VLC_INIT_STATIC_TABLE_FROM_LENGTHS(studio_luma_dc, STUDIO_INTRA_BITS, 19,
3972 &ff_mpeg4_studio_dc_luma[0][1], 2,
3973 &ff_mpeg4_studio_dc_luma[0][0], 2, 1,
3974 0, 0);
3975
3976 124 VLC_INIT_STATIC_TABLE_FROM_LENGTHS(studio_chroma_dc, STUDIO_INTRA_BITS, 19,
3977 &ff_mpeg4_studio_dc_chroma[0][1], 2,
3978 &ff_mpeg4_studio_dc_chroma[0][0], 2, 1,
3979 0, 0);
3980
3981
2/2
✓ Branch 7 → 5 taken 1488 times.
✓ Branch 7 → 8 taken 124 times.
1612 for (unsigned i = 0; i < 12; i++) {
3982 1488 studio_intra_tab[i] =
3983 1488 ff_vlc_init_tables_from_lengths(&state, STUDIO_INTRA_BITS, 24,
3984 1488 &ff_mpeg4_studio_intra[i][0][1], 2,
3985 1488 &ff_mpeg4_studio_intra[i][0][0], 2, 1,
3986 0, 0);
3987 }
3988
3989 static uint8_t mpeg4_rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
3990 124 ff_rl_init(&ff_mpeg4_rl_intra, mpeg4_rl_intra_table);
3991 124 ff_h263_init_rl_inter();
3992
3993 124 INIT_FIRST_VLC_RL(ff_mpeg4_rl_intra, 554);
3994
2/2
✓ Branch 13 → 12 taken 3968 times.
✓ Branch 13 → 14 taken 124 times.
4092 VLC_INIT_RL(ff_rvlc_rl_inter, 1072);
3995 124 INIT_FIRST_VLC_RL(ff_rvlc_rl_intra, 1072);
3996 124 VLC_INIT_STATIC_TABLE(dc_lum, DC_VLC_BITS, 10 /* 13 */,
3997 &ff_mpeg4_DCtab_lum[0][1], 2, 1,
3998 &ff_mpeg4_DCtab_lum[0][0], 2, 1, 0);
3999 124 VLC_INIT_STATIC_TABLE(dc_chrom, DC_VLC_BITS, 10 /* 13 */,
4000 &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
4001 &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 0);
4002 124 VLC_INIT_STATIC_TABLE_FROM_LENGTHS(sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
4003 ff_sprite_trajectory_lens, 1,
4004 NULL, 0, 0, 0, 0);
4005 124 VLC_INIT_STATIC_SPARSE_TABLE(mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
4006 &ff_mb_type_b_tab[0][1], 2, 1,
4007 &ff_mb_type_b_tab[0][0], 2, 1,
4008 mb_type_b_map, 2, 2, 0);
4009 124 }
4010
4011 231 static av_cold int decode_init(AVCodecContext *avctx)
4012 {
4013 static AVOnce init_static_once = AV_ONCE_INIT;
4014 231 Mpeg4DecContext *ctx = avctx->priv_data;
4015 231 H263DecContext *const h = &ctx->h;
4016 MPVUnquantDSPContext unquant_dsp_ctx;
4017 int ret;
4018
4019 231 ctx->divx_version =
4020 231 ctx->divx_build =
4021 231 ctx->xvid_build =
4022 231 ctx->lavc_build = -1;
4023
4024
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 231 times.
231 if ((ret = ff_h263_decode_init(avctx)) < 0)
4025 ✗ return ret;
4026
4027 231 ff_mpv_unquantize_init(&unquant_dsp_ctx,
4028 avctx->flags & AV_CODEC_FLAG_BITEXACT, 0);
4029
4030 231 ctx->dct_unquantize_h263_intra = unquant_dsp_ctx.dct_unquantize_h263_intra;
4031 231 ctx->dct_unquantize_mpeg2_intra = unquant_dsp_ctx.dct_unquantize_mpeg2_intra;
4032 // dct_unquantize_inter is only used with MPEG-2 quantizers,
4033 // so that is all we keep.
4034 231 ctx->dct_unquantize_mpeg2_inter = unquant_dsp_ctx.dct_unquantize_mpeg2_inter;
4035
4036 231 h->c.y_dc_scale_table = ff_mpeg4_y_dc_scale_table;
4037 231 h->c.c_dc_scale_table = ff_mpeg4_c_dc_scale_table;
4038
4039 231 h->c.h263_pred = 1;
4040 231 h->c.low_delay = 0; /* default, might be overridden in the vol header during header parsing */
4041 231 h->decode_header = mpeg4_decode_picture_header;
4042 231 h->decode_mb = mpeg4_decode_mb;
4043 231 ctx->time_increment_bits = 4; /* default value for broken headers */
4044 231 ctx->quant_precision = 5;
4045
4046 231 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
4047
4048 231 ff_qpeldsp_init(&h->c.qdsp);
4049 231 ff_mpeg4videodsp_init(&ctx->mdsp);
4050
4051 231 ff_thread_once(&init_static_once, mpeg4_init_static);
4052
4053 /* Must be after initializing the MPEG-4 static tables */
4054
4/4
✓ Branch 9 → 10 taken 161 times.
✓ Branch 9 → 15 taken 70 times.
✓ Branch 10 → 11 taken 145 times.
✓ Branch 10 → 15 taken 16 times.
231 if (avctx->extradata_size && !avctx->internal->is_copy) {
4055 GetBitContext gb;
4056
4057
1/2
✓ Branch 12 → 13 taken 145 times.
✗ Branch 12 → 14 not taken.
145 if (init_get_bits8(&gb, avctx->extradata, avctx->extradata_size) >= 0)
4058 145 ff_mpeg4_parse_picture_header(ctx, &gb, 1, 0);
4059 }
4060
4061 231 return 0;
4062 }
4063
4064 ✗ static av_cold void mpeg4_flush(AVCodecContext *avctx)
4065 {
4066 ✗ Mpeg4DecContext *const ctx = avctx->priv_data;
4067
4068 ✗ av_buffer_unref(&ctx->bitstream_buffer);
4069 ✗ ff_mpeg_flush(avctx);
4070 ✗ }
4071
4072 231 static av_cold int mpeg4_close(AVCodecContext *avctx)
4073 {
4074 231 Mpeg4DecContext *const ctx = avctx->priv_data;
4075
4076 231 av_buffer_unref(&ctx->bitstream_buffer);
4077
4078 231 return ff_mpv_decode_close(avctx);
4079 }
4080
4081 #define OFFSET(x) offsetof(H263DecContext, x)
4082 #define FLAGS AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY
4083 static const AVOption mpeg4_options[] = {
4084 {"quarter_sample", "1/4 subpel MC", OFFSET(c.quarter_sample), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS},
4085 {"divx_packed", "divx style packed b frames", OFFSET(divx_packed), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS},
4086 {NULL}
4087 };
4088
4089 static const AVClass mpeg4_class = {
4090 .class_name = "MPEG4 Video Decoder",
4091 .item_name = av_default_item_name,
4092 .option = mpeg4_options,
4093 .version = LIBAVUTIL_VERSION_INT,
4094 };
4095
4096 const FFCodec ff_mpeg4_decoder = {
4097 .p.name = "mpeg4",
4098 CODEC_LONG_NAME("MPEG-4 part 2"),
4099 .p.type = AVMEDIA_TYPE_VIDEO,
4100 .p.id = AV_CODEC_ID_MPEG4,
4101 .priv_data_size = sizeof(Mpeg4DecContext),
4102 .init = decode_init,
4103 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
4104 .close = mpeg4_close,
4105 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
4106 AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS,
4107 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
4108 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
4109 .flush = mpeg4_flush,
4110 .p.max_lowres = 3,
4111 .p.profiles = NULL_IF_CONFIG_SMALL(ff_mpeg4_video_profiles),
4112 UPDATE_THREAD_CONTEXT(mpeg4_update_thread_context),
4113 UPDATE_THREAD_CONTEXT_FOR_USER(mpeg4_update_thread_context_for_user),
4114 .p.priv_class = &mpeg4_class,
4115 .hw_configs = (const AVCodecHWConfigInternal *const []) {
4116 #if CONFIG_MPEG4_NVDEC_HWACCEL
4117 HWACCEL_NVDEC(mpeg4),
4118 #endif
4119 #if CONFIG_MPEG4_NVDEC_CUARRAY_HWACCEL
4120 HWACCEL_NVDEC_CUARRAY(mpeg4),
4121 #endif
4122 #if CONFIG_MPEG4_VAAPI_HWACCEL
4123 HWACCEL_VAAPI(mpeg4),
4124 #endif
4125 #if CONFIG_MPEG4_VDPAU_HWACCEL
4126 HWACCEL_VDPAU(mpeg4),
4127 #endif
4128 #if CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
4129 HWACCEL_VIDEOTOOLBOX(mpeg4),
4130 #endif
4131 NULL
4132 },
4133 };
4134 #endif /* CONFIG_MPEG4_DECODER */
4135