Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_encoder.c

Issue 1015483002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_firstpass.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "vp9/encoder/vp9_segmentation.h" 45 #include "vp9/encoder/vp9_segmentation.h"
46 #include "vp9/encoder/vp9_speed_features.h" 46 #include "vp9/encoder/vp9_speed_features.h"
47 #if CONFIG_INTERNAL_STATS 47 #if CONFIG_INTERNAL_STATS
48 #include "vp9/encoder/vp9_ssim.h" 48 #include "vp9/encoder/vp9_ssim.h"
49 #endif 49 #endif
50 #include "vp9/encoder/vp9_temporal_filter.h" 50 #include "vp9/encoder/vp9_temporal_filter.h"
51 #include "vp9/encoder/vp9_resize.h" 51 #include "vp9/encoder/vp9_resize.h"
52 #include "vp9/encoder/vp9_svc_layercontext.h" 52 #include "vp9/encoder/vp9_svc_layercontext.h"
53 #include "vp9/encoder/vp9_skin_detection.h" 53 #include "vp9/encoder/vp9_skin_detection.h"
54 54
55 #define AM_SEGMENT_ID_INACTIVE 7
56 #define AM_SEGMENT_ID_ACTIVE 0
55 57
56 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ 58 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */
57 59
58 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv 60 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv
59 // for altref computation. 61 // for altref computation.
60 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision 62 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision
61 // mv. Choose a very high value for 63 // mv. Choose a very high value for
62 // now so that HIGH_PRECISION is always 64 // now so that HIGH_PRECISION is always
63 // chosen. 65 // chosen.
64 // #define OUTPUT_YUV_REC 66 // #define OUTPUT_YUV_REC
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 *hs = 2; 100 *hs = 2;
99 break; 101 break;
100 default: 102 default:
101 *hr = 1; 103 *hr = 1;
102 *hs = 1; 104 *hs = 1;
103 assert(0); 105 assert(0);
104 break; 106 break;
105 } 107 }
106 } 108 }
107 109
110 // Mark all inactive blocks as active. Other segmentation features may be set
111 // so memset cannot be used, instead only inactive blocks should be reset.
112 void vp9_suppress_active_map(VP9_COMP *cpi) {
113 unsigned char *const seg_map = cpi->segmentation_map;
114 int i;
115 if (cpi->active_map.enabled || cpi->active_map.update)
116 for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
117 if (seg_map[i] == AM_SEGMENT_ID_INACTIVE)
118 seg_map[i] = AM_SEGMENT_ID_ACTIVE;
119 }
120
121 void vp9_apply_active_map(VP9_COMP *cpi) {
122 struct segmentation *const seg = &cpi->common.seg;
123 unsigned char *const seg_map = cpi->segmentation_map;
124 const unsigned char *const active_map = cpi->active_map.map;
125 int i;
126
127 assert(AM_SEGMENT_ID_ACTIVE == CR_SEGMENT_ID_BASE);
128
129 if (cpi->active_map.update) {
130 if (cpi->active_map.enabled) {
131 for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i)
132 if (seg_map[i] == AM_SEGMENT_ID_ACTIVE) seg_map[i] = active_map[i];
133 vp9_enable_segmentation(seg);
134 vp9_enable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
135 } else {
136 vp9_disable_segfeature(seg, AM_SEGMENT_ID_INACTIVE, SEG_LVL_SKIP);
137 if (seg->enabled) {
138 seg->update_data = 1;
139 seg->update_map = 1;
140 }
141 }
142 cpi->active_map.update = 0;
143 }
144 }
145
146 int vp9_set_active_map(VP9_COMP* cpi,
147 unsigned char* new_map_16x16,
148 int rows,
149 int cols) {
150 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
151 unsigned char *const active_map_8x8 = cpi->active_map.map;
152 const int mi_rows = cpi->common.mi_rows;
153 const int mi_cols = cpi->common.mi_cols;
154 cpi->active_map.update = 1;
155 if (new_map_16x16) {
156 int r, c;
157 for (r = 0; r < mi_rows; ++r) {
158 for (c = 0; c < mi_cols; ++c) {
159 active_map_8x8[r * mi_cols + c] =
160 new_map_16x16[(r >> 1) * cols + (c >> 1)]
161 ? AM_SEGMENT_ID_ACTIVE
162 : AM_SEGMENT_ID_INACTIVE;
163 }
164 }
165 cpi->active_map.enabled = 1;
166 } else {
167 cpi->active_map.enabled = 0;
168 }
169 return 0;
170 } else {
171 return -1;
172 }
173 }
174
108 void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv) { 175 void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv) {
109 MACROBLOCK *const mb = &cpi->td.mb; 176 MACROBLOCK *const mb = &cpi->td.mb;
110 cpi->common.allow_high_precision_mv = allow_high_precision_mv; 177 cpi->common.allow_high_precision_mv = allow_high_precision_mv;
111 if (cpi->common.allow_high_precision_mv) { 178 if (cpi->common.allow_high_precision_mv) {
112 mb->mvcost = mb->nmvcost_hp; 179 mb->mvcost = mb->nmvcost_hp;
113 mb->mvsadcost = mb->nmvsadcost_hp; 180 mb->mvsadcost = mb->nmvsadcost_hp;
114 } else { 181 } else {
115 mb->mvcost = mb->nmvcost; 182 mb->mvcost = mb->nmvcost;
116 mb->mvsadcost = mb->nmvsadcost; 183 mb->mvsadcost = mb->nmvsadcost;
117 } 184 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 cpi->nmvsadcosts[1] = NULL; 293 cpi->nmvsadcosts[1] = NULL;
227 294
228 vpx_free(cpi->nmvsadcosts_hp[0]); 295 vpx_free(cpi->nmvsadcosts_hp[0]);
229 vpx_free(cpi->nmvsadcosts_hp[1]); 296 vpx_free(cpi->nmvsadcosts_hp[1]);
230 cpi->nmvsadcosts_hp[0] = NULL; 297 cpi->nmvsadcosts_hp[0] = NULL;
231 cpi->nmvsadcosts_hp[1] = NULL; 298 cpi->nmvsadcosts_hp[1] = NULL;
232 299
233 vp9_cyclic_refresh_free(cpi->cyclic_refresh); 300 vp9_cyclic_refresh_free(cpi->cyclic_refresh);
234 cpi->cyclic_refresh = NULL; 301 cpi->cyclic_refresh = NULL;
235 302
303 vpx_free(cpi->active_map.map);
304 cpi->active_map.map = NULL;
305
236 vp9_free_ref_frame_buffers(cm); 306 vp9_free_ref_frame_buffers(cm);
237 vp9_free_context_buffers(cm); 307 vp9_free_context_buffers(cm);
238 308
239 vp9_free_frame_buffer(&cpi->last_frame_uf); 309 vp9_free_frame_buffer(&cpi->last_frame_uf);
240 vp9_free_frame_buffer(&cpi->scaled_source); 310 vp9_free_frame_buffer(&cpi->scaled_source);
241 vp9_free_frame_buffer(&cpi->scaled_last_source); 311 vp9_free_frame_buffer(&cpi->scaled_last_source);
242 vp9_free_frame_buffer(&cpi->alt_ref_buffer); 312 vp9_free_frame_buffer(&cpi->alt_ref_buffer);
243 vp9_lookahead_destroy(cpi->lookahead); 313 vp9_lookahead_destroy(cpi->lookahead);
244 314
245 vpx_free(cpi->tile_tok[0][0]); 315 vpx_free(cpi->tile_tok[0][0]);
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 cpi->use_svc = 0; 1492 cpi->use_svc = 0;
1423 cpi->common.buffer_pool = pool; 1493 cpi->common.buffer_pool = pool;
1424 1494
1425 init_config(cpi, oxcf); 1495 init_config(cpi, oxcf);
1426 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); 1496 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
1427 1497
1428 cm->current_video_frame = 0; 1498 cm->current_video_frame = 0;
1429 cpi->partition_search_skippable_frame = 0; 1499 cpi->partition_search_skippable_frame = 0;
1430 cpi->tile_data = NULL; 1500 cpi->tile_data = NULL;
1431 1501
1502 // TODO(aconverse): Realloc these tables on frame resize
1432 // Create the encoder segmentation map and set all entries to 0 1503 // Create the encoder segmentation map and set all entries to 0
1433 CHECK_MEM_ERROR(cm, cpi->segmentation_map, 1504 CHECK_MEM_ERROR(cm, cpi->segmentation_map,
1434 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); 1505 vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
1435 1506
1436 // Create a map used for cyclic background refresh. 1507 // Create a map used for cyclic background refresh.
1437 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh, 1508 CHECK_MEM_ERROR(cm, cpi->cyclic_refresh,
1438 vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols)); 1509 vp9_cyclic_refresh_alloc(cm->mi_rows, cm->mi_cols));
1439 1510
1511 CHECK_MEM_ERROR(cm, cpi->active_map.map,
1512 vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
1513
1440 // And a place holder structure is the coding context 1514 // And a place holder structure is the coding context
1441 // for use if we want to save and restore it 1515 // for use if we want to save and restore it
1442 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, 1516 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy,
1443 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); 1517 vpx_calloc(cm->mi_rows * cm->mi_cols, 1));
1444 1518
1445 CHECK_MEM_ERROR(cm, cpi->nmvcosts[0], 1519 CHECK_MEM_ERROR(cm, cpi->nmvcosts[0],
1446 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[0]))); 1520 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[0])));
1447 CHECK_MEM_ERROR(cm, cpi->nmvcosts[1], 1521 CHECK_MEM_ERROR(cm, cpi->nmvcosts[1],
1448 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[1]))); 1522 vpx_calloc(MV_VALS, sizeof(*cpi->nmvcosts[1])));
1449 CHECK_MEM_ERROR(cm, cpi->nmvcosts_hp[0], 1523 CHECK_MEM_ERROR(cm, cpi->nmvcosts_hp[0],
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 } 2898 }
2825 2899
2826 set_size_independent_vars(cpi); 2900 set_size_independent_vars(cpi);
2827 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); 2901 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index);
2828 2902
2829 vp9_set_quantizer(cm, q); 2903 vp9_set_quantizer(cm, q);
2830 vp9_set_vbp_thresholds(cpi, q); 2904 vp9_set_vbp_thresholds(cpi, q);
2831 2905
2832 setup_frame(cpi); 2906 setup_frame(cpi);
2833 2907
2908 vp9_suppress_active_map(cpi);
2834 // Variance adaptive and in frame q adjustment experiments are mutually 2909 // Variance adaptive and in frame q adjustment experiments are mutually
2835 // exclusive. 2910 // exclusive.
2836 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { 2911 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
2837 vp9_vaq_frame_setup(cpi); 2912 vp9_vaq_frame_setup(cpi);
2838 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { 2913 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
2839 vp9_setup_in_frame_q_adj(cpi); 2914 vp9_setup_in_frame_q_adj(cpi);
2840 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { 2915 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) {
2841 vp9_cyclic_refresh_setup(cpi); 2916 vp9_cyclic_refresh_setup(cpi);
2842 } 2917 }
2918 vp9_apply_active_map(cpi);
2919
2843 // transform / motion compensation build reconstruction frame 2920 // transform / motion compensation build reconstruction frame
2844 vp9_encode_frame(cpi); 2921 vp9_encode_frame(cpi);
2845 2922
2923 // Update some stats from cyclic refresh, and check if we should not update
2924 // golden reference, for non-SVC 1 pass CBR.
2925 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ &&
2926 cm->frame_type != KEY_FRAME &&
2927 !cpi->use_svc &&
2928 (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR))
2929 vp9_cyclic_refresh_check_golden_update(cpi);
2930
2846 // Update the skip mb flag probabilities based on the distribution 2931 // Update the skip mb flag probabilities based on the distribution
2847 // seen in the last encoder iteration. 2932 // seen in the last encoder iteration.
2848 // update_base_skip_probs(cpi); 2933 // update_base_skip_probs(cpi);
2849 vp9_clear_system_state(); 2934 vp9_clear_system_state();
2850 } 2935 }
2851 2936
2852 static void encode_with_recode_loop(VP9_COMP *cpi, 2937 static void encode_with_recode_loop(VP9_COMP *cpi,
2853 size_t *size, 2938 size_t *size,
2854 uint8_t *dest) { 2939 uint8_t *dest) {
2855 VP9_COMMON *const cm = &cpi->common; 2940 VP9_COMMON *const cm = &cpi->common;
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
3213 static void encode_frame_to_data_rate(VP9_COMP *cpi, 3298 static void encode_frame_to_data_rate(VP9_COMP *cpi,
3214 size_t *size, 3299 size_t *size,
3215 uint8_t *dest, 3300 uint8_t *dest,
3216 unsigned int *frame_flags) { 3301 unsigned int *frame_flags) {
3217 VP9_COMMON *const cm = &cpi->common; 3302 VP9_COMMON *const cm = &cpi->common;
3218 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 3303 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
3219 struct segmentation *const seg = &cm->seg; 3304 struct segmentation *const seg = &cm->seg;
3220 TX_SIZE t; 3305 TX_SIZE t;
3221 3306
3222 set_ext_overrides(cpi); 3307 set_ext_overrides(cpi);
3223
3224 vp9_clear_system_state(); 3308 vp9_clear_system_state();
3225 3309
3226 // Set the arf sign bias for this frame. 3310 // Set the arf sign bias for this frame.
3227 set_arf_sign_bias(cpi); 3311 set_arf_sign_bias(cpi);
3228 3312
3229 // Set default state for segment based loop filter update flags. 3313 // Set default state for segment based loop filter update flags.
3230 cm->lf.mode_ref_delta_update = 0; 3314 cm->lf.mode_ref_delta_update = 0;
3231 3315
3232 if (cpi->oxcf.pass == 2 && 3316 if (cpi->oxcf.pass == 2 &&
3233 cpi->sf.adaptive_interp_filter_search) 3317 cpi->sf.adaptive_interp_filter_search)
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
4072 ret = 0; 4156 ret = 0;
4073 } else { 4157 } else {
4074 ret = -1; 4158 ret = -1;
4075 } 4159 }
4076 #endif // !CONFIG_VP9_POSTPROC 4160 #endif // !CONFIG_VP9_POSTPROC
4077 vp9_clear_system_state(); 4161 vp9_clear_system_state();
4078 return ret; 4162 return ret;
4079 } 4163 }
4080 } 4164 }
4081 4165
4082 int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols) {
4083 if (rows == cpi->common.mb_rows && cols == cpi->common.mb_cols) {
4084 const int mi_rows = cpi->common.mi_rows;
4085 const int mi_cols = cpi->common.mi_cols;
4086 if (map) {
4087 int r, c;
4088 for (r = 0; r < mi_rows; r++) {
4089 for (c = 0; c < mi_cols; c++) {
4090 cpi->segmentation_map[r * mi_cols + c] =
4091 !map[(r >> 1) * cols + (c >> 1)];
4092 }
4093 }
4094 vp9_enable_segfeature(&cpi->common.seg, 1, SEG_LVL_SKIP);
4095 vp9_enable_segmentation(&cpi->common.seg);
4096 } else {
4097 vp9_disable_segmentation(&cpi->common.seg);
4098 }
4099 return 0;
4100 } else {
4101 return -1;
4102 }
4103 }
4104
4105 int vp9_set_internal_size(VP9_COMP *cpi, 4166 int vp9_set_internal_size(VP9_COMP *cpi,
4106 VPX_SCALING horiz_mode, VPX_SCALING vert_mode) { 4167 VPX_SCALING horiz_mode, VPX_SCALING vert_mode) {
4107 VP9_COMMON *cm = &cpi->common; 4168 VP9_COMMON *cm = &cpi->common;
4108 int hr = 0, hs = 0, vr = 0, vs = 0; 4169 int hr = 0, hs = 0, vr = 0, vs = 0;
4109 4170
4110 if (horiz_mode > ONETWO || vert_mode > ONETWO) 4171 if (horiz_mode > ONETWO || vert_mode > ONETWO)
4111 return -1; 4172 return -1;
4112 4173
4113 Scale2Ratio(horiz_mode, &hr, &hs); 4174 Scale2Ratio(horiz_mode, &hr, &hs);
4114 Scale2Ratio(vert_mode, &vr, &vs); 4175 Scale2Ratio(vert_mode, &vr, &vs);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
4222 if (flags & VP8_EFLAG_NO_UPD_ARF) 4283 if (flags & VP8_EFLAG_NO_UPD_ARF)
4223 upd ^= VP9_ALT_FLAG; 4284 upd ^= VP9_ALT_FLAG;
4224 4285
4225 vp9_update_reference(cpi, upd); 4286 vp9_update_reference(cpi, upd);
4226 } 4287 }
4227 4288
4228 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { 4289 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) {
4229 vp9_update_entropy(cpi, 0); 4290 vp9_update_entropy(cpi, 0);
4230 } 4291 }
4231 } 4292 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_firstpass.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698