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