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 #include <math.h> | 11 #include <math.h> |
12 #include <stdio.h> | 12 #include <stdio.h> |
13 #include <limits.h> | 13 #include <limits.h> |
14 | 14 |
15 #include "./vpx_config.h" | 15 #include "./vpx_config.h" |
16 #include "./vpx_scale_rtcd.h" | 16 #include "./vpx_scale_rtcd.h" |
17 #include "vpx/internal/vpx_psnr.h" | 17 #include "vpx/internal/vpx_psnr.h" |
18 #include "vpx_ports/vpx_timer.h" | 18 #include "vpx_ports/vpx_timer.h" |
19 | 19 |
20 #include "vp9/common/vp9_alloccommon.h" | 20 #include "vp9/common/vp9_alloccommon.h" |
21 #include "vp9/common/vp9_filter.h" | 21 #include "vp9/common/vp9_filter.h" |
22 #include "vp9/common/vp9_idct.h" | 22 #include "vp9/common/vp9_idct.h" |
23 #if CONFIG_VP9_POSTPROC | 23 #if CONFIG_VP9_POSTPROC |
24 #include "vp9/common/vp9_postproc.h" | 24 #include "vp9/common/vp9_postproc.h" |
25 #endif | 25 #endif |
26 #include "vp9/common/vp9_reconinter.h" | 26 #include "vp9/common/vp9_reconinter.h" |
27 #include "vp9/common/vp9_systemdependent.h" | 27 #include "vp9/common/vp9_systemdependent.h" |
28 #include "vp9/common/vp9_tile_common.h" | 28 #include "vp9/common/vp9_tile_common.h" |
29 | 29 |
| 30 #include "vp9/encoder/vp9_aq_complexity.h" |
| 31 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" |
| 32 #include "vp9/encoder/vp9_aq_variance.h" |
30 #include "vp9/encoder/vp9_bitstream.h" | 33 #include "vp9/encoder/vp9_bitstream.h" |
| 34 #include "vp9/encoder/vp9_encodeframe.h" |
31 #include "vp9/encoder/vp9_encodemv.h" | 35 #include "vp9/encoder/vp9_encodemv.h" |
32 #include "vp9/encoder/vp9_firstpass.h" | 36 #include "vp9/encoder/vp9_firstpass.h" |
33 #include "vp9/encoder/vp9_mbgraph.h" | 37 #include "vp9/encoder/vp9_mbgraph.h" |
34 #include "vp9/encoder/vp9_onyx_int.h" | 38 #include "vp9/encoder/vp9_onyx_int.h" |
35 #include "vp9/encoder/vp9_picklpf.h" | 39 #include "vp9/encoder/vp9_picklpf.h" |
36 #include "vp9/encoder/vp9_ratectrl.h" | 40 #include "vp9/encoder/vp9_ratectrl.h" |
37 #include "vp9/encoder/vp9_rdopt.h" | 41 #include "vp9/encoder/vp9_rdopt.h" |
38 #include "vp9/encoder/vp9_segmentation.h" | 42 #include "vp9/encoder/vp9_segmentation.h" |
| 43 #include "vp9/encoder/vp9_speed_features.h" |
| 44 #if CONFIG_INTERNAL_STATS |
| 45 #include "vp9/encoder/vp9_ssim.h" |
| 46 #endif |
39 #include "vp9/encoder/vp9_temporal_filter.h" | 47 #include "vp9/encoder/vp9_temporal_filter.h" |
40 #include "vp9/encoder/vp9_vaq.h" | |
41 #include "vp9/encoder/vp9_resize.h" | 48 #include "vp9/encoder/vp9_resize.h" |
| 49 #include "vp9/encoder/vp9_svc_layercontext.h" |
42 | 50 |
43 void vp9_coef_tree_initialize(); | 51 void vp9_coef_tree_initialize(); |
44 | 52 |
45 #define DEFAULT_INTERP_FILTER SWITCHABLE | 53 #define DEFAULT_INTERP_FILTER SWITCHABLE |
46 | 54 |
47 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ | 55 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ |
48 | 56 |
49 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv | 57 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
50 // for altref computation. | 58 // for altref computation. |
51 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision | 59 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
52 // mv. Choose a very high value for | 60 // mv. Choose a very high value for |
53 // now so that HIGH_PRECISION is always | 61 // now so that HIGH_PRECISION is always |
54 // chosen. | 62 // chosen. |
55 | 63 |
56 // Masks for partially or completely disabling split mode | |
57 #define DISABLE_ALL_SPLIT 0x3F | |
58 #define DISABLE_ALL_INTER_SPLIT 0x1F | |
59 #define DISABLE_COMPOUND_SPLIT 0x18 | |
60 #define LAST_AND_INTRA_SPLIT_ONLY 0x1E | |
61 | |
62 // Max rate target for 1080P and below encodes under normal circumstances | 64 // Max rate target for 1080P and below encodes under normal circumstances |
63 // (1920 * 1080 / (16 * 16)) * MAX_MB_RATE bits per MB | 65 // (1920 * 1080 / (16 * 16)) * MAX_MB_RATE bits per MB |
64 #define MAX_MB_RATE 250 | 66 #define MAX_MB_RATE 250 |
65 #define MAXRATE_1080P 2025000 | 67 #define MAXRATE_1080P 2025000 |
66 | 68 |
67 #if CONFIG_INTERNAL_STATS | |
68 extern double vp9_calc_ssim(YV12_BUFFER_CONFIG *source, | |
69 YV12_BUFFER_CONFIG *dest, int lumamask, | |
70 double *weight); | |
71 | |
72 | |
73 extern double vp9_calc_ssimg(YV12_BUFFER_CONFIG *source, | |
74 YV12_BUFFER_CONFIG *dest, double *ssim_y, | |
75 double *ssim_u, double *ssim_v); | |
76 | |
77 | |
78 #endif | |
79 | |
80 // #define OUTPUT_YUV_REC | 69 // #define OUTPUT_YUV_REC |
81 | 70 |
82 #ifdef OUTPUT_YUV_SRC | 71 #ifdef OUTPUT_YUV_SRC |
83 FILE *yuv_file; | 72 FILE *yuv_file; |
84 #endif | 73 #endif |
85 #ifdef OUTPUT_YUV_REC | 74 #ifdef OUTPUT_YUV_REC |
86 FILE *yuv_rec_file; | 75 FILE *yuv_rec_file; |
87 #endif | 76 #endif |
88 | 77 |
89 #if 0 | 78 #if 0 |
90 FILE *framepsnr; | 79 FILE *framepsnr; |
91 FILE *kf_list; | 80 FILE *kf_list; |
92 FILE *keyfile; | 81 FILE *keyfile; |
93 #endif | 82 #endif |
94 | 83 |
95 void vp9_init_quantizer(VP9_COMP *cpi); | 84 static INLINE void Scale2Ratio(VPX_SCALING mode, int *hr, int *hs) { |
96 | |
97 static const double in_frame_q_adj_ratio[MAX_SEGMENTS] = | |
98 {1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; | |
99 | |
100 static INLINE void Scale2Ratio(int mode, int *hr, int *hs) { | |
101 switch (mode) { | 85 switch (mode) { |
102 case NORMAL: | 86 case NORMAL: |
103 *hr = 1; | 87 *hr = 1; |
104 *hs = 1; | 88 *hs = 1; |
105 break; | 89 break; |
106 case FOURFIVE: | 90 case FOURFIVE: |
107 *hr = 4; | 91 *hr = 4; |
108 *hs = 5; | 92 *hs = 5; |
109 break; | 93 break; |
110 case THREEFIVE: | 94 case THREEFIVE: |
(...skipping 17 matching lines...) Expand all Loading... |
128 cpi->common.allow_high_precision_mv = allow_high_precision_mv; | 112 cpi->common.allow_high_precision_mv = allow_high_precision_mv; |
129 if (cpi->common.allow_high_precision_mv) { | 113 if (cpi->common.allow_high_precision_mv) { |
130 mb->mvcost = mb->nmvcost_hp; | 114 mb->mvcost = mb->nmvcost_hp; |
131 mb->mvsadcost = mb->nmvsadcost_hp; | 115 mb->mvsadcost = mb->nmvsadcost_hp; |
132 } else { | 116 } else { |
133 mb->mvcost = mb->nmvcost; | 117 mb->mvcost = mb->nmvcost; |
134 mb->mvsadcost = mb->nmvsadcost; | 118 mb->mvsadcost = mb->nmvsadcost; |
135 } | 119 } |
136 } | 120 } |
137 | 121 |
| 122 static void setup_key_frame(VP9_COMP *cpi) { |
| 123 vp9_setup_past_independence(&cpi->common); |
| 124 |
| 125 // All buffers are implicitly updated on key frames. |
| 126 cpi->refresh_golden_frame = 1; |
| 127 cpi->refresh_alt_ref_frame = 1; |
| 128 } |
| 129 |
| 130 static void setup_inter_frame(VP9_COMMON *cm) { |
| 131 if (cm->error_resilient_mode || cm->intra_only) |
| 132 vp9_setup_past_independence(cm); |
| 133 |
| 134 assert(cm->frame_context_idx < FRAME_CONTEXTS); |
| 135 cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
| 136 } |
| 137 |
138 void vp9_initialize_enc() { | 138 void vp9_initialize_enc() { |
139 static int init_done = 0; | 139 static int init_done = 0; |
140 | 140 |
141 if (!init_done) { | 141 if (!init_done) { |
142 vp9_initialize_common(); | 142 vp9_init_neighbors(); |
| 143 vp9_init_quant_tables(); |
| 144 |
143 vp9_coef_tree_initialize(); | 145 vp9_coef_tree_initialize(); |
144 vp9_tokenize_initialize(); | 146 vp9_tokenize_initialize(); |
145 vp9_init_quant_tables(); | |
146 vp9_init_me_luts(); | 147 vp9_init_me_luts(); |
147 vp9_rc_init_minq_luts(); | 148 vp9_rc_init_minq_luts(); |
148 // init_base_skip_probs(); | |
149 vp9_entropy_mv_init(); | 149 vp9_entropy_mv_init(); |
150 vp9_entropy_mode_init(); | 150 vp9_entropy_mode_init(); |
151 init_done = 1; | 151 init_done = 1; |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 static void dealloc_compressor_data(VP9_COMP *cpi) { | 155 static void dealloc_compressor_data(VP9_COMP *cpi) { |
156 VP9_COMMON *const cm = &cpi->common; | 156 VP9_COMMON *const cm = &cpi->common; |
| 157 int i; |
157 | 158 |
158 // Delete sementation map | 159 // Delete sementation map |
159 vpx_free(cpi->segmentation_map); | 160 vpx_free(cpi->segmentation_map); |
160 cpi->segmentation_map = NULL; | 161 cpi->segmentation_map = NULL; |
161 vpx_free(cm->last_frame_seg_map); | 162 vpx_free(cm->last_frame_seg_map); |
162 cm->last_frame_seg_map = NULL; | 163 cm->last_frame_seg_map = NULL; |
163 vpx_free(cpi->coding_context.last_frame_seg_map_copy); | 164 vpx_free(cpi->coding_context.last_frame_seg_map_copy); |
164 cpi->coding_context.last_frame_seg_map_copy = NULL; | 165 cpi->coding_context.last_frame_seg_map_copy = NULL; |
165 | 166 |
166 vpx_free(cpi->complexity_map); | 167 vpx_free(cpi->complexity_map); |
167 cpi->complexity_map = 0; | 168 cpi->complexity_map = NULL; |
| 169 |
| 170 vp9_cyclic_refresh_free(cpi->cyclic_refresh); |
| 171 cpi->cyclic_refresh = NULL; |
| 172 |
168 vpx_free(cpi->active_map); | 173 vpx_free(cpi->active_map); |
169 cpi->active_map = 0; | 174 cpi->active_map = NULL; |
170 | 175 |
171 vp9_free_frame_buffers(cm); | 176 vp9_free_frame_buffers(cm); |
172 | 177 |
173 vp9_free_frame_buffer(&cpi->last_frame_uf); | 178 vp9_free_frame_buffer(&cpi->last_frame_uf); |
174 vp9_free_frame_buffer(&cpi->scaled_source); | 179 vp9_free_frame_buffer(&cpi->scaled_source); |
| 180 vp9_free_frame_buffer(&cpi->scaled_last_source); |
175 vp9_free_frame_buffer(&cpi->alt_ref_buffer); | 181 vp9_free_frame_buffer(&cpi->alt_ref_buffer); |
176 vp9_lookahead_destroy(cpi->lookahead); | 182 vp9_lookahead_destroy(cpi->lookahead); |
177 | 183 |
178 vpx_free(cpi->tok); | 184 vpx_free(cpi->tok); |
179 cpi->tok = 0; | 185 cpi->tok = 0; |
180 | 186 |
181 // Activity mask based per mb zbin adjustments | 187 // Activity mask based per mb zbin adjustments |
182 vpx_free(cpi->mb_activity_map); | 188 vpx_free(cpi->mb_activity_map); |
183 cpi->mb_activity_map = 0; | 189 cpi->mb_activity_map = 0; |
184 vpx_free(cpi->mb_norm_activity_map); | 190 vpx_free(cpi->mb_norm_activity_map); |
185 cpi->mb_norm_activity_map = 0; | 191 cpi->mb_norm_activity_map = 0; |
186 | 192 |
187 vpx_free(cpi->above_context[0]); | 193 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { |
188 cpi->above_context[0] = NULL; | 194 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i]; |
189 | 195 vpx_free(lc->rc_twopass_stats_in.buf); |
190 vpx_free(cpi->above_seg_context); | 196 lc->rc_twopass_stats_in.buf = NULL; |
191 cpi->above_seg_context = NULL; | 197 lc->rc_twopass_stats_in.sz = 0; |
| 198 } |
192 } | 199 } |
193 | 200 |
194 // Computes a q delta (in "q index" terms) to get from a starting q value | 201 static void save_coding_context(VP9_COMP *cpi) { |
195 // to a target value | 202 CODING_CONTEXT *const cc = &cpi->coding_context; |
196 // target q value | 203 VP9_COMMON *cm = &cpi->common; |
197 int vp9_compute_qdelta(const VP9_COMP *cpi, double qstart, double qtarget) { | |
198 const RATE_CONTROL *const rc = &cpi->rc; | |
199 int start_index = rc->worst_quality; | |
200 int target_index = rc->worst_quality; | |
201 int i; | |
202 | 204 |
203 // Convert the average q value to an index. | 205 // Stores a snapshot of key state variables which can subsequently be |
204 for (i = rc->best_quality; i < rc->worst_quality; ++i) { | 206 // restored with a call to vp9_restore_coding_context. These functions are |
205 start_index = i; | 207 // intended for use in a re-code loop in vp9_compress_frame where the |
206 if (vp9_convert_qindex_to_q(i) >= qstart) | 208 // quantizer value is adjusted between loop iterations. |
207 break; | 209 vp9_copy(cc->nmvjointcost, cpi->mb.nmvjointcost); |
208 } | 210 vp9_copy(cc->nmvcosts, cpi->mb.nmvcosts); |
| 211 vp9_copy(cc->nmvcosts_hp, cpi->mb.nmvcosts_hp); |
209 | 212 |
210 // Convert the q target to an index | 213 vp9_copy(cc->segment_pred_probs, cm->seg.pred_probs); |
211 for (i = rc->best_quality; i < rc->worst_quality; ++i) { | |
212 target_index = i; | |
213 if (vp9_convert_qindex_to_q(i) >= qtarget) | |
214 break; | |
215 } | |
216 | 214 |
217 return target_index - start_index; | 215 vpx_memcpy(cpi->coding_context.last_frame_seg_map_copy, |
| 216 cm->last_frame_seg_map, (cm->mi_rows * cm->mi_cols)); |
| 217 |
| 218 vp9_copy(cc->last_ref_lf_deltas, cm->lf.last_ref_deltas); |
| 219 vp9_copy(cc->last_mode_lf_deltas, cm->lf.last_mode_deltas); |
| 220 |
| 221 cc->fc = cm->fc; |
218 } | 222 } |
219 | 223 |
220 // Computes a q delta (in "q index" terms) to get from a starting q value | 224 static void restore_coding_context(VP9_COMP *cpi) { |
221 // to a value that should equate to thegiven rate ratio. | 225 CODING_CONTEXT *const cc = &cpi->coding_context; |
| 226 VP9_COMMON *cm = &cpi->common; |
222 | 227 |
223 static int compute_qdelta_by_rate(VP9_COMP *cpi, int base_q_index, | 228 // Restore key state variables to the snapshot state stored in the |
224 double rate_target_ratio) { | 229 // previous call to vp9_save_coding_context. |
225 int i; | 230 vp9_copy(cpi->mb.nmvjointcost, cc->nmvjointcost); |
226 int target_index = cpi->rc.worst_quality; | 231 vp9_copy(cpi->mb.nmvcosts, cc->nmvcosts); |
| 232 vp9_copy(cpi->mb.nmvcosts_hp, cc->nmvcosts_hp); |
227 | 233 |
228 // Look up the current projected bits per block for the base index | 234 vp9_copy(cm->seg.pred_probs, cc->segment_pred_probs); |
229 const int base_bits_per_mb = vp9_rc_bits_per_mb(cpi->common.frame_type, | |
230 base_q_index, 1.0); | |
231 | 235 |
232 // Find the target bits per mb based on the base value and given ratio. | 236 vpx_memcpy(cm->last_frame_seg_map, |
233 const int target_bits_per_mb = (int)(rate_target_ratio * base_bits_per_mb); | 237 cpi->coding_context.last_frame_seg_map_copy, |
| 238 (cm->mi_rows * cm->mi_cols)); |
234 | 239 |
235 // Convert the q target to an index | 240 vp9_copy(cm->lf.last_ref_deltas, cc->last_ref_lf_deltas); |
236 for (i = cpi->rc.best_quality; i < cpi->rc.worst_quality; ++i) { | 241 vp9_copy(cm->lf.last_mode_deltas, cc->last_mode_lf_deltas); |
237 target_index = i; | |
238 if (vp9_rc_bits_per_mb(cpi->common.frame_type, i, 1.0) <= | |
239 target_bits_per_mb ) | |
240 break; | |
241 } | |
242 | 242 |
243 return target_index - base_q_index; | 243 cm->fc = cc->fc; |
244 } | 244 } |
245 | 245 |
246 // This function sets up a set of segments with delta Q values around | 246 static void configure_static_seg_features(VP9_COMP *cpi) { |
247 // the baseline frame quantizer. | |
248 static void setup_in_frame_q_adj(VP9_COMP *cpi) { | |
249 VP9_COMMON *const cm = &cpi->common; | 247 VP9_COMMON *const cm = &cpi->common; |
| 248 const RATE_CONTROL *const rc = &cpi->rc; |
250 struct segmentation *const seg = &cm->seg; | 249 struct segmentation *const seg = &cm->seg; |
251 | 250 |
252 // Make SURE use of floating point in this function is safe. | 251 int high_q = (int)(rc->avg_q > 48.0); |
253 vp9_clear_system_state(); | |
254 | |
255 if (cm->frame_type == KEY_FRAME || | |
256 cpi->refresh_alt_ref_frame || | |
257 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { | |
258 int segment; | |
259 | |
260 // Clear down the segment map | |
261 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); | |
262 | |
263 // Clear down the complexity map used for rd | |
264 vpx_memset(cpi->complexity_map, 0, cm->mi_rows * cm->mi_cols); | |
265 | |
266 vp9_enable_segmentation(seg); | |
267 vp9_clearall_segfeatures(seg); | |
268 | |
269 // Select delta coding method | |
270 seg->abs_delta = SEGMENT_DELTADATA; | |
271 | |
272 // Segment 0 "Q" feature is disabled so it defaults to the baseline Q | |
273 vp9_disable_segfeature(seg, 0, SEG_LVL_ALT_Q); | |
274 | |
275 // Use some of the segments for in frame Q adjustment | |
276 for (segment = 1; segment < 2; segment++) { | |
277 const int qindex_delta = compute_qdelta_by_rate(cpi, cm->base_qindex, | |
278 in_frame_q_adj_ratio[segment]); | |
279 vp9_enable_segfeature(seg, segment, SEG_LVL_ALT_Q); | |
280 vp9_set_segdata(seg, segment, SEG_LVL_ALT_Q, qindex_delta); | |
281 } | |
282 } | |
283 } | |
284 static void configure_static_seg_features(VP9_COMP *cpi) { | |
285 VP9_COMMON *const cm = &cpi->common; | |
286 struct segmentation *const seg = &cm->seg; | |
287 | |
288 int high_q = (int)(cpi->rc.avg_q > 48.0); | |
289 int qi_delta; | 252 int qi_delta; |
290 | 253 |
291 // Disable and clear down for KF | 254 // Disable and clear down for KF |
292 if (cm->frame_type == KEY_FRAME) { | 255 if (cm->frame_type == KEY_FRAME) { |
293 // Clear down the global segmentation map | 256 // Clear down the global segmentation map |
294 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); | 257 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
295 seg->update_map = 0; | 258 seg->update_map = 0; |
296 seg->update_data = 0; | 259 seg->update_data = 0; |
297 cpi->static_mb_pct = 0; | 260 cpi->static_mb_pct = 0; |
298 | 261 |
(...skipping 17 matching lines...) Expand all Loading... |
316 // Scan frames from current to arf frame. | 279 // Scan frames from current to arf frame. |
317 // This function re-enables segmentation if appropriate. | 280 // This function re-enables segmentation if appropriate. |
318 vp9_update_mbgraph_stats(cpi); | 281 vp9_update_mbgraph_stats(cpi); |
319 | 282 |
320 // If segmentation was enabled set those features needed for the | 283 // If segmentation was enabled set those features needed for the |
321 // arf itself. | 284 // arf itself. |
322 if (seg->enabled) { | 285 if (seg->enabled) { |
323 seg->update_map = 1; | 286 seg->update_map = 1; |
324 seg->update_data = 1; | 287 seg->update_data = 1; |
325 | 288 |
326 qi_delta = vp9_compute_qdelta( | 289 qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 0.875); |
327 cpi, cpi->rc.avg_q, (cpi->rc.avg_q * 0.875)); | 290 vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2); |
328 vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, (qi_delta - 2)); | |
329 vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); | 291 vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
330 | 292 |
331 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); | 293 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
332 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); | 294 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
333 | 295 |
334 // Where relevant assume segment data is delta data | 296 // Where relevant assume segment data is delta data |
335 seg->abs_delta = SEGMENT_DELTADATA; | 297 seg->abs_delta = SEGMENT_DELTADATA; |
336 } | 298 } |
337 } else if (seg->enabled) { | 299 } else if (seg->enabled) { |
338 // All other frames if segmentation has been enabled | 300 // All other frames if segmentation has been enabled |
339 | 301 |
340 // First normal frame in a valid gf or alt ref group | 302 // First normal frame in a valid gf or alt ref group |
341 if (cpi->rc.frames_since_golden == 0) { | 303 if (rc->frames_since_golden == 0) { |
342 // Set up segment features for normal frames in an arf group | 304 // Set up segment features for normal frames in an arf group |
343 if (cpi->rc.source_alt_ref_active) { | 305 if (rc->source_alt_ref_active) { |
344 seg->update_map = 0; | 306 seg->update_map = 0; |
345 seg->update_data = 1; | 307 seg->update_data = 1; |
346 seg->abs_delta = SEGMENT_DELTADATA; | 308 seg->abs_delta = SEGMENT_DELTADATA; |
347 | 309 |
348 qi_delta = vp9_compute_qdelta(cpi, cpi->rc.avg_q, | 310 qi_delta = vp9_compute_qdelta(rc, rc->avg_q, rc->avg_q * 1.125); |
349 (cpi->rc.avg_q * 1.125)); | 311 vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2); |
350 vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, (qi_delta + 2)); | |
351 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); | 312 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q); |
352 | 313 |
353 vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); | 314 vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2); |
354 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); | 315 vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF); |
355 | 316 |
356 // Segment coding disabled for compred testing | 317 // Segment coding disabled for compred testing |
357 if (high_q || (cpi->static_mb_pct == 100)) { | 318 if (high_q || (cpi->static_mb_pct == 100)) { |
358 vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); | 319 vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME); |
359 vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); | 320 vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
360 vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP); | 321 vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP); |
361 } | 322 } |
362 } else { | 323 } else { |
363 // Disable segmentation and clear down features if alt ref | 324 // Disable segmentation and clear down features if alt ref |
364 // is not active for this group | 325 // is not active for this group |
365 | 326 |
366 vp9_disable_segmentation(seg); | 327 vp9_disable_segmentation(seg); |
367 | 328 |
368 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); | 329 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
369 | 330 |
370 seg->update_map = 0; | 331 seg->update_map = 0; |
371 seg->update_data = 0; | 332 seg->update_data = 0; |
372 | 333 |
373 vp9_clearall_segfeatures(seg); | 334 vp9_clearall_segfeatures(seg); |
374 } | 335 } |
375 } else if (cpi->rc.is_src_frame_alt_ref) { | 336 } else if (rc->is_src_frame_alt_ref) { |
376 // Special case where we are coding over the top of a previous | 337 // Special case where we are coding over the top of a previous |
377 // alt ref frame. | 338 // alt ref frame. |
378 // Segment coding disabled for compred testing | 339 // Segment coding disabled for compred testing |
379 | 340 |
380 // Enable ref frame features for segment 0 as well | 341 // Enable ref frame features for segment 0 as well |
381 vp9_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); | 342 vp9_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME); |
382 vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); | 343 vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME); |
383 | 344 |
384 // All mbs should use ALTREF_FRAME | 345 // All mbs should use ALTREF_FRAME |
385 vp9_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); | 346 vp9_clear_segdata(seg, 0, SEG_LVL_REF_FRAME); |
(...skipping 11 matching lines...) Expand all Loading... |
397 } else { | 358 } else { |
398 // All other frames. | 359 // All other frames. |
399 | 360 |
400 // No updates.. leave things as they are. | 361 // No updates.. leave things as they are. |
401 seg->update_map = 0; | 362 seg->update_map = 0; |
402 seg->update_data = 0; | 363 seg->update_data = 0; |
403 } | 364 } |
404 } | 365 } |
405 } | 366 } |
406 | 367 |
407 // DEBUG: Print out the segment id of each MB in the current frame. | |
408 static void print_seg_map(VP9_COMP *cpi) { | |
409 VP9_COMMON *cm = &cpi->common; | |
410 int row, col; | |
411 int map_index = 0; | |
412 FILE *statsfile = fopen("segmap.stt", "a"); | |
413 | |
414 fprintf(statsfile, "%10d\n", cm->current_video_frame); | |
415 | |
416 for (row = 0; row < cpi->common.mi_rows; row++) { | |
417 for (col = 0; col < cpi->common.mi_cols; col++) { | |
418 fprintf(statsfile, "%10d", cpi->segmentation_map[map_index]); | |
419 map_index++; | |
420 } | |
421 fprintf(statsfile, "\n"); | |
422 } | |
423 fprintf(statsfile, "\n"); | |
424 | |
425 fclose(statsfile); | |
426 } | |
427 | |
428 static void update_reference_segmentation_map(VP9_COMP *cpi) { | 368 static void update_reference_segmentation_map(VP9_COMP *cpi) { |
429 VP9_COMMON *const cm = &cpi->common; | 369 VP9_COMMON *const cm = &cpi->common; |
430 MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; | 370 MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible; |
431 uint8_t *cache_ptr = cm->last_frame_seg_map; | 371 uint8_t *cache_ptr = cm->last_frame_seg_map; |
432 int row, col; | 372 int row, col; |
433 | 373 |
434 for (row = 0; row < cm->mi_rows; row++) { | 374 for (row = 0; row < cm->mi_rows; row++) { |
435 MODE_INFO **mi_8x8 = mi_8x8_ptr; | 375 MODE_INFO **mi_8x8 = mi_8x8_ptr; |
436 uint8_t *cache = cache_ptr; | 376 uint8_t *cache = cache_ptr; |
437 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) | 377 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
438 cache[0] = mi_8x8[0]->mbmi.segment_id; | 378 cache[0] = mi_8x8[0]->mbmi.segment_id; |
439 mi_8x8_ptr += cm->mode_info_stride; | 379 mi_8x8_ptr += cm->mi_stride; |
440 cache_ptr += cm->mi_cols; | 380 cache_ptr += cm->mi_cols; |
441 } | 381 } |
442 } | 382 } |
443 static int is_slowest_mode(int mode) { | 383 static int is_slowest_mode(int mode) { |
444 return (mode == MODE_SECONDPASS_BEST || mode == MODE_BESTQUALITY); | 384 return (mode == MODE_SECONDPASS_BEST || mode == MODE_BESTQUALITY); |
445 } | 385 } |
446 | 386 |
447 static void set_rd_speed_thresholds(VP9_COMP *cpi) { | 387 static void set_rd_speed_thresholds(VP9_COMP *cpi) { |
448 SPEED_FEATURES *sf = &cpi->sf; | |
449 int i; | 388 int i; |
450 | 389 |
451 // Set baseline threshold values | 390 // Set baseline threshold values |
452 for (i = 0; i < MAX_MODES; ++i) | 391 for (i = 0; i < MAX_MODES; ++i) |
453 sf->thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; | 392 cpi->rd_thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; |
454 | 393 |
455 sf->thresh_mult[THR_NEARESTMV] = 0; | 394 cpi->rd_thresh_mult[THR_NEARESTMV] = 0; |
456 sf->thresh_mult[THR_NEARESTG] = 0; | 395 cpi->rd_thresh_mult[THR_NEARESTG] = 0; |
457 sf->thresh_mult[THR_NEARESTA] = 0; | 396 cpi->rd_thresh_mult[THR_NEARESTA] = 0; |
458 | 397 |
459 sf->thresh_mult[THR_DC] += 1000; | 398 cpi->rd_thresh_mult[THR_DC] += 1000; |
460 | 399 |
461 sf->thresh_mult[THR_NEWMV] += 1000; | 400 cpi->rd_thresh_mult[THR_NEWMV] += 1000; |
462 sf->thresh_mult[THR_NEWA] += 1000; | 401 cpi->rd_thresh_mult[THR_NEWA] += 1000; |
463 sf->thresh_mult[THR_NEWG] += 1000; | 402 cpi->rd_thresh_mult[THR_NEWG] += 1000; |
464 | 403 |
465 sf->thresh_mult[THR_NEARMV] += 1000; | 404 cpi->rd_thresh_mult[THR_NEARMV] += 1000; |
466 sf->thresh_mult[THR_NEARA] += 1000; | 405 cpi->rd_thresh_mult[THR_NEARA] += 1000; |
467 sf->thresh_mult[THR_COMP_NEARESTLA] += 1000; | 406 cpi->rd_thresh_mult[THR_COMP_NEARESTLA] += 1000; |
468 sf->thresh_mult[THR_COMP_NEARESTGA] += 1000; | 407 cpi->rd_thresh_mult[THR_COMP_NEARESTGA] += 1000; |
469 | 408 |
470 sf->thresh_mult[THR_TM] += 1000; | 409 cpi->rd_thresh_mult[THR_TM] += 1000; |
471 | 410 |
472 sf->thresh_mult[THR_COMP_NEARLA] += 1500; | 411 cpi->rd_thresh_mult[THR_COMP_NEARLA] += 1500; |
473 sf->thresh_mult[THR_COMP_NEWLA] += 2000; | 412 cpi->rd_thresh_mult[THR_COMP_NEWLA] += 2000; |
474 sf->thresh_mult[THR_NEARG] += 1000; | 413 cpi->rd_thresh_mult[THR_NEARG] += 1000; |
475 sf->thresh_mult[THR_COMP_NEARGA] += 1500; | 414 cpi->rd_thresh_mult[THR_COMP_NEARGA] += 1500; |
476 sf->thresh_mult[THR_COMP_NEWGA] += 2000; | 415 cpi->rd_thresh_mult[THR_COMP_NEWGA] += 2000; |
477 | 416 |
478 sf->thresh_mult[THR_ZEROMV] += 2000; | 417 cpi->rd_thresh_mult[THR_ZEROMV] += 2000; |
479 sf->thresh_mult[THR_ZEROG] += 2000; | 418 cpi->rd_thresh_mult[THR_ZEROG] += 2000; |
480 sf->thresh_mult[THR_ZEROA] += 2000; | 419 cpi->rd_thresh_mult[THR_ZEROA] += 2000; |
481 sf->thresh_mult[THR_COMP_ZEROLA] += 2500; | 420 cpi->rd_thresh_mult[THR_COMP_ZEROLA] += 2500; |
482 sf->thresh_mult[THR_COMP_ZEROGA] += 2500; | 421 cpi->rd_thresh_mult[THR_COMP_ZEROGA] += 2500; |
483 | 422 |
484 sf->thresh_mult[THR_H_PRED] += 2000; | 423 cpi->rd_thresh_mult[THR_H_PRED] += 2000; |
485 sf->thresh_mult[THR_V_PRED] += 2000; | 424 cpi->rd_thresh_mult[THR_V_PRED] += 2000; |
486 sf->thresh_mult[THR_D45_PRED ] += 2500; | 425 cpi->rd_thresh_mult[THR_D45_PRED ] += 2500; |
487 sf->thresh_mult[THR_D135_PRED] += 2500; | 426 cpi->rd_thresh_mult[THR_D135_PRED] += 2500; |
488 sf->thresh_mult[THR_D117_PRED] += 2500; | 427 cpi->rd_thresh_mult[THR_D117_PRED] += 2500; |
489 sf->thresh_mult[THR_D153_PRED] += 2500; | 428 cpi->rd_thresh_mult[THR_D153_PRED] += 2500; |
490 sf->thresh_mult[THR_D207_PRED] += 2500; | 429 cpi->rd_thresh_mult[THR_D207_PRED] += 2500; |
491 sf->thresh_mult[THR_D63_PRED] += 2500; | 430 cpi->rd_thresh_mult[THR_D63_PRED] += 2500; |
492 | 431 |
493 /* disable frame modes if flags not set */ | 432 /* disable frame modes if flags not set */ |
494 if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) { | 433 if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) { |
495 sf->thresh_mult[THR_NEWMV ] = INT_MAX; | 434 cpi->rd_thresh_mult[THR_NEWMV ] = INT_MAX; |
496 sf->thresh_mult[THR_NEARESTMV] = INT_MAX; | 435 cpi->rd_thresh_mult[THR_NEARESTMV] = INT_MAX; |
497 sf->thresh_mult[THR_ZEROMV ] = INT_MAX; | 436 cpi->rd_thresh_mult[THR_ZEROMV ] = INT_MAX; |
498 sf->thresh_mult[THR_NEARMV ] = INT_MAX; | 437 cpi->rd_thresh_mult[THR_NEARMV ] = INT_MAX; |
499 } | 438 } |
500 if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) { | 439 if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) { |
501 sf->thresh_mult[THR_NEARESTG ] = INT_MAX; | 440 cpi->rd_thresh_mult[THR_NEARESTG ] = INT_MAX; |
502 sf->thresh_mult[THR_ZEROG ] = INT_MAX; | 441 cpi->rd_thresh_mult[THR_ZEROG ] = INT_MAX; |
503 sf->thresh_mult[THR_NEARG ] = INT_MAX; | 442 cpi->rd_thresh_mult[THR_NEARG ] = INT_MAX; |
504 sf->thresh_mult[THR_NEWG ] = INT_MAX; | 443 cpi->rd_thresh_mult[THR_NEWG ] = INT_MAX; |
505 } | 444 } |
506 if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) { | 445 if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) { |
507 sf->thresh_mult[THR_NEARESTA ] = INT_MAX; | 446 cpi->rd_thresh_mult[THR_NEARESTA ] = INT_MAX; |
508 sf->thresh_mult[THR_ZEROA ] = INT_MAX; | 447 cpi->rd_thresh_mult[THR_ZEROA ] = INT_MAX; |
509 sf->thresh_mult[THR_NEARA ] = INT_MAX; | 448 cpi->rd_thresh_mult[THR_NEARA ] = INT_MAX; |
510 sf->thresh_mult[THR_NEWA ] = INT_MAX; | 449 cpi->rd_thresh_mult[THR_NEWA ] = INT_MAX; |
511 } | 450 } |
512 | 451 |
513 if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) != | 452 if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) != |
514 (VP9_LAST_FLAG | VP9_ALT_FLAG)) { | 453 (VP9_LAST_FLAG | VP9_ALT_FLAG)) { |
515 sf->thresh_mult[THR_COMP_ZEROLA ] = INT_MAX; | 454 cpi->rd_thresh_mult[THR_COMP_ZEROLA ] = INT_MAX; |
516 sf->thresh_mult[THR_COMP_NEARESTLA] = INT_MAX; | 455 cpi->rd_thresh_mult[THR_COMP_NEARESTLA] = INT_MAX; |
517 sf->thresh_mult[THR_COMP_NEARLA ] = INT_MAX; | 456 cpi->rd_thresh_mult[THR_COMP_NEARLA ] = INT_MAX; |
518 sf->thresh_mult[THR_COMP_NEWLA ] = INT_MAX; | 457 cpi->rd_thresh_mult[THR_COMP_NEWLA ] = INT_MAX; |
519 } | 458 } |
520 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != | 459 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != |
521 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) { | 460 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) { |
522 sf->thresh_mult[THR_COMP_ZEROGA ] = INT_MAX; | 461 cpi->rd_thresh_mult[THR_COMP_ZEROGA ] = INT_MAX; |
523 sf->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX; | 462 cpi->rd_thresh_mult[THR_COMP_NEARESTGA] = INT_MAX; |
524 sf->thresh_mult[THR_COMP_NEARGA ] = INT_MAX; | 463 cpi->rd_thresh_mult[THR_COMP_NEARGA ] = INT_MAX; |
525 sf->thresh_mult[THR_COMP_NEWGA ] = INT_MAX; | 464 cpi->rd_thresh_mult[THR_COMP_NEWGA ] = INT_MAX; |
526 } | 465 } |
527 } | 466 } |
528 | 467 |
529 static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) { | 468 static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) { |
530 SPEED_FEATURES *sf = &cpi->sf; | 469 const SPEED_FEATURES *const sf = &cpi->sf; |
531 int i; | 470 int i; |
532 | 471 |
533 for (i = 0; i < MAX_REFS; ++i) | 472 for (i = 0; i < MAX_REFS; ++i) |
534 sf->thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; | 473 cpi->rd_thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; |
535 | 474 |
536 sf->thresh_mult_sub8x8[THR_LAST] += 2500; | 475 cpi->rd_thresh_mult_sub8x8[THR_LAST] += 2500; |
537 sf->thresh_mult_sub8x8[THR_GOLD] += 2500; | 476 cpi->rd_thresh_mult_sub8x8[THR_GOLD] += 2500; |
538 sf->thresh_mult_sub8x8[THR_ALTR] += 2500; | 477 cpi->rd_thresh_mult_sub8x8[THR_ALTR] += 2500; |
539 sf->thresh_mult_sub8x8[THR_INTRA] += 2500; | 478 cpi->rd_thresh_mult_sub8x8[THR_INTRA] += 2500; |
540 sf->thresh_mult_sub8x8[THR_COMP_LA] += 4500; | 479 cpi->rd_thresh_mult_sub8x8[THR_COMP_LA] += 4500; |
541 sf->thresh_mult_sub8x8[THR_COMP_GA] += 4500; | 480 cpi->rd_thresh_mult_sub8x8[THR_COMP_GA] += 4500; |
542 | 481 |
543 // Check for masked out split cases. | 482 // Check for masked out split cases. |
544 for (i = 0; i < MAX_REFS; i++) { | 483 for (i = 0; i < MAX_REFS; i++) |
545 if (sf->disable_split_mask & (1 << i)) | 484 if (sf->disable_split_mask & (1 << i)) |
546 sf->thresh_mult_sub8x8[i] = INT_MAX; | 485 cpi->rd_thresh_mult_sub8x8[i] = INT_MAX; |
547 } | |
548 | 486 |
549 // disable mode test if frame flag is not set | 487 // disable mode test if frame flag is not set |
550 if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) | 488 if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) |
551 sf->thresh_mult_sub8x8[THR_LAST] = INT_MAX; | 489 cpi->rd_thresh_mult_sub8x8[THR_LAST] = INT_MAX; |
552 if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) | 490 if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) |
553 sf->thresh_mult_sub8x8[THR_GOLD] = INT_MAX; | 491 cpi->rd_thresh_mult_sub8x8[THR_GOLD] = INT_MAX; |
554 if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) | 492 if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) |
555 sf->thresh_mult_sub8x8[THR_ALTR] = INT_MAX; | 493 cpi->rd_thresh_mult_sub8x8[THR_ALTR] = INT_MAX; |
556 if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) != | 494 if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) != |
557 (VP9_LAST_FLAG | VP9_ALT_FLAG)) | 495 (VP9_LAST_FLAG | VP9_ALT_FLAG)) |
558 sf->thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX; | 496 cpi->rd_thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX; |
559 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != | 497 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != |
560 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) | 498 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) |
561 sf->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX; | 499 cpi->rd_thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX; |
562 } | 500 } |
563 | 501 |
564 static void set_good_speed_feature(VP9_COMMON *cm, | 502 static void set_speed_features(VP9_COMP *cpi) { |
565 SPEED_FEATURES *sf, | 503 #if CONFIG_INTERNAL_STATS |
566 int speed) { | |
567 int i; | 504 int i; |
568 sf->adaptive_rd_thresh = 1; | |
569 sf->recode_loop = ((speed < 1) ? ALLOW_RECODE : ALLOW_RECODE_KFMAXBW); | |
570 if (speed == 1) { | |
571 sf->use_square_partition_only = !frame_is_intra_only(cm); | |
572 sf->less_rectangular_check = 1; | |
573 sf->tx_size_search_method = frame_is_intra_only(cm) | |
574 ? USE_FULL_RD : USE_LARGESTALL; | |
575 | |
576 if (MIN(cm->width, cm->height) >= 720) | |
577 sf->disable_split_mask = cm->show_frame ? | |
578 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; | |
579 else | |
580 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT; | |
581 | |
582 sf->use_rd_breakout = 1; | |
583 sf->adaptive_motion_search = 1; | |
584 sf->adaptive_pred_interp_filter = 1; | |
585 sf->auto_mv_step_size = 1; | |
586 sf->adaptive_rd_thresh = 2; | |
587 sf->recode_loop = ALLOW_RECODE_KFARFGF; | |
588 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; | |
589 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; | |
590 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; | |
591 } | |
592 if (speed == 2) { | |
593 sf->use_square_partition_only = !frame_is_intra_only(cm); | |
594 sf->less_rectangular_check = 1; | |
595 sf->tx_size_search_method = frame_is_intra_only(cm) | |
596 ? USE_FULL_RD : USE_LARGESTALL; | |
597 | |
598 if (MIN(cm->width, cm->height) >= 720) | |
599 sf->disable_split_mask = cm->show_frame ? | |
600 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; | |
601 else | |
602 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY; | |
603 | |
604 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | | |
605 FLAG_SKIP_INTRA_BESTINTER | | |
606 FLAG_SKIP_COMP_BESTINTRA | | |
607 FLAG_SKIP_INTRA_LOWVAR; | |
608 sf->use_rd_breakout = 1; | |
609 sf->adaptive_motion_search = 1; | |
610 sf->adaptive_pred_interp_filter = 2; | |
611 sf->reference_masking = 1; | |
612 sf->auto_mv_step_size = 1; | |
613 | |
614 sf->disable_filter_search_var_thresh = 50; | |
615 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | |
616 | |
617 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; | |
618 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION; | |
619 sf->adjust_partitioning_from_last_frame = 1; | |
620 sf->last_partitioning_redo_frequency = 3; | |
621 | |
622 sf->adaptive_rd_thresh = 2; | |
623 sf->recode_loop = ALLOW_RECODE_KFARFGF; | |
624 sf->use_lp32x32fdct = 1; | |
625 sf->mode_skip_start = 11; | |
626 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; | |
627 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; | |
628 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; | |
629 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; | |
630 } | |
631 if (speed == 3) { | |
632 sf->use_square_partition_only = 1; | |
633 sf->tx_size_search_method = USE_LARGESTALL; | |
634 | |
635 if (MIN(cm->width, cm->height) >= 720) | |
636 sf->disable_split_mask = DISABLE_ALL_SPLIT; | |
637 else | |
638 sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT; | |
639 | |
640 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | | |
641 FLAG_SKIP_INTRA_BESTINTER | | |
642 FLAG_SKIP_COMP_BESTINTRA | | |
643 FLAG_SKIP_INTRA_LOWVAR; | |
644 | |
645 sf->use_rd_breakout = 1; | |
646 sf->adaptive_motion_search = 1; | |
647 sf->adaptive_pred_interp_filter = 2; | |
648 sf->reference_masking = 1; | |
649 sf->auto_mv_step_size = 1; | |
650 | |
651 sf->disable_split_var_thresh = 32; | |
652 sf->disable_filter_search_var_thresh = 100; | |
653 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | |
654 | |
655 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; | |
656 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; | |
657 sf->adjust_partitioning_from_last_frame = 1; | |
658 sf->last_partitioning_redo_frequency = 3; | |
659 | |
660 sf->use_uv_intra_rd_estimate = 1; | |
661 sf->skip_encode_sb = 1; | |
662 sf->use_lp32x32fdct = 1; | |
663 sf->subpel_iters_per_step = 1; | |
664 sf->use_fast_coef_updates = 2; | |
665 | |
666 sf->adaptive_rd_thresh = 4; | |
667 sf->mode_skip_start = 6; | |
668 } | |
669 if (speed == 4) { | |
670 sf->use_square_partition_only = 1; | |
671 sf->tx_size_search_method = USE_LARGESTALL; | |
672 sf->disable_split_mask = DISABLE_ALL_SPLIT; | |
673 | |
674 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | | |
675 FLAG_SKIP_INTRA_BESTINTER | | |
676 FLAG_SKIP_COMP_BESTINTRA | | |
677 FLAG_SKIP_COMP_REFMISMATCH | | |
678 FLAG_SKIP_INTRA_LOWVAR | | |
679 FLAG_EARLY_TERMINATE; | |
680 | |
681 sf->use_rd_breakout = 1; | |
682 sf->adaptive_motion_search = 1; | |
683 sf->adaptive_pred_interp_filter = 2; | |
684 sf->reference_masking = 1; | |
685 sf->auto_mv_step_size = 1; | |
686 | |
687 sf->disable_split_var_thresh = 64; | |
688 sf->disable_filter_search_var_thresh = 200; | |
689 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | |
690 | |
691 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; | |
692 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; | |
693 sf->adjust_partitioning_from_last_frame = 1; | |
694 sf->last_partitioning_redo_frequency = 3; | |
695 | |
696 sf->use_uv_intra_rd_estimate = 1; | |
697 sf->skip_encode_sb = 1; | |
698 sf->use_lp32x32fdct = 1; | |
699 sf->subpel_iters_per_step = 1; | |
700 sf->use_fast_coef_updates = 2; | |
701 | |
702 sf->adaptive_rd_thresh = 4; | |
703 sf->mode_skip_start = 6; | |
704 } | |
705 if (speed >= 5) { | |
706 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | |
707 sf->partition_search_type = FIXED_PARTITION; | |
708 sf->always_this_block_size = BLOCK_16X16; | |
709 sf->tx_size_search_method = frame_is_intra_only(cm) ? | |
710 USE_FULL_RD : USE_LARGESTALL; | |
711 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | | |
712 FLAG_SKIP_INTRA_BESTINTER | | |
713 FLAG_SKIP_COMP_BESTINTRA | | |
714 FLAG_SKIP_COMP_REFMISMATCH | | |
715 FLAG_SKIP_INTRA_LOWVAR | | |
716 FLAG_EARLY_TERMINATE; | |
717 sf->use_rd_breakout = 1; | |
718 sf->use_lp32x32fdct = 1; | |
719 sf->optimize_coefficients = 0; | |
720 sf->auto_mv_step_size = 1; | |
721 sf->reference_masking = 1; | |
722 | |
723 sf->disable_split_mask = DISABLE_ALL_SPLIT; | |
724 sf->search_method = HEX; | |
725 sf->subpel_iters_per_step = 1; | |
726 sf->disable_split_var_thresh = 64; | |
727 sf->disable_filter_search_var_thresh = 500; | |
728 for (i = 0; i < TX_SIZES; i++) { | |
729 sf->intra_y_mode_mask[i] = INTRA_DC_ONLY; | |
730 sf->intra_uv_mode_mask[i] = INTRA_DC_ONLY; | |
731 } | |
732 sf->use_fast_coef_updates = 2; | |
733 sf->adaptive_rd_thresh = 4; | |
734 sf->mode_skip_start = 6; | |
735 } | |
736 } | |
737 | |
738 static void set_rt_speed_feature(VP9_COMMON *cm, | |
739 SPEED_FEATURES *sf, | |
740 int speed) { | |
741 sf->static_segmentation = 0; | |
742 sf->adaptive_rd_thresh = 1; | |
743 sf->recode_loop = ((speed < 1) ? ALLOW_RECODE : ALLOW_RECODE_KFMAXBW); | |
744 sf->encode_breakout_thresh = 1; | |
745 | |
746 if (speed == 1) { | |
747 sf->use_square_partition_only = !frame_is_intra_only(cm); | |
748 sf->less_rectangular_check = 1; | |
749 sf->tx_size_search_method = | |
750 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL; | |
751 | |
752 if (MIN(cm->width, cm->height) >= 720) | |
753 sf->disable_split_mask = cm->show_frame ? | |
754 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; | |
755 else | |
756 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT; | |
757 | |
758 sf->use_rd_breakout = 1; | |
759 sf->adaptive_motion_search = 1; | |
760 sf->adaptive_pred_interp_filter = 1; | |
761 sf->auto_mv_step_size = 1; | |
762 sf->adaptive_rd_thresh = 2; | |
763 sf->recode_loop = ALLOW_RECODE_KFARFGF; | |
764 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; | |
765 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; | |
766 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; | |
767 sf->encode_breakout_thresh = 8; | |
768 } | |
769 if (speed >= 2) { | |
770 sf->use_square_partition_only = !frame_is_intra_only(cm); | |
771 sf->less_rectangular_check = 1; | |
772 sf->tx_size_search_method = | |
773 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL; | |
774 | |
775 if (MIN(cm->width, cm->height) >= 720) | |
776 sf->disable_split_mask = cm->show_frame ? | |
777 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; | |
778 else | |
779 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY; | |
780 | |
781 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | |
782 | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA | |
783 | FLAG_SKIP_INTRA_LOWVAR; | |
784 | |
785 sf->use_rd_breakout = 1; | |
786 sf->adaptive_motion_search = 1; | |
787 sf->adaptive_pred_interp_filter = 2; | |
788 sf->auto_mv_step_size = 1; | |
789 sf->reference_masking = 1; | |
790 | |
791 sf->disable_filter_search_var_thresh = 50; | |
792 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | |
793 | |
794 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; | |
795 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION; | |
796 sf->adjust_partitioning_from_last_frame = 1; | |
797 sf->last_partitioning_redo_frequency = 3; | |
798 | |
799 sf->adaptive_rd_thresh = 2; | |
800 sf->recode_loop = ALLOW_RECODE_KFARFGF; | |
801 sf->use_lp32x32fdct = 1; | |
802 sf->mode_skip_start = 11; | |
803 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; | |
804 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; | |
805 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; | |
806 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; | |
807 sf->encode_breakout_thresh = 200; | |
808 } | |
809 if (speed >= 3) { | |
810 sf->use_square_partition_only = 1; | |
811 sf->tx_size_search_method = USE_LARGESTALL; | |
812 | |
813 if (MIN(cm->width, cm->height) >= 720) | |
814 sf->disable_split_mask = DISABLE_ALL_SPLIT; | |
815 else | |
816 sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT; | |
817 | |
818 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | |
819 | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA | |
820 | FLAG_SKIP_INTRA_LOWVAR; | |
821 | |
822 sf->disable_filter_search_var_thresh = 100; | |
823 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; | |
824 sf->use_uv_intra_rd_estimate = 1; | |
825 sf->skip_encode_sb = 1; | |
826 sf->subpel_iters_per_step = 1; | |
827 sf->use_fast_coef_updates = 2; | |
828 sf->adaptive_rd_thresh = 4; | |
829 sf->mode_skip_start = 6; | |
830 sf->encode_breakout_thresh = 400; | |
831 } | |
832 if (speed >= 4) { | |
833 sf->optimize_coefficients = 0; | |
834 sf->disable_split_mask = DISABLE_ALL_SPLIT; | |
835 sf->use_fast_lpf_pick = 2; | |
836 sf->encode_breakout_thresh = 700; | |
837 } | |
838 if (speed >= 5) { | |
839 int i; | |
840 sf->adaptive_rd_thresh = 5; | |
841 sf->auto_min_max_partition_size = frame_is_intra_only(cm) ? | |
842 RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX; | |
843 sf->adjust_partitioning_from_last_frame = | |
844 cm->last_frame_type == KEY_FRAME || (0 == | |
845 (cm->current_video_frame + 1) % sf->last_partitioning_redo_frequency); | |
846 sf->subpel_force_stop = 1; | |
847 for (i = 0; i < TX_SIZES; i++) { | |
848 sf->intra_y_mode_mask[i] = INTRA_DC_H_V; | |
849 sf->intra_uv_mode_mask[i] = INTRA_DC_ONLY; | |
850 } | |
851 sf->frame_parameter_update = 0; | |
852 sf->encode_breakout_thresh = 1000; | |
853 sf->search_method = FAST_HEX; | |
854 } | |
855 if (speed >= 6) { | |
856 sf->partition_search_type = VAR_BASED_FIXED_PARTITION; | |
857 sf->search_method = HEX; | |
858 } | |
859 if (speed >= 7) { | |
860 sf->partition_search_type = VAR_BASED_FIXED_PARTITION; | |
861 sf->use_nonrd_pick_mode = 1; | |
862 sf->search_method = FAST_HEX; | |
863 } | |
864 if (speed >= 8) { | |
865 int i; | |
866 for (i = 0; i < BLOCK_SIZES; ++i) | |
867 sf->disable_inter_mode_mask[i] = 14; // only search NEARESTMV (0) | |
868 } | |
869 } | |
870 | |
871 void vp9_set_speed_features(VP9_COMP *cpi) { | |
872 SPEED_FEATURES *sf = &cpi->sf; | |
873 VP9_COMMON *cm = &cpi->common; | |
874 int speed = cpi->speed; | |
875 int i; | |
876 | |
877 // Convert negative speed to positive | |
878 if (speed < 0) | |
879 speed = -speed; | |
880 | |
881 #if CONFIG_INTERNAL_STATS | |
882 for (i = 0; i < MAX_MODES; ++i) | 505 for (i = 0; i < MAX_MODES; ++i) |
883 cpi->mode_chosen_counts[i] = 0; | 506 cpi->mode_chosen_counts[i] = 0; |
884 #endif | 507 #endif |
885 | 508 |
886 // best quality defaults | 509 vp9_set_speed_features(cpi); |
887 sf->frame_parameter_update = 1; | |
888 sf->search_method = NSTEP; | |
889 sf->recode_loop = ALLOW_RECODE; | |
890 sf->subpel_search_method = SUBPEL_TREE; | |
891 sf->subpel_iters_per_step = 2; | |
892 sf->subpel_force_stop = 0; | |
893 sf->optimize_coefficients = !cpi->oxcf.lossless; | |
894 sf->reduce_first_step_size = 0; | |
895 sf->auto_mv_step_size = 0; | |
896 sf->max_step_search_steps = MAX_MVSEARCH_STEPS; | |
897 sf->comp_inter_joint_search_thresh = BLOCK_4X4; | |
898 sf->adaptive_rd_thresh = 0; | |
899 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_OFF; | |
900 sf->tx_size_search_method = USE_FULL_RD; | |
901 sf->use_lp32x32fdct = 0; | |
902 sf->adaptive_motion_search = 0; | |
903 sf->adaptive_pred_interp_filter = 0; | |
904 sf->reference_masking = 0; | |
905 sf->partition_search_type = SEARCH_PARTITION; | |
906 sf->less_rectangular_check = 0; | |
907 sf->use_square_partition_only = 0; | |
908 sf->auto_min_max_partition_size = NOT_IN_USE; | |
909 sf->max_partition_size = BLOCK_64X64; | |
910 sf->min_partition_size = BLOCK_4X4; | |
911 sf->adjust_partitioning_from_last_frame = 0; | |
912 sf->last_partitioning_redo_frequency = 4; | |
913 sf->disable_split_mask = 0; | |
914 sf->mode_search_skip_flags = 0; | |
915 sf->disable_split_var_thresh = 0; | |
916 sf->disable_filter_search_var_thresh = 0; | |
917 for (i = 0; i < TX_SIZES; i++) { | |
918 sf->intra_y_mode_mask[i] = ALL_INTRA_MODES; | |
919 sf->intra_uv_mode_mask[i] = ALL_INTRA_MODES; | |
920 } | |
921 sf->use_rd_breakout = 0; | |
922 sf->skip_encode_sb = 0; | |
923 sf->use_uv_intra_rd_estimate = 0; | |
924 sf->use_fast_lpf_pick = 0; | |
925 sf->use_fast_coef_updates = 0; | |
926 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set | |
927 sf->use_nonrd_pick_mode = 0; | |
928 sf->encode_breakout_thresh = 0; | |
929 for (i = 0; i < BLOCK_SIZES; ++i) | |
930 sf->disable_inter_mode_mask[i] = 0; | |
931 | |
932 switch (cpi->oxcf.mode) { | |
933 case MODE_BESTQUALITY: | |
934 case MODE_SECONDPASS_BEST: // This is the best quality mode. | |
935 cpi->diamond_search_sad = vp9_full_range_search; | |
936 break; | |
937 case MODE_FIRSTPASS: | |
938 case MODE_GOODQUALITY: | |
939 case MODE_SECONDPASS: | |
940 set_good_speed_feature(cm, sf, speed); | |
941 break; | |
942 case MODE_REALTIME: | |
943 set_rt_speed_feature(cm, sf, speed); | |
944 break; | |
945 }; /* switch */ | |
946 | 510 |
947 // Set rd thresholds based on mode and speed setting | 511 // Set rd thresholds based on mode and speed setting |
948 set_rd_speed_thresholds(cpi); | 512 set_rd_speed_thresholds(cpi); |
949 set_rd_speed_thresholds_sub8x8(cpi); | 513 set_rd_speed_thresholds_sub8x8(cpi); |
950 | 514 |
951 // Slow quant, dct and trellis not worthwhile for first pass | |
952 // so make sure they are always turned off. | |
953 if (cpi->pass == 1) { | |
954 sf->optimize_coefficients = 0; | |
955 } | |
956 | |
957 // No recode for 1 pass. | |
958 if (cpi->pass == 0) { | |
959 sf->recode_loop = DISALLOW_RECODE; | |
960 sf->optimize_coefficients = 0; | |
961 } | |
962 | |
963 cpi->mb.fwd_txm4x4 = vp9_fdct4x4; | 515 cpi->mb.fwd_txm4x4 = vp9_fdct4x4; |
964 if (cpi->oxcf.lossless || cpi->mb.e_mbd.lossless) { | 516 if (cpi->oxcf.lossless || cpi->mb.e_mbd.lossless) { |
965 cpi->mb.fwd_txm4x4 = vp9_fwht4x4; | 517 cpi->mb.fwd_txm4x4 = vp9_fwht4x4; |
966 } | 518 } |
967 | |
968 if (cpi->sf.subpel_search_method == SUBPEL_TREE) { | |
969 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree; | |
970 cpi->find_fractional_mv_step_comp = vp9_find_best_sub_pixel_comp_tree; | |
971 } | |
972 | |
973 cpi->mb.optimize = cpi->sf.optimize_coefficients == 1 && cpi->pass != 1; | |
974 | |
975 if (cpi->encode_breakout && cpi->oxcf.mode == MODE_REALTIME && | |
976 sf->encode_breakout_thresh > cpi->encode_breakout) | |
977 cpi->encode_breakout = sf->encode_breakout_thresh; | |
978 | |
979 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) | |
980 sf->adaptive_pred_interp_filter = 0; | |
981 } | 519 } |
982 | 520 |
983 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { | 521 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { |
984 VP9_COMMON *cm = &cpi->common; | 522 VP9_COMMON *cm = &cpi->common; |
985 const VP9_CONFIG *oxcf = &cpi->oxcf; | 523 const VP9_CONFIG *oxcf = &cpi->oxcf; |
986 | 524 |
987 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, | 525 cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height, |
988 cm->subsampling_x, cm->subsampling_y, | 526 cm->subsampling_x, cm->subsampling_y, |
989 oxcf->lag_in_frames); | 527 oxcf->lag_in_frames); |
990 if (!cpi->lookahead) | 528 if (!cpi->lookahead) |
(...skipping 22 matching lines...) Expand all Loading... |
1013 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 551 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
1014 "Failed to allocate last frame buffer"); | 552 "Failed to allocate last frame buffer"); |
1015 | 553 |
1016 if (vp9_alloc_frame_buffer(&cpi->scaled_source, | 554 if (vp9_alloc_frame_buffer(&cpi->scaled_source, |
1017 cm->width, cm->height, | 555 cm->width, cm->height, |
1018 cm->subsampling_x, cm->subsampling_y, | 556 cm->subsampling_x, cm->subsampling_y, |
1019 VP9_ENC_BORDER_IN_PIXELS)) | 557 VP9_ENC_BORDER_IN_PIXELS)) |
1020 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 558 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
1021 "Failed to allocate scaled source buffer"); | 559 "Failed to allocate scaled source buffer"); |
1022 | 560 |
| 561 if (vp9_alloc_frame_buffer(&cpi->scaled_last_source, |
| 562 cm->width, cm->height, |
| 563 cm->subsampling_x, cm->subsampling_y, |
| 564 VP9_ENC_BORDER_IN_PIXELS)) |
| 565 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 566 "Failed to allocate scaled last source buffer"); |
| 567 |
1023 vpx_free(cpi->tok); | 568 vpx_free(cpi->tok); |
1024 | 569 |
1025 { | 570 { |
1026 unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); | 571 unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); |
1027 | 572 |
1028 CHECK_MEM_ERROR(cm, cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); | 573 CHECK_MEM_ERROR(cm, cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); |
1029 } | 574 } |
1030 | 575 |
1031 vpx_free(cpi->mb_activity_map); | 576 vpx_free(cpi->mb_activity_map); |
1032 CHECK_MEM_ERROR(cm, cpi->mb_activity_map, | 577 CHECK_MEM_ERROR(cm, cpi->mb_activity_map, |
1033 vpx_calloc(sizeof(unsigned int), | 578 vpx_calloc(sizeof(unsigned int), |
1034 cm->mb_rows * cm->mb_cols)); | 579 cm->mb_rows * cm->mb_cols)); |
1035 | 580 |
1036 vpx_free(cpi->mb_norm_activity_map); | 581 vpx_free(cpi->mb_norm_activity_map); |
1037 CHECK_MEM_ERROR(cm, cpi->mb_norm_activity_map, | 582 CHECK_MEM_ERROR(cm, cpi->mb_norm_activity_map, |
1038 vpx_calloc(sizeof(unsigned int), | 583 vpx_calloc(sizeof(unsigned int), |
1039 cm->mb_rows * cm->mb_cols)); | 584 cm->mb_rows * cm->mb_cols)); |
1040 | |
1041 // 2 contexts per 'mi unit', so that we have one context per 4x4 txfm | |
1042 // block where mi unit size is 8x8. | |
1043 vpx_free(cpi->above_context[0]); | |
1044 CHECK_MEM_ERROR(cm, cpi->above_context[0], | |
1045 vpx_calloc(2 * mi_cols_aligned_to_sb(cm->mi_cols) * | |
1046 MAX_MB_PLANE, | |
1047 sizeof(*cpi->above_context[0]))); | |
1048 | |
1049 vpx_free(cpi->above_seg_context); | |
1050 CHECK_MEM_ERROR(cm, cpi->above_seg_context, | |
1051 vpx_calloc(mi_cols_aligned_to_sb(cm->mi_cols), | |
1052 sizeof(*cpi->above_seg_context))); | |
1053 } | 585 } |
1054 | 586 |
1055 | 587 |
1056 static void update_frame_size(VP9_COMP *cpi) { | 588 static void update_frame_size(VP9_COMP *cpi) { |
1057 VP9_COMMON *cm = &cpi->common; | 589 VP9_COMMON *const cm = &cpi->common; |
| 590 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
1058 | 591 |
1059 vp9_update_frame_size(cm); | 592 vp9_update_frame_size(cm); |
1060 | 593 |
1061 // Update size of buffers local to this frame | 594 // Update size of buffers local to this frame |
1062 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, | 595 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, |
1063 cm->width, cm->height, | 596 cm->width, cm->height, |
1064 cm->subsampling_x, cm->subsampling_y, | 597 cm->subsampling_x, cm->subsampling_y, |
1065 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) | 598 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
1066 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 599 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
1067 "Failed to reallocate last frame buffer"); | 600 "Failed to reallocate last frame buffer"); |
1068 | 601 |
1069 if (vp9_realloc_frame_buffer(&cpi->scaled_source, | 602 if (vp9_realloc_frame_buffer(&cpi->scaled_source, |
1070 cm->width, cm->height, | 603 cm->width, cm->height, |
1071 cm->subsampling_x, cm->subsampling_y, | 604 cm->subsampling_x, cm->subsampling_y, |
1072 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) | 605 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
1073 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 606 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
1074 "Failed to reallocate scaled source buffer"); | 607 "Failed to reallocate scaled source buffer"); |
1075 | 608 |
| 609 if (vp9_realloc_frame_buffer(&cpi->scaled_last_source, |
| 610 cm->width, cm->height, |
| 611 cm->subsampling_x, cm->subsampling_y, |
| 612 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
| 613 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 614 "Failed to reallocate scaled last source buffer"); |
| 615 |
1076 { | 616 { |
1077 int y_stride = cpi->scaled_source.y_stride; | 617 int y_stride = cpi->scaled_source.y_stride; |
1078 | 618 |
1079 if (cpi->sf.search_method == NSTEP) { | 619 if (cpi->sf.search_method == NSTEP) { |
1080 vp9_init3smotion_compensation(&cpi->mb, y_stride); | 620 vp9_init3smotion_compensation(&cpi->mb, y_stride); |
1081 } else if (cpi->sf.search_method == DIAMOND) { | 621 } else if (cpi->sf.search_method == DIAMOND) { |
1082 vp9_init_dsmotion_compensation(&cpi->mb, y_stride); | 622 vp9_init_dsmotion_compensation(&cpi->mb, y_stride); |
1083 } | 623 } |
1084 } | 624 } |
1085 | 625 |
1086 { | 626 init_macroblockd(cm, xd); |
1087 int i; | |
1088 for (i = 1; i < MAX_MB_PLANE; ++i) { | |
1089 cpi->above_context[i] = cpi->above_context[0] + | |
1090 i * sizeof(*cpi->above_context[0]) * 2 * | |
1091 mi_cols_aligned_to_sb(cm->mi_cols); | |
1092 } | |
1093 } | |
1094 } | 627 } |
1095 | 628 |
1096 | |
1097 // Table that converts 0-63 Q range values passed in outside to the Qindex | |
1098 // range used internally. | |
1099 static const int q_trans[] = { | |
1100 0, 4, 8, 12, 16, 20, 24, 28, | |
1101 32, 36, 40, 44, 48, 52, 56, 60, | |
1102 64, 68, 72, 76, 80, 84, 88, 92, | |
1103 96, 100, 104, 108, 112, 116, 120, 124, | |
1104 128, 132, 136, 140, 144, 148, 152, 156, | |
1105 160, 164, 168, 172, 176, 180, 184, 188, | |
1106 192, 196, 200, 204, 208, 212, 216, 220, | |
1107 224, 228, 232, 236, 240, 244, 249, 255, | |
1108 }; | |
1109 | |
1110 int vp9_reverse_trans(int x) { | |
1111 int i; | |
1112 | |
1113 for (i = 0; i < 64; i++) | |
1114 if (q_trans[i] >= x) | |
1115 return i; | |
1116 | |
1117 return 63; | |
1118 }; | |
1119 | |
1120 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { | 629 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { |
1121 VP9_COMMON *const cm = &cpi->common; | 630 VP9_COMMON *const cm = &cpi->common; |
| 631 RATE_CONTROL *const rc = &cpi->rc; |
| 632 VP9_CONFIG *const oxcf = &cpi->oxcf; |
1122 int vbr_max_bits; | 633 int vbr_max_bits; |
1123 | 634 |
1124 if (framerate < 0.1) | 635 oxcf->framerate = framerate < 0.1 ? 30 : framerate; |
1125 framerate = 30; | 636 cpi->output_framerate = cpi->oxcf.framerate; |
| 637 rc->av_per_frame_bandwidth = (int)(oxcf->target_bandwidth / |
| 638 cpi->output_framerate); |
| 639 rc->min_frame_bandwidth = (int)(rc->av_per_frame_bandwidth * |
| 640 oxcf->two_pass_vbrmin_section / 100); |
1126 | 641 |
1127 cpi->oxcf.framerate = framerate; | 642 rc->min_frame_bandwidth = MAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS); |
1128 cpi->output_framerate = cpi->oxcf.framerate; | |
1129 cpi->rc.av_per_frame_bandwidth = (int)(cpi->oxcf.target_bandwidth | |
1130 / cpi->output_framerate); | |
1131 cpi->rc.min_frame_bandwidth = (int)(cpi->rc.av_per_frame_bandwidth * | |
1132 cpi->oxcf.two_pass_vbrmin_section / 100); | |
1133 | |
1134 | |
1135 cpi->rc.min_frame_bandwidth = MAX(cpi->rc.min_frame_bandwidth, | |
1136 FRAME_OVERHEAD_BITS); | |
1137 | 643 |
1138 // A maximum bitrate for a frame is defined. | 644 // A maximum bitrate for a frame is defined. |
1139 // The baseline for this aligns with HW implementations that | 645 // The baseline for this aligns with HW implementations that |
1140 // can support decode of 1080P content up to a bitrate of MAX_MB_RATE bits | 646 // can support decode of 1080P content up to a bitrate of MAX_MB_RATE bits |
1141 // per 16x16 MB (averaged over a frame). However this limit is extended if | 647 // per 16x16 MB (averaged over a frame). However this limit is extended if |
1142 // a very high rate is given on the command line or the the rate cannnot | 648 // a very high rate is given on the command line or the the rate cannnot |
1143 // be acheived because of a user specificed max q (e.g. when the user | 649 // be acheived because of a user specificed max q (e.g. when the user |
1144 // specifies lossless encode. | 650 // specifies lossless encode. |
1145 // | 651 // |
1146 vbr_max_bits = (int)(((int64_t)cpi->rc.av_per_frame_bandwidth * | 652 vbr_max_bits = (int)(((int64_t)rc->av_per_frame_bandwidth * |
1147 cpi->oxcf.two_pass_vbrmax_section) / 100); | 653 oxcf->two_pass_vbrmax_section) / 100); |
1148 cpi->rc.max_frame_bandwidth = | 654 rc->max_frame_bandwidth = MAX(MAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), |
1149 MAX(MAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P), vbr_max_bits); | 655 vbr_max_bits); |
1150 | 656 |
1151 // Set Maximum gf/arf interval | 657 // Set Maximum gf/arf interval |
1152 cpi->rc.max_gf_interval = 16; | 658 rc->max_gf_interval = 16; |
1153 | 659 |
1154 // Extended interval for genuinely static scenes | 660 // Extended interval for genuinely static scenes |
1155 cpi->twopass.static_scene_max_gf_interval = cpi->key_frame_frequency >> 1; | 661 rc->static_scene_max_gf_interval = cpi->key_frame_frequency >> 1; |
1156 | 662 |
1157 // Special conditions when alt ref frame enabled in lagged compress mode | 663 // Special conditions when alt ref frame enabled in lagged compress mode |
1158 if (cpi->oxcf.play_alternate && cpi->oxcf.lag_in_frames) { | 664 if (oxcf->play_alternate && oxcf->lag_in_frames) { |
1159 if (cpi->rc.max_gf_interval > cpi->oxcf.lag_in_frames - 1) | 665 if (rc->max_gf_interval > oxcf->lag_in_frames - 1) |
1160 cpi->rc.max_gf_interval = cpi->oxcf.lag_in_frames - 1; | 666 rc->max_gf_interval = oxcf->lag_in_frames - 1; |
1161 | 667 |
1162 if (cpi->twopass.static_scene_max_gf_interval > cpi->oxcf.lag_in_frames - 1) | 668 if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1) |
1163 cpi->twopass.static_scene_max_gf_interval = cpi->oxcf.lag_in_frames - 1; | 669 rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1; |
1164 } | 670 } |
1165 | 671 |
1166 if (cpi->rc.max_gf_interval > cpi->twopass.static_scene_max_gf_interval) | 672 if (rc->max_gf_interval > rc->static_scene_max_gf_interval) |
1167 cpi->rc.max_gf_interval = cpi->twopass.static_scene_max_gf_interval; | 673 rc->max_gf_interval = rc->static_scene_max_gf_interval; |
1168 } | 674 } |
1169 | 675 |
1170 static int64_t rescale(int64_t val, int64_t num, int denom) { | 676 int64_t vp9_rescale(int64_t val, int64_t num, int denom) { |
1171 int64_t llnum = num; | 677 int64_t llnum = num; |
1172 int64_t llden = denom; | 678 int64_t llden = denom; |
1173 int64_t llval = val; | 679 int64_t llval = val; |
1174 | 680 |
1175 return (llval * llnum / llden); | 681 return (llval * llnum / llden); |
1176 } | 682 } |
1177 | 683 |
1178 // Initialize layer context data from init_config(). | |
1179 static void init_layer_context(VP9_COMP *const cpi) { | |
1180 const VP9_CONFIG *const oxcf = &cpi->oxcf; | |
1181 int temporal_layer = 0; | |
1182 cpi->svc.spatial_layer_id = 0; | |
1183 cpi->svc.temporal_layer_id = 0; | |
1184 for (temporal_layer = 0; temporal_layer < cpi->svc.number_temporal_layers; | |
1185 ++temporal_layer) { | |
1186 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[temporal_layer]; | |
1187 RATE_CONTROL *const lrc = &lc->rc; | |
1188 lrc->avg_frame_qindex[INTER_FRAME] = q_trans[oxcf->worst_allowed_q]; | |
1189 lrc->last_q[INTER_FRAME] = q_trans[oxcf->worst_allowed_q]; | |
1190 lrc->ni_av_qi = q_trans[oxcf->worst_allowed_q]; | |
1191 lrc->total_actual_bits = 0; | |
1192 lrc->total_target_vs_actual = 0; | |
1193 lrc->ni_tot_qi = 0; | |
1194 lrc->tot_q = 0.0; | |
1195 lrc->avg_q = 0.0; | |
1196 lrc->ni_frames = 0; | |
1197 lrc->decimation_count = 0; | |
1198 lrc->decimation_factor = 0; | |
1199 lrc->rate_correction_factor = 1.0; | |
1200 lrc->key_frame_rate_correction_factor = 1.0; | |
1201 lc->target_bandwidth = oxcf->ts_target_bitrate[temporal_layer] * | |
1202 1000; | |
1203 lrc->buffer_level = rescale((int)(oxcf->starting_buffer_level), | |
1204 lc->target_bandwidth, 1000); | |
1205 lrc->bits_off_target = lrc->buffer_level; | |
1206 } | |
1207 } | |
1208 | |
1209 // Update the layer context from a change_config() call. | |
1210 static void update_layer_context_change_config(VP9_COMP *const cpi, | |
1211 const int target_bandwidth) { | |
1212 const VP9_CONFIG *const oxcf = &cpi->oxcf; | |
1213 const RATE_CONTROL *const rc = &cpi->rc; | |
1214 int temporal_layer = 0; | |
1215 float bitrate_alloc = 1.0; | |
1216 for (temporal_layer = 0; temporal_layer < cpi->svc.number_temporal_layers; | |
1217 ++temporal_layer) { | |
1218 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[temporal_layer]; | |
1219 RATE_CONTROL *const lrc = &lc->rc; | |
1220 lc->target_bandwidth = oxcf->ts_target_bitrate[temporal_layer] * 1000; | |
1221 bitrate_alloc = (float)lc->target_bandwidth / (float)target_bandwidth; | |
1222 // Update buffer-related quantities. | |
1223 lc->starting_buffer_level = | |
1224 (int64_t)(oxcf->starting_buffer_level * bitrate_alloc); | |
1225 lc->optimal_buffer_level = | |
1226 (int64_t)(oxcf->optimal_buffer_level * bitrate_alloc); | |
1227 lc->maximum_buffer_size = | |
1228 (int64_t)(oxcf->maximum_buffer_size * bitrate_alloc); | |
1229 lrc->bits_off_target = MIN(lrc->bits_off_target, lc->maximum_buffer_size); | |
1230 lrc->buffer_level = MIN(lrc->buffer_level, lc->maximum_buffer_size); | |
1231 // Update framerate-related quantities. | |
1232 lc->framerate = oxcf->framerate / oxcf->ts_rate_decimator[temporal_layer]; | |
1233 lrc->av_per_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); | |
1234 lrc->max_frame_bandwidth = rc->max_frame_bandwidth; | |
1235 // Update qp-related quantities. | |
1236 lrc->worst_quality = rc->worst_quality; | |
1237 lrc->best_quality = rc->best_quality; | |
1238 } | |
1239 } | |
1240 | |
1241 // Prior to encoding the frame, update framerate-related quantities | |
1242 // for the current layer. | |
1243 static void update_layer_framerate(VP9_COMP *const cpi) { | |
1244 int temporal_layer = cpi->svc.temporal_layer_id; | |
1245 const VP9_CONFIG *const oxcf = &cpi->oxcf; | |
1246 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[temporal_layer]; | |
1247 RATE_CONTROL *const lrc = &lc->rc; | |
1248 lc->framerate = oxcf->framerate / oxcf->ts_rate_decimator[temporal_layer]; | |
1249 lrc->av_per_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); | |
1250 lrc->max_frame_bandwidth = cpi->rc.max_frame_bandwidth; | |
1251 // Update the average layer frame size (non-cumulative per-frame-bw). | |
1252 if (temporal_layer == 0) { | |
1253 lc->avg_frame_size = lrc->av_per_frame_bandwidth; | |
1254 } else { | |
1255 double prev_layer_framerate = oxcf->framerate / | |
1256 oxcf->ts_rate_decimator[temporal_layer - 1]; | |
1257 int prev_layer_target_bandwidth = | |
1258 oxcf->ts_target_bitrate[temporal_layer - 1] * 1000; | |
1259 lc->avg_frame_size = | |
1260 (int)((lc->target_bandwidth - prev_layer_target_bandwidth) / | |
1261 (lc->framerate - prev_layer_framerate)); | |
1262 } | |
1263 } | |
1264 | |
1265 // Prior to encoding the frame, set the layer context, for the current layer | |
1266 // to be encoded, to the cpi struct. | |
1267 static void restore_layer_context(VP9_COMP *const cpi) { | |
1268 int temporal_layer = cpi->svc.temporal_layer_id; | |
1269 LAYER_CONTEXT *lc = &cpi->svc.layer_context[temporal_layer]; | |
1270 int frame_since_key = cpi->rc.frames_since_key; | |
1271 int frame_to_key = cpi->rc.frames_to_key; | |
1272 cpi->rc = lc->rc; | |
1273 cpi->oxcf.target_bandwidth = lc->target_bandwidth; | |
1274 cpi->oxcf.starting_buffer_level = lc->starting_buffer_level; | |
1275 cpi->oxcf.optimal_buffer_level = lc->optimal_buffer_level; | |
1276 cpi->oxcf.maximum_buffer_size = lc->maximum_buffer_size; | |
1277 cpi->output_framerate = lc->framerate; | |
1278 // Reset the frames_since_key and frames_to_key counters to their values | |
1279 // before the layer restore. Keep these defined for the stream (not layer). | |
1280 cpi->rc.frames_since_key = frame_since_key; | |
1281 cpi->rc.frames_to_key = frame_to_key; | |
1282 } | |
1283 | |
1284 // Save the layer context after encoding the frame. | |
1285 static void save_layer_context(VP9_COMP *const cpi) { | |
1286 int temporal_layer = cpi->svc.temporal_layer_id; | |
1287 LAYER_CONTEXT *lc = &cpi->svc.layer_context[temporal_layer]; | |
1288 lc->rc = cpi->rc; | |
1289 lc->target_bandwidth = (int)cpi->oxcf.target_bandwidth; | |
1290 lc->starting_buffer_level = cpi->oxcf.starting_buffer_level; | |
1291 lc->optimal_buffer_level = cpi->oxcf.optimal_buffer_level; | |
1292 lc->maximum_buffer_size = cpi->oxcf.maximum_buffer_size; | |
1293 lc->framerate = cpi->output_framerate; | |
1294 } | |
1295 | |
1296 static void set_tile_limits(VP9_COMP *cpi) { | 684 static void set_tile_limits(VP9_COMP *cpi) { |
1297 VP9_COMMON *const cm = &cpi->common; | 685 VP9_COMMON *const cm = &cpi->common; |
1298 | 686 |
1299 int min_log2_tile_cols, max_log2_tile_cols; | 687 int min_log2_tile_cols, max_log2_tile_cols; |
1300 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); | 688 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); |
1301 | 689 |
1302 cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns, | 690 cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns, |
1303 min_log2_tile_cols, max_log2_tile_cols); | 691 min_log2_tile_cols, max_log2_tile_cols); |
1304 cm->log2_tile_rows = cpi->oxcf.tile_rows; | 692 cm->log2_tile_rows = cpi->oxcf.tile_rows; |
1305 } | 693 } |
1306 | 694 |
1307 static void init_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { | 695 static void init_config(struct VP9_COMP *cpi, VP9_CONFIG *oxcf) { |
1308 VP9_COMP *cpi = (VP9_COMP *)(ptr); | |
1309 VP9_COMMON *const cm = &cpi->common; | 696 VP9_COMMON *const cm = &cpi->common; |
1310 int i; | 697 int i; |
1311 | 698 |
1312 cpi->oxcf = *oxcf; | 699 cpi->oxcf = *oxcf; |
1313 | 700 |
1314 cm->version = oxcf->version; | 701 cm->profile = oxcf->profile; |
| 702 cm->bit_depth = oxcf->bit_depth; |
1315 | 703 |
1316 cm->width = oxcf->width; | 704 cm->width = oxcf->width; |
1317 cm->height = oxcf->height; | 705 cm->height = oxcf->height; |
1318 cm->subsampling_x = 0; | 706 cm->subsampling_x = 0; |
1319 cm->subsampling_y = 0; | 707 cm->subsampling_y = 0; |
1320 vp9_alloc_compressor_data(cpi); | 708 vp9_alloc_compressor_data(cpi); |
1321 | 709 |
1322 // Spatial scalability. | 710 // Spatial scalability. |
1323 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; | 711 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; |
1324 // Temporal scalability. | 712 // Temporal scalability. |
1325 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; | 713 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; |
1326 | 714 |
1327 if (cpi->svc.number_temporal_layers > 1 && | 715 if ((cpi->svc.number_temporal_layers > 1 && |
1328 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { | 716 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) || |
1329 init_layer_context(cpi); | 717 (cpi->svc.number_spatial_layers > 1 && |
| 718 cpi->oxcf.mode == MODE_SECONDPASS_BEST)) { |
| 719 vp9_init_layer_context(cpi); |
1330 } | 720 } |
1331 | 721 |
1332 // change includes all joint functionality | 722 // change includes all joint functionality |
1333 vp9_change_config(ptr, oxcf); | 723 vp9_change_config(cpi, oxcf); |
1334 | |
1335 // Initialize active best and worst q and average q values. | |
1336 if (cpi->pass == 0 && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { | |
1337 cpi->rc.avg_frame_qindex[0] = cpi->oxcf.worst_allowed_q; | |
1338 cpi->rc.avg_frame_qindex[1] = cpi->oxcf.worst_allowed_q; | |
1339 cpi->rc.avg_frame_qindex[2] = cpi->oxcf.worst_allowed_q; | |
1340 } else { | |
1341 cpi->rc.avg_frame_qindex[0] = (cpi->oxcf.worst_allowed_q + | |
1342 cpi->oxcf.best_allowed_q) / 2; | |
1343 cpi->rc.avg_frame_qindex[1] = (cpi->oxcf.worst_allowed_q + | |
1344 cpi->oxcf.best_allowed_q) / 2; | |
1345 cpi->rc.avg_frame_qindex[2] = (cpi->oxcf.worst_allowed_q + | |
1346 cpi->oxcf.best_allowed_q) / 2; | |
1347 } | |
1348 cpi->rc.last_q[0] = cpi->oxcf.best_allowed_q; | |
1349 cpi->rc.last_q[1] = cpi->oxcf.best_allowed_q; | |
1350 cpi->rc.last_q[2] = cpi->oxcf.best_allowed_q; | |
1351 | |
1352 // Initialise the starting buffer levels | |
1353 cpi->rc.buffer_level = cpi->oxcf.starting_buffer_level; | |
1354 cpi->rc.bits_off_target = cpi->oxcf.starting_buffer_level; | |
1355 | |
1356 cpi->rc.rolling_target_bits = cpi->rc.av_per_frame_bandwidth; | |
1357 cpi->rc.rolling_actual_bits = cpi->rc.av_per_frame_bandwidth; | |
1358 cpi->rc.long_rolling_target_bits = cpi->rc.av_per_frame_bandwidth; | |
1359 cpi->rc.long_rolling_actual_bits = cpi->rc.av_per_frame_bandwidth; | |
1360 | |
1361 cpi->rc.total_actual_bits = 0; | |
1362 cpi->rc.total_target_vs_actual = 0; | |
1363 | 724 |
1364 cpi->static_mb_pct = 0; | 725 cpi->static_mb_pct = 0; |
1365 | 726 |
1366 cpi->lst_fb_idx = 0; | 727 cpi->lst_fb_idx = 0; |
1367 cpi->gld_fb_idx = 1; | 728 cpi->gld_fb_idx = 1; |
1368 cpi->alt_fb_idx = 2; | 729 cpi->alt_fb_idx = 2; |
1369 | 730 |
1370 set_tile_limits(cpi); | 731 set_tile_limits(cpi); |
1371 | 732 |
1372 cpi->fixed_divide[0] = 0; | 733 cpi->fixed_divide[0] = 0; |
1373 for (i = 1; i < 512; i++) | 734 for (i = 1; i < 512; i++) |
1374 cpi->fixed_divide[i] = 0x80000 / i; | 735 cpi->fixed_divide[i] = 0x80000 / i; |
1375 } | 736 } |
1376 | 737 |
1377 void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { | 738 void vp9_change_config(struct VP9_COMP *cpi, const VP9_CONFIG *oxcf) { |
1378 VP9_COMP *cpi = (VP9_COMP *)(ptr); | |
1379 VP9_COMMON *const cm = &cpi->common; | 739 VP9_COMMON *const cm = &cpi->common; |
| 740 RATE_CONTROL *const rc = &cpi->rc; |
1380 | 741 |
1381 if (!cpi || !oxcf) | 742 if (cm->profile != oxcf->profile) |
1382 return; | 743 cm->profile = oxcf->profile; |
| 744 cm->bit_depth = oxcf->bit_depth; |
1383 | 745 |
1384 if (cm->version != oxcf->version) { | 746 if (cm->profile <= PROFILE_1) |
1385 cm->version = oxcf->version; | 747 assert(cm->bit_depth == BITS_8); |
1386 } | 748 else |
| 749 assert(cm->bit_depth > BITS_8); |
1387 | 750 |
1388 cpi->oxcf = *oxcf; | 751 cpi->oxcf = *oxcf; |
1389 | 752 |
1390 if (cpi->oxcf.cpu_used == -6) | 753 if (cpi->oxcf.cpu_used == -6) |
1391 cpi->oxcf.play_alternate = 0; | 754 cpi->oxcf.play_alternate = 0; |
1392 | 755 |
1393 switch (cpi->oxcf.mode) { | 756 switch (cpi->oxcf.mode) { |
1394 // Real time and one pass deprecated in test code base | 757 // Real time and one pass deprecated in test code base |
1395 case MODE_GOODQUALITY: | 758 case MODE_GOODQUALITY: |
1396 cpi->pass = 0; | 759 cpi->pass = 0; |
1397 cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5); | 760 cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5); |
1398 break; | 761 break; |
1399 | 762 |
| 763 case MODE_BESTQUALITY: |
| 764 cpi->pass = 0; |
| 765 break; |
| 766 |
1400 case MODE_FIRSTPASS: | 767 case MODE_FIRSTPASS: |
1401 cpi->pass = 1; | 768 cpi->pass = 1; |
1402 break; | 769 break; |
1403 | 770 |
1404 case MODE_SECONDPASS: | 771 case MODE_SECONDPASS: |
1405 cpi->pass = 2; | 772 cpi->pass = 2; |
1406 cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5); | 773 cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5); |
1407 break; | 774 break; |
1408 | 775 |
1409 case MODE_SECONDPASS_BEST: | 776 case MODE_SECONDPASS_BEST: |
1410 cpi->pass = 2; | 777 cpi->pass = 2; |
1411 break; | 778 break; |
1412 | 779 |
1413 case MODE_REALTIME: | 780 case MODE_REALTIME: |
1414 cpi->pass = 0; | 781 cpi->pass = 0; |
1415 break; | 782 break; |
1416 } | 783 } |
1417 | 784 |
1418 cpi->oxcf.worst_allowed_q = q_trans[oxcf->worst_allowed_q]; | |
1419 cpi->oxcf.best_allowed_q = q_trans[oxcf->best_allowed_q]; | |
1420 cpi->oxcf.cq_level = q_trans[cpi->oxcf.cq_level]; | |
1421 | |
1422 cpi->oxcf.lossless = oxcf->lossless; | 785 cpi->oxcf.lossless = oxcf->lossless; |
1423 cpi->mb.e_mbd.itxm_add = cpi->oxcf.lossless ? vp9_iwht4x4_add | 786 if (cpi->oxcf.lossless) { |
1424 : vp9_idct4x4_add; | 787 // In lossless mode, make sure right quantizer range and correct transform |
1425 cpi->rc.baseline_gf_interval = DEFAULT_GF_INTERVAL; | 788 // is set. |
1426 | 789 cpi->oxcf.worst_allowed_q = 0; |
| 790 cpi->oxcf.best_allowed_q = 0; |
| 791 cpi->mb.e_mbd.itxm_add = vp9_iwht4x4_add; |
| 792 } else { |
| 793 cpi->mb.e_mbd.itxm_add = vp9_idct4x4_add; |
| 794 } |
| 795 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; |
1427 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; | 796 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
1428 | 797 |
1429 cpi->refresh_golden_frame = 0; | 798 cpi->refresh_golden_frame = 0; |
1430 cpi->refresh_last_frame = 1; | 799 cpi->refresh_last_frame = 1; |
1431 cm->refresh_frame_context = 1; | 800 cm->refresh_frame_context = 1; |
1432 cm->reset_frame_context = 0; | 801 cm->reset_frame_context = 0; |
1433 | 802 |
1434 vp9_reset_segment_features(&cm->seg); | 803 vp9_reset_segment_features(&cm->seg); |
1435 set_high_precision_mv(cpi, 0); | 804 set_high_precision_mv(cpi, 0); |
1436 | 805 |
1437 { | 806 { |
1438 int i; | 807 int i; |
1439 | 808 |
1440 for (i = 0; i < MAX_SEGMENTS; i++) | 809 for (i = 0; i < MAX_SEGMENTS; i++) |
1441 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout; | 810 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout; |
1442 } | 811 } |
1443 cpi->encode_breakout = cpi->oxcf.encode_breakout; | 812 cpi->encode_breakout = cpi->oxcf.encode_breakout; |
1444 | 813 |
1445 // local file playback mode == really big buffer | 814 // local file playback mode == really big buffer |
1446 if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK) { | 815 if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK) { |
1447 cpi->oxcf.starting_buffer_level = 60000; | 816 cpi->oxcf.starting_buffer_level = 60000; |
1448 cpi->oxcf.optimal_buffer_level = 60000; | 817 cpi->oxcf.optimal_buffer_level = 60000; |
1449 cpi->oxcf.maximum_buffer_size = 240000; | 818 cpi->oxcf.maximum_buffer_size = 240000; |
1450 } | 819 } |
1451 | 820 |
1452 // Convert target bandwidth from Kbit/s to Bit/s | 821 // Convert target bandwidth from Kbit/s to Bit/s |
1453 cpi->oxcf.target_bandwidth *= 1000; | 822 cpi->oxcf.target_bandwidth *= 1000; |
1454 | 823 |
1455 cpi->oxcf.starting_buffer_level = rescale(cpi->oxcf.starting_buffer_level, | 824 cpi->oxcf.starting_buffer_level = |
1456 cpi->oxcf.target_bandwidth, 1000); | 825 vp9_rescale(cpi->oxcf.starting_buffer_level, |
| 826 cpi->oxcf.target_bandwidth, 1000); |
1457 | 827 |
1458 // Set or reset optimal and maximum buffer levels. | 828 // Set or reset optimal and maximum buffer levels. |
1459 if (cpi->oxcf.optimal_buffer_level == 0) | 829 if (cpi->oxcf.optimal_buffer_level == 0) |
1460 cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; | 830 cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; |
1461 else | 831 else |
1462 cpi->oxcf.optimal_buffer_level = rescale(cpi->oxcf.optimal_buffer_level, | 832 cpi->oxcf.optimal_buffer_level = |
1463 cpi->oxcf.target_bandwidth, 1000); | 833 vp9_rescale(cpi->oxcf.optimal_buffer_level, |
| 834 cpi->oxcf.target_bandwidth, 1000); |
1464 | 835 |
1465 if (cpi->oxcf.maximum_buffer_size == 0) | 836 if (cpi->oxcf.maximum_buffer_size == 0) |
1466 cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; | 837 cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; |
1467 else | 838 else |
1468 cpi->oxcf.maximum_buffer_size = rescale(cpi->oxcf.maximum_buffer_size, | 839 cpi->oxcf.maximum_buffer_size = |
1469 cpi->oxcf.target_bandwidth, 1000); | 840 vp9_rescale(cpi->oxcf.maximum_buffer_size, |
| 841 cpi->oxcf.target_bandwidth, 1000); |
1470 // Under a configuration change, where maximum_buffer_size may change, | 842 // Under a configuration change, where maximum_buffer_size may change, |
1471 // keep buffer level clipped to the maximum allowed buffer size. | 843 // keep buffer level clipped to the maximum allowed buffer size. |
1472 cpi->rc.bits_off_target = MIN(cpi->rc.bits_off_target, | 844 rc->bits_off_target = MIN(rc->bits_off_target, cpi->oxcf.maximum_buffer_size); |
1473 cpi->oxcf.maximum_buffer_size); | 845 rc->buffer_level = MIN(rc->buffer_level, cpi->oxcf.maximum_buffer_size); |
1474 cpi->rc.buffer_level = MIN(cpi->rc.buffer_level, | |
1475 cpi->oxcf.maximum_buffer_size); | |
1476 | 846 |
1477 // Set up frame rate and related parameters rate control values. | 847 // Set up frame rate and related parameters rate control values. |
1478 vp9_new_framerate(cpi, cpi->oxcf.framerate); | 848 vp9_new_framerate(cpi, cpi->oxcf.framerate); |
1479 | 849 |
1480 // Set absolute upper and lower quality limits | 850 // Set absolute upper and lower quality limits |
1481 cpi->rc.worst_quality = cpi->oxcf.worst_allowed_q; | 851 rc->worst_quality = cpi->oxcf.worst_allowed_q; |
1482 cpi->rc.best_quality = cpi->oxcf.best_allowed_q; | 852 rc->best_quality = cpi->oxcf.best_allowed_q; |
1483 | 853 |
1484 // active values should only be modified if out of new range | 854 // active values should only be modified if out of new range |
1485 | 855 |
1486 cpi->cq_target_quality = cpi->oxcf.cq_level; | 856 cpi->cq_target_quality = cpi->oxcf.cq_level; |
1487 | 857 |
1488 cm->interp_filter = DEFAULT_INTERP_FILTER; | 858 cm->interp_filter = DEFAULT_INTERP_FILTER; |
1489 | 859 |
1490 cm->display_width = cpi->oxcf.width; | 860 cm->display_width = cpi->oxcf.width; |
1491 cm->display_height = cpi->oxcf.height; | 861 cm->display_height = cpi->oxcf.height; |
1492 | 862 |
1493 // VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs) | 863 // VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs) |
1494 cpi->oxcf.sharpness = MIN(7, cpi->oxcf.sharpness); | 864 cpi->oxcf.sharpness = MIN(7, cpi->oxcf.sharpness); |
1495 | 865 |
1496 cpi->common.lf.sharpness_level = cpi->oxcf.sharpness; | 866 cpi->common.lf.sharpness_level = cpi->oxcf.sharpness; |
1497 | 867 |
1498 if (cpi->initial_width) { | 868 if (cpi->initial_width) { |
1499 // Increasing the size of the frame beyond the first seen frame, or some | 869 // Increasing the size of the frame beyond the first seen frame, or some |
1500 // otherwise signaled maximum size, is not supported. | 870 // otherwise signaled maximum size, is not supported. |
1501 // TODO(jkoleszar): exit gracefully. | 871 // TODO(jkoleszar): exit gracefully. |
1502 assert(cm->width <= cpi->initial_width); | 872 assert(cm->width <= cpi->initial_width); |
1503 assert(cm->height <= cpi->initial_height); | 873 assert(cm->height <= cpi->initial_height); |
1504 } | 874 } |
1505 update_frame_size(cpi); | 875 update_frame_size(cpi); |
1506 | 876 |
1507 if (cpi->svc.number_temporal_layers > 1 && | 877 if ((cpi->svc.number_temporal_layers > 1 && |
1508 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { | 878 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) || |
1509 update_layer_context_change_config(cpi, (int)cpi->oxcf.target_bandwidth); | 879 (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { |
| 880 vp9_update_layer_context_change_config(cpi, |
| 881 (int)cpi->oxcf.target_bandwidth); |
1510 } | 882 } |
1511 | 883 |
1512 cpi->speed = abs(cpi->oxcf.cpu_used); | 884 cpi->speed = abs(cpi->oxcf.cpu_used); |
1513 | 885 |
1514 // Limit on lag buffers as these are not currently dynamically allocated. | 886 // Limit on lag buffers as these are not currently dynamically allocated. |
1515 if (cpi->oxcf.lag_in_frames > MAX_LAG_BUFFERS) | 887 if (cpi->oxcf.lag_in_frames > MAX_LAG_BUFFERS) |
1516 cpi->oxcf.lag_in_frames = MAX_LAG_BUFFERS; | 888 cpi->oxcf.lag_in_frames = MAX_LAG_BUFFERS; |
1517 | 889 |
1518 #if CONFIG_MULTIPLE_ARF | 890 #if CONFIG_MULTIPLE_ARF |
1519 vp9_zero(cpi->alt_ref_source); | 891 vp9_zero(cpi->alt_ref_source); |
1520 #else | 892 #else |
1521 cpi->alt_ref_source = NULL; | 893 cpi->alt_ref_source = NULL; |
1522 #endif | 894 #endif |
1523 cpi->rc.is_src_frame_alt_ref = 0; | 895 rc->is_src_frame_alt_ref = 0; |
1524 | 896 |
1525 #if 0 | 897 #if 0 |
1526 // Experimental RD Code | 898 // Experimental RD Code |
1527 cpi->frame_distortion = 0; | 899 cpi->frame_distortion = 0; |
1528 cpi->last_frame_distortion = 0; | 900 cpi->last_frame_distortion = 0; |
1529 #endif | 901 #endif |
1530 | 902 |
1531 set_tile_limits(cpi); | 903 set_tile_limits(cpi); |
1532 | 904 |
1533 cpi->ext_refresh_frame_flags_pending = 0; | 905 cpi->ext_refresh_frame_flags_pending = 0; |
1534 cpi->ext_refresh_frame_context_pending = 0; | 906 cpi->ext_refresh_frame_context_pending = 0; |
1535 } | 907 } |
1536 | 908 |
1537 #define M_LOG2_E 0.693147180559945309417 | 909 #define M_LOG2_E 0.693147180559945309417 |
1538 #define log2f(x) (log (x) / (float) M_LOG2_E) | 910 #define log2f(x) (log (x) / (float) M_LOG2_E) |
1539 | 911 |
1540 static void cal_nmvjointsadcost(int *mvjointsadcost) { | 912 static void cal_nmvjointsadcost(int *mvjointsadcost) { |
1541 mvjointsadcost[0] = 600; | 913 mvjointsadcost[0] = 600; |
1542 mvjointsadcost[1] = 300; | 914 mvjointsadcost[1] = 300; |
1543 mvjointsadcost[2] = 300; | 915 mvjointsadcost[2] = 300; |
1544 mvjointsadcost[0] = 300; | 916 mvjointsadcost[3] = 300; |
1545 } | 917 } |
1546 | 918 |
1547 static void cal_nmvsadcosts(int *mvsadcost[2]) { | 919 static void cal_nmvsadcosts(int *mvsadcost[2]) { |
1548 int i = 1; | 920 int i = 1; |
1549 | 921 |
1550 mvsadcost[0][0] = 0; | 922 mvsadcost[0][0] = 0; |
1551 mvsadcost[1][0] = 0; | 923 mvsadcost[1][0] = 0; |
1552 | 924 |
1553 do { | 925 do { |
1554 double z = 256 * (2 * (log2f(8 * i) + .6)); | 926 double z = 256 * (2 * (log2f(8 * i) + .6)); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1686 PICK_MODE_CONTEXT *ctx = get_block_context(x, i); | 1058 PICK_MODE_CONTEXT *ctx = get_block_context(x, i); |
1687 free_mode_context(ctx); | 1059 free_mode_context(ctx); |
1688 } | 1060 } |
1689 } else { | 1061 } else { |
1690 PICK_MODE_CONTEXT *ctx = get_block_context(x, i); | 1062 PICK_MODE_CONTEXT *ctx = get_block_context(x, i); |
1691 free_mode_context(ctx); | 1063 free_mode_context(ctx); |
1692 } | 1064 } |
1693 } | 1065 } |
1694 } | 1066 } |
1695 | 1067 |
1696 VP9_PTR vp9_create_compressor(VP9_CONFIG *oxcf) { | 1068 VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) { |
1697 int i, j; | 1069 int i, j; |
1698 volatile union { | 1070 VP9_COMP *const cpi = vpx_memalign(32, sizeof(VP9_COMP)); |
1699 VP9_COMP *cpi; | 1071 VP9_COMMON *const cm = cpi != NULL ? &cpi->common : NULL; |
1700 VP9_PTR ptr; | |
1701 } ctx; | |
1702 | 1072 |
1703 VP9_COMP *cpi; | 1073 if (!cm) |
1704 VP9_COMMON *cm; | 1074 return NULL; |
1705 | |
1706 cpi = ctx.cpi = vpx_memalign(32, sizeof(VP9_COMP)); | |
1707 // Check that the CPI instance is valid | |
1708 if (!cpi) | |
1709 return 0; | |
1710 | |
1711 cm = &cpi->common; | |
1712 | 1075 |
1713 vp9_zero(*cpi); | 1076 vp9_zero(*cpi); |
1714 | 1077 |
1715 if (setjmp(cm->error.jmp)) { | 1078 if (setjmp(cm->error.jmp)) { |
1716 VP9_PTR ptr = ctx.ptr; | 1079 cm->error.setjmp = 0; |
1717 | 1080 vp9_remove_compressor(cpi); |
1718 ctx.cpi->common.error.setjmp = 0; | |
1719 vp9_remove_compressor(&ptr); | |
1720 return 0; | 1081 return 0; |
1721 } | 1082 } |
1722 | 1083 |
1723 cm->error.setjmp = 1; | 1084 cm->error.setjmp = 1; |
1724 | 1085 |
1725 CHECK_MEM_ERROR(cm, cpi->mb.ss, vpx_calloc(sizeof(search_site), | 1086 CHECK_MEM_ERROR(cm, cpi->mb.ss, vpx_calloc(sizeof(search_site), |
1726 (MAX_MVSEARCH_STEPS * 8) + 1)); | 1087 (MAX_MVSEARCH_STEPS * 8) + 1)); |
1727 | 1088 |
1728 vp9_rtcd(); | 1089 vp9_rtcd(); |
1729 | 1090 |
1730 cpi->use_svc = 0; | 1091 cpi->use_svc = 0; |
1731 | 1092 |
1732 init_config((VP9_PTR)cpi, oxcf); | 1093 init_config(cpi, oxcf); |
1733 | 1094 vp9_rc_init(&cpi->oxcf, cpi->pass, &cpi->rc); |
1734 init_pick_mode_context(cpi); | 1095 init_pick_mode_context(cpi); |
1735 | 1096 |
1736 cm->current_video_frame = 0; | 1097 cm->current_video_frame = 0; |
1737 | 1098 |
1738 // Set reference frame sign bias for ALTREF frame to 1 (for now) | 1099 // Set reference frame sign bias for ALTREF frame to 1 (for now) |
1739 cm->ref_frame_sign_bias[ALTREF_FRAME] = 1; | 1100 cm->ref_frame_sign_bias[ALTREF_FRAME] = 1; |
1740 | 1101 |
1741 cpi->rc.baseline_gf_interval = DEFAULT_GF_INTERVAL; | |
1742 | |
1743 cpi->gold_is_last = 0; | 1102 cpi->gold_is_last = 0; |
1744 cpi->alt_is_last = 0; | 1103 cpi->alt_is_last = 0; |
1745 cpi->gold_is_alt = 0; | 1104 cpi->gold_is_alt = 0; |
1746 | 1105 |
1747 // Create the encoder segmentation map and set all entries to 0 | 1106 // Create the encoder segmentation map and set all entries to 0 |
1748 CHECK_MEM_ERROR(cm, cpi->segmentation_map, | 1107 CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
1749 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1108 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
1750 | 1109 |
1751 // Create a complexity map used for rd adjustment | 1110 // Create a complexity map used for rd adjustment |
1752 CHECK_MEM_ERROR(cm, cpi->complexity_map, | 1111 CHECK_MEM_ERROR(cm, cpi->complexity_map, |
1753 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1112 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
1754 | 1113 |
| 1114 // Create a map used for cyclic background refresh. |
| 1115 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, |
| 1116 vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); |
1755 | 1117 |
1756 // And a place holder structure is the coding context | 1118 // And a place holder structure is the coding context |
1757 // for use if we want to save and restore it | 1119 // for use if we want to save and restore it |
1758 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, | 1120 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, |
1759 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1121 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
1760 | 1122 |
1761 CHECK_MEM_ERROR(cm, cpi->active_map, vpx_calloc(cm->MBs, 1)); | 1123 CHECK_MEM_ERROR(cm, cpi->active_map, vpx_calloc(cm->MBs, 1)); |
1762 vpx_memset(cpi->active_map, 1, cm->MBs); | 1124 vpx_memset(cpi->active_map, 1, cm->MBs); |
1763 cpi->active_map_enabled = 0; | 1125 cpi->active_map_enabled = 0; |
1764 | 1126 |
1765 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / | 1127 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / |
1766 sizeof(cpi->mbgraph_stats[0])); i++) { | 1128 sizeof(cpi->mbgraph_stats[0])); i++) { |
1767 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats, | 1129 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats, |
1768 vpx_calloc(cm->MBs * | 1130 vpx_calloc(cm->MBs * |
1769 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); | 1131 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
1770 } | 1132 } |
1771 | 1133 |
1772 /*Initialize the feed-forward activity masking.*/ | 1134 /*Initialize the feed-forward activity masking.*/ |
1773 cpi->activity_avg = 90 << 12; | 1135 cpi->activity_avg = 90 << 12; |
1774 cpi->key_frame_frequency = cpi->oxcf.key_freq; | 1136 cpi->key_frame_frequency = cpi->oxcf.key_freq; |
1775 | |
1776 cpi->rc.frames_since_key = 8; // Sensible default for first frame. | |
1777 cpi->rc.this_key_frame_forced = 0; | |
1778 cpi->rc.next_key_frame_forced = 0; | |
1779 | |
1780 cpi->rc.source_alt_ref_pending = 0; | |
1781 cpi->rc.source_alt_ref_active = 0; | |
1782 cpi->refresh_alt_ref_frame = 0; | 1137 cpi->refresh_alt_ref_frame = 0; |
1783 | 1138 |
1784 #if CONFIG_MULTIPLE_ARF | 1139 #if CONFIG_MULTIPLE_ARF |
1785 // Turn multiple ARF usage on/off. This is a quick hack for the initial test | 1140 // Turn multiple ARF usage on/off. This is a quick hack for the initial test |
1786 // version. It should eventually be set via the codec API. | 1141 // version. It should eventually be set via the codec API. |
1787 cpi->multi_arf_enabled = 1; | 1142 cpi->multi_arf_enabled = 1; |
1788 | 1143 |
1789 if (cpi->multi_arf_enabled) { | 1144 if (cpi->multi_arf_enabled) { |
1790 cpi->sequence_number = 0; | 1145 cpi->sequence_number = 0; |
1791 cpi->frame_coding_order_period = 0; | 1146 cpi->frame_coding_order_period = 0; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1827 cpi->total_ssimg_y = 0; | 1182 cpi->total_ssimg_y = 0; |
1828 cpi->total_ssimg_u = 0; | 1183 cpi->total_ssimg_u = 0; |
1829 cpi->total_ssimg_v = 0; | 1184 cpi->total_ssimg_v = 0; |
1830 cpi->total_ssimg_all = 0; | 1185 cpi->total_ssimg_all = 0; |
1831 } | 1186 } |
1832 | 1187 |
1833 #endif | 1188 #endif |
1834 | 1189 |
1835 cpi->first_time_stamp_ever = INT64_MAX; | 1190 cpi->first_time_stamp_ever = INT64_MAX; |
1836 | 1191 |
1837 cpi->rc.frames_till_gf_update_due = 0; | |
1838 | |
1839 cpi->rc.ni_av_qi = cpi->oxcf.worst_allowed_q; | |
1840 cpi->rc.ni_tot_qi = 0; | |
1841 cpi->rc.ni_frames = 0; | |
1842 cpi->rc.tot_q = 0.0; | |
1843 cpi->rc.avg_q = vp9_convert_qindex_to_q(cpi->oxcf.worst_allowed_q); | |
1844 | |
1845 cpi->rc.rate_correction_factor = 1.0; | |
1846 cpi->rc.key_frame_rate_correction_factor = 1.0; | |
1847 cpi->rc.gf_rate_correction_factor = 1.0; | |
1848 | |
1849 cal_nmvjointsadcost(cpi->mb.nmvjointsadcost); | 1192 cal_nmvjointsadcost(cpi->mb.nmvjointsadcost); |
1850 cpi->mb.nmvcost[0] = &cpi->mb.nmvcosts[0][MV_MAX]; | 1193 cpi->mb.nmvcost[0] = &cpi->mb.nmvcosts[0][MV_MAX]; |
1851 cpi->mb.nmvcost[1] = &cpi->mb.nmvcosts[1][MV_MAX]; | 1194 cpi->mb.nmvcost[1] = &cpi->mb.nmvcosts[1][MV_MAX]; |
1852 cpi->mb.nmvsadcost[0] = &cpi->mb.nmvsadcosts[0][MV_MAX]; | 1195 cpi->mb.nmvsadcost[0] = &cpi->mb.nmvsadcosts[0][MV_MAX]; |
1853 cpi->mb.nmvsadcost[1] = &cpi->mb.nmvsadcosts[1][MV_MAX]; | 1196 cpi->mb.nmvsadcost[1] = &cpi->mb.nmvsadcosts[1][MV_MAX]; |
1854 cal_nmvsadcosts(cpi->mb.nmvsadcost); | 1197 cal_nmvsadcosts(cpi->mb.nmvsadcost); |
1855 | 1198 |
1856 cpi->mb.nmvcost_hp[0] = &cpi->mb.nmvcosts_hp[0][MV_MAX]; | 1199 cpi->mb.nmvcost_hp[0] = &cpi->mb.nmvcosts_hp[0][MV_MAX]; |
1857 cpi->mb.nmvcost_hp[1] = &cpi->mb.nmvcosts_hp[1][MV_MAX]; | 1200 cpi->mb.nmvcost_hp[1] = &cpi->mb.nmvcosts_hp[1][MV_MAX]; |
1858 cpi->mb.nmvsadcost_hp[0] = &cpi->mb.nmvsadcosts_hp[0][MV_MAX]; | 1201 cpi->mb.nmvsadcost_hp[0] = &cpi->mb.nmvsadcosts_hp[0][MV_MAX]; |
(...skipping 12 matching lines...) Expand all Loading... |
1871 kf_list = fopen("kf_list.stt", "w"); | 1214 kf_list = fopen("kf_list.stt", "w"); |
1872 #endif | 1215 #endif |
1873 | 1216 |
1874 cpi->output_pkt_list = oxcf->output_pkt_list; | 1217 cpi->output_pkt_list = oxcf->output_pkt_list; |
1875 | 1218 |
1876 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; | 1219 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; |
1877 | 1220 |
1878 if (cpi->pass == 1) { | 1221 if (cpi->pass == 1) { |
1879 vp9_init_first_pass(cpi); | 1222 vp9_init_first_pass(cpi); |
1880 } else if (cpi->pass == 2) { | 1223 } else if (cpi->pass == 2) { |
1881 size_t packet_sz = sizeof(FIRSTPASS_STATS); | 1224 const size_t packet_sz = sizeof(FIRSTPASS_STATS); |
1882 int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); | 1225 const int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
1883 | 1226 |
1884 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; | 1227 if (cpi->svc.number_spatial_layers > 1 |
1885 cpi->twopass.stats_in = cpi->twopass.stats_in_start; | 1228 && cpi->svc.number_temporal_layers == 1) { |
1886 cpi->twopass.stats_in_end = (void *)((char *)cpi->twopass.stats_in | 1229 FIRSTPASS_STATS *const stats = oxcf->two_pass_stats_in.buf; |
1887 + (packets - 1) * packet_sz); | 1230 FIRSTPASS_STATS *stats_copy[VPX_SS_MAX_LAYERS] = {0}; |
1888 vp9_init_second_pass(cpi); | 1231 int i; |
| 1232 |
| 1233 for (i = 0; i < oxcf->ss_number_layers; ++i) { |
| 1234 FIRSTPASS_STATS *const last_packet_for_layer = |
| 1235 &stats[packets - oxcf->ss_number_layers + i]; |
| 1236 const int layer_id = (int)last_packet_for_layer->spatial_layer_id; |
| 1237 const int packets_in_layer = (int)last_packet_for_layer->count + 1; |
| 1238 if (layer_id >= 0 && layer_id < oxcf->ss_number_layers) { |
| 1239 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[layer_id]; |
| 1240 |
| 1241 vpx_free(lc->rc_twopass_stats_in.buf); |
| 1242 |
| 1243 lc->rc_twopass_stats_in.sz = packets_in_layer * packet_sz; |
| 1244 CHECK_MEM_ERROR(cm, lc->rc_twopass_stats_in.buf, |
| 1245 vpx_malloc(lc->rc_twopass_stats_in.sz)); |
| 1246 lc->twopass.stats_in_start = lc->rc_twopass_stats_in.buf; |
| 1247 lc->twopass.stats_in = lc->twopass.stats_in_start; |
| 1248 lc->twopass.stats_in_end = lc->twopass.stats_in_start |
| 1249 + packets_in_layer - 1; |
| 1250 stats_copy[layer_id] = lc->rc_twopass_stats_in.buf; |
| 1251 } |
| 1252 } |
| 1253 |
| 1254 for (i = 0; i < packets; ++i) { |
| 1255 const int layer_id = (int)stats[i].spatial_layer_id; |
| 1256 if (layer_id >= 0 && layer_id < oxcf->ss_number_layers |
| 1257 && stats_copy[layer_id] != NULL) { |
| 1258 *stats_copy[layer_id] = stats[i]; |
| 1259 ++stats_copy[layer_id]; |
| 1260 } |
| 1261 } |
| 1262 |
| 1263 vp9_init_second_pass_spatial_svc(cpi); |
| 1264 } else { |
| 1265 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 1266 cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 1267 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 1268 |
| 1269 vp9_init_second_pass(cpi); |
| 1270 } |
1889 } | 1271 } |
1890 | 1272 |
1891 vp9_set_speed_features(cpi); | 1273 set_speed_features(cpi); |
1892 | 1274 |
1893 // Default rd threshold factors for mode selection | 1275 // Default rd threshold factors for mode selection |
1894 for (i = 0; i < BLOCK_SIZES; ++i) { | 1276 for (i = 0; i < BLOCK_SIZES; ++i) { |
1895 for (j = 0; j < MAX_MODES; ++j) | 1277 for (j = 0; j < MAX_MODES; ++j) |
1896 cpi->rd_thresh_freq_fact[i][j] = 32; | 1278 cpi->rd_thresh_freq_fact[i][j] = 32; |
1897 for (j = 0; j < MAX_REFS; ++j) | 1279 for (j = 0; j < MAX_REFS; ++j) |
1898 cpi->rd_thresh_freq_sub8x8[i][j] = 32; | 1280 cpi->rd_thresh_freq_sub8x8[i][j] = 32; |
1899 } | 1281 } |
1900 | 1282 |
1901 #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SVFHH, SVFHV, SVFHHV, \ | 1283 #define BFP(BT, SDF, SDAF, VF, SVF, SVAF, SVFHH, SVFHV, SVFHHV, \ |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2003 vp9_loop_filter_init(cm); | 1385 vp9_loop_filter_init(cm); |
2004 | 1386 |
2005 cm->error.setjmp = 0; | 1387 cm->error.setjmp = 0; |
2006 | 1388 |
2007 vp9_zero(cpi->common.counts.uv_mode); | 1389 vp9_zero(cpi->common.counts.uv_mode); |
2008 | 1390 |
2009 #ifdef MODE_TEST_HIT_STATS | 1391 #ifdef MODE_TEST_HIT_STATS |
2010 vp9_zero(cpi->mode_test_hits); | 1392 vp9_zero(cpi->mode_test_hits); |
2011 #endif | 1393 #endif |
2012 | 1394 |
2013 return (VP9_PTR) cpi; | 1395 return cpi; |
2014 } | 1396 } |
2015 | 1397 |
2016 void vp9_remove_compressor(VP9_PTR *ptr) { | 1398 void vp9_remove_compressor(VP9_COMP *cpi) { |
2017 VP9_COMP *cpi = (VP9_COMP *)(*ptr); | |
2018 int i; | 1399 int i; |
2019 | 1400 |
2020 if (!cpi) | 1401 if (!cpi) |
2021 return; | 1402 return; |
2022 | 1403 |
2023 if (cpi && (cpi->common.current_video_frame > 0)) { | 1404 if (cpi && (cpi->common.current_video_frame > 0)) { |
2024 #if CONFIG_INTERNAL_STATS | 1405 #if CONFIG_INTERNAL_STATS |
2025 | 1406 |
2026 vp9_clear_system_state(); | 1407 vp9_clear_system_state(); |
2027 | 1408 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2114 vpx_free(cpi->mb.ss); | 1495 vpx_free(cpi->mb.ss); |
2115 vpx_free(cpi->tok); | 1496 vpx_free(cpi->tok); |
2116 | 1497 |
2117 for (i = 0; i < sizeof(cpi->mbgraph_stats) / | 1498 for (i = 0; i < sizeof(cpi->mbgraph_stats) / |
2118 sizeof(cpi->mbgraph_stats[0]); ++i) { | 1499 sizeof(cpi->mbgraph_stats[0]); ++i) { |
2119 vpx_free(cpi->mbgraph_stats[i].mb_stats); | 1500 vpx_free(cpi->mbgraph_stats[i].mb_stats); |
2120 } | 1501 } |
2121 | 1502 |
2122 vp9_remove_common(&cpi->common); | 1503 vp9_remove_common(&cpi->common); |
2123 vpx_free(cpi); | 1504 vpx_free(cpi); |
2124 *ptr = 0; | |
2125 | 1505 |
2126 #ifdef OUTPUT_YUV_SRC | 1506 #ifdef OUTPUT_YUV_SRC |
2127 fclose(yuv_file); | 1507 fclose(yuv_file); |
2128 #endif | 1508 #endif |
2129 #ifdef OUTPUT_YUV_REC | 1509 #ifdef OUTPUT_YUV_REC |
2130 fclose(yuv_rec_file); | 1510 fclose(yuv_rec_file); |
2131 #endif | 1511 #endif |
2132 | 1512 |
2133 #if 0 | 1513 #if 0 |
2134 | 1514 |
2135 if (keyfile) | 1515 if (keyfile) |
2136 fclose(keyfile); | 1516 fclose(keyfile); |
2137 | 1517 |
2138 if (framepsnr) | 1518 if (framepsnr) |
2139 fclose(framepsnr); | 1519 fclose(framepsnr); |
2140 | 1520 |
2141 if (kf_list) | 1521 if (kf_list) |
2142 fclose(kf_list); | 1522 fclose(kf_list); |
2143 | 1523 |
2144 #endif | 1524 #endif |
2145 } | 1525 } |
| 1526 static int64_t get_sse(const uint8_t *a, int a_stride, |
| 1527 const uint8_t *b, int b_stride, |
| 1528 int width, int height) { |
| 1529 const int dw = width % 16; |
| 1530 const int dh = height % 16; |
| 1531 int64_t total_sse = 0; |
| 1532 unsigned int sse = 0; |
| 1533 int sum = 0; |
| 1534 int x, y; |
2146 | 1535 |
| 1536 if (dw > 0) { |
| 1537 variance(&a[width - dw], a_stride, &b[width - dw], b_stride, |
| 1538 dw, height, &sse, &sum); |
| 1539 total_sse += sse; |
| 1540 } |
2147 | 1541 |
2148 static uint64_t calc_plane_error(const uint8_t *orig, int orig_stride, | 1542 if (dh > 0) { |
2149 const uint8_t *recon, int recon_stride, | 1543 variance(&a[(height - dh) * a_stride], a_stride, |
2150 unsigned int cols, unsigned int rows) { | 1544 &b[(height - dh) * b_stride], b_stride, |
2151 unsigned int row, col; | 1545 width - dw, dh, &sse, &sum); |
2152 uint64_t total_sse = 0; | 1546 total_sse += sse; |
2153 int diff; | 1547 } |
2154 | 1548 |
2155 for (row = 0; row + 16 <= rows; row += 16) { | 1549 for (y = 0; y < height / 16; ++y) { |
2156 for (col = 0; col + 16 <= cols; col += 16) { | 1550 const uint8_t *pa = a; |
2157 unsigned int sse; | 1551 const uint8_t *pb = b; |
| 1552 for (x = 0; x < width / 16; ++x) { |
| 1553 vp9_mse16x16(pa, a_stride, pb, b_stride, &sse); |
| 1554 total_sse += sse; |
2158 | 1555 |
2159 vp9_mse16x16(orig + col, orig_stride, recon + col, recon_stride, &sse); | 1556 pa += 16; |
2160 total_sse += sse; | 1557 pb += 16; |
2161 } | 1558 } |
2162 | 1559 |
2163 /* Handle odd-sized width */ | 1560 a += 16 * a_stride; |
2164 if (col < cols) { | 1561 b += 16 * b_stride; |
2165 unsigned int border_row, border_col; | |
2166 const uint8_t *border_orig = orig; | |
2167 const uint8_t *border_recon = recon; | |
2168 | |
2169 for (border_row = 0; border_row < 16; border_row++) { | |
2170 for (border_col = col; border_col < cols; border_col++) { | |
2171 diff = border_orig[border_col] - border_recon[border_col]; | |
2172 total_sse += diff * diff; | |
2173 } | |
2174 | |
2175 border_orig += orig_stride; | |
2176 border_recon += recon_stride; | |
2177 } | |
2178 } | |
2179 | |
2180 orig += orig_stride * 16; | |
2181 recon += recon_stride * 16; | |
2182 } | |
2183 | |
2184 /* Handle odd-sized height */ | |
2185 for (; row < rows; row++) { | |
2186 for (col = 0; col < cols; col++) { | |
2187 diff = orig[col] - recon[col]; | |
2188 total_sse += diff * diff; | |
2189 } | |
2190 | |
2191 orig += orig_stride; | |
2192 recon += recon_stride; | |
2193 } | 1562 } |
2194 | 1563 |
2195 return total_sse; | 1564 return total_sse; |
2196 } | 1565 } |
2197 | 1566 |
2198 typedef struct { | 1567 typedef struct { |
2199 double psnr[4]; // total/y/u/v | 1568 double psnr[4]; // total/y/u/v |
2200 uint64_t sse[4]; // total/y/u/v | 1569 uint64_t sse[4]; // total/y/u/v |
2201 uint32_t samples[4]; // total/y/u/v | 1570 uint32_t samples[4]; // total/y/u/v |
2202 } PSNR_STATS; | 1571 } PSNR_STATS; |
2203 | 1572 |
2204 static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, | 1573 static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, |
2205 PSNR_STATS *psnr) { | 1574 PSNR_STATS *psnr) { |
2206 const int widths[3] = {a->y_width, a->uv_width, a->uv_width }; | 1575 const int widths[3] = {a->y_width, a->uv_width, a->uv_width }; |
2207 const int heights[3] = {a->y_height, a->uv_height, a->uv_height}; | 1576 const int heights[3] = {a->y_height, a->uv_height, a->uv_height}; |
2208 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer }; | 1577 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer }; |
2209 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride}; | 1578 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride}; |
2210 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer }; | 1579 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer }; |
2211 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride}; | 1580 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride}; |
2212 int i; | 1581 int i; |
2213 uint64_t total_sse = 0; | 1582 uint64_t total_sse = 0; |
2214 uint32_t total_samples = 0; | 1583 uint32_t total_samples = 0; |
2215 | 1584 |
2216 for (i = 0; i < 3; ++i) { | 1585 for (i = 0; i < 3; ++i) { |
2217 const int w = widths[i]; | 1586 const int w = widths[i]; |
2218 const int h = heights[i]; | 1587 const int h = heights[i]; |
2219 const uint32_t samples = w * h; | 1588 const uint32_t samples = w * h; |
2220 const uint64_t sse = calc_plane_error(a_planes[i], a_strides[i], | 1589 const uint64_t sse = get_sse(a_planes[i], a_strides[i], |
2221 b_planes[i], b_strides[i], | 1590 b_planes[i], b_strides[i], |
2222 w, h); | 1591 w, h); |
2223 psnr->sse[1 + i] = sse; | 1592 psnr->sse[1 + i] = sse; |
2224 psnr->samples[1 + i] = samples; | 1593 psnr->samples[1 + i] = samples; |
2225 psnr->psnr[1 + i] = vpx_sse_to_psnr(samples, 255.0, (double)sse); | 1594 psnr->psnr[1 + i] = vpx_sse_to_psnr(samples, 255.0, (double)sse); |
2226 | 1595 |
2227 total_sse += sse; | 1596 total_sse += sse; |
2228 total_samples += samples; | 1597 total_samples += samples; |
2229 } | 1598 } |
2230 | 1599 |
2231 psnr->sse[0] = total_sse; | 1600 psnr->sse[0] = total_sse; |
2232 psnr->samples[0] = total_samples; | 1601 psnr->samples[0] = total_samples; |
2233 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, 255.0, | 1602 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, 255.0, |
2234 (double)total_sse); | 1603 (double)total_sse); |
2235 } | 1604 } |
2236 | 1605 |
2237 static void generate_psnr_packet(VP9_COMP *cpi) { | 1606 static void generate_psnr_packet(VP9_COMP *cpi) { |
2238 struct vpx_codec_cx_pkt pkt; | 1607 struct vpx_codec_cx_pkt pkt; |
2239 int i; | 1608 int i; |
2240 PSNR_STATS psnr; | 1609 PSNR_STATS psnr; |
2241 calc_psnr(cpi->Source, cpi->common.frame_to_show, &psnr); | 1610 calc_psnr(cpi->Source, cpi->common.frame_to_show, &psnr); |
2242 for (i = 0; i < 4; ++i) { | 1611 for (i = 0; i < 4; ++i) { |
2243 pkt.data.psnr.samples[i] = psnr.samples[i]; | 1612 pkt.data.psnr.samples[i] = psnr.samples[i]; |
2244 pkt.data.psnr.sse[i] = psnr.sse[i]; | 1613 pkt.data.psnr.sse[i] = psnr.sse[i]; |
2245 pkt.data.psnr.psnr[i] = psnr.psnr[i]; | 1614 pkt.data.psnr.psnr[i] = psnr.psnr[i]; |
2246 } | 1615 } |
2247 pkt.kind = VPX_CODEC_PSNR_PKT; | 1616 pkt.kind = VPX_CODEC_PSNR_PKT; |
2248 vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt); | 1617 vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt); |
2249 } | 1618 } |
2250 | 1619 |
2251 int vp9_use_as_reference(VP9_PTR ptr, int ref_frame_flags) { | 1620 int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags) { |
2252 VP9_COMP *cpi = (VP9_COMP *)(ptr); | |
2253 | |
2254 if (ref_frame_flags > 7) | 1621 if (ref_frame_flags > 7) |
2255 return -1; | 1622 return -1; |
2256 | 1623 |
2257 cpi->ref_frame_flags = ref_frame_flags; | 1624 cpi->ref_frame_flags = ref_frame_flags; |
2258 return 0; | 1625 return 0; |
2259 } | 1626 } |
2260 | 1627 |
2261 int vp9_update_reference(VP9_PTR ptr, int ref_frame_flags) { | 1628 void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags) { |
2262 VP9_COMP *cpi = (VP9_COMP *)(ptr); | 1629 cpi->ext_refresh_golden_frame = (ref_frame_flags & VP9_GOLD_FLAG) != 0; |
2263 | 1630 cpi->ext_refresh_alt_ref_frame = (ref_frame_flags & VP9_ALT_FLAG) != 0; |
2264 if (ref_frame_flags > 7) | 1631 cpi->ext_refresh_last_frame = (ref_frame_flags & VP9_LAST_FLAG) != 0; |
2265 return -1; | |
2266 | |
2267 cpi->ext_refresh_golden_frame = 0; | |
2268 cpi->ext_refresh_alt_ref_frame = 0; | |
2269 cpi->ext_refresh_last_frame = 0; | |
2270 | |
2271 if (ref_frame_flags & VP9_LAST_FLAG) | |
2272 cpi->ext_refresh_last_frame = 1; | |
2273 | |
2274 if (ref_frame_flags & VP9_GOLD_FLAG) | |
2275 cpi->ext_refresh_golden_frame = 1; | |
2276 | |
2277 if (ref_frame_flags & VP9_ALT_FLAG) | |
2278 cpi->ext_refresh_alt_ref_frame = 1; | |
2279 | |
2280 cpi->ext_refresh_frame_flags_pending = 1; | 1632 cpi->ext_refresh_frame_flags_pending = 1; |
2281 return 0; | |
2282 } | 1633 } |
2283 | 1634 |
2284 static YV12_BUFFER_CONFIG *get_vp9_ref_frame_buffer(VP9_COMP *cpi, | 1635 static YV12_BUFFER_CONFIG *get_vp9_ref_frame_buffer(VP9_COMP *cpi, |
2285 VP9_REFFRAME ref_frame_flag) { | 1636 VP9_REFFRAME ref_frame_flag) { |
2286 MV_REFERENCE_FRAME ref_frame = NONE; | 1637 MV_REFERENCE_FRAME ref_frame = NONE; |
2287 if (ref_frame_flag == VP9_LAST_FLAG) | 1638 if (ref_frame_flag == VP9_LAST_FLAG) |
2288 ref_frame = LAST_FRAME; | 1639 ref_frame = LAST_FRAME; |
2289 else if (ref_frame_flag == VP9_GOLD_FLAG) | 1640 else if (ref_frame_flag == VP9_GOLD_FLAG) |
2290 ref_frame = GOLDEN_FRAME; | 1641 ref_frame = GOLDEN_FRAME; |
2291 else if (ref_frame_flag == VP9_ALT_FLAG) | 1642 else if (ref_frame_flag == VP9_ALT_FLAG) |
2292 ref_frame = ALTREF_FRAME; | 1643 ref_frame = ALTREF_FRAME; |
2293 | 1644 |
2294 return ref_frame == NONE ? NULL : get_ref_frame_buffer(cpi, ref_frame); | 1645 return ref_frame == NONE ? NULL : get_ref_frame_buffer(cpi, ref_frame); |
2295 } | 1646 } |
2296 | 1647 |
2297 int vp9_copy_reference_enc(VP9_PTR ptr, VP9_REFFRAME ref_frame_flag, | 1648 int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag, |
2298 YV12_BUFFER_CONFIG *sd) { | 1649 YV12_BUFFER_CONFIG *sd) { |
2299 VP9_COMP *const cpi = (VP9_COMP *)ptr; | |
2300 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); | 1650 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); |
2301 if (cfg) { | 1651 if (cfg) { |
2302 vp8_yv12_copy_frame(cfg, sd); | 1652 vp8_yv12_copy_frame(cfg, sd); |
2303 return 0; | 1653 return 0; |
2304 } else { | 1654 } else { |
2305 return -1; | 1655 return -1; |
2306 } | 1656 } |
2307 } | 1657 } |
2308 | 1658 |
2309 int vp9_get_reference_enc(VP9_PTR ptr, int index, YV12_BUFFER_CONFIG **fb) { | 1659 int vp9_get_reference_enc(VP9_COMP *cpi, int index, YV12_BUFFER_CONFIG **fb) { |
2310 VP9_COMP *cpi = (VP9_COMP *)ptr; | |
2311 VP9_COMMON *cm = &cpi->common; | 1660 VP9_COMMON *cm = &cpi->common; |
2312 | 1661 |
2313 if (index < 0 || index >= REF_FRAMES) | 1662 if (index < 0 || index >= REF_FRAMES) |
2314 return -1; | 1663 return -1; |
2315 | 1664 |
2316 *fb = &cm->frame_bufs[cm->ref_frame_map[index]].buf; | 1665 *fb = &cm->frame_bufs[cm->ref_frame_map[index]].buf; |
2317 return 0; | 1666 return 0; |
2318 } | 1667 } |
2319 | 1668 |
2320 int vp9_set_reference_enc(VP9_PTR ptr, VP9_REFFRAME ref_frame_flag, | 1669 int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag, |
2321 YV12_BUFFER_CONFIG *sd) { | 1670 YV12_BUFFER_CONFIG *sd) { |
2322 VP9_COMP *cpi = (VP9_COMP *)ptr; | |
2323 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); | 1671 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); |
2324 if (cfg) { | 1672 if (cfg) { |
2325 vp8_yv12_copy_frame(sd, cfg); | 1673 vp8_yv12_copy_frame(sd, cfg); |
2326 return 0; | 1674 return 0; |
2327 } else { | 1675 } else { |
2328 return -1; | 1676 return -1; |
2329 } | 1677 } |
2330 } | 1678 } |
2331 | 1679 |
2332 int vp9_update_entropy(VP9_PTR comp, int update) { | 1680 int vp9_update_entropy(VP9_COMP * cpi, int update) { |
2333 ((VP9_COMP *)comp)->ext_refresh_frame_context = update; | 1681 cpi->ext_refresh_frame_context = update; |
2334 ((VP9_COMP *)comp)->ext_refresh_frame_context_pending = 1; | 1682 cpi->ext_refresh_frame_context_pending = 1; |
2335 return 0; | 1683 return 0; |
2336 } | 1684 } |
2337 | 1685 |
2338 | 1686 |
2339 #ifdef OUTPUT_YUV_SRC | 1687 #ifdef OUTPUT_YUV_SRC |
2340 void vp9_write_yuv_frame(YV12_BUFFER_CONFIG *s) { | 1688 void vp9_write_yuv_frame(YV12_BUFFER_CONFIG *s) { |
2341 uint8_t *src = s->y_buffer; | 1689 uint8_t *src = s->y_buffer; |
2342 int h = s->y_height; | 1690 int h = s->y_height; |
2343 | 1691 |
2344 do { | 1692 do { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2525 yframe = fopen(filename, "wb"); | 1873 yframe = fopen(filename, "wb"); |
2526 | 1874 |
2527 for (i = 0; i < frame->uv_height; i++) | 1875 for (i = 0; i < frame->uv_height; i++) |
2528 fwrite(frame->v_buffer + i * frame->uv_stride, | 1876 fwrite(frame->v_buffer + i * frame->uv_stride, |
2529 frame->uv_width, 1, yframe); | 1877 frame->uv_width, 1, yframe); |
2530 | 1878 |
2531 fclose(yframe); | 1879 fclose(yframe); |
2532 } | 1880 } |
2533 #endif | 1881 #endif |
2534 | 1882 |
2535 static double compute_edge_pixel_proportion(YV12_BUFFER_CONFIG *frame) { | |
2536 #define EDGE_THRESH 128 | |
2537 int i, j; | |
2538 int num_edge_pels = 0; | |
2539 int num_pels = (frame->y_height - 2) * (frame->y_width - 2); | |
2540 uint8_t *prev = frame->y_buffer + 1; | |
2541 uint8_t *curr = frame->y_buffer + 1 + frame->y_stride; | |
2542 uint8_t *next = frame->y_buffer + 1 + 2 * frame->y_stride; | |
2543 for (i = 1; i < frame->y_height - 1; i++) { | |
2544 for (j = 1; j < frame->y_width - 1; j++) { | |
2545 /* Sobel hor and ver gradients */ | |
2546 int v = 2 * (curr[1] - curr[-1]) + (prev[1] - prev[-1]) + | |
2547 (next[1] - next[-1]); | |
2548 int h = 2 * (prev[0] - next[0]) + (prev[1] - next[1]) + | |
2549 (prev[-1] - next[-1]); | |
2550 h = (h < 0 ? -h : h); | |
2551 v = (v < 0 ? -v : v); | |
2552 if (h > EDGE_THRESH || v > EDGE_THRESH) | |
2553 num_edge_pels++; | |
2554 curr++; | |
2555 prev++; | |
2556 next++; | |
2557 } | |
2558 curr += frame->y_stride - frame->y_width + 2; | |
2559 prev += frame->y_stride - frame->y_width + 2; | |
2560 next += frame->y_stride - frame->y_width + 2; | |
2561 } | |
2562 return (double)num_edge_pels / num_pels; | |
2563 } | |
2564 | |
2565 // Function to test for conditions that indicate we should loop | 1883 // Function to test for conditions that indicate we should loop |
2566 // back and recode a frame. | 1884 // back and recode a frame. |
2567 static int recode_loop_test(const VP9_COMP *cpi, | 1885 static int recode_loop_test(const VP9_COMP *cpi, |
2568 int high_limit, int low_limit, | 1886 int high_limit, int low_limit, |
2569 int q, int maxq, int minq) { | 1887 int q, int maxq, int minq) { |
2570 const VP9_COMMON *const cm = &cpi->common; | 1888 const VP9_COMMON *const cm = &cpi->common; |
2571 const RATE_CONTROL *const rc = &cpi->rc; | 1889 const RATE_CONTROL *const rc = &cpi->rc; |
2572 int force_recode = 0; | 1890 int force_recode = 0; |
2573 | 1891 |
2574 // Special case trap if maximum allowed frame size exceeded. | 1892 // Special case trap if maximum allowed frame size exceeded. |
(...skipping 16 matching lines...) Expand all Loading... |
2591 // below the automatically set cq level. | 1909 // below the automatically set cq level. |
2592 if (q > cpi->cq_target_quality && | 1910 if (q > cpi->cq_target_quality && |
2593 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { | 1911 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
2594 force_recode = 1; | 1912 force_recode = 1; |
2595 } | 1913 } |
2596 } | 1914 } |
2597 } | 1915 } |
2598 return force_recode; | 1916 return force_recode; |
2599 } | 1917 } |
2600 | 1918 |
2601 static void update_reference_frames(VP9_COMP * const cpi) { | 1919 void vp9_update_reference_frames(VP9_COMP *cpi) { |
2602 VP9_COMMON * const cm = &cpi->common; | 1920 VP9_COMMON * const cm = &cpi->common; |
2603 | 1921 |
2604 // At this point the new frame has been encoded. | 1922 // At this point the new frame has been encoded. |
2605 // If any buffer copy / swapping is signaled it should be done here. | 1923 // If any buffer copy / swapping is signaled it should be done here. |
2606 if (cm->frame_type == KEY_FRAME) { | 1924 if (cm->frame_type == KEY_FRAME) { |
2607 ref_cnt_fb(cm->frame_bufs, | 1925 ref_cnt_fb(cm->frame_bufs, |
2608 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); | 1926 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); |
2609 ref_cnt_fb(cm->frame_bufs, | 1927 ref_cnt_fb(cm->frame_bufs, |
2610 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); | 1928 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); |
2611 } | 1929 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2662 struct loopfilter *lf = &cm->lf; | 1980 struct loopfilter *lf = &cm->lf; |
2663 if (xd->lossless) { | 1981 if (xd->lossless) { |
2664 lf->filter_level = 0; | 1982 lf->filter_level = 0; |
2665 } else { | 1983 } else { |
2666 struct vpx_usec_timer timer; | 1984 struct vpx_usec_timer timer; |
2667 | 1985 |
2668 vp9_clear_system_state(); | 1986 vp9_clear_system_state(); |
2669 | 1987 |
2670 vpx_usec_timer_start(&timer); | 1988 vpx_usec_timer_start(&timer); |
2671 | 1989 |
2672 vp9_pick_filter_level(cpi->Source, cpi, cpi->sf.use_fast_lpf_pick); | 1990 vp9_pick_filter_level(cpi->Source, cpi, cpi->sf.lpf_pick); |
2673 | 1991 |
2674 vpx_usec_timer_mark(&timer); | 1992 vpx_usec_timer_mark(&timer); |
2675 cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer); | 1993 cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer); |
2676 } | 1994 } |
2677 | 1995 |
2678 if (lf->filter_level > 0) { | 1996 if (lf->filter_level > 0) { |
2679 vp9_set_alt_lf_level(cpi, lf->filter_level); | |
2680 vp9_loop_filter_frame(cm, xd, lf->filter_level, 0, 0); | 1997 vp9_loop_filter_frame(cm, xd, lf->filter_level, 0, 0); |
2681 } | 1998 } |
2682 | 1999 |
2683 vp9_extend_frame_inner_borders(cm->frame_to_show); | 2000 vp9_extend_frame_inner_borders(cm->frame_to_show); |
2684 } | 2001 } |
2685 | 2002 |
2686 static void scale_references(VP9_COMP *cpi) { | 2003 void vp9_scale_references(VP9_COMP *cpi) { |
2687 VP9_COMMON *cm = &cpi->common; | 2004 VP9_COMMON *cm = &cpi->common; |
2688 MV_REFERENCE_FRAME ref_frame; | 2005 MV_REFERENCE_FRAME ref_frame; |
2689 | 2006 |
2690 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2007 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
2691 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | 2008 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
2692 YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf; | 2009 YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf; |
2693 | 2010 |
2694 if (ref->y_crop_width != cm->width || | 2011 if (ref->y_crop_width != cm->width || |
2695 ref->y_crop_height != cm->height) { | 2012 ref->y_crop_height != cm->height) { |
2696 const int new_fb = get_free_fb(cm); | 2013 const int new_fb = get_free_fb(cm); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2738 } | 2055 } |
2739 | 2056 |
2740 #if 0 && CONFIG_INTERNAL_STATS | 2057 #if 0 && CONFIG_INTERNAL_STATS |
2741 static void output_frame_level_debug_stats(VP9_COMP *cpi) { | 2058 static void output_frame_level_debug_stats(VP9_COMP *cpi) { |
2742 VP9_COMMON *const cm = &cpi->common; | 2059 VP9_COMMON *const cm = &cpi->common; |
2743 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); | 2060 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
2744 int recon_err; | 2061 int recon_err; |
2745 | 2062 |
2746 vp9_clear_system_state(); | 2063 vp9_clear_system_state(); |
2747 | 2064 |
2748 recon_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); | 2065 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); |
2749 | 2066 |
2750 if (cpi->twopass.total_left_stats.coded_error != 0.0) | 2067 if (cpi->twopass.total_left_stats.coded_error != 0.0) |
2751 fprintf(f, "%10u %10d %10d %10d %10d %10d " | 2068 fprintf(f, "%10u %10d %10d %10d %10d %10d " |
2752 "%10"PRId64" %10"PRId64" %10d " | 2069 "%10"PRId64" %10"PRId64" %10d " |
2753 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" | 2070 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
2754 "%6d %6d %5d %5d %5d " | 2071 "%6d %6d %5d %5d %5d " |
2755 "%10"PRId64" %10.3lf" | 2072 "%10"PRId64" %10.3lf" |
2756 "%10lf %8u %10d %10d %10d\n", | 2073 "%10lf %8u %10d %10d %10d\n", |
2757 cpi->common.current_video_frame, cpi->rc.this_frame_target, | 2074 cpi->common.current_video_frame, cpi->rc.this_frame_target, |
2758 cpi->rc.projected_frame_size, | 2075 cpi->rc.projected_frame_size, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2794 } | 2111 } |
2795 } | 2112 } |
2796 #endif | 2113 #endif |
2797 | 2114 |
2798 static void encode_without_recode_loop(VP9_COMP *cpi, | 2115 static void encode_without_recode_loop(VP9_COMP *cpi, |
2799 size_t *size, | 2116 size_t *size, |
2800 uint8_t *dest, | 2117 uint8_t *dest, |
2801 int q) { | 2118 int q) { |
2802 VP9_COMMON *const cm = &cpi->common; | 2119 VP9_COMMON *const cm = &cpi->common; |
2803 vp9_clear_system_state(); | 2120 vp9_clear_system_state(); |
2804 vp9_set_quantizer(cpi, q); | 2121 vp9_set_quantizer(cm, q); |
2805 | 2122 |
2806 // Set up entropy context depending on frame type. The decoder mandates | 2123 // Set up entropy context depending on frame type. The decoder mandates |
2807 // the use of the default context, index 0, for keyframes and inter | 2124 // the use of the default context, index 0, for keyframes and inter |
2808 // frames where the error_resilient_mode or intra_only flag is set. For | 2125 // frames where the error_resilient_mode or intra_only flag is set. For |
2809 // other inter-frames the encoder currently uses only two contexts; | 2126 // other inter-frames the encoder currently uses only two contexts; |
2810 // context 1 for ALTREF frames and context 0 for the others. | 2127 // context 1 for ALTREF frames and context 0 for the others. |
2811 if (cm->frame_type == KEY_FRAME) { | 2128 if (cm->frame_type == KEY_FRAME) { |
2812 vp9_setup_key_frame(cpi); | 2129 setup_key_frame(cpi); |
2813 } else { | 2130 } else { |
2814 if (!cm->intra_only && !cm->error_resilient_mode && !cpi->use_svc) { | 2131 if (!cm->intra_only && !cm->error_resilient_mode && !cpi->use_svc) |
2815 cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame; | 2132 cm->frame_context_idx = cpi->refresh_alt_ref_frame; |
2816 } | 2133 |
2817 vp9_setup_inter_frame(cpi); | 2134 setup_inter_frame(cm); |
2818 } | 2135 } |
2819 // Variance adaptive and in frame q adjustment experiments are mutually | 2136 // Variance adaptive and in frame q adjustment experiments are mutually |
2820 // exclusive. | 2137 // exclusive. |
2821 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 2138 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
2822 vp9_vaq_frame_setup(cpi); | 2139 vp9_vaq_frame_setup(cpi); |
2823 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 2140 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
2824 setup_in_frame_q_adj(cpi); | 2141 vp9_setup_in_frame_q_adj(cpi); |
| 2142 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
| 2143 vp9_cyclic_refresh_setup(cpi); |
2825 } | 2144 } |
2826 // transform / motion compensation build reconstruction frame | 2145 // transform / motion compensation build reconstruction frame |
2827 vp9_encode_frame(cpi); | 2146 vp9_encode_frame(cpi); |
2828 | 2147 |
2829 // Update the skip mb flag probabilities based on the distribution | 2148 // Update the skip mb flag probabilities based on the distribution |
2830 // seen in the last encoder iteration. | 2149 // seen in the last encoder iteration. |
2831 // update_base_skip_probs(cpi); | 2150 // update_base_skip_probs(cpi); |
2832 vp9_clear_system_state(); | 2151 vp9_clear_system_state(); |
2833 } | 2152 } |
2834 | 2153 |
(...skipping 14 matching lines...) Expand all Loading... |
2849 int frame_under_shoot_limit; | 2168 int frame_under_shoot_limit; |
2850 | 2169 |
2851 // Decide frame size bounds | 2170 // Decide frame size bounds |
2852 vp9_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, | 2171 vp9_rc_compute_frame_size_bounds(cpi, rc->this_frame_target, |
2853 &frame_under_shoot_limit, | 2172 &frame_under_shoot_limit, |
2854 &frame_over_shoot_limit); | 2173 &frame_over_shoot_limit); |
2855 | 2174 |
2856 do { | 2175 do { |
2857 vp9_clear_system_state(); | 2176 vp9_clear_system_state(); |
2858 | 2177 |
2859 vp9_set_quantizer(cpi, q); | 2178 vp9_set_quantizer(cm, q); |
2860 | 2179 |
2861 if (loop_count == 0) { | 2180 if (loop_count == 0) { |
2862 // Set up entropy context depending on frame type. The decoder mandates | 2181 // Set up entropy context depending on frame type. The decoder mandates |
2863 // the use of the default context, index 0, for keyframes and inter | 2182 // the use of the default context, index 0, for keyframes and inter |
2864 // frames where the error_resilient_mode or intra_only flag is set. For | 2183 // frames where the error_resilient_mode or intra_only flag is set. For |
2865 // other inter-frames the encoder currently uses only two contexts; | 2184 // other inter-frames the encoder currently uses only two contexts; |
2866 // context 1 for ALTREF frames and context 0 for the others. | 2185 // context 1 for ALTREF frames and context 0 for the others. |
2867 if (cm->frame_type == KEY_FRAME) { | 2186 if (cm->frame_type == KEY_FRAME) { |
2868 vp9_setup_key_frame(cpi); | 2187 setup_key_frame(cpi); |
2869 } else { | 2188 } else { |
2870 if (!cm->intra_only && !cm->error_resilient_mode && !cpi->use_svc) { | 2189 if (!cm->intra_only && !cm->error_resilient_mode && !cpi->use_svc) |
2871 cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame; | 2190 cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame; |
2872 } | 2191 |
2873 vp9_setup_inter_frame(cpi); | 2192 setup_inter_frame(cm); |
2874 } | 2193 } |
2875 } | 2194 } |
2876 | 2195 |
2877 // Variance adaptive and in frame q adjustment experiments are mutually | 2196 // Variance adaptive and in frame q adjustment experiments are mutually |
2878 // exclusive. | 2197 // exclusive. |
2879 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 2198 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
2880 vp9_vaq_frame_setup(cpi); | 2199 vp9_vaq_frame_setup(cpi); |
2881 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 2200 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
2882 setup_in_frame_q_adj(cpi); | 2201 vp9_setup_in_frame_q_adj(cpi); |
2883 } | 2202 } |
2884 | 2203 |
2885 // transform / motion compensation build reconstruction frame | 2204 // transform / motion compensation build reconstruction frame |
2886 vp9_encode_frame(cpi); | 2205 vp9_encode_frame(cpi); |
2887 | 2206 |
2888 // Update the skip mb flag probabilities based on the distribution | 2207 // Update the skip mb flag probabilities based on the distribution |
2889 // seen in the last encoder iteration. | 2208 // seen in the last encoder iteration. |
2890 // update_base_skip_probs(cpi); | 2209 // update_base_skip_probs(cpi); |
2891 | 2210 |
2892 vp9_clear_system_state(); | 2211 vp9_clear_system_state(); |
2893 | 2212 |
2894 // Dummy pack of the bitstream using up to date stats to get an | 2213 // Dummy pack of the bitstream using up to date stats to get an |
2895 // accurate estimate of output frame size to determine if we need | 2214 // accurate estimate of output frame size to determine if we need |
2896 // to recode. | 2215 // to recode. |
2897 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { | 2216 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
2898 vp9_save_coding_context(cpi); | 2217 save_coding_context(cpi); |
2899 cpi->dummy_packing = 1; | 2218 cpi->dummy_packing = 1; |
2900 if (!cpi->sf.use_nonrd_pick_mode) | 2219 if (!cpi->sf.use_nonrd_pick_mode) |
2901 vp9_pack_bitstream(cpi, dest, size); | 2220 vp9_pack_bitstream(cpi, dest, size); |
2902 | 2221 |
2903 rc->projected_frame_size = (int)(*size) << 3; | 2222 rc->projected_frame_size = (int)(*size) << 3; |
2904 vp9_restore_coding_context(cpi); | 2223 restore_coding_context(cpi); |
2905 | 2224 |
2906 if (frame_over_shoot_limit == 0) | 2225 if (frame_over_shoot_limit == 0) |
2907 frame_over_shoot_limit = 1; | 2226 frame_over_shoot_limit = 1; |
2908 } | 2227 } |
2909 | 2228 |
2910 if (cpi->oxcf.end_usage == USAGE_CONSTANT_QUALITY) { | 2229 if (cpi->oxcf.end_usage == USAGE_CONSTANT_QUALITY) { |
2911 loop = 0; | 2230 loop = 0; |
2912 } else { | 2231 } else { |
2913 if ((cm->frame_type == KEY_FRAME) && | 2232 if ((cm->frame_type == KEY_FRAME) && |
2914 rc->this_key_frame_forced && | 2233 rc->this_key_frame_forced && |
2915 (rc->projected_frame_size < rc->max_frame_bandwidth)) { | 2234 (rc->projected_frame_size < rc->max_frame_bandwidth)) { |
2916 int last_q = q; | 2235 int last_q = q; |
2917 int kf_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); | 2236 int kf_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); |
2918 | 2237 |
2919 int high_err_target = cpi->ambient_err; | 2238 int high_err_target = cpi->ambient_err; |
2920 int low_err_target = cpi->ambient_err >> 1; | 2239 int low_err_target = cpi->ambient_err >> 1; |
2921 | 2240 |
2922 // Prevent possible divide by zero error below for perfect KF | 2241 // Prevent possible divide by zero error below for perfect KF |
2923 kf_err += !kf_err; | 2242 kf_err += !kf_err; |
2924 | 2243 |
2925 // The key frame is not good enough or we can afford | 2244 // The key frame is not good enough or we can afford |
2926 // to make it better without undue risk of popping. | 2245 // to make it better without undue risk of popping. |
2927 if ((kf_err > high_err_target && | 2246 if ((kf_err > high_err_target && |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3111 | 2430 |
3112 /* Scale the source buffer, if required. */ | 2431 /* Scale the source buffer, if required. */ |
3113 if (cm->mi_cols * MI_SIZE != cpi->un_scaled_source->y_width || | 2432 if (cm->mi_cols * MI_SIZE != cpi->un_scaled_source->y_width || |
3114 cm->mi_rows * MI_SIZE != cpi->un_scaled_source->y_height) { | 2433 cm->mi_rows * MI_SIZE != cpi->un_scaled_source->y_height) { |
3115 scale_and_extend_frame_nonnormative(cpi->un_scaled_source, | 2434 scale_and_extend_frame_nonnormative(cpi->un_scaled_source, |
3116 &cpi->scaled_source); | 2435 &cpi->scaled_source); |
3117 cpi->Source = &cpi->scaled_source; | 2436 cpi->Source = &cpi->scaled_source; |
3118 } else { | 2437 } else { |
3119 cpi->Source = cpi->un_scaled_source; | 2438 cpi->Source = cpi->un_scaled_source; |
3120 } | 2439 } |
3121 scale_references(cpi); | 2440 |
| 2441 // Scale the last source buffer, if required. |
| 2442 if (cpi->unscaled_last_source != NULL) { |
| 2443 if (cm->mi_cols * MI_SIZE != cpi->unscaled_last_source->y_width || |
| 2444 cm->mi_rows * MI_SIZE != cpi->unscaled_last_source->y_height) { |
| 2445 scale_and_extend_frame_nonnormative(cpi->unscaled_last_source, |
| 2446 &cpi->scaled_last_source); |
| 2447 cpi->Last_Source = &cpi->scaled_last_source; |
| 2448 } else { |
| 2449 cpi->Last_Source = cpi->unscaled_last_source; |
| 2450 } |
| 2451 } |
| 2452 |
| 2453 vp9_scale_references(cpi); |
3122 | 2454 |
3123 vp9_clear_system_state(); | 2455 vp9_clear_system_state(); |
3124 | 2456 |
3125 // Enable or disable mode based tweaking of the zbin. | 2457 // Enable or disable mode based tweaking of the zbin. |
3126 // For 2 pass only used where GF/ARF prediction quality | 2458 // For 2 pass only used where GF/ARF prediction quality |
3127 // is above a threshold. | 2459 // is above a threshold. |
3128 cpi->zbin_mode_boost = 0; | 2460 cpi->zbin_mode_boost = 0; |
3129 cpi->zbin_mode_boost_enabled = 0; | 2461 cpi->zbin_mode_boost_enabled = 0; |
3130 | 2462 |
3131 // Current default encoder behavior for the altref sign bias. | 2463 // Current default encoder behavior for the altref sign bias. |
(...skipping 16 matching lines...) Expand all Loading... |
3148 // in the previous frame, capped by the default max_mv_magnitude based | 2480 // in the previous frame, capped by the default max_mv_magnitude based |
3149 // on resolution. | 2481 // on resolution. |
3150 cpi->mv_step_param = vp9_init_search_range(cpi, MIN(max_mv_def, 2 * | 2482 cpi->mv_step_param = vp9_init_search_range(cpi, MIN(max_mv_def, 2 * |
3151 cpi->max_mv_magnitude)); | 2483 cpi->max_mv_magnitude)); |
3152 cpi->max_mv_magnitude = 0; | 2484 cpi->max_mv_magnitude = 0; |
3153 } | 2485 } |
3154 } | 2486 } |
3155 | 2487 |
3156 // Set various flags etc to special state if it is a key frame. | 2488 // Set various flags etc to special state if it is a key frame. |
3157 if (frame_is_intra_only(cm)) { | 2489 if (frame_is_intra_only(cm)) { |
3158 vp9_setup_key_frame(cpi); | 2490 setup_key_frame(cpi); |
3159 // Reset the loop filter deltas and segmentation map. | 2491 // Reset the loop filter deltas and segmentation map. |
3160 vp9_reset_segment_features(&cm->seg); | 2492 vp9_reset_segment_features(&cm->seg); |
3161 | 2493 |
3162 // If segmentation is enabled force a map update for key frames. | 2494 // If segmentation is enabled force a map update for key frames. |
3163 if (seg->enabled) { | 2495 if (seg->enabled) { |
3164 seg->update_map = 1; | 2496 seg->update_map = 1; |
3165 seg->update_data = 1; | 2497 seg->update_data = 1; |
3166 } | 2498 } |
3167 | 2499 |
3168 // The alternate reference frame cannot be active for a key frame. | 2500 // The alternate reference frame cannot be active for a key frame. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3230 break; | 2562 break; |
3231 } | 2563 } |
3232 vp9_denoise(cpi->Source, cpi->Source, l); | 2564 vp9_denoise(cpi->Source, cpi->Source, l); |
3233 } | 2565 } |
3234 #endif | 2566 #endif |
3235 | 2567 |
3236 #ifdef OUTPUT_YUV_SRC | 2568 #ifdef OUTPUT_YUV_SRC |
3237 vp9_write_yuv_frame(cpi->Source); | 2569 vp9_write_yuv_frame(cpi->Source); |
3238 #endif | 2570 #endif |
3239 | 2571 |
| 2572 set_speed_features(cpi); |
| 2573 |
3240 // Decide q and q bounds. | 2574 // Decide q and q bounds. |
3241 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); | 2575 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); |
3242 | 2576 |
3243 if (!frame_is_intra_only(cm)) { | 2577 if (!frame_is_intra_only(cm)) { |
3244 cm->interp_filter = DEFAULT_INTERP_FILTER; | 2578 cm->interp_filter = DEFAULT_INTERP_FILTER; |
3245 /* TODO: Decide this more intelligently */ | 2579 /* TODO: Decide this more intelligently */ |
3246 set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH); | 2580 set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH); |
3247 } | 2581 } |
3248 | 2582 |
3249 if (cpi->sf.recode_loop == DISALLOW_RECODE) { | 2583 if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
3250 encode_without_recode_loop(cpi, size, dest, q); | 2584 encode_without_recode_loop(cpi, size, dest, q); |
3251 } else { | 2585 } else { |
3252 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); | 2586 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); |
3253 } | 2587 } |
3254 | 2588 |
3255 // Special case code to reduce pulsing when key frames are forced at a | 2589 // Special case code to reduce pulsing when key frames are forced at a |
3256 // fixed interval. Note the reconstruction error if it is the frame before | 2590 // fixed interval. Note the reconstruction error if it is the frame before |
3257 // the force key frame | 2591 // the force key frame |
3258 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { | 2592 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { |
3259 cpi->ambient_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); | 2593 cpi->ambient_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); |
3260 } | 2594 } |
3261 | 2595 |
3262 // If the encoder forced a KEY_FRAME decision | 2596 // If the encoder forced a KEY_FRAME decision |
3263 if (cm->frame_type == KEY_FRAME) | 2597 if (cm->frame_type == KEY_FRAME) |
3264 cpi->refresh_last_frame = 1; | 2598 cpi->refresh_last_frame = 1; |
3265 | 2599 |
3266 cm->frame_to_show = get_frame_new_buffer(cm); | 2600 cm->frame_to_show = get_frame_new_buffer(cm); |
3267 | 2601 |
3268 #if WRITE_RECON_BUFFER | 2602 #if WRITE_RECON_BUFFER |
3269 if (cm->show_frame) | 2603 if (cm->show_frame) |
(...skipping 17 matching lines...) Expand all Loading... |
3287 #endif | 2621 #endif |
3288 | 2622 |
3289 // build the bitstream | 2623 // build the bitstream |
3290 cpi->dummy_packing = 0; | 2624 cpi->dummy_packing = 0; |
3291 vp9_pack_bitstream(cpi, dest, size); | 2625 vp9_pack_bitstream(cpi, dest, size); |
3292 | 2626 |
3293 if (cm->seg.update_map) | 2627 if (cm->seg.update_map) |
3294 update_reference_segmentation_map(cpi); | 2628 update_reference_segmentation_map(cpi); |
3295 | 2629 |
3296 release_scaled_references(cpi); | 2630 release_scaled_references(cpi); |
3297 update_reference_frames(cpi); | 2631 vp9_update_reference_frames(cpi); |
3298 | 2632 |
3299 for (t = TX_4X4; t <= TX_32X32; t++) | 2633 for (t = TX_4X4; t <= TX_32X32; t++) |
3300 full_to_model_counts(cm->counts.coef[t], cpi->coef_counts[t]); | 2634 full_to_model_counts(cm->counts.coef[t], cpi->coef_counts[t]); |
3301 | 2635 |
3302 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) | 2636 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) |
3303 vp9_adapt_coef_probs(cm); | 2637 vp9_adapt_coef_probs(cm); |
3304 | 2638 |
3305 if (!frame_is_intra_only(cm)) { | 2639 if (!frame_is_intra_only(cm)) { |
3306 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { | 2640 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { |
3307 vp9_adapt_mode_probs(cm); | 2641 vp9_adapt_mode_probs(cm); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3364 | 2698 |
3365 // keep track of the last coded dimensions | 2699 // keep track of the last coded dimensions |
3366 cm->last_width = cm->width; | 2700 cm->last_width = cm->width; |
3367 cm->last_height = cm->height; | 2701 cm->last_height = cm->height; |
3368 | 2702 |
3369 // reset to normal state now that we are done. | 2703 // reset to normal state now that we are done. |
3370 if (!cm->show_existing_frame) | 2704 if (!cm->show_existing_frame) |
3371 cm->last_show_frame = cm->show_frame; | 2705 cm->last_show_frame = cm->show_frame; |
3372 | 2706 |
3373 if (cm->show_frame) { | 2707 if (cm->show_frame) { |
3374 // current mip will be the prev_mip for the next frame | 2708 vp9_swap_mi_and_prev_mi(cm); |
3375 MODE_INFO *temp = cm->prev_mip; | |
3376 MODE_INFO **temp2 = cm->prev_mi_grid_base; | |
3377 cm->prev_mip = cm->mip; | |
3378 cm->mip = temp; | |
3379 cm->prev_mi_grid_base = cm->mi_grid_base; | |
3380 cm->mi_grid_base = temp2; | |
3381 | |
3382 // update the upper left visible macroblock ptrs | |
3383 cm->mi = cm->mip + cm->mode_info_stride + 1; | |
3384 cm->mi_grid_visible = cm->mi_grid_base + cm->mode_info_stride + 1; | |
3385 | |
3386 cpi->mb.e_mbd.mi_8x8 = cm->mi_grid_visible; | |
3387 cpi->mb.e_mbd.mi_8x8[0] = cm->mi; | |
3388 | 2709 |
3389 // Don't increment frame counters if this was an altref buffer | 2710 // Don't increment frame counters if this was an altref buffer |
3390 // update not a real frame | 2711 // update not a real frame |
3391 ++cm->current_video_frame; | 2712 ++cm->current_video_frame; |
| 2713 if (cpi->use_svc) |
| 2714 vp9_inc_frame_in_layer(&cpi->svc); |
3392 } | 2715 } |
3393 | |
3394 // restore prev_mi | |
3395 cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1; | |
3396 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1; | |
3397 } | 2716 } |
3398 | 2717 |
3399 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 2718 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
3400 unsigned int *frame_flags) { | 2719 unsigned int *frame_flags) { |
3401 vp9_rc_get_svc_params(cpi); | 2720 vp9_rc_get_svc_params(cpi); |
3402 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 2721 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
3403 } | 2722 } |
3404 | 2723 |
3405 static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 2724 static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
3406 unsigned int *frame_flags) { | 2725 unsigned int *frame_flags) { |
3407 if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { | 2726 if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { |
3408 vp9_rc_get_one_pass_cbr_params(cpi); | 2727 vp9_rc_get_one_pass_cbr_params(cpi); |
3409 } else { | 2728 } else { |
3410 vp9_rc_get_one_pass_vbr_params(cpi); | 2729 vp9_rc_get_one_pass_vbr_params(cpi); |
3411 } | 2730 } |
3412 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 2731 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
3413 } | 2732 } |
3414 | 2733 |
3415 static void Pass1Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 2734 static void Pass1Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
3416 unsigned int *frame_flags) { | 2735 unsigned int *frame_flags) { |
3417 (void) size; | 2736 (void) size; |
3418 (void) dest; | 2737 (void) dest; |
3419 (void) frame_flags; | 2738 (void) frame_flags; |
3420 | 2739 |
3421 vp9_rc_get_first_pass_params(cpi); | 2740 vp9_rc_get_first_pass_params(cpi); |
3422 vp9_set_quantizer(cpi, find_fp_qindex()); | 2741 vp9_set_quantizer(&cpi->common, find_fp_qindex()); |
3423 vp9_first_pass(cpi); | 2742 vp9_first_pass(cpi); |
3424 } | 2743 } |
3425 | 2744 |
3426 static void Pass2Encode(VP9_COMP *cpi, size_t *size, | 2745 static void Pass2Encode(VP9_COMP *cpi, size_t *size, |
3427 uint8_t *dest, unsigned int *frame_flags) { | 2746 uint8_t *dest, unsigned int *frame_flags) { |
3428 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; | 2747 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; |
3429 | 2748 |
3430 vp9_rc_get_second_pass_params(cpi); | 2749 vp9_rc_get_second_pass_params(cpi); |
3431 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 2750 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
3432 | 2751 |
3433 vp9_twopass_postencode_update(cpi, *size); | 2752 vp9_twopass_postencode_update(cpi); |
3434 } | 2753 } |
3435 | 2754 |
3436 static void check_initial_width(VP9_COMP *cpi, int subsampling_x, | 2755 static void check_initial_width(VP9_COMP *cpi, int subsampling_x, |
3437 int subsampling_y) { | 2756 int subsampling_y) { |
3438 VP9_COMMON *const cm = &cpi->common; | 2757 VP9_COMMON *const cm = &cpi->common; |
3439 | 2758 |
3440 if (!cpi->initial_width) { | 2759 if (!cpi->initial_width) { |
3441 cm->subsampling_x = subsampling_x; | 2760 cm->subsampling_x = subsampling_x; |
3442 cm->subsampling_y = subsampling_y; | 2761 cm->subsampling_y = subsampling_y; |
3443 alloc_raw_frame_buffers(cpi); | 2762 alloc_raw_frame_buffers(cpi); |
3444 cpi->initial_width = cm->width; | 2763 cpi->initial_width = cm->width; |
3445 cpi->initial_height = cm->height; | 2764 cpi->initial_height = cm->height; |
3446 } | 2765 } |
3447 } | 2766 } |
3448 | 2767 |
3449 | 2768 |
3450 int vp9_receive_raw_frame(VP9_PTR ptr, unsigned int frame_flags, | 2769 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags, |
3451 YV12_BUFFER_CONFIG *sd, int64_t time_stamp, | 2770 YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
3452 int64_t end_time) { | 2771 int64_t end_time) { |
3453 VP9_COMP *cpi = (VP9_COMP *)ptr; | |
3454 VP9_COMMON *cm = &cpi->common; | 2772 VP9_COMMON *cm = &cpi->common; |
3455 struct vpx_usec_timer timer; | 2773 struct vpx_usec_timer timer; |
3456 int res = 0; | 2774 int res = 0; |
3457 const int subsampling_x = sd->uv_width < sd->y_width; | 2775 const int subsampling_x = sd->uv_width < sd->y_width; |
3458 const int subsampling_y = sd->uv_height < sd->y_height; | 2776 const int subsampling_y = sd->uv_height < sd->y_height; |
3459 | 2777 |
3460 check_initial_width(cpi, subsampling_x, subsampling_y); | 2778 check_initial_width(cpi, subsampling_x, subsampling_y); |
3461 vpx_usec_timer_start(&timer); | 2779 vpx_usec_timer_start(&timer); |
3462 if (vp9_lookahead_push(cpi->lookahead, | 2780 if (vp9_lookahead_push(cpi->lookahead, |
3463 sd, time_stamp, end_time, frame_flags)) | 2781 sd, time_stamp, end_time, frame_flags)) |
3464 res = -1; | 2782 res = -1; |
3465 vpx_usec_timer_mark(&timer); | 2783 vpx_usec_timer_mark(&timer); |
3466 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); | 2784 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); |
3467 | 2785 |
3468 if (cm->version == 0 && (subsampling_x != 1 || subsampling_y != 1)) { | 2786 if (cm->profile == PROFILE_0 && (subsampling_x != 1 || subsampling_y != 1)) { |
3469 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, | 2787 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, |
3470 "Non-4:2:0 color space requires profile >= 1"); | 2788 "Non-4:2:0 color space requires profile >= 1"); |
3471 res = -1; | 2789 res = -1; |
3472 } | 2790 } |
3473 | 2791 |
3474 return res; | 2792 return res; |
3475 } | 2793 } |
3476 | 2794 |
3477 | 2795 |
3478 static int frame_is_reference(const VP9_COMP *cpi) { | 2796 static int frame_is_reference(const VP9_COMP *cpi) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3526 avg_duration *= (interval - avg_duration + this_duration); | 2844 avg_duration *= (interval - avg_duration + this_duration); |
3527 avg_duration /= interval; | 2845 avg_duration /= interval; |
3528 | 2846 |
3529 vp9_new_framerate(cpi, 10000000.0 / avg_duration); | 2847 vp9_new_framerate(cpi, 10000000.0 / avg_duration); |
3530 } | 2848 } |
3531 } | 2849 } |
3532 cpi->last_time_stamp_seen = cpi->source->ts_start; | 2850 cpi->last_time_stamp_seen = cpi->source->ts_start; |
3533 cpi->last_end_time_stamp_seen = cpi->source->ts_end; | 2851 cpi->last_end_time_stamp_seen = cpi->source->ts_end; |
3534 } | 2852 } |
3535 | 2853 |
3536 int vp9_get_compressed_data(VP9_PTR ptr, unsigned int *frame_flags, | 2854 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, |
3537 size_t *size, uint8_t *dest, | 2855 size_t *size, uint8_t *dest, |
3538 int64_t *time_stamp, int64_t *time_end, int flush) { | 2856 int64_t *time_stamp, int64_t *time_end, int flush) { |
3539 VP9_COMP *cpi = (VP9_COMP *) ptr; | 2857 VP9_COMMON *const cm = &cpi->common; |
3540 VP9_COMMON *cm = &cpi->common; | 2858 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
3541 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 2859 RATE_CONTROL *const rc = &cpi->rc; |
3542 struct vpx_usec_timer cmptimer; | 2860 struct vpx_usec_timer cmptimer; |
3543 YV12_BUFFER_CONFIG *force_src_buffer = NULL; | 2861 YV12_BUFFER_CONFIG *force_src_buffer = NULL; |
3544 MV_REFERENCE_FRAME ref_frame; | 2862 MV_REFERENCE_FRAME ref_frame; |
3545 | 2863 |
3546 if (!cpi) | 2864 if (!cpi) |
3547 return -1; | 2865 return -1; |
3548 | 2866 |
| 2867 if (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2) { |
| 2868 vp9_restore_layer_context(cpi); |
| 2869 } |
| 2870 |
3549 vpx_usec_timer_start(&cmptimer); | 2871 vpx_usec_timer_start(&cmptimer); |
3550 | 2872 |
3551 cpi->source = NULL; | 2873 cpi->source = NULL; |
| 2874 cpi->last_source = NULL; |
3552 | 2875 |
3553 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); | 2876 set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV); |
3554 | 2877 |
3555 // Normal defaults | 2878 // Normal defaults |
3556 cm->reset_frame_context = 0; | 2879 cm->reset_frame_context = 0; |
3557 cm->refresh_frame_context = 1; | 2880 cm->refresh_frame_context = 1; |
3558 cpi->refresh_last_frame = 1; | 2881 cpi->refresh_last_frame = 1; |
3559 cpi->refresh_golden_frame = 0; | 2882 cpi->refresh_golden_frame = 0; |
3560 cpi->refresh_alt_ref_frame = 0; | 2883 cpi->refresh_alt_ref_frame = 0; |
3561 | 2884 |
3562 // Should we code an alternate reference frame. | 2885 // Should we code an alternate reference frame. |
3563 if (cpi->oxcf.play_alternate && cpi->rc.source_alt_ref_pending) { | 2886 if (cpi->oxcf.play_alternate && rc->source_alt_ref_pending) { |
3564 int frames_to_arf; | 2887 int frames_to_arf; |
3565 | 2888 |
3566 #if CONFIG_MULTIPLE_ARF | 2889 #if CONFIG_MULTIPLE_ARF |
3567 assert(!cpi->multi_arf_enabled || | 2890 assert(!cpi->multi_arf_enabled || |
3568 cpi->frame_coding_order[cpi->sequence_number] < 0); | 2891 cpi->frame_coding_order[cpi->sequence_number] < 0); |
3569 | 2892 |
3570 if (cpi->multi_arf_enabled && (cpi->pass == 2)) | 2893 if (cpi->multi_arf_enabled && (cpi->pass == 2)) |
3571 frames_to_arf = (-cpi->frame_coding_order[cpi->sequence_number]) | 2894 frames_to_arf = (-cpi->frame_coding_order[cpi->sequence_number]) |
3572 - cpi->next_frame_in_order; | 2895 - cpi->next_frame_in_order; |
3573 else | 2896 else |
3574 #endif | 2897 #endif |
3575 frames_to_arf = cpi->rc.frames_till_gf_update_due; | 2898 frames_to_arf = rc->frames_till_gf_update_due; |
3576 | 2899 |
3577 assert(frames_to_arf <= cpi->rc.frames_to_key); | 2900 assert(frames_to_arf <= rc->frames_to_key); |
3578 | 2901 |
3579 if ((cpi->source = vp9_lookahead_peek(cpi->lookahead, frames_to_arf))) { | 2902 if ((cpi->source = vp9_lookahead_peek(cpi->lookahead, frames_to_arf))) { |
3580 #if CONFIG_MULTIPLE_ARF | 2903 #if CONFIG_MULTIPLE_ARF |
3581 cpi->alt_ref_source[cpi->arf_buffered] = cpi->source; | 2904 cpi->alt_ref_source[cpi->arf_buffered] = cpi->source; |
3582 #else | 2905 #else |
3583 cpi->alt_ref_source = cpi->source; | 2906 cpi->alt_ref_source = cpi->source; |
3584 #endif | 2907 #endif |
3585 | 2908 |
3586 if (cpi->oxcf.arnr_max_frames > 0) { | 2909 if (cpi->oxcf.arnr_max_frames > 0) { |
3587 // Produce the filtered ARF frame. | 2910 // Produce the filtered ARF frame. |
3588 // TODO(agrange) merge these two functions. | 2911 // TODO(agrange) merge these two functions. |
3589 vp9_configure_arnr_filter(cpi, frames_to_arf, cpi->rc.gfu_boost); | 2912 vp9_configure_arnr_filter(cpi, frames_to_arf, rc->gfu_boost); |
3590 vp9_temporal_filter_prepare(cpi, frames_to_arf); | 2913 vp9_temporal_filter_prepare(cpi, frames_to_arf); |
3591 vp9_extend_frame_borders(&cpi->alt_ref_buffer); | 2914 vp9_extend_frame_borders(&cpi->alt_ref_buffer); |
3592 force_src_buffer = &cpi->alt_ref_buffer; | 2915 force_src_buffer = &cpi->alt_ref_buffer; |
3593 } | 2916 } |
3594 | 2917 |
3595 cm->show_frame = 0; | 2918 cm->show_frame = 0; |
3596 cpi->refresh_alt_ref_frame = 1; | 2919 cpi->refresh_alt_ref_frame = 1; |
3597 cpi->refresh_golden_frame = 0; | 2920 cpi->refresh_golden_frame = 0; |
3598 cpi->refresh_last_frame = 0; | 2921 cpi->refresh_last_frame = 0; |
3599 cpi->rc.is_src_frame_alt_ref = 0; | 2922 rc->is_src_frame_alt_ref = 0; |
3600 | 2923 |
3601 #if CONFIG_MULTIPLE_ARF | 2924 #if CONFIG_MULTIPLE_ARF |
3602 if (!cpi->multi_arf_enabled) | 2925 if (!cpi->multi_arf_enabled) |
3603 #endif | 2926 #endif |
3604 cpi->rc.source_alt_ref_pending = 0; | 2927 rc->source_alt_ref_pending = 0; |
3605 } else { | 2928 } else { |
3606 cpi->rc.source_alt_ref_pending = 0; | 2929 rc->source_alt_ref_pending = 0; |
3607 } | 2930 } |
3608 } | 2931 } |
3609 | 2932 |
3610 if (!cpi->source) { | 2933 if (!cpi->source) { |
3611 #if CONFIG_MULTIPLE_ARF | 2934 #if CONFIG_MULTIPLE_ARF |
3612 int i; | 2935 int i; |
3613 #endif | 2936 #endif |
| 2937 |
| 2938 // Get last frame source. |
| 2939 if (cm->current_video_frame > 0) { |
| 2940 if ((cpi->last_source = vp9_lookahead_peek(cpi->lookahead, -1)) == NULL) |
| 2941 return -1; |
| 2942 } |
| 2943 |
3614 if ((cpi->source = vp9_lookahead_pop(cpi->lookahead, flush))) { | 2944 if ((cpi->source = vp9_lookahead_pop(cpi->lookahead, flush))) { |
3615 cm->show_frame = 1; | 2945 cm->show_frame = 1; |
3616 cm->intra_only = 0; | 2946 cm->intra_only = 0; |
3617 | 2947 |
3618 #if CONFIG_MULTIPLE_ARF | 2948 #if CONFIG_MULTIPLE_ARF |
3619 // Is this frame the ARF overlay. | 2949 // Is this frame the ARF overlay. |
3620 cpi->rc.is_src_frame_alt_ref = 0; | 2950 rc->is_src_frame_alt_ref = 0; |
3621 for (i = 0; i < cpi->arf_buffered; ++i) { | 2951 for (i = 0; i < cpi->arf_buffered; ++i) { |
3622 if (cpi->source == cpi->alt_ref_source[i]) { | 2952 if (cpi->source == cpi->alt_ref_source[i]) { |
3623 cpi->rc.is_src_frame_alt_ref = 1; | 2953 rc->is_src_frame_alt_ref = 1; |
3624 cpi->refresh_golden_frame = 1; | 2954 cpi->refresh_golden_frame = 1; |
3625 break; | 2955 break; |
3626 } | 2956 } |
3627 } | 2957 } |
3628 #else | 2958 #else |
3629 cpi->rc.is_src_frame_alt_ref = cpi->alt_ref_source | 2959 rc->is_src_frame_alt_ref = cpi->alt_ref_source && |
3630 && (cpi->source == cpi->alt_ref_source); | 2960 (cpi->source == cpi->alt_ref_source); |
3631 #endif | 2961 #endif |
3632 if (cpi->rc.is_src_frame_alt_ref) { | 2962 if (rc->is_src_frame_alt_ref) { |
3633 // Current frame is an ARF overlay frame. | 2963 // Current frame is an ARF overlay frame. |
3634 #if CONFIG_MULTIPLE_ARF | 2964 #if CONFIG_MULTIPLE_ARF |
3635 cpi->alt_ref_source[i] = NULL; | 2965 cpi->alt_ref_source[i] = NULL; |
3636 #else | 2966 #else |
3637 cpi->alt_ref_source = NULL; | 2967 cpi->alt_ref_source = NULL; |
3638 #endif | 2968 #endif |
3639 // Don't refresh the last buffer for an ARF overlay frame. It will | 2969 // Don't refresh the last buffer for an ARF overlay frame. It will |
3640 // become the GF so preserve last as an alternative prediction option. | 2970 // become the GF so preserve last as an alternative prediction option. |
3641 cpi->refresh_last_frame = 0; | 2971 cpi->refresh_last_frame = 0; |
3642 } | 2972 } |
3643 #if CONFIG_MULTIPLE_ARF | 2973 #if CONFIG_MULTIPLE_ARF |
3644 ++cpi->next_frame_in_order; | 2974 ++cpi->next_frame_in_order; |
3645 #endif | 2975 #endif |
3646 } | 2976 } |
3647 } | 2977 } |
3648 | 2978 |
3649 if (cpi->source) { | 2979 if (cpi->source) { |
3650 cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer | 2980 cpi->un_scaled_source = cpi->Source = force_src_buffer ? force_src_buffer |
3651 : &cpi->source->img; | 2981 : &cpi->source->img; |
| 2982 |
| 2983 if (cpi->last_source != NULL) { |
| 2984 cpi->unscaled_last_source = &cpi->last_source->img; |
| 2985 } else { |
| 2986 cpi->unscaled_last_source = NULL; |
| 2987 } |
| 2988 |
3652 *time_stamp = cpi->source->ts_start; | 2989 *time_stamp = cpi->source->ts_start; |
3653 *time_end = cpi->source->ts_end; | 2990 *time_end = cpi->source->ts_end; |
3654 *frame_flags = cpi->source->flags; | 2991 *frame_flags = cpi->source->flags; |
3655 | 2992 |
3656 #if CONFIG_MULTIPLE_ARF | 2993 #if CONFIG_MULTIPLE_ARF |
3657 if ((cm->frame_type != KEY_FRAME) && (cpi->pass == 2)) | 2994 if (cm->frame_type != KEY_FRAME && cpi->pass == 2) |
3658 cpi->rc.source_alt_ref_pending = is_next_frame_arf(cpi); | 2995 rc->source_alt_ref_pending = is_next_frame_arf(cpi); |
3659 #endif | 2996 #endif |
3660 } else { | 2997 } else { |
3661 *size = 0; | 2998 *size = 0; |
3662 if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done) { | 2999 if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done) { |
3663 vp9_end_first_pass(cpi); /* get last stats packet */ | 3000 vp9_end_first_pass(cpi); /* get last stats packet */ |
3664 cpi->twopass.first_pass_done = 1; | 3001 cpi->twopass.first_pass_done = 1; |
3665 } | 3002 } |
3666 return -1; | 3003 return -1; |
3667 } | 3004 } |
3668 | 3005 |
3669 if (cpi->source->ts_start < cpi->first_time_stamp_ever) { | 3006 if (cpi->source->ts_start < cpi->first_time_stamp_ever) { |
3670 cpi->first_time_stamp_ever = cpi->source->ts_start; | 3007 cpi->first_time_stamp_ever = cpi->source->ts_start; |
3671 cpi->last_end_time_stamp_seen = cpi->source->ts_start; | 3008 cpi->last_end_time_stamp_seen = cpi->source->ts_start; |
3672 } | 3009 } |
3673 | 3010 |
3674 // adjust frame rates based on timestamps given | 3011 // adjust frame rates based on timestamps given |
3675 if (cm->show_frame) { | 3012 if (cm->show_frame) { |
3676 adjust_frame_rate(cpi); | 3013 adjust_frame_rate(cpi); |
3677 } | 3014 } |
3678 | 3015 |
3679 if (cpi->svc.number_temporal_layers > 1 && | 3016 if (cpi->svc.number_temporal_layers > 1 && |
3680 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { | 3017 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { |
3681 update_layer_framerate(cpi); | 3018 vp9_update_temporal_layer_framerate(cpi); |
3682 restore_layer_context(cpi); | 3019 vp9_restore_layer_context(cpi); |
3683 } | 3020 } |
3684 | 3021 |
3685 // start with a 0 size frame | 3022 // start with a 0 size frame |
3686 *size = 0; | 3023 *size = 0; |
3687 | 3024 |
3688 // Clear down mmx registers | 3025 // Clear down mmx registers |
3689 vp9_clear_system_state(); | 3026 vp9_clear_system_state(); |
3690 | 3027 |
3691 /* find a free buffer for the new frame, releasing the reference previously | 3028 /* find a free buffer for the new frame, releasing the reference previously |
3692 * held. | 3029 * held. |
(...skipping 28 matching lines...) Expand all Loading... |
3721 ref_buf->idx = idx; | 3058 ref_buf->idx = idx; |
3722 vp9_setup_scale_factors_for_frame(&ref_buf->sf, | 3059 vp9_setup_scale_factors_for_frame(&ref_buf->sf, |
3723 buf->y_crop_width, buf->y_crop_height, | 3060 buf->y_crop_width, buf->y_crop_height, |
3724 cm->width, cm->height); | 3061 cm->width, cm->height); |
3725 | 3062 |
3726 if (vp9_is_scaled(&ref_buf->sf)) | 3063 if (vp9_is_scaled(&ref_buf->sf)) |
3727 vp9_extend_frame_borders(buf); | 3064 vp9_extend_frame_borders(buf); |
3728 } | 3065 } |
3729 | 3066 |
3730 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); | 3067 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
3731 xd->interp_kernel = vp9_get_interp_kernel( | |
3732 DEFAULT_INTERP_FILTER == SWITCHABLE ? EIGHTTAP : DEFAULT_INTERP_FILTER); | |
3733 | 3068 |
3734 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 3069 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
3735 vp9_vaq_init(); | 3070 vp9_vaq_init(); |
3736 } | 3071 } |
3737 | 3072 |
3738 if (cpi->use_svc) { | 3073 if (cpi->pass == 1 && |
| 3074 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { |
| 3075 Pass1Encode(cpi, size, dest, frame_flags); |
| 3076 } else if (cpi->pass == 2 && |
| 3077 (!cpi->use_svc || cpi->svc.number_temporal_layers == 1)) { |
| 3078 Pass2Encode(cpi, size, dest, frame_flags); |
| 3079 } else if (cpi->use_svc) { |
3739 SvcEncode(cpi, size, dest, frame_flags); | 3080 SvcEncode(cpi, size, dest, frame_flags); |
3740 } else if (cpi->pass == 1) { | |
3741 Pass1Encode(cpi, size, dest, frame_flags); | |
3742 } else if (cpi->pass == 2) { | |
3743 Pass2Encode(cpi, size, dest, frame_flags); | |
3744 } else { | 3081 } else { |
3745 // One pass encode | 3082 // One pass encode |
3746 Pass0Encode(cpi, size, dest, frame_flags); | 3083 Pass0Encode(cpi, size, dest, frame_flags); |
3747 } | 3084 } |
3748 | 3085 |
3749 if (cm->refresh_frame_context) | 3086 if (cm->refresh_frame_context) |
3750 cm->frame_contexts[cm->frame_context_idx] = cm->fc; | 3087 cm->frame_contexts[cm->frame_context_idx] = cm->fc; |
3751 | 3088 |
3752 // Frame was dropped, release scaled references. | 3089 // Frame was dropped, release scaled references. |
3753 if (*size == 0) { | 3090 if (*size == 0) { |
3754 release_scaled_references(cpi); | 3091 release_scaled_references(cpi); |
3755 } | 3092 } |
3756 | 3093 |
3757 if (*size > 0) { | 3094 if (*size > 0) { |
3758 cpi->droppable = !frame_is_reference(cpi); | 3095 cpi->droppable = !frame_is_reference(cpi); |
3759 } | 3096 } |
3760 | 3097 |
3761 // Save layer specific state. | 3098 // Save layer specific state. |
3762 if (cpi->svc.number_temporal_layers > 1 && | 3099 if ((cpi->svc.number_temporal_layers > 1 && |
3763 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { | 3100 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) || |
3764 save_layer_context(cpi); | 3101 (cpi->svc.number_spatial_layers > 1 && cpi->pass == 2)) { |
| 3102 vp9_save_layer_context(cpi); |
3765 } | 3103 } |
3766 | 3104 |
3767 vpx_usec_timer_mark(&cmptimer); | 3105 vpx_usec_timer_mark(&cmptimer); |
3768 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); | 3106 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); |
3769 | 3107 |
3770 if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) | 3108 if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) |
3771 generate_psnr_packet(cpi); | 3109 generate_psnr_packet(cpi); |
3772 | 3110 |
3773 #if CONFIG_INTERNAL_STATS | 3111 #if CONFIG_INTERNAL_STATS |
3774 | 3112 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3839 cpi->total_ssimg_v += v; | 3177 cpi->total_ssimg_v += v; |
3840 cpi->total_ssimg_all += frame_all; | 3178 cpi->total_ssimg_all += frame_all; |
3841 } | 3179 } |
3842 } | 3180 } |
3843 } | 3181 } |
3844 | 3182 |
3845 #endif | 3183 #endif |
3846 return 0; | 3184 return 0; |
3847 } | 3185 } |
3848 | 3186 |
3849 int vp9_get_preview_raw_frame(VP9_PTR comp, YV12_BUFFER_CONFIG *dest, | 3187 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, |
3850 vp9_ppflags_t *flags) { | 3188 vp9_ppflags_t *flags) { |
3851 VP9_COMP *cpi = (VP9_COMP *)comp; | |
3852 VP9_COMMON *cm = &cpi->common; | 3189 VP9_COMMON *cm = &cpi->common; |
3853 | 3190 |
3854 if (!cm->show_frame) { | 3191 if (!cm->show_frame) { |
3855 return -1; | 3192 return -1; |
3856 } else { | 3193 } else { |
3857 int ret; | 3194 int ret; |
3858 #if CONFIG_VP9_POSTPROC | 3195 #if CONFIG_VP9_POSTPROC |
3859 ret = vp9_post_proc_frame(cm, dest, flags); | 3196 ret = vp9_post_proc_frame(cm, dest, flags); |
3860 #else | 3197 #else |
3861 | 3198 |
3862 if (cm->frame_to_show) { | 3199 if (cm->frame_to_show) { |
3863 *dest = *cm->frame_to_show; | 3200 *dest = *cm->frame_to_show; |
3864 dest->y_width = cm->width; | 3201 dest->y_width = cm->width; |
3865 dest->y_height = cm->height; | 3202 dest->y_height = cm->height; |
3866 dest->uv_width = cm->width >> cm->subsampling_x; | 3203 dest->uv_width = cm->width >> cm->subsampling_x; |
3867 dest->uv_height = cm->height >> cm->subsampling_y; | 3204 dest->uv_height = cm->height >> cm->subsampling_y; |
3868 ret = 0; | 3205 ret = 0; |
3869 } else { | 3206 } else { |
3870 ret = -1; | 3207 ret = -1; |
3871 } | 3208 } |
3872 | 3209 |
3873 #endif // !CONFIG_VP9_POSTPROC | 3210 #endif // !CONFIG_VP9_POSTPROC |
3874 vp9_clear_system_state(); | 3211 vp9_clear_system_state(); |
3875 return ret; | 3212 return ret; |
3876 } | 3213 } |
3877 } | 3214 } |
3878 | 3215 |
3879 int vp9_set_roimap(VP9_PTR comp, unsigned char *map, unsigned int rows, | 3216 int vp9_set_roimap(VP9_COMP *cpi, unsigned char *map, unsigned int rows, |
3880 unsigned int cols, int delta_q[MAX_SEGMENTS], | 3217 unsigned int cols, int delta_q[MAX_SEGMENTS], |
3881 int delta_lf[MAX_SEGMENTS], | 3218 int delta_lf[MAX_SEGMENTS], |
3882 unsigned int threshold[MAX_SEGMENTS]) { | 3219 unsigned int threshold[MAX_SEGMENTS]) { |
3883 VP9_COMP *cpi = (VP9_COMP *) comp; | |
3884 signed char feature_data[SEG_LVL_MAX][MAX_SEGMENTS]; | 3220 signed char feature_data[SEG_LVL_MAX][MAX_SEGMENTS]; |
3885 struct segmentation *seg = &cpi->common.seg; | 3221 struct segmentation *seg = &cpi->common.seg; |
3886 int i; | 3222 int i; |
3887 | 3223 |
3888 if (cpi->common.mb_rows != rows || cpi->common.mb_cols != cols) | 3224 if (cpi->common.mb_rows != rows || cpi->common.mb_cols != cols) |
3889 return -1; | 3225 return -1; |
3890 | 3226 |
3891 if (!map) { | 3227 if (!map) { |
3892 vp9_disable_segmentation(seg); | 3228 vp9_disable_segmentation(seg); |
3893 return 0; | 3229 return 0; |
(...skipping 25 matching lines...) Expand all Loading... |
3919 vp9_disable_segfeature(seg, i, SEG_LVL_ALT_LF); | 3255 vp9_disable_segfeature(seg, i, SEG_LVL_ALT_LF); |
3920 } | 3256 } |
3921 | 3257 |
3922 // Initialize the feature data structure | 3258 // Initialize the feature data structure |
3923 // SEGMENT_DELTADATA 0, SEGMENT_ABSDATA 1 | 3259 // SEGMENT_DELTADATA 0, SEGMENT_ABSDATA 1 |
3924 vp9_set_segment_data(seg, &feature_data[0][0], SEGMENT_DELTADATA); | 3260 vp9_set_segment_data(seg, &feature_data[0][0], SEGMENT_DELTADATA); |
3925 | 3261 |
3926 return 0; | 3262 return 0; |
3927 } | 3263 } |
3928 | 3264 |
3929 int vp9_set_active_map(VP9_PTR comp, unsigned char *map, | 3265 int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, |
3930 unsigned int rows, unsigned int cols) { | 3266 unsigned int rows, unsigned int cols) { |
3931 VP9_COMP *cpi = (VP9_COMP *) comp; | |
3932 | |
3933 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { | 3267 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) { |
3934 if (map) { | 3268 if (map) { |
3935 vpx_memcpy(cpi->active_map, map, rows * cols); | 3269 vpx_memcpy(cpi->active_map, map, rows * cols); |
3936 cpi->active_map_enabled = 1; | 3270 cpi->active_map_enabled = 1; |
3937 } else { | 3271 } else { |
3938 cpi->active_map_enabled = 0; | 3272 cpi->active_map_enabled = 0; |
3939 } | 3273 } |
3940 | 3274 |
3941 return 0; | 3275 return 0; |
3942 } else { | 3276 } else { |
3943 // cpi->active_map_enabled = 0; | 3277 // cpi->active_map_enabled = 0; |
3944 return -1; | 3278 return -1; |
3945 } | 3279 } |
3946 } | 3280 } |
3947 | 3281 |
3948 int vp9_set_internal_size(VP9_PTR comp, | 3282 int vp9_set_internal_size(VP9_COMP *cpi, |
3949 VPX_SCALING horiz_mode, VPX_SCALING vert_mode) { | 3283 VPX_SCALING horiz_mode, VPX_SCALING vert_mode) { |
3950 VP9_COMP *cpi = (VP9_COMP *) comp; | |
3951 VP9_COMMON *cm = &cpi->common; | 3284 VP9_COMMON *cm = &cpi->common; |
3952 int hr = 0, hs = 0, vr = 0, vs = 0; | 3285 int hr = 0, hs = 0, vr = 0, vs = 0; |
3953 | 3286 |
3954 if (horiz_mode > ONETWO || vert_mode > ONETWO) | 3287 if (horiz_mode > ONETWO || vert_mode > ONETWO) |
3955 return -1; | 3288 return -1; |
3956 | 3289 |
3957 Scale2Ratio(horiz_mode, &hr, &hs); | 3290 Scale2Ratio(horiz_mode, &hr, &hs); |
3958 Scale2Ratio(vert_mode, &vr, &vs); | 3291 Scale2Ratio(vert_mode, &vr, &vs); |
3959 | 3292 |
3960 // always go to the next whole number | 3293 // always go to the next whole number |
3961 cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs; | 3294 cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
3962 cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs; | 3295 cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
3963 | 3296 |
3964 assert(cm->width <= cpi->initial_width); | 3297 assert(cm->width <= cpi->initial_width); |
3965 assert(cm->height <= cpi->initial_height); | 3298 assert(cm->height <= cpi->initial_height); |
3966 update_frame_size(cpi); | 3299 update_frame_size(cpi); |
3967 return 0; | 3300 return 0; |
3968 } | 3301 } |
3969 | 3302 |
3970 int vp9_set_size_literal(VP9_PTR comp, unsigned int width, | 3303 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, |
3971 unsigned int height) { | 3304 unsigned int height) { |
3972 VP9_COMP *cpi = (VP9_COMP *)comp; | |
3973 VP9_COMMON *cm = &cpi->common; | 3305 VP9_COMMON *cm = &cpi->common; |
3974 | 3306 |
3975 check_initial_width(cpi, 1, 1); | 3307 check_initial_width(cpi, 1, 1); |
3976 | 3308 |
3977 if (width) { | 3309 if (width) { |
3978 cm->width = width; | 3310 cm->width = width; |
3979 if (cm->width * 5 < cpi->initial_width) { | 3311 if (cm->width * 5 < cpi->initial_width) { |
3980 cm->width = cpi->initial_width / 5 + 1; | 3312 cm->width = cpi->initial_width / 5 + 1; |
3981 printf("Warning: Desired width too small, changed to %d\n", cm->width); | 3313 printf("Warning: Desired width too small, changed to %d\n", cm->width); |
3982 } | 3314 } |
(...skipping 14 matching lines...) Expand all Loading... |
3997 printf("Warning: Desired height too large, changed to %d\n", cm->height); | 3329 printf("Warning: Desired height too large, changed to %d\n", cm->height); |
3998 } | 3330 } |
3999 } | 3331 } |
4000 | 3332 |
4001 assert(cm->width <= cpi->initial_width); | 3333 assert(cm->width <= cpi->initial_width); |
4002 assert(cm->height <= cpi->initial_height); | 3334 assert(cm->height <= cpi->initial_height); |
4003 update_frame_size(cpi); | 3335 update_frame_size(cpi); |
4004 return 0; | 3336 return 0; |
4005 } | 3337 } |
4006 | 3338 |
4007 void vp9_set_svc(VP9_PTR comp, int use_svc) { | 3339 void vp9_set_svc(VP9_COMP *cpi, int use_svc) { |
4008 VP9_COMP *cpi = (VP9_COMP *)comp; | |
4009 cpi->use_svc = use_svc; | 3340 cpi->use_svc = use_svc; |
4010 return; | 3341 return; |
4011 } | 3342 } |
4012 | 3343 |
4013 int vp9_calc_ss_err(const YV12_BUFFER_CONFIG *source, | 3344 int vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b) { |
4014 const YV12_BUFFER_CONFIG *reference) { | 3345 assert(a->y_crop_width == b->y_crop_width); |
4015 int i, j; | 3346 assert(a->y_crop_height == b->y_crop_height); |
4016 int total = 0; | |
4017 | 3347 |
4018 const uint8_t *src = source->y_buffer; | 3348 return (int)get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, |
4019 const uint8_t *ref = reference->y_buffer; | 3349 a->y_crop_width, a->y_crop_height); |
4020 | |
4021 // Loop through the Y plane raw and reconstruction data summing | |
4022 // (square differences) | |
4023 for (i = 0; i < source->y_height; i += 16) { | |
4024 for (j = 0; j < source->y_width; j += 16) { | |
4025 unsigned int sse; | |
4026 total += vp9_mse16x16(src + j, source->y_stride, | |
4027 ref + j, reference->y_stride, &sse); | |
4028 } | |
4029 | |
4030 src += 16 * source->y_stride; | |
4031 ref += 16 * reference->y_stride; | |
4032 } | |
4033 | |
4034 return total; | |
4035 } | 3350 } |
4036 | 3351 |
4037 | 3352 |
4038 int vp9_get_quantizer(VP9_PTR c) { | 3353 int vp9_get_quantizer(VP9_COMP *cpi) { |
4039 return ((VP9_COMP *)c)->common.base_qindex; | 3354 return cpi->common.base_qindex; |
4040 } | 3355 } |
OLD | NEW |