comparison h264.c @ 2551:615995277bc5 libavcodec

MBAFF I slice no deblocking patch by (Loic >>lll+ffmpeg m4x org<<)
author michael
date Sun, 06 Mar 2005 23:02:25 +0000
parents bca31bc0cbae
children 48c1b17233e8
comparison
equal deleted inserted replaced
2550:8bf96ac84409 2551:615995277bc5
196 /** 196 /**
197 * is 1 if the specific list MV&references are set to 0,0,-2. 197 * is 1 if the specific list MV&references are set to 0,0,-2.
198 */ 198 */
199 int mv_cache_clean[2]; 199 int mv_cache_clean[2];
200 200
201 int block_offset[16+8]; 201 /**
202 int chroma_subblock_offset[16]; //FIXME remove 202 * block_offset[ 0..23] for frame macroblocks
203 * block_offset[24..47] for field macroblocks
204 */
205 int block_offset[2*(16+8)];
203 206
204 uint16_t *mb2b_xy; //FIXME are these 4 a good idea? 207 uint16_t *mb2b_xy; //FIXME are these 4 a good idea?
205 uint16_t *mb2b8_xy; 208 uint16_t *mb2b8_xy;
206 int b_stride; //FIXME use s->b4_stride 209 int b_stride; //FIXME use s->b4_stride
207 int b8_stride; 210 int b8_stride;
414 static inline void fill_caches(H264Context *h, int mb_type, int for_deblock){ 417 static inline void fill_caches(H264Context *h, int mb_type, int for_deblock){
415 MpegEncContext * const s = &h->s; 418 MpegEncContext * const s = &h->s;
416 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; 419 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
417 int topleft_xy, top_xy, topright_xy, left_xy[2]; 420 int topleft_xy, top_xy, topright_xy, left_xy[2];
418 int topleft_type, top_type, topright_type, left_type[2]; 421 int topleft_type, top_type, topright_type, left_type[2];
419 int left_block[4]; 422 int left_block[8];
420 int i; 423 int i;
421 424
422 //wow what a mess, why didnt they simplify the interlacing&intra stuff, i cant imagine that these complex rules are worth it 425 //wow what a mess, why didnt they simplify the interlacing&intra stuff, i cant imagine that these complex rules are worth it
423 426
427 top_xy = mb_xy - s->mb_stride;
428 topleft_xy = top_xy - 1;
429 topright_xy= top_xy + 1;
430 left_xy[1] = left_xy[0] = mb_xy-1;
431 left_block[0]= 0;
432 left_block[1]= 1;
433 left_block[2]= 2;
434 left_block[3]= 3;
435 left_block[4]= 7;
436 left_block[5]= 10;
437 left_block[6]= 8;
438 left_block[7]= 11;
424 if(h->sps.mb_aff){ 439 if(h->sps.mb_aff){
425 //FIXME 440 const int pair_xy = s->mb_x + (s->mb_y & ~1)*s->mb_stride;
426 topleft_xy = 0; /* avoid warning */ 441 const int top_pair_xy = pair_xy - s->mb_stride;
427 top_xy = 0; /* avoid warning */ 442 const int topleft_pair_xy = top_pair_xy - 1;
428 topright_xy = 0; /* avoid warning */ 443 const int topright_pair_xy = top_pair_xy + 1;
429 }else{ 444 const int topleft_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topleft_pair_xy]);
430 topleft_xy = mb_xy-1 - s->mb_stride; 445 const int top_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[top_pair_xy]);
431 top_xy = mb_xy - s->mb_stride; 446 const int topright_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[topright_pair_xy]);
432 topright_xy= mb_xy+1 - s->mb_stride; 447 const int left_mb_frame_flag = !IS_INTERLACED(s->current_picture.mb_type[pair_xy-1]);
433 left_xy[0] = mb_xy-1; 448 const int curr_mb_frame_flag = !IS_INTERLACED(mb_type);
434 left_xy[1] = mb_xy-1; 449 const int bottom = (s->mb_y & 1);
435 left_block[0]= 0; 450 tprintf("fill_caches: curr_mb_frame_flag:%d, left_mb_frame_flag:%d, topleft_mb_frame_flag:%d, top_mb_frame_flag:%d, topright_mb_frame_flag:%d\n", curr_mb_frame_flag, left_mb_frame_flag, topleft_mb_frame_flag, top_mb_frame_flag, topright_mb_frame_flag);
436 left_block[1]= 1; 451 if (bottom
437 left_block[2]= 2; 452 ? !curr_mb_frame_flag // bottom macroblock
438 left_block[3]= 3; 453 : (!curr_mb_frame_flag && !top_mb_frame_flag) // top macroblock
454 ) {
455 top_xy -= s->mb_stride;
456 }
457 if (bottom
458 ? !curr_mb_frame_flag // bottom macroblock
459 : (!curr_mb_frame_flag && !topleft_mb_frame_flag) // top macroblock
460 ) {
461 topleft_xy -= s->mb_stride;
462 }
463 if (bottom
464 ? !curr_mb_frame_flag // bottom macroblock
465 : (!curr_mb_frame_flag && !topright_mb_frame_flag) // top macroblock
466 ) {
467 topright_xy -= s->mb_stride;
468 }
469 if (left_mb_frame_flag != curr_mb_frame_flag) {
470 left_xy[1] = left_xy[0] = pair_xy - 1;
471 if (curr_mb_frame_flag) {
472 if (bottom) {
473 left_block[0]= 2;
474 left_block[1]= 2;
475 left_block[2]= 3;
476 left_block[3]= 3;
477 left_block[4]= 8;
478 left_block[5]= 11;
479 left_block[6]= 8;
480 left_block[7]= 11;
481 } else {
482 left_block[0]= 0;
483 left_block[1]= 0;
484 left_block[2]= 1;
485 left_block[3]= 1;
486 left_block[4]= 7;
487 left_block[5]= 10;
488 left_block[6]= 7;
489 left_block[7]= 10;
490 }
491 } else {
492 left_xy[1] += s->mb_stride;
493 //left_block[0]= 0;
494 left_block[1]= 2;
495 left_block[2]= 0;
496 left_block[3]= 2;
497 //left_block[4]= 7;
498 left_block[5]= 10;
499 left_block[6]= 7;
500 left_block[7]= 10;
501 }
502 }
439 } 503 }
440 504
441 if(for_deblock){ 505 if(for_deblock){
442 topleft_type = h->slice_table[topleft_xy ] < 255 ? s->current_picture.mb_type[topleft_xy] : 0; 506 topleft_type = h->slice_table[topleft_xy ] < 255 ? s->current_picture.mb_type[topleft_xy] : 0;
443 top_type = h->slice_table[top_xy ] < 255 ? s->current_picture.mb_type[top_xy] : 0; 507 top_type = h->slice_table[top_xy ] < 255 ? s->current_picture.mb_type[top_xy] : 0;
521 4 L . .L . . . . 585 4 L . .L . . . .
522 5 L . .. . . . . 586 5 L . .. . . . .
523 */ 587 */
524 //FIXME constraint_intra_pred & partitioning & nnz (lets hope this is just a typo in the spec) 588 //FIXME constraint_intra_pred & partitioning & nnz (lets hope this is just a typo in the spec)
525 if(top_type){ 589 if(top_type){
526 h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][0]; 590 h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][4];
527 h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][1]; 591 h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][5];
528 h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][2]; 592 h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][6];
529 h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3]; 593 h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3];
530 594
531 h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][7]; 595 h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][9];
532 h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8]; 596 h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][8];
533 597
534 h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][10]; 598 h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][12];
535 h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11]; 599 h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][11];
536 600
537 h->top_cbp= h->cbp_table[top_xy]; 601 h->top_cbp= h->cbp_table[top_xy];
538 }else{ 602 }else{
539 h->non_zero_count_cache[4+8*0]= 603 h->non_zero_count_cache[4+8*0]=
549 613
550 if(IS_INTRA(mb_type)) h->top_cbp= 0x1C0; 614 if(IS_INTRA(mb_type)) h->top_cbp= 0x1C0;
551 else h->top_cbp= 0; 615 else h->top_cbp= 0;
552 } 616 }
553 617
554 if(left_type[0]){ 618 for (i=0; i<2; i++) {
555 h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][6]; 619 if(left_type[i]){
556 h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][5]; 620 h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[0+2*i]];
557 h->non_zero_count_cache[0+8*1]= h->non_zero_count[left_xy[0]][9]; //FIXME left_block 621 h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[1+2*i]];
558 h->non_zero_count_cache[0+8*4]= h->non_zero_count[left_xy[0]][12]; 622 h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[4+2*i]];
559 h->left_cbp= h->cbp_table[left_xy[0]]; //FIXME interlacing 623 h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[5+2*i]];
560 }else{ 624 h->left_cbp= h->cbp_table[left_xy[i]]; //FIXME interlacing
561 h->non_zero_count_cache[3+8*1]= 625 }else{
562 h->non_zero_count_cache[3+8*2]= 626 h->non_zero_count_cache[3+8*1 + 2*8*i]=
563 h->non_zero_count_cache[0+8*1]= 627 h->non_zero_count_cache[3+8*2 + 2*8*i]=
564 h->non_zero_count_cache[0+8*4]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64; 628 h->non_zero_count_cache[0+8*1 + 8*i]=
565 629 h->non_zero_count_cache[0+8*4 + 8*i]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64;
566 if(IS_INTRA(mb_type)) h->left_cbp= 0x1C0;//FIXME interlacing 630
567 else h->left_cbp= 0; 631 if(IS_INTRA(mb_type)) h->left_cbp= 0x1C0;//FIXME interlacing
568 } 632 else h->left_cbp= 0;
569 633 }
570 if(left_type[1]){ 634 }
571 h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[1]][4]; 635
572 h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[1]][3];
573 h->non_zero_count_cache[0+8*2]= h->non_zero_count[left_xy[1]][8];
574 h->non_zero_count_cache[0+8*5]= h->non_zero_count[left_xy[1]][11];
575 }else{
576 h->non_zero_count_cache[3+8*3]=
577 h->non_zero_count_cache[3+8*4]=
578 h->non_zero_count_cache[0+8*2]=
579 h->non_zero_count_cache[0+8*5]= h->pps.cabac && !IS_INTRA(mb_type) ? 0 : 64;
580 }
581
582 #if 1 636 #if 1
583 //FIXME direct mb can skip much of this 637 //FIXME direct mb can skip much of this
584 if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ 638 if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){
585 int list; 639 int list;
586 for(list=0; list<2; list++){ 640 for(list=0; list<2; list++){
849 903
850 static inline void write_back_non_zero_count(H264Context *h){ 904 static inline void write_back_non_zero_count(H264Context *h){
851 MpegEncContext * const s = &h->s; 905 MpegEncContext * const s = &h->s;
852 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; 906 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
853 907
854 h->non_zero_count[mb_xy][0]= h->non_zero_count_cache[4+8*4]; 908 h->non_zero_count[mb_xy][0]= h->non_zero_count_cache[7+8*1];
855 h->non_zero_count[mb_xy][1]= h->non_zero_count_cache[5+8*4]; 909 h->non_zero_count[mb_xy][1]= h->non_zero_count_cache[7+8*2];
856 h->non_zero_count[mb_xy][2]= h->non_zero_count_cache[6+8*4]; 910 h->non_zero_count[mb_xy][2]= h->non_zero_count_cache[7+8*3];
857 h->non_zero_count[mb_xy][3]= h->non_zero_count_cache[7+8*4]; 911 h->non_zero_count[mb_xy][3]= h->non_zero_count_cache[7+8*4];
858 h->non_zero_count[mb_xy][4]= h->non_zero_count_cache[7+8*3]; 912 h->non_zero_count[mb_xy][4]= h->non_zero_count_cache[4+8*4];
859 h->non_zero_count[mb_xy][5]= h->non_zero_count_cache[7+8*2]; 913 h->non_zero_count[mb_xy][5]= h->non_zero_count_cache[5+8*4];
860 h->non_zero_count[mb_xy][6]= h->non_zero_count_cache[7+8*1]; 914 h->non_zero_count[mb_xy][6]= h->non_zero_count_cache[6+8*4];
861 915
862 h->non_zero_count[mb_xy][7]= h->non_zero_count_cache[1+8*2]; 916 h->non_zero_count[mb_xy][9]= h->non_zero_count_cache[1+8*2];
863 h->non_zero_count[mb_xy][8]= h->non_zero_count_cache[2+8*2]; 917 h->non_zero_count[mb_xy][8]= h->non_zero_count_cache[2+8*2];
864 h->non_zero_count[mb_xy][9]= h->non_zero_count_cache[2+8*1]; 918 h->non_zero_count[mb_xy][7]= h->non_zero_count_cache[2+8*1];
865 919
866 h->non_zero_count[mb_xy][10]=h->non_zero_count_cache[1+8*5]; 920 h->non_zero_count[mb_xy][12]=h->non_zero_count_cache[1+8*5];
867 h->non_zero_count[mb_xy][11]=h->non_zero_count_cache[2+8*5]; 921 h->non_zero_count[mb_xy][11]=h->non_zero_count_cache[2+8*5];
868 h->non_zero_count[mb_xy][12]=h->non_zero_count_cache[2+8*4]; 922 h->non_zero_count[mb_xy][10]=h->non_zero_count_cache[2+8*4];
869 } 923 }
870 924
871 /** 925 /**
872 * gets the predicted number of non zero coefficients. 926 * gets the predicted number of non zero coefficients.
873 * @param n block index 927 * @param n block index
2652 2706
2653 assert(s->linesize && s->uvlinesize); 2707 assert(s->linesize && s->uvlinesize);
2654 2708
2655 for(i=0; i<16; i++){ 2709 for(i=0; i<16; i++){
2656 h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3); 2710 h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3);
2657 h->chroma_subblock_offset[i]= 2*((scan8[i] - scan8[0])&7) + 2*s->uvlinesize*((scan8[i] - scan8[0])>>3); 2711 h->block_offset[24+i]= 4*((scan8[i] - scan8[0])&7) + 8*s->linesize*((scan8[i] - scan8[0])>>3);
2658 } 2712 }
2659 for(i=0; i<4; i++){ 2713 for(i=0; i<4; i++){
2660 h->block_offset[16+i]= 2714 h->block_offset[16+i]=
2661 h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3); 2715 h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3);
2716 h->block_offset[24+16+i]=
2717 h->block_offset[24+20+i]= 4*((scan8[i] - scan8[0])&7) + 8*s->uvlinesize*((scan8[i] - scan8[0])>>3);
2662 } 2718 }
2663 2719
2664 /* can't be in alloc_tables because linesize isn't known there. 2720 /* can't be in alloc_tables because linesize isn't known there.
2665 * FIXME: redo bipred weight to not require extra buffer? */ 2721 * FIXME: redo bipred weight to not require extra buffer? */
2666 if(!s->obmc_scratchpad) 2722 if(!s->obmc_scratchpad)
2675 2731
2676 src_y -= linesize; 2732 src_y -= linesize;
2677 src_cb -= uvlinesize; 2733 src_cb -= uvlinesize;
2678 src_cr -= uvlinesize; 2734 src_cr -= uvlinesize;
2679 2735
2736 // There is two lines saved, the line above the the top macroblock of a pair,
2737 // and the line above the bottom macroblock
2680 h->left_border[0]= h->top_border[s->mb_x][15]; 2738 h->left_border[0]= h->top_border[s->mb_x][15];
2681 for(i=1; i<17; i++){ 2739 for(i=1; i<17; i++){
2682 h->left_border[i]= src_y[15+i* linesize]; 2740 h->left_border[i]= src_y[15+i* linesize];
2683 } 2741 }
2684 2742
2746 const int mb_xy= mb_x + mb_y*s->mb_stride; 2804 const int mb_xy= mb_x + mb_y*s->mb_stride;
2747 const int mb_type= s->current_picture.mb_type[mb_xy]; 2805 const int mb_type= s->current_picture.mb_type[mb_xy];
2748 uint8_t *dest_y, *dest_cb, *dest_cr; 2806 uint8_t *dest_y, *dest_cb, *dest_cr;
2749 int linesize, uvlinesize /*dct_offset*/; 2807 int linesize, uvlinesize /*dct_offset*/;
2750 int i; 2808 int i;
2809 int *block_offset = &h->block_offset[0];
2751 2810
2752 if(!s->decode) 2811 if(!s->decode)
2753 return; 2812 return;
2754
2755 if(s->mb_skiped){
2756 }
2757 2813
2758 dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16; 2814 dest_y = s->current_picture.data[0] + (mb_y * 16* s->linesize ) + mb_x * 16;
2759 dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; 2815 dest_cb = s->current_picture.data[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
2760 dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; 2816 dest_cr = s->current_picture.data[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8;
2761 2817
2762 if (h->mb_field_decoding_flag) { 2818 if (h->mb_field_decoding_flag) {
2763 linesize = s->linesize * 2; 2819 linesize = s->linesize * 2;
2764 uvlinesize = s->uvlinesize * 2; 2820 uvlinesize = s->uvlinesize * 2;
2821 block_offset = &h->block_offset[24];
2765 if(mb_y&1){ //FIXME move out of this func? 2822 if(mb_y&1){ //FIXME move out of this func?
2766 dest_y -= s->linesize*15; 2823 dest_y -= s->linesize*15;
2767 dest_cb-= s->linesize*7; 2824 dest_cb-= s->uvlinesize*7;
2768 dest_cr-= s->linesize*7; 2825 dest_cr-= s->uvlinesize*7;
2769 } 2826 }
2770 } else { 2827 } else {
2771 linesize = s->linesize; 2828 linesize = s->linesize;
2772 uvlinesize = s->uvlinesize; 2829 uvlinesize = s->uvlinesize;
2773 // dct_offset = s->linesize * 16; 2830 // dct_offset = s->linesize * 16;
2779 // The pixels are stored in h->mb array in the same order as levels, 2836 // The pixels are stored in h->mb array in the same order as levels,
2780 // copy them in output in the correct order. 2837 // copy them in output in the correct order.
2781 for(i=0; i<16; i++) { 2838 for(i=0; i<16; i++) {
2782 for (y=0; y<4; y++) { 2839 for (y=0; y<4; y++) {
2783 for (x=0; x<4; x++) { 2840 for (x=0; x<4; x++) {
2784 *(dest_y + h->block_offset[i] + y*linesize + x) = h->mb[i*16+y*4+x]; 2841 *(dest_y + block_offset[i] + y*linesize + x) = h->mb[i*16+y*4+x];
2785 } 2842 }
2786 } 2843 }
2787 } 2844 }
2788 for(i=16; i<16+4; i++) { 2845 for(i=16; i<16+4; i++) {
2789 for (y=0; y<4; y++) { 2846 for (y=0; y<4; y++) {
2790 for (x=0; x<4; x++) { 2847 for (x=0; x<4; x++) {
2791 *(dest_cb + h->block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x]; 2848 *(dest_cb + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
2792 } 2849 }
2793 } 2850 }
2794 } 2851 }
2795 for(i=20; i<20+4; i++) { 2852 for(i=20; i<20+4; i++) {
2796 for (y=0; y<4; y++) { 2853 for (y=0; y<4; y++) {
2797 for (x=0; x<4; x++) { 2854 for (x=0; x<4; x++) {
2798 *(dest_cr + h->block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x]; 2855 *(dest_cr + block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
2799 } 2856 }
2800 } 2857 }
2801 } 2858 }
2802 } else { 2859 } else {
2803 if(IS_INTRA(mb_type)){ 2860 if(IS_INTRA(mb_type)){
2810 } 2867 }
2811 2868
2812 if(IS_INTRA4x4(mb_type)){ 2869 if(IS_INTRA4x4(mb_type)){
2813 if(!s->encoding){ 2870 if(!s->encoding){
2814 for(i=0; i<16; i++){ 2871 for(i=0; i<16; i++){
2815 uint8_t * const ptr= dest_y + h->block_offset[i]; 2872 uint8_t * const ptr= dest_y + block_offset[i];
2816 uint8_t *topright; 2873 uint8_t *topright;
2817 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; 2874 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ];
2818 int tr; 2875 int tr;
2819 2876
2820 if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){ 2877 if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){
2821 const int topright_avail= (h->topright_samples_available<<i)&0x8000; 2878 const int topright_avail= (h->topright_samples_available<<i)&0x8000;
2822 assert(mb_y || linesize <= h->block_offset[i]); 2879 assert(mb_y || linesize <= block_offset[i]);
2823 if(!topright_avail){ 2880 if(!topright_avail){
2824 tr= ptr[3 - linesize]*0x01010101; 2881 tr= ptr[3 - linesize]*0x01010101;
2825 topright= (uint8_t*) &tr; 2882 topright= (uint8_t*) &tr;
2826 }else if(i==5 && h->deblocking_filter){ 2883 }else if(i==5 && h->deblocking_filter){
2827 tr= *(uint32_t*)h->top_border[mb_x+1]; 2884 tr= *(uint32_t*)h->top_border[mb_x+1];
2859 2916
2860 if(!IS_INTRA4x4(mb_type)){ 2917 if(!IS_INTRA4x4(mb_type)){
2861 if(s->codec_id == CODEC_ID_H264){ 2918 if(s->codec_id == CODEC_ID_H264){
2862 for(i=0; i<16; i++){ 2919 for(i=0; i<16; i++){
2863 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below 2920 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below
2864 uint8_t * const ptr= dest_y + h->block_offset[i]; 2921 uint8_t * const ptr= dest_y + block_offset[i];
2865 s->dsp.h264_idct_add(ptr, h->mb + i*16, linesize); 2922 s->dsp.h264_idct_add(ptr, h->mb + i*16, linesize);
2866 } 2923 }
2867 } 2924 }
2868 }else{ 2925 }else{
2869 for(i=0; i<16; i++){ 2926 for(i=0; i<16; i++){
2870 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below 2927 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below
2871 uint8_t * const ptr= dest_y + h->block_offset[i]; 2928 uint8_t * const ptr= dest_y + block_offset[i];
2872 svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0); 2929 svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0);
2873 } 2930 }
2874 } 2931 }
2875 } 2932 }
2876 } 2933 }
2879 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp); 2936 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp);
2880 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp); 2937 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp);
2881 if(s->codec_id == CODEC_ID_H264){ 2938 if(s->codec_id == CODEC_ID_H264){
2882 for(i=16; i<16+4; i++){ 2939 for(i=16; i<16+4; i++){
2883 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ 2940 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
2884 uint8_t * const ptr= dest_cb + h->block_offset[i]; 2941 uint8_t * const ptr= dest_cb + block_offset[i];
2885 s->dsp.h264_idct_add(ptr, h->mb + i*16, uvlinesize); 2942 s->dsp.h264_idct_add(ptr, h->mb + i*16, uvlinesize);
2886 } 2943 }
2887 } 2944 }
2888 for(i=20; i<20+4; i++){ 2945 for(i=20; i<20+4; i++){
2889 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ 2946 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
2890 uint8_t * const ptr= dest_cr + h->block_offset[i]; 2947 uint8_t * const ptr= dest_cr + block_offset[i];
2891 s->dsp.h264_idct_add(ptr, h->mb + i*16, uvlinesize); 2948 s->dsp.h264_idct_add(ptr, h->mb + i*16, uvlinesize);
2892 } 2949 }
2893 } 2950 }
2894 }else{ 2951 }else{
2895 for(i=16; i<16+4; i++){ 2952 for(i=16; i<16+4; i++){
2896 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ 2953 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
2897 uint8_t * const ptr= dest_cb + h->block_offset[i]; 2954 uint8_t * const ptr= dest_cb + block_offset[i];
2898 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); 2955 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2);
2899 } 2956 }
2900 } 2957 }
2901 for(i=20; i<20+4; i++){ 2958 for(i=20; i<20+4; i++){
2902 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ 2959 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){
2903 uint8_t * const ptr= dest_cr + h->block_offset[i]; 2960 uint8_t * const ptr= dest_cr + block_offset[i];
2904 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); 2961 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2);
2905 } 2962 }
2906 } 2963 }
2907 } 2964 }
2908 } 2965 }
3575 av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n"); 3632 av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n");
3576 return -1; 3633 return -1;
3577 } 3634 }
3578 3635
3579 s->mb_width= h->sps.mb_width; 3636 s->mb_width= h->sps.mb_width;
3580 s->mb_height= h->sps.mb_height; 3637 s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);
3581 3638
3582 h->b_stride= s->mb_width*4 + 1; 3639 h->b_stride= s->mb_width*4 + 1;
3583 h->b8_stride= s->mb_width*2 + 1; 3640 h->b8_stride= s->mb_width*2 + 1;
3584 3641
3585 s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;
3586 s->resync_mb_y = s->mb_y = first_mb_in_slice / s->mb_width; //FIXME AFFW
3587
3588 s->width = 16*s->mb_width - 2*(h->sps.crop_left + h->sps.crop_right ); 3642 s->width = 16*s->mb_width - 2*(h->sps.crop_left + h->sps.crop_right );
3589 if(h->sps.frame_mbs_only_flag) 3643 if(h->sps.frame_mbs_only_flag)
3590 s->height= 16*s->mb_height - 2*(h->sps.crop_top + h->sps.crop_bottom); 3644 s->height= 16*s->mb_height - 2*(h->sps.crop_top + h->sps.crop_bottom);
3591 else 3645 else
3592 s->height= 16*s->mb_height - 4*(h->sps.crop_top + h->sps.crop_bottom); //FIXME recheck 3646 s->height= 16*s->mb_height - 4*(h->sps.crop_top + h->sps.crop_bottom); //FIXME recheck
3624 if(h->sps.frame_mbs_only_flag){ 3678 if(h->sps.frame_mbs_only_flag){
3625 s->picture_structure= PICT_FRAME; 3679 s->picture_structure= PICT_FRAME;
3626 }else{ 3680 }else{
3627 if(get_bits1(&s->gb)) //field_pic_flag 3681 if(get_bits1(&s->gb)) //field_pic_flag
3628 s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag 3682 s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag
3629 else 3683 else {
3630 s->picture_structure= PICT_FRAME; 3684 s->picture_structure= PICT_FRAME;
3631 } 3685 first_mb_in_slice <<= 1;
3632 3686 }
3687 }
3688
3689 s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;
3690 s->resync_mb_y = s->mb_y = first_mb_in_slice / s->mb_width; //FIXME AFFW
3691
3633 if(s->picture_structure==PICT_FRAME){ 3692 if(s->picture_structure==PICT_FRAME){
3634 h->curr_pic_num= h->frame_num; 3693 h->curr_pic_num= h->frame_num;
3635 h->max_pic_num= 1<< h->sps.log2_max_frame_num; 3694 h->max_pic_num= 1<< h->sps.log2_max_frame_num;
3636 }else{ 3695 }else{
3637 h->curr_pic_num= 2*h->frame_num; 3696 h->curr_pic_num= 2*h->frame_num;
3740 #endif 3799 #endif
3741 3800
3742 h->slice_num++; 3801 h->slice_num++;
3743 3802
3744 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ 3803 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
3745 av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d mb:%d %c pps:%d frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d weight:%d%s\n", 3804 av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c pps:%d frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d weight:%d%s\n",
3746 h->slice_num, first_mb_in_slice, 3805 h->slice_num,
3806 (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),
3807 first_mb_in_slice,
3747 av_get_pict_type_char(h->slice_type), 3808 av_get_pict_type_char(h->slice_type),
3748 pps_id, h->frame_num, 3809 pps_id, h->frame_num,
3749 s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1], 3810 s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],
3750 h->ref_count[0], h->ref_count[1], 3811 h->ref_count[0], h->ref_count[1],
3751 s->qscale, 3812 s->qscale,
3992 if (s->mb_skip_run--) { 4053 if (s->mb_skip_run--) {
3993 decode_mb_skip(h); 4054 decode_mb_skip(h);
3994 return 0; 4055 return 0;
3995 } 4056 }
3996 } 4057 }
3997 if(h->sps.mb_aff /* && !field pic FIXME needed? */){ 4058 if(h->sps.mb_aff && s->picture_structure==PICT_FRAME ){
3998 if((s->mb_y&1)==0) 4059 if ( ((s->mb_y&1) == 0) || h->prev_mb_skiped)
3999 h->mb_field_decoding_flag = get_bits1(&s->gb); 4060 h->mb_field_decoding_flag = get_bits1(&s->gb);
4000 }else 4061 }else
4001 h->mb_field_decoding_flag=0; //FIXME som ed note ?! 4062 h->mb_field_decoding_flag= (s->picture_structure!=PICT_FRAME);
4002 4063
4003 h->prev_mb_skiped= 0; 4064 h->prev_mb_skiped= 0;
4004 4065
4005 mb_type= get_ue_golomb(&s->gb); 4066 mb_type= get_ue_golomb(&s->gb);
4006 if(h->slice_type == B_TYPE){ 4067 if(h->slice_type == B_TYPE){
4616 mbb_xy = -1; 4677 mbb_xy = -1;
4617 } 4678 }
4618 } 4679 }
4619 4680
4620 /* No need to test for skip as we put 0 for skip block */ 4681 /* No need to test for skip as we put 0 for skip block */
4682 /* No need to test for IPCM as we put 1 for IPCM block */
4621 if( mba_xy >= 0 ) { 4683 if( mba_xy >= 0 ) {
4622 int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; 4684 int i8x8a = block_idx_xy[(x-1)&0x03][y]/4;
4623 if( ((h->cbp_table[mba_xy] >> i8x8a)&0x01) == 0 ) 4685 if( ((h->cbp_table[mba_xy] >> i8x8a)&0x01) == 0 )
4624 ctx++; 4686 ctx++;
4625 } 4687 }
5762 h->cabac_state[i] = 2 * ( pre - 64 ) + 1; 5824 h->cabac_state[i] = 2 * ( pre - 64 ) + 1;
5763 } 5825 }
5764 5826
5765 for(;;){ 5827 for(;;){
5766 int ret = decode_mb_cabac(h); 5828 int ret = decode_mb_cabac(h);
5767 int eos = get_cabac_terminate( &h->cabac ); /* End of Slice flag */ 5829 int eos;
5768 5830
5769 if(ret>=0) hl_decode_mb(h); 5831 if(ret>=0) hl_decode_mb(h);
5770 5832
5771 /* XXX: useless as decode_mb_cabac it doesn't support that ... */ 5833 /* XXX: useless as decode_mb_cabac it doesn't support that ... */
5772 if( ret >= 0 && h->sps.mb_aff ) { //FIXME optimal? or let mb_decode decode 16x32 ? 5834 if( ret >= 0 && h->sps.mb_aff ) { //FIXME optimal? or let mb_decode decode 16x32 ?
5773 s->mb_y++; 5835 s->mb_y++;
5774 5836
5775 if(ret>=0) ret = decode_mb_cabac(h); 5837 if(ret>=0) ret = decode_mb_cabac(h);
5776 eos = get_cabac_terminate( &h->cabac );
5777 5838
5778 hl_decode_mb(h); 5839 hl_decode_mb(h);
5779 s->mb_y--; 5840 s->mb_y--;
5780 } 5841 }
5842 eos = get_cabac_terminate( &h->cabac );
5781 5843
5782 if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 1) { 5844 if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 1) {
5783 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); 5845 av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y);
5784 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); 5846 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask);
5785 return -1; 5847 return -1;
5787 5849
5788 if( ++s->mb_x >= s->mb_width ) { 5850 if( ++s->mb_x >= s->mb_width ) {
5789 s->mb_x = 0; 5851 s->mb_x = 0;
5790 ff_draw_horiz_band(s, 16*s->mb_y, 16); 5852 ff_draw_horiz_band(s, 16*s->mb_y, 16);
5791 ++s->mb_y; 5853 ++s->mb_y;
5854 if(h->sps.mb_aff && s->picture_structure==PICT_FRAME ) {
5855 ++s->mb_y;
5856 }
5792 } 5857 }
5793 5858
5794 if( eos || s->mb_y >= s->mb_height ) { 5859 if( eos || s->mb_y >= s->mb_height ) {
5795 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); 5860 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
5796 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); 5861 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
5827 } 5892 }
5828 5893
5829 if(++s->mb_x >= s->mb_width){ 5894 if(++s->mb_x >= s->mb_width){
5830 s->mb_x=0; 5895 s->mb_x=0;
5831 ff_draw_horiz_band(s, 16*s->mb_y, 16); 5896 ff_draw_horiz_band(s, 16*s->mb_y, 16);
5832 if(++s->mb_y >= s->mb_height){ 5897 ++s->mb_y;
5898 if(h->sps.mb_aff && s->picture_structure==PICT_FRAME ) {
5899 ++s->mb_y;
5900 }
5901 if(s->mb_y >= s->mb_height){
5833 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); 5902 tprintf("slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits);
5834 5903
5835 if(get_bits_count(&s->gb) == s->gb.size_in_bits ) { 5904 if(get_bits_count(&s->gb) == s->gb.size_in_bits ) {
5836 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); 5905 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask);
5837 5906