| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 typedef enum { | 27 typedef enum { |
| 28 INTER_NORMAL = 0, | 28 INTER_NORMAL = 0, |
| 29 INTER_HIGH = 1, | 29 INTER_HIGH = 1, |
| 30 GF_ARF_LOW = 2, | 30 GF_ARF_LOW = 2, |
| 31 GF_ARF_STD = 3, | 31 GF_ARF_STD = 3, |
| 32 KF_STD = 4, | 32 KF_STD = 4, |
| 33 RATE_FACTOR_LEVELS = 5 | 33 RATE_FACTOR_LEVELS = 5 |
| 34 } RATE_FACTOR_LEVEL; | 34 } RATE_FACTOR_LEVEL; |
| 35 | 35 |
| 36 // Internal frame scaling level. |
| 37 typedef enum { |
| 38 UNSCALED = 0, // Frame is unscaled. |
| 39 SCALE_STEP1 = 1, // First-level down-scaling. |
| 40 FRAME_SCALE_STEPS |
| 41 } FRAME_SCALE_LEVEL; |
| 42 |
| 43 // Frame dimensions multiplier wrt the native frame size, in 1/16ths, |
| 44 // specified for the scale-up case. |
| 45 // e.g. 24 => 16/24 = 2/3 of native size. The restriction to 1/16th is |
| 46 // intended to match the capabilities of the normative scaling filters, |
| 47 // giving precedence to the up-scaling accuracy. |
| 48 static const int frame_scale_factor[FRAME_SCALE_STEPS] = {16, 24}; |
| 49 |
| 50 // Multiplier of the target rate to be used as threshold for triggering scaling. |
| 51 static const double rate_thresh_mult[FRAME_SCALE_STEPS] = {1.0, 2.0}; |
| 52 |
| 53 // Scale dependent Rate Correction Factor multipliers. Compensates for the |
| 54 // greater number of bits per pixel generated in down-scaled frames. |
| 55 static const double rcf_mult[FRAME_SCALE_STEPS] = {1.0, 2.0}; |
| 56 |
| 36 typedef struct { | 57 typedef struct { |
| 37 // Rate targetting variables | 58 // Rate targetting variables |
| 38 int base_frame_target; // A baseline frame target before adjustment | 59 int base_frame_target; // A baseline frame target before adjustment |
| 39 // for previous under or over shoot. | 60 // for previous under or over shoot. |
| 40 int this_frame_target; // Actual frame target after rc adjustment. | 61 int this_frame_target; // Actual frame target after rc adjustment. |
| 41 int projected_frame_size; | 62 int projected_frame_size; |
| 42 int sb64_target_rate; | 63 int sb64_target_rate; |
| 43 int last_q[FRAME_TYPES]; // Separate values for Intra/Inter | 64 int last_q[FRAME_TYPES]; // Separate values for Intra/Inter |
| 44 int last_boosted_qindex; // Last boosted GF/KF/ARF q | 65 int last_boosted_qindex; // Last boosted GF/KF/ARF q |
| 45 int last_kf_qindex; // Q index of the last key frame coded. | 66 int last_kf_qindex; // Q index of the last key frame coded. |
| 46 | 67 |
| 47 int gfu_boost; | 68 int gfu_boost; |
| 48 int last_boost; | 69 int last_boost; |
| 49 int kf_boost; | 70 int kf_boost; |
| 50 | 71 |
| 51 double rate_correction_factors[RATE_FACTOR_LEVELS]; | 72 double rate_correction_factors[RATE_FACTOR_LEVELS]; |
| 52 | 73 |
| 53 int frames_since_golden; | 74 int frames_since_golden; |
| 54 int frames_till_gf_update_due; | 75 int frames_till_gf_update_due; |
| 55 int max_gf_interval; | 76 int max_gf_interval; |
| 56 int static_scene_max_gf_interval; | 77 int static_scene_max_gf_interval; |
| 57 int baseline_gf_interval; | 78 int baseline_gf_interval; |
| 79 int constrained_gf_group; |
| 58 int frames_to_key; | 80 int frames_to_key; |
| 59 int frames_since_key; | 81 int frames_since_key; |
| 60 int this_key_frame_forced; | 82 int this_key_frame_forced; |
| 61 int next_key_frame_forced; | 83 int next_key_frame_forced; |
| 62 int source_alt_ref_pending; | 84 int source_alt_ref_pending; |
| 63 int source_alt_ref_active; | 85 int source_alt_ref_active; |
| 64 int is_src_frame_alt_ref; | 86 int is_src_frame_alt_ref; |
| 65 | 87 |
| 66 int avg_frame_bandwidth; // Average frame size target for clip | 88 int avg_frame_bandwidth; // Average frame size target for clip |
| 67 int min_frame_bandwidth; // Minimum allocation used for any frame | 89 int min_frame_bandwidth; // Minimum allocation used for any frame |
| (...skipping 24 matching lines...) Expand all Loading... |
| 92 int64_t total_actual_bits; | 114 int64_t total_actual_bits; |
| 93 int64_t total_target_bits; | 115 int64_t total_target_bits; |
| 94 int64_t total_target_vs_actual; | 116 int64_t total_target_vs_actual; |
| 95 | 117 |
| 96 int worst_quality; | 118 int worst_quality; |
| 97 int best_quality; | 119 int best_quality; |
| 98 | 120 |
| 99 int64_t starting_buffer_level; | 121 int64_t starting_buffer_level; |
| 100 int64_t optimal_buffer_level; | 122 int64_t optimal_buffer_level; |
| 101 int64_t maximum_buffer_size; | 123 int64_t maximum_buffer_size; |
| 124 |
| 102 // rate control history for last frame(1) and the frame before(2). | 125 // rate control history for last frame(1) and the frame before(2). |
| 103 // -1: undershot | 126 // -1: undershot |
| 104 // 1: overshoot | 127 // 1: overshoot |
| 105 // 0: not initialized. | 128 // 0: not initialized. |
| 106 int rc_1_frame; | 129 int rc_1_frame; |
| 107 int rc_2_frame; | 130 int rc_2_frame; |
| 108 int q_1_frame; | 131 int q_1_frame; |
| 109 int q_2_frame; | 132 int q_2_frame; |
| 133 |
| 134 // Auto frame-scaling variables. |
| 135 FRAME_SCALE_LEVEL frame_size_selector; |
| 136 FRAME_SCALE_LEVEL next_frame_size_selector; |
| 137 int frame_width[FRAME_SCALE_STEPS]; |
| 138 int frame_height[FRAME_SCALE_STEPS]; |
| 139 int rf_level_maxq[RATE_FACTOR_LEVELS]; |
| 110 } RATE_CONTROL; | 140 } RATE_CONTROL; |
| 111 | 141 |
| 112 struct VP9_COMP; | 142 struct VP9_COMP; |
| 113 struct VP9EncoderConfig; | 143 struct VP9EncoderConfig; |
| 114 | 144 |
| 115 void vp9_rc_init(const struct VP9EncoderConfig *oxcf, int pass, | 145 void vp9_rc_init(const struct VP9EncoderConfig *oxcf, int pass, |
| 116 RATE_CONTROL *rc); | 146 RATE_CONTROL *rc); |
| 117 | 147 |
| 118 int vp9_estimate_bits_at_q(FRAME_TYPE frame_kind, int q, int mbs, | 148 int vp9_estimate_bits_at_q(FRAME_TYPE frame_kind, int q, int mbs, |
| 119 double correction_factor, | 149 double correction_factor, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 void vp9_rc_get_svc_params(struct VP9_COMP *cpi); | 182 void vp9_rc_get_svc_params(struct VP9_COMP *cpi); |
| 153 | 183 |
| 154 // Post encode update of the rate control parameters based | 184 // Post encode update of the rate control parameters based |
| 155 // on bytes used | 185 // on bytes used |
| 156 void vp9_rc_postencode_update(struct VP9_COMP *cpi, uint64_t bytes_used); | 186 void vp9_rc_postencode_update(struct VP9_COMP *cpi, uint64_t bytes_used); |
| 157 // Post encode update of the rate control parameters for dropped frames | 187 // Post encode update of the rate control parameters for dropped frames |
| 158 void vp9_rc_postencode_update_drop_frame(struct VP9_COMP *cpi); | 188 void vp9_rc_postencode_update_drop_frame(struct VP9_COMP *cpi); |
| 159 | 189 |
| 160 // Updates rate correction factors | 190 // Updates rate correction factors |
| 161 // Changes only the rate correction factors in the rate control structure. | 191 // Changes only the rate correction factors in the rate control structure. |
| 162 void vp9_rc_update_rate_correction_factors(struct VP9_COMP *cpi, int damp_var); | 192 void vp9_rc_update_rate_correction_factors(struct VP9_COMP *cpi); |
| 163 | 193 |
| 164 // Decide if we should drop this frame: For 1-pass CBR. | 194 // Decide if we should drop this frame: For 1-pass CBR. |
| 165 // Changes only the decimation count in the rate control structure | 195 // Changes only the decimation count in the rate control structure |
| 166 int vp9_rc_drop_frame(struct VP9_COMP *cpi); | 196 int vp9_rc_drop_frame(struct VP9_COMP *cpi); |
| 167 | 197 |
| 168 // Computes frame size bounds. | 198 // Computes frame size bounds. |
| 169 void vp9_rc_compute_frame_size_bounds(const struct VP9_COMP *cpi, | 199 void vp9_rc_compute_frame_size_bounds(const struct VP9_COMP *cpi, |
| 170 int this_frame_target, | 200 int this_frame_target, |
| 171 int *frame_under_shoot_limit, | 201 int *frame_under_shoot_limit, |
| 172 int *frame_over_shoot_limit); | 202 int *frame_over_shoot_limit); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 197 // to a target q value | 227 // to a target q value |
| 198 int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget, | 228 int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget, |
| 199 vpx_bit_depth_t bit_depth); | 229 vpx_bit_depth_t bit_depth); |
| 200 | 230 |
| 201 // Computes a q delta (in "q index" terms) to get from a starting q value | 231 // Computes a q delta (in "q index" terms) to get from a starting q value |
| 202 // to a value that should equate to the given rate ratio. | 232 // to a value that should equate to the given rate ratio. |
| 203 int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type, | 233 int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type, |
| 204 int qindex, double rate_target_ratio, | 234 int qindex, double rate_target_ratio, |
| 205 vpx_bit_depth_t bit_depth); | 235 vpx_bit_depth_t bit_depth); |
| 206 | 236 |
| 237 int vp9_frame_type_qdelta(const struct VP9_COMP *cpi, int rf_level, int q); |
| 238 |
| 207 void vp9_rc_update_framerate(struct VP9_COMP *cpi); | 239 void vp9_rc_update_framerate(struct VP9_COMP *cpi); |
| 208 | 240 |
| 209 void vp9_rc_set_gf_max_interval(const struct VP9_COMP *const cpi, | 241 void vp9_rc_set_gf_max_interval(const struct VP9_COMP *const cpi, |
| 210 RATE_CONTROL *const rc); | 242 RATE_CONTROL *const rc); |
| 211 | 243 |
| 212 void vp9_set_target_rate(struct VP9_COMP *cpi); | 244 void vp9_set_target_rate(struct VP9_COMP *cpi); |
| 213 | 245 |
| 214 #ifdef __cplusplus | 246 #ifdef __cplusplus |
| 215 } // extern "C" | 247 } // extern "C" |
| 216 #endif | 248 #endif |
| 217 | 249 |
| 218 #endif // VP9_ENCODER_VP9_RATECTRL_H_ | 250 #endif // VP9_ENCODER_VP9_RATECTRL_H_ |
| OLD | NEW |