FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/msmpeg4dec.c
Date: 2022-07-05 19:52:29
Exec Total Coverage
Lines: 407 467 87.2%
Branches: 214 277 77.3%

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