comparison mpeg12.c @ 2201:ccff80bb955f libavcodec

optional non spec compliant optimizations
author michael
date Thu, 02 Sep 2004 15:30:46 +0000
parents 76334bbb5038
children 8079b177ff5c
comparison
equal deleted inserted replaced
2200:733c60a6e30c 2201:ccff80bb955f
68 DCTELEM *block, 68 DCTELEM *block,
69 int n); 69 int n);
70 static inline int mpeg2_decode_block_intra(MpegEncContext *s, 70 static inline int mpeg2_decode_block_intra(MpegEncContext *s,
71 DCTELEM *block, 71 DCTELEM *block,
72 int n); 72 int n);
73 static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n);
73 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); 74 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
74 static void exchange_uv(MpegEncContext *s); 75 static void exchange_uv(MpegEncContext *s);
75 76
76 #ifdef HAVE_XVMC 77 #ifdef HAVE_XVMC
77 extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx); 78 extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx);
1356 } 1357 }
1357 } 1358 }
1358 #endif 1359 #endif
1359 1360
1360 if (s->codec_id == CODEC_ID_MPEG2VIDEO) { 1361 if (s->codec_id == CODEC_ID_MPEG2VIDEO) {
1361 cbp<<= 12-mb_block_count; 1362 if(s->flags2 & CODEC_FLAG2_FAST){
1362 1363 for(i=0;i<6;i++) {
1363 for(i=0;i<mb_block_count;i++) { 1364 if(cbp & 32) {
1364 if ( cbp & (1<<11) ) { 1365 mpeg2_fast_decode_block_non_intra(s, s->pblocks[i], i);
1365 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0) 1366 } else {
1366 return -1; 1367 s->block_last_index[i] = -1;
1367 } else { 1368 }
1368 s->block_last_index[i] = -1; 1369 cbp+=cbp;
1369 } 1370 }
1370 cbp+=cbp; 1371 }else{
1372 cbp<<= 12-mb_block_count;
1373
1374 for(i=0;i<mb_block_count;i++) {
1375 if ( cbp & (1<<11) ) {
1376 if (mpeg2_decode_block_non_intra(s, s->pblocks[i], i) < 0)
1377 return -1;
1378 } else {
1379 s->block_last_index[i] = -1;
1380 }
1381 cbp+=cbp;
1382 }
1371 } 1383 }
1372 } else { 1384 } else {
1373 for(i=0;i<6;i++) { 1385 for(i=0;i<6;i++) {
1374 if (cbp & 32) { 1386 if (cbp & 32) {
1375 if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0) 1387 if (mpeg1_decode_block_inter(s, s->pblocks[i], i) < 0)
1590 } 1602 }
1591 s->block_last_index[n] = i; 1603 s->block_last_index[n] = i;
1592 return 0; 1604 return 0;
1593 } 1605 }
1594 1606
1595 /* Also does unquantization here, since I will never support mpeg2
1596 encoding */
1597 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, 1607 static inline int mpeg2_decode_block_non_intra(MpegEncContext *s,
1598 DCTELEM *block, 1608 DCTELEM *block,
1599 int n) 1609 int n)
1600 { 1610 {
1601 int level, i, j, run; 1611 int level, i, j, run;
1670 block[63] ^= (mismatch & 1); 1680 block[63] ^= (mismatch & 1);
1671 1681
1672 s->block_last_index[n] = i; 1682 s->block_last_index[n] = i;
1673 return 0; 1683 return 0;
1674 } 1684 }
1685
1686 static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s,
1687 DCTELEM *block,
1688 int n)
1689 {
1690 int level, i, j, run;
1691 RLTable *rl = &rl_mpeg1;
1692 uint8_t * const scantable= s->intra_scantable.permutated;
1693 const int qscale= s->qscale;
1694 int v;
1695 OPEN_READER(re, &s->gb);
1696 i = -1;
1697
1698 /* special case for the first coef. no need to add a second vlc table */
1699 UPDATE_CACHE(re, &s->gb);
1700 v= SHOW_UBITS(re, &s->gb, 2);
1701 if (v & 2) {
1702 LAST_SKIP_BITS(re, &s->gb, 2);
1703 level= (3*qscale)>>1;
1704 if(v&1)
1705 level= -level;
1706 block[0] = level;
1707 i++;
1708 }
1709
1710 /* now quantify & encode AC coefs */
1711 for(;;) {
1712 UPDATE_CACHE(re, &s->gb);
1713 GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2);
1714
1715 if(level == 127){
1716 break;
1717 } else if(level != 0) {
1718 i += run;
1719 j = scantable[i];
1720 level= ((level*2+1)*qscale)>>1;
1721 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
1722 LAST_SKIP_BITS(re, &s->gb, 1);
1723 } else {
1724 /* escape */
1725 run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6);
1726 UPDATE_CACHE(re, &s->gb);
1727 level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12);
1728
1729 i += run;
1730 j = scantable[i];
1731 if(level<0){
1732 level= ((-level*2+1)*qscale)>>1;
1733 level= -level;
1734 }else{
1735 level= ((level*2+1)*qscale)>>1;
1736 }
1737 }
1738
1739 block[j] = level;
1740 }
1741 CLOSE_READER(re, &s->gb);
1742 s->block_last_index[n] = i;
1743 return 0;
1744 }
1745
1675 1746
1676 static inline int mpeg2_decode_block_intra(MpegEncContext *s, 1747 static inline int mpeg2_decode_block_intra(MpegEncContext *s,
1677 DCTELEM *block, 1748 DCTELEM *block,
1678 int n) 1749 int n)
1679 { 1750 {