Revision 7bc9090a libavcodec/h263.c

View differences:

libavcodec/h263.c
39 39
//#undef NDEBUG
40 40
//#include <assert.h>
41 41

  
42
#if 1
43
#define PRINT_MB_TYPE(a) {}
44
#else
45
#define PRINT_MB_TYPE(a) printf(a)
46
#endif
47

  
48 42
#define INTRA_MCBPC_VLC_BITS 6
49 43
#define INTER_MCBPC_VLC_BITS 6
50 44
#define CBPY_VLC_BITS 6
......
290 284
        ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
291 285
        ac_val1= ac_val;
292 286
        if(dir[n]){
293
            const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width;
287
            const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
294 288
            /* top prediction */
295 289
            ac_val-= s->block_wrap[n]*16;
296 290
            if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
......
313 307
                }
314 308
            }
315 309
        }else{
316
            const int xy= s->mb_x-1 + s->mb_y*s->mb_width;
310
            const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
317 311
            /* left prediction */
318 312
            ac_val-= 16;
319 313
            if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
......
349 343
    int8_t * const qscale_table= s->current_picture.qscale_table;
350 344
    
351 345
    for(i=1; i<s->mb_num; i++){
352
        if(qscale_table[i] - qscale_table[i-1] >2)
353
            qscale_table[i]= qscale_table[i-1]+2;
346
        if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2)
347
            qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2;
354 348
    }
355 349
    for(i=s->mb_num-2; i>=0; i--){
356
        if(qscale_table[i] - qscale_table[i+1] >2)
357
            qscale_table[i]= qscale_table[i+1]+2;
350
        if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i+1] ] >2)
351
            qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i+1] ]+2;
358 352
    }
359 353
}
360 354

  
......
368 362
    ff_clean_h263_qscales(s);
369 363
    
370 364
    for(i=1; i<s->mb_num; i++){
371
        if(qscale_table[i] != qscale_table[i-1] && (s->mb_type[i]&MB_TYPE_INTER4V)){
372
            s->mb_type[i]&= ~MB_TYPE_INTER4V;
373
            s->mb_type[i]|= MB_TYPE_INTER;
365
        int mb_xy= s->mb_index2xy[i];
366
    
367
        if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&MB_TYPE_INTER4V)){
368
            s->mb_type[mb_xy]&= ~MB_TYPE_INTER4V;
369
            s->mb_type[mb_xy]|= MB_TYPE_INTER;
374 370
        }
375 371
    }
376 372

  
......
380 376
           for the actual adaptive quantization */
381 377
        
382 378
        for(i=0; i<s->mb_num; i++){
383
            odd += qscale_table[i]&1;
379
            int mb_xy= s->mb_index2xy[i];
380
            odd += qscale_table[mb_xy]&1;
384 381
        }
385 382
        
386 383
        if(2*odd > s->mb_num) odd=1;
387 384
        else                  odd=0;
388 385
        
389 386
        for(i=0; i<s->mb_num; i++){
390
            if((qscale_table[i]&1) != odd)
391
                qscale_table[i]++;
392
            if(qscale_table[i] > 31)
393
                qscale_table[i]= 31;
387
            int mb_xy= s->mb_index2xy[i];
388
            if((qscale_table[mb_xy]&1) != odd)
389
                qscale_table[mb_xy]++;
390
            if(qscale_table[mb_xy] > 31)
391
                qscale_table[mb_xy]= 31;
394 392
        }            
395 393
    
396 394
        for(i=1; i<s->mb_num; i++){
397
            if(qscale_table[i] != qscale_table[i-1] && (s->mb_type[i]&MB_TYPE_DIRECT)){
398
                s->mb_type[i]&= ~MB_TYPE_DIRECT;
399
                s->mb_type[i]|= MB_TYPE_BIDIR;
395
            int mb_xy= s->mb_index2xy[i];
396
            if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&MB_TYPE_DIRECT)){
397
                s->mb_type[mb_xy]&= ~MB_TYPE_DIRECT;
398
                s->mb_type[mb_xy]|= MB_TYPE_BIDIR;
400 399
            }
401 400
        }
402 401
    }
403 402
}
404 403

  
405 404
#endif //CONFIG_ENCODERS
406

  
407
void ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){
408
    const int mb_index= s->mb_x + s->mb_y*s->mb_width;
405
/**
406
 *
407
 * @return the mb_type
408
 */
409
int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){
410
    const int mb_index= s->mb_x + s->mb_y*s->mb_stride;
411
    const int colocated_mb_type= s->next_picture.mb_type[mb_index]; //FIXME or next?
409 412
    int xy= s->block_index[0];
410 413
    uint16_t time_pp= s->pp_time;
411 414
    uint16_t time_pb= s->pb_time;
412 415
    int i;
413 416
    
414 417
    //FIXME avoid divides
415
    switch(s->co_located_type_table[mb_index]){
416
    case 0:
417
        s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->motion_val[xy][0]*time_pb/time_pp + mx;
418
        s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->motion_val[xy][1]*time_pb/time_pp + my;
419
        s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0]
420
                            : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp;
421
        s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] 
422
                            : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp;
423
        if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample)
424
            s->mv_type= MV_TYPE_16X16;
425
        else
426
            s->mv_type= MV_TYPE_8X8;
427
        break;
428
    case CO_LOCATED_TYPE_4MV:
418
    
419
    if(IS_8X8(colocated_mb_type)){
429 420
        s->mv_type = MV_TYPE_8X8;
430 421
        for(i=0; i<4; i++){
431 422
            xy= s->block_index[i];
......
436 427
            s->mv[1][i][1] = my ? s->mv[0][i][1] - s->motion_val[xy][1] 
437 428
                                : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp;
438 429
        }
439
        break;
440
    case CO_LOCATED_TYPE_FIELDMV:
430
        return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1;
431
    } else if(IS_INTERLACED(colocated_mb_type)){
441 432
        s->mv_type = MV_TYPE_FIELD;
442 433
        for(i=0; i<2; i++){
443 434
            if(s->top_field_first){
......
454 445
            s->mv[1][i][1] = my ? s->mv[0][i][1] - s->field_mv_table[mb_index][i][1] 
455 446
                                : s->field_mv_table[mb_index][i][1]*(time_pb - time_pp)/time_pp;
456 447
        }
457
        break;
448
        return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED;
449
    }else{
450
        s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->motion_val[xy][0]*time_pb/time_pp + mx;
451
        s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->motion_val[xy][1]*time_pb/time_pp + my;
452
        s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0]
453
                            : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp;
454
        s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] 
455
                            : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp;
456
        if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample)
457
            s->mv_type= MV_TYPE_16X16;
458
        else
459
            s->mv_type= MV_TYPE_8X8;
460
        return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line
458 461
    }
459 462
}
460 463

  
......
496 499
            assert(mb_type>=0);
497 500

  
498 501
            /* nothing to do if this MB was skiped in the next P Frame */
499
            if(s->next_picture.mbskip_table[s->mb_y * s->mb_width + s->mb_x]){ //FIXME avoid DCT & ...
502
            if(s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]){ //FIXME avoid DCT & ...
500 503
                s->skip_count++;
501 504
                s->mv[0][0][0]= 
502 505
                s->mv[0][0][1]= 
......
1890 1893
    ac_val1 = ac_val;
1891 1894
    if (s->ac_pred) {
1892 1895
        if (dir == 0) {
1893
            const int xy= s->mb_x-1 + s->mb_y*s->mb_width;
1896
            const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
1894 1897
            /* left prediction */
1895 1898
            ac_val -= 16;
1896 1899
            
......
1906 1909
                }
1907 1910
            }
1908 1911
        } else {
1909
            const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width;
1912
            const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
1910 1913
            /* top prediction */
1911 1914
            ac_val -= 16 * s->block_wrap[n];
1912 1915

  
......
1946 1949
    ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
1947 1950
 
1948 1951
    if (dir == 0) {
1949
        const int xy= s->mb_x-1 + s->mb_y*s->mb_width;
1952
        const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
1950 1953
        /* left prediction */
1951 1954
        ac_val -= 16;
1952 1955
        if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
......
1961 1964
            }
1962 1965
        }
1963 1966
    } else {
1964
        const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width;
1967
        const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
1965 1968
        /* top prediction */
1966 1969
        ac_val -= 16 * s->block_wrap[n];
1967 1970
        if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
......
2500 2503
        return -1;
2501 2504
    }
2502 2505
    if(s->pict_type == B_TYPE){
2503
        while(s->next_picture.mbskip_table[ mb_num ]) mb_num++;
2506
        while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) mb_num++;
2504 2507
        if(mb_num >= s->mb_num) return -1; // slice contains just skiped MBs which where allready decoded
2505 2508
    }
2506 2509
    
......
2693 2696
    for(; s->mb_y<s->mb_height; s->mb_y++){
2694 2697
        ff_init_block_index(s);
2695 2698
        for(; s->mb_x<s->mb_width; s->mb_x++){
2696
            const int xy= s->mb_x + s->mb_y*s->mb_width;
2699
            const int xy= s->mb_x + s->mb_y*s->mb_stride;
2697 2700
            int cbpc;
2698 2701
            int dir=0;
2699 2702
            
......
2702 2705
            if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1)
2703 2706
                s->first_slice_line=0;
2704 2707
            
2705
            if(s->mb_x==0) PRINT_MB_TYPE("\n");
2706

  
2707 2708
            if(s->pict_type==I_TYPE){
2708 2709
                int i;
2709 2710

  
......
2711 2712
                    return mb_num-1;
2712 2713
                }
2713 2714

  
2714
                PRINT_MB_TYPE("I");
2715 2715
                cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
2716 2716
                if (cbpc < 0){
2717 2717

  
......
2719 2719
                    return -1;
2720 2720
                }
2721 2721
                s->cbp_table[xy]= cbpc & 3;
2722
                s->mb_type[xy]= MB_TYPE_INTRA;
2722
                s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
2723 2723
                s->mb_intra = 1;
2724 2724

  
2725 2725
                if(cbpc & 4) {
......
2751 2751
                skip_bits1(&s->gb);
2752 2752
                if(bits&0x10000){
2753 2753
                    /* skip mb */
2754
                    s->mb_type[xy]= MB_TYPE_SKIPED;
2755 2754
                    if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
2756
                        PRINT_MB_TYPE("G");
2755
                        s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
2757 2756
                        mx= get_amv(s, 0);
2758 2757
                        my= get_amv(s, 1);
2759 2758
                    }else{
2760
                        PRINT_MB_TYPE("S");
2759
                        s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
2761 2760
                        mx=my=0;
2762 2761
                    }
2763 2762
                    mot_val[0       ]= mot_val[2       ]=
......
2783 2782
                s->mb_intra = ((cbpc & 4) != 0);
2784 2783
        
2785 2784
                if(s->mb_intra){
2786
                    PRINT_MB_TYPE("I");
2785
                    s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
2787 2786
                    s->mbintra_table[xy]= 1;
2788
                    s->mb_type[xy]= MB_TYPE_INTRA;
2789 2787
                    mot_val[0       ]= mot_val[2       ]= 
2790 2788
                    mot_val[0+stride]= mot_val[2+stride]= 0;
2791 2789
                    mot_val[1       ]= mot_val[3       ]=
......
2799 2797
                    else s->mcsel= 0;
2800 2798
        
2801 2799
                    if ((cbpc & 16) == 0) {
2802
                        PRINT_MB_TYPE("P");
2803 2800
                        /* 16x16 motion prediction */
2804
                        s->mb_type[xy]= MB_TYPE_INTER;
2805 2801

  
2806 2802
                        h263_pred_motion(s, 0, &pred_x, &pred_y);
2807 2803
                        if(!s->mcsel){
......
2812 2808
                            my = h263_decode_motion(s, pred_y, s->f_code);
2813 2809
                            if (my >= 0xffff)
2814 2810
                                return -1;
2811
                            s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
2815 2812
                        } else {
2816 2813
                            mx = get_amv(s, 0);
2817 2814
                            my = get_amv(s, 1);
2815
                            s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
2818 2816
                        }
2819 2817

  
2820 2818
                        mot_val[0       ]= mot_val[2       ] =
......
2823 2821
                        mot_val[1+stride]= mot_val[3+stride]= my;
2824 2822
                    } else {
2825 2823
                        int i;
2826
                        PRINT_MB_TYPE("4");
2827
                        s->mb_type[xy]= MB_TYPE_INTER4V;
2824
                        s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
2828 2825
                        for(i=0;i<4;i++) {
2829 2826
                            int16_t *mot_val= h263_pred_motion(s, i, &pred_x, &pred_y);
2830 2827
                            mx = h263_decode_motion(s, pred_x, s->f_code);
......
2860 2857
    for(s->mb_y= s->resync_mb_y; mb_num < mb_count; s->mb_y++){
2861 2858
        ff_init_block_index(s);
2862 2859
        for(; mb_num < mb_count && s->mb_x<s->mb_width; s->mb_x++){
2863
            const int xy= s->mb_x + s->mb_y*s->mb_width;
2860
            const int xy= s->mb_x + s->mb_y*s->mb_stride;
2864 2861

  
2865 2862
            mb_num++;
2866 2863
            ff_update_block_index(s);
......
2876 2873
                }
2877 2874
                
2878 2875
                s->cbp_table[xy]|= cbpy<<2;
2879
                s->pred_dir_table[xy]|= ac_pred<<7;
2876
                s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; 
2880 2877
            }else{ /* P || S_TYPE */
2881
                if(s->mb_type[xy]&MB_TYPE_INTRA){          
2878
                if(IS_INTRA(s->current_picture.mb_type[xy])){          
2882 2879
                    int dir=0,i;
2883 2880
                    int ac_pred = get_bits1(&s->gb);
2884 2881
                    int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
......
2905 2902
                    }
2906 2903
                    s->cbp_table[xy]&= 3; //remove dquant
2907 2904
                    s->cbp_table[xy]|= cbpy<<2;
2908
                    s->pred_dir_table[xy]= dir | (ac_pred<<7);
2909
                }else if(s->mb_type[xy]&MB_TYPE_SKIPED){
2905
                    s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; 
2906
                    s->pred_dir_table[xy]= dir;
2907
                }else if(IS_SKIP(s->current_picture.mb_type[xy])){
2910 2908
                    s->current_picture.qscale_table[xy]= s->qscale;
2911 2909
                    s->cbp_table[xy]= 0;
2912 2910
                }else{
......
2989 2987
static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64])
2990 2988
{
2991 2989
    int cbp, mb_type;
2992
    const int xy= s->mb_x + s->mb_y*s->mb_width;
2990
    const int xy= s->mb_x + s->mb_y*s->mb_stride;
2993 2991

  
2994
    mb_type= s->mb_type[xy];
2992
    mb_type= s->current_picture.mb_type[xy];
2995 2993
    cbp = s->cbp_table[xy];
2996 2994

  
2997 2995
    if(s->current_picture.qscale_table[xy] != s->qscale){
......
3006 3004
            s->mv[0][i][0] = s->motion_val[ s->block_index[i] ][0];
3007 3005
            s->mv[0][i][1] = s->motion_val[ s->block_index[i] ][1];
3008 3006
        }
3009
        s->mb_intra = mb_type&MB_TYPE_INTRA;
3007
        s->mb_intra = IS_INTRA(mb_type);
3010 3008

  
3011
        if (mb_type&MB_TYPE_SKIPED) {
3009
        if (IS_SKIP(mb_type)) {
3012 3010
            /* skip mb */
3013 3011
            for(i=0;i<6;i++)
3014 3012
                s->block_last_index[i] = -1;
......
3022 3020
                s->mb_skiped = 1;
3023 3021
            }
3024 3022
        }else if(s->mb_intra){
3025
            s->ac_pred = s->pred_dir_table[xy]>>7;
3023
            s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
3026 3024
        }else if(!s->mb_intra){
3027 3025
//            s->mcsel= 0; //FIXME do we need to init that
3028 3026
            
3029 3027
            s->mv_dir = MV_DIR_FORWARD;
3030
            if (mb_type&MB_TYPE_INTER4V) {
3028
            if (IS_8X8(mb_type)) {
3031 3029
                s->mv_type = MV_TYPE_8X8;
3032 3030
            } else {
3033 3031
                s->mv_type = MV_TYPE_16X16;
......
3035 3033
        }
3036 3034
    } else { /* I-Frame */
3037 3035
        s->mb_intra = 1;
3038
        s->ac_pred = s->pred_dir_table[xy]>>7;
3036
        s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
3039 3037
    }
3040 3038

  
3041
    if (!(mb_type&MB_TYPE_SKIPED)) {
3039
    if (!IS_SKIP(mb_type)) {
3042 3040
        int i;
3043 3041
        /* decode each block */
3044 3042
        for (i = 0; i < 6; i++) {
......
3059 3057
        else
3060 3058
            return SLICE_NOEND;     
3061 3059
    }else{
3062
        if(s->cbp_table[xy+1] && mpeg4_is_resync(s))
3063
            return SLICE_END;
3064
        else
3065
            return SLICE_OK;
3060
        if(mpeg4_is_resync(s)){
3061
            const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
3062
            if(s->cbp_table[xy+delta])
3063
                return SLICE_END;
3064
        }
3065
        return SLICE_OK;
3066 3066
    }
3067 3067
}
3068 3068

  
......
3072 3072
    int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
3073 3073
    int16_t *mot_val;
3074 3074
    static int8_t quant_tab[4] = { -1, -2, 1, 2 };
3075

  
3076
    if(s->mb_x==0) PRINT_MB_TYPE("\n");
3075
    const int xy= s->mb_x + s->mb_y * s->mb_stride;
3077 3076

  
3078 3077
    if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) {
3079 3078
        if (get_bits1(&s->gb)) {
......
3084 3083
            s->mv_dir = MV_DIR_FORWARD;
3085 3084
            s->mv_type = MV_TYPE_16X16;
3086 3085
            if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){
3087
                PRINT_MB_TYPE("G");
3086
                s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
3088 3087
                s->mcsel=1;
3089 3088
                s->mv[0][0][0]= get_amv(s, 0);
3090 3089
                s->mv[0][0][1]= get_amv(s, 1);
3091 3090

  
3092 3091
                s->mb_skiped = 0;
3093 3092
            }else{
3094
                PRINT_MB_TYPE("S");
3093
                s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
3095 3094
                s->mcsel=0;
3096 3095
                s->mv[0][0][0] = 0;
3097 3096
                s->mv[0][0][1] = 0;
......
3126 3125
        s->mv_dir = MV_DIR_FORWARD;
3127 3126
        if ((cbpc & 16) == 0) {
3128 3127
            if(s->mcsel){
3129
                PRINT_MB_TYPE("G");
3128
                s->current_picture.mb_type[xy]= MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
3130 3129
                /* 16x16 global motion prediction */
3131 3130
                s->mv_type = MV_TYPE_16X16;
3132 3131
                mx= get_amv(s, 0);
......
3134 3133
                s->mv[0][0][0] = mx;
3135 3134
                s->mv[0][0][1] = my;
3136 3135
            }else if((!s->progressive_sequence) && get_bits1(&s->gb)){
3137
                PRINT_MB_TYPE("f");
3136
                s->current_picture.mb_type[xy]= MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED; 
3138 3137
                /* 16x8 field motion prediction */
3139 3138
                s->mv_type= MV_TYPE_FIELD;
3140 3139

  
......
3156 3155
                    s->mv[0][i][1] = my;
3157 3156
                }
3158 3157
            }else{
3159
                PRINT_MB_TYPE("P");
3158
                s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; 
3160 3159
                /* 16x16 motion prediction */
3161 3160
                s->mv_type = MV_TYPE_16X16;
3162 3161
                h263_pred_motion(s, 0, &pred_x, &pred_y);
......
3182 3181
                   skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */                   
3183 3182
            }
3184 3183
        } else {
3185
            PRINT_MB_TYPE("4");
3184
            s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; 
3186 3185
            s->mv_type = MV_TYPE_8X8;
3187 3186
            for(i=0;i<4;i++) {
3188 3187
                mot_val = h263_pred_motion(s, i, &pred_x, &pred_y);
......
3225 3224
        }
3226 3225

  
3227 3226
        /* if we skipped it in the future P Frame than skip it now too */
3228
        s->mb_skiped= s->next_picture.mbskip_table[s->mb_y * s->mb_width + s->mb_x]; // Note, skiptab=0 if last was GMC
3227
        s->mb_skiped= s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC
3229 3228

  
3230 3229
        if(s->mb_skiped){
3231 3230
                /* skip mb */
......
3238 3237
            s->mv[0][0][1] = 0;
3239 3238
            s->mv[1][0][0] = 0;
3240 3239
            s->mv[1][0][1] = 0;
3241
            PRINT_MB_TYPE("s");
3240
            s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; 
3242 3241
            goto end;
3243 3242
        }
3244 3243

  
3245 3244
        modb1= get_bits1(&s->gb); 
3246 3245
        if(modb1){
3247
            mb_type=4; //like MB_TYPE_B_DIRECT but no vectors coded
3246
            mb_type= MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1; //like MB_TYPE_B_DIRECT but no vectors coded
3248 3247
            cbp=0;
3249 3248
        }else{
3250
            int field_mv;
3251
        
3252 3249
            modb2= get_bits1(&s->gb);
3253 3250
            mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1);
3251
            if(mb_type<0){
3252
                printf("illegal MB_type\n");
3253
                return -1;
3254
            }
3255
            mb_type= mb_type_b_map[ mb_type ];
3254 3256
            if(modb2) cbp= 0;
3255 3257
            else      cbp= get_bits(&s->gb, 6);
3256 3258

  
3257
            if (mb_type!=MB_TYPE_B_DIRECT && cbp) {
3259
            if ((!IS_DIRECT(mb_type)) && cbp) {
3258 3260
                if(get_bits1(&s->gb)){
3259 3261
                    change_qscale(s, get_bits1(&s->gb)*4 - 2);
3260 3262
                }
3261 3263
            }
3262
            field_mv=0;
3263 3264

  
3264 3265
            if(!s->progressive_sequence){
3265 3266
                if(cbp)
3266 3267
                    s->interlaced_dct= get_bits1(&s->gb);
3267 3268

  
3268
                if(mb_type!=MB_TYPE_B_DIRECT && get_bits1(&s->gb)){
3269
                    field_mv=1;
3269
                if(!IS_DIRECT(mb_type) && get_bits1(&s->gb)){
3270
                    mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
3271
                    mb_type &= ~MB_TYPE_16x16;
3270 3272

  
3271
                    if(mb_type!=MB_TYPE_B_BACKW){
3273
                    if(USES_LIST(mb_type, 0)){
3272 3274
                        s->field_select[0][0]= get_bits1(&s->gb);
3273 3275
                        s->field_select[0][1]= get_bits1(&s->gb);
3274 3276
                    }
3275
                    if(mb_type!=MB_TYPE_B_FORW){
3277
                    if(USES_LIST(mb_type, 1)){
3276 3278
                        s->field_select[1][0]= get_bits1(&s->gb);
3277 3279
                        s->field_select[1][1]= get_bits1(&s->gb);
3278 3280
                    }
......
3280 3282
            }
3281 3283

  
3282 3284
            s->mv_dir = 0;
3283
            if(mb_type!=MB_TYPE_B_DIRECT && !field_mv){
3285
            if((mb_type & (MB_TYPE_DIRECT2|MB_TYPE_INTERLACED)) == 0){
3284 3286
                s->mv_type= MV_TYPE_16X16;
3285
                if(mb_type!=MB_TYPE_B_BACKW){
3287

  
3288
                if(USES_LIST(mb_type, 0)){
3286 3289
                    s->mv_dir = MV_DIR_FORWARD;
3287 3290

  
3288 3291
                    mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);
......
3291 3294
                    s->last_mv[0][1][1]= s->last_mv[0][0][1]= s->mv[0][0][1] = my;
3292 3295
                }
3293 3296
    
3294
                if(mb_type!=MB_TYPE_B_FORW){
3297
                if(USES_LIST(mb_type, 1)){
3295 3298
                    s->mv_dir |= MV_DIR_BACKWARD;
3296 3299

  
3297 3300
                    mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);
......
3299 3302
                    s->last_mv[1][1][0]= s->last_mv[1][0][0]= s->mv[1][0][0] = mx;
3300 3303
                    s->last_mv[1][1][1]= s->last_mv[1][0][1]= s->mv[1][0][1] = my;
3301 3304
                }
3302
                if(mb_type!=MB_TYPE_B_DIRECT)
3303
                    PRINT_MB_TYPE(mb_type==MB_TYPE_B_FORW ? "F" : (mb_type==MB_TYPE_B_BACKW ? "B" : "T"));
3304
            }else if(mb_type!=MB_TYPE_B_DIRECT){
3305
            }else if(!IS_DIRECT(mb_type)){
3305 3306
                s->mv_type= MV_TYPE_FIELD;
3306 3307

  
3307
                if(mb_type!=MB_TYPE_B_BACKW){
3308
                if(USES_LIST(mb_type, 0)){
3308 3309
                    s->mv_dir = MV_DIR_FORWARD;
3309 3310
                
3310 3311
                    for(i=0; i<2; i++){
......
3315 3316
                    }
3316 3317
                }
3317 3318
    
3318
                if(mb_type!=MB_TYPE_B_FORW){
3319
                if(USES_LIST(mb_type, 1)){
3319 3320
                    s->mv_dir |= MV_DIR_BACKWARD;
3320 3321

  
3321 3322
                    for(i=0; i<2; i++){
......
3325 3326
                        s->last_mv[1][i][1]= (s->mv[1][i][1] = my)*2;
3326 3327
                    }
3327 3328
                }
3328
                if(mb_type!=MB_TYPE_B_DIRECT)
3329
                    PRINT_MB_TYPE(mb_type==MB_TYPE_B_FORW ? "f" : (mb_type==MB_TYPE_B_BACKW ? "b" : "t"));
3330 3329
            }
3331 3330
        }
3332 3331
          
3333
        if(mb_type==4 || mb_type==MB_TYPE_B_DIRECT){
3334
            if(mb_type==4)
3332
        if(IS_DIRECT(mb_type)){
3333
            if(IS_SKIP(mb_type))
3335 3334
                mx=my=0;
3336 3335
            else{
3337 3336
                mx = h263_decode_motion(s, 0, 1);
......
3339 3338
            }
3340 3339
 
3341 3340
            s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
3342
            ff_mpeg4_set_direct_mv(s, mx, my);
3343
        }
3344
        
3345
        if(mb_type<0 || mb_type>4){
3346
            printf("illegal MB_type\n");
3347
            return -1;
3341
            mb_type |= ff_mpeg4_set_direct_mv(s, mx, my);
3348 3342
        }
3343
        s->current_picture.mb_type[xy]= mb_type;
3349 3344
    } else { /* I-Frame */
3350 3345
        cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
3351 3346
        if (cbpc < 0)
......
3353 3348
        dquant = cbpc & 4;
3354 3349
        s->mb_intra = 1;
3355 3350
intra:
3356
        s->ac_pred = 0;
3351
        s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
3357 3352
        if (s->h263_pred || s->h263_aic) {
3358 3353
            s->ac_pred = get_bits1(&s->gb);
3359
            if (s->ac_pred && s->h263_aic)
3360
                s->h263_aic_dir = get_bits1(&s->gb);
3361
        }
3362
        PRINT_MB_TYPE(s->ac_pred ? "A" : "I");
3354
            if(s->ac_pred){
3355
                s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED;
3356
            
3357
                if (s->h263_aic)
3358
                    s->h263_aic_dir = get_bits1(&s->gb);
3359
            }
3360
        }else
3361
            s->ac_pred = 0;
3363 3362
        
3364 3363
        cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
3365 3364
        if(cbpy<0) return -1;
......
3407 3406
        /* per-MB end of slice check */
3408 3407
    if(s->codec_id==CODEC_ID_MPEG4){
3409 3408
        if(mpeg4_is_resync(s)){
3410
            if(s->pict_type==B_TYPE && s->next_picture.mbskip_table[s->mb_y * s->mb_width + s->mb_x+1])
3409
            const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
3410
            if(s->pict_type==B_TYPE && s->next_picture.mbskip_table[xy + delta])
3411 3411
                return SLICE_OK;
3412 3412
            return SLICE_END;
3413 3413
        }
......
3429 3429
{
3430 3430
    int code, val, sign, shift, l;
3431 3431
    code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
3432
    if (code < 0)
3433
        return 0xffff;
3434 3432

  
3435 3433
    if (code == 0)
3436 3434
        return pred;
3435
    if (code < 0)
3436
        return 0xffff;
3437 3437

  
3438 3438
    sign = get_bits1(&s->gb);
3439 3439
    shift = f_code - 1;
......
3676 3676
            level = s->dc_val[0][ s->block_index[n] ];
3677 3677
            if(n<4) level= (level + (s->y_dc_scale>>1))/s->y_dc_scale; //FIXME optimizs
3678 3678
            else    level= (level + (s->c_dc_scale>>1))/s->c_dc_scale;
3679
            dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_width]<<n)&32;
3679
            dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<<n)&32;
3680 3680
        }else{
3681 3681
            level = mpeg4_decode_dc(s, n, &dc_pred_dir);
3682 3682
            if (level < 0)

Also available in: Unified diff