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 |
11 | 11 |
12 #ifndef VP9_ENCODER_VP9_RATECTRL_H_ | 12 #ifndef VP9_ENCODER_VP9_RATECTRL_H_ |
13 #define VP9_ENCODER_VP9_RATECTRL_H_ | 13 #define VP9_ENCODER_VP9_RATECTRL_H_ |
14 | 14 |
| 15 #include "vpx/vpx_integer.h" |
| 16 |
| 17 #include "vp9/common/vp9_blockd.h" |
| 18 |
15 #ifdef __cplusplus | 19 #ifdef __cplusplus |
16 extern "C" { | 20 extern "C" { |
17 #endif | 21 #endif |
18 | 22 |
19 #define FRAME_OVERHEAD_BITS 200 | 23 #define FRAME_OVERHEAD_BITS 200 |
20 | 24 |
| 25 // Bits Per MB at different Q (Multiplied by 512) |
| 26 #define BPER_MB_NORMBITS 9 |
| 27 |
21 typedef struct { | 28 typedef struct { |
22 // Rate targetting variables | 29 // Rate targetting variables |
23 int this_frame_target; | 30 int this_frame_target; |
24 int projected_frame_size; | 31 int projected_frame_size; |
25 int sb64_target_rate; | 32 int sb64_target_rate; |
26 int last_q[3]; // Separate values for Intra/Inter/ARF-GF | 33 int last_q[3]; // Separate values for Intra/Inter/ARF-GF |
27 int last_boosted_qindex; // Last boosted GF/KF/ARF q | 34 int last_boosted_qindex; // Last boosted GF/KF/ARF q |
28 | 35 |
29 int gfu_boost; | 36 int gfu_boost; |
30 int last_boost; | 37 int last_boost; |
31 int kf_boost; | 38 int kf_boost; |
32 | 39 |
33 double rate_correction_factor; | 40 double rate_correction_factor; |
34 double key_frame_rate_correction_factor; | 41 double key_frame_rate_correction_factor; |
35 double gf_rate_correction_factor; | 42 double gf_rate_correction_factor; |
36 | 43 |
37 int frames_since_golden; | 44 int frames_since_golden; |
38 int frames_till_gf_update_due; | 45 int frames_till_gf_update_due; |
39 int max_gf_interval; | 46 int max_gf_interval; |
| 47 int static_scene_max_gf_interval; |
40 int baseline_gf_interval; | 48 int baseline_gf_interval; |
41 int frames_to_key; | 49 int frames_to_key; |
42 int frames_since_key; | 50 int frames_since_key; |
43 int this_key_frame_forced; | 51 int this_key_frame_forced; |
44 int next_key_frame_forced; | 52 int next_key_frame_forced; |
45 int source_alt_ref_pending; | 53 int source_alt_ref_pending; |
46 int source_alt_ref_active; | 54 int source_alt_ref_active; |
47 int is_src_frame_alt_ref; | 55 int is_src_frame_alt_ref; |
48 | 56 |
49 int av_per_frame_bandwidth; // Average frame size target for clip | 57 int av_per_frame_bandwidth; // Average frame size target for clip |
50 int min_frame_bandwidth; // Minimum allocation used for any frame | 58 int min_frame_bandwidth; // Minimum allocation used for any frame |
51 int max_frame_bandwidth; // Maximum burst rate allowed for a frame. | 59 int max_frame_bandwidth; // Maximum burst rate allowed for a frame. |
52 | 60 |
53 int ni_av_qi; | 61 int ni_av_qi; |
54 int ni_tot_qi; | 62 int ni_tot_qi; |
55 int ni_frames; | 63 int ni_frames; |
56 int avg_frame_qindex[3]; // 0 - KEY, 1 - INTER, 2 - ARF/GF | 64 int avg_frame_qindex[3]; // 0 - KEY, 1 - INTER, 2 - ARF/GF |
57 double tot_q; | 65 double tot_q; |
58 double avg_q; | 66 double avg_q; |
59 | 67 |
60 int64_t buffer_level; | 68 int64_t buffer_level; |
61 int64_t bits_off_target; | 69 int64_t bits_off_target; |
62 | 70 |
63 int decimation_factor; | 71 int decimation_factor; |
64 int decimation_count; | 72 int decimation_count; |
65 | 73 |
66 int rolling_target_bits; | 74 int rolling_target_bits; |
67 int rolling_actual_bits; | 75 int rolling_actual_bits; |
68 | 76 |
69 int long_rolling_target_bits; | 77 int long_rolling_target_bits; |
70 int long_rolling_actual_bits; | 78 int long_rolling_actual_bits; |
71 | 79 |
72 int64_t total_actual_bits; | 80 int64_t total_actual_bits; |
73 int total_target_vs_actual; // debug stats | 81 int64_t total_target_bits; |
| 82 int64_t total_target_vs_actual; |
74 | 83 |
75 int worst_quality; | 84 int worst_quality; |
76 int best_quality; | 85 int best_quality; |
77 // int active_best_quality; | 86 // int active_best_quality; |
78 } RATE_CONTROL; | 87 } RATE_CONTROL; |
79 | 88 |
80 struct VP9_COMP; | 89 struct VP9_COMP; |
| 90 struct VP9_CONFIG; |
81 | 91 |
82 void vp9_save_coding_context(struct VP9_COMP *cpi); | 92 void vp9_rc_init(const struct VP9_CONFIG *oxcf, int pass, RATE_CONTROL *rc); |
83 void vp9_restore_coding_context(struct VP9_COMP *cpi); | |
84 | |
85 void vp9_setup_key_frame(struct VP9_COMP *cpi); | |
86 void vp9_setup_inter_frame(struct VP9_COMP *cpi); | |
87 | 93 |
88 double vp9_convert_qindex_to_q(int qindex); | 94 double vp9_convert_qindex_to_q(int qindex); |
89 | 95 |
90 // initialize luts for minq | 96 void vp9_rc_init_minq_luts(); |
91 void vp9_rc_init_minq_luts(void); | |
92 | 97 |
93 // Generally at the high level, the following flow is expected | 98 // Generally at the high level, the following flow is expected |
94 // to be enforced for rate control: | 99 // to be enforced for rate control: |
95 // First call per frame, one of: | 100 // First call per frame, one of: |
96 // vp9_rc_get_one_pass_vbr_params() | 101 // vp9_rc_get_one_pass_vbr_params() |
97 // vp9_rc_get_one_pass_cbr_params() | 102 // vp9_rc_get_one_pass_cbr_params() |
98 // vp9_rc_get_svc_params() | 103 // vp9_rc_get_svc_params() |
99 // vp9_rc_get_first_pass_params() | 104 // vp9_rc_get_first_pass_params() |
100 // vp9_rc_get_second_pass_params() | 105 // vp9_rc_get_second_pass_params() |
101 // depending on the usage to set the rate control encode parameters desired. | 106 // depending on the usage to set the rate control encode parameters desired. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 159 |
155 // Clamping utilities for bitrate targets for iframes and pframes. | 160 // Clamping utilities for bitrate targets for iframes and pframes. |
156 int vp9_rc_clamp_iframe_target_size(const struct VP9_COMP *const cpi, | 161 int vp9_rc_clamp_iframe_target_size(const struct VP9_COMP *const cpi, |
157 int target); | 162 int target); |
158 int vp9_rc_clamp_pframe_target_size(const struct VP9_COMP *const cpi, | 163 int vp9_rc_clamp_pframe_target_size(const struct VP9_COMP *const cpi, |
159 int target); | 164 int target); |
160 // Utility to set frame_target into the RATE_CONTROL structure | 165 // Utility to set frame_target into the RATE_CONTROL structure |
161 // This function is called only from the vp9_rc_get_..._params() functions. | 166 // This function is called only from the vp9_rc_get_..._params() functions. |
162 void vp9_rc_set_frame_target(struct VP9_COMP *cpi, int target); | 167 void vp9_rc_set_frame_target(struct VP9_COMP *cpi, int target); |
163 | 168 |
| 169 // Computes a q delta (in "q index" terms) to get from a starting q value |
| 170 // to a target q value |
| 171 int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget); |
| 172 |
| 173 // Computes a q delta (in "q index" terms) to get from a starting q value |
| 174 // to a value that should equate to the given rate ratio. |
| 175 int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type, |
| 176 int qindex, double rate_target_ratio); |
| 177 |
164 #ifdef __cplusplus | 178 #ifdef __cplusplus |
165 } // extern "C" | 179 } // extern "C" |
166 #endif | 180 #endif |
167 | 181 |
168 #endif // VP9_ENCODER_VP9_RATECTRL_H_ | 182 #endif // VP9_ENCODER_VP9_RATECTRL_H_ |
OLD | NEW |