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