| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 |
| 11 #include <limits.h> | 11 #include <limits.h> |
| 12 #include <math.h> | 12 #include <math.h> |
| 13 | 13 |
| 14 #include "vp9/encoder/vp9_aq_variance.h" |
| 15 #include "vp9/encoder/vp9_encodeframe.h" |
| 14 #include "vp9/common/vp9_seg_common.h" | 16 #include "vp9/common/vp9_seg_common.h" |
| 15 | |
| 16 #include "vp9/encoder/vp9_segmentation.h" | 17 #include "vp9/encoder/vp9_segmentation.h" |
| 17 | 18 |
| 18 #define AQ_C_SEGMENTS 3 | 19 #define AQ_C_SEGMENTS 3 |
| 19 #define AQ_C_STRENGTHS 3 | 20 #define AQ_C_STRENGTHS 3 |
| 20 static const int aq_c_active_segments[AQ_C_STRENGTHS] = {1, 2, 3}; | 21 static const int aq_c_active_segments[AQ_C_STRENGTHS] = {1, 2, 3}; |
| 21 static const double aq_c_q_adj_factor[AQ_C_STRENGTHS][AQ_C_SEGMENTS] = | 22 static const double aq_c_q_adj_factor[AQ_C_STRENGTHS][AQ_C_SEGMENTS] = |
| 22 {{1.0, 1.0, 1.0}, {1.0, 2.0, 1.0}, {1.0, 1.5, 2.5}}; | 23 {{1.0, 1.0, 1.0}, {1.0, 2.0, 1.0}, {1.0, 1.5, 2.5}}; |
| 23 static const double aq_c_transitions[AQ_C_STRENGTHS][AQ_C_SEGMENTS] = | 24 static const double aq_c_transitions[AQ_C_STRENGTHS][AQ_C_SEGMENTS] = |
| 24 {{1.0, 1.0, 1.0}, {1.0, 0.25, 0.0}, {1.0, 0.5, 0.25}}; | 25 {{1.0, 1.0, 1.0}, {1.0, 0.25, 0.0}, {1.0, 0.5, 0.25}}; |
| 26 static const double aq_c_var_thresholds[AQ_C_SEGMENTS] = {100.0, 12.0, 10.0}; |
| 25 | 27 |
| 26 static int get_aq_c_strength(int q_index, vpx_bit_depth_t bit_depth) { | 28 static int get_aq_c_strength(int q_index, vpx_bit_depth_t bit_depth) { |
| 27 // Approximate base quatizer (truncated to int) | 29 // Approximate base quatizer (truncated to int) |
| 28 const int base_quant = vp9_ac_quant(q_index, 0, bit_depth) / 4; | 30 const int base_quant = vp9_ac_quant(q_index, 0, bit_depth) / 4; |
| 29 return (base_quant > 20) + (base_quant > 45); | 31 return (base_quant > 20) + (base_quant > 45); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void vp9_setup_in_frame_q_adj(VP9_COMP *cpi) { | 34 void vp9_setup_in_frame_q_adj(VP9_COMP *cpi) { |
| 33 VP9_COMMON *const cm = &cpi->common; | 35 VP9_COMMON *const cm = &cpi->common; |
| 34 struct segmentation *const seg = &cm->seg; | 36 struct segmentation *const seg = &cm->seg; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 } | 91 } |
| 90 | 92 |
| 91 // Select a segment for the current SB64 block. | 93 // Select a segment for the current SB64 block. |
| 92 // The choice of segment for a block depends on the ratio of the projected | 94 // The choice of segment for a block depends on the ratio of the projected |
| 93 // bits for the block vs a target average. | 95 // bits for the block vs a target average. |
| 94 // An "aq_strength" value determines how many segments are supported, | 96 // An "aq_strength" value determines how many segments are supported, |
| 95 // the set of transition points to use and the extent of the quantizer | 97 // the set of transition points to use and the extent of the quantizer |
| 96 // adjustment for each segment (configured in vp9_setup_in_frame_q_adj()). | 98 // adjustment for each segment (configured in vp9_setup_in_frame_q_adj()). |
| 97 void vp9_select_in_frame_q_segment(VP9_COMP *cpi, | 99 void vp9_select_in_frame_q_segment(VP9_COMP *cpi, BLOCK_SIZE bs, |
| 98 int mi_row, int mi_col, | 100 int mi_row, int mi_col, |
| 99 int output_enabled, int projected_rate) { | 101 int output_enabled, int projected_rate) { |
| 100 VP9_COMMON *const cm = &cpi->common; | 102 VP9_COMMON *const cm = &cpi->common; |
| 101 | 103 |
| 102 const int mi_offset = mi_row * cm->mi_cols + mi_col; | 104 const int mi_offset = mi_row * cm->mi_cols + mi_col; |
| 103 const int bw = num_8x8_blocks_wide_lookup[BLOCK_64X64]; | 105 const int bw = num_8x8_blocks_wide_lookup[BLOCK_64X64]; |
| 104 const int bh = num_8x8_blocks_high_lookup[BLOCK_64X64]; | 106 const int bh = num_8x8_blocks_high_lookup[BLOCK_64X64]; |
| 105 const int xmis = MIN(cm->mi_cols - mi_col, bw); | 107 const int xmis = MIN(cm->mi_cols - mi_col, bw); |
| 106 const int ymis = MIN(cm->mi_rows - mi_row, bh); | 108 const int ymis = MIN(cm->mi_rows - mi_row, bh); |
| 107 int complexity_metric = 64; | 109 int complexity_metric = 64; |
| 108 int x, y; | 110 int x, y; |
| 109 | 111 |
| 110 unsigned char segment; | 112 unsigned char segment; |
| 111 | 113 |
| 112 if (!output_enabled) { | 114 if (!output_enabled) { |
| 113 segment = 0; | 115 segment = 0; |
| 114 } else { | 116 } else { |
| 115 // Rate depends on fraction of a SB64 in frame (xmis * ymis / bw * bh). | 117 // Rate depends on fraction of a SB64 in frame (xmis * ymis / bw * bh). |
| 116 // It is converted to bits * 256 units. | 118 // It is converted to bits * 256 units. |
| 117 const int target_rate = (cpi->rc.sb64_target_rate * xmis * ymis * 256) / | 119 const int target_rate = (cpi->rc.sb64_target_rate * xmis * ymis * 256) / |
| 118 (bw * bh); | 120 (bw * bh); |
| 119 const int aq_strength = get_aq_c_strength(cm->base_qindex, cm->bit_depth); | 121 const int aq_strength = get_aq_c_strength(cm->base_qindex, cm->bit_depth); |
| 120 const int active_segments = aq_c_active_segments[aq_strength]; | 122 const int active_segments = aq_c_active_segments[aq_strength]; |
| 123 double logvar; |
| 124 |
| 125 vp9_setup_src_planes(&cpi->mb, cpi->Source, mi_row, mi_col); |
| 126 logvar = vp9_log_block_var(cpi, &cpi->mb, bs); |
| 121 | 127 |
| 122 // The number of segments considered and the transition points used to | 128 // The number of segments considered and the transition points used to |
| 123 // select them is determined by the "aq_strength" value. | 129 // select them is determined by the "aq_strength" value. |
| 124 // Currently this loop only supports segments that reduce Q (i.e. where | 130 // Currently this loop only supports segments that reduce Q (i.e. where |
| 125 // there is undershoot. | 131 // there is undershoot. |
| 126 // The loop counts down towards segment 0 which is the default segment | 132 // The loop counts down towards segment 0 which is the default segment |
| 127 // with no Q adjustment. | 133 // with no Q adjustment. |
| 128 segment = active_segments - 1; | 134 segment = active_segments - 1; |
| 129 while (segment > 0) { | 135 while (segment > 0) { |
| 130 if (projected_rate < | 136 if ((projected_rate < |
| 131 (target_rate * aq_c_transitions[aq_strength][segment])) { | 137 target_rate * aq_c_transitions[aq_strength][segment]) && |
| 138 (logvar < aq_c_var_thresholds[segment])) { |
| 132 break; | 139 break; |
| 133 } | 140 } |
| 134 --segment; | 141 --segment; |
| 135 } | 142 } |
| 136 | 143 |
| 137 if (target_rate > 0) { | 144 if (target_rate > 0) { |
| 138 complexity_metric = | 145 complexity_metric = |
| 139 clamp((int)((projected_rate * 64) / target_rate), 16, 255); | 146 clamp((int)((projected_rate * 64) / target_rate), 16, 255); |
| 140 } | 147 } |
| 141 } | 148 } |
| 142 | 149 |
| 143 // Fill in the entires in the segment map corresponding to this SB64. | 150 // Fill in the entires in the segment map corresponding to this SB64. |
| 144 for (y = 0; y < ymis; y++) { | 151 for (y = 0; y < ymis; y++) { |
| 145 for (x = 0; x < xmis; x++) { | 152 for (x = 0; x < xmis; x++) { |
| 146 cpi->segmentation_map[mi_offset + y * cm->mi_cols + x] = segment; | 153 cpi->segmentation_map[mi_offset + y * cm->mi_cols + x] = segment; |
| 147 cpi->complexity_map[mi_offset + y * cm->mi_cols + x] = | 154 cpi->complexity_map[mi_offset + y * cm->mi_cols + x] = |
| 148 (unsigned char)complexity_metric; | 155 (unsigned char)complexity_metric; |
| 149 } | 156 } |
| 150 } | 157 } |
| 151 } | 158 } |
| OLD | NEW |