comparison mpeg12.c @ 545:6df843af36cb libavcodec

optimization (get_vlc() -> get_vlc2())
author michaelni
date Sat, 13 Jul 2002 16:10:27 +0000
parents 3c07cf9595de
children 26971b5a271d
comparison
equal deleted inserted replaced
544:5264fb104700 545:6df843af36cb
531 static VLC mbincr_vlc; 531 static VLC mbincr_vlc;
532 static VLC mb_ptype_vlc; 532 static VLC mb_ptype_vlc;
533 static VLC mb_btype_vlc; 533 static VLC mb_btype_vlc;
534 static VLC mb_pat_vlc; 534 static VLC mb_pat_vlc;
535 535
536 #define DC_VLC_BITS 9
537 #define MV_VLC_BITS 9
538 #define MBINCR_VLC_BITS 9
539 #define MB_PAT_VLC_BITS 9
540 #define MB_PTYPE_VLC_BITS 6
541 #define MB_BTYPE_VLC_BITS 6
542 #define TEX_VLC_BITS 9
543
536 void mpeg1_init_vlc(MpegEncContext *s) 544 void mpeg1_init_vlc(MpegEncContext *s)
537 { 545 {
538 static int done = 0; 546 static int done = 0;
539 547
540 if (!done) { 548 if (!done) {
541 done = 1; 549 done = 1;
542 550
543 init_vlc(&dc_lum_vlc, 9, 12, 551 init_vlc(&dc_lum_vlc, DC_VLC_BITS, 10/*12*/,
544 vlc_dc_lum_bits, 1, 1, 552 vlc_dc_lum_bits, 1, 1,
545 vlc_dc_lum_code, 2, 2); 553 vlc_dc_lum_code, 2, 2);
546 init_vlc(&dc_chroma_vlc, 9, 12, 554 init_vlc(&dc_chroma_vlc, DC_VLC_BITS, 10/*12*/,
547 vlc_dc_chroma_bits, 1, 1, 555 vlc_dc_chroma_bits, 1, 1,
548 vlc_dc_chroma_code, 2, 2); 556 vlc_dc_chroma_code, 2, 2);
549 init_vlc(&mv_vlc, 9, 17, 557 init_vlc(&mv_vlc, MV_VLC_BITS, 17,
550 &mbMotionVectorTable[0][1], 2, 1, 558 &mbMotionVectorTable[0][1], 2, 1,
551 &mbMotionVectorTable[0][0], 2, 1); 559 &mbMotionVectorTable[0][0], 2, 1);
552 init_vlc(&mbincr_vlc, 9, 35, 560 init_vlc(&mbincr_vlc, MBINCR_VLC_BITS, 35,
553 &mbAddrIncrTable[0][1], 2, 1, 561 &mbAddrIncrTable[0][1], 2, 1,
554 &mbAddrIncrTable[0][0], 2, 1); 562 &mbAddrIncrTable[0][0], 2, 1);
555 init_vlc(&mb_pat_vlc, 9, 63, 563 init_vlc(&mb_pat_vlc, MB_PAT_VLC_BITS, 63,
556 &mbPatTable[0][1], 2, 1, 564 &mbPatTable[0][1], 2, 1,
557 &mbPatTable[0][0], 2, 1); 565 &mbPatTable[0][0], 2, 1);
558 566
559 init_vlc(&mb_ptype_vlc, 6, 32, 567 init_vlc(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 32,
560 &table_mb_ptype[0][1], 2, 1, 568 &table_mb_ptype[0][1], 2, 1,
561 &table_mb_ptype[0][0], 2, 1); 569 &table_mb_ptype[0][0], 2, 1);
562 init_vlc(&mb_btype_vlc, 6, 32, 570 init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 32,
563 &table_mb_btype[0][1], 2, 1, 571 &table_mb_btype[0][1], 2, 1,
564 &table_mb_btype[0][0], 2, 1); 572 &table_mb_btype[0][0], 2, 1);
565 init_rl(&rl_mpeg1); 573 init_rl(&rl_mpeg1);
566 init_rl(&rl_mpeg2); 574 init_rl(&rl_mpeg2);
567 /* cannot use generic init because we must add the EOB code */ 575 /* cannot use generic init because we must add the EOB code */
568 init_vlc(&rl_mpeg1.vlc, 9, rl_mpeg1.n + 2, 576 init_vlc(&rl_mpeg1.vlc, TEX_VLC_BITS, rl_mpeg1.n + 2,
569 &rl_mpeg1.table_vlc[0][1], 4, 2, 577 &rl_mpeg1.table_vlc[0][1], 4, 2,
570 &rl_mpeg1.table_vlc[0][0], 4, 2); 578 &rl_mpeg1.table_vlc[0][0], 4, 2);
571 init_vlc(&rl_mpeg2.vlc, 9, rl_mpeg2.n + 2, 579 init_vlc(&rl_mpeg2.vlc, TEX_VLC_BITS, rl_mpeg2.n + 2,
572 &rl_mpeg2.table_vlc[0][1], 4, 2, 580 &rl_mpeg2.table_vlc[0][1], 4, 2,
573 &rl_mpeg2.table_vlc[0][0], 4, 2); 581 &rl_mpeg2.table_vlc[0][0], 4, 2);
574 } 582 }
575 } 583 }
576 584
612 /* skip mb handling */ 620 /* skip mb handling */
613 if (s->mb_incr == 0) { 621 if (s->mb_incr == 0) {
614 /* read again increment */ 622 /* read again increment */
615 s->mb_incr = 1; 623 s->mb_incr = 1;
616 for(;;) { 624 for(;;) {
617 code = get_vlc(&s->gb, &mbincr_vlc); 625 code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
618 if (code < 0) 626 if (code < 0)
619 return 1; /* error = end of slice */ 627 return 1; /* error = end of slice */
620 if (code >= 33) { 628 if (code >= 33) {
621 if (code == 33) { 629 if (code == 33) {
622 s->mb_incr += 33; 630 s->mb_incr += 33;
669 } else { 677 } else {
670 mb_type = MB_INTRA; 678 mb_type = MB_INTRA;
671 } 679 }
672 break; 680 break;
673 case P_TYPE: 681 case P_TYPE:
674 mb_type = get_vlc(&s->gb, &mb_ptype_vlc); 682 mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1);
675 if (mb_type < 0) 683 if (mb_type < 0)
676 return -1; 684 return -1;
677 break; 685 break;
678 case B_TYPE: 686 case B_TYPE:
679 mb_type = get_vlc(&s->gb, &mb_btype_vlc); 687 mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1);
680 if (mb_type < 0) 688 if (mb_type < 0)
681 return -1; 689 return -1;
682 break; 690 break;
683 } 691 }
684 dprintf("mb_type=%x\n", mb_type); 692 dprintf("mb_type=%x\n", mb_type);
844 if ((mb_type & MB_INTRA) && s->concealment_motion_vectors) { 852 if ((mb_type & MB_INTRA) && s->concealment_motion_vectors) {
845 skip_bits1(&s->gb); /* marker */ 853 skip_bits1(&s->gb); /* marker */
846 } 854 }
847 855
848 if (mb_type & MB_PAT) { 856 if (mb_type & MB_PAT) {
849 cbp = get_vlc(&s->gb, &mb_pat_vlc); 857 cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1);
850 if (cbp < 0) 858 if (cbp < 0)
851 return -1; 859 return -1;
852 cbp++; 860 cbp++;
853 } 861 }
854 dprintf("cbp=%x\n", cbp); 862 dprintf("cbp=%x\n", cbp);
889 /* as h263, but only 17 codes */ 897 /* as h263, but only 17 codes */
890 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) 898 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
891 { 899 {
892 int code, sign, val, m, l, shift; 900 int code, sign, val, m, l, shift;
893 901
894 code = get_vlc(&s->gb, &mv_vlc); 902 code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
895 if (code < 0) { 903 if (code < 0) {
896 return 0xffff; 904 return 0xffff;
897 } 905 }
898 if (code == 0) { 906 if (code == 0) {
899 return pred; 907 return pred;
922 static inline int decode_dc(MpegEncContext *s, int component) 930 static inline int decode_dc(MpegEncContext *s, int component)
923 { 931 {
924 int code, diff; 932 int code, diff;
925 933
926 if (component == 0) { 934 if (component == 0) {
927 code = get_vlc(&s->gb, &dc_lum_vlc); 935 code = get_vlc2(&s->gb, dc_lum_vlc.table, DC_VLC_BITS, 1);
928 } else { 936 } else {
929 code = get_vlc(&s->gb, &dc_chroma_vlc); 937 code = get_vlc2(&s->gb, dc_chroma_vlc.table, DC_VLC_BITS, 1);
930 } 938 }
931 if (code < 0) 939 if (code < 0)
932 return 0xffff; 940 return 0xffff;
933 if (code == 0) { 941 if (code == 0) {
934 diff = 0; 942 diff = 0;
977 CLOSE_READER(re, &s->gb); 985 CLOSE_READER(re, &s->gb);
978 } 986 }
979 987
980 /* now quantify & encode AC coefs */ 988 /* now quantify & encode AC coefs */
981 for(;;) { 989 for(;;) {
982 code = get_vlc(&s->gb, &rl->vlc); 990 code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
983 if (code < 0) { 991 if (code < 0) {
984 return -1; 992 return -1;
985 } 993 }
986 if (code == 112) { 994 if (code == 112) {
987 break; 995 break;
1055 CLOSE_READER(re, &s->gb); 1063 CLOSE_READER(re, &s->gb);
1056 } 1064 }
1057 1065
1058 /* now quantify & encode AC coefs */ 1066 /* now quantify & encode AC coefs */
1059 for(;;) { 1067 for(;;) {
1060 code = get_vlc(&s->gb, &rl->vlc); 1068 code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
1061 if (code < 0) 1069 if (code < 0)
1062 return -1; 1070 return -1;
1063 if (code == 112) { 1071 if (code == 112) {
1064 break; 1072 break;
1065 } else if (code == 111) { 1073 } else if (code == 111) {
1134 else 1142 else
1135 matrix = s->chroma_intra_matrix; 1143 matrix = s->chroma_intra_matrix;
1136 1144
1137 /* now quantify & encode AC coefs */ 1145 /* now quantify & encode AC coefs */
1138 for(;;) { 1146 for(;;) {
1139 code = get_vlc(&s->gb, &rl->vlc); 1147 code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2);
1140 if (code < 0) 1148 if (code < 0)
1141 return -1; 1149 return -1;
1142 if (code == 112) { 1150 if (code == 112) {
1143 break; 1151 break;
1144 } else if (code == 111) { 1152 } else if (code == 111) {