| 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 26 matching lines...) Expand all Loading... |
| 37 #include "vp9/encoder/vp9_rd.h" | 37 #include "vp9/encoder/vp9_rd.h" |
| 38 #include "vp9/encoder/vp9_tokenize.h" | 38 #include "vp9/encoder/vp9_tokenize.h" |
| 39 #include "vp9/encoder/vp9_variance.h" | 39 #include "vp9/encoder/vp9_variance.h" |
| 40 | 40 |
| 41 #define RD_THRESH_POW 1.25 | 41 #define RD_THRESH_POW 1.25 |
| 42 #define RD_MULT_EPB_RATIO 64 | 42 #define RD_MULT_EPB_RATIO 64 |
| 43 | 43 |
| 44 // Factor to weigh the rate for switchable interp filters. | 44 // Factor to weigh the rate for switchable interp filters. |
| 45 #define SWITCHABLE_INTERP_RATE_FACTOR 1 | 45 #define SWITCHABLE_INTERP_RATE_FACTOR 1 |
| 46 | 46 |
| 47 void vp9_rd_cost_reset(RD_COST *rd_cost) { |
| 48 rd_cost->rate = INT_MAX; |
| 49 rd_cost->dist = INT64_MAX; |
| 50 rd_cost->rdcost = INT64_MAX; |
| 51 } |
| 52 |
| 53 void vp9_rd_cost_init(RD_COST *rd_cost) { |
| 54 rd_cost->rate = 0; |
| 55 rd_cost->dist = 0; |
| 56 rd_cost->rdcost = 0; |
| 57 } |
| 58 |
| 47 // The baseline rd thresholds for breaking out of the rd loop for | 59 // The baseline rd thresholds for breaking out of the rd loop for |
| 48 // certain modes are assumed to be based on 8x8 blocks. | 60 // certain modes are assumed to be based on 8x8 blocks. |
| 49 // This table is used to correct for block size. | 61 // This table is used to correct for block size. |
| 50 // The factors here are << 2 (2 = x0.5, 32 = x8 etc). | 62 // The factors here are << 2 (2 = x0.5, 32 = x8 etc). |
| 51 static const uint8_t rd_thresh_block_size_factor[BLOCK_SIZES] = { | 63 static const uint8_t rd_thresh_block_size_factor[BLOCK_SIZES] = { |
| 52 2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32 | 64 2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32 |
| 53 }; | 65 }; |
| 54 | 66 |
| 55 static void fill_mode_costs(VP9_COMP *cpi) { | 67 static void fill_mode_costs(VP9_COMP *cpi) { |
| 56 const FRAME_CONTEXT *const fc = &cpi->common.fc; | 68 const FRAME_CONTEXT *const fc = &cpi->common.fc; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 141 |
| 130 static const int rd_boost_factor[16] = { | 142 static const int rd_boost_factor[16] = { |
| 131 64, 32, 32, 32, 24, 16, 12, 12, | 143 64, 32, 32, 32, 24, 16, 12, 12, |
| 132 8, 8, 4, 4, 2, 2, 1, 0 | 144 8, 8, 4, 4, 2, 2, 1, 0 |
| 133 }; | 145 }; |
| 134 static const int rd_frame_type_factor[FRAME_UPDATE_TYPES] = { | 146 static const int rd_frame_type_factor[FRAME_UPDATE_TYPES] = { |
| 135 128, 144, 128, 128, 144 | 147 128, 144, 128, 128, 144 |
| 136 }; | 148 }; |
| 137 | 149 |
| 138 int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) { | 150 int vp9_compute_rd_mult(const VP9_COMP *cpi, int qindex) { |
| 139 const int q = vp9_dc_quant(qindex, 0, cpi->common.bit_depth); | 151 const int64_t q = vp9_dc_quant(qindex, 0, cpi->common.bit_depth); |
| 140 #if CONFIG_VP9_HIGHBITDEPTH | 152 #if CONFIG_VP9_HIGHBITDEPTH |
| 141 int rdmult = 0; | 153 int64_t rdmult = 0; |
| 142 switch (cpi->common.bit_depth) { | 154 switch (cpi->common.bit_depth) { |
| 143 case VPX_BITS_8: | 155 case VPX_BITS_8: |
| 144 rdmult = 88 * q * q / 24; | 156 rdmult = 88 * q * q / 24; |
| 145 break; | 157 break; |
| 146 case VPX_BITS_10: | 158 case VPX_BITS_10: |
| 147 rdmult = ROUND_POWER_OF_TWO(88 * q * q / 24, 4); | 159 rdmult = ROUND_POWER_OF_TWO(88 * q * q / 24, 4); |
| 148 break; | 160 break; |
| 149 case VPX_BITS_12: | 161 case VPX_BITS_12: |
| 150 rdmult = ROUND_POWER_OF_TWO(88 * q * q / 24, 8); | 162 rdmult = ROUND_POWER_OF_TWO(88 * q * q / 24, 8); |
| 151 break; | 163 break; |
| 152 default: | 164 default: |
| 153 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); | 165 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); |
| 154 return -1; | 166 return -1; |
| 155 } | 167 } |
| 156 #else | 168 #else |
| 157 int rdmult = 88 * q * q / 24; | 169 int64_t rdmult = 88 * q * q / 24; |
| 158 #endif | 170 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 159 if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { | 171 if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { |
| 160 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 172 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 161 const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index]; | 173 const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index]; |
| 162 const int boost_index = MIN(15, (cpi->rc.gfu_boost / 100)); | 174 const int boost_index = MIN(15, (cpi->rc.gfu_boost / 100)); |
| 163 | 175 |
| 164 rdmult = (rdmult * rd_frame_type_factor[frame_type]) >> 7; | 176 rdmult = (rdmult * rd_frame_type_factor[frame_type]) >> 7; |
| 165 rdmult += ((rdmult * rd_boost_factor[boost_index]) >> 7); | 177 rdmult += ((rdmult * rd_boost_factor[boost_index]) >> 7); |
| 166 } | 178 } |
| 167 return rdmult; | 179 return (int)rdmult; |
| 168 } | 180 } |
| 169 | 181 |
| 170 static int compute_rd_thresh_factor(int qindex, vpx_bit_depth_t bit_depth) { | 182 static int compute_rd_thresh_factor(int qindex, vpx_bit_depth_t bit_depth) { |
| 171 double q; | 183 double q; |
| 172 #if CONFIG_VP9_HIGHBITDEPTH | 184 #if CONFIG_VP9_HIGHBITDEPTH |
| 173 switch (bit_depth) { | 185 switch (bit_depth) { |
| 174 case VPX_BITS_8: | 186 case VPX_BITS_8: |
| 175 q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0; | 187 q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0; |
| 176 break; | 188 break; |
| 177 case VPX_BITS_10: | 189 case VPX_BITS_10: |
| 178 q = vp9_dc_quant(qindex, 0, VPX_BITS_10) / 16.0; | 190 q = vp9_dc_quant(qindex, 0, VPX_BITS_10) / 16.0; |
| 179 break; | 191 break; |
| 180 case VPX_BITS_12: | 192 case VPX_BITS_12: |
| 181 q = vp9_dc_quant(qindex, 0, VPX_BITS_12) / 64.0; | 193 q = vp9_dc_quant(qindex, 0, VPX_BITS_12) / 64.0; |
| 182 break; | 194 break; |
| 183 default: | 195 default: |
| 184 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); | 196 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); |
| 185 return -1; | 197 return -1; |
| 186 } | 198 } |
| 187 #else | 199 #else |
| 188 (void) bit_depth; | 200 (void) bit_depth; |
| 189 q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0; | 201 q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0; |
| 190 #endif | 202 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 191 // TODO(debargha): Adjust the function below. | 203 // TODO(debargha): Adjust the function below. |
| 192 return MAX((int)(pow(q, RD_THRESH_POW) * 5.12), 8); | 204 return MAX((int)(pow(q, RD_THRESH_POW) * 5.12), 8); |
| 193 } | 205 } |
| 194 | 206 |
| 195 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) { | 207 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) { |
| 196 #if CONFIG_VP9_HIGHBITDEPTH | 208 #if CONFIG_VP9_HIGHBITDEPTH |
| 197 switch (cpi->common.bit_depth) { | 209 switch (cpi->common.bit_depth) { |
| 198 case VPX_BITS_8: | 210 case VPX_BITS_8: |
| 199 cpi->mb.sadperbit16 = sad_per_bit16lut_8[qindex]; | 211 cpi->mb.sadperbit16 = sad_per_bit16lut_8[qindex]; |
| 200 cpi->mb.sadperbit4 = sad_per_bit4lut_8[qindex]; | 212 cpi->mb.sadperbit4 = sad_per_bit4lut_8[qindex]; |
| 201 break; | 213 break; |
| 202 case VPX_BITS_10: | 214 case VPX_BITS_10: |
| 203 cpi->mb.sadperbit16 = sad_per_bit16lut_10[qindex]; | 215 cpi->mb.sadperbit16 = sad_per_bit16lut_10[qindex]; |
| 204 cpi->mb.sadperbit4 = sad_per_bit4lut_10[qindex]; | 216 cpi->mb.sadperbit4 = sad_per_bit4lut_10[qindex]; |
| 205 break; | 217 break; |
| 206 case VPX_BITS_12: | 218 case VPX_BITS_12: |
| 207 cpi->mb.sadperbit16 = sad_per_bit16lut_12[qindex]; | 219 cpi->mb.sadperbit16 = sad_per_bit16lut_12[qindex]; |
| 208 cpi->mb.sadperbit4 = sad_per_bit4lut_12[qindex]; | 220 cpi->mb.sadperbit4 = sad_per_bit4lut_12[qindex]; |
| 209 break; | 221 break; |
| 210 default: | 222 default: |
| 211 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); | 223 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); |
| 212 } | 224 } |
| 213 #else | 225 #else |
| 214 cpi->mb.sadperbit16 = sad_per_bit16lut_8[qindex]; | 226 cpi->mb.sadperbit16 = sad_per_bit16lut_8[qindex]; |
| 215 cpi->mb.sadperbit4 = sad_per_bit4lut_8[qindex]; | 227 cpi->mb.sadperbit4 = sad_per_bit4lut_8[qindex]; |
| 216 #endif | 228 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 217 } | 229 } |
| 218 | 230 |
| 219 static void set_block_thresholds(const VP9_COMMON *cm, RD_OPT *rd) { | 231 static void set_block_thresholds(const VP9_COMMON *cm, RD_OPT *rd) { |
| 220 int i, bsize, segment_id; | 232 int i, bsize, segment_id; |
| 221 | 233 |
| 222 for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) { | 234 for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) { |
| 223 const int qindex = | 235 const int qindex = |
| 224 clamp(vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex) + | 236 clamp(vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex) + |
| 225 cm->y_dc_delta_q, 0, MAXQ); | 237 cm->y_dc_delta_q, 0, MAXQ); |
| 226 const int q = compute_rd_thresh_factor(qindex, cm->bit_depth); | 238 const int q = compute_rd_thresh_factor(qindex, cm->bit_depth); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 rd->thresh_mult_sub8x8[THR_ALTR] += 2500; | 603 rd->thresh_mult_sub8x8[THR_ALTR] += 2500; |
| 592 rd->thresh_mult_sub8x8[THR_INTRA] += 2500; | 604 rd->thresh_mult_sub8x8[THR_INTRA] += 2500; |
| 593 rd->thresh_mult_sub8x8[THR_COMP_LA] += 4500; | 605 rd->thresh_mult_sub8x8[THR_COMP_LA] += 4500; |
| 594 rd->thresh_mult_sub8x8[THR_COMP_GA] += 4500; | 606 rd->thresh_mult_sub8x8[THR_COMP_GA] += 4500; |
| 595 | 607 |
| 596 // Check for masked out split cases. | 608 // Check for masked out split cases. |
| 597 for (i = 0; i < MAX_REFS; ++i) | 609 for (i = 0; i < MAX_REFS; ++i) |
| 598 if (sf->disable_split_mask & (1 << i)) | 610 if (sf->disable_split_mask & (1 << i)) |
| 599 rd->thresh_mult_sub8x8[i] = INT_MAX; | 611 rd->thresh_mult_sub8x8[i] = INT_MAX; |
| 600 } | 612 } |
| 613 |
| 614 int vp9_get_intra_cost_penalty(int qindex, int qdelta, |
| 615 vpx_bit_depth_t bit_depth) { |
| 616 const int q = vp9_dc_quant(qindex, qdelta, bit_depth); |
| 617 #if CONFIG_VP9_HIGHBITDEPTH |
| 618 switch (bit_depth) { |
| 619 case VPX_BITS_8: |
| 620 return 20 * q; |
| 621 case VPX_BITS_10: |
| 622 return 5 * q; |
| 623 case VPX_BITS_12: |
| 624 return ROUND_POWER_OF_TWO(5 * q, 2); |
| 625 default: |
| 626 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); |
| 627 return -1; |
| 628 } |
| 629 #else |
| 630 return 20 * q; |
| 631 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 632 } |
| 633 |
| OLD | NEW |