comparison h264.c @ 2504:f12657081093 libavcodec

INTRA PCM macroblocks support patch by (Loic )lll+ffmpeg m4x org) This patch adds the support for INTRA PCM macroblocks in CAVLC and CABAC mode, the deblocking needed a small modification and so did the intra4x4_pred_mode prediction. With this patch, the 5 streams of the conformance suite containing INTRA PCM macroblocks now decode entirely, 4 are completely corrects, 1 is incorrect since the first B slice because of deblocking in B slice not yet implemented. The code is not optimized for speed, it is not necessary IPCM macroblocks are rare, but it could be optimized for code size, if someone want to do this, feel free.
author michael
date Mon, 07 Feb 2005 00:10:28 +0000
parents 4d6d056a00c6
children b3b06ba8787c
comparison
equal deleted inserted replaced
2503:5a28a7dd57d7 2504:f12657081093
480 h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5]; 480 h->intra4x4_pred_mode_cache[5+8*0]= h->intra4x4_pred_mode[top_xy][5];
481 h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6]; 481 h->intra4x4_pred_mode_cache[6+8*0]= h->intra4x4_pred_mode[top_xy][6];
482 h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3]; 482 h->intra4x4_pred_mode_cache[7+8*0]= h->intra4x4_pred_mode[top_xy][3];
483 }else{ 483 }else{
484 int pred; 484 int pred;
485 if(IS_INTRA16x16(top_type) || (IS_INTER(top_type) && !h->pps.constrained_intra_pred)) 485 if(!top_type || (IS_INTER(top_type) && h->pps.constrained_intra_pred))
486 pred= -1;
487 else{
486 pred= 2; 488 pred= 2;
487 else{
488 pred= -1;
489 } 489 }
490 h->intra4x4_pred_mode_cache[4+8*0]= 490 h->intra4x4_pred_mode_cache[4+8*0]=
491 h->intra4x4_pred_mode_cache[5+8*0]= 491 h->intra4x4_pred_mode_cache[5+8*0]=
492 h->intra4x4_pred_mode_cache[6+8*0]= 492 h->intra4x4_pred_mode_cache[6+8*0]=
493 h->intra4x4_pred_mode_cache[7+8*0]= pred; 493 h->intra4x4_pred_mode_cache[7+8*0]= pred;
496 if(IS_INTRA4x4(left_type[i])){ 496 if(IS_INTRA4x4(left_type[i])){
497 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]]; 497 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[0+2*i]];
498 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]]; 498 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= h->intra4x4_pred_mode[left_xy[i]][left_block[1+2*i]];
499 }else{ 499 }else{
500 int pred; 500 int pred;
501 if(IS_INTRA16x16(left_type[i]) || (IS_INTER(left_type[i]) && !h->pps.constrained_intra_pred)) 501 if(!left_type[i] || (IS_INTER(left_type[i]) && h->pps.constrained_intra_pred))
502 pred= -1;
503 else{
502 pred= 2; 504 pred= 2;
503 else{
504 pred= -1;
505 } 505 }
506 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= 506 h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]=
507 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred; 507 h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= pred;
508 } 508 }
509 } 509 }
2737 linesize = s->linesize; 2737 linesize = s->linesize;
2738 uvlinesize = s->uvlinesize; 2738 uvlinesize = s->uvlinesize;
2739 // dct_offset = s->linesize * 16; 2739 // dct_offset = s->linesize * 16;
2740 } 2740 }
2741 2741
2742 if (IS_INTRA_PCM(mb_type)) {
2743 unsigned int x, y;
2744
2745 // The pixels are stored in h->mb array in the same order as levels,
2746 // copy them in output in the correct order.
2747 for(i=0; i<16; i++) {
2748 for (y=0; y<4; y++) {
2749 for (x=0; x<4; x++) {
2750 *(dest_y + h->block_offset[i] + y*linesize + x) = h->mb[i*16+y*4+x];
2751 }
2752 }
2753 }
2754 for(i=16; i<16+4; i++) {
2755 for (y=0; y<4; y++) {
2756 for (x=0; x<4; x++) {
2757 *(dest_cb + h->block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
2758 }
2759 }
2760 }
2761 for(i=20; i<20+4; i++) {
2762 for (y=0; y<4; y++) {
2763 for (x=0; x<4; x++) {
2764 *(dest_cr + h->block_offset[i] + y*uvlinesize + x) = h->mb[i*16+y*4+x];
2765 }
2766 }
2767 }
2768 goto deblock;
2769 }
2742 if(IS_INTRA(mb_type)){ 2770 if(IS_INTRA(mb_type)){
2743 if(h->deblocking_filter) 2771 if(h->deblocking_filter)
2744 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1); 2772 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1);
2745 2773
2746 if(!(s->flags&CODEC_FLAG_GRAY)){ 2774 if(!(s->flags&CODEC_FLAG_GRAY)){
2843 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2); 2871 svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, chroma_qp[s->qscale + 12] - 12, 2);
2844 } 2872 }
2845 } 2873 }
2846 } 2874 }
2847 } 2875 }
2876 deblock:
2848 if(h->deblocking_filter) { 2877 if(h->deblocking_filter) {
2849 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize); 2878 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
2850 fill_caches(h, mb_type, 1); //FIXME dont fill stuff which isnt used by filter_mb 2879 fill_caches(h, mb_type, 1); //FIXME dont fill stuff which isnt used by filter_mb
2851 filter_mb(h, mb_x, mb_y, dest_y, dest_cb, dest_cr); 2880 filter_mb(h, mb_x, mb_y, dest_y, dest_cb, dest_cr);
2852 } 2881 }
3982 4011
3983 s->current_picture.mb_type[mb_xy]= mb_type; 4012 s->current_picture.mb_type[mb_xy]= mb_type;
3984 h->slice_table[ mb_xy ]= h->slice_num; 4013 h->slice_table[ mb_xy ]= h->slice_num;
3985 4014
3986 if(IS_INTRA_PCM(mb_type)){ 4015 if(IS_INTRA_PCM(mb_type)){
3987 const uint8_t *ptr; 4016 unsigned int x, y;
3988 int x, y;
3989 4017
3990 // we assume these blocks are very rare so we dont optimize it 4018 // we assume these blocks are very rare so we dont optimize it
3991 align_get_bits(&s->gb); 4019 align_get_bits(&s->gb);
3992 4020
3993 ptr= s->gb.buffer + get_bits_count(&s->gb); 4021 // The pixels are stored in the same order as levels in h->mb array.
3994
3995 for(y=0; y<16; y++){ 4022 for(y=0; y<16; y++){
3996 const int index= 4*(y&3) + 64*(y>>2); 4023 const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);
3997 for(x=0; x<16; x++){ 4024 for(x=0; x<16; x++){
3998 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); 4025 tprintf("LUMA ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
4026 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= get_bits(&s->gb, 8);
3999 } 4027 }
4000 } 4028 }
4001 for(y=0; y<8; y++){ 4029 for(y=0; y<8; y++){
4002 const int index= 256 + 4*(y&3) + 32*(y>>2); 4030 const int index= 256 + 4*(y&3) + 32*(y>>2);
4003 for(x=0; x<8; x++){ 4031 for(x=0; x<8; x++){
4004 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); 4032 tprintf("CHROMA U ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
4033 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
4005 } 4034 }
4006 } 4035 }
4007 for(y=0; y<8; y++){ 4036 for(y=0; y<8; y++){
4008 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2); 4037 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
4009 for(x=0; x<8; x++){ 4038 for(x=0; x<8; x++){
4010 h->mb[index + (x&3) + 16*(x>>2)]= *(ptr++); 4039 tprintf("CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
4011 } 4040 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
4012 } 4041 }
4013 4042 }
4014 skip_bits(&s->gb, 384); //FIXME check /fix the bitstream readers 4043
4015 4044 // In deblocking, the quantiser is 0
4016 //FIXME deblock filter, non_zero_count_cache init ... 4045 s->current_picture.qscale_table[mb_xy]= 0;
4046 h->chroma_qp = get_chroma_qp(h, 0);
4047 // All coeffs are presents
4017 memset(h->non_zero_count[mb_xy], 16, 16); 4048 memset(h->non_zero_count[mb_xy], 16, 16);
4018 s->current_picture.qscale_table[mb_xy]= s->qscale;
4019 4049
4020 return 0; 4050 return 0;
4021 } 4051 }
4022 4052
4023 fill_caches(h, mb_type, 0); 4053 fill_caches(h, mb_type, 0);
4917 4947
4918 s->current_picture.mb_type[mb_xy]= mb_type; 4948 s->current_picture.mb_type[mb_xy]= mb_type;
4919 h->slice_table[ mb_xy ]= h->slice_num; 4949 h->slice_table[ mb_xy ]= h->slice_num;
4920 4950
4921 if(IS_INTRA_PCM(mb_type)) { 4951 if(IS_INTRA_PCM(mb_type)) {
4922 /* TODO */ 4952 const uint8_t *ptr;
4923 assert(0); 4953 unsigned int x, y;
4924 h->cbp_table[mb_xy] = 0xf +4*2; //FIXME ?! 4954
4925 h->cbp_table[mb_xy] |= 0x1C0; 4955 // We assume these blocks are very rare so we dont optimize it.
4956 // FIXME The two following lines get the bitstream position in the cabac
4957 // decode, I think it should be done by a function in cabac.h (or cabac.c).
4958 ptr= h->cabac.bytestream;
4959 if (h->cabac.low&0x1) ptr-=CABAC_BITS/8;
4960
4961 // The pixels are stored in the same order as levels in h->mb array.
4962 for(y=0; y<16; y++){
4963 const int index= 4*(y&3) + 32*((y>>2)&1) + 128*(y>>3);
4964 for(x=0; x<16; x++){
4965 tprintf("LUMA ICPM LEVEL (%3d)\n", *ptr);
4966 h->mb[index + (x&3) + 16*((x>>2)&1) + 64*(x>>3)]= *ptr++;
4967 }
4968 }
4969 for(y=0; y<8; y++){
4970 const int index= 256 + 4*(y&3) + 32*(y>>2);
4971 for(x=0; x<8; x++){
4972 tprintf("CHROMA U ICPM LEVEL (%3d)\n", *ptr);
4973 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;
4974 }
4975 }
4976 for(y=0; y<8; y++){
4977 const int index= 256 + 64 + 4*(y&3) + 32*(y>>2);
4978 for(x=0; x<8; x++){
4979 tprintf("CHROMA V ICPM LEVEL (%3d)\n", *ptr);
4980 h->mb[index + (x&3) + 16*(x>>2)]= *ptr++;
4981 }
4982 }
4983
4984 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
4985
4986 // All blocks are presents
4987 h->cbp_table[mb_xy] = 0x1ef;
4926 h->chroma_pred_mode_table[mb_xy] = 0; 4988 h->chroma_pred_mode_table[mb_xy] = 0;
4927 s->current_picture.qscale_table[mb_xy]= s->qscale; 4989 // In deblocking, the quantiser is 0
4928 return -1; 4990 s->current_picture.qscale_table[mb_xy]= 0;
4991 h->chroma_qp = get_chroma_qp(h, 0);
4992 // All coeffs are presents
4993 memset(h->non_zero_count[mb_xy], 16, 16);
4994 return 0;
4929 } 4995 }
4930 4996
4931 fill_caches(h, mb_type, 0); 4997 fill_caches(h, mb_type, 0);
4932 4998
4933 if( IS_INTRA( mb_type ) ) { 4999 if( IS_INTRA( mb_type ) ) {
5603 if(bS[0]+bS[1]+bS[2]+bS[3] == 0) 5669 if(bS[0]+bS[1]+bS[2]+bS[3] == 0)
5604 continue; 5670 continue;
5605 } 5671 }
5606 5672
5607 /* Filter edge */ 5673 /* Filter edge */
5608 qp = ( s->qscale + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; 5674 // Do not use s->qscale as luma quantiser because it has not the same
5675 // value in IPCM macroblocks.
5676 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
5609 //tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]); 5677 //tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]);
5610 if( dir == 0 ) { 5678 if( dir == 0 ) {
5611 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); 5679 filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp );
5612 if( (edge&1) == 0 ) { 5680 if( (edge&1) == 0 ) {
5613 int chroma_qp = ( h->chroma_qp + 5681 int chroma_qp = ( h->chroma_qp +