FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/msmpeg4dec.c
Date: 2021-09-24 03:35:22
Exec Total Coverage
Lines: 406 466 87.1%
Branches: 218 283 77.0%

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