cosmetics: Align codec declarations
[libav.git] / libavcodec / msmpeg4.c
1 /*
2 * MSMPEG4 backend for encoder and decoder
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of Libav.
9 *
10 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * MSMPEG4 backend for encoder and decoder
28 */
29
30 #include "avcodec.h"
31 #include "dsputil.h"
32 #include "mpegvideo.h"
33 #include "msmpeg4.h"
34 #include "libavutil/x86_cpu.h"
35 #include "h263.h"
36 #include "mpeg4video.h"
37 #include "msmpeg4data.h"
38 #include "vc1data.h"
39
40 /*
41 * You can also call this codec : MPEG4 with a twist !
42 *
43 * TODO:
44 * - (encoding) select best mv table (two choices)
45 * - (encoding) select best vlc/dc table
46 */
47 //#define DEBUG
48
49 #define DC_VLC_BITS 9
50 #define V2_INTRA_CBPC_VLC_BITS 3
51 #define V2_MB_TYPE_VLC_BITS 7
52 #define MV_VLC_BITS 9
53 #define V2_MV_VLC_BITS 9
54 #define TEX_VLC_BITS 9
55
56 #define DEFAULT_INTER_INDEX 3
57
58 /* This table is practically identical to the one from h263
59 * except that it is inverted. */
60 static av_cold void init_h263_dc_for_msmpeg4(void)
61 {
62 int level, uni_code, uni_len;
63
64 for(level=-256; level<256; level++){
65 int size, v, l;
66 /* find number of bits */
67 size = 0;
68 v = abs(level);
69 while (v) {
70 v >>= 1;
71 size++;
72 }
73
74 if (level < 0)
75 l= (-level) ^ ((1 << size) - 1);
76 else
77 l= level;
78
79 /* luminance h263 */
80 uni_code= ff_mpeg4_DCtab_lum[size][0];
81 uni_len = ff_mpeg4_DCtab_lum[size][1];
82 uni_code ^= (1<<uni_len)-1; //M$ does not like compatibility
83
84 if (size > 0) {
85 uni_code<<=size; uni_code|=l;
86 uni_len+=size;
87 if (size > 8){
88 uni_code<<=1; uni_code|=1;
89 uni_len++;
90 }
91 }
92 ff_v2_dc_lum_table[level + 256][0] = uni_code;
93 ff_v2_dc_lum_table[level + 256][1] = uni_len;
94
95 /* chrominance h263 */
96 uni_code= ff_mpeg4_DCtab_chrom[size][0];
97 uni_len = ff_mpeg4_DCtab_chrom[size][1];
98 uni_code ^= (1<<uni_len)-1; //M$ does not like compatibility
99
100 if (size > 0) {
101 uni_code<<=size; uni_code|=l;
102 uni_len+=size;
103 if (size > 8){
104 uni_code<<=1; uni_code|=1;
105 uni_len++;
106 }
107 }
108 ff_v2_dc_chroma_table[level + 256][0] = uni_code;
109 ff_v2_dc_chroma_table[level + 256][1] = uni_len;
110
111 }
112 }
113
114 av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
115 {
116 static int initialized=0;
117
118 switch(s->msmpeg4_version){
119 case 1:
120 case 2:
121 s->y_dc_scale_table=
122 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
123 break;
124 case 3:
125 if(s->workaround_bugs){
126 s->y_dc_scale_table= ff_old_ff_y_dc_scale_table;
127 s->c_dc_scale_table= ff_wmv1_c_dc_scale_table;
128 } else{
129 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
130 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
131 }
132 break;
133 case 4:
134 case 5:
135 s->y_dc_scale_table= ff_wmv1_y_dc_scale_table;
136 s->c_dc_scale_table= ff_wmv1_c_dc_scale_table;
137 break;
138 #if CONFIG_VC1_DECODER
139 case 6:
140 s->y_dc_scale_table= ff_wmv3_dc_scale_table;
141 s->c_dc_scale_table= ff_wmv3_dc_scale_table;
142 break;
143 #endif
144
145 }
146
147
148 if(s->msmpeg4_version>=4){
149 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_wmv1_scantable[1]);
150 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_wmv1_scantable[2]);
151 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_wmv1_scantable[3]);
152 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_wmv1_scantable[0]);
153 }
154 //Note the default tables are set in common_init in mpegvideo.c
155
156 if(!initialized){
157 initialized=1;
158
159 init_h263_dc_for_msmpeg4();
160 }
161 }
162
163 /* predict coded block */
164 int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
165 {
166 int xy, wrap, pred, a, b, c;
167
168 xy = s->block_index[n];
169 wrap = s->b8_stride;
170
171 /* B C
172 * A X
173 */
174 a = s->coded_block[xy - 1 ];
175 b = s->coded_block[xy - 1 - wrap];
176 c = s->coded_block[xy - wrap];
177
178 if (b == c) {
179 pred = a;
180 } else {
181 pred = c;
182 }
183
184 /* store value */
185 *coded_block_ptr = &s->coded_block[xy];
186
187 return pred;
188 }
189
190 static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
191 int32_t **dc_val_ptr)
192 {
193 int i;
194
195 if (n < 4) {
196 i= 0;
197 } else {
198 i= n-3;
199 }
200
201 *dc_val_ptr= &s->last_dc[i];
202 return s->last_dc[i];
203 }
204
205 static int get_dc(uint8_t *src, int stride, int scale)
206 {
207 int y;
208 int sum=0;
209 for(y=0; y<8; y++){
210 int x;
211 for(x=0; x<8; x++){
212 sum+=src[x + y*stride];
213 }
214 }
215 return FASTDIV((sum + (scale>>1)), scale);
216 }
217
218 /* dir = 0: left, dir = 1: top prediction */
219 int ff_msmpeg4_pred_dc(MpegEncContext *s, int n,
220 int16_t **dc_val_ptr, int *dir_ptr)
221 {
222 int a, b, c, wrap, pred, scale;
223 int16_t *dc_val;
224
225 /* find prediction */
226 if (n < 4) {
227 scale = s->y_dc_scale;
228 } else {
229 scale = s->c_dc_scale;
230 }
231
232 wrap = s->block_wrap[n];
233 dc_val= s->dc_val[0] + s->block_index[n];
234
235 /* B C
236 * A X
237 */
238 a = dc_val[ - 1];
239 b = dc_val[ - 1 - wrap];
240 c = dc_val[ - wrap];
241
242 if(s->first_slice_line && (n&2)==0 && s->msmpeg4_version<4){
243 b=c=1024;
244 }
245
246 /* XXX: the following solution consumes divisions, but it does not
247 necessitate to modify mpegvideo.c. The problem comes from the
248 fact they decided to store the quantized DC (which would lead
249 to problems if Q could vary !) */
250 #if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE
251 __asm__ volatile(
252 "movl %3, %%eax \n\t"
253 "shrl $1, %%eax \n\t"
254 "addl %%eax, %2 \n\t"
255 "addl %%eax, %1 \n\t"
256 "addl %0, %%eax \n\t"
257 "mull %4 \n\t"
258 "movl %%edx, %0 \n\t"
259 "movl %1, %%eax \n\t"
260 "mull %4 \n\t"
261 "movl %%edx, %1 \n\t"
262 "movl %2, %%eax \n\t"
263 "mull %4 \n\t"
264 "movl %%edx, %2 \n\t"
265 : "+b" (a), "+c" (b), "+D" (c)
266 : "g" (scale), "S" (ff_inverse[scale])
267 : "%eax", "%edx"
268 );
269 #else
270 /* #elif ARCH_ALPHA */
271 /* Divisions are extremely costly on Alpha; optimize the most
272 common case. But they are costly everywhere...
273 */
274 if (scale == 8) {
275 a = (a + (8 >> 1)) / 8;
276 b = (b + (8 >> 1)) / 8;
277 c = (c + (8 >> 1)) / 8;
278 } else {
279 a = FASTDIV((a + (scale >> 1)), scale);
280 b = FASTDIV((b + (scale >> 1)), scale);
281 c = FASTDIV((c + (scale >> 1)), scale);
282 }
283 #endif
284 /* XXX: WARNING: they did not choose the same test as MPEG4. This
285 is very important ! */
286 if(s->msmpeg4_version>3){
287 if(s->inter_intra_pred){
288 uint8_t *dest;
289 int wrap;
290
291 if(n==1){
292 pred=a;
293 *dir_ptr = 0;
294 }else if(n==2){
295 pred=c;
296 *dir_ptr = 1;
297 }else if(n==3){
298 if (abs(a - b) < abs(b - c)) {
299 pred = c;
300 *dir_ptr = 1;
301 } else {
302 pred = a;
303 *dir_ptr = 0;
304 }
305 }else{
306 if(n<4){
307 wrap= s->linesize;
308 dest= s->current_picture.f.data[0] + (((n >> 1) + 2*s->mb_y) * 8* wrap ) + ((n & 1) + 2*s->mb_x) * 8;
309 }else{
310 wrap= s->uvlinesize;
311 dest= s->current_picture.f.data[n - 3] + (s->mb_y * 8 * wrap) + s->mb_x * 8;
312 }
313 if(s->mb_x==0) a= (1024 + (scale>>1))/scale;
314 else a= get_dc(dest-8, wrap, scale*8);
315 if(s->mb_y==0) c= (1024 + (scale>>1))/scale;
316 else c= get_dc(dest-8*wrap, wrap, scale*8);
317
318 if (s->h263_aic_dir==0) {
319 pred= a;
320 *dir_ptr = 0;
321 }else if (s->h263_aic_dir==1) {
322 if(n==0){
323 pred= c;
324 *dir_ptr = 1;
325 }else{
326 pred= a;
327 *dir_ptr = 0;
328 }
329 }else if (s->h263_aic_dir==2) {
330 if(n==0){
331 pred= a;
332 *dir_ptr = 0;
333 }else{
334 pred= c;
335 *dir_ptr = 1;
336 }
337 } else {
338 pred= c;
339 *dir_ptr = 1;
340 }
341 }
342 }else{
343 if (abs(a - b) < abs(b - c)) {
344 pred = c;
345 *dir_ptr = 1;
346 } else {
347 pred = a;
348 *dir_ptr = 0;
349 }
350 }
351 }else{
352 if (abs(a - b) <= abs(b - c)) {
353 pred = c;
354 *dir_ptr = 1;
355 } else {
356 pred = a;
357 *dir_ptr = 0;
358 }
359 }
360
361 /* update predictor */
362 *dc_val_ptr = &dc_val[0];
363 return pred;
364 }
365
366 /****************************************/
367 /* decoding stuff */
368
369 VLC ff_mb_non_intra_vlc[4];
370 static VLC v2_dc_lum_vlc;
371 static VLC v2_dc_chroma_vlc;
372 static VLC v2_intra_cbpc_vlc;
373 static VLC v2_mb_type_vlc;
374 static VLC v2_mv_vlc;
375 VLC ff_inter_intra_vlc;
376
377 /* This is identical to h263 except that its range is multiplied by 2. */
378 static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
379 {
380 int code, val, sign, shift;
381
382 code = get_vlc2(&s->gb, v2_mv_vlc.table, V2_MV_VLC_BITS, 2);
383 // printf("MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
384 if (code < 0)
385 return 0xffff;
386
387 if (code == 0)
388 return pred;
389 sign = get_bits1(&s->gb);
390 shift = f_code - 1;
391 val = code;
392 if (shift) {
393 val = (val - 1) << shift;
394 val |= get_bits(&s->gb, shift);
395 val++;
396 }
397 if (sign)
398 val = -val;
399
400 val += pred;
401 if (val <= -64)
402 val += 64;
403 else if (val >= 64)
404 val -= 64;
405
406 return val;
407 }
408
409 static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
410 {
411 int cbp, code, i;
412
413 if (s->pict_type == AV_PICTURE_TYPE_P) {
414 if (s->use_skip_mb_code) {
415 if (get_bits1(&s->gb)) {
416 /* skip mb */
417 s->mb_intra = 0;
418 for(i=0;i<6;i++)
419 s->block_last_index[i] = -1;
420 s->mv_dir = MV_DIR_FORWARD;
421 s->mv_type = MV_TYPE_16X16;
422 s->mv[0][0][0] = 0;
423 s->mv[0][0][1] = 0;
424 s->mb_skipped = 1;
425 return 0;
426 }
427 }
428
429 if(s->msmpeg4_version==2)
430 code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1);
431 else
432 code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
433 if(code<0 || code>7){
434 av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
435 return -1;
436 }
437
438 s->mb_intra = code >>2;
439
440 cbp = code & 0x3;
441 } else {
442 s->mb_intra = 1;
443 if(s->msmpeg4_version==2)
444 cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1);
445 else
446 cbp= get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
447 if(cbp<0 || cbp>3){
448 av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
449 return -1;
450 }
451 }
452
453 if (!s->mb_intra) {
454 int mx, my, cbpy;
455
456 cbpy= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
457 if(cbpy<0){
458 av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
459 return -1;
460 }
461
462 cbp|= cbpy<<2;
463 if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C;
464
465 ff_h263_pred_motion(s, 0, 0, &mx, &my);
466 mx= msmpeg4v2_decode_motion(s, mx, 1);
467 my= msmpeg4v2_decode_motion(s, my, 1);
468
469 s->mv_dir = MV_DIR_FORWARD;
470 s->mv_type = MV_TYPE_16X16;
471 s->mv[0][0][0] = mx;
472 s->mv[0][0][1] = my;
473 } else {
474 if(s->msmpeg4_version==2){
475 s->ac_pred = get_bits1(&s->gb);
476 cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors
477 } else{
478 s->ac_pred = 0;
479 cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors
480 if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C;
481 }
482 }
483
484 s->dsp.clear_blocks(s->block[0]);
485 for (i = 0; i < 6; i++) {
486 if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
487 {
488 av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
489 return -1;
490 }
491 }
492 return 0;
493 }
494
495 static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
496 {
497 int cbp, code, i;
498 uint8_t *coded_val;
499 uint32_t * const mb_type_ptr = &s->current_picture.f.mb_type[s->mb_x + s->mb_y*s->mb_stride];
500
501 if (s->pict_type == AV_PICTURE_TYPE_P) {
502 if (s->use_skip_mb_code) {
503 if (get_bits1(&s->gb)) {
504 /* skip mb */
505 s->mb_intra = 0;
506 for(i=0;i<6;i++)
507 s->block_last_index[i] = -1;
508 s->mv_dir = MV_DIR_FORWARD;
509 s->mv_type = MV_TYPE_16X16;
510 s->mv[0][0][0] = 0;
511 s->mv[0][0][1] = 0;
512 s->mb_skipped = 1;
513 *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
514
515 return 0;
516 }
517 }
518
519 code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3);
520 if (code < 0)
521 return -1;
522 //s->mb_intra = (code & 0x40) ? 0 : 1;
523 s->mb_intra = (~code & 0x40) >> 6;
524
525 cbp = code & 0x3f;
526 } else {
527 s->mb_intra = 1;
528 code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
529 if (code < 0)
530 return -1;
531 /* predict coded block pattern */
532 cbp = 0;
533 for(i=0;i<6;i++) {
534 int val = ((code >> (5 - i)) & 1);
535 if (i < 4) {
536 int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
537 val = val ^ pred;
538 *coded_val = val;
539 }
540 cbp |= val << (5 - i);
541 }
542 }
543
544 if (!s->mb_intra) {
545 int mx, my;
546 //printf("P at %d %d\n", s->mb_x, s->mb_y);
547 if(s->per_mb_rl_table && cbp){
548 s->rl_table_index = decode012(&s->gb);
549 s->rl_chroma_table_index = s->rl_table_index;
550 }
551 ff_h263_pred_motion(s, 0, 0, &mx, &my);
552 if (ff_msmpeg4_decode_motion(s, &mx, &my) < 0)
553 return -1;
554 s->mv_dir = MV_DIR_FORWARD;
555 s->mv_type = MV_TYPE_16X16;
556 s->mv[0][0][0] = mx;
557 s->mv[0][0][1] = my;
558 *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
559 } else {
560 //printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24));
561 s->ac_pred = get_bits1(&s->gb);
562 *mb_type_ptr = MB_TYPE_INTRA;
563 if(s->inter_intra_pred){
564 s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
565 // printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y);
566 }
567 if(s->per_mb_rl_table && cbp){
568 s->rl_table_index = decode012(&s->gb);
569 s->rl_chroma_table_index = s->rl_table_index;
570 }
571 }
572
573 s->dsp.clear_blocks(s->block[0]);
574 for (i = 0; i < 6; i++) {
575 if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
576 {
577 av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
578 return -1;
579 }
580 }
581
582 return 0;
583 }
584
585 /* init all vlc decoding tables */
586 av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
587 {
588 MpegEncContext *s = avctx->priv_data;
589 static int done = 0;
590 int i;
591 MVTable *mv;
592
593 if (ff_h263_decode_init(avctx) < 0)
594 return -1;
595
596 ff_msmpeg4_common_init(s);
597
598 if (!done) {
599 done = 1;
600
601 for(i=0;i<NB_RL_TABLES;i++) {
602 ff_init_rl(&ff_rl_table[i], ff_static_rl_table_store[i]);
603 }
604 INIT_VLC_RL(ff_rl_table[0], 642);
605 INIT_VLC_RL(ff_rl_table[1], 1104);
606 INIT_VLC_RL(ff_rl_table[2], 554);
607 INIT_VLC_RL(ff_rl_table[3], 940);
608 INIT_VLC_RL(ff_rl_table[4], 962);
609 INIT_VLC_RL(ff_rl_table[5], 554);
610
611 mv = &ff_mv_tables[0];
612 INIT_VLC_STATIC(&mv->vlc, MV_VLC_BITS, mv->n + 1,
613 mv->table_mv_bits, 1, 1,
614 mv->table_mv_code, 2, 2, 3714);
615 mv = &ff_mv_tables[1];
616 INIT_VLC_STATIC(&mv->vlc, MV_VLC_BITS, mv->n + 1,
617 mv->table_mv_bits, 1, 1,
618 mv->table_mv_code, 2, 2, 2694);
619
620 INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[0], DC_VLC_BITS, 120,
621 &ff_table0_dc_lum[0][1], 8, 4,
622 &ff_table0_dc_lum[0][0], 8, 4, 1158);
623 INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[0], DC_VLC_BITS, 120,
624 &ff_table0_dc_chroma[0][1], 8, 4,
625 &ff_table0_dc_chroma[0][0], 8, 4, 1118);
626 INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[1], DC_VLC_BITS, 120,
627 &ff_table1_dc_lum[0][1], 8, 4,
628 &ff_table1_dc_lum[0][0], 8, 4, 1476);
629 INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[1], DC_VLC_BITS, 120,
630 &ff_table1_dc_chroma[0][1], 8, 4,
631 &ff_table1_dc_chroma[0][0], 8, 4, 1216);
632
633 INIT_VLC_STATIC(&v2_dc_lum_vlc, DC_VLC_BITS, 512,
634 &ff_v2_dc_lum_table[0][1], 8, 4,
635 &ff_v2_dc_lum_table[0][0], 8, 4, 1472);
636 INIT_VLC_STATIC(&v2_dc_chroma_vlc, DC_VLC_BITS, 512,
637 &ff_v2_dc_chroma_table[0][1], 8, 4,
638 &ff_v2_dc_chroma_table[0][0], 8, 4, 1506);
639
640 INIT_VLC_STATIC(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
641 &ff_v2_intra_cbpc[0][1], 2, 1,
642 &ff_v2_intra_cbpc[0][0], 2, 1, 8);
643 INIT_VLC_STATIC(&v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8,
644 &ff_v2_mb_type[0][1], 2, 1,
645 &ff_v2_mb_type[0][0], 2, 1, 128);
646 INIT_VLC_STATIC(&v2_mv_vlc, V2_MV_VLC_BITS, 33,
647 &ff_mvtab[0][1], 2, 1,
648 &ff_mvtab[0][0], 2, 1, 538);
649
650 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[0], MB_NON_INTRA_VLC_BITS, 128,
651 &ff_wmv2_inter_table[0][0][1], 8, 4,
652 &ff_wmv2_inter_table[0][0][0], 8, 4, 1636);
653 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[1], MB_NON_INTRA_VLC_BITS, 128,
654 &ff_wmv2_inter_table[1][0][1], 8, 4,
655 &ff_wmv2_inter_table[1][0][0], 8, 4, 2648);
656 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[2], MB_NON_INTRA_VLC_BITS, 128,
657 &ff_wmv2_inter_table[2][0][1], 8, 4,
658 &ff_wmv2_inter_table[2][0][0], 8, 4, 1532);
659 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[3], MB_NON_INTRA_VLC_BITS, 128,
660 &ff_wmv2_inter_table[3][0][1], 8, 4,
661 &ff_wmv2_inter_table[3][0][0], 8, 4, 2488);
662
663 INIT_VLC_STATIC(&ff_msmp4_mb_i_vlc, MB_INTRA_VLC_BITS, 64,
664 &ff_msmp4_mb_i_table[0][1], 4, 2,
665 &ff_msmp4_mb_i_table[0][0], 4, 2, 536);
666
667 INIT_VLC_STATIC(&ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 4,
668 &ff_table_inter_intra[0][1], 2, 1,
669 &ff_table_inter_intra[0][0], 2, 1, 8);
670 }
671
672 switch(s->msmpeg4_version){
673 case 1:
674 case 2:
675 s->decode_mb= msmpeg4v12_decode_mb;
676 break;
677 case 3:
678 case 4:
679 s->decode_mb= msmpeg4v34_decode_mb;
680 break;
681 case 5:
682 if (CONFIG_WMV2_DECODER)
683 s->decode_mb= ff_wmv2_decode_mb;
684 case 6:
685 //FIXME + TODO VC1 decode mb
686 break;
687 }
688
689 s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe
690
691 return 0;
692 }
693
694 int ff_msmpeg4_decode_picture_header(MpegEncContext * s)
695 {
696 int code;
697
698 if(s->msmpeg4_version==1){
699 int start_code = get_bits_long(&s->gb, 32);
700 if(start_code!=0x00000100){
701 av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
702 return -1;
703 }
704
705 skip_bits(&s->gb, 5); // frame number */
706 }
707
708 s->pict_type = get_bits(&s->gb, 2) + 1;
709 if (s->pict_type != AV_PICTURE_TYPE_I &&
710 s->pict_type != AV_PICTURE_TYPE_P){
711 av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
712 return -1;
713 }
714 #if 0
715 {
716 static int had_i=0;
717 if(s->pict_type == AV_PICTURE_TYPE_I) had_i=1;
718 if(!had_i) return -1;
719 }
720 #endif
721 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
722 if(s->qscale==0){
723 av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
724 return -1;
725 }
726
727 if (s->pict_type == AV_PICTURE_TYPE_I) {
728 code = get_bits(&s->gb, 5);
729 if(s->msmpeg4_version==1){
730 if(code==0 || code>s->mb_height){
731 av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
732 return -1;
733 }
734
735 s->slice_height = code;
736 }else{
737 /* 0x17: one slice, 0x18: two slices, ... */
738 if (code < 0x17){
739 av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
740 return -1;
741 }
742
743 s->slice_height = s->mb_height / (code - 0x16);
744 }
745
746 switch(s->msmpeg4_version){
747 case 1:
748 case 2:
749 s->rl_chroma_table_index = 2;
750 s->rl_table_index = 2;
751
752 s->dc_table_index = 0; //not used
753 break;
754 case 3:
755 s->rl_chroma_table_index = decode012(&s->gb);
756 s->rl_table_index = decode012(&s->gb);
757
758 s->dc_table_index = get_bits1(&s->gb);
759 break;
760 case 4:
761 ff_msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
762
763 if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
764 else s->per_mb_rl_table= 0;
765
766 if(!s->per_mb_rl_table){
767 s->rl_chroma_table_index = decode012(&s->gb);
768 s->rl_table_index = decode012(&s->gb);
769 }
770
771 s->dc_table_index = get_bits1(&s->gb);
772 s->inter_intra_pred= 0;
773 break;
774 }
775 s->no_rounding = 1;
776 if(s->avctx->debug&FF_DEBUG_PICT_INFO)
777 av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
778 s->qscale,
779 s->rl_chroma_table_index,
780 s->rl_table_index,
781 s->dc_table_index,
782 s->per_mb_rl_table,
783 s->slice_height);
784 } else {
785 switch(s->msmpeg4_version){
786 case 1:
787 case 2:
788 if(s->msmpeg4_version==1)
789 s->use_skip_mb_code = 1;
790 else
791 s->use_skip_mb_code = get_bits1(&s->gb);
792 s->rl_table_index = 2;
793 s->rl_chroma_table_index = s->rl_table_index;
794 s->dc_table_index = 0; //not used
795 s->mv_table_index = 0;
796 break;
797 case 3:
798 s->use_skip_mb_code = get_bits1(&s->gb);
799 s->rl_table_index = decode012(&s->gb);
800 s->rl_chroma_table_index = s->rl_table_index;
801
802 s->dc_table_index = get_bits1(&s->gb);
803
804 s->mv_table_index = get_bits1(&s->gb);
805 break;
806 case 4:
807 s->use_skip_mb_code = get_bits1(&s->gb);
808
809 if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
810 else s->per_mb_rl_table= 0;
811
812 if(!s->per_mb_rl_table){
813 s->rl_table_index = decode012(&s->gb);
814 s->rl_chroma_table_index = s->rl_table_index;
815 }
816
817 s->dc_table_index = get_bits1(&s->gb);
818
819 s->mv_table_index = get_bits1(&s->gb);
820 s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
821 break;
822 }
823
824 if(s->avctx->debug&FF_DEBUG_PICT_INFO)
825 av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
826 s->use_skip_mb_code,
827 s->rl_table_index,
828 s->rl_chroma_table_index,
829 s->dc_table_index,
830 s->mv_table_index,
831 s->per_mb_rl_table,
832 s->qscale);
833
834 if(s->flipflop_rounding){
835 s->no_rounding ^= 1;
836 }else{
837 s->no_rounding = 0;
838 }
839 }
840 //printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height);
841
842 s->esc3_level_length= 0;
843 s->esc3_run_length= 0;
844
845 return 0;
846 }
847
848 int ff_msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
849 {
850 int left= buf_size*8 - get_bits_count(&s->gb);
851 int length= s->msmpeg4_version>=3 ? 17 : 16;
852 /* the alt_bitstream reader could read over the end so we need to check it */
853 if(left>=length && left<length+8)
854 {
855 skip_bits(&s->gb, 5); /* fps */
856 s->bit_rate= get_bits(&s->gb, 11)*1024;
857 if(s->msmpeg4_version>=3)
858 s->flipflop_rounding= get_bits1(&s->gb);
859 else
860 s->flipflop_rounding= 0;
861
862 // printf("fps:%2d bps:%2d roundingType:%1d\n", fps, s->bit_rate/1024, s->flipflop_rounding);
863 }
864 else if(left<length+8)
865 {
866 s->flipflop_rounding= 0;
867 if(s->msmpeg4_version != 2)
868 av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
869 }
870 else
871 {
872 av_log(s->avctx, AV_LOG_ERROR, "I frame too long, ignoring ext header\n");
873 }
874
875 return 0;
876 }
877
878 static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
879 {
880 int level, pred;
881
882 if(s->msmpeg4_version<=2){
883 if (n < 4) {
884 level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3);
885 } else {
886 level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3);
887 }
888 if (level < 0)
889 return -1;
890 level-=256;
891 }else{ //FIXME optimize use unified tables & index
892 if (n < 4) {
893 level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
894 } else {
895 level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
896 }
897 if (level < 0){
898 av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
899 return -1;
900 }
901
902 if (level == DC_MAX) {
903 level = get_bits(&s->gb, 8);
904 if (get_bits1(&s->gb))
905 level = -level;
906 } else if (level != 0) {
907 if (get_bits1(&s->gb))
908 level = -level;
909 }
910 }
911
912 if(s->msmpeg4_version==1){
913 int32_t *dc_val;
914 pred = msmpeg4v1_pred_dc(s, n, &dc_val);
915 level += pred;
916
917 /* update predictor */
918 *dc_val= level;
919 }else{
920 int16_t *dc_val;
921 pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
922 level += pred;
923
924 /* update predictor */
925 if (n < 4) {
926 *dc_val = level * s->y_dc_scale;
927 } else {
928 *dc_val = level * s->c_dc_scale;
929 }
930 }
931
932 return level;
933 }
934
935 //#define ERROR_DETAILS
936 int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
937 int n, int coded, const uint8_t *scan_table)
938 {
939 int level, i, last, run, run_diff;
940 int av_uninit(dc_pred_dir);
941 RLTable *rl;
942 RL_VLC_ELEM *rl_vlc;
943 int qmul, qadd;
944
945 if (s->mb_intra) {
946 qmul=1;
947 qadd=0;
948
949 /* DC coef */
950 level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
951
952 if (level < 0){
953 av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
954 if(s->inter_intra_pred) level=0;
955 else return -1;
956 }
957 if (n < 4) {
958 rl = &ff_rl_table[s->rl_table_index];
959 if(level > 256*s->y_dc_scale){
960 av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
961 if(!s->inter_intra_pred) return -1;
962 }
963 } else {
964 rl = &ff_rl_table[3 + s->rl_chroma_table_index];
965 if(level > 256*s->c_dc_scale){
966 av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
967 if(!s->inter_intra_pred) return -1;
968 }
969 }
970 block[0] = level;
971
972 run_diff = s->msmpeg4_version >= 4;
973 i = 0;
974 if (!coded) {
975 goto not_coded;
976 }
977 if (s->ac_pred) {
978 if (dc_pred_dir == 0)
979 scan_table = s->intra_v_scantable.permutated; /* left */
980 else
981 scan_table = s->intra_h_scantable.permutated; /* top */
982 } else {
983 scan_table = s->intra_scantable.permutated;
984 }
985 rl_vlc= rl->rl_vlc[0];
986 } else {
987 qmul = s->qscale << 1;
988 qadd = (s->qscale - 1) | 1;
989 i = -1;
990 rl = &ff_rl_table[3 + s->rl_table_index];
991
992 if(s->msmpeg4_version==2)
993 run_diff = 0;
994 else
995 run_diff = 1;
996
997 if (!coded) {
998 s->block_last_index[n] = i;
999 return 0;
1000 }
1001 if(!scan_table)
1002 scan_table = s->inter_scantable.permutated;
1003 rl_vlc= rl->rl_vlc[s->qscale];
1004 }
1005 {
1006 OPEN_READER(re, &s->gb);
1007 for(;;) {
1008 UPDATE_CACHE(re, &s->gb);
1009 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
1010 if (level==0) {
1011 int cache;
1012 cache= GET_CACHE(re, &s->gb);
1013 /* escape */
1014 if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {
1015 if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {
1016 /* third escape */
1017 if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);
1018 UPDATE_CACHE(re, &s->gb);
1019 if(s->msmpeg4_version<=3){
1020 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
1021 run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
1022 level= SHOW_SBITS(re, &s->gb, 8);
1023 SKIP_COUNTER(re, &s->gb, 1+6+8);
1024 }else{
1025 int sign;
1026 last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
1027 if(!s->esc3_level_length){
1028 int ll;
1029 //printf("ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
1030 if(s->qscale<8){
1031 ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
1032 if(ll==0){
1033 ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
1034 }
1035 }else{
1036 ll=2;
1037 while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
1038 ll++;
1039 SKIP_BITS(re, &s->gb, 1);
1040 }
1041 if(ll<8) SKIP_BITS(re, &s->gb, 1);
1042 }
1043
1044 s->esc3_level_length= ll;
1045 s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
1046 //printf("level length:%d, run length: %d\n", ll, s->esc3_run_length);
1047 UPDATE_CACHE(re, &s->gb);
1048 }
1049 run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
1050 SKIP_BITS(re, &s->gb, s->esc3_run_length);
1051
1052 sign= SHOW_UBITS(re, &s->gb, 1);
1053 SKIP_BITS(re, &s->gb, 1);
1054
1055 level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
1056 SKIP_BITS(re, &s->gb, s->esc3_level_length);
1057 if(sign) level= -level;
1058 }
1059 //printf("level: %d, run: %d at %d %d\n", level, run, s->mb_x, s->mb_y);
1060 #if 0 // waste of time / this will detect very few errors
1061 {
1062 const int abs_level= FFABS(level);
1063 const int run1= run - rl->max_run[last][abs_level] - run_diff;
1064 if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
1065 if(abs_level <= rl->max_level[last][run]){
1066 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
1067 return DECODING_AC_LOST;
1068 }
1069 if(abs_level <= rl->max_level[last][run]*2){
1070 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
1071 return DECODING_AC_LOST;
1072 }
1073 if(run1>=0 && abs_level <= rl->max_level[last][run1]){
1074 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
1075 return DECODING_AC_LOST;
1076 }
1077 }
1078 }
1079 #endif
1080 //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
1081 if (level>0) level= level * qmul + qadd;
1082 else level= level * qmul - qadd;
1083 #if 0 // waste of time too :(
1084 if(level>2048 || level<-2048){
1085 av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n");
1086 return DECODING_AC_LOST;
1087 }
1088 #endif
1089 i+= run + 1;
1090 if(last) i+=192;
1091 #ifdef ERROR_DETAILS
1092 if(run==66)
1093 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level);
1094 else if((i>62 && i<192) || i>192+63)
1095 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level);
1096 #endif
1097 } else {
1098 /* second escape */
1099 SKIP_BITS(re, &s->gb, 2);
1100 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
1101 i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing
1102 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
1103 LAST_SKIP_BITS(re, &s->gb, 1);
1104 #ifdef ERROR_DETAILS
1105 if(run==66)
1106 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level);
1107 else if((i>62 && i<192) || i>192+63)
1108 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level);
1109 #endif
1110 }
1111 } else {
1112 /* first escape */
1113 SKIP_BITS(re, &s->gb, 1);
1114 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
1115 i+= run;
1116 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing
1117 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
1118 LAST_SKIP_BITS(re, &s->gb, 1);
1119 #ifdef ERROR_DETAILS
1120 if(run==66)
1121 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level);
1122 else if((i>62 && i<192) || i>192+63)
1123 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level);
1124 #endif
1125 }
1126 } else {
1127 i+= run;
1128 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
1129 LAST_SKIP_BITS(re, &s->gb, 1);
1130 #ifdef ERROR_DETAILS
1131 if(run==66)
1132 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level);
1133 else if((i>62 && i<192) || i>192+63)
1134 av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level);
1135 #endif
1136 }
1137 if (i > 62){
1138 i-= 192;
1139 if(i&(~63)){
1140 const int left= get_bits_left(&s->gb);
1141 if(((i+192 == 64 && level/qmul==-1) || !(s->err_recognition&AV_EF_BITSTREAM)) && left>=0){
1142 av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
1143 break;
1144 }else{
1145 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
1146 return -1;
1147 }
1148 }
1149
1150 block[scan_table[i]] = level;
1151 break;
1152 }
1153
1154 block[scan_table[i]] = level;
1155 }
1156 CLOSE_READER(re, &s->gb);
1157 }
1158 not_coded:
1159 if (s->mb_intra) {
1160 ff_mpeg4_pred_ac(s, block, n, dc_pred_dir);
1161 if (s->ac_pred) {
1162 i = 63; /* XXX: not optimal */
1163 }
1164 }
1165 if(s->msmpeg4_version>=4 && i>0) i=63; //FIXME/XXX optimize
1166 s->block_last_index[n] = i;
1167
1168 return 0;
1169 }
1170
1171 int ff_msmpeg4_decode_motion(MpegEncContext * s,
1172 int *mx_ptr, int *my_ptr)
1173 {
1174 MVTable *mv;
1175 int code, mx, my;
1176
1177 mv = &ff_mv_tables[s->mv_table_index];
1178
1179 code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2);
1180 if (code < 0){
1181 av_log(s->avctx, AV_LOG_ERROR, "illegal MV code at %d %d\n", s->mb_x, s->mb_y);
1182 return -1;
1183 }
1184 if (code == mv->n) {
1185 //printf("MV ESC %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
1186 mx = get_bits(&s->gb, 6);
1187 my = get_bits(&s->gb, 6);
1188 } else {
1189 mx = mv->table_mvx[code];
1190 my = mv->table_mvy[code];
1191 }
1192
1193 mx += *mx_ptr - 32;
1194 my += *my_ptr - 32;
1195 /* WARNING : they do not do exactly modulo encoding */
1196 if (mx <= -64)
1197 mx += 64;
1198 else if (mx >= 64)
1199 mx -= 64;
1200
1201 if (my <= -64)
1202 my += 64;
1203 else if (my >= 64)
1204 my -= 64;
1205 *mx_ptr = mx;
1206 *my_ptr = my;
1207 return 0;
1208 }
1209
1210 AVCodec ff_msmpeg4v1_decoder = {
1211 .name = "msmpeg4v1",
1212 .type = AVMEDIA_TYPE_VIDEO,
1213 .id = CODEC_ID_MSMPEG4V1,
1214 .priv_data_size = sizeof(MpegEncContext),
1215 .init = ff_msmpeg4_decode_init,
1216 .close = ff_h263_decode_end,
1217 .decode = ff_h263_decode_frame,
1218 .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
1219 .max_lowres = 3,
1220 .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"),
1221 .pix_fmts = ff_pixfmt_list_420,
1222 };
1223
1224 AVCodec ff_msmpeg4v2_decoder = {
1225 .name = "msmpeg4v2",
1226 .type = AVMEDIA_TYPE_VIDEO,
1227 .id = CODEC_ID_MSMPEG4V2,
1228 .priv_data_size = sizeof(MpegEncContext),
1229 .init = ff_msmpeg4_decode_init,
1230 .close = ff_h263_decode_end,
1231 .decode = ff_h263_decode_frame,
1232 .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
1233 .max_lowres = 3,
1234 .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
1235 .pix_fmts = ff_pixfmt_list_420,
1236 };
1237
1238 AVCodec ff_msmpeg4v3_decoder = {
1239 .name = "msmpeg4",
1240 .type = AVMEDIA_TYPE_VIDEO,
1241 .id = CODEC_ID_MSMPEG4V3,
1242 .priv_data_size = sizeof(MpegEncContext),
1243 .init = ff_msmpeg4_decode_init,
1244 .close = ff_h263_decode_end,
1245 .decode = ff_h263_decode_frame,
1246 .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
1247 .max_lowres = 3,
1248 .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
1249 .pix_fmts = ff_pixfmt_list_420,
1250 };
1251
1252 AVCodec ff_wmv1_decoder = {
1253 .name = "wmv1",
1254 .type = AVMEDIA_TYPE_VIDEO,
1255 .id = CODEC_ID_WMV1,
1256 .priv_data_size = sizeof(MpegEncContext),
1257 .init = ff_msmpeg4_decode_init,
1258 .close = ff_h263_decode_end,
1259 .decode = ff_h263_decode_frame,
1260 .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
1261 .max_lowres = 3,
1262 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
1263 .pix_fmts = ff_pixfmt_list_420,
1264 };