comparison h264_cabac.c @ 11275:63d329cd8d80 libavcodec

Calculate mvd without abs() same speed (ask gcc why, i dont know)
author michael
date Wed, 24 Feb 2010 18:50:02 +0000
parents f4b0ebc8c9ad
children c12d6c6c027e
comparison
equal deleted inserted replaced
11274:f4b0ebc8c9ad 11275:63d329cd8d80
907 } 907 }
908 } 908 }
909 return ref; 909 return ref;
910 } 910 }
911 911
912 static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd ) { 912 static int decode_cabac_mb_mvd( H264Context *h, int ctxbase, int amvd, int *mvda) {
913 int mvd; 913 int mvd;
914 914
915 if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+(amvd>2)+(amvd>32)])) 915 if(!get_cabac(&h->cabac, &h->cabac_state[ctxbase+(amvd>2)+(amvd>32)])){
916 *mvda= 0;
916 return 0; 917 return 0;
918 }
917 919
918 mvd= 1; 920 mvd= 1;
919 ctxbase+= 3; 921 ctxbase+= 3;
920 while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase] ) ) { 922 while( mvd < 9 && get_cabac( &h->cabac, &h->cabac_state[ctxbase] ) ) {
921 if( mvd < 4 ) 923 if( mvd < 4 )
935 } 937 }
936 while( k-- ) { 938 while( k-- ) {
937 mvd += get_cabac_bypass( &h->cabac )<<k; 939 mvd += get_cabac_bypass( &h->cabac )<<k;
938 } 940 }
939 } 941 }
942 *mvda=mvd;
940 return get_cabac_bypass_sign( &h->cabac, -mvd ); 943 return get_cabac_bypass_sign( &h->cabac, -mvd );
941 } 944 }
942 945
943 #define DECODE_CABAC_MB_MVD( h, list, n )\ 946 #define DECODE_CABAC_MB_MVD( h, list, n )\
944 {\ 947 {\
945 int amvd0 = h->mvd_cache[list][scan8[n] - 1][0] +\ 948 int amvd0 = h->mvd_cache[list][scan8[n] - 1][0] +\
946 h->mvd_cache[list][scan8[n] - 8][0];\ 949 h->mvd_cache[list][scan8[n] - 8][0];\
947 int amvd1 = h->mvd_cache[list][scan8[n] - 1][1] +\ 950 int amvd1 = h->mvd_cache[list][scan8[n] - 1][1] +\
948 h->mvd_cache[list][scan8[n] - 8][1];\ 951 h->mvd_cache[list][scan8[n] - 8][1];\
949 \ 952 \
950 mx = mpx + decode_cabac_mb_mvd( h, 40, amvd0 );\ 953 mx += decode_cabac_mb_mvd( h, 40, amvd0, &mpx );\
951 my = mpy + decode_cabac_mb_mvd( h, 47, amvd1 );\ 954 my += decode_cabac_mb_mvd( h, 47, amvd1, &mpy );\
952 } 955 }
953 956
954 static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int is_dc ) { 957 static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int is_dc ) {
955 int nza, nzb; 958 int nza, nzb;
956 int ctx = 0; 959 int ctx = 0;
1437 int mpx, mpy; 1440 int mpx, mpy;
1438 int mx, my; 1441 int mx, my;
1439 const int index= 4*i + block_width*j; 1442 const int index= 4*i + block_width*j;
1440 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ]; 1443 int16_t (* mv_cache)[2]= &h->mv_cache[list][ scan8[index] ];
1441 int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ]; 1444 int16_t (* mvd_cache)[2]= &h->mvd_cache[list][ scan8[index] ];
1442 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mpx, &mpy); 1445 pred_motion(h, index, block_width, list, h->ref_cache[list][ scan8[index] ], &mx, &my);
1443 1446
1444 DECODE_CABAC_MB_MVD( h, list, index) 1447 DECODE_CABAC_MB_MVD( h, list, index)
1445 tprintf(s->avctx, "final mv:%d %d\n", mx, my); 1448 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
1446 1449
1447 mpx= abs(mpx-mx);
1448 mpy= abs(mpy-my);
1449 if(IS_SUB_8X8(sub_mb_type)){ 1450 if(IS_SUB_8X8(sub_mb_type)){
1450 mv_cache[ 1 ][0]= 1451 mv_cache[ 1 ][0]=
1451 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx; 1452 mv_cache[ 8 ][0]= mv_cache[ 9 ][0]= mx;
1452 mv_cache[ 1 ][1]= 1453 mv_cache[ 1 ][1]=
1453 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my; 1454 mv_cache[ 8 ][1]= mv_cache[ 9 ][1]= my;
1485 ff_h264_pred_direct_motion(h, &mb_type); 1486 ff_h264_pred_direct_motion(h, &mb_type);
1486 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4); 1487 fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4);
1487 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4); 1488 fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4);
1488 dct8x8_allowed &= h->sps.direct_8x8_inference_flag; 1489 dct8x8_allowed &= h->sps.direct_8x8_inference_flag;
1489 } else { 1490 } else {
1490 int list, mx, my, i, mpx, mpy; 1491 int list, i;
1491 if(IS_16X16(mb_type)){ 1492 if(IS_16X16(mb_type)){
1492 for(list=0; list<h->list_count; list++){ 1493 for(list=0; list<h->list_count; list++){
1493 if(IS_DIR(mb_type, 0, list)){ 1494 if(IS_DIR(mb_type, 0, list)){
1494 int ref; 1495 int ref;
1495 if(h->ref_count[list] > 1){ 1496 if(h->ref_count[list] > 1){
1504 }else 1505 }else
1505 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1); //FIXME factorize and the other fill_rect below too 1506 fill_rectangle(&h->ref_cache[list][ scan8[0] ], 4, 4, 8, (uint8_t)LIST_NOT_USED, 1); //FIXME factorize and the other fill_rect below too
1506 } 1507 }
1507 for(list=0; list<h->list_count; list++){ 1508 for(list=0; list<h->list_count; list++){
1508 if(IS_DIR(mb_type, 0, list)){ 1509 if(IS_DIR(mb_type, 0, list)){
1509 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mpx, &mpy); 1510 int mx,my,mpx,mpy;
1511 pred_motion(h, 0, 4, list, h->ref_cache[list][ scan8[0] ], &mx, &my);
1510 DECODE_CABAC_MB_MVD( h, list, 0) 1512 DECODE_CABAC_MB_MVD( h, list, 0)
1511 tprintf(s->avctx, "final mv:%d %d\n", mx, my); 1513 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
1512 1514
1513 fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(abs(mx-mpx),abs(my-mpy)), 4); 1515 fill_rectangle(h->mvd_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mpx,mpy), 4);
1514 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4); 1516 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, pack16to32(mx,my), 4);
1515 }else 1517 }else
1516 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4); 1518 fill_rectangle(h->mv_cache[list][ scan8[0] ], 4, 4, 8, 0, 4);
1517 } 1519 }
1518 } 1520 }
1535 } 1537 }
1536 } 1538 }
1537 for(list=0; list<h->list_count; list++){ 1539 for(list=0; list<h->list_count; list++){
1538 for(i=0; i<2; i++){ 1540 for(i=0; i<2; i++){
1539 if(IS_DIR(mb_type, i, list)){ 1541 if(IS_DIR(mb_type, i, list)){
1540 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mpx, &mpy); 1542 int mx,my,mpx,mpy;
1543 pred_16x8_motion(h, 8*i, list, h->ref_cache[list][scan8[0] + 16*i], &mx, &my);
1541 DECODE_CABAC_MB_MVD( h, list, 8*i) 1544 DECODE_CABAC_MB_MVD( h, list, 8*i)
1542 tprintf(s->avctx, "final mv:%d %d\n", mx, my); 1545 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
1543 1546
1544 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(abs(mx-mpx),abs(my-mpy)), 4); 1547 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mpx,mpy), 4);
1545 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4); 1548 fill_rectangle(h->mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, pack16to32(mx,my), 4);
1546 }else{ 1549 }else{
1547 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); 1550 fill_rectangle(h->mvd_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);
1548 fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4); 1551 fill_rectangle(h-> mv_cache[list][ scan8[0] + 16*i ], 4, 2, 8, 0, 4);
1549 } 1552 }
1569 } 1572 }
1570 } 1573 }
1571 for(list=0; list<h->list_count; list++){ 1574 for(list=0; list<h->list_count; list++){
1572 for(i=0; i<2; i++){ 1575 for(i=0; i<2; i++){
1573 if(IS_DIR(mb_type, i, list)){ 1576 if(IS_DIR(mb_type, i, list)){
1574 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mpx, &mpy); 1577 int mx,my,mpx,mpy;
1578 pred_8x16_motion(h, i*4, list, h->ref_cache[list][ scan8[0] + 2*i ], &mx, &my);
1575 DECODE_CABAC_MB_MVD( h, list, 4*i) 1579 DECODE_CABAC_MB_MVD( h, list, 4*i)
1576 1580
1577 tprintf(s->avctx, "final mv:%d %d\n", mx, my); 1581 tprintf(s->avctx, "final mv:%d %d\n", mx, my);
1578 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(abs(mx-mpx),abs(my-mpy)), 4); 1582 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mpx,mpy), 4);
1579 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4); 1583 fill_rectangle(h->mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, pack16to32(mx,my), 4);
1580 }else{ 1584 }else{
1581 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); 1585 fill_rectangle(h->mvd_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);
1582 fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4); 1586 fill_rectangle(h-> mv_cache[list][ scan8[0] + 2*i ], 2, 4, 8, 0, 4);
1583 } 1587 }