Mercurial > libavcodec.hg
comparison h264.c @ 11499:2a4dc3c0b012 libavcodec
Move H264 dsputil functions into their own struct
This moves the H264-specific functions from DSPContext to the new
H264DSPContext. The code is made conditional on CONFIG_H264DSP
which is set by the codecs requiring it.
The qpel and chroma MC functions are not moved as these are used by
non-h264 code.
author | mru |
---|---|
date | Tue, 16 Mar 2010 01:17:00 +0000 |
parents | 049a0c71e5a3 |
children | 9adad5749f23 |
comparison
equal
deleted
inserted
replaced
11498:8e889ce0d616 | 11499:2a4dc3c0b012 |
---|---|
676 } | 676 } |
677 } | 677 } |
678 | 678 |
679 static void init_dequant8_coeff_table(H264Context *h){ | 679 static void init_dequant8_coeff_table(H264Context *h){ |
680 int i,q,x; | 680 int i,q,x; |
681 const int transpose = (h->s.dsp.h264_idct8_add != ff_h264_idct8_add_c); //FIXME ugly | 681 const int transpose = (h->h264dsp.h264_idct8_add != ff_h264_idct8_add_c); //FIXME ugly |
682 h->dequant8_coeff[0] = h->dequant8_buffer[0]; | 682 h->dequant8_coeff[0] = h->dequant8_buffer[0]; |
683 h->dequant8_coeff[1] = h->dequant8_buffer[1]; | 683 h->dequant8_coeff[1] = h->dequant8_buffer[1]; |
684 | 684 |
685 for(i=0; i<2; i++ ){ | 685 for(i=0; i<2; i++ ){ |
686 if(i && !memcmp(h->pps.scaling_matrix8[0], h->pps.scaling_matrix8[1], 64*sizeof(uint8_t))){ | 686 if(i && !memcmp(h->pps.scaling_matrix8[0], h->pps.scaling_matrix8[1], 64*sizeof(uint8_t))){ |
699 } | 699 } |
700 } | 700 } |
701 | 701 |
702 static void init_dequant4_coeff_table(H264Context *h){ | 702 static void init_dequant4_coeff_table(H264Context *h){ |
703 int i,j,q,x; | 703 int i,j,q,x; |
704 const int transpose = (h->s.dsp.h264_idct_add != ff_h264_idct_add_c); //FIXME ugly | 704 const int transpose = (h->h264dsp.h264_idct_add != ff_h264_idct_add_c); //FIXME ugly |
705 for(i=0; i<6; i++ ){ | 705 for(i=0; i<6; i++ ){ |
706 h->dequant4_coeff[i] = h->dequant4_buffer[i]; | 706 h->dequant4_coeff[i] = h->dequant4_buffer[i]; |
707 for(j=0; j<i; j++){ | 707 for(j=0; j<i; j++){ |
708 if(!memcmp(h->pps.scaling_matrix4[j], h->pps.scaling_matrix4[i], 16*sizeof(uint8_t))){ | 708 if(!memcmp(h->pps.scaling_matrix4[j], h->pps.scaling_matrix4[i], 16*sizeof(uint8_t))){ |
709 h->dequant4_coeff[i] = h->dequant4_buffer[j]; | 709 h->dequant4_coeff[i] = h->dequant4_buffer[j]; |
829 | 829 |
830 s->width = s->avctx->width; | 830 s->width = s->avctx->width; |
831 s->height = s->avctx->height; | 831 s->height = s->avctx->height; |
832 s->codec_id= s->avctx->codec->id; | 832 s->codec_id= s->avctx->codec->id; |
833 | 833 |
834 ff_h264dsp_init(&h->h264dsp); | |
834 ff_h264_pred_init(&h->hpc, s->codec_id); | 835 ff_h264_pred_init(&h->hpc, s->codec_id); |
835 | 836 |
836 h->dequant_coeff_pps= -1; | 837 h->dequant_coeff_pps= -1; |
837 s->unrestricted_mv=1; | 838 s->unrestricted_mv=1; |
838 s->decode=1; //FIXME | 839 s->decode=1; //FIXME |
1157 if(IS_8x8DCT(mb_type)){ | 1158 if(IS_8x8DCT(mb_type)){ |
1158 if(transform_bypass){ | 1159 if(transform_bypass){ |
1159 idct_dc_add = | 1160 idct_dc_add = |
1160 idct_add = s->dsp.add_pixels8; | 1161 idct_add = s->dsp.add_pixels8; |
1161 }else{ | 1162 }else{ |
1162 idct_dc_add = s->dsp.h264_idct8_dc_add; | 1163 idct_dc_add = h->h264dsp.h264_idct8_dc_add; |
1163 idct_add = s->dsp.h264_idct8_add; | 1164 idct_add = h->h264dsp.h264_idct8_add; |
1164 } | 1165 } |
1165 for(i=0; i<16; i+=4){ | 1166 for(i=0; i<16; i+=4){ |
1166 uint8_t * const ptr= dest_y + block_offset[i]; | 1167 uint8_t * const ptr= dest_y + block_offset[i]; |
1167 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; | 1168 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; |
1168 if(transform_bypass && h->sps.profile_idc==244 && dir<=1){ | 1169 if(transform_bypass && h->sps.profile_idc==244 && dir<=1){ |
1182 }else{ | 1183 }else{ |
1183 if(transform_bypass){ | 1184 if(transform_bypass){ |
1184 idct_dc_add = | 1185 idct_dc_add = |
1185 idct_add = s->dsp.add_pixels4; | 1186 idct_add = s->dsp.add_pixels4; |
1186 }else{ | 1187 }else{ |
1187 idct_dc_add = s->dsp.h264_idct_dc_add; | 1188 idct_dc_add = h->h264dsp.h264_idct_dc_add; |
1188 idct_add = s->dsp.h264_idct_add; | 1189 idct_add = h->h264dsp.h264_idct_add; |
1189 } | 1190 } |
1190 for(i=0; i<16; i++){ | 1191 for(i=0; i<16; i++){ |
1191 uint8_t * const ptr= dest_y + block_offset[i]; | 1192 uint8_t * const ptr= dest_y + block_offset[i]; |
1192 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; | 1193 const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; |
1193 | 1194 |
1234 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, simple); | 1235 xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, simple); |
1235 }else if(is_h264){ | 1236 }else if(is_h264){ |
1236 hl_motion(h, dest_y, dest_cb, dest_cr, | 1237 hl_motion(h, dest_y, dest_cb, dest_cr, |
1237 s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, | 1238 s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, |
1238 s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, | 1239 s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, |
1239 s->dsp.weight_h264_pixels_tab, s->dsp.biweight_h264_pixels_tab); | 1240 h->h264dsp.weight_h264_pixels_tab, h->h264dsp.biweight_h264_pixels_tab); |
1240 } | 1241 } |
1241 | 1242 |
1242 | 1243 |
1243 if(!IS_INTRA4x4(mb_type)){ | 1244 if(!IS_INTRA4x4(mb_type)){ |
1244 if(is_h264){ | 1245 if(is_h264){ |
1251 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]) | 1252 if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]) |
1252 s->dsp.add_pixels4(dest_y + block_offset[i], h->mb + i*16, linesize); | 1253 s->dsp.add_pixels4(dest_y + block_offset[i], h->mb + i*16, linesize); |
1253 } | 1254 } |
1254 } | 1255 } |
1255 }else{ | 1256 }else{ |
1256 s->dsp.h264_idct_add16intra(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); | 1257 h->h264dsp.h264_idct_add16intra(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); |
1257 } | 1258 } |
1258 }else if(h->cbp&15){ | 1259 }else if(h->cbp&15){ |
1259 if(transform_bypass){ | 1260 if(transform_bypass){ |
1260 const int di = IS_8x8DCT(mb_type) ? 4 : 1; | 1261 const int di = IS_8x8DCT(mb_type) ? 4 : 1; |
1261 idct_add= IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4; | 1262 idct_add= IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4; |
1264 idct_add(dest_y + block_offset[i], h->mb + i*16, linesize); | 1265 idct_add(dest_y + block_offset[i], h->mb + i*16, linesize); |
1265 } | 1266 } |
1266 } | 1267 } |
1267 }else{ | 1268 }else{ |
1268 if(IS_8x8DCT(mb_type)){ | 1269 if(IS_8x8DCT(mb_type)){ |
1269 s->dsp.h264_idct8_add4(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); | 1270 h->h264dsp.h264_idct8_add4(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); |
1270 }else{ | 1271 }else{ |
1271 s->dsp.h264_idct_add16(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); | 1272 h->h264dsp.h264_idct_add16(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); |
1272 } | 1273 } |
1273 } | 1274 } |
1274 } | 1275 } |
1275 }else{ | 1276 }else{ |
1276 for(i=0; i<16; i++){ | 1277 for(i=0; i<16; i++){ |
1297 } | 1298 } |
1298 }else{ | 1299 }else{ |
1299 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp[0], h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]); | 1300 chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp[0], h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]); |
1300 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp[1], h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]); | 1301 chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp[1], h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]); |
1301 if(is_h264){ | 1302 if(is_h264){ |
1302 idct_add = s->dsp.h264_idct_add; | 1303 idct_add = h->h264dsp.h264_idct_add; |
1303 idct_dc_add = s->dsp.h264_idct_dc_add; | 1304 idct_dc_add = h->h264dsp.h264_idct_dc_add; |
1304 for(i=16; i<16+8; i++){ | 1305 for(i=16; i<16+8; i++){ |
1305 if(h->non_zero_count_cache[ scan8[i] ]) | 1306 if(h->non_zero_count_cache[ scan8[i] ]) |
1306 idct_add (dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize); | 1307 idct_add (dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize); |
1307 else if(h->mb[i*16]) | 1308 else if(h->mb[i*16]) |
1308 idct_dc_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize); | 1309 idct_dc_add(dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize); |
1558 * initialize scan tables | 1559 * initialize scan tables |
1559 */ | 1560 */ |
1560 static void init_scan_tables(H264Context *h){ | 1561 static void init_scan_tables(H264Context *h){ |
1561 MpegEncContext * const s = &h->s; | 1562 MpegEncContext * const s = &h->s; |
1562 int i; | 1563 int i; |
1563 if(s->dsp.h264_idct_add == ff_h264_idct_add_c){ //FIXME little ugly | 1564 if(h->h264dsp.h264_idct_add == ff_h264_idct_add_c){ //FIXME little ugly |
1564 memcpy(h->zigzag_scan, zigzag_scan, 16*sizeof(uint8_t)); | 1565 memcpy(h->zigzag_scan, zigzag_scan, 16*sizeof(uint8_t)); |
1565 memcpy(h-> field_scan, field_scan, 16*sizeof(uint8_t)); | 1566 memcpy(h-> field_scan, field_scan, 16*sizeof(uint8_t)); |
1566 }else{ | 1567 }else{ |
1567 for(i=0; i<16; i++){ | 1568 for(i=0; i<16; i++){ |
1568 #define T(x) (x>>2) | ((x<<2) & 0xF) | 1569 #define T(x) (x>>2) | ((x<<2) & 0xF) |
1569 h->zigzag_scan[i] = T(zigzag_scan[i]); | 1570 h->zigzag_scan[i] = T(zigzag_scan[i]); |
1570 h-> field_scan[i] = T( field_scan[i]); | 1571 h-> field_scan[i] = T( field_scan[i]); |
1571 #undef T | 1572 #undef T |
1572 } | 1573 } |
1573 } | 1574 } |
1574 if(s->dsp.h264_idct8_add == ff_h264_idct8_add_c){ | 1575 if(h->h264dsp.h264_idct8_add == ff_h264_idct8_add_c){ |
1575 memcpy(h->zigzag_scan8x8, ff_zigzag_direct, 64*sizeof(uint8_t)); | 1576 memcpy(h->zigzag_scan8x8, ff_zigzag_direct, 64*sizeof(uint8_t)); |
1576 memcpy(h->zigzag_scan8x8_cavlc, zigzag_scan8x8_cavlc, 64*sizeof(uint8_t)); | 1577 memcpy(h->zigzag_scan8x8_cavlc, zigzag_scan8x8_cavlc, 64*sizeof(uint8_t)); |
1577 memcpy(h->field_scan8x8, field_scan8x8, 64*sizeof(uint8_t)); | 1578 memcpy(h->field_scan8x8, field_scan8x8, 64*sizeof(uint8_t)); |
1578 memcpy(h->field_scan8x8_cavlc, field_scan8x8_cavlc, 64*sizeof(uint8_t)); | 1579 memcpy(h->field_scan8x8_cavlc, field_scan8x8_cavlc, 64*sizeof(uint8_t)); |
1579 }else{ | 1580 }else{ |
3001 if(j&1) block[j]= (block[j]*4 + 2)/5; | 3002 if(j&1) block[j]= (block[j]*4 + 2)/5; |
3002 if(j&4) block[j]= (block[j]*4 + 2)/5; | 3003 if(j&4) block[j]= (block[j]*4 + 2)/5; |
3003 } | 3004 } |
3004 // printf("\n"); | 3005 // printf("\n"); |
3005 | 3006 |
3006 s->dsp.h264_idct_add(ref, block, 4); | 3007 h->h264dsp.h264_idct_add(ref, block, 4); |
3007 /* for(j=0; j<16; j++){ | 3008 /* for(j=0; j<16; j++){ |
3008 printf("%d ", ref[j]); | 3009 printf("%d ", ref[j]); |
3009 } | 3010 } |
3010 printf("\n");*/ | 3011 printf("\n");*/ |
3011 | 3012 |