OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 VP8_COMMON *const x = & cpi->common; | 111 VP8_COMMON *const x = & cpi->common; |
112 | 112 |
113 vp8_writer *const w = cpi->bc; | 113 vp8_writer *const w = cpi->bc; |
114 | 114 |
115 { | 115 { |
116 vp8_prob Pnew [VP8_YMODES-1]; | 116 vp8_prob Pnew [VP8_YMODES-1]; |
117 unsigned int bct [VP8_YMODES-1] [2]; | 117 unsigned int bct [VP8_YMODES-1] [2]; |
118 | 118 |
119 update_mode( | 119 update_mode( |
120 w, VP8_YMODES, vp8_ymode_encodings, vp8_ymode_tree, | 120 w, VP8_YMODES, vp8_ymode_encodings, vp8_ymode_tree, |
121 Pnew, x->fc.ymode_prob, bct, (unsigned int *)cpi->ymode_count | 121 Pnew, x->fc.ymode_prob, bct, (unsigned int *)cpi->mb.ymode_count |
122 ); | 122 ); |
123 } | 123 } |
124 { | 124 { |
125 vp8_prob Pnew [VP8_UV_MODES-1]; | 125 vp8_prob Pnew [VP8_UV_MODES-1]; |
126 unsigned int bct [VP8_UV_MODES-1] [2]; | 126 unsigned int bct [VP8_UV_MODES-1] [2]; |
127 | 127 |
128 update_mode( | 128 update_mode( |
129 w, VP8_UV_MODES, vp8_uv_mode_encodings, vp8_uv_mode_tree, | 129 w, VP8_UV_MODES, vp8_uv_mode_encodings, vp8_uv_mode_tree, |
130 Pnew, x->fc.uv_mode_prob, bct, (unsigned int *)cpi->uv_mode_count | 130 Pnew, x->fc.uv_mode_prob, bct, (unsigned int *)cpi->mb.uv_mode_count |
131 ); | 131 ); |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 static void write_ymode(vp8_writer *bc, int m, const vp8_prob *p) | 135 static void write_ymode(vp8_writer *bc, int m, const vp8_prob *p) |
136 { | 136 { |
137 vp8_write_token(bc, vp8_ymode_tree, p, vp8_ymode_encodings + m); | 137 vp8_write_token(bc, vp8_ymode_tree, p, vp8_ymode_encodings + m); |
138 } | 138 } |
139 | 139 |
140 static void kfwrite_ymode(vp8_writer *bc, int m, const vp8_prob *p) | 140 static void kfwrite_ymode(vp8_writer *bc, int m, const vp8_prob *p) |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 /* TRAP.. This should not happen */ | 486 /* TRAP.. This should not happen */ |
487 default: | 487 default: |
488 vp8_write(w, 0, x->mb_segment_tree_probs[0]); | 488 vp8_write(w, 0, x->mb_segment_tree_probs[0]); |
489 vp8_write(w, 0, x->mb_segment_tree_probs[1]); | 489 vp8_write(w, 0, x->mb_segment_tree_probs[1]); |
490 break; | 490 break; |
491 } | 491 } |
492 } | 492 } |
493 } | 493 } |
494 void vp8_convert_rfct_to_prob(VP8_COMP *const cpi) | 494 void vp8_convert_rfct_to_prob(VP8_COMP *const cpi) |
495 { | 495 { |
496 const int *const rfct = cpi->count_mb_ref_frame_usage; | 496 const int *const rfct = cpi->mb.count_mb_ref_frame_usage; |
497 const int rf_intra = rfct[INTRA_FRAME]; | 497 const int rf_intra = rfct[INTRA_FRAME]; |
498 const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRA
ME]; | 498 const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRA
ME]; |
499 | 499 |
500 /* Calculate the probabilities used to code the ref frame based on usage */ | 500 /* Calculate the probabilities used to code the ref frame based on usage */ |
501 if (!(cpi->prob_intra_coded = rf_intra * 255 / (rf_intra + rf_inter))) | 501 if (!(cpi->prob_intra_coded = rf_intra * 255 / (rf_intra + rf_inter))) |
502 cpi->prob_intra_coded = 1; | 502 cpi->prob_intra_coded = 1; |
503 | 503 |
504 cpi->prob_last_coded = rf_inter ? (rfct[LAST_FRAME] * 255) / rf_inter : 128; | 504 cpi->prob_last_coded = rf_inter ? (rfct[LAST_FRAME] * 255) / rf_inter : 128; |
505 | 505 |
506 if (!cpi->prob_last_coded) | 506 if (!cpi->prob_last_coded) |
(...skipping 25 matching lines...) Expand all Loading... |
532 vp8_convert_rfct_to_prob(cpi); | 532 vp8_convert_rfct_to_prob(cpi); |
533 | 533 |
534 #ifdef ENTROPY_STATS | 534 #ifdef ENTROPY_STATS |
535 active_section = 1; | 535 active_section = 1; |
536 #endif | 536 #endif |
537 | 537 |
538 if (pc->mb_no_coeff_skip) | 538 if (pc->mb_no_coeff_skip) |
539 { | 539 { |
540 int total_mbs = pc->mb_rows * pc->mb_cols; | 540 int total_mbs = pc->mb_rows * pc->mb_cols; |
541 | 541 |
542 prob_skip_false = (total_mbs - cpi->skip_true_count ) * 256 / total_mbs; | 542 prob_skip_false = (total_mbs - cpi->mb.skip_true_count ) * 256 / total_m
bs; |
543 | 543 |
544 if (prob_skip_false <= 1) | 544 if (prob_skip_false <= 1) |
545 prob_skip_false = 1; | 545 prob_skip_false = 1; |
546 | 546 |
547 if (prob_skip_false > 255) | 547 if (prob_skip_false > 255) |
548 prob_skip_false = 255; | 548 prob_skip_false = 255; |
549 | 549 |
550 cpi->prob_skip_false = prob_skip_false; | 550 cpi->prob_skip_false = prob_skip_false; |
551 vp8_write_literal(w, prob_skip_false, 8); | 551 vp8_write_literal(w, prob_skip_false, 8); |
552 } | 552 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 /* const */ | 723 /* const */ |
724 MODE_INFO *m = c->mi; | 724 MODE_INFO *m = c->mi; |
725 | 725 |
726 int mb_row = -1; | 726 int mb_row = -1; |
727 int prob_skip_false = 0; | 727 int prob_skip_false = 0; |
728 | 728 |
729 if (c->mb_no_coeff_skip) | 729 if (c->mb_no_coeff_skip) |
730 { | 730 { |
731 int total_mbs = c->mb_rows * c->mb_cols; | 731 int total_mbs = c->mb_rows * c->mb_cols; |
732 | 732 |
733 prob_skip_false = (total_mbs - cpi->skip_true_count ) * 256 / total_mbs; | 733 prob_skip_false = (total_mbs - cpi->mb.skip_true_count ) * 256 / total_m
bs; |
734 | 734 |
735 if (prob_skip_false <= 1) | 735 if (prob_skip_false <= 1) |
736 prob_skip_false = 1; | 736 prob_skip_false = 1; |
737 | 737 |
738 if (prob_skip_false >= 255) | 738 if (prob_skip_false >= 255) |
739 prob_skip_false = 255; | 739 prob_skip_false = 255; |
740 | 740 |
741 cpi->prob_skip_false = prob_skip_false; | 741 cpi->prob_skip_false = prob_skip_false; |
742 vp8_write_literal(bc, prob_skip_false, 8); | 742 vp8_write_literal(bc, prob_skip_false, 8); |
743 } | 743 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 const int old_b = vp8_cost_branch(ct, oldp); | 844 const int old_b = vp8_cost_branch(ct, oldp); |
845 const int new_b = vp8_cost_branch(ct, newp); | 845 const int new_b = vp8_cost_branch(ct, newp); |
846 const int update_b = 8 + | 846 const int update_b = 8 + |
847 ((vp8_cost_one(upd) - vp8_cost_zero(upd)) >> 8); | 847 ((vp8_cost_one(upd) - vp8_cost_zero(upd)) >> 8); |
848 | 848 |
849 return old_b - new_b - update_b; | 849 return old_b - new_b - update_b; |
850 } | 850 } |
851 | 851 |
852 static int independent_coef_context_savings(VP8_COMP *cpi) | 852 static int independent_coef_context_savings(VP8_COMP *cpi) |
853 { | 853 { |
| 854 MACROBLOCK *const x = & cpi->mb; |
854 int savings = 0; | 855 int savings = 0; |
855 int i = 0; | 856 int i = 0; |
856 do | 857 do |
857 { | 858 { |
858 int j = 0; | 859 int j = 0; |
859 do | 860 do |
860 { | 861 { |
861 int k = 0; | 862 int k = 0; |
862 unsigned int prev_coef_count_sum[MAX_ENTROPY_TOKENS] = {0}; | 863 unsigned int prev_coef_count_sum[MAX_ENTROPY_TOKENS] = {0}; |
863 int prev_coef_savings[MAX_ENTROPY_TOKENS] = {0}; | 864 int prev_coef_savings[MAX_ENTROPY_TOKENS] = {0}; |
864 const unsigned int (*probs)[MAX_ENTROPY_TOKENS]; | 865 const unsigned int (*probs)[MAX_ENTROPY_TOKENS]; |
865 /* Calculate new probabilities given the constraint that | 866 /* Calculate new probabilities given the constraint that |
866 * they must be equal over the prev coef contexts | 867 * they must be equal over the prev coef contexts |
867 */ | 868 */ |
868 | 869 |
869 probs = (const unsigned int (*)[MAX_ENTROPY_TOKENS]) | 870 probs = (const unsigned int (*)[MAX_ENTROPY_TOKENS]) |
870 cpi->coef_counts[i][j]; | 871 x->coef_counts[i][j]; |
871 | 872 |
872 /* Reset to default probabilities at key frames */ | 873 /* Reset to default probabilities at key frames */ |
873 if (cpi->common.frame_type == KEY_FRAME) | 874 if (cpi->common.frame_type == KEY_FRAME) |
874 probs = default_coef_counts[i][j]; | 875 probs = default_coef_counts[i][j]; |
875 | 876 |
876 sum_probs_over_prev_coef_context(probs, prev_coef_count_sum); | 877 sum_probs_over_prev_coef_context(probs, prev_coef_count_sum); |
877 | 878 |
878 do | 879 do |
879 { | 880 { |
880 /* at every context */ | 881 /* at every context */ |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 while (++k < ENTROPY_NODES); | 920 while (++k < ENTROPY_NODES); |
920 } | 921 } |
921 while (++j < COEF_BANDS); | 922 while (++j < COEF_BANDS); |
922 } | 923 } |
923 while (++i < BLOCK_TYPES); | 924 while (++i < BLOCK_TYPES); |
924 return savings; | 925 return savings; |
925 } | 926 } |
926 | 927 |
927 static int default_coef_context_savings(VP8_COMP *cpi) | 928 static int default_coef_context_savings(VP8_COMP *cpi) |
928 { | 929 { |
| 930 MACROBLOCK *const x = & cpi->mb; |
929 int savings = 0; | 931 int savings = 0; |
930 int i = 0; | 932 int i = 0; |
931 do | 933 do |
932 { | 934 { |
933 int j = 0; | 935 int j = 0; |
934 do | 936 do |
935 { | 937 { |
936 int k = 0; | 938 int k = 0; |
937 do | 939 do |
938 { | 940 { |
939 /* at every context */ | 941 /* at every context */ |
940 | 942 |
941 /* calc probs and branch cts for this frame only */ | 943 /* calc probs and branch cts for this frame only */ |
942 int t = 0; /* token/prob index */ | 944 int t = 0; /* token/prob index */ |
943 | 945 |
944 vp8_tree_probs_from_distribution( | 946 vp8_tree_probs_from_distribution( |
945 MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree, | 947 MAX_ENTROPY_TOKENS, vp8_coef_encodings, vp8_coef_tree, |
946 cpi->frame_coef_probs [i][j][k], | 948 cpi->frame_coef_probs [i][j][k], |
947 cpi->frame_branch_ct [i][j][k], | 949 cpi->frame_branch_ct [i][j][k], |
948 cpi->coef_counts [i][j][k], | 950 x->coef_counts [i][j][k], |
949 256, 1 | 951 256, 1 |
950 ); | 952 ); |
951 | 953 |
952 do | 954 do |
953 { | 955 { |
954 const unsigned int *ct = cpi->frame_branch_ct [i][j][k][t]; | 956 const unsigned int *ct = cpi->frame_branch_ct [i][j][k][t]; |
955 const vp8_prob newp = cpi->frame_coef_probs [i][j][k][t]; | 957 const vp8_prob newp = cpi->frame_coef_probs [i][j][k][t]; |
956 const vp8_prob oldp = cpi->common.fc.coef_probs [i][j][k][t]
; | 958 const vp8_prob oldp = cpi->common.fc.coef_probs [i][j][k][t]
; |
957 const vp8_prob upd = vp8_coef_update_probs [i][j][k][t]; | 959 const vp8_prob upd = vp8_coef_update_probs [i][j][k][t]; |
958 const int s = prob_update_savings(ct, oldp, newp, upd); | 960 const int s = prob_update_savings(ct, oldp, newp, upd); |
(...skipping 28 matching lines...) Expand all Loading... |
987 ref_frame_cost[ALTREF_FRAME] = vp8_cost_one(prob_intra) | 989 ref_frame_cost[ALTREF_FRAME] = vp8_cost_one(prob_intra) |
988 + vp8_cost_one(prob_last) | 990 + vp8_cost_one(prob_last) |
989 + vp8_cost_one(prob_garf); | 991 + vp8_cost_one(prob_garf); |
990 | 992 |
991 } | 993 } |
992 | 994 |
993 int vp8_estimate_entropy_savings(VP8_COMP *cpi) | 995 int vp8_estimate_entropy_savings(VP8_COMP *cpi) |
994 { | 996 { |
995 int savings = 0; | 997 int savings = 0; |
996 | 998 |
997 const int *const rfct = cpi->count_mb_ref_frame_usage; | 999 const int *const rfct = cpi->mb.count_mb_ref_frame_usage; |
998 const int rf_intra = rfct[INTRA_FRAME]; | 1000 const int rf_intra = rfct[INTRA_FRAME]; |
999 const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRA
ME]; | 1001 const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRA
ME]; |
1000 int new_intra, new_last, new_garf, oldtotal, newtotal; | 1002 int new_intra, new_last, new_garf, oldtotal, newtotal; |
1001 int ref_frame_cost[MAX_REF_FRAMES]; | 1003 int ref_frame_cost[MAX_REF_FRAMES]; |
1002 | 1004 |
1003 vp8_clear_system_state(); | 1005 vp8_clear_system_state(); |
1004 | 1006 |
1005 if (cpi->common.frame_type != KEY_FRAME) | 1007 if (cpi->common.frame_type != KEY_FRAME) |
1006 { | 1008 { |
1007 if (!(new_intra = rf_intra * 255 / (rf_intra + rf_inter))) | 1009 if (!(new_intra = rf_intra * 255 / (rf_intra + rf_inter))) |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 fprintf(f, " },\n"); | 1723 fprintf(f, " },\n"); |
1722 } | 1724 } |
1723 | 1725 |
1724 fprintf(f, " },\n"); | 1726 fprintf(f, " },\n"); |
1725 } | 1727 } |
1726 | 1728 |
1727 fprintf(f, "};\n"); | 1729 fprintf(f, "};\n"); |
1728 fclose(f); | 1730 fclose(f); |
1729 } | 1731 } |
1730 #endif | 1732 #endif |
OLD | NEW |