comparison h263.c @ 619:2be2cc8fd0a1 libavcodec

mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
author michaelni
date Tue, 27 Aug 2002 16:28:19 +0000
parents df2102629fef
children dddcff6841f2
comparison
equal deleted inserted replaced
618:4f3d4a07d374 619:2be2cc8fd0a1
1744 &sprite_trajectory_tab[0][0], 4, 2); 1744 &sprite_trajectory_tab[0][0], 4, 2);
1745 init_vlc(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4, 1745 init_vlc(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
1746 &mb_type_b_tab[0][1], 2, 1, 1746 &mb_type_b_tab[0][1], 2, 1,
1747 &mb_type_b_tab[0][0], 2, 1); 1747 &mb_type_b_tab[0][0], 2, 1);
1748 } 1748 }
1749
1750 s->progressive_sequence=1; // set to most likely for the case of incomplete headers
1749 } 1751 }
1750 1752
1751 int h263_decode_gob_header(MpegEncContext *s) 1753 int h263_decode_gob_header(MpegEncContext *s)
1752 { 1754 {
1753 unsigned int val, gfid; 1755 unsigned int val, gfid;
2424 } 2426 }
2425 } 2427 }
2426 2428
2427 return 0; 2429 return 0;
2428 } 2430 }
2429 2431 #if 0
2432 static inline void decode_interlaced_info(MpegEncContext *s, int cbp, int mb_type){
2433 s->mv_type= 0;
2434 if(!s->progressive_sequence){
2435 if(cbp || s->mb_intra)
2436 s->interlaced_dct= get_bits1(&s->gb);
2437
2438 if(!s->mb_intra){
2439 if( s->pict_type==P_TYPE //FIXME check that 4MV is forbidden
2440 || (s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && !s->mcsel)
2441 || (s->pict_type==B_TYPE && mb_type!=0) ){
2442
2443 if(get_bits1(&s->gb)){
2444 s->mv_type= MV_TYPE_FIELD;
2445
2446 if( s->pict_type==P_TYPE
2447 || (s->pict_type==B_TYPE && mb_type!=2)){
2448 s->field_select[0][0]= get_bits1(&s->gb);
2449 s->field_select[0][1]= get_bits1(&s->gb);
2450 }
2451 if(s->pict_type==B_TYPE && mb_type!=3){
2452 s->field_select[1][0]= get_bits1(&s->gb);
2453 s->field_select[1][1]= get_bits1(&s->gb);
2454 }
2455 }else
2456 s->mv_type= 0;
2457 }
2458 }
2459 }
2460 }
2461 #endif
2430 2462
2431 int h263_decode_mb(MpegEncContext *s, 2463 int h263_decode_mb(MpegEncContext *s,
2432 DCTELEM block[6][64]) 2464 DCTELEM block[6][64])
2433 { 2465 {
2434 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; 2466 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
2505 s->qscale = 1; 2537 s->qscale = 1;
2506 else if (s->qscale > 31) 2538 else if (s->qscale > 31)
2507 s->qscale = 31; 2539 s->qscale = 31;
2508 h263_dc_scale(s); 2540 h263_dc_scale(s);
2509 } 2541 }
2542 if((!s->progressive_sequence) && (cbp || s->workaround_bugs==2))
2543 s->interlaced_dct= get_bits1(&s->gb);
2544
2510 s->mv_dir = MV_DIR_FORWARD; 2545 s->mv_dir = MV_DIR_FORWARD;
2511 if ((cbpc & 16) == 0) { 2546 if ((cbpc & 16) == 0) {
2512 PRINT_MB_TYPE("P"); 2547 if(s->mcsel){
2513 /* 16x16 motion prediction */ 2548 const int a= s->sprite_warping_accuracy;
2514 s->mv_type = MV_TYPE_16X16; 2549 PRINT_MB_TYPE("G");
2515 h263_pred_motion(s, 0, &pred_x, &pred_y); 2550 /* 16x16 global motion prediction */
2516 if (s->umvplus_dec) 2551 s->mv_type = MV_TYPE_16X16;
2517 mx = h263p_decode_umotion(s, pred_x);
2518 else if(!s->mcsel)
2519 mx = h263_decode_motion(s, pred_x, s->f_code);
2520 else {
2521 const int a= s->sprite_warping_accuracy;
2522 // int l = (1 << (s->f_code - 1)) * 32; 2552 // int l = (1 << (s->f_code - 1)) * 32;
2523 if(s->divx_version==500 && s->divx_build==413){ 2553 if(s->divx_version==500 && s->divx_build==413){
2524 mx = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample)); 2554 mx = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample));
2555 my = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample));
2525 }else{ 2556 }else{
2526 mx = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); 2557 mx = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample);
2527 } 2558 my = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample);
2528 // if (mx < -l) mx= -l, printf("C"); 2559 }
2529 // else if (mx >= l) mx= l-1, printf("C"); 2560 // int l = (1 << (s->f_code - 1)) * 32;
2530 } 2561 s->mv[0][0][0] = mx;
2531 if (mx >= 0xffff) 2562 s->mv[0][0][1] = my;
2532 return -1; 2563 }else if((!s->progressive_sequence) && get_bits1(&s->gb)){
2564 PRINT_MB_TYPE("f");
2565 /* 16x8 field motion prediction */
2566 s->mv_type= MV_TYPE_FIELD;
2567
2568 s->field_select[0][0]= get_bits1(&s->gb);
2569 s->field_select[0][1]= get_bits1(&s->gb);
2570
2571 h263_pred_motion(s, 0, &pred_x, &pred_y);
2572
2573 for(i=0; i<2; i++){
2574 mx = h263_decode_motion(s, pred_x, s->f_code);
2575 if (mx >= 0xffff)
2576 return -1;
2533 2577
2534 if (s->umvplus_dec) 2578 my = h263_decode_motion(s, pred_y/2, s->f_code);
2535 my = h263p_decode_umotion(s, pred_y); 2579 if (my >= 0xffff)
2536 else if(!s->mcsel) 2580 return -1;
2537 my = h263_decode_motion(s, pred_y, s->f_code); 2581
2538 else{ 2582 s->mv[0][i][0] = mx;
2539 const int a= s->sprite_warping_accuracy; 2583 s->mv[0][i][1] = my*2;
2540 // int l = (1 << (s->f_code - 1)) * 32; 2584 }
2541 if(s->divx_version==500 && s->divx_build==413){ 2585 }else{
2542 my = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample)); 2586 PRINT_MB_TYPE("P");
2543 }else{ 2587 /* 16x16 motion prediction */
2544 my = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); 2588 s->mv_type = MV_TYPE_16X16;
2545 } 2589 h263_pred_motion(s, 0, &pred_x, &pred_y);
2546 // if (my < -l) my= -l, printf("C"); 2590 if (s->umvplus_dec)
2547 // else if (my >= l) my= l-1, printf("C"); 2591 mx = h263p_decode_umotion(s, pred_x);
2548 } 2592 else
2549 if (my >= 0xffff) 2593 mx = h263_decode_motion(s, pred_x, s->f_code);
2550 return -1; 2594
2551 s->mv[0][0][0] = mx; 2595 if (mx >= 0xffff)
2552 s->mv[0][0][1] = my; 2596 return -1;
2553 /*fprintf(stderr, "\n MB %d", (s->mb_y * s->mb_width) + s->mb_x); 2597
2554 fprintf(stderr, "\n\tmvx: %d\t\tpredx: %d", mx, pred_x); 2598 if (s->umvplus_dec)
2555 fprintf(stderr, "\n\tmvy: %d\t\tpredy: %d", my, pred_y);*/ 2599 my = h263p_decode_umotion(s, pred_y);
2556 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) 2600 else
2557 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ 2601 my = h263_decode_motion(s, pred_y, s->f_code);
2558 2602
2603 if (my >= 0xffff)
2604 return -1;
2605 s->mv[0][0][0] = mx;
2606 s->mv[0][0][1] = my;
2607
2608 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1)
2609 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
2610 }
2559 } else { 2611 } else {
2560 PRINT_MB_TYPE("4"); 2612 PRINT_MB_TYPE("4");
2561 s->mv_type = MV_TYPE_8X8; 2613 s->mv_type = MV_TYPE_8X8;
2562 for(i=0;i<4;i++) { 2614 for(i=0;i<4;i++) {
2563 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); 2615 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);
2612 s->mv_type = MV_TYPE_16X16; 2664 s->mv_type = MV_TYPE_16X16;
2613 s->mv[0][0][0] = 0; 2665 s->mv[0][0][0] = 0;
2614 s->mv[0][0][1] = 0; 2666 s->mv[0][0][1] = 0;
2615 s->mv[1][0][0] = 0; 2667 s->mv[1][0][0] = 0;
2616 s->mv[1][0][1] = 0; 2668 s->mv[1][0][1] = 0;
2617 //FIXME is this correct?
2618 /* s->last_mv[0][0][0]=
2619 s->last_mv[0][0][1]=0;*/
2620 PRINT_MB_TYPE("s"); 2669 PRINT_MB_TYPE("s");
2621 return 0; 2670 return 0;
2622 } 2671 }
2623 2672
2624 modb1= get_bits1(&s->gb); 2673 modb1= get_bits1(&s->gb);
2635 else if (s->qscale > 31) 2684 else if (s->qscale > 31)
2636 s->qscale = 31; 2685 s->qscale = 31;
2637 h263_dc_scale(s); 2686 h263_dc_scale(s);
2638 } 2687 }
2639 } 2688 }
2689 // decode_interlaced_info(s, cbp, mb_type);
2640 }else{ 2690 }else{
2641 mb_type=4; //like 0 but no vectors coded 2691 mb_type=4; //like 0 but no vectors coded
2642 cbp=0; 2692 cbp=0;
2643 } 2693 }
2644 s->mv_type = MV_TYPE_16X16; // we'll switch to 8x8 only if the last P frame had 8x8 for this MB and mb_type=0 here 2694 s->mv_type = MV_TYPE_16X16; // we'll switch to 8x8 only if the last P frame had 8x8 for this MB and mb_type=0 here
2680 /* s->mv[0][0][0] = 2730 /* s->mv[0][0][0] =
2681 s->mv[0][0][1] = 2731 s->mv[0][0][1] =
2682 s->mv[1][0][0] = 2732 s->mv[1][0][0] =
2683 s->mv[1][0][1] = 1000;*/ 2733 s->mv[1][0][1] = 1000;*/
2684 break; 2734 break;
2735 //FIXME additional MVs for interlaced stuff
2685 case 1: 2736 case 1:
2686 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; 2737 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;
2687 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); 2738 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);
2688 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); 2739 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code);
2689 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; 2740 s->last_mv[0][0][0]= s->mv[0][0][0] = mx;
2739 s->qscale = 1; 2790 s->qscale = 1;
2740 else if (s->qscale > 31) 2791 else if (s->qscale > 31)
2741 s->qscale = 31; 2792 s->qscale = 31;
2742 h263_dc_scale(s); 2793 h263_dc_scale(s);
2743 } 2794 }
2795 if(!s->progressive_sequence)
2796 s->interlaced_dct= get_bits1(&s->gb);
2744 2797
2745 /* decode each block */ 2798 /* decode each block */
2746 if (s->h263_pred) { 2799 if (s->h263_pred) {
2747 for (i = 0; i < 6; i++) { 2800 for (i = 0; i < 6; i++) {
2748 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1) < 0) 2801 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1) < 0)
3604 s->height = height; 3657 s->height = height;
3605 // printf("width/height: %d %d\n", width, height); 3658 // printf("width/height: %d %d\n", width, height);
3606 } 3659 }
3607 } 3660 }
3608 3661
3609 if(get_bits1(&s->gb)) printf("interlaced not supported\n"); /* interlaced */ 3662 s->progressive_sequence= get_bits1(&s->gb)^1;
3610 if(!get_bits1(&s->gb)) printf("OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */ 3663 if(!get_bits1(&s->gb)) printf("OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */
3611 if (vo_ver_id == 1) { 3664 if (vo_ver_id == 1) {
3612 s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */ 3665 s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */
3613 } else { 3666 } else {
3614 s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */ 3667 s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */
3761 s->divx_build= build; 3814 s->divx_build= build;
3762 if(s->picture_number==0){ 3815 if(s->picture_number==0){
3763 printf("This file was encoded with DivX%d Build%d\n", ver, build); 3816 printf("This file was encoded with DivX%d Build%d\n", ver, build);
3764 if(ver==500 && build==413){ 3817 if(ver==500 && build==413){
3765 printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n"); 3818 printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n");
3766 #if 0
3767 }else{
3768 printf("hmm, i havnt seen that version of divx yet, lets assume they fixed these bugs ...\n"
3769 "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n");
3770 #endif
3771 } 3819 }
3772 } 3820 }
3773 } 3821 }
3774 //printf("User Data: %s\n", buf); 3822 //printf("User Data: %s\n", buf);
3775 goto redo; 3823 goto redo;
3849 3897
3850 if (s->shape != BIN_ONLY_SHAPE) { 3898 if (s->shape != BIN_ONLY_SHAPE) {
3851 int t; 3899 int t;
3852 t=get_bits(&s->gb, 3); /* intra dc VLC threshold */ 3900 t=get_bits(&s->gb, 3); /* intra dc VLC threshold */
3853 //printf("threshold %d\n", t); 3901 //printf("threshold %d\n", t);
3854 //FIXME interlaced specific bits 3902 if(!s->progressive_sequence){
3903 s->top_field_first= get_bits1(&s->gb);
3904 s->alternate_scan= get_bits1(&s->gb);
3905 //printf("top:%d alt:%d\n", s->top_field_first, s->alternate_scan);
3906 }
3855 } 3907 }
3856 3908
3857 if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ 3909 if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){
3858 if(s->num_sprite_warping_points){ 3910 if(s->num_sprite_warping_points){
3859 mpeg4_decode_sprite_trajectory(s); 3911 mpeg4_decode_sprite_trajectory(s);