Revision 7bc9090a

View differences:

libavcodec/common.h
999 999
#define free please_use_av_free
1000 1000
#define realloc please_use_av_realloc
1001 1001

  
1002
#define CHECKED_ALLOCZ(p, size)\
1003
{\
1004
    p= av_mallocz(size);\
1005
    if(p==NULL){\
1006
        perror("malloc");\
1007
        goto fail;\
1008
    }\
1009
}
1010

  
1002 1011
#endif /* HAVE_AV_CONFIG_H */
1003 1012

  
1004 1013
#endif /* COMMON_H */
libavcodec/error_resilience.c
23 23
 * Error resilience / concealment.
24 24
 */
25 25

  
26
#include <limits.h>
27
 
26 28
#include "avcodec.h"
27 29
#include "dsputil.h"
28 30
#include "mpegvideo.h"
......
111 113
            int mb_index, error, j;
112 114
            int64_t guess, weight_sum;
113 115
            
114
            mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_width;
116
            mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;
115 117
            
116 118
            error= s->error_status_table[mb_index];
117 119
            
118
            if(!(s->mb_type[mb_index]&MB_TYPE_INTRA)) continue; //inter
120
            if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
119 121
            if(!(error&DC_ERROR)) continue;           //dc-ok
120 122
            
121 123
            /* right block */
