Originally committed as revision 4516 to svn://svn.ffmpeg.org/ffmpeg/trunk
Unified · Split
| @@ -620,230 +620,6 @@ static int init_block_mapping(Vp3DecodeContext *s) · 619 unmodified lines | |||
| 620 | return 0; /* successful path out */ | 620 | return 0; /* successful path out */ |
| 621 | } | 621 | } |
| 622 | 622 | ||
| 623 | /* | ||
| 624 | * This function unpacks a single token (which should be in the range 0..31) | ||
| 625 | * and returns a zero run (number of zero coefficients in current DCT matrix | ||
| 626 | * before next non-zero coefficient), the next DCT coefficient, and the | ||
| 627 | * number of consecutive, non-EOB'd DCT blocks to EOB. | ||
| 628 | */ | ||
| 629 | static void unpack_token(GetBitContext *gb, int token, int *zero_run, | ||
| 630 | DCTELEM *coeff, int *eob_run) | ||
| 631 | { | ||
| 632 | int sign; | ||
| 633 | |||
| 634 | *zero_run = 0; | ||
| 635 | *eob_run = 0; | ||
| 636 | *coeff = 0; | ||
| 637 | |||
| 638 | debug_token(" vp3 token %d: ", token); | ||
| 639 | switch (token) { | ||
| 640 | |||
| 641 | case 0: | ||
| 642 | debug_token("DCT_EOB_TOKEN, EOB next block\n"); | ||
| 643 | *eob_run = 1; | ||
| 644 | break; | ||
| 645 | |||
| 646 | case 1: | ||
| 647 | debug_token("DCT_EOB_PAIR_TOKEN, EOB next 2 blocks\n"); | ||
| 648 | *eob_run = 2; | ||
| 649 | break; | ||
| 650 | |||
| 651 | case 2: | ||
| 652 | debug_token("DCT_EOB_TRIPLE_TOKEN, EOB next 3 blocks\n"); | ||
| 653 | *eob_run = 3; | ||
| 654 | break; | ||
| 655 | |||
| 656 | case 3: | ||
| 657 | debug_token("DCT_REPEAT_RUN_TOKEN, "); | ||
| 658 | *eob_run = get_bits(gb, 2) + 4; | ||
| 659 | debug_token("EOB the next %d blocks\n", *eob_run); | ||
| 660 | break; | ||
| 661 | |||
| 662 | case 4: | ||
| 663 | debug_token("DCT_REPEAT_RUN2_TOKEN, "); | ||
| 664 | *eob_run = get_bits(gb, 3) + 8; | ||
| 665 | debug_token("EOB the next %d blocks\n", *eob_run); | ||
| 666 | break; | ||
| 667 | |||
| 668 | case 5: | ||
| 669 | debug_token("DCT_REPEAT_RUN3_TOKEN, "); | ||
| 670 | *eob_run = get_bits(gb, 4) + 16; | ||
| 671 | debug_token("EOB the next %d blocks\n", *eob_run); | ||
| 672 | break; | ||
| 673 | |||
| 674 | case 6: | ||
| 675 | debug_token("DCT_REPEAT_RUN4_TOKEN, "); | ||
| 676 | *eob_run = get_bits(gb, 12); | ||
| 677 | debug_token("EOB the next %d blocks\n", *eob_run); | ||
| 678 | break; | ||
| 679 | |||
| 680 | case 7: | ||
| 681 | debug_token("DCT_SHORT_ZRL_TOKEN, "); | ||
| 682 | /* note that this token actually indicates that (3 extra bits) + 1 0s | ||
| 683 | * should be output; this case specifies a run of (3 EBs) 0s and a | ||
| 684 | * coefficient of 0. */ | ||
| 685 | *zero_run = get_bits(gb, 3); | ||
| 686 | *coeff = 0; | ||
| 687 | debug_token("skip the next %d positions in output matrix\n", *zero_run + 1); | ||
| 688 | break; | ||
| 689 | |||
| 690 | case 8: | ||
| 691 | debug_token("DCT_ZRL_TOKEN, "); | ||
| 692 | /* note that this token actually indicates that (6 extra bits) + 1 0s | ||
| 693 | * should be output; this case specifies a run of (6 EBs) 0s and a | ||
| 694 | * coefficient of 0. */ | ||
| 695 | *zero_run = get_bits(gb, 6); | ||
| 696 | *coeff = 0; | ||
| 697 | debug_token("skip the next %d positions in output matrix\n", *zero_run + 1); | ||
| 698 | break; | ||
| 699 | |||
| 700 | case 9: | ||
| 701 | debug_token("ONE_TOKEN, output 1\n"); | ||
| 702 | *coeff = 1; | ||
| 703 | break; | ||
| 704 | |||
| 705 | case 10: | ||
| 706 | debug_token("MINUS_ONE_TOKEN, output -1\n"); | ||
| 707 | *coeff = -1; | ||
| 708 | break; | ||
| 709 | |||
| 710 | case 11: | ||
| 711 | debug_token("TWO_TOKEN, output 2\n"); | ||
| 712 | *coeff = 2; | ||
| 713 | break; | ||
| 714 | |||
| 715 | case 12: | ||
| 716 | debug_token("MINUS_TWO_TOKEN, output -2\n"); | ||
| 717 | *coeff = -2; | ||
| 718 | break; | ||
| 719 | |||
| 720 | case 13: | ||
| 721 | case 14: | ||
| 722 | case 15: | ||
| 723 | case 16: | ||
| 724 | debug_token("LOW_VAL_TOKENS, "); | ||
| 725 | if (get_bits(gb, 1)) | ||
| 726 | *coeff = -(3 + (token - 13)); | ||
| 727 | else | ||
| 728 | *coeff = 3 + (token - 13); | ||
| 729 | debug_token("output %d\n", *coeff); | ||
| 730 | break; | ||
| 731 | |||
| 732 | case 17: | ||
| 733 | debug_token("DCT_VAL_CATEGORY3, "); | ||
| 734 | sign = get_bits(gb, 1); | ||
| 735 | *coeff = 7 + get_bits(gb, 1); | ||
| 736 | if (sign) | ||
| 737 | *coeff = -(*coeff); | ||
| 738 | debug_token("output %d\n", *coeff); | ||
| 739 | break; | ||
| 740 | |||
| 741 | case 18: | ||
| 742 | debug_token("DCT_VAL_CATEGORY4, "); | ||
| 743 | sign = get_bits(gb, 1); | ||
| 744 | *coeff = 9 + get_bits(gb, 2); | ||
| 745 | if (sign) | ||
| 746 | *coeff = -(*coeff); | ||
| 747 | debug_token("output %d\n", *coeff); | ||
| 748 | break; | ||
| 749 | |||
| 750 | case 19: | ||
| 751 | debug_token("DCT_VAL_CATEGORY5, "); | ||
| 752 | sign = get_bits(gb, 1); | ||
| 753 | *coeff = 13 + get_bits(gb, 3); | ||
| 754 | if (sign) | ||
| 755 | *coeff = -(*coeff); | ||
| 756 | debug_token("output %d\n", *coeff); | ||
| 757 | break; | ||
| 758 | |||
| 759 | case 20: | ||
| 760 | debug_token("DCT_VAL_CATEGORY6, "); | ||
| 761 | sign = get_bits(gb, 1); | ||
| 762 | *coeff = 21 + get_bits(gb, 4); | ||
| 763 | if (sign) | ||
| 764 | *coeff = -(*coeff); | ||
| 765 | debug_token("output %d\n", *coeff); | ||
| 766 | break; | ||
| 767 | |||
| 768 | case 21: | ||
| 769 | debug_token("DCT_VAL_CATEGORY7, "); | ||
| 770 | sign = get_bits(gb, 1); | ||
| 771 | *coeff = 37 + get_bits(gb, 5); | ||
| 772 | if (sign) | ||
| 773 | *coeff = -(*coeff); | ||
| 774 | debug_token("output %d\n", *coeff); | ||
| 775 | break; | ||
| 776 | |||
| 777 | case 22: | ||
| 778 | debug_token("DCT_VAL_CATEGORY8, "); | ||
| 779 | sign = get_bits(gb, 1); | ||
| 780 | *coeff = 69 + get_bits(gb, 9); | ||
| 781 | if (sign) | ||
| 782 | *coeff = -(*coeff); | ||
| 783 | debug_token("output %d\n", *coeff); | ||
| 784 | break; | ||
| 785 | |||
| 786 | case 23: | ||
| 787 | case 24: | ||
| 788 | case 25: | ||
| 789 | case 26: | ||
| 790 | case 27: | ||
| 791 | debug_token("DCT_RUN_CATEGORY1, "); | ||
| 792 | *zero_run = token - 22; | ||
| 793 | if (get_bits(gb, 1)) | ||
| 794 | *coeff = -1; | ||
| 795 | else | ||
| 796 | *coeff = 1; | ||
| 797 | debug_token("output %d 0s, then %d\n", *zero_run, *coeff); | ||
| 798 | break; | ||
| 799 | |||
| 800 | case 28: | ||
| 801 | debug_token("DCT_RUN_CATEGORY1B, "); | ||
| 802 | if (get_bits(gb, 1)) | ||
| 803 | *coeff = -1; | ||
| 804 | else | ||
| 805 | *coeff = 1; | ||
| 806 | *zero_run = 6 + get_bits(gb, 2); | ||
| 807 | debug_token("output %d 0s, then %d\n", *zero_run, *coeff); | ||
| 808 | break; | ||
| 809 | |||
| 810 | case 29: | ||
| 811 | debug_token("DCT_RUN_CATEGORY1C, "); | ||
| 812 | if (get_bits(gb, 1)) | ||
| 813 | *coeff = -1; | ||
| 814 | else | ||
| 815 | *coeff = 1; | ||
| 816 | *zero_run = 10 + get_bits(gb, 3); | ||
| 817 | debug_token("output %d 0s, then %d\n", *zero_run, *coeff); | ||
| 818 | break; | ||
| 819 | |||
| 820 | case 30: | ||
| 821 | debug_token("DCT_RUN_CATEGORY2, "); | ||
| 822 | sign = get_bits(gb, 1); | ||
| 823 | *coeff = 2 + get_bits(gb, 1); | ||
| 824 | if (sign) | ||
| 825 | *coeff = -(*coeff); | ||
| 826 | *zero_run = 1; | ||
| 827 | debug_token("output %d 0s, then %d\n", *zero_run, *coeff); | ||
| 828 | break; | ||
| 829 | |||
| 830 | case 31: | ||
| 831 | debug_token("DCT_RUN_CATEGORY2, "); | ||
| 832 | sign = get_bits(gb, 1); | ||
| 833 | *coeff = 2 + get_bits(gb, 1); | ||
| 834 | if (sign) | ||
| 835 | *coeff = -(*coeff); | ||
| 836 | *zero_run = 2 + get_bits(gb, 1); | ||
| 837 | debug_token("output %d 0s, then %d\n", *zero_run, *coeff); | ||
| 838 | break; | ||
| 839 | |||
| 840 | default: | ||
| 841 | av_log(NULL, AV_LOG_ERROR, " vp3: help! Got a bad token: %d > 31\n", token); | ||
| 842 | break; | ||
| 843 | |||
| 844 | } | ||
| 845 | } | ||
| 846 | |||
| 847 | /* | 623 | /* |
| 848 | * This function wipes out all of the fragment data. | 624 | * This function wipes out all of the fragment data. |
| 849 | */ | 625 | */ |
| @@ -982,213 +758,6 @@ static void init_loop_filter(Vp3DecodeContext *s) · 132 unmodified lines | |||
| 982 | } | 758 | } |
| 983 | } | 759 | } |
| 984 | 760 | ||
| 985 | /* | ||
| 986 | * This function is used to fetch runs of 1s or 0s from the bitstream for | ||
| 987 | * use in determining which superblocks are fully and partially coded. | ||
| 988 | * | ||
| 989 | * Codeword RunLength | ||
| 990 | * 0 1 | ||
| 991 | * 10x 2-3 | ||
| 992 | * 110x 4-5 | ||
| 993 | * 1110xx 6-9 | ||
| 994 | * 11110xxx 10-17 | ||
| 995 | * 111110xxxx 18-33 | ||
| 996 | * 111111xxxxxxxxxxxx 34-4129 | ||
| 997 | */ | ||
| 998 | static int get_superblock_run_length(GetBitContext *gb) | ||
| 999 | { | ||
| 1000 | |||
| 1001 | if (get_bits(gb, 1) == 0) | ||
| 1002 | return 1; | ||
| 1003 | |||
| 1004 | else if (get_bits(gb, 1) == 0) | ||
| 1005 | return (2 + get_bits(gb, 1)); | ||
| 1006 | |||
| 1007 | else if (get_bits(gb, 1) == 0) | ||
| 1008 | return (4 + get_bits(gb, 1)); | ||
| 1009 | |||
| 1010 | else if (get_bits(gb, 1) == 0) | ||
| 1011 | return (6 + get_bits(gb, 2)); | ||
| 1012 | |||
| 1013 | else if (get_bits(gb, 1) == 0) | ||
| 1014 | return (10 + get_bits(gb, 3)); | ||
| 1015 | |||
| 1016 | else if (get_bits(gb, 1) == 0) | ||
| 1017 | return (18 + get_bits(gb, 4)); | ||
| 1018 | |||
| 1019 | else | ||
| 1020 | return (34 + get_bits(gb, 12)); | ||
| 1021 | |||
| 1022 | } | ||
| 1023 | |||
| 1024 | /* | ||
| 1025 | * This function is used to fetch runs of 1s or 0s from the bitstream for | ||
| 1026 | * use in determining which particular fragments are coded. | ||
| 1027 | * | ||
| 1028 | * Codeword RunLength | ||
| 1029 | * 0x 1-2 | ||
| 1030 | * 10x 3-4 | ||
| 1031 | * 110x 5-6 | ||
| 1032 | * 1110xx 7-10 | ||
| 1033 | * 11110xx 11-14 | ||
| 1034 | * 11111xxxx 15-30 | ||
| 1035 | */ | ||
| 1036 | static int get_fragment_run_length(GetBitContext *gb) | ||
| 1037 | { | ||
| 1038 | |||
| 1039 | if (get_bits(gb, 1) == 0) | ||
| 1040 | return (1 + get_bits(gb, 1)); | ||
| 1041 | |||
| 1042 | else if (get_bits(gb, 1) == 0) | ||
| 1043 | return (3 + get_bits(gb, 1)); | ||
| 1044 | |||
| 1045 | else if (get_bits(gb, 1) == 0) | ||
| 1046 | return (5 + get_bits(gb, 1)); | ||
| 1047 | |||
| 1048 | else if (get_bits(gb, 1) == 0) | ||
| 1049 | return (7 + get_bits(gb, 2)); | ||
| 1050 | |||
| 1051 | else if (get_bits(gb, 1) == 0) | ||
| 1052 | return (11 + get_bits(gb, 2)); | ||
| 1053 | |||
| 1054 | else | ||
| 1055 | return (15 + get_bits(gb, 4)); | ||
| 1056 | |||
| 1057 | } | ||
| 1058 | |||
| 1059 | /* | ||
| 1060 | * This function decodes a VLC from the bitstream and returns a number | ||
| 1061 | * that ranges from 0..7. The number indicates which of the 8 coding | ||
| 1062 | * modes to use. | ||
| 1063 | * | ||
| 1064 | * VLC Number | ||
| 1065 | * 0 0 | ||
| 1066 | * 10 1 | ||
| 1067 | * 110 2 | ||
| 1068 | * 1110 3 | ||
| 1069 | * 11110 4 | ||
| 1070 | * 111110 5 | ||
| 1071 | * 1111110 6 | ||
| 1072 | * 1111111 7 | ||
| 1073 | * | ||
| 1074 | */ | ||
| 1075 | static int get_mode_code(GetBitContext *gb) | ||
| 1076 | { | ||
| 1077 | |||
| 1078 | if (get_bits(gb, 1) == 0) | ||
| 1079 | return 0; | ||
| 1080 | |||
| 1081 | else if (get_bits(gb, 1) == 0) | ||
| 1082 | return 1; | ||
| 1083 | |||
| 1084 | else if (get_bits(gb, 1) == 0) | ||
| 1085 | return 2; | ||
| 1086 | |||
| 1087 | else if (get_bits(gb, 1) == 0) | ||
| 1088 | return 3; | ||
| 1089 | |||
| 1090 | else if (get_bits(gb, 1) == 0) | ||
| 1091 | return 4; | ||
| 1092 | |||
| 1093 | else if (get_bits(gb, 1) == 0) | ||
| 1094 | return 5; | ||
| 1095 | |||
| 1096 | else if (get_bits(gb, 1) == 0) | ||
| 1097 | return 6; | ||
| 1098 | |||
| 1099 | else | ||
| 1100 | return 7; | ||
| 1101 | |||
| 1102 | } | ||
| 1103 | |||
| 1104 | /* | ||
| 1105 | * This function extracts a motion vector from the bitstream using a VLC | ||
| 1106 | * scheme. 3 bits are fetched from the bitstream and 1 of 8 actions is | ||
| 1107 | * taken depending on the value on those 3 bits: | ||
| 1108 | * | ||
| 1109 | * 0: return 0 | ||
| 1110 | * 1: return 1 | ||
| 1111 | * 2: return -1 | ||
| 1112 | * 3: if (next bit is 1) return -2, else return 2 | ||
| 1113 | * 4: if (next bit is 1) return -3, else return 3 | ||
| 1114 | * 5: return 4 + (next 2 bits), next bit is sign | ||
| 1115 | * 6: return 8 + (next 3 bits), next bit is sign | ||
| 1116 | * 7: return 16 + (next 4 bits), next bit is sign | ||
| 1117 | */ | ||
| 1118 | static int get_motion_vector_vlc(GetBitContext *gb) | ||
| 1119 | { | ||
| 1120 | int bits; | ||
| 1121 | |||
| 1122 | bits = get_bits(gb, 3); | ||
| 1123 | |||
| 1124 | switch(bits) { | ||
| 1125 | |||
| 1126 | case 0: | ||
| 1127 | bits = 0; | ||
| 1128 | break; | ||
| 1129 | |||
| 1130 | case 1: | ||
| 1131 | bits = 1; | ||
| 1132 | break; | ||
| 1133 | |||
| 1134 | case 2: | ||
| 1135 | bits = -1; | ||
| 1136 | break; | ||
| 1137 | |||
| 1138 | case 3: | ||
| 1139 | if (get_bits(gb, 1) == 0) | ||
| 1140 | bits = 2; | ||
| 1141 | else | ||
| 1142 | bits = -2; | ||
| 1143 | break; | ||
| 1144 | |||
| 1145 | case 4: | ||
| 1146 | if (get_bits(gb, 1) == 0) | ||
| 1147 | bits = 3; | ||
| 1148 | else | ||
| 1149 | bits = -3; | ||
| 1150 | break; | ||
| 1151 | |||
| 1152 | case 5: | ||
| 1153 | bits = 4 + get_bits(gb, 2); | ||
| 1154 | if (get_bits(gb, 1) == 1) | ||
| 1155 | bits = -bits; | ||
| 1156 | break; | ||
| 1157 | |||
| 1158 | case 6: | ||
| 1159 | bits = 8 + get_bits(gb, 3); | ||
| 1160 | if (get_bits(gb, 1) == 1) | ||
| 1161 | bits = -bits; | ||
| 1162 | break; | ||
| 1163 | |||
| 1164 | case 7: | ||
| 1165 | bits = 16 + get_bits(gb, 4); | ||
| 1166 | if (get_bits(gb, 1) == 1) | ||
| 1167 | bits = -bits; | ||
| 1168 | break; | ||
| 1169 | |||
| 1170 | } | ||
| 1171 | |||
| 1172 | return bits; | ||
| 1173 | } | ||
| 1174 | |||
| 1175 | /* | ||
| 1176 | * This function fetches a 5-bit number from the stream followed by | ||
| 1177 | * a sign and calls it a motion vector. | ||
| 1178 | */ | ||
| 1179 | static int get_motion_vector_fixed(GetBitContext *gb) | ||
| 1180 | { | ||
| 1181 | |||
| 1182 | int bits; | ||
| 1183 | |||
| 1184 | bits = get_bits(gb, 5); | ||
| 1185 | |||
| 1186 | if (get_bits(gb, 1) == 1) | ||
| 1187 | bits = -bits; | ||
| 1188 | |||
| 1189 | return bits; | ||
| 1190 | } | ||
| 1191 | |||
| 1192 | /* | 761 | /* |
| 1193 | * This function unpacks all of the superblock/macroblock/fragment coding | 762 | * This function unpacks all of the superblock/macroblock/fragment coding |
| 1194 | * information from the bitstream. | 763 | * information from the bitstream. |
| @@ -1222,14 +791,10 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) · 27 unmodified lines | |||
| 1222 | while (current_superblock < s->superblock_count) { | 791 | while (current_superblock < s->superblock_count) { |
| 1223 | if (current_run-- == 0) { | 792 | if (current_run-- == 0) { |
| 1224 | bit ^= 1; | 793 | bit ^= 1; |
| 1225 | #if 1 | ||
| 1226 | current_run = get_vlc2(gb, | 794 | current_run = get_vlc2(gb, |
| 1227 | s->superblock_run_length_vlc.table, 6, 2); | 795 | s->superblock_run_length_vlc.table, 6, 2); |
| 1228 | if (current_run == 33) | 796 | if (current_run == 33) |
| 1229 | current_run += get_bits(gb, 12); | 797 | current_run += get_bits(gb, 12); |
| 1230 | #else | ||
| 1231 | current_run = get_superblock_run_length(gb); | ||
| 1232 | #endif | ||
| 1233 | debug_block_coding(" setting superblocks %d..%d to %s\n", | 798 | debug_block_coding(" setting superblocks %d..%d to %s\n", |
| 1234 | current_superblock, | 799 | current_superblock, |
| 1235 | current_superblock + current_run - 1, | 800 | current_superblock + current_run - 1, |
| @@ -1266,14 +831,10 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) · 30 unmodified lines | |||
| 1266 | 831 | ||
| 1267 | if (current_run-- == 0) { | 832 | if (current_run-- == 0) { |
| 1268 | bit ^= 1; | 833 | bit ^= 1; |
| 1269 | #if 1 | ||
| 1270 | current_run = get_vlc2(gb, | 834 | current_run = get_vlc2(gb, |
| 1271 | s->superblock_run_length_vlc.table, 6, 2); | 835 | s->superblock_run_length_vlc.table, 6, 2); |
| 1272 | if (current_run == 33) | 836 | if (current_run == 33) |
| 1273 | current_run += get_bits(gb, 12); | 837 | current_run += get_bits(gb, 12); |
| 1274 | #else | ||
| 1275 | current_run = get_superblock_run_length(gb); | ||
| 1276 | #endif | ||
| 1277 | } | 838 | } |
| 1278 | 839 | ||
| 1279 | debug_block_coding(" setting superblock %d to %s\n", | 840 | debug_block_coding(" setting superblock %d to %s\n", |
| @@ -1330,12 +891,8 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) · 50 unmodified lines | |||
| 1330 | * that cares about the fragment coding runs */ | 891 | * that cares about the fragment coding runs */ |
| 1331 | if (current_run-- == 0) { | 892 | if (current_run-- == 0) { |
| 1332 | bit ^= 1; | 893 | bit ^= 1; |
| 1333 | #if 1 | ||
| 1334 | current_run = get_vlc2(gb, | 894 | current_run = get_vlc2(gb, |
| 1335 | s->fragment_run_length_vlc.table, 5, 2); | 895 | s->fragment_run_length_vlc.table, 5, 2); |
| 1336 | #else | ||
| 1337 | current_run = get_fragment_run_length(gb); | ||
| 1338 | #endif | ||
| 1339 | } | 896 | } |
| 1340 | 897 | ||
| 1341 | if (bit) { | 898 | if (bit) { |
| @@ -1463,14 +1020,8 @@ static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb) · 121 unmodified lines | |||
| 1463 | if (scheme == 7) | 1020 | if (scheme == 7) |
| 1464 | coding_mode = get_bits(gb, 3); | 1021 | coding_mode = get_bits(gb, 3); |
| 1465 | else | 1022 | else |
| 1466 | { | ||
| 1467 | #if 1 | ||
| 1468 | coding_mode = ModeAlphabet[scheme] | 1023 | coding_mode = ModeAlphabet[scheme] |
| 1469 | [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)]; | 1024 | [get_vlc2(gb, s->mode_code_vlc.table, 3, 3)]; |
| 1470 | #else | ||
| 1471 | coding_mode = ModeAlphabet[scheme][get_mode_code(gb)]; | ||
| 1472 | #endif | ||
| 1473 | } | ||
| 1474 | 1025 | ||
| 1475 | s->macroblock_coding[current_macroblock] = coding_mode; | 1026 | s->macroblock_coding[current_macroblock] = coding_mode; |
| 1476 | for (k = 0; k < 6; k++) { | 1027 | for (k = 0; k < 6; k++) { |
| @@ -1557,21 +1108,11 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) · 80 unmodified lines | |||
| 1557 | case MODE_GOLDEN_MV: | 1108 | case MODE_GOLDEN_MV: |
| 1558 | /* all 6 fragments use the same motion vector */ | 1109 | /* all 6 fragments use the same motion vector */ |
| 1559 | if (coding_mode == 0) { | 1110 | if (coding_mode == 0) { |
| 1560 | #if 1 | ||
| 1561 | motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; | 1111 | motion_x[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; |
| 1562 | motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; | 1112 | motion_y[0] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; |
| 1563 | #else | ||
| 1564 | motion_x[0] = get_motion_vector_vlc(gb); | ||
| 1565 | motion_y[0] = get_motion_vector_vlc(gb); | ||
| 1566 | #endif | ||
| 1567 | } else { | 1113 | } else { |
| 1568 | #if 1 | ||
| 1569 | motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)]; | 1114 | motion_x[0] = fixed_motion_vector_table[get_bits(gb, 6)]; |
| 1570 | motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)]; | 1115 | motion_y[0] = fixed_motion_vector_table[get_bits(gb, 6)]; |
| 1571 | #else | ||
| 1572 | motion_x[0] = get_motion_vector_fixed(gb); | ||
| 1573 | motion_y[0] = get_motion_vector_fixed(gb); | ||
| 1574 | #endif | ||
| 1575 | } | 1116 | } |
| 1576 | 1117 | ||
| 1577 | for (k = 1; k < 6; k++) { | 1118 | for (k = 1; k < 6; k++) { |
| @@ -1595,21 +1136,11 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) · 17 unmodified lines | |||
| 1595 | motion_x[4] = motion_y[4] = 0; | 1136 | motion_x[4] = motion_y[4] = 0; |
| 1596 | for (k = 0; k < 4; k++) { | 1137 | for (k = 0; k < 4; k++) { |
| 1597 | if (coding_mode == 0) { | 1138 | if (coding_mode == 0) { |
| 1598 | #if 1 | ||
| 1599 | motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; | 1139 | motion_x[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; |
| 1600 | motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; | 1140 | motion_y[k] = motion_vector_table[get_vlc2(gb, s->motion_vector_vlc.table, 6, 2)]; |
| 1601 | #else | ||
| 1602 | motion_x[k] = get_motion_vector_vlc(gb); | ||
| 1603 | motion_y[k] = get_motion_vector_vlc(gb); | ||
| 1604 | #endif | ||
| 1605 | } else { | 1141 | } else { |
| 1606 | #if 1 | ||
| 1607 | motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)]; | 1142 | motion_x[k] = fixed_motion_vector_table[get_bits(gb, 6)]; |
| 1608 | motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)]; | 1143 | motion_y[k] = fixed_motion_vector_table[get_bits(gb, 6)]; |
| 1609 | #else | ||
| 1610 | motion_x[k] = get_motion_vector_fixed(gb); | ||
| 1611 | motion_y[k] = get_motion_vector_fixed(gb); | ||
| 1612 | #endif | ||
| 1613 | } | 1144 | } |
| 1614 | motion_x[4] += motion_x[k]; | 1145 | motion_x[4] += motion_x[k]; |
| 1615 | motion_y[4] += motion_y[k]; | 1146 | motion_y[4] += motion_y[k]; |
| @@ -1744,7 +1275,6 @@ static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb, · 128 unmodified lines | |||
| 1744 | token = get_vlc2(gb, table->table, 5, 3); | 1275 | token = get_vlc2(gb, table->table, 5, 3); |
| 1745 | debug_vlc(" token = %2d, ", token); | 1276 | debug_vlc(" token = %2d, ", token); |
| 1746 | /* use the token to get a zero run, a coefficient, and an eob run */ | 1277 | /* use the token to get a zero run, a coefficient, and an eob run */ |
| 1747 | #if 1 | ||
| 1748 | if (token <= 6) { | 1278 | if (token <= 6) { |
| 1749 | eob_run = eob_run_base[token]; | 1279 | eob_run = eob_run_base[token]; |
| 1750 | if (eob_run_get_bits[token]) | 1280 | if (eob_run_get_bits[token]) |
| @@ -1761,9 +1291,6 @@ static int unpack_vlcs(Vp3DecodeContext *s, GetBitContext *gb, · 10 unmodified lines | |||
| 1761 | if (zero_run_get_bits[token]) | 1291 | if (zero_run_get_bits[token]) |
| 1762 | zero_run += get_bits(gb, zero_run_get_bits[token]); | 1292 | zero_run += get_bits(gb, zero_run_get_bits[token]); |
| 1763 | } | 1293 | } |
| 1764 | #else | ||
| 1765 | unpack_token(gb, token, &zero_run, &coeff, &eob_run); | ||
| 1766 | #endif | ||
| 1767 | } | 1294 | } |
| 1768 | 1295 | ||
| 1769 | if (!eob_run) { | 1296 | if (!eob_run) { |
| @@ -2443,209 +1970,6 @@ static void render_slice(Vp3DecodeContext *s, int slice) · 673 unmodified lines | |||
| 2443 | emms_c(); | 1970 | emms_c(); |
| 2444 | } | 1971 | } |
| 2445 | 1972 | ||
| 2446 | /* | ||
| 2447 | * This function performs the final rendering of each fragment's data | ||
| 2448 | * onto the output frame. | ||
| 2449 | */ | ||
| 2450 | static void render_fragments(Vp3DecodeContext *s, | ||
| 2451 | int first_fragment, | ||
| 2452 | int width, | ||
| 2453 | int height, | ||
| 2454 | int plane /* 0 = Y, 1 = U, 2 = V */) | ||
| 2455 | { | ||
| 2456 | int x, y; | ||
| 2457 | int m, n; | ||
| 2458 | int i = first_fragment; | ||
| 2459 | int16_t *dequantizer; | ||
| 2460 | DCTELEM __align16 block[64]; | ||
| 2461 | unsigned char *output_plane; | ||
| 2462 | unsigned char *last_plane; | ||
| 2463 | unsigned char *golden_plane; | ||
| 2464 | int stride; | ||
| 2465 | int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef; | ||
| 2466 | int upper_motion_limit, lower_motion_limit; | ||
| 2467 | int motion_halfpel_index; | ||
| 2468 | uint8_t *motion_source; | ||
| 2469 | |||
| 2470 | debug_vp3(" vp3: rendering final fragments for %s\n", | ||
| 2471 | (plane == 0) ? "Y plane" : (plane == 1) ? "U plane" : "V plane"); | ||
| 2472 | |||
| 2473 | /* set up plane-specific parameters */ | ||
| 2474 | if (plane == 0) { | ||
| 2475 | output_plane = s->current_frame.data[0]; | ||
| 2476 | last_plane = s->last_frame.data[0]; | ||
| 2477 | golden_plane = s->golden_frame.data[0]; | ||
| 2478 | stride = s->current_frame.linesize[0]; | ||
| 2479 | if (!s->flipped_image) stride = -stride; | ||
| 2480 | upper_motion_limit = 7 * s->current_frame.linesize[0]; | ||
| 2481 | lower_motion_limit = height * s->current_frame.linesize[0] + width - 8; | ||
| 2482 | } else if (plane == 1) { | ||
| 2483 | output_plane = s->current_frame.data[1]; | ||
| 2484 | last_plane = s->last_frame.data[1]; | ||
| 2485 | golden_plane = s->golden_frame.data[1]; | ||
| 2486 | stride = s->current_frame.linesize[1]; | ||
| 2487 | if (!s->flipped_image) stride = -stride; | ||
| 2488 | upper_motion_limit = 7 * s->current_frame.linesize[1]; | ||
| 2489 | lower_motion_limit = height * s->current_frame.linesize[1] + width - 8; | ||
| 2490 | } else { | ||
| 2491 | output_plane = s->current_frame.data[2]; | ||
| 2492 | last_plane = s->last_frame.data[2]; | ||
| 2493 | golden_plane = s->golden_frame.data[2]; | ||
| 2494 | stride = s->current_frame.linesize[2]; | ||
| 2495 | if (!s->flipped_image) stride = -stride; | ||
| 2496 | upper_motion_limit = 7 * s->current_frame.linesize[2]; | ||
| 2497 | lower_motion_limit = height * s->current_frame.linesize[2] + width - 8; | ||
| 2498 | } | ||
| 2499 | |||
| 2500 | if(ABS(stride) > 2048) | ||
| 2501 | return; //various tables are fixed size | ||
| 2502 | |||
| 2503 | /* for each fragment row... */ | ||
| 2504 | for (y = 0; y < height; y += 8) { | ||
| 2505 | |||
| 2506 | /* for each fragment in a row... */ | ||
| 2507 | for (x = 0; x < width; x += 8, i++) { | ||
| 2508 | |||
| 2509 | if ((i < 0) || (i >= s->fragment_count)) { | ||
| 2510 | av_log(s->avctx, AV_LOG_ERROR, " vp3:render_fragments(): bad fragment number (%d)\n", i); | ||
| 2511 | return; | ||
| 2512 | } | ||
| 2513 | |||
| 2514 | /* transform if this block was coded */ | ||
| 2515 | if ((s->all_fragments[i].coding_method != MODE_COPY) && | ||
| 2516 | !((s->avctx->flags & CODEC_FLAG_GRAY) && plane)) { | ||
| 2517 | |||
| 2518 | if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) || | ||
| 2519 | (s->all_fragments[i].coding_method == MODE_GOLDEN_MV)) | ||
| 2520 | motion_source= golden_plane; | ||
| 2521 | else | ||
| 2522 | motion_source= last_plane; | ||
| 2523 | |||
| 2524 | motion_source += s->all_fragments[i].first_pixel; | ||
| 2525 | motion_halfpel_index = 0; | ||
| 2526 | |||
| 2527 | /* sort out the motion vector if this fragment is coded | ||
| 2528 | * using a motion vector method */ | ||
| 2529 | if ((s->all_fragments[i].coding_method > MODE_INTRA) && | ||
| 2530 | (s->all_fragments[i].coding_method != MODE_USING_GOLDEN)) { | ||
| 2531 | int src_x, src_y; | ||
| 2532 | motion_x = s->all_fragments[i].motion_x; | ||
| 2533 | motion_y = s->all_fragments[i].motion_y; | ||
| 2534 | if(plane){ | ||
| 2535 | motion_x= (motion_x>>1) | (motion_x&1); | ||
| 2536 | motion_y= (motion_y>>1) | (motion_y&1); | ||
| 2537 | } | ||
| 2538 | |||
| 2539 | src_x= (motion_x>>1) + x; | ||
| 2540 | src_y= (motion_y>>1) + y; | ||
| 2541 | if ((motion_x == 127) || (motion_y == 127)) | ||
| 2542 | av_log(s->avctx, AV_LOG_ERROR, " help! got invalid motion vector! (%X, %X)\n", motion_x, motion_y); | ||
| 2543 | |||
| 2544 | motion_halfpel_index = motion_x & 0x01; | ||
| 2545 | motion_source += (motion_x >> 1); | ||
| 2546 | |||
| 2547 | motion_halfpel_index |= (motion_y & 0x01) << 1; | ||
| 2548 | motion_source += ((motion_y >> 1) * stride); | ||
| 2549 | |||
| 2550 | if(src_x<0 || src_y<0 || src_x + 9 >= width || src_y + 9 >= height){ | ||
| 2551 | uint8_t *temp= s->edge_emu_buffer; | ||
| 2552 | if(stride<0) temp -= 9*stride; | ||
| 2553 | else temp += 9*stride; | ||
| 2554 | |||
| 2555 | ff_emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, width, height); | ||
| 2556 | motion_source= temp; | ||
| 2557 | } | ||
| 2558 | } | ||
| 2559 | |||
| 2560 | |||
| 2561 | /* first, take care of copying a block from either the | ||
| 2562 | * previous or the golden frame */ | ||
| 2563 | if (s->all_fragments[i].coding_method != MODE_INTRA) { | ||
| 2564 | //Note, it is possible to implement all MC cases with put_no_rnd_pixels_l2 which would look more like the VP3 source but this would be slower as put_no_rnd_pixels_tab is better optimzed | ||
| 2565 | if(motion_halfpel_index != 3){ | ||
| 2566 | s->dsp.put_no_rnd_pixels_tab[1][motion_halfpel_index]( | ||
| 2567 | output_plane + s->all_fragments[i].first_pixel, | ||
| 2568 | motion_source, stride, 8); | ||
| 2569 | }else{ | ||
| 2570 | int d= (motion_x ^ motion_y)>>31; // d is 0 if motion_x and _y have the same sign, else -1 | ||
| 2571 | s->dsp.put_no_rnd_pixels_l2[1]( | ||
| 2572 | output_plane + s->all_fragments[i].first_pixel, | ||
| 2573 | motion_source - d, | ||
| 2574 | motion_source + stride + 1 + d, | ||
| 2575 | stride, 8); | ||
| 2576 | } | ||
| 2577 | dequantizer = s->inter_dequant; | ||
| 2578 | }else{ | ||
| 2579 | if (plane == 0) | ||
| 2580 | dequantizer = s->intra_y_dequant; | ||
| 2581 | else | ||
| 2582 | dequantizer = s->intra_c_dequant; | ||
| 2583 | } | ||
| 2584 | |||
| 2585 | /* dequantize the DCT coefficients */ | ||
| 2586 | debug_idct("fragment %d, coding mode %d, DC = %d, dequant = %d:\n", | ||
| 2587 | i, s->all_fragments[i].coding_method, | ||
| 2588 | DC_COEFF(i), dequantizer[0]); | ||
| 2589 | |||
| 2590 | if(s->avctx->idct_algo==FF_IDCT_VP3){ | ||
| 2591 | Coeff *coeff= s->coeffs + i; | ||
| 2592 | memset(block, 0, sizeof(block)); | ||
| 2593 | while(coeff->next){ | ||
| 2594 | block[coeff->index]= coeff->coeff * dequantizer[coeff->index]; | ||
| 2595 | coeff= coeff->next; | ||
| 2596 | } | ||
| 2597 | }else{ | ||
| 2598 | Coeff *coeff= s->coeffs + i; | ||
| 2599 | memset(block, 0, sizeof(block)); | ||
| 2600 | while(coeff->next){ | ||
| 2601 | block[coeff->index]= (coeff->coeff * dequantizer[coeff->index] + 2)>>2; | ||
| 2602 | coeff= coeff->next; | ||
| 2603 | } | ||
| 2604 | } | ||
| 2605 | |||
| 2606 | /* invert DCT and place (or add) in final output */ | ||
| 2607 | |||
| 2608 | if (s->all_fragments[i].coding_method == MODE_INTRA) { | ||
| 2609 | if(s->avctx->idct_algo!=FF_IDCT_VP3) | ||
| 2610 | block[0] += 128<<3; | ||
| 2611 | s->dsp.idct_put( | ||
| 2612 | output_plane + s->all_fragments[i].first_pixel, | ||
| 2613 | stride, | ||
| 2614 | block); | ||
| 2615 | } else { | ||
| 2616 | s->dsp.idct_add( | ||
| 2617 | output_plane + s->all_fragments[i].first_pixel, | ||
| 2618 | stride, | ||
| 2619 | block); | ||
| 2620 | } | ||
| 2621 | |||
| 2622 | debug_idct("block after idct_%s():\n", | ||
| 2623 | (s->all_fragments[i].coding_method == MODE_INTRA)? | ||
| 2624 | "put" : "add"); | ||
| 2625 | for (m = 0; m < 8; m++) { | ||
| 2626 | for (n = 0; n < 8; n++) { | ||
| 2627 | debug_idct(" %3d", *(output_plane + | ||
| 2628 | s->all_fragments[i].first_pixel + (m * stride + n))); | ||
| 2629 | } | ||
| 2630 | debug_idct("\n"); | ||
| 2631 | } | ||
| 2632 | debug_idct("\n"); | ||
| 2633 | |||
| 2634 | } else { | ||
| 2635 | |||
| 2636 | /* copy directly from the previous frame */ | ||
| 2637 | s->dsp.put_pixels_tab[1][0]( | ||
| 2638 | output_plane + s->all_fragments[i].first_pixel, | ||
| 2639 | last_plane + s->all_fragments[i].first_pixel, | ||
| 2640 | stride, 8); | ||
| 2641 | |||
| 2642 | } | ||
| 2643 | } | ||
| 2644 | } | ||
| 2645 | |||
| 2646 | emms_c(); | ||
| 2647 | } | ||
| 2648 | |||
| 2649 | static void horizontal_filter(unsigned char *first_pixel, int stride, | 1973 | static void horizontal_filter(unsigned char *first_pixel, int stride, |
| 2650 | int *bounding_values) | 1974 | int *bounding_values) |
| 2651 | { | 1975 | { |
| @@ -3233,19 +2557,8 @@ if (!s->keyframe) { · 581 unmodified lines | |||
| 3233 | STOP_TIMER("reverse_dc_prediction")} | 2557 | STOP_TIMER("reverse_dc_prediction")} |
| 3234 | {START_TIMER | 2558 | {START_TIMER |
| 3235 | 2559 | ||
| 3236 | #if 1 | ||
| 3237 | for (i = 0; i < s->macroblock_height; i++) | 2560 | for (i = 0; i < s->macroblock_height; i++) |
| 3238 | render_slice(s, i); | 2561 | render_slice(s, i); |
| 3239 | #else | ||
| 3240 | render_fragments(s, 0, s->width, s->height, 0); | ||
| 3241 | if ((avctx->flags & CODEC_FLAG_GRAY) == 0) { | ||
| 3242 | render_fragments(s, s->u_fragment_start, s->width / 2, s->height / 2, 1); | ||
| 3243 | render_fragments(s, s->v_fragment_start, s->width / 2, s->height / 2, 2); | ||
| 3244 | } else { | ||
| 3245 | memset(s->current_frame.data[1], 0x80, s->width * s->height / 4); | ||
| 3246 | memset(s->current_frame.data[2], 0x80, s->width * s->height / 4); | ||
| 3247 | } | ||
| 3248 | #endif | ||
| 3249 | STOP_TIMER("render_fragments")} | 2562 | STOP_TIMER("render_fragments")} |
| 3250 | 2563 | ||
| 3251 | {START_TIMER | 2564 | {START_TIMER |