FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/wmv2dec.c
Date: 2022-01-28 07:56:06
Exec Total Coverage
Lines: 276 309 89.3%
Branches: 154 189 81.5%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2002 The FFmpeg Project
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "avcodec.h"
22 #include "h263.h"
23 #include "internal.h"
24 #include "intrax8.h"
25 #include "mathops.h"
26 #include "mpegutils.h"
27 #include "mpegvideo.h"
28 #include "msmpeg4.h"
29 #include "msmpeg4data.h"
30 #include "simple_idct.h"
31 #include "wmv2.h"
32
33
34 1140894 static void wmv2_add_block(Wmv2Context *w, int16_t *block1,
35 uint8_t *dst, int stride, int n)
36 {
37 1140894 MpegEncContext *const s = &w->s;
38
39
2/2
✓ Branch 0 taken 180589 times.
✓ Branch 1 taken 960305 times.
1140894 if (s->block_last_index[n] >= 0) {
40
3/4
✓ Branch 0 taken 149142 times.
✓ Branch 1 taken 16469 times.
✓ Branch 2 taken 14978 times.
✗ Branch 3 not taken.
180589 switch (w->abt_type_table[n]) {
41 149142 case 0:
42 149142 w->wdsp.idct_add(dst, stride, block1);
43 149142 break;
44 16469 case 1:
45 16469 ff_simple_idct84_add(dst, stride, block1);
46 16469 ff_simple_idct84_add(dst + 4 * stride, stride, w->abt_block2[n]);
47 16469 s->bdsp.clear_block(w->abt_block2[n]);
48 16469 break;
49 14978 case 2:
50 14978 ff_simple_idct48_add(dst, stride, block1);
51 14978 ff_simple_idct48_add(dst + 4, stride, w->abt_block2[n]);
52 14978 s->bdsp.clear_block(w->abt_block2[n]);
53 14978 break;
54 default:
55 av_log(s->avctx, AV_LOG_ERROR, "internal error in WMV2 abt\n");
56 }
57 }
58 1140894 }
59
60 190149 void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64],
61 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr)
62 {
63 190149 Wmv2Context *const w = (Wmv2Context *) s;
64
65 190149 wmv2_add_block(w, block1[0], dest_y, s->linesize, 0);
66 190149 wmv2_add_block(w, block1[1], dest_y + 8, s->linesize, 1);
67 190149 wmv2_add_block(w, block1[2], dest_y + 8 * s->linesize, s->linesize, 2);
68 190149 wmv2_add_block(w, block1[3], dest_y + 8 + 8 * s->linesize, s->linesize, 3);
69
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 190149 times.
190149 if (s->avctx->flags & AV_CODEC_FLAG_GRAY)
71 return;
72
73 190149 wmv2_add_block(w, block1[4], dest_cb, s->uvlinesize, 4);
74 190149 wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5);
75 }
76
77 645 static int parse_mb_skip(Wmv2Context *w)
78 {
79 int mb_x, mb_y;
80 645 int coded_mb_count = 0;
81 645 MpegEncContext *const s = &w->s;
82 645 uint32_t *const mb_type = s->current_picture_ptr->mb_type;
83
84 645 w->skip_type = get_bits(&s->gb, 2);
85
4/5
✓ Branch 0 taken 230 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 354 times.
✓ Branch 3 taken 33 times.
✗ Branch 4 not taken.
645 switch (w->skip_type) {
86 230 case SKIP_TYPE_NONE:
87
2/2
✓ Branch 0 taken 3315 times.
✓ Branch 1 taken 230 times.
3545 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
88
2/2
✓ Branch 0 taken 68865 times.
✓ Branch 1 taken 3315 times.
72180 for (mb_x = 0; mb_x < s->mb_width; mb_x++)
89 68865 mb_type[mb_y * s->mb_stride + mb_x] =
90 MB_TYPE_16x16 | MB_TYPE_L0;
91 230 break;
92 28 case SKIP_TYPE_MPEG:
93
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
28 if (get_bits_left(&s->gb) < s->mb_height * s->mb_width)
94 return AVERROR_INVALIDDATA;
95
2/2
✓ Branch 0 taken 420 times.
✓ Branch 1 taken 28 times.
448 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
96
2/2
✓ Branch 0 taken 8400 times.
✓ Branch 1 taken 420 times.
8820 for (mb_x = 0; mb_x < s->mb_width; mb_x++)
97 8400 mb_type[mb_y * s->mb_stride + mb_x] =
98
2/2
✓ Branch 1 taken 5149 times.
✓ Branch 2 taken 3251 times.
8400 (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
99 28 break;
100 354 case SKIP_TYPE_ROW:
101
2/2
✓ Branch 0 taken 5310 times.
✓ Branch 1 taken 354 times.
5664 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
102
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5310 times.
5310 if (get_bits_left(&s->gb) < 1)
103 return AVERROR_INVALIDDATA;
104
2/2
✓ Branch 1 taken 820 times.
✓ Branch 2 taken 4490 times.
5310 if (get_bits1(&s->gb)) {
105
2/2
✓ Branch 0 taken 16400 times.
✓ Branch 1 taken 820 times.
17220 for (mb_x = 0; mb_x < s->mb_width; mb_x++)
106 16400 mb_type[mb_y * s->mb_stride + mb_x] =
107 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
108 } else {
109
2/2
✓ Branch 0 taken 89800 times.
✓ Branch 1 taken 4490 times.
94290 for (mb_x = 0; mb_x < s->mb_width; mb_x++)
110 89800 mb_type[mb_y * s->mb_stride + mb_x] =
111
2/2
✓ Branch 1 taken 42505 times.
✓ Branch 2 taken 47295 times.
89800 (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
112 }
113 }
114 354 break;
115 33 case SKIP_TYPE_COL:
116
2/2
✓ Branch 0 taken 660 times.
✓ Branch 1 taken 33 times.
693 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
117
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 660 times.
660 if (get_bits_left(&s->gb) < 1)
118 return AVERROR_INVALIDDATA;
119
2/2
✓ Branch 1 taken 171 times.
✓ Branch 2 taken 489 times.
660 if (get_bits1(&s->gb)) {
120
2/2
✓ Branch 0 taken 2565 times.
✓ Branch 1 taken 171 times.
2736 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
121 2565 mb_type[mb_y * s->mb_stride + mb_x] =
122 MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
123 } else {
124
2/2
✓ Branch 0 taken 7335 times.
✓ Branch 1 taken 489 times.
7824 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
125 7335 mb_type[mb_y * s->mb_stride + mb_x] =
126
2/2
✓ Branch 1 taken 5106 times.
✓ Branch 2 taken 2229 times.
7335 (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0;
127 }
128 }
129 33 break;
130 }
131
132
2/2
✓ Branch 0 taken 9540 times.
✓ Branch 1 taken 645 times.
10185 for (mb_y = 0; mb_y < s->mb_height; mb_y++)
133
2/2
✓ Branch 0 taken 193365 times.
✓ Branch 1 taken 9540 times.
202905 for (mb_x = 0; mb_x < s->mb_width; mb_x++)
134 193365 coded_mb_count += !IS_SKIP(mb_type[mb_y * s->mb_stride + mb_x]);
135
136
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
645 if (coded_mb_count > get_bits_left(&s->gb))
137 return AVERROR_INVALIDDATA;
138
139 645 return 0;
140 }
141
142 5 static int decode_ext_header(Wmv2Context *w)
143 {
144 5 MpegEncContext *const s = &w->s;
145 GetBitContext gb;
146 int fps;
147 int code;
148
149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (s->avctx->extradata_size < 4)
150 return AVERROR_INVALIDDATA;
151
152 5 init_get_bits(&gb, s->avctx->extradata, 32);
153
154 5 fps = get_bits(&gb, 5);
155 5 s->bit_rate = get_bits(&gb, 11) * 1024;
156 5 w->mspel_bit = get_bits1(&gb);
157 5 s->loop_filter = get_bits1(&gb);
158 5 w->abt_flag = get_bits1(&gb);
159 5 w->j_type_bit = get_bits1(&gb);
160 5 w->top_left_mv_flag = get_bits1(&gb);
161 5 w->per_mb_rl_bit = get_bits1(&gb);
162 5 code = get_bits(&gb, 3);
163
164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (code == 0)
165 return AVERROR_INVALIDDATA;
166
167 5 s->slice_height = s->mb_height / code;
168
169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
170 av_log(s->avctx, AV_LOG_DEBUG,
171 "fps:%d, br:%"PRId64", qpbit:%d, abt_flag:%d, j_type_bit:%d, "
172 "tl_mv_flag:%d, mbrl_bit:%d, code:%d, loop_filter:%d, "
173 "slices:%d\n",
174 fps, s->bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit,
175 w->top_left_mv_flag, w->per_mb_rl_bit, code, s->loop_filter,
176 code);
177 5 return 0;
178 }
179
180 674 int ff_wmv2_decode_picture_header(MpegEncContext *s)
181 {
182 674 Wmv2Context *const w = (Wmv2Context *) s;
183 int code;
184
185
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 669 times.
674 if (s->picture_number == 0)
186 5 decode_ext_header(w);
187
188 674 s->pict_type = get_bits1(&s->gb) + 1;
189
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 645 times.
674 if (s->pict_type == AV_PICTURE_TYPE_I) {
190 29 code = get_bits(&s->gb, 7);
191 29 av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code);
192 }
193 674 s->chroma_qscale = s->qscale = get_bits(&s->gb, 5);
194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 674 times.
674 if (s->qscale <= 0)
195 return AVERROR_INVALIDDATA;
196
197
4/4
✓ Branch 0 taken 645 times.
✓ Branch 1 taken 29 times.
✓ Branch 3 taken 387 times.
✓ Branch 4 taken 258 times.
674 if (s->pict_type != AV_PICTURE_TYPE_I && show_bits(&s->gb, 1)) {
198 387 GetBitContext gb = s->gb;
199 387 int skip_type = get_bits(&gb, 2);
200
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 354 times.
387 int run = skip_type == SKIP_TYPE_COL ? s->mb_width : s->mb_height;
201
202
1/2
✓ Branch 0 taken 387 times.
✗ Branch 1 not taken.
387 while (run > 0) {
203 387 int block = FFMIN(run, 25);
204
1/2
✓ Branch 1 taken 387 times.
✗ Branch 2 not taken.
387 if (get_bits(&gb, block) + 1 != 1<<block)
205 387 break;
206 run -= block;
207 }
208
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 387 times.
387 if (!run)
209 return FRAME_SKIPPED;
210 }
211
212 674 return 0;
213 }
214
215 674 int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
216 {
217 674 Wmv2Context *const w = (Wmv2Context *) s;
218
219
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 645 times.
674 if (s->pict_type == AV_PICTURE_TYPE_I) {
220
1/2
✓ Branch 0 taken 29 times.
✗ Branch 1 not taken.
29 if (w->j_type_bit)
221 29 w->j_type = get_bits1(&s->gb);
222 else
223 w->j_type = 0; // FIXME check
224
225
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 3 times.
29 if (!w->j_type) {
226
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if (w->per_mb_rl_bit)
227 26 s->per_mb_rl_table = get_bits1(&s->gb);
228 else
229 s->per_mb_rl_table = 0;
230
231
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if (!s->per_mb_rl_table) {
232 26 s->rl_chroma_table_index = decode012(&s->gb);
233 26 s->rl_table_index = decode012(&s->gb);
234 }
235
236 26 s->dc_table_index = get_bits1(&s->gb);
237
238 // at minimum one bit per macroblock is required at least in a valid frame,
239 // we discard frames much smaller than this. Frames smaller than 1/8 of the
240 // smallest "black/skip" frame generally contain not much recoverable content
241 // while at the same time they have the highest computational requirements
242 // per byte
243
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
26 if (get_bits_left(&s->gb) * 8LL < (s->width+15)/16 * ((s->height+15)/16))
244 return AVERROR_INVALIDDATA;
245 }
246 29 s->inter_intra_pred = 0;
247 29 s->no_rounding = 1;
248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
29 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
249 av_log(s->avctx, AV_LOG_DEBUG,
250 "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n",
251 s->qscale, s->rl_chroma_table_index, s->rl_table_index,
252 s->dc_table_index, s->per_mb_rl_table, w->j_type);
253 }
254 } else {
255 int cbp_index;
256 int ret;
257 645 w->j_type = 0;
258
259 645 ret = parse_mb_skip(w);
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 645 times.
645 if (ret < 0)
261 return ret;
262 645 cbp_index = decode012(&s->gb);
263 645 w->cbp_table_index = wmv2_get_cbp_table_index(s, cbp_index);
264
265
1/2
✓ Branch 0 taken 645 times.
✗ Branch 1 not taken.
645 if (w->mspel_bit)
266 645 s->mspel = get_bits1(&s->gb);
267 else
268 s->mspel = 0; // FIXME check
269
270
1/2
✓ Branch 0 taken 645 times.
✗ Branch 1 not taken.
645 if (w->abt_flag) {
271 645 w->per_mb_abt = get_bits1(&s->gb) ^ 1;
272
2/2
✓ Branch 0 taken 187 times.
✓ Branch 1 taken 458 times.
645 if (!w->per_mb_abt)
273 187 w->abt_type = decode012(&s->gb);
274 }
275
276
1/2
✓ Branch 0 taken 645 times.
✗ Branch 1 not taken.
645 if (w->per_mb_rl_bit)
277 645 s->per_mb_rl_table = get_bits1(&s->gb);
278 else
279 s->per_mb_rl_table = 0;
280
281
2/2
✓ Branch 0 taken 617 times.
✓ Branch 1 taken 28 times.
645 if (!s->per_mb_rl_table) {
282 617 s->rl_table_index = decode012(&s->gb);
283 617 s->rl_chroma_table_index = s->rl_table_index;
284 }
285
286
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 645 times.
645 if (get_bits_left(&s->gb) < 2)
287 return AVERROR_INVALIDDATA;
288
289 645 s->dc_table_index = get_bits1(&s->gb);
290 645 s->mv_table_index = get_bits1(&s->gb);
291
292 645 s->inter_intra_pred = 0; // (s->width * s->height < 320 * 240 && s->bit_rate <= II_BITRATE);
293 645 s->no_rounding ^= 1;
294
295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 645 times.
645 if (s->avctx->debug & FF_DEBUG_PICT_INFO) {
296 av_log(s->avctx, AV_LOG_DEBUG,
297 "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d "
298 "per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n",
299 s->rl_table_index, s->rl_chroma_table_index,
300 s->dc_table_index, s->mv_table_index,
301 s->per_mb_rl_table, s->qscale, s->mspel,
302 w->per_mb_abt, w->abt_type, w->cbp_table_index,
303 s->inter_intra_pred);
304 }
305 }
306 674 s->esc3_level_length = 0;
307 674 s->esc3_run_length = 0;
308 674 s->picture_number++; // FIXME ?
309
310
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 671 times.
674 if (w->j_type) {
311 3 ff_intrax8_decode_picture(&w->x8, &s->current_picture,
312 &s->gb, &s->mb_x, &s->mb_y,
313 3 2 * s->qscale, (s->qscale - 1) | 1,
314 s->loop_filter, s->low_delay);
315
316 3 ff_er_add_slice(&w->s.er, 0, 0,
317 3 (w->s.mb_x >> 1) - 1, (w->s.mb_y >> 1) - 1,
318 ER_MB_END);
319 3 return 1;
320 }
321
322 671 return 0;
323 }
324
325 118424 static inline void wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr)
326 {
327 118424 MpegEncContext *const s = &w->s;
328
329 118424 ff_msmpeg4_decode_motion(s, mx_ptr, my_ptr);
330
331
4/4
✓ Branch 0 taken 50949 times.
✓ Branch 1 taken 67475 times.
✓ Branch 2 taken 19528 times.
✓ Branch 3 taken 31421 times.
118424 if ((((*mx_ptr) | (*my_ptr)) & 1) && s->mspel)
332 19528 w->hshift = get_bits1(&s->gb);
333 else
334 98896 w->hshift = 0;
335 118424 }
336
337 118424 static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py)
338 {
339 118424 MpegEncContext *const s = &w->s;
340 int xy, wrap, diff, type;
341 int16_t *A, *B, *C, *mot_val;
342
343 118424 wrap = s->b8_stride;
344 118424 xy = s->block_index[0];
345
346 118424 mot_val = s->current_picture.motion_val[0][xy];
347
348 118424 A = s->current_picture.motion_val[0][xy - 1];
349 118424 B = s->current_picture.motion_val[0][xy - wrap];
350 118424 C = s->current_picture.motion_val[0][xy + 2 - wrap];
351
352
8/8
✓ Branch 0 taken 113312 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 109268 times.
✓ Branch 3 taken 4044 times.
✓ Branch 4 taken 68720 times.
✓ Branch 5 taken 40548 times.
✓ Branch 6 taken 22431 times.
✓ Branch 7 taken 46289 times.
118424 if (s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag)
353 22431 diff = FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1]));
354 else
355 95993 diff = 0;
356
357
2/2
✓ Branch 0 taken 3203 times.
✓ Branch 1 taken 115221 times.
118424 if (diff >= 8)
358 3203 type = get_bits1(&s->gb);
359 else
360 115221 type = 2;
361
362
2/2
✓ Branch 0 taken 1698 times.
✓ Branch 1 taken 116726 times.
118424 if (type == 0) {
363 1698 *px = A[0];
364 1698 *py = A[1];
365
2/2
✓ Branch 0 taken 1505 times.
✓ Branch 1 taken 115221 times.
116726 } else if (type == 1) {
366 1505 *px = B[0];
367 1505 *py = B[1];
368 } else {
369 /* special case for first (slice) line */
370
2/2
✓ Branch 0 taken 4281 times.
✓ Branch 1 taken 110940 times.
115221 if (s->first_slice_line) {
371 4281 *px = A[0];
372 4281 *py = A[1];
373 } else {
374 110940 *px = mid_pred(A[0], B[0], C[0]);
375 110940 *py = mid_pred(A[1], B[1], C[1]);
376 }
377 }
378
379 118424 return mot_val;
380 }
381
382 710544 static inline int wmv2_decode_inter_block(Wmv2Context *w, int16_t *block,
383 int n, int cbp)
384 {
385 710544 MpegEncContext *const s = &w->s;
386 static const int sub_cbp_table[3] = { 2, 3, 1 };
387 int sub_cbp, ret;
388
389
2/2
✓ Branch 0 taken 529955 times.
✓ Branch 1 taken 180589 times.
710544 if (!cbp) {
390 529955 s->block_last_index[n] = -1;
391 529955 return 0;
392 }
393
394
2/2
✓ Branch 0 taken 20828 times.
✓ Branch 1 taken 159761 times.
180589 if (w->per_block_abt)
395 20828 w->abt_type = decode012(&s->gb);
396 180589 w->abt_type_table[n] = w->abt_type;
397
398
2/2
✓ Branch 0 taken 31447 times.
✓ Branch 1 taken 149142 times.
180589 if (w->abt_type) {
399 // const uint8_t *scantable = w->abt_scantable[w->abt_type - 1].permutated;
400 31447 const uint8_t *scantable = w->abt_scantable[w->abt_type - 1].scantable;
401 // const uint8_t *scantable = w->abt_type - 1 ? w->abt_scantable[1].permutated : w->abt_scantable[0].scantable;
402
403 31447 sub_cbp = sub_cbp_table[decode012(&s->gb)];
404
405
2/2
✓ Branch 0 taken 18950 times.
✓ Branch 1 taken 12497 times.
31447 if (sub_cbp & 1)
406
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 18950 times.
18950 if ((ret = ff_msmpeg4_decode_block(s, block, n, 1, scantable)) < 0)
407 return ret;
408
409
2/2
✓ Branch 0 taken 19090 times.
✓ Branch 1 taken 12357 times.
31447 if (sub_cbp & 2)
410
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 19090 times.
19090 if ((ret = ff_msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable)) < 0)
411 return ret;
412
413 31447 s->block_last_index[n] = 63;
414
415 31447 return 0;
416 } else {
417 149142 return ff_msmpeg4_decode_block(s, block, n, 1,
418 149142 s->inter_scantable.permutated);
419 }
420 }
421
422 201150 int ff_wmv2_decode_mb(MpegEncContext *s, int16_t block[6][64])
423 {
424 201150 Wmv2Context *const w = (Wmv2Context *) s;
425 int cbp, code, i, ret;
426 uint8_t *coded_val;
427
428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 201150 times.
201150 if (w->j_type)
429 return 0;
430
431
2/2
✓ Branch 0 taken 193365 times.
✓ Branch 1 taken 7785 times.
201150 if (s->pict_type == AV_PICTURE_TYPE_P) {
432
2/2
✓ Branch 0 taken 71725 times.
✓ Branch 1 taken 121640 times.
193365 if (IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])) {
433 /* skip mb */
434 71725 s->mb_intra = 0;
435
2/2
✓ Branch 0 taken 430350 times.
✓ Branch 1 taken 71725 times.
502075 for (i = 0; i < 6; i++)
436 430350 s->block_last_index[i] = -1;
437 71725 s->mv_dir = MV_DIR_FORWARD;
438 71725 s->mv_type = MV_TYPE_16X16;
439 71725 s->mv[0][0][0] = 0;
440 71725 s->mv[0][0][1] = 0;
441 71725 s->mb_skipped = 1;
442 71725 w->hshift = 0;
443 71725 return 0;
444 }
445
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 121640 times.
121640 if (get_bits_left(&s->gb) <= 0)
446 return AVERROR_INVALIDDATA;
447
448 121640 code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[w->cbp_table_index].table,
449 MB_NON_INTRA_VLC_BITS, 3);
450 121640 s->mb_intra = (~code & 0x40) >> 6;
451
452 121640 cbp = code & 0x3f;
453 } else {
454 7785 s->mb_intra = 1;
455
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 7785 times.
7785 if (get_bits_left(&s->gb) <= 0)
456 return AVERROR_INVALIDDATA;
457 7785 code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
458 /* predict coded block pattern */
459 7785 cbp = 0;
460
2/2
✓ Branch 0 taken 46710 times.
✓ Branch 1 taken 7785 times.
54495 for (i = 0; i < 6; i++) {
461 46710 int val = ((code >> (5 - i)) & 1);
462
2/2
✓ Branch 0 taken 31140 times.
✓ Branch 1 taken 15570 times.
46710 if (i < 4) {
463 31140 int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
464 31140 val = val ^ pred;
465 31140 *coded_val = val;
466 }
467 46710 cbp |= val << (5 - i);
468 }
469 }
470
471
2/2
✓ Branch 0 taken 118424 times.
✓ Branch 1 taken 11001 times.
129425 if (!s->mb_intra) {
472 int mx, my;
473 118424 wmv2_pred_motion(w, &mx, &my);
474
475
2/2
✓ Branch 0 taken 76773 times.
✓ Branch 1 taken 41651 times.
118424 if (cbp) {
476 76773 s->bdsp.clear_blocks(s->block[0]);
477
2/2
✓ Branch 0 taken 1656 times.
✓ Branch 1 taken 75117 times.
76773 if (s->per_mb_rl_table) {
478 1656 s->rl_table_index = decode012(&s->gb);
479 1656 s->rl_chroma_table_index = s->rl_table_index;
480 }
481
482
3/4
✓ Branch 0 taken 76773 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37493 times.
✓ Branch 3 taken 39280 times.
76773 if (w->abt_flag && w->per_mb_abt) {
483 37493 w->per_block_abt = get_bits1(&s->gb);
484
2/2
✓ Branch 0 taken 30618 times.
✓ Branch 1 taken 6875 times.
37493 if (!w->per_block_abt)
485 30618 w->abt_type = decode012(&s->gb);
486 } else
487 39280 w->per_block_abt = 0;
488 }
489
490 118424 wmv2_decode_motion(w, &mx, &my);
491
492 118424 s->mv_dir = MV_DIR_FORWARD;
493 118424 s->mv_type = MV_TYPE_16X16;
494 118424 s->mv[0][0][0] = mx;
495 118424 s->mv[0][0][1] = my;
496
497
2/2
✓ Branch 0 taken 710544 times.
✓ Branch 1 taken 118424 times.
828968 for (i = 0; i < 6; i++) {
498
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 710544 times.
710544 if ((ret = wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1)) < 0) {
499 av_log(s->avctx, AV_LOG_ERROR,
500 "\nerror while decoding inter block: %d x %d (%d)\n",
501 s->mb_x, s->mb_y, i);
502 return ret;
503 }
504 }
505 } else {
506 11001 if (s->pict_type == AV_PICTURE_TYPE_P)
507 ff_dlog(s->avctx, "%d%d ", s->inter_intra_pred, cbp);
508 ff_dlog(s->avctx, "I at %d %d %d %06X\n", s->mb_x, s->mb_y,
509 ((cbp & 3) ? 1 : 0) + ((cbp & 0x3C) ? 2 : 0),
510 show_bits(&s->gb, 24));
511 11001 s->ac_pred = get_bits1(&s->gb);
512
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11001 times.
11001 if (s->inter_intra_pred) {
513 s->h263_aic_dir = get_vlc2(&s->gb, ff_inter_intra_vlc.table,
514 INTER_INTRA_VLC_BITS, 1);
515 ff_dlog(s->avctx, "%d%d %d %d/",
516 s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
517 }
518
4/4
✓ Branch 0 taken 261 times.
✓ Branch 1 taken 10740 times.
✓ Branch 2 taken 128 times.
✓ Branch 3 taken 133 times.
11001 if (s->per_mb_rl_table && cbp) {
519 128 s->rl_table_index = decode012(&s->gb);
520 128 s->rl_chroma_table_index = s->rl_table_index;
521 }
522
523 11001 s->bdsp.clear_blocks(s->block[0]);
524
2/2
✓ Branch 0 taken 66006 times.
✓ Branch 1 taken 11001 times.
77007 for (i = 0; i < 6; i++) {
525
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 66006 times.
66006 if ((ret = ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL)) < 0) {
526 av_log(s->avctx, AV_LOG_ERROR,
527 "\nerror while decoding intra block: %d x %d (%d)\n",
528 s->mb_x, s->mb_y, i);
529 return ret;
530 }
531 }
532 }
533
534 129425 return 0;
535 }
536
537 12 static av_cold int wmv2_decode_init(AVCodecContext *avctx)
538 {
539 12 Wmv2Context *const w = avctx->priv_data;
540 int ret;
541
542
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if ((ret = ff_msmpeg4_decode_init(avctx)) < 0)
543 return ret;
544
545 12 ff_wmv2_common_init(w);
546
547 12 return ff_intrax8_common_init(avctx, &w->x8, &w->s.idsp,
548 12 w->s.block, w->s.block_last_index,
549 w->s.mb_width, w->s.mb_height);
550 }
551
552 12 static av_cold int wmv2_decode_end(AVCodecContext *avctx)
553 {
554 12 Wmv2Context *w = avctx->priv_data;
555
556 12 ff_intrax8_common_end(&w->x8);
557 12 return ff_h263_decode_end(avctx);
558 }
559
560 const AVCodec ff_wmv2_decoder = {
561 .name = "wmv2",
562 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 8"),
563 .type = AVMEDIA_TYPE_VIDEO,
564 .id = AV_CODEC_ID_WMV2,
565 .priv_data_size = sizeof(Wmv2Context),
566 .init = wmv2_decode_init,
567 .close = wmv2_decode_end,
568 .decode = ff_h263_decode_frame,
569 .capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
570 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
571 .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
572 AV_PIX_FMT_NONE },
573 };
574