FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/msmpeg4dec.c
Date: 2025-07-28 20:30:09
Exec Total Coverage
Lines: 411 480 85.6%
Functions: 11 11 100.0%
Branches: 205 268 76.5%

Line Branch Exec Source
1 /*
2 * MSMPEG4 backend for encoder and decoder
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2013 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #include "libavutil/thread.h"
26
27 #include "avcodec.h"
28 #include "codec_internal.h"
29 #include "mpegutils.h"
30 #include "mpegvideo.h"
31 #include "mpegvideodec.h"
32 #include "msmpeg4.h"
33 #include "msmpeg4dec.h"
34 #include "libavutil/imgutils.h"
35 #include "h263.h"
36 #include "h263data.h"
37 #include "h263dec.h"
38 #include "mpeg4videodec.h"
39 #include "msmpeg4data.h"
40 #include "msmpeg4_vc1_data.h"
41
42 #define V2_INTRA_CBPC_VLC_BITS 3
43 #define V2_MB_TYPE_VLC_BITS 7
44 #define MV_VLC_BITS 9
45 #define TEX_VLC_BITS 9
46
47 #define DEFAULT_INTER_INDEX 3
48
49 static const VLCElem *mv_tables[2];
50
51 5490 static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
52 int32_t **dc_val_ptr)
53 {
54 int i;
55
56
2/2
✓ Branch 0 taken 3660 times.
✓ Branch 1 taken 1830 times.
5490 if (n < 4) {
57 3660 i= 0;
58 } else {
59 1830 i= n-3;
60 }
61
62 5490 *dc_val_ptr= &s->last_dc[i];
63 5490 return s->last_dc[i];
64 }
65
66 /****************************************/
67 /* decoding stuff */
68
69 const VLCElem *ff_mb_non_intra_vlc[4];
70 static VLCElem v2_dc_lum_vlc[1472];
71 static VLCElem v2_dc_chroma_vlc[1506];
72 static VLCElem v2_intra_cbpc_vlc[8];
73 static VLCElem v2_mb_type_vlc[128];
74 VLCElem ff_inter_intra_vlc[8];
75
76 /* This is identical to H.263 except that its range is multiplied by 2. */
77 132268 static int msmpeg4v2_decode_motion(H263DecContext *const h, int pred, int f_code)
78 {
79 int code, val, sign, shift;
80
81 132268 code = get_vlc2(&h->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
82 ff_dlog(h->c.avctx, "MV code %d at %d %d pred: %d\n",
83 code, h->c.mb_x,h->c.mb_y, pred);
84
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132268 times.
132268 if (code < 0)
85 return 0xffff;
86
87
2/2
✓ Branch 0 taken 68571 times.
✓ Branch 1 taken 63697 times.
132268 if (code == 0)
88 68571 return pred;
89 63697 sign = get_bits1(&h->gb);
90 63697 shift = f_code - 1;
91 63697 val = code;
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63697 times.
63697 if (shift) {
93 val = (val - 1) << shift;
94 val |= get_bits(&h->gb, shift);
95 val++;
96 }
97
2/2
✓ Branch 0 taken 26289 times.
✓ Branch 1 taken 37408 times.
63697 if (sign)
98 26289 val = -val;
99
100 63697 val += pred;
101
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 63559 times.
63697 if (val <= -64)
102 138 val += 64;
103
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 63546 times.
63559 else if (val >= 64)
104 13 val -= 64;
105
106 63697 return val;
107 }
108
109 76350 static int msmpeg4v12_decode_mb(H263DecContext *const h)
110 {
111 76350 MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
112 int cbp, code, i;
113 76350 uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride];
114
115
2/2
✓ Branch 0 taken 70035 times.
✓ Branch 1 taken 6315 times.
76350 if (h->c.pict_type == AV_PICTURE_TYPE_P) {
116
1/2
✓ Branch 0 taken 70035 times.
✗ Branch 1 not taken.
70035 if (ms->use_skip_mb_code) {
117
2/2
✓ Branch 1 taken 1159 times.
✓ Branch 2 taken 68876 times.
70035 if (get_bits1(&h->gb)) {
118 /* skip mb */
119 1159 h->c.mb_intra = 0;
120
2/2
✓ Branch 0 taken 6954 times.
✓ Branch 1 taken 1159 times.
8113 for(i=0;i<6;i++)
121 6954 h->c.block_last_index[i] = -1;
122 1159 h->c.mv_dir = MV_DIR_FORWARD;
123 1159 h->c.mv_type = MV_TYPE_16X16;
124 1159 h->c.mv[0][0][0] = 0;
125 1159 h->c.mv[0][0][1] = 0;
126 1159 h->c.mb_skipped = 1;
127 1159 *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
128 1159 return 0;
129 }
130 }
131
132
2/2
✓ Branch 0 taken 53160 times.
✓ Branch 1 taken 15716 times.
68876 if (h->c.msmpeg4_version == MSMP4_V2)
133 53160 code = get_vlc2(&h->gb, v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 1);
134 else
135 15716 code = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
136
2/4
✓ Branch 0 taken 68876 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 68876 times.
68876 if(code<0 || code>7){
137 av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",
138 code, h->c.mb_x, h->c.mb_y);
139 return -1;
140 }
141
142 68876 h->c.mb_intra = code >>2;
143
144 68876 cbp = code & 0x3;
145 } else {
146 6315 h->c.mb_intra = 1;
147
2/2
✓ Branch 0 taken 5985 times.
✓ Branch 1 taken 330 times.
6315 if (h->c.msmpeg4_version == MSMP4_V2)
148 5985 cbp = get_vlc2(&h->gb, v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 1);
149 else
150 330 cbp = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
151
2/4
✓ Branch 0 taken 6315 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6315 times.
6315 if(cbp<0 || cbp>3){
152 av_log(h->c.avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n",
153 cbp, h->c.mb_x, h->c.mb_y);
154 return -1;
155 }
156 }
157
158
2/2
✓ Branch 0 taken 66134 times.
✓ Branch 1 taken 9057 times.
75191 if (!h->c.mb_intra) {
159 int mx, my, cbpy;
160
161 66134 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66134 times.
66134 if(cbpy<0){
163 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n",
164 cbp, h->c.mb_x, h->c.mb_y);
165 return -1;
166 }
167
168 66134 cbp|= cbpy<<2;
169
4/4
✓ Branch 0 taken 51003 times.
✓ Branch 1 taken 15131 times.
✓ Branch 2 taken 40593 times.
✓ Branch 3 taken 10410 times.
66134 if (h->c.msmpeg4_version == MSMP4_V1 || (cbp&3) != 3)
170 55724 cbp ^= 0x3C;
171
172 66134 ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);
173 66134 mx = msmpeg4v2_decode_motion(h, mx, 1);
174 66134 my = msmpeg4v2_decode_motion(h, my, 1);
175
176 66134 h->c.mv_dir = MV_DIR_FORWARD;
177 66134 h->c.mv_type = MV_TYPE_16X16;
178 66134 h->c.mv[0][0][0] = mx;
179 66134 h->c.mv[0][0][1] = my;
180 66134 *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
181 } else {
182 int v;
183
2/2
✓ Branch 0 taken 8142 times.
✓ Branch 1 taken 915 times.
9057 if (h->c.msmpeg4_version == MSMP4_V2) {
184 8142 h->c.ac_pred = get_bits1(&h->gb);
185 8142 v = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
186
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8142 times.
8142 if (v < 0) {
187 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
188 return -1;
189 }
190 8142 cbp|= v<<2;
191 } else{
192 915 h->c.ac_pred = 0;
193 915 v = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 915 times.
915 if (v < 0) {
195 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy vlc invalid\n");
196 return -1;
197 }
198 915 cbp|= v<<2;
199
2/2
✓ Branch 0 taken 585 times.
✓ Branch 1 taken 330 times.
915 if (h->c.pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
200 }
201 9057 *mb_type_ptr = MB_TYPE_INTRA;
202 }
203
204 75191 h->c.bdsp.clear_blocks(h->block[0]);
205
2/2
✓ Branch 0 taken 451146 times.
✓ Branch 1 taken 75191 times.
526337 for (i = 0; i < 6; i++) {
206
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 451146 times.
451146 if (ff_msmpeg4_decode_block(ms, h->block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
207 {
208 av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
209 h->c.mb_x, h->c.mb_y, i);
210 return -1;
211 }
212 }
213 75191 return 0;
214 }
215
216 129600 static int msmpeg4v34_decode_mb(H263DecContext *const h)
217 {
218 129600 MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
219 int cbp, code, i;
220 uint8_t *coded_val;
221 129600 uint32_t * const mb_type_ptr = &h->c.cur_pic.mb_type[h->c.mb_x + h->c.mb_y*h->c.mb_stride];
222
223
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 129600 times.
129600 if (get_bits_left(&h->gb) <= 0)
224 return AVERROR_INVALIDDATA;
225
226
2/2
✓ Branch 0 taken 116442 times.
✓ Branch 1 taken 13158 times.
129600 if (h->c.pict_type == AV_PICTURE_TYPE_P) {
227
1/2
✓ Branch 0 taken 116442 times.
✗ Branch 1 not taken.
116442 if (ms->use_skip_mb_code) {
228
2/2
✓ Branch 1 taken 1554 times.
✓ Branch 2 taken 114888 times.
116442 if (get_bits1(&h->gb)) {
229 /* skip mb */
230 1554 h->c.mb_intra = 0;
231
2/2
✓ Branch 0 taken 9324 times.
✓ Branch 1 taken 1554 times.
10878 for(i=0;i<6;i++)
232 9324 h->c.block_last_index[i] = -1;
233 1554 h->c.mv_dir = MV_DIR_FORWARD;
234 1554 h->c.mv_type = MV_TYPE_16X16;
235 1554 h->c.mv[0][0][0] = 0;
236 1554 h->c.mv[0][0][1] = 0;
237 1554 h->c.mb_skipped = 1;
238 1554 *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
239
240 1554 return 0;
241 }
242 }
243
244 114888 code = get_vlc2(&h->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX], MB_NON_INTRA_VLC_BITS, 3);
245 //h->c.mb_intra = (code & 0x40) ? 0 : 1;
246 114888 h->c.mb_intra = (~code & 0x40) >> 6;
247
248 114888 cbp = code & 0x3f;
249 } else {
250 13158 h->c.mb_intra = 1;
251 13158 code = get_vlc2(&h->gb, ff_msmp4_mb_i_vlc, MSMP4_MB_INTRA_VLC_BITS, 2);
252 /* predict coded block pattern */
253 13158 cbp = 0;
254
2/2
✓ Branch 0 taken 78948 times.
✓ Branch 1 taken 13158 times.
92106 for(i=0;i<6;i++) {
255 78948 int val = ((code >> (5 - i)) & 1);
256
2/2
✓ Branch 0 taken 52632 times.
✓ Branch 1 taken 26316 times.
78948 if (i < 4) {
257 52632 int pred = ff_msmpeg4_coded_block_pred(&h->c, i, &coded_val);
258 52632 val = val ^ pred;
259 52632 *coded_val = val;
260 }
261 78948 cbp |= val << (5 - i);
262 }
263 }
264
265
2/2
✓ Branch 0 taken 109652 times.
✓ Branch 1 taken 18394 times.
128046 if (!h->c.mb_intra) {
266 int mx, my;
267
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 109652 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
109652 if (ms->per_mb_rl_table && cbp) {
268 ms->rl_table_index = decode012(&h->gb);
269 ms->rl_chroma_table_index = ms->rl_table_index;
270 }
271 109652 ff_h263_pred_motion(&h->c, 0, 0, &mx, &my);
272 109652 ff_msmpeg4_decode_motion(ms, &mx, &my);
273 109652 h->c.mv_dir = MV_DIR_FORWARD;
274 109652 h->c.mv_type = MV_TYPE_16X16;
275 109652 h->c.mv[0][0][0] = mx;
276 109652 h->c.mv[0][0][1] = my;
277 109652 *mb_type_ptr = MB_TYPE_FORWARD_MV | MB_TYPE_16x16;
278 } else {
279 ff_dlog(h->c.avctx, "I at %d %d %d %06X\n", h->c.mb_x, h->c.mb_y,
280 ((cbp & 3) ? 1 : 0) +((cbp & 0x3C)? 2 : 0),
281 show_bits(&h->gb, 24));
282 18394 h->c.ac_pred = get_bits1(&h->gb);
283 18394 *mb_type_ptr = MB_TYPE_INTRA;
284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18394 times.
18394 if (h->c.inter_intra_pred) {
285 h->c.h263_aic_dir = get_vlc2(&h->gb, ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 1);
286 ff_dlog(h->c.avctx, "%d%d %d %d/",
287 h->c.ac_pred, h->c.h263_aic_dir, h->c.mb_x, h->c.mb_y);
288 }
289
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18394 if (ms->per_mb_rl_table && cbp) {
290 ms->rl_table_index = decode012(&h->gb);
291 ms->rl_chroma_table_index = ms->rl_table_index;
292 }
293 }
294
295 128046 h->c.bdsp.clear_blocks(h->block[0]);
296
2/2
✓ Branch 0 taken 768276 times.
✓ Branch 1 taken 128046 times.
896322 for (i = 0; i < 6; i++) {
297
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 768276 times.
768276 if (ff_msmpeg4_decode_block(ms, h->block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
298 {
299 av_log(h->c.avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n",
300 h->c.mb_x, h->c.mb_y, i);
301 return -1;
302 }
303 }
304
305 128046 return 0;
306 }
307
308 /* init all vlc decoding tables */
309 26 static av_cold void msmpeg4_decode_init_static(void)
310 {
311 static VLCElem vlc_buf[3714 + 2694 + 1636 + 2648 + 1532 + 2488];
312 26 VLCInitState state = VLC_INIT_STATE(vlc_buf);
313
314 26 INIT_FIRST_VLC_RL(ff_rl_table[0], 642);
315 26 INIT_FIRST_VLC_RL(ff_rl_table[1], 1104);
316 26 INIT_FIRST_VLC_RL(ff_rl_table[2], 554);
317
2/2
✓ Branch 0 taken 832 times.
✓ Branch 1 taken 26 times.
858 VLC_INIT_RL(ff_rl_table[3], 940);
318
2/2
✓ Branch 0 taken 832 times.
✓ Branch 1 taken 26 times.
858 VLC_INIT_RL(ff_rl_table[4], 962);
319 /* ff_rl_table[5] coincides with ff_h263_rl_inter which has just been
320 * initialized in ff_h263_decode_init() earlier. So just copy the VLCs. */
321 av_assert1(ff_h263_rl_inter.rl_vlc[0]);
322 26 memcpy(ff_rl_table[5].rl_vlc, ff_h263_rl_inter.rl_vlc, sizeof(ff_rl_table[5].rl_vlc));
323
324 26 VLC_INIT_STATIC_TABLE(v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 512,
325 &ff_v2_dc_lum_table[0][1], 8, 4,
326 &ff_v2_dc_lum_table[0][0], 8, 4, 0);
327 26 VLC_INIT_STATIC_TABLE(v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 512,
328 &ff_v2_dc_chroma_table[0][1], 8, 4,
329 &ff_v2_dc_chroma_table[0][0], 8, 4, 0);
330
331 26 VLC_INIT_STATIC_TABLE(v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
332 &ff_v2_intra_cbpc[0][1], 2, 1,
333 &ff_v2_intra_cbpc[0][0], 2, 1, 0);
334 26 VLC_INIT_STATIC_TABLE(v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8,
335 &ff_v2_mb_type[0][1], 2, 1,
336 &ff_v2_mb_type[0][0], 2, 1, 0);
337
338 26 mv_tables[0] = ff_vlc_init_tables_from_lengths(&state, MV_VLC_BITS,
339 MSMPEG4_MV_TABLES_NB_ELEMS,
340 ff_msmp4_mv_table0_lens, 1,
341 ff_msmp4_mv_table0, 2, 2,
342 0, 0);
343 26 mv_tables[1] = ff_vlc_init_tables_from_lengths(&state, MV_VLC_BITS,
344 MSMPEG4_MV_TABLES_NB_ELEMS,
345 ff_msmp4_mv_table1_lens, 1,
346 ff_msmp4_mv_table1, 2, 2,
347 0, 0);
348
349
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 26 times.
130 for (unsigned i = 0; i < 4; i++) {
350 104 ff_mb_non_intra_vlc[i] =
351 104 ff_vlc_init_tables_sparse(&state, MB_NON_INTRA_VLC_BITS, 128,
352 104 &ff_wmv2_inter_table[i][0][1], 8, 4,
353 104 &ff_wmv2_inter_table[i][0][0], 8, 4,
354 NULL, 0, 0, 0);
355 }
356
357 26 VLC_INIT_STATIC_TABLE(ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 4,
358 &ff_table_inter_intra[0][1], 2, 1,
359 &ff_table_inter_intra[0][0], 2, 1, 0);
360 26 ff_msmp4_vc1_vlcs_init_once();
361 26 }
362
363 675 static int msmpeg4_decode_picture_header(H263DecContext *const h)
364 {
365 675 MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
366 int code;
367
368 // at minimum one bit per macroblock is required at least in a valid frame,
369 // we discard frames much smaller than this. Frames smaller than 1/8 of the
370 // smallest "black/skip" frame generally contain not much recoverable content
371 // while at the same time they have the highest computational requirements
372 // per byte
373
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 675 times.
675 if (get_bits_left(&h->gb) * 8LL < (h->c.width+15)/16 * ((h->c.height+15)/16))
374 return AVERROR_INVALIDDATA;
375
376
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 625 times.
675 if (h->c.msmpeg4_version == MSMP4_V1) {
377 50 int start_code = get_bits_long(&h->gb, 32);
378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if(start_code!=0x00000100){
379 av_log(h->c.avctx, AV_LOG_ERROR, "invalid startcode\n");
380 return -1;
381 }
382
383 50 skip_bits(&h->gb, 5); // frame number */
384 }
385
386 675 h->c.pict_type = get_bits(&h->gb, 2) + 1;
387
2/2
✓ Branch 0 taken 611 times.
✓ Branch 1 taken 64 times.
675 if (h->c.pict_type != AV_PICTURE_TYPE_I &&
388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 611 times.
611 h->c.pict_type != AV_PICTURE_TYPE_P){
389 av_log(h->c.avctx, AV_LOG_ERROR, "invalid picture type\n");
390 return -1;
391 }
392 675 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 675 times.
675 if (h->c.qscale == 0) {
394 av_log(h->c.avctx, AV_LOG_ERROR, "invalid qscale\n");
395 return -1;
396 }
397
398
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 611 times.
675 if (h->c.pict_type == AV_PICTURE_TYPE_I) {
399 64 code = get_bits(&h->gb, 5);
400
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63 times.
64 if (h->c.msmpeg4_version == MSMP4_V1) {
401
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if(code==0 || code>h->c.mb_height) {
402 av_log(h->c.avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
403 return -1;
404 }
405
406 1 h->slice_height = code;
407 }else{
408 /* 0x17: one slice, 0x18: two slices, ... */
409
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 63 times.
63 if (code < 0x17){
410 av_log(h->c.avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
411 return -1;
412 }
413
414 63 h->slice_height = h->c.mb_height / (code - 0x16);
415 }
416
417
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
64 switch (h->c.msmpeg4_version) {
418 21 case MSMP4_V1:
419 case MSMP4_V2:
420 21 ms->rl_chroma_table_index = 2;
421 21 ms->rl_table_index = 2;
422
423 21 ms->dc_table_index = 0; //not used
424 21 break;
425 23 case MSMP4_V3:
426 23 ms->rl_chroma_table_index = decode012(&h->gb);
427 23 ms->rl_table_index = decode012(&h->gb);
428
429 23 ms->dc_table_index = get_bits1(&h->gb);
430 23 break;
431 20 case MSMP4_WMV1:
432 20 ff_msmpeg4_decode_ext_header(h, (2+5+5+17+7)/8);
433
434
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (ms->bit_rate > MBAC_BITRATE)
435 20 ms->per_mb_rl_table = get_bits1(&h->gb);
436 else
437 ms->per_mb_rl_table = 0;
438
439
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (!ms->per_mb_rl_table) {
440 20 ms->rl_chroma_table_index = decode012(&h->gb);
441 20 ms->rl_table_index = decode012(&h->gb);
442 }
443
444 20 ms->dc_table_index = get_bits1(&h->gb);
445 20 h->c.inter_intra_pred= 0;
446 20 break;
447 default:
448 av_unreachable("msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
449 }
450 64 h->c.no_rounding = 1;
451
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 64 times.
64 if (h->c.avctx->debug & FF_DEBUG_PICT_INFO)
452 av_log(h->c.avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
453 h->c.qscale,
454 ms->rl_chroma_table_index,
455 ms->rl_table_index,
456 ms->dc_table_index,
457 ms->per_mb_rl_table,
458 h->slice_height);
459 } else {
460
3/4
✓ Branch 0 taken 229 times.
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 180 times.
✗ Branch 3 not taken.
611 switch (h->c.msmpeg4_version) {
461 229 case MSMP4_V1:
462 case MSMP4_V2:
463
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 180 times.
229 if (h->c.msmpeg4_version == MSMP4_V1)
464 49 ms->use_skip_mb_code = 1;
465 else
466 180 ms->use_skip_mb_code = get_bits1(&h->gb);
467 229 ms->rl_table_index = 2;
468 229 ms->rl_chroma_table_index = ms->rl_table_index;
469 229 ms->dc_table_index = 0; //not used
470 229 ms->mv_table_index = 0;
471 229 break;
472 202 case MSMP4_V3:
473 202 ms->use_skip_mb_code = get_bits1(&h->gb);
474 202 ms->rl_table_index = decode012(&h->gb);
475 202 ms->rl_chroma_table_index = ms->rl_table_index;
476
477 202 ms->dc_table_index = get_bits1(&h->gb);
478
479 202 ms->mv_table_index = get_bits1(&h->gb);
480 202 break;
481 180 case MSMP4_WMV1:
482 180 ms->use_skip_mb_code = get_bits1(&h->gb);
483
484
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if (ms->bit_rate > MBAC_BITRATE)
485 180 ms->per_mb_rl_table = get_bits1(&h->gb);
486 else
487 ms->per_mb_rl_table = 0;
488
489
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if (!ms->per_mb_rl_table) {
490 180 ms->rl_table_index = decode012(&h->gb);
491 180 ms->rl_chroma_table_index = ms->rl_table_index;
492 }
493
494 180 ms->dc_table_index = get_bits1(&h->gb);
495
496 180 ms->mv_table_index = get_bits1(&h->gb);
497
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 135 times.
225 h->c.inter_intra_pred = h->c.width*h->c.height < 320*240 &&
498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 ms->bit_rate <= II_BITRATE;
499 180 break;
500 default:
501 av_unreachable("msmpeg4_decode_picture_header() only used by MSMP4V1-3, WMV1");
502 }
503
504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 611 times.
611 if (h->c.avctx->debug&FF_DEBUG_PICT_INFO)
505 av_log(h->c.avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
506 ms->use_skip_mb_code,
507 ms->rl_table_index,
508 ms->rl_chroma_table_index,
509 ms->dc_table_index,
510 ms->mv_table_index,
511 ms->per_mb_rl_table,
512 h->c.qscale);
513
514
2/2
✓ Branch 0 taken 382 times.
✓ Branch 1 taken 229 times.
611 if (ms->flipflop_rounding) {
515 382 h->c.no_rounding ^= 1;
516 }else{
517 229 h->c.no_rounding = 0;
518 }
519 }
520 ff_dlog(h->c.avctx, "%d %d %d %d %d\n", h->c.pict_type, ms->bit_rate,
521 h->c.inter_intra_pred, h->c.width, h->c.height);
522
523 675 ms->esc3_level_length = 0;
524 675 ms->esc3_run_length = 0;
525
526 675 return 0;
527 }
528
529 64 int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)
530 {
531 64 MSMP4DecContext *const ms = mpv_to_msmpeg4(h);
532 64 int left = buf_size*8 - get_bits_count(&h->gb);
533
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 21 times.
64 int length = h->c.msmpeg4_version >= MSMP4_V3 ? 17 : 16;
534 /* the alt_bitstream reader could read over the end so we need to check it */
535
3/4
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
64 if(left>=length && left<length+8)
536 {
537 63 skip_bits(&h->gb, 5); /* fps */
538 63 ms->bit_rate = get_bits(&h->gb, 11) * 1024;
539
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 20 times.
63 if (h->c.msmpeg4_version >= MSMP4_V3)
540 43 ms->flipflop_rounding = get_bits1(&h->gb);
541 else
542 20 ms->flipflop_rounding = 0;
543 }
544
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if(left<length+8)
545 {
546 1 ms->flipflop_rounding = 0;
547
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (h->c.msmpeg4_version != MSMP4_V2)
548 1 av_log(h->c.avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
549 }
550 else
551 {
552 av_log(h->c.avctx, AV_LOG_ERROR, "I-frame too long, ignoring ext header\n");
553 }
554
555 64 return 0;
556 }
557
558 230712 static int msmpeg4_decode_dc(MSMP4DecContext *const ms, int n, int *dir_ptr)
559 {
560 230712 H263DecContext *const h = &ms->h;
561 int level, pred;
562
563
2/2
✓ Branch 0 taken 54342 times.
✓ Branch 1 taken 176370 times.
230712 if (h->c.msmpeg4_version <= MSMP4_V2) {
564
2/2
✓ Branch 0 taken 36228 times.
✓ Branch 1 taken 18114 times.
54342 if (n < 4) {
565 36228 level = get_vlc2(&h->gb, v2_dc_lum_vlc, MSMP4_DC_VLC_BITS, 3);
566 } else {
567 18114 level = get_vlc2(&h->gb, v2_dc_chroma_vlc, MSMP4_DC_VLC_BITS, 3);
568 }
569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54342 times.
54342 if (level < 0) {
570 av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc vlc\n");
571 *dir_ptr = 0;
572 return -1;
573 }
574 54342 level-=256;
575 } else {
576 176370 level = get_vlc2(&h->gb, ff_msmp4_dc_vlc[ms->dc_table_index][n >= 4],
577 MSMP4_DC_VLC_BITS, 3);
578
579
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 176322 times.
176370 if (level == DC_MAX) {
580 48 level = get_bits(&h->gb, 8);
581
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 42 times.
48 if (get_bits1(&h->gb))
582 6 level = -level;
583
2/2
✓ Branch 0 taken 153813 times.
✓ Branch 1 taken 22509 times.
176322 } else if (level != 0) {
584
2/2
✓ Branch 1 taken 74512 times.
✓ Branch 2 taken 79301 times.
153813 if (get_bits1(&h->gb))
585 74512 level = -level;
586 }
587 }
588
589
2/2
✓ Branch 0 taken 5490 times.
✓ Branch 1 taken 225222 times.
230712 if (h->c.msmpeg4_version == MSMP4_V1) {
590 int32_t *dc_val;
591 5490 pred = msmpeg4v1_pred_dc(&h->c, n, &dc_val);
592 5490 level += pred;
593
594 /* update predictor */
595 5490 *dc_val= level;
596 }else{
597 int16_t *dc_val;
598 225222 pred = ff_msmpeg4_pred_dc(&h->c, n, &dc_val, dir_ptr);
599 225222 level += pred;
600
601 /* update predictor */
602
2/2
✓ Branch 0 taken 150148 times.
✓ Branch 1 taken 75074 times.
225222 if (n < 4) {
603 150148 *dc_val = level * h->c.y_dc_scale;
604 } else {
605 75074 *dc_val = level * h->c.c_dc_scale;
606 }
607 }
608
609 230712 return level;
610 }
611
612 1472610 int ff_msmpeg4_decode_block(MSMP4DecContext *const ms, int16_t * block,
613 int n, int coded, const uint8_t *scan_table)
614 {
615 1472610 H263DecContext *const h = &ms->h;
616 int level, i, last, run, run_diff;
617 1472610 int dc_pred_dir = -1; //unused but its passed around, so it needs to be initialized
618 const RLTable *rl;
619 const RL_VLC_ELEM *rl_vlc;
620 int qmul, qadd;
621
622
2/2
✓ Branch 0 taken 230712 times.
✓ Branch 1 taken 1241898 times.
1472610 if (h->c.mb_intra) {
623 230712 qmul=1;
624 230712 qadd=0;
625
626 /* DC coef */
627 230712 level = msmpeg4_decode_dc(ms, n, &dc_pred_dir);
628
629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 230712 times.
230712 if (level < 0){
630 av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, h->c.qscale);
631 if (h->c.inter_intra_pred)
632 level = 0;
633 }
634
2/2
✓ Branch 0 taken 153808 times.
✓ Branch 1 taken 76904 times.
230712 if (n < 4) {
635 153808 rl = &ff_rl_table[ms->rl_table_index];
636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 153808 times.
153808 if (level > 256 * h->c.y_dc_scale) {
637 av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", h->c.qscale);
638 if (!h->c.inter_intra_pred)
639 return -1;
640 }
641 } else {
642 76904 rl = &ff_rl_table[3 + ms->rl_chroma_table_index];
643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76904 times.
76904 if (level > 256 * h->c.c_dc_scale) {
644 av_log(h->c.avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", h->c.qscale);
645 if (!h->c.inter_intra_pred)
646 return -1;
647 }
648 }
649 230712 block[0] = level;
650
651 230712 run_diff = h->c.msmpeg4_version >= MSMP4_WMV1;
652 230712 i = 0;
653
2/2
✓ Branch 0 taken 42456 times.
✓ Branch 1 taken 188256 times.
230712 if (!coded) {
654 42456 goto not_coded;
655 }
656
2/2
✓ Branch 0 taken 3224 times.
✓ Branch 1 taken 185032 times.
188256 if (h->c.ac_pred) {
657
2/2
✓ Branch 0 taken 1928 times.
✓ Branch 1 taken 1296 times.
3224 if (dc_pred_dir == 0)
658 1928 scan_table = h->c.permutated_intra_v_scantable; /* left */
659 else
660 1296 scan_table = h->c.permutated_intra_h_scantable; /* top */
661 } else {
662 185032 scan_table = h->c.intra_scantable.permutated;
663 }
664 188256 rl_vlc= rl->rl_vlc[0];
665 } else {
666 1241898 qmul = h->c.qscale << 1;
667 1241898 qadd = (h->c.qscale - 1) | 1;
668 1241898 i = -1;
669 1241898 rl = &ff_rl_table[3 + ms->rl_table_index];
670
671
2/2
✓ Branch 0 taken 306018 times.
✓ Branch 1 taken 935880 times.
1241898 if (h->c.msmpeg4_version == MSMP4_V2)
672 306018 run_diff = 0;
673 else
674 935880 run_diff = 1;
675
676
2/2
✓ Branch 0 taken 633723 times.
✓ Branch 1 taken 608175 times.
1241898 if (!coded) {
677 633723 h->c.block_last_index[n] = i;
678 633723 return 0;
679 }
680
2/2
✓ Branch 0 taken 420993 times.
✓ Branch 1 taken 187182 times.
608175 if(!scan_table)
681 420993 scan_table = h->c.inter_scantable.permutated;
682 608175 rl_vlc= rl->rl_vlc[h->c.qscale];
683 }
684 {
685 796431 OPEN_READER(re, &h->gb);
686 for(;;) {
687 9175903 UPDATE_CACHE(re, &h->gb);
688
2/2
✓ Branch 1 taken 297834 times.
✓ Branch 2 taken 4688333 times.
4986167 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
689
2/2
✓ Branch 0 taken 162066 times.
✓ Branch 1 taken 4824101 times.
4986167 if (level==0) {
690 int cache;
691 162066 cache= GET_CACHE(re, &h->gb);
692 /* escape */
693
4/4
✓ Branch 0 taken 140175 times.
✓ Branch 1 taken 21891 times.
✓ Branch 2 taken 74501 times.
✓ Branch 3 taken 65674 times.
162066 if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x80000000)==0) {
694
4/4
✓ Branch 0 taken 74501 times.
✓ Branch 1 taken 21891 times.
✓ Branch 2 taken 19659 times.
✓ Branch 3 taken 54842 times.
96392 if (h->c.msmpeg4_version == MSMP4_V1 || (cache&0x40000000)==0) {
695 /* third escape */
696
2/2
✓ Branch 0 taken 19659 times.
✓ Branch 1 taken 21891 times.
41550 if (h->c.msmpeg4_version != MSMP4_V1)
697 19659 LAST_SKIP_BITS(re, &h->gb, 2);
698 41550 UPDATE_CACHE(re, &h->gb);
699
2/2
✓ Branch 0 taken 34734 times.
✓ Branch 1 taken 6816 times.
41550 if (h->c.msmpeg4_version <= MSMP4_V3) {
700 34734 last = SHOW_UBITS(re, &h->gb, 1); SKIP_CACHE(re, &h->gb, 1);
701 34734 run = SHOW_UBITS(re, &h->gb, 6); SKIP_CACHE(re, &h->gb, 6);
702 34734 level = SHOW_SBITS(re, &h->gb, 8);
703 34734 SKIP_COUNTER(re, &h->gb, 1 + 6 + 8);
704 }else{
705 int sign;
706 6816 last = SHOW_UBITS(re, &h->gb, 1); SKIP_BITS(re, &h->gb, 1);
707
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 6432 times.
6816 if (!ms->esc3_level_length) {
708 int ll;
709 ff_dlog(h->c.avctx, "ESC-3 %X at %d %d\n",
710 show_bits(&h->gb, 24), h->c.mb_x, h->c.mb_y);
711
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 306 times.
384 if (h->c.qscale < 8) {
712 78 ll = SHOW_UBITS(re, &h->gb, 3); SKIP_BITS(re, &h->gb, 3);
713
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 78 times.
78 if(ll==0){
714 ll = 8+SHOW_UBITS(re, &h->gb, 1); SKIP_BITS(re, &h->gb, 1);
715 }
716 }else{
717 306 ll=2;
718
4/4
✓ Branch 0 taken 1734 times.
✓ Branch 1 taken 280 times.
✓ Branch 3 taken 1708 times.
✓ Branch 4 taken 26 times.
2014 while (ll < 8 && SHOW_UBITS(re, &h->gb, 1) == 0) {
719 1708 ll++;
720 1708 SKIP_BITS(re, &h->gb, 1);
721 }
722
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 280 times.
306 if (ll<8) SKIP_BITS(re, &h->gb, 1);
723 }
724
725 384 ms->esc3_level_length = ll;
726 384 ms->esc3_run_length = SHOW_UBITS(re, &h->gb, 2) + 3; SKIP_BITS(re, &h->gb, 2);
727 384 UPDATE_CACHE(re, &h->gb);
728 }
729 6816 run = SHOW_UBITS(re, &h->gb, ms->esc3_run_length);
730 6816 SKIP_BITS(re, &h->gb, ms->esc3_run_length);
731
732 6816 sign= SHOW_UBITS(re, &h->gb, 1);
733 6816 SKIP_BITS(re, &h->gb, 1);
734
735 6816 level = SHOW_UBITS(re, &h->gb, ms->esc3_level_length);
736 6816 SKIP_BITS(re, &h->gb, ms->esc3_level_length);
737
2/2
✓ Branch 0 taken 3395 times.
✓ Branch 1 taken 3421 times.
6816 if(sign) level= -level;
738 }
739
740 //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
741
2/2
✓ Branch 0 taken 20943 times.
✓ Branch 1 taken 20607 times.
41550 if (level>0) level= level * qmul + qadd;
742 20607 else level= level * qmul - qadd;
743 41550 i+= run + 1;
744
2/2
✓ Branch 0 taken 18888 times.
✓ Branch 1 taken 22662 times.
41550 if(last) i+=192;
745 } else {
746 /* second escape */
747 54842 SKIP_BITS(re, &h->gb, 2);
748
2/2
✓ Branch 1 taken 7490 times.
✓ Branch 2 taken 47352 times.
54842 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
749 54842 i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
750 54842 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
751 54842 LAST_SKIP_BITS(re, &h->gb, 1);
752 }
753 } else {
754 /* first escape */
755 65674 SKIP_BITS(re, &h->gb, 1);
756
2/2
✓ Branch 1 taken 8895 times.
✓ Branch 2 taken 56779 times.
65674 GET_RL_VLC(level, run, re, &h->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
757 65674 i+= run;
758 65674 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
759 65674 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
760 65674 LAST_SKIP_BITS(re, &h->gb, 1);
761 }
762 } else {
763 4824101 i+= run;
764 4824101 level = (level ^ SHOW_SBITS(re, &h->gb, 1)) - SHOW_SBITS(re, &h->gb, 1);
765 4824101 LAST_SKIP_BITS(re, &h->gb, 1);
766 }
767
2/2
✓ Branch 0 taken 796431 times.
✓ Branch 1 taken 4189736 times.
4986167 if (i > 62){
768 796431 i-= 192;
769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 796431 times.
796431 if(i&(~63)){
770 const int left = get_bits_left(&h->gb);
771 if (((i + 192 == 64 && level / qmul == -1) ||
772 !(h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) &&
773 left >= 0) {
774 av_log(h->c.avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n",
775 h->c.mb_x, h->c.mb_y);
776 i = 63;
777 break;
778 }else{
779 av_log(h->c.avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n",
780 h->c.mb_x, h->c.mb_y);
781 return -1;
782 }
783 }
784
785 796431 block[scan_table[i]] = level;
786 796431 break;
787 }
788
789 4189736 block[scan_table[i]] = level;
790 }
791 796431 CLOSE_READER(re, &h->gb);
792 }
793
2/2
✓ Branch 0 taken 188256 times.
✓ Branch 1 taken 608175 times.
796431 if (h->c.mb_intra) {
794 188256 not_coded:
795 230712 ff_mpeg4_pred_ac(h, block, n, dc_pred_dir);
796 }
797 838887 h->c.block_last_index[n] = i;
798
799 838887 return 0;
800 }
801
802 228076 void ff_msmpeg4_decode_motion(MSMP4DecContext *const ms, int *mx_ptr, int *my_ptr)
803 {
804 228076 const VLCElem *const mv_vlc = mv_tables[ms->mv_table_index];
805 228076 H263DecContext *const h = &ms->h;
806 int sym, mx, my;
807
808 228076 sym = get_vlc2(&h->gb, mv_vlc, MV_VLC_BITS, 2);
809
2/2
✓ Branch 0 taken 226220 times.
✓ Branch 1 taken 1856 times.
228076 if (sym) {
810 226220 mx = sym >> 8;
811 226220 my = sym & 0xFF;
812 } else {
813 /* Escape */
814 1856 mx = get_bits(&h->gb, 6);
815 1856 my = get_bits(&h->gb, 6);
816 }
817
818 228076 mx += *mx_ptr - 32;
819 228076 my += *my_ptr - 32;
820 /* WARNING : they do not do exactly modulo encoding */
821
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 228054 times.
228076 if (mx <= -64)
822 22 mx += 64;
823
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 228044 times.
228054 else if (mx >= 64)
824 10 mx -= 64;
825
826
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 228070 times.
228076 if (my <= -64)
827 6 my += 64;
828
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 228066 times.
228070 else if (my >= 64)
829 4 my -= 64;
830 228076 *mx_ptr = mx;
831 228076 *my_ptr = my;
832 228076 }
833
834 45 av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
835 {
836 static AVOnce init_static_once = AV_ONCE_INIT;
837 45 H263DecContext *const h = avctx->priv_data;
838 int ret;
839
840 45 ret = av_image_check_size(avctx->width, avctx->height, 0, avctx);
841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
45 if (ret < 0)
842 return ret;
843
844
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
45 if (ff_h263_decode_init(avctx) < 0)
845 return -1;
846
847 // We unquantize inter blocks as we parse them.
848 45 h->c.dct_unquantize_inter = NULL;
849
850 45 h->decode_header = msmpeg4_decode_picture_header;
851
852 45 ff_msmpeg4_common_init(&h->c);
853
854
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
45 switch (h->c.msmpeg4_version) {
855 11 case MSMP4_V1:
856 case MSMP4_V2:
857 11 h->decode_mb = msmpeg4v12_decode_mb;
858 11 break;
859 22 case MSMP4_V3:
860 case MSMP4_WMV1:
861 22 h->decode_mb = msmpeg4v34_decode_mb;
862 22 break;
863 12 case MSMP4_WMV2:
864 12 break;
865 default:
866 av_unreachable("List contains all cases using ff_msmpeg4_decode_init()");
867 }
868
869 45 h->slice_height = h->c.mb_height; //to avoid 1/0 if the first frame is not a keyframe
870
871 45 ff_thread_once(&init_static_once, msmpeg4_decode_init_static);
872
873 45 return 0;
874 }
875
876 const FFCodec ff_msmpeg4v1_decoder = {
877 .p.name = "msmpeg4v1",
878 CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 1"),
879 .p.type = AVMEDIA_TYPE_VIDEO,
880 .p.id = AV_CODEC_ID_MSMPEG4V1,
881 .priv_data_size = sizeof(MSMP4DecContext),
882 .init = ff_msmpeg4_decode_init,
883 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
884 .close = ff_mpv_decode_close,
885 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
886 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
887 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
888 .p.max_lowres = 3,
889 };
890
891 const FFCodec ff_msmpeg4v2_decoder = {
892 .p.name = "msmpeg4v2",
893 CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 2"),
894 .p.type = AVMEDIA_TYPE_VIDEO,
895 .p.id = AV_CODEC_ID_MSMPEG4V2,
896 .priv_data_size = sizeof(MSMP4DecContext),
897 .init = ff_msmpeg4_decode_init,
898 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
899 .close = ff_mpv_decode_close,
900 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
901 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
902 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
903 .p.max_lowres = 3,
904 };
905
906 const FFCodec ff_msmpeg4v3_decoder = {
907 .p.name = "msmpeg4",
908 CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 3"),
909 .p.type = AVMEDIA_TYPE_VIDEO,
910 .p.id = AV_CODEC_ID_MSMPEG4V3,
911 .priv_data_size = sizeof(MSMP4DecContext),
912 .init = ff_msmpeg4_decode_init,
913 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
914 .close = ff_mpv_decode_close,
915 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
916 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
917 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
918 .p.max_lowres = 3,
919 };
920
921 const FFCodec ff_wmv1_decoder = {
922 .p.name = "wmv1",
923 CODEC_LONG_NAME("Windows Media Video 7"),
924 .p.type = AVMEDIA_TYPE_VIDEO,
925 .p.id = AV_CODEC_ID_WMV1,
926 .priv_data_size = sizeof(MSMP4DecContext),
927 .init = ff_msmpeg4_decode_init,
928 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
929 .close = ff_mpv_decode_close,
930 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1,
931 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
932 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
933 .p.max_lowres = 3,
934 };
935