comparison mpeg12.c @ 2076:23280e1b8dbf libavcodec

better cbp handling and small speedup in mpeg12
author iive
date Sat, 12 Jun 2004 16:51:15 +0000
parents 2faafe7a3db6
children 82816cad0e29
comparison
equal deleted inserted replaced
2075:aae3b4e66560 2076:23280e1b8dbf
1036 1036
1037 static int mpeg_decode_mb(MpegEncContext *s, 1037 static int mpeg_decode_mb(MpegEncContext *s,
1038 DCTELEM block[12][64]) 1038 DCTELEM block[12][64])
1039 { 1039 {
1040 int i, j, k, cbp, val, mb_type, motion_type; 1040 int i, j, k, cbp, val, mb_type, motion_type;
1041 1041 const int mb_block_count = 4 + (1<< s->chroma_format)
1042
1042 dprintf("decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y); 1043 dprintf("decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y);
1043 1044
1044 assert(s->mb_skiped==0); 1045 assert(s->mb_skiped==0);
1045 1046
1046 if (s->mb_skip_run-- != 0) { 1047 if (s->mb_skip_run-- != 0) {
1149 } 1150 }
1150 } 1151 }
1151 #endif 1152 #endif
1152 1153
1153 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { 1154 if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
1154 for(i=0;i<4+(1<<s->chroma_format);i++) { 1155 for(i=0;i<mb_block_count;i++) {
1155 if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0) 1156 if (mpeg2_decode_block_intra(s, s->pblocks[i], i) < 0)
1156 return -1; 1157 return -1;
1157 } 1158 }
1158 } else { 1159 } else {
1159 for(i=0;i<6;i++) { 1160 for(i=0;i<6;i++) {
1333 cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); 1334 cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
1334 if (cbp < 0 || ((cbp == 0) && (s->chroma_format < 2)) ){ 1335 if (cbp < 0 || ((cbp == 0) && (s->chroma_format < 2)) ){
1335 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); 1336 av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y);
1336 return -1; 1337 return -1;
1337 } 1338 }
1338 if(s->chroma_format == 2){//CHROMA422 1339 if(mb_block_count > 6){
1339 cbp|= ( get_bits(&s->gb,2) ) << 6; 1340 cbp<<= mb_block_count-6;
1340 }else 1341 cbp |= get_bits(&s->gb, mb_block_count-6);
1341 if(s->chroma_format > 2){//CHROMA444
1342 cbp|= ( get_bits(&s->gb,6) ) << 6;
1343 } 1342 }
1344 1343
1345 #ifdef HAVE_XVMC 1344 #ifdef HAVE_XVMC
1346 //on 1 we memcpy blocks in xvmcvideo 1345 //on 1 we memcpy blocks in xvmcvideo
1347 if(s->avctx->xvmc_acceleration > 1){ 1346 if(s->avctx->xvmc_acceleration > 1){
1351 } 1350 }
1352 } 1351 }
1353 #endif 1352 #endif
1354 1353
1355 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { 1354 if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
1356 for(i=0;i<6;i++) { 1355 cbp<<= 12-mb_block_count;
1357 if (cbp & (1<<(5-i)) ) { 1356
1357 for(i=0;i<mb_block_count;i++) {
1358 if ( cbp & (1<<11) ) {
1358 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0) 1359 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
1359 return -1; 1360 return -1;
1360 } else { 1361 } else {
1361 s->block_last_index[i] = -1; 1362 s->block_last_index[i] = -1;
1362 } 1363 }
1363 } 1364 cbp+=cbp;
1364 if (s->chroma_format >= 2) {
1365 if (s->chroma_format == 2) {//CHROMA_422)
1366 for(i=6;i<8;i++) {
1367 if (cbp & (1<<(6+7-i)) ) {
1368 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
1369 return -1;
1370 } else {
1371 s->block_last_index[i] = -1;
1372 }
1373 }
1374 }else{ /*CHROMA_444*/
1375 for(i=6;i<12;i++) {
1376 if (cbp & (1<<(6+11-i)) ) {
1377 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
1378 return -1;
1379 } else {
1380 s->block_last_index[i] = -1;
1381 }
1382 }
1383 }
1384 } 1365 }
1385 } else { 1366 } else {
1386 for(i=0;i<6;i++) { 1367 for(i=0;i<6;i++) {
1387 if (cbp & 32) { 1368 if (cbp & 32) {
1388 if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0) 1369 if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0)
3011 2992
3012 #ifdef HAVE_XVMC 2993 #ifdef HAVE_XVMC
3013 static int mpeg_mc_decode_init(AVCodecContext *avctx){ 2994 static int mpeg_mc_decode_init(AVCodecContext *avctx){
3014 Mpeg1Context *s; 2995 Mpeg1Context *s;
3015 2996
2997 if( avctx->thread_count > 1)
2998 return -1;
3016 if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) ) 2999 if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
3017 return -1; 3000 return -1;
3018 if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){ 3001 if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){
3019 dprintf("mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n"); 3002 dprintf("mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n");
3020 } 3003 }