122 124
            for(j=b_x+1; j<w; j++){
123
                int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_width;
125
                int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
124 126
                int error_j= s->error_status_table[mb_index_j];
125
                int intra_j= s->mb_type[mb_index_j]&MB_TYPE_INTRA;
127
                int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
126 128
                if(intra_j==0 || !(error_j&DC_ERROR)){
127 129
                    color[0]= dc[j + b_y*stride];
128 130
                    distance[0]= j-b_x;
......
132 134
            
133 135
            /* left block */
134 136
            for(j=b_x-1; j>=0; j--){
135
                int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_width;
137
                int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
136 138
                int error_j= s->error_status_table[mb_index_j];
137
                int intra_j= s->mb_type[mb_index_j]&MB_TYPE_INTRA;
139
                int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
138 140
                if(intra_j==0 || !(error_j&DC_ERROR)){
139 141
                    color[1]= dc[j + b_y*stride];
140 142
                    distance[1]= b_x-j;
......
144 146

  
145 147
            /* bottom block */
146 148
            for(j=b_y+1; j<h; j++){
147
                int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_width;
149
                int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
148 150
                int error_j= s->error_status_table[mb_index_j];
149
                int intra_j= s->mb_type[mb_index_j]&MB_TYPE_INTRA;
151
                int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
150 152
                if(intra_j==0 || !(error_j&DC_ERROR)){
151 153
                    color[2]= dc[b_x + j*stride];
152 154
                    distance[2]= j-b_y;
......
156 158

  
157 159
            /* top block */
158 160
            for(j=b_y-1; j>=0; j--){
159
                int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_width;
161
                int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
160 162
                int error_j= s->error_status_table[mb_index_j];
161
                int intra_j= s->mb_type[mb_index_j]&MB_TYPE_INTRA;
163
                int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
162 164
                if(intra_j==0 || !(error_j&DC_ERROR)){
163 165
                    color[3]= dc[b_x + j*stride];
164 166
                    distance[3]= b_y-j;
......
192 194
    for(b_y=0; b_y<h; b_y++){
193 195
        for(b_x=0; b_x<w-1; b_x++){
194 196
            int y;
195
            int left_status = s->error_status_table[( b_x   >>is_luma) + (b_y>>is_luma)*s->mb_width];
196
            int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_width];
197
            int left_intra=   s->mb_type      [( b_x   >>is_luma) + (b_y>>is_luma)*s->mb_width]&MB_TYPE_INTRA;
198
            int right_intra=  s->mb_type      [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_width]&MB_TYPE_INTRA;
197
            int left_status = s->error_status_table[( b_x   >>is_luma) + (b_y>>is_luma)*s->mb_stride];
198
            int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
199
            int left_intra=   IS_INTRA(s->current_picture.mb_type      [( b_x   >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
200
            int right_intra=  IS_INTRA(s->current_picture.mb_type      [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
199 201
            int left_damage =  left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
200 202
            int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
201 203
            int offset= b_x*8 + b_y*stride*8;
......
252 254
    for(b_y=0; b_y<h-1; b_y++){
253 255
        for(b_x=0; b_x<w; b_x++){
254 256
            int x;
255
            int top_status   = s->error_status_table[(b_x>>is_luma) + ( b_y   >>is_luma)*s->mb_width];
256
            int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_width];
257
            int top_intra=     s->mb_type      [(b_x>>is_luma) + ( b_y   >>is_luma)*s->mb_width]&MB_TYPE_INTRA;
258
            int bottom_intra=  s->mb_type      [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_width]&MB_TYPE_INTRA;
257
            int top_status   = s->error_status_table[(b_x>>is_luma) + ( b_y   >>is_luma)*s->mb_stride];
258
            int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
259
            int top_intra=     IS_INTRA(s->current_picture.mb_type      [(b_x>>is_luma) + ( b_y   >>is_luma)*s->mb_stride]);
260
            int bottom_intra=  IS_INTRA(s->current_picture.mb_type      [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
259 261
            int top_damage =      top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
260 262
            int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
261 263
            int offset= b_x*8 + b_y*stride*8;
......
301 303
}
302 304

  
303 305
static void guess_mv(MpegEncContext *s){
304
    uint8_t fixed[s->mb_num];
306
    uint8_t fixed[s->mb_stride * s->mb_height];
305 307
#define MV_FROZEN    3
306 308
#define MV_CHANGED   2
307 309
#define MV_UNCHANGED 1
310
    const int mb_stride = s->mb_stride;
308 311
    const int mb_width = s->mb_width;
309 312
    const int mb_height= s->mb_height;
310 313
    int i, depth, num_avail;
314
    int mb_x, mb_y;
311 315
   
312 316
    num_avail=0;
313 317
    for(i=0; i<s->mb_num; i++){
318
        const int mb_xy= s->mb_index2xy[ i ];
314 319
        int f=0;
315
        int error= s->error_status_table[i];
320
        int error= s->error_status_table[mb_xy];
316 321

  
317
        if(s->mb_type[i]&MB_TYPE_INTRA) f=MV_FROZEN; //intra //FIXME check
322
        if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
318 323
        if(!(error&MV_ERROR)) f=MV_FROZEN;           //inter with undamaged MV
319 324
        
320
        fixed[i]= f;
325
        fixed[mb_xy]= f;
321 326
        if(f==MV_FROZEN)
322 327
            num_avail++;
323 328
    }
324 329
    
325 330
    if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){
326
        int mb_x, mb_y;
327
        i= -1;
328 331
        for(mb_y=0; mb_y<s->mb_height; mb_y++){
329 332
            for(mb_x=0; mb_x<s->mb_width; mb_x++){
330
                i++;
333
                const int mb_xy= mb_x + mb_y*s->mb_stride;
331 334
                
332
                if(s->mb_type[i]&MB_TYPE_INTRA) continue;
333
                if(!(s->error_status_table[i]&MV_ERROR)) continue;
335
                if(IS_INTRA(s->current_picture.mb_type[mb_xy]))  continue;
336
                if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
334 337

  
335 338
                s->mv_dir = MV_DIR_FORWARD;
336 339
                s->mb_intra=0;
......
355 358
        none_left=1;
356 359
        changed=1;
357 360
        for(pass=0; (changed || pass<2) && pass<10; pass++){
358
            int i,mb_x, mb_y;
361
            int mb_x, mb_y;
359 362
int score_sum=0;
360 363
 
361 364
            changed=0;
362
            i= -1;
363 365
            for(mb_y=0; mb_y<s->mb_height; mb_y++){
364 366
                for(mb_x=0; mb_x<s->mb_width; mb_x++){
367
                    const int mb_xy= mb_x + mb_y*s->mb_stride;
365 368
                    int mv_predictor[8][2]={{0}};
366 369
                    int pred_count=0;
367 370
                    int j;
......
372 375
                    int prev_x= s->motion_val[mot_index][0];
373 376
                    int prev_y= s->motion_val[mot_index][1];
374 377

  
375
                    i++;
376 378
                    if((mb_x^mb_y^pass)&1) continue;
377 379
                    
378
                    if(fixed[i]==MV_FROZEN) continue;
380
                    if(fixed[mb_xy]==MV_FROZEN) continue;
381
                    assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
382
                    assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
379 383
                    
380 384
                    j=0;
381
                    if(mb_x>0           && fixed[i-1       ]==MV_FROZEN) j=1;
382
                    if(mb_x+1<mb_width  && fixed[i+1       ]==MV_FROZEN) j=1;
383
                    if(mb_y>0           && fixed[i-mb_width]==MV_FROZEN) j=1;
384
                    if(mb_y+1<mb_height && fixed[i+mb_width]==MV_FROZEN) j=1;
385
                    if(mb_x>0           && fixed[mb_xy-1        ]==MV_FROZEN) j=1;
386
                    if(mb_x+1<mb_width  && fixed[mb_xy+1        ]==MV_FROZEN) j=1;
387
                    if(mb_y>0           && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;
388
                    if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;
385 389
                    if(j==0) continue;
386 390

  
387 391
                    j=0;
388
                    if(mb_x>0           && fixed[i-1       ]==MV_CHANGED) j=1;
389
                    if(mb_x+1<mb_width  && fixed[i+1       ]==MV_CHANGED) j=1;
390
                    if(mb_y>0           && fixed[i-mb_width]==MV_CHANGED) j=1;
391
                    if(mb_y+1<mb_height && fixed[i+mb_width]==MV_CHANGED) j=1;
392
                    if(mb_x>0           && fixed[mb_xy-1        ]==MV_CHANGED) j=1;
393
                    if(mb_x+1<mb_width  && fixed[mb_xy+1        ]==MV_CHANGED) j=1;
394
                    if(mb_y>0           && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;
395
                    if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;
392 396
                    if(j==0 && pass>1) continue;
393 397
                    
394 398
                    none_left=0;
395 399
                    
396
                    if(mb_x>0 && fixed[i-1]){
400
                    if(mb_x>0 && fixed[mb_xy-1]){
397 401
                        mv_predictor[pred_count][0]= s->motion_val[mot_index - 2][0];
398 402
                        mv_predictor[pred_count][1]= s->motion_val[mot_index - 2][1];
399 403
                        pred_count++;
400 404
                    }
401
                    if(mb_x+1<mb_width && fixed[i+1]){
405
                    if(mb_x+1<mb_width && fixed[mb_xy+1]){
402 406
                        mv_predictor[pred_count][0]= s->motion_val[mot_index + 2][0];
403 407
                        mv_predictor[pred_count][1]= s->motion_val[mot_index + 2][1];
404 408
                        pred_count++;
405 409
                    }
406
                    if(mb_y>0 && fixed[i-mb_width]){
410
                    if(mb_y>0 && fixed[mb_xy-mb_stride]){
407 411
                        mv_predictor[pred_count][0]= s->motion_val[mot_index - mot_stride*2][0];
408 412
                        mv_predictor[pred_count][1]= s->motion_val[mot_index - mot_stride*2][1];
409 413
                        pred_count++;
410 414
                    }
411
                    if(mb_y+1<mb_height && fixed[i+mb_width]){
415
                    if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
412 416
                        mv_predictor[pred_count][0]= s->motion_val[mot_index + mot_stride*2][0];
413 417
                        mv_predictor[pred_count][1]= s->motion_val[mot_index + mot_stride*2][1];
414 418
                        pred_count++;
......
468 472

  
469 473
                    s->mb_x= mb_x;
470 474
                    s->mb_y= mb_y;
475

  
471 476
                    for(j=0; j<pred_count; j++){
472 477
                        int score=0;
473 478
                        uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
474 479

  
475 480
                        s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
476 481
                        s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
482

  
477 483
                        MPV_decode_mb(s, s->block);
478 484
                        
479
                        if(mb_x>0 && fixed[i-1]){
485
                        if(mb_x>0 && fixed[mb_xy-1]){
480 486
                            int k;
481 487
                            for(k=0; k<16; k++)
482 488
                                score += ABS(src[k*s->linesize-1 ]-src[k*s->linesize   ]);
483 489
                        }
484
                        if(mb_x+1<mb_width && fixed[i+1]){
490
                        if(mb_x+1<mb_width && fixed[mb_xy+1]){
485 491
                            int k;
486 492
                            for(k=0; k<16; k++)
487 493
                                score += ABS(src[k*s->linesize+15]-src[k*s->linesize+16]);
488 494
                        }
489
                        if(mb_y>0 && fixed[i-mb_width]){
495
                        if(mb_y>0 && fixed[mb_xy-mb_stride]){
490 496
                            int k;
491 497
                            for(k=0; k<16; k++)
492 498
                                score += ABS(src[k-s->linesize   ]-src[k               ]);
493 499
                        }
494
                        if(mb_y+1<mb_height && fixed[i+mb_width]){
500
                        if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
495 501
                            int k;
496 502
                            for(k=0; k<16; k++)
497 503
                                score += ABS(src[k+s->linesize*15]-src[k+s->linesize*16]);
......
511 517

  
512 518
                    
513 519
                    if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){
514
                        fixed[i]=MV_CHANGED;
520
                        fixed[mb_xy]=MV_CHANGED;
515 521
                        changed++;
516 522
                    }else
517
                        fixed[i]=MV_UNCHANGED;
523
                        fixed[mb_xy]=MV_UNCHANGED;
518 524
                }
519 525
            }
520 526

  
......
525 531
            return;
526 532
            
527 533
        for(i=0; i<s->mb_num; i++){
528
            if(fixed[i])
529
                fixed[i]=MV_FROZEN;
534
            int mb_xy= s->mb_index2xy[i];
535
            if(fixed[mb_xy])
536
                fixed[mb_xy]=MV_FROZEN;
530 537
        }
531 538
//        printf(":"); fflush(stdout);
532 539
    }
......
539 546

  
540 547
    undamaged_count=0;
541 548
    for(i=0; i<s->mb_num; i++){
542
        int error= s->error_status_table[i];
549
        const int mb_xy= s->mb_index2xy[i];
550
        const int error= s->error_status_table[mb_xy];
543 551
        if(!((error&DC_ERROR) && (error&MV_ERROR)))
544 552
            undamaged_count++;
545 553
    }
......
550 558
    is_intra_likely=0;
551 559

  
552 560
    j=0;
553
    i=-1;
554 561
    for(mb_y= 0; mb_y<s->mb_height-1; mb_y++){
555 562
        for(mb_x= 0; mb_x<s->mb_width; mb_x++){
556 563
            int error;
564
            const int mb_xy= mb_x + mb_y*s->mb_stride;
557 565

  
558
            i++;
559
            error= s->error_status_table[i];
566
            error= s->error_status_table[mb_xy];
560 567
            if((error&DC_ERROR) && (error&MV_ERROR))
561 568
                continue; //skip damaged
562 569
        
......
570 577
		is_intra_likely += s->dsp.pix_abs16x16(last_mb_ptr, mb_ptr                    , s->linesize);
571 578
                is_intra_likely -= s->dsp.pix_abs16x16(last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize);
572 579
            }else{
573
                if(s->mbintra_table[i]) //HACK (this is allways inited but we should use mb_type[])
580
                if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
574 581
                   is_intra_likely++;
575 582
                else
576 583
                   is_intra_likely--;
......
584 591
void ff_er_frame_start(MpegEncContext *s){
585 592
    if(!s->error_resilience) return;
586 593

  
587
    memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_num*sizeof(uint8_t));
594
    memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
595
    s->error_count= 3*s->mb_num;
588 596
}
589 597

  
590 598
/**
......
594 602
 *               error of the same type occured
595 603
 */
596 604
void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){
597
    const int start_xy= clip(startx + starty * s->mb_width, 0, s->mb_num-1);
598
    const int end_xy  = clip(endx   + endy   * s->mb_width, 0, s->mb_num);
599
    const int mb_count= end_xy - start_xy;
605
    const int start_i= clip(startx + starty * s->mb_width    , 0, s->mb_num-1);
606
    const int end_i  = clip(endx   + endy   * s->mb_width    , 0, s->mb_num);
607
    const int start_xy= s->mb_index2xy[start_i];
608
    const int end_xy  = s->mb_index2xy[end_i];
600 609
    int mask= -1;
601 610
    
602 611
    if(!s->error_resilience) return;
603 612

  
604 613
    mask &= ~VP_START;
605
    if(status & (AC_ERROR|AC_END)) mask &= ~(AC_ERROR|AC_END);
606
    if(status & (DC_ERROR|DC_END)) mask &= ~(DC_ERROR|DC_END);
607
    if(status & (MV_ERROR|MV_END)) mask &= ~(MV_ERROR|MV_END);    
614
    if(status & (AC_ERROR|AC_END)){
615
        mask &= ~(AC_ERROR|AC_END);
616
        s->error_count -= end_i - start_i + 1;
617
    }
618
    if(status & (DC_ERROR|DC_END)){
619
        mask &= ~(DC_ERROR|DC_END);
620
        s->error_count -= end_i - start_i + 1;
621
    }
622
    if(status & (MV_ERROR|MV_END)){
623
        mask &= ~(MV_ERROR|MV_END);
624
        s->error_count -= end_i - start_i + 1;
625
    }
626

  
627
    if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX;
608 628

  
609 629
    if(mask == ~0x7F){
610
        memset(&s->error_status_table[start_xy], 0, mb_count * sizeof(uint8_t));
630
        memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t));
611 631
    }else{
612 632
        int i;
613 633
        for(i=start_xy; i<end_xy; i++){
614
            s->error_status_table[i] &= mask;
634
            s->error_status_table[ i ] &= mask;
615 635
        }
616 636
    }
617
   
618
    if(end_xy < s->mb_num){
637

  
638
    if(end_i == s->mb_num) 
639
        s->error_count= INT_MAX;
640
    else{
619 641
        s->error_status_table[end_xy] &= mask;
620 642
        s->error_status_table[end_xy] |= status;
621 643
    }
622 644
 
623 645
    s->error_status_table[start_xy] |= VP_START;
646

  
647
    if(start_xy > 0){
648
        int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
649
        
650
        prev_status &= ~ VP_START;
651
        if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX;
652
    }
624 653
}
625 654

  
626 655
void ff_er_frame_end(MpegEncContext *s){
......
629 658
    int threshold_part[4]= {100,100,100};
630 659
    int threshold= 50;
631 660
    int is_intra_likely;
632
    int num_end_markers=0;
633 661
    
634
    if(!s->error_resilience) return;
662
    if(!s->error_resilience || s->error_count==0) return;
635 663

  
636
    error=0;
637
    for(i=0; i<s->mb_num; i++){
638
        int status= s->error_status_table[i];
664
    fprintf(stderr, "concealing errors\n");
665
    
666
    if(s->motion_val == NULL){
667
        int size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
639 668
        
640
        if(status==0) continue;
641

  
642
        if(status&(DC_ERROR|AC_ERROR|MV_ERROR))
643
            error=1;
644
        if(status&VP_START){
645
            if(num_end_markers) 
646
                error=1;
647
            num_end_markers=3;
648
        }
649
        if(status&AC_END)
650
            num_end_markers--;
651
        if(status&DC_END)
652
            num_end_markers--;
653
        if(status&MV_END)
654
            num_end_markers--;
669
        fprintf(stderr, "Warning MVs not available\n");
670
        
671
        s->motion_val= av_mallocz(size * 2 * sizeof(int16_t));
655 672
    }
656
    if(num_end_markers==0 && error==0)
657
        return;
658

  
659
    fprintf(stderr, "concealing errors\n");
660

  
661
    if(s->avctx->debug&FF_DEBUG_ER){    
662
        for(i=0; i<s->mb_num; i++){
663
            int status= s->error_status_table[i];
673
    
674
    if(s->avctx->debug&FF_DEBUG_ER){
675
        for(mb_y=0; mb_y<s->mb_height; mb_y++){
676
            for(mb_x=0; mb_x<s->mb_width; mb_x++){
677
                int status= s->error_status_table[mb_x + mb_y*s->mb_stride];
664 678
            
665
            if(i%s->mb_width == 0) printf("\n");
666
            printf("%2X ", status); 
679
                printf("%2X ", status); 
680
            }
681
            printf("\n");
667 682
        }
668 683
    }
669 684
    
......
673 688
        int end_ok=0;
674 689

  
675 690
        for(i=s->mb_num-1; i>=0; i--){
676
            int error= s->error_status_table[i];
691
            const int mb_xy= s->mb_index2xy[i];
692
            int error= s->error_status_table[mb_xy];
677 693
        
678 694
            if(error&(1<<error_type))
679 695
                end_ok=1;
......
681 697
                end_ok=1;
682 698

  
683 699
            if(!end_ok)
684
                s->error_status_table[i]|= 1<<error_type;
700
                s->error_status_table[mb_xy]|= 1<<error_type;
685 701

  
686 702
            if(error&VP_START)
687 703
                end_ok=0;
......
694 710
        int end_ok=0;
695 711

  
696 712
        for(i=s->mb_num-1; i>=0; i--){
697
            int error= s->error_status_table[i];
713
            const int mb_xy= s->mb_index2xy[i];
714
            int error= s->error_status_table[mb_xy];
698 715
        
699 716
            if(error&AC_END)
700 717
                end_ok=0;
......
702 719
                end_ok=1;
703 720

  
704 721
            if(!end_ok)
705
                s->error_status_table[i]|= AC_ERROR;
722
                s->error_status_table[mb_xy]|= AC_ERROR;
706 723

  
707 724
            if(error&VP_START)
708 725
                end_ok=0;
......
714 731
        int end_ok=1;
715 732
                
716 733
        for(i=s->mb_num-2; i>=s->mb_width+100; i--){ //FIXME +100 hack
717
            int error1= s->error_status_table[i  ];
718
            int error2= s->error_status_table[i+1];
734
            const int mb_xy= s->mb_index2xy[i];
735
            int error1= s->error_status_table[mb_xy  ];
736
            int error2= s->error_status_table[mb_xy+1];
719 737
        
720 738
            if(error1&VP_START)
721 739
                end_ok=1;
......
727 745
            }
728 746
        
729 747
            if(!end_ok)
730
                s->error_status_table[i]|= DC_ERROR|AC_ERROR|MV_ERROR;
748
                s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;
731 749
        }
732 750
    }
733 751
    
......
736 754
    distance=9999999;
737 755
    for(error_type=1; error_type<=3; error_type++){
738 756
        for(i=s->mb_num-1; i>=0; i--){
739
            int error= s->error_status_table[i];
757
            const int mb_xy= s->mb_index2xy[i];
758
            int error= s->error_status_table[mb_xy];
740 759
            
741
            if(!s->mbskip_table[i]) //FIXME partition specific
760
            if(!s->mbskip_table[mb_xy]) //FIXME partition specific
742 761
                distance++;            
743 762
            if(error&(1<<error_type))
744 763
                distance= 0;
745 764

  
746 765
            if(s->partitioned_frame){
747 766
                if(distance < threshold_part[error_type-1])
748
                    s->error_status_table[i]|= 1<<error_type;
767
                    s->error_status_table[mb_xy]|= 1<<error_type;
749 768
            }else{
750 769
                if(distance < threshold)
751
                    s->error_status_table[i]|= 1<<error_type;
770
                    s->error_status_table[mb_xy]|= 1<<error_type;
752 771
            }
753 772

  
754 773
            if(error&VP_START)
......
760 779
    /* forward mark errors */
761 780
    error=0;
762 781
    for(i=0; i<s->mb_num; i++){
763
        int old_error= s->error_status_table[i];
782
        const int mb_xy= s->mb_index2xy[i];
783
        int old_error= s->error_status_table[mb_xy];
764 784
        
765 785
        if(old_error&VP_START)
766 786
            error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
767 787
        else{
768 788
            error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
769
            s->error_status_table[i]|= error;
789
            s->error_status_table[mb_xy]|= error;
770 790
        }
771 791
    }
772 792
#if 1
773 793
    /* handle not partitioned case */
774 794
    if(!s->partitioned_frame){
775 795
        for(i=0; i<s->mb_num; i++){
776
            error= s->error_status_table[i];
796
            const int mb_xy= s->mb_index2xy[i];
797
            error= s->error_status_table[mb_xy];
777 798
            if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
778 799
                error|= AC_ERROR|DC_ERROR|MV_ERROR;
779
            s->error_status_table[i]= error;
800
            s->error_status_table[mb_xy]= error;
780 801
        }
781 802
    }
782 803
#endif
......
784 805

  
785 806
    /* set unknown mb-type to most likely */
786 807
    for(i=0; i<s->mb_num; i++){
787
        int intra;
788
        error= s->error_status_table[i];
789
        if((error&DC_ERROR) && (error&MV_ERROR))
790
            intra= is_intra_likely;
791
        else
792
            intra= s->mbintra_table[i];
808
        const int mb_xy= s->mb_index2xy[i];
809
        error= s->error_status_table[mb_xy];
810
        if(!((error&DC_ERROR) && (error&MV_ERROR)))
811
            continue;
793 812

  
794
        if(intra)
795
            s->mb_type[i]|= MB_TYPE_INTRA;
813
        if(is_intra_likely)
814
            s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
796 815
        else
797
            s->mb_type[i]&= ~MB_TYPE_INTRA;
816
            s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
798 817
    }
799 818
    
800 819
    /* handle inter blocks with damaged AC */
801
    i= -1;
802 820
    for(mb_y=0; mb_y<s->mb_height; mb_y++){
803 821
        for(mb_x=0; mb_x<s->mb_width; mb_x++){
804
            i++;
805
            error= s->error_status_table[i];
822
            const int mb_xy= mb_x + mb_y * s->mb_stride;
823
            const int mb_type= s->current_picture.mb_type[mb_xy];
824
            error= s->error_status_table[mb_xy];
806 825

  
807
            if(s->mb_type[i]&MB_TYPE_INTRA) continue; //intra
826
            if(IS_INTRA(mb_type)) continue; //intra
808 827
            if(error&MV_ERROR) continue;              //inter with damaged MV
809 828
            if(!(error&AC_ERROR)) continue;           //undamaged inter
810 829
            
811 830
            s->mv_dir = MV_DIR_FORWARD;
812 831
            s->mb_intra=0;
813 832
            s->mb_skiped=0;
814
            if(s->mb_type[i]&MB_TYPE_INTER4V){
833
            if(IS_8X8(mb_type)){
815 834
                int mb_index= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0];
816 835
                int j;
817 836
                s->mv_type = MV_TYPE_8X8;
......
835 854

  
836 855
    /* guess MVs */
837 856
    if(s->pict_type==B_TYPE){
838
        i= -1;
839 857
        for(mb_y=0; mb_y<s->mb_height; mb_y++){
840 858
            for(mb_x=0; mb_x<s->mb_width; mb_x++){
841 859
                int xy= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0];
842
                i++;
843
                error= s->error_status_table[i];
860
                const int mb_xy= mb_x + mb_y * s->mb_stride;
861
                const int mb_type= s->current_picture.mb_type[mb_xy];
862
                error= s->error_status_table[mb_xy];
844 863

  
845
                if(s->mb_type[i]&MB_TYPE_INTRA) continue; //intra
864
                if(IS_INTRA(mb_type)) continue;
846 865
                if(!(error&MV_ERROR)) continue;           //inter with undamaged MV
847 866
                if(!(error&AC_ERROR)) continue;           //undamaged inter
848 867
            
......
876 895
        guess_mv(s);
877 896

  
878 897
    /* fill DC for inter blocks */
879
    i= -1;
880 898
    for(mb_y=0; mb_y<s->mb_height; mb_y++){
881 899
        for(mb_x=0; mb_x<s->mb_width; mb_x++){
882 900
            int dc, dcu, dcv, y, n;
883 901
            int16_t *dc_ptr;
884 902
            uint8_t *dest_y, *dest_cb, *dest_cr;
903
            const int mb_xy= mb_x + mb_y * s->mb_stride;
904
            const int mb_type= s->current_picture.mb_type[mb_xy];
885 905
           
886
            i++;
887
            error= s->error_status_table[i];
906
            error= s->error_status_table[mb_xy];
888 907

  
889
            if(s->mb_type[i]&MB_TYPE_INTRA) continue; //intra
908
            if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
890 909
//            if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
891 910
            
892 911
            dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
......
928 947
    
929 948
#if 1
930 949
    /* render DC only intra */
931
    i= -1;
932 950
    for(mb_y=0; mb_y<s->mb_height; mb_y++){
933 951
        for(mb_x=0; mb_x<s->mb_width; mb_x++){
934 952
            uint8_t *dest_y, *dest_cb, *dest_cr;
935
           
936
            i++;
937
            error= s->error_status_table[i];
953
            const int mb_xy= mb_x + mb_y * s->mb_stride;
954
            const int mb_type= s->current_picture.mb_type[mb_xy];
955

  
956
            error= s->error_status_table[mb_xy];
938 957

  
939
            if(!(s->mb_type[i]&MB_TYPE_INTRA)) continue; //inter
958
            if(IS_INTER(mb_type)) continue;
940 959
            if(!(error&AC_ERROR)) continue;              //undamaged
941 960
            
942 961
            dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
......
962 981

  
963 982
    /* clean a few tables */
964 983
    for(i=0; i<s->mb_num; i++){
965
        int error= s->error_status_table[i];
984
        const int mb_xy= s->mb_index2xy[i];
985
        int error= s->error_status_table[mb_xy];
966 986
        
967 987
        if(s->pict_type!=B_TYPE && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){
968
            s->mbskip_table[i]=0;
988
            s->mbskip_table[mb_xy]=0;
969 989
        }
970
        s->mbintra_table[i]=1;
990
        s->mbintra_table[mb_xy]=1;
971 991
    }    
972 992
}
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)
libavcodec/h263dec.c
209 209
            MPV_decode_mb(s, s->block);
210 210

  
211 211
            if(ret<0){
212
                const int xy= s->mb_x + s->mb_y*s->mb_width;
212
                const int xy= s->mb_x + s->mb_y*s->mb_stride;
213 213
                if(ret==SLICE_END){
214 214
//printf("%d %d %d %06X\n", s->mb_x, s->mb_y, s->gb.size*8 - get_bits_count(&s->gb), show_bits(&s->gb, 24));
215 215
                    ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
......
644 644
    ff_er_frame_start(s);
645 645
    
646 646
    /* decode each macroblock */
647
    s->block_wrap[0]=
648
    s->block_wrap[1]=
649
    s->block_wrap[2]=
650
    s->block_wrap[3]= s->mb_width*2 + 2;
651
    s->block_wrap[4]=
652
    s->block_wrap[5]= s->mb_width + 2;
653 647
    s->mb_x=0; 
654 648
    s->mb_y=0;
655 649
    
......
708 702
        for(mb_y=0; mb_y<s->mb_height; mb_y++){
709 703
            int mb_x;
710 704
            for(mb_x=0; mb_x<s->mb_width; mb_x++){
711
                const int mb_index= mb_x + mb_y*s->mb_width;
712
                if(s->co_located_type_table[mb_index] == MV_TYPE_8X8){
705
                const int mb_index= mb_x + mb_y*s->mb_stride;
706
                if(IS_8X8(s->current_picture.mb_type[mb_index])){
713 707
                    int i;
714 708
                    for(i=0; i<4; i++){
715 709
                        int sx= mb_x*16 + 4 + 8*(i&1);
......
732 726
        }
733 727
    }
734 728

  
735

  
736 729
    if(s->pict_type==B_TYPE || s->low_delay){
737 730
        *pict= *(AVFrame*)&s->current_picture;
731
        ff_print_debug_info(s, s->current_picture_ptr);
738 732
    } else {
739 733
        *pict= *(AVFrame*)&s->last_picture;
734
        ff_print_debug_info(s, s->last_picture_ptr);
740 735
    }
741

  
742
    if(avctx->debug&FF_DEBUG_QP){
743
        int8_t *qtab= pict->qscale_table;
744
        int x,y;
745
        
746
        for(y=0; y<s->mb_height; y++){
747
            for(x=0; x<s->mb_width; x++){
748
                printf("%2d ", qtab[x + y*s->mb_width]);
749
            }
750
            printf("\n");
751
        }
752
        printf("\n");
753
    }
736
    
754 737

  
755 738
    /* Return the Picture timestamp as the frame number */
756 739
    /* we substract 1 because it is added on utils.c    */
libavcodec/h264.c
149 149
    uint8_t *rbsp_buffer;
150 150
    int rbsp_buffer_size;
151 151

  
152
    int mb_stride; ///< stride of some mb tables
153

  
154 152
    int chroma_qp; //QPc
155 153

  
156 154
    int prev_mb_skiped; //FIXME remove (IMHO not used)
......
355 353

  
356 354
static inline void fill_caches(H264Context *h, int mb_type){
357 355
    MpegEncContext * const s = &h->s;
358
    const int mb_xy= s->mb_x + s->mb_y*h->mb_stride;
356
    const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
359 357
    int topleft_xy, top_xy, topright_xy, left_xy[2];
360 358
    int topleft_type, top_type, topright_type, left_type[2];
361 359
    int left_block[4];
......
366 364
    if(h->sps.mb_aff){
367 365
    //FIXME
368 366
    }else{
369
        topleft_xy = mb_xy-1 - h->mb_stride;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff