Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include <limits.h> |
michael@0 | 12 | |
michael@0 | 13 | #include "vpx_mem/vpx_mem.h" |
michael@0 | 14 | #include "vp9/encoder/vp9_encodeintra.h" |
michael@0 | 15 | #include "vp9/encoder/vp9_rdopt.h" |
michael@0 | 16 | #include "vp9/encoder/vp9_segmentation.h" |
michael@0 | 17 | #include "vp9/encoder/vp9_mcomp.h" |
michael@0 | 18 | #include "vp9/common/vp9_blockd.h" |
michael@0 | 19 | #include "vp9/common/vp9_reconinter.h" |
michael@0 | 20 | #include "vp9/common/vp9_reconintra.h" |
michael@0 | 21 | #include "vp9/common/vp9_systemdependent.h" |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | |
michael@0 | 25 | static unsigned int do_16x16_motion_iteration(VP9_COMP *cpi, |
michael@0 | 26 | int_mv *ref_mv, |
michael@0 | 27 | int_mv *dst_mv, |
michael@0 | 28 | int mb_row, |
michael@0 | 29 | int mb_col) { |
michael@0 | 30 | MACROBLOCK *const x = &cpi->mb; |
michael@0 | 31 | MACROBLOCKD *const xd = &x->e_mbd; |
michael@0 | 32 | vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[BLOCK_16X16]; |
michael@0 | 33 | unsigned int best_err; |
michael@0 | 34 | |
michael@0 | 35 | const int tmp_col_min = x->mv_col_min; |
michael@0 | 36 | const int tmp_col_max = x->mv_col_max; |
michael@0 | 37 | const int tmp_row_min = x->mv_row_min; |
michael@0 | 38 | const int tmp_row_max = x->mv_row_max; |
michael@0 | 39 | int_mv ref_full; |
michael@0 | 40 | |
michael@0 | 41 | // Further step/diamond searches as necessary |
michael@0 | 42 | int step_param = cpi->sf.reduce_first_step_size + |
michael@0 | 43 | (cpi->speed < 8 ? (cpi->speed > 5 ? 1 : 0) : 2); |
michael@0 | 44 | step_param = MIN(step_param, (cpi->sf.max_step_search_steps - 2)); |
michael@0 | 45 | |
michael@0 | 46 | vp9_clamp_mv_min_max(x, &ref_mv->as_mv); |
michael@0 | 47 | |
michael@0 | 48 | ref_full.as_mv.col = ref_mv->as_mv.col >> 3; |
michael@0 | 49 | ref_full.as_mv.row = ref_mv->as_mv.row >> 3; |
michael@0 | 50 | |
michael@0 | 51 | /*cpi->sf.search_method == HEX*/ |
michael@0 | 52 | best_err = vp9_hex_search(x, &ref_full.as_mv, step_param, x->errorperbit, |
michael@0 | 53 | 0, &v_fn_ptr, |
michael@0 | 54 | 0, &ref_mv->as_mv, &dst_mv->as_mv); |
michael@0 | 55 | |
michael@0 | 56 | // Try sub-pixel MC |
michael@0 | 57 | // if (bestsme > error_thresh && bestsme < INT_MAX) |
michael@0 | 58 | { |
michael@0 | 59 | int distortion; |
michael@0 | 60 | unsigned int sse; |
michael@0 | 61 | best_err = cpi->find_fractional_mv_step( |
michael@0 | 62 | x, |
michael@0 | 63 | &dst_mv->as_mv, &ref_mv->as_mv, |
michael@0 | 64 | cpi->common.allow_high_precision_mv, |
michael@0 | 65 | x->errorperbit, &v_fn_ptr, |
michael@0 | 66 | 0, cpi->sf.subpel_iters_per_step, NULL, NULL, |
michael@0 | 67 | & distortion, &sse); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | vp9_set_mbmode_and_mvs(x, NEWMV, dst_mv); |
michael@0 | 71 | vp9_build_inter_predictors_sby(xd, mb_row, mb_col, BLOCK_16X16); |
michael@0 | 72 | best_err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride, |
michael@0 | 73 | xd->plane[0].dst.buf, xd->plane[0].dst.stride, |
michael@0 | 74 | INT_MAX); |
michael@0 | 75 | |
michael@0 | 76 | /* restore UMV window */ |
michael@0 | 77 | x->mv_col_min = tmp_col_min; |
michael@0 | 78 | x->mv_col_max = tmp_col_max; |
michael@0 | 79 | x->mv_row_min = tmp_row_min; |
michael@0 | 80 | x->mv_row_max = tmp_row_max; |
michael@0 | 81 | |
michael@0 | 82 | return best_err; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | static int do_16x16_motion_search(VP9_COMP *cpi, int_mv *ref_mv, int_mv *dst_mv, |
michael@0 | 86 | int mb_row, int mb_col) { |
michael@0 | 87 | MACROBLOCK *const x = &cpi->mb; |
michael@0 | 88 | MACROBLOCKD *const xd = &x->e_mbd; |
michael@0 | 89 | unsigned int err, tmp_err; |
michael@0 | 90 | int_mv tmp_mv; |
michael@0 | 91 | |
michael@0 | 92 | // Try zero MV first |
michael@0 | 93 | // FIXME should really use something like near/nearest MV and/or MV prediction |
michael@0 | 94 | err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride, |
michael@0 | 95 | xd->plane[0].pre[0].buf, xd->plane[0].pre[0].stride, |
michael@0 | 96 | INT_MAX); |
michael@0 | 97 | dst_mv->as_int = 0; |
michael@0 | 98 | |
michael@0 | 99 | // Test last reference frame using the previous best mv as the |
michael@0 | 100 | // starting point (best reference) for the search |
michael@0 | 101 | tmp_err = do_16x16_motion_iteration(cpi, ref_mv, &tmp_mv, mb_row, mb_col); |
michael@0 | 102 | if (tmp_err < err) { |
michael@0 | 103 | err = tmp_err; |
michael@0 | 104 | dst_mv->as_int = tmp_mv.as_int; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | // If the current best reference mv is not centered on 0,0 then do a 0,0 |
michael@0 | 108 | // based search as well. |
michael@0 | 109 | if (ref_mv->as_int) { |
michael@0 | 110 | unsigned int tmp_err; |
michael@0 | 111 | int_mv zero_ref_mv, tmp_mv; |
michael@0 | 112 | |
michael@0 | 113 | zero_ref_mv.as_int = 0; |
michael@0 | 114 | tmp_err = do_16x16_motion_iteration(cpi, &zero_ref_mv, &tmp_mv, |
michael@0 | 115 | mb_row, mb_col); |
michael@0 | 116 | if (tmp_err < err) { |
michael@0 | 117 | dst_mv->as_int = tmp_mv.as_int; |
michael@0 | 118 | err = tmp_err; |
michael@0 | 119 | } |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | return err; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | static int do_16x16_zerozero_search(VP9_COMP *cpi, int_mv *dst_mv) { |
michael@0 | 126 | MACROBLOCK *const x = &cpi->mb; |
michael@0 | 127 | MACROBLOCKD *const xd = &x->e_mbd; |
michael@0 | 128 | unsigned int err; |
michael@0 | 129 | |
michael@0 | 130 | // Try zero MV first |
michael@0 | 131 | // FIXME should really use something like near/nearest MV and/or MV prediction |
michael@0 | 132 | err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride, |
michael@0 | 133 | xd->plane[0].pre[0].buf, xd->plane[0].pre[0].stride, |
michael@0 | 134 | INT_MAX); |
michael@0 | 135 | |
michael@0 | 136 | dst_mv->as_int = 0; |
michael@0 | 137 | |
michael@0 | 138 | return err; |
michael@0 | 139 | } |
michael@0 | 140 | static int find_best_16x16_intra(VP9_COMP *cpi, |
michael@0 | 141 | int mb_y_offset, |
michael@0 | 142 | MB_PREDICTION_MODE *pbest_mode) { |
michael@0 | 143 | MACROBLOCK *const x = &cpi->mb; |
michael@0 | 144 | MACROBLOCKD *const xd = &x->e_mbd; |
michael@0 | 145 | MB_PREDICTION_MODE best_mode = -1, mode; |
michael@0 | 146 | unsigned int best_err = INT_MAX; |
michael@0 | 147 | |
michael@0 | 148 | // calculate SATD for each intra prediction mode; |
michael@0 | 149 | // we're intentionally not doing 4x4, we just want a rough estimate |
michael@0 | 150 | for (mode = DC_PRED; mode <= TM_PRED; mode++) { |
michael@0 | 151 | unsigned int err; |
michael@0 | 152 | |
michael@0 | 153 | xd->mi_8x8[0]->mbmi.mode = mode; |
michael@0 | 154 | vp9_predict_intra_block(xd, 0, 2, TX_16X16, mode, |
michael@0 | 155 | x->plane[0].src.buf, x->plane[0].src.stride, |
michael@0 | 156 | xd->plane[0].dst.buf, xd->plane[0].dst.stride); |
michael@0 | 157 | err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride, |
michael@0 | 158 | xd->plane[0].dst.buf, xd->plane[0].dst.stride, best_err); |
michael@0 | 159 | |
michael@0 | 160 | // find best |
michael@0 | 161 | if (err < best_err) { |
michael@0 | 162 | best_err = err; |
michael@0 | 163 | best_mode = mode; |
michael@0 | 164 | } |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | if (pbest_mode) |
michael@0 | 168 | *pbest_mode = best_mode; |
michael@0 | 169 | |
michael@0 | 170 | return best_err; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | static void update_mbgraph_mb_stats |
michael@0 | 174 | ( |
michael@0 | 175 | VP9_COMP *cpi, |
michael@0 | 176 | MBGRAPH_MB_STATS *stats, |
michael@0 | 177 | YV12_BUFFER_CONFIG *buf, |
michael@0 | 178 | int mb_y_offset, |
michael@0 | 179 | YV12_BUFFER_CONFIG *golden_ref, |
michael@0 | 180 | int_mv *prev_golden_ref_mv, |
michael@0 | 181 | int gld_y_offset, |
michael@0 | 182 | YV12_BUFFER_CONFIG *alt_ref, |
michael@0 | 183 | int_mv *prev_alt_ref_mv, |
michael@0 | 184 | int arf_y_offset, |
michael@0 | 185 | int mb_row, |
michael@0 | 186 | int mb_col |
michael@0 | 187 | ) { |
michael@0 | 188 | MACROBLOCK *const x = &cpi->mb; |
michael@0 | 189 | MACROBLOCKD *const xd = &x->e_mbd; |
michael@0 | 190 | int intra_error; |
michael@0 | 191 | VP9_COMMON *cm = &cpi->common; |
michael@0 | 192 | |
michael@0 | 193 | // FIXME in practice we're completely ignoring chroma here |
michael@0 | 194 | x->plane[0].src.buf = buf->y_buffer + mb_y_offset; |
michael@0 | 195 | x->plane[0].src.stride = buf->y_stride; |
michael@0 | 196 | |
michael@0 | 197 | xd->plane[0].dst.buf = get_frame_new_buffer(cm)->y_buffer + mb_y_offset; |
michael@0 | 198 | xd->plane[0].dst.stride = get_frame_new_buffer(cm)->y_stride; |
michael@0 | 199 | |
michael@0 | 200 | // do intra 16x16 prediction |
michael@0 | 201 | intra_error = find_best_16x16_intra(cpi, mb_y_offset, |
michael@0 | 202 | &stats->ref[INTRA_FRAME].m.mode); |
michael@0 | 203 | if (intra_error <= 0) |
michael@0 | 204 | intra_error = 1; |
michael@0 | 205 | stats->ref[INTRA_FRAME].err = intra_error; |
michael@0 | 206 | |
michael@0 | 207 | // Golden frame MV search, if it exists and is different than last frame |
michael@0 | 208 | if (golden_ref) { |
michael@0 | 209 | int g_motion_error; |
michael@0 | 210 | xd->plane[0].pre[0].buf = golden_ref->y_buffer + mb_y_offset; |
michael@0 | 211 | xd->plane[0].pre[0].stride = golden_ref->y_stride; |
michael@0 | 212 | g_motion_error = do_16x16_motion_search(cpi, |
michael@0 | 213 | prev_golden_ref_mv, |
michael@0 | 214 | &stats->ref[GOLDEN_FRAME].m.mv, |
michael@0 | 215 | mb_row, mb_col); |
michael@0 | 216 | stats->ref[GOLDEN_FRAME].err = g_motion_error; |
michael@0 | 217 | } else { |
michael@0 | 218 | stats->ref[GOLDEN_FRAME].err = INT_MAX; |
michael@0 | 219 | stats->ref[GOLDEN_FRAME].m.mv.as_int = 0; |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | // Do an Alt-ref frame MV search, if it exists and is different than |
michael@0 | 223 | // last/golden frame. |
michael@0 | 224 | if (alt_ref) { |
michael@0 | 225 | int a_motion_error; |
michael@0 | 226 | xd->plane[0].pre[0].buf = alt_ref->y_buffer + mb_y_offset; |
michael@0 | 227 | xd->plane[0].pre[0].stride = alt_ref->y_stride; |
michael@0 | 228 | a_motion_error = do_16x16_zerozero_search(cpi, |
michael@0 | 229 | &stats->ref[ALTREF_FRAME].m.mv); |
michael@0 | 230 | |
michael@0 | 231 | stats->ref[ALTREF_FRAME].err = a_motion_error; |
michael@0 | 232 | } else { |
michael@0 | 233 | stats->ref[ALTREF_FRAME].err = INT_MAX; |
michael@0 | 234 | stats->ref[ALTREF_FRAME].m.mv.as_int = 0; |
michael@0 | 235 | } |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | static void update_mbgraph_frame_stats(VP9_COMP *cpi, |
michael@0 | 239 | MBGRAPH_FRAME_STATS *stats, |
michael@0 | 240 | YV12_BUFFER_CONFIG *buf, |
michael@0 | 241 | YV12_BUFFER_CONFIG *golden_ref, |
michael@0 | 242 | YV12_BUFFER_CONFIG *alt_ref) { |
michael@0 | 243 | MACROBLOCK *const x = &cpi->mb; |
michael@0 | 244 | MACROBLOCKD *const xd = &x->e_mbd; |
michael@0 | 245 | VP9_COMMON *const cm = &cpi->common; |
michael@0 | 246 | |
michael@0 | 247 | int mb_col, mb_row, offset = 0; |
michael@0 | 248 | int mb_y_offset = 0, arf_y_offset = 0, gld_y_offset = 0; |
michael@0 | 249 | int_mv arf_top_mv, gld_top_mv; |
michael@0 | 250 | MODE_INFO mi_local = { { 0 } }; |
michael@0 | 251 | |
michael@0 | 252 | // Set up limit values for motion vectors to prevent them extending outside |
michael@0 | 253 | // the UMV borders. |
michael@0 | 254 | arf_top_mv.as_int = 0; |
michael@0 | 255 | gld_top_mv.as_int = 0; |
michael@0 | 256 | x->mv_row_min = -BORDER_MV_PIXELS_B16; |
michael@0 | 257 | x->mv_row_max = (cm->mb_rows - 1) * 8 + BORDER_MV_PIXELS_B16; |
michael@0 | 258 | xd->up_available = 0; |
michael@0 | 259 | xd->plane[0].dst.stride = buf->y_stride; |
michael@0 | 260 | xd->plane[0].pre[0].stride = buf->y_stride; |
michael@0 | 261 | xd->plane[1].dst.stride = buf->uv_stride; |
michael@0 | 262 | xd->mi_8x8[0] = &mi_local; |
michael@0 | 263 | mi_local.mbmi.sb_type = BLOCK_16X16; |
michael@0 | 264 | mi_local.mbmi.ref_frame[0] = LAST_FRAME; |
michael@0 | 265 | mi_local.mbmi.ref_frame[1] = NONE; |
michael@0 | 266 | |
michael@0 | 267 | for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) { |
michael@0 | 268 | int_mv arf_left_mv, gld_left_mv; |
michael@0 | 269 | int mb_y_in_offset = mb_y_offset; |
michael@0 | 270 | int arf_y_in_offset = arf_y_offset; |
michael@0 | 271 | int gld_y_in_offset = gld_y_offset; |
michael@0 | 272 | |
michael@0 | 273 | // Set up limit values for motion vectors to prevent them extending outside |
michael@0 | 274 | // the UMV borders. |
michael@0 | 275 | arf_left_mv.as_int = arf_top_mv.as_int; |
michael@0 | 276 | gld_left_mv.as_int = gld_top_mv.as_int; |
michael@0 | 277 | x->mv_col_min = -BORDER_MV_PIXELS_B16; |
michael@0 | 278 | x->mv_col_max = (cm->mb_cols - 1) * 8 + BORDER_MV_PIXELS_B16; |
michael@0 | 279 | xd->left_available = 0; |
michael@0 | 280 | |
michael@0 | 281 | for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { |
michael@0 | 282 | MBGRAPH_MB_STATS *mb_stats = &stats->mb_stats[offset + mb_col]; |
michael@0 | 283 | |
michael@0 | 284 | update_mbgraph_mb_stats(cpi, mb_stats, buf, mb_y_in_offset, |
michael@0 | 285 | golden_ref, &gld_left_mv, gld_y_in_offset, |
michael@0 | 286 | alt_ref, &arf_left_mv, arf_y_in_offset, |
michael@0 | 287 | mb_row, mb_col); |
michael@0 | 288 | arf_left_mv.as_int = mb_stats->ref[ALTREF_FRAME].m.mv.as_int; |
michael@0 | 289 | gld_left_mv.as_int = mb_stats->ref[GOLDEN_FRAME].m.mv.as_int; |
michael@0 | 290 | if (mb_col == 0) { |
michael@0 | 291 | arf_top_mv.as_int = arf_left_mv.as_int; |
michael@0 | 292 | gld_top_mv.as_int = gld_left_mv.as_int; |
michael@0 | 293 | } |
michael@0 | 294 | xd->left_available = 1; |
michael@0 | 295 | mb_y_in_offset += 16; |
michael@0 | 296 | gld_y_in_offset += 16; |
michael@0 | 297 | arf_y_in_offset += 16; |
michael@0 | 298 | x->mv_col_min -= 16; |
michael@0 | 299 | x->mv_col_max -= 16; |
michael@0 | 300 | } |
michael@0 | 301 | xd->up_available = 1; |
michael@0 | 302 | mb_y_offset += buf->y_stride * 16; |
michael@0 | 303 | gld_y_offset += golden_ref->y_stride * 16; |
michael@0 | 304 | if (alt_ref) |
michael@0 | 305 | arf_y_offset += alt_ref->y_stride * 16; |
michael@0 | 306 | x->mv_row_min -= 16; |
michael@0 | 307 | x->mv_row_max -= 16; |
michael@0 | 308 | offset += cm->mb_cols; |
michael@0 | 309 | } |
michael@0 | 310 | } |
michael@0 | 311 | |
michael@0 | 312 | // void separate_arf_mbs_byzz |
michael@0 | 313 | static void separate_arf_mbs(VP9_COMP *cpi) { |
michael@0 | 314 | VP9_COMMON *const cm = &cpi->common; |
michael@0 | 315 | int mb_col, mb_row, offset, i; |
michael@0 | 316 | int mi_row, mi_col; |
michael@0 | 317 | int ncnt[4] = { 0 }; |
michael@0 | 318 | int n_frames = cpi->mbgraph_n_frames; |
michael@0 | 319 | |
michael@0 | 320 | int *arf_not_zz; |
michael@0 | 321 | |
michael@0 | 322 | CHECK_MEM_ERROR(cm, arf_not_zz, |
michael@0 | 323 | vpx_calloc(cm->mb_rows * cm->mb_cols * sizeof(*arf_not_zz), |
michael@0 | 324 | 1)); |
michael@0 | 325 | |
michael@0 | 326 | // We are not interested in results beyond the alt ref itself. |
michael@0 | 327 | if (n_frames > cpi->frames_till_gf_update_due) |
michael@0 | 328 | n_frames = cpi->frames_till_gf_update_due; |
michael@0 | 329 | |
michael@0 | 330 | // defer cost to reference frames |
michael@0 | 331 | for (i = n_frames - 1; i >= 0; i--) { |
michael@0 | 332 | MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i]; |
michael@0 | 333 | |
michael@0 | 334 | for (offset = 0, mb_row = 0; mb_row < cm->mb_rows; |
michael@0 | 335 | offset += cm->mb_cols, mb_row++) { |
michael@0 | 336 | for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { |
michael@0 | 337 | MBGRAPH_MB_STATS *mb_stats = &frame_stats->mb_stats[offset + mb_col]; |
michael@0 | 338 | |
michael@0 | 339 | int altref_err = mb_stats->ref[ALTREF_FRAME].err; |
michael@0 | 340 | int intra_err = mb_stats->ref[INTRA_FRAME ].err; |
michael@0 | 341 | int golden_err = mb_stats->ref[GOLDEN_FRAME].err; |
michael@0 | 342 | |
michael@0 | 343 | // Test for altref vs intra and gf and that its mv was 0,0. |
michael@0 | 344 | if (altref_err > 1000 || |
michael@0 | 345 | altref_err > intra_err || |
michael@0 | 346 | altref_err > golden_err) { |
michael@0 | 347 | arf_not_zz[offset + mb_col]++; |
michael@0 | 348 | } |
michael@0 | 349 | } |
michael@0 | 350 | } |
michael@0 | 351 | } |
michael@0 | 352 | |
michael@0 | 353 | // arf_not_zz is indexed by MB, but this loop is indexed by MI to avoid out |
michael@0 | 354 | // of bound access in segmentation_map |
michael@0 | 355 | for (mi_row = 0; mi_row < cm->mi_rows; mi_row++) { |
michael@0 | 356 | for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) { |
michael@0 | 357 | // If any of the blocks in the sequence failed then the MB |
michael@0 | 358 | // goes in segment 0 |
michael@0 | 359 | if (arf_not_zz[mi_row/2*cm->mb_cols + mi_col/2]) { |
michael@0 | 360 | ncnt[0]++; |
michael@0 | 361 | cpi->segmentation_map[mi_row * cm->mi_cols + mi_col] = 0; |
michael@0 | 362 | } else { |
michael@0 | 363 | cpi->segmentation_map[mi_row * cm->mi_cols + mi_col] = 1; |
michael@0 | 364 | ncnt[1]++; |
michael@0 | 365 | } |
michael@0 | 366 | } |
michael@0 | 367 | } |
michael@0 | 368 | |
michael@0 | 369 | // Only bother with segmentation if over 10% of the MBs in static segment |
michael@0 | 370 | // if ( ncnt[1] && (ncnt[0] / ncnt[1] < 10) ) |
michael@0 | 371 | if (1) { |
michael@0 | 372 | // Note % of blocks that are marked as static |
michael@0 | 373 | if (cm->MBs) |
michael@0 | 374 | cpi->static_mb_pct = (ncnt[1] * 100) / (cm->mi_rows * cm->mi_cols); |
michael@0 | 375 | |
michael@0 | 376 | // This error case should not be reachable as this function should |
michael@0 | 377 | // never be called with the common data structure uninitialized. |
michael@0 | 378 | else |
michael@0 | 379 | cpi->static_mb_pct = 0; |
michael@0 | 380 | |
michael@0 | 381 | cpi->seg0_cnt = ncnt[0]; |
michael@0 | 382 | vp9_enable_segmentation((VP9_PTR)cpi); |
michael@0 | 383 | } else { |
michael@0 | 384 | cpi->static_mb_pct = 0; |
michael@0 | 385 | vp9_disable_segmentation((VP9_PTR)cpi); |
michael@0 | 386 | } |
michael@0 | 387 | |
michael@0 | 388 | // Free localy allocated storage |
michael@0 | 389 | vpx_free(arf_not_zz); |
michael@0 | 390 | } |
michael@0 | 391 | |
michael@0 | 392 | void vp9_update_mbgraph_stats(VP9_COMP *cpi) { |
michael@0 | 393 | VP9_COMMON *const cm = &cpi->common; |
michael@0 | 394 | int i, n_frames = vp9_lookahead_depth(cpi->lookahead); |
michael@0 | 395 | YV12_BUFFER_CONFIG *golden_ref = |
michael@0 | 396 | &cm->yv12_fb[cm->ref_frame_map[cpi->gld_fb_idx]]; |
michael@0 | 397 | |
michael@0 | 398 | // we need to look ahead beyond where the ARF transitions into |
michael@0 | 399 | // being a GF - so exit if we don't look ahead beyond that |
michael@0 | 400 | if (n_frames <= cpi->frames_till_gf_update_due) |
michael@0 | 401 | return; |
michael@0 | 402 | if (n_frames > (int)cpi->frames_till_alt_ref_frame) |
michael@0 | 403 | n_frames = cpi->frames_till_alt_ref_frame; |
michael@0 | 404 | if (n_frames > MAX_LAG_BUFFERS) |
michael@0 | 405 | n_frames = MAX_LAG_BUFFERS; |
michael@0 | 406 | |
michael@0 | 407 | cpi->mbgraph_n_frames = n_frames; |
michael@0 | 408 | for (i = 0; i < n_frames; i++) { |
michael@0 | 409 | MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i]; |
michael@0 | 410 | vpx_memset(frame_stats->mb_stats, 0, |
michael@0 | 411 | cm->mb_rows * cm->mb_cols * |
michael@0 | 412 | sizeof(*cpi->mbgraph_stats[i].mb_stats)); |
michael@0 | 413 | } |
michael@0 | 414 | |
michael@0 | 415 | // do motion search to find contribution of each reference to data |
michael@0 | 416 | // later on in this GF group |
michael@0 | 417 | // FIXME really, the GF/last MC search should be done forward, and |
michael@0 | 418 | // the ARF MC search backwards, to get optimal results for MV caching |
michael@0 | 419 | for (i = 0; i < n_frames; i++) { |
michael@0 | 420 | MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i]; |
michael@0 | 421 | struct lookahead_entry *q_cur = vp9_lookahead_peek(cpi->lookahead, i); |
michael@0 | 422 | |
michael@0 | 423 | assert(q_cur != NULL); |
michael@0 | 424 | |
michael@0 | 425 | update_mbgraph_frame_stats(cpi, frame_stats, &q_cur->img, |
michael@0 | 426 | golden_ref, cpi->Source); |
michael@0 | 427 | } |
michael@0 | 428 | |
michael@0 | 429 | vp9_clear_system_state(); // __asm emms; |
michael@0 | 430 | |
michael@0 | 431 | separate_arf_mbs(cpi); |
michael@0 | 432 | } |