| 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 <limits.h> | 11 #include <limits.h> |
| 12 | 12 |
| 13 #include <vpx_mem/vpx_mem.h> | 13 #include "vpx_mem/vpx_mem.h" |
| 14 #include <vp9/encoder/vp9_encodeintra.h> | 14 #include "vp9/encoder/vp9_encodeintra.h" |
| 15 #include <vp9/encoder/vp9_rdopt.h> | 15 #include "vp9/encoder/vp9_rdopt.h" |
| 16 #include <vp9/common/vp9_blockd.h> | 16 #include "vp9/encoder/vp9_segmentation.h" |
| 17 #include <vp9/common/vp9_reconinter.h> | 17 #include "vp9/encoder/vp9_mcomp.h" |
| 18 #include <vp9/common/vp9_reconintra.h> | 18 #include "vp9/common/vp9_blockd.h" |
| 19 #include <vp9/common/vp9_systemdependent.h> | 19 #include "vp9/common/vp9_reconinter.h" |
| 20 #include <vp9/encoder/vp9_segmentation.h> | 20 #include "vp9/common/vp9_reconintra.h" |
| 21 #include "vp9/common/vp9_systemdependent.h" |
| 22 |
| 23 |
| 21 | 24 |
| 22 static unsigned int do_16x16_motion_iteration(VP9_COMP *cpi, | 25 static unsigned int do_16x16_motion_iteration(VP9_COMP *cpi, |
| 23 int_mv *ref_mv, | 26 int_mv *ref_mv, |
| 24 int_mv *dst_mv, | 27 int_mv *dst_mv, |
| 25 int mb_row, | 28 int mb_row, |
| 26 int mb_col) { | 29 int mb_col) { |
| 27 MACROBLOCK *const x = &cpi->mb; | 30 MACROBLOCK *const x = &cpi->mb; |
| 28 MACROBLOCKD *const xd = &x->e_mbd; | 31 MACROBLOCKD *const xd = &x->e_mbd; |
| 29 vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[BLOCK_16X16]; | 32 vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[BLOCK_16X16]; |
| 30 unsigned int best_err; | 33 unsigned int best_err; |
| 31 | 34 |
| 32 const int tmp_col_min = x->mv_col_min; | 35 const int tmp_col_min = x->mv_col_min; |
| 33 const int tmp_col_max = x->mv_col_max; | 36 const int tmp_col_max = x->mv_col_max; |
| 34 const int tmp_row_min = x->mv_row_min; | 37 const int tmp_row_min = x->mv_row_min; |
| 35 const int tmp_row_max = x->mv_row_max; | 38 const int tmp_row_max = x->mv_row_max; |
| 36 int_mv ref_full; | 39 int_mv ref_full; |
| 37 | 40 |
| 38 // Further step/diamond searches as necessary | 41 // Further step/diamond searches as necessary |
| 39 int step_param = cpi->sf.reduce_first_step_size + | 42 int step_param = cpi->sf.reduce_first_step_size + |
| 40 (cpi->speed < 8 ? (cpi->speed > 5 ? 1 : 0) : 2); | 43 (cpi->speed < 8 ? (cpi->speed > 5 ? 1 : 0) : 2); |
| 41 step_param = MIN(step_param, (cpi->sf.max_step_search_steps - 2)); | 44 step_param = MIN(step_param, (cpi->sf.max_step_search_steps - 2)); |
| 42 | 45 |
| 43 vp9_clamp_mv_min_max(x, &ref_mv->as_mv); | 46 vp9_clamp_mv_min_max(x, &ref_mv->as_mv); |
| 44 | 47 |
| 45 ref_full.as_mv.col = ref_mv->as_mv.col >> 3; | 48 ref_full.as_mv.col = ref_mv->as_mv.col >> 3; |
| 46 ref_full.as_mv.row = ref_mv->as_mv.row >> 3; | 49 ref_full.as_mv.row = ref_mv->as_mv.row >> 3; |
| 47 | 50 |
| 48 /*cpi->sf.search_method == HEX*/ | 51 /*cpi->sf.search_method == HEX*/ |
| 49 best_err = vp9_hex_search(x, &ref_full, step_param, x->errorperbit, | 52 best_err = vp9_hex_search(x, &ref_full.as_mv, step_param, x->errorperbit, |
| 50 0, &v_fn_ptr, | 53 0, &v_fn_ptr, |
| 51 0, ref_mv, dst_mv); | 54 0, &ref_mv->as_mv, &dst_mv->as_mv); |
| 52 | 55 |
| 53 // Try sub-pixel MC | 56 // Try sub-pixel MC |
| 54 // if (bestsme > error_thresh && bestsme < INT_MAX) | 57 // if (bestsme > error_thresh && bestsme < INT_MAX) |
| 55 { | 58 { |
| 56 int distortion; | 59 int distortion; |
| 57 unsigned int sse; | 60 unsigned int sse; |
| 58 best_err = cpi->find_fractional_mv_step( | 61 best_err = cpi->find_fractional_mv_step( |
| 59 x, | 62 x, |
| 60 dst_mv, ref_mv, | 63 &dst_mv->as_mv, &ref_mv->as_mv, |
| 64 cpi->common.allow_high_precision_mv, |
| 61 x->errorperbit, &v_fn_ptr, | 65 x->errorperbit, &v_fn_ptr, |
| 62 0, cpi->sf.subpel_iters_per_step, NULL, NULL, | 66 0, cpi->sf.subpel_iters_per_step, NULL, NULL, |
| 63 & distortion, &sse); | 67 & distortion, &sse); |
| 64 } | 68 } |
| 65 | 69 |
| 66 vp9_set_mbmode_and_mvs(x, NEWMV, dst_mv); | 70 vp9_set_mbmode_and_mvs(x, NEWMV, dst_mv); |
| 67 vp9_build_inter_predictors_sby(xd, mb_row, mb_col, BLOCK_16X16); | 71 vp9_build_inter_predictors_sby(xd, mb_row, mb_col, BLOCK_16X16); |
| 68 best_err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride, | 72 best_err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride, |
| 69 xd->plane[0].dst.buf, xd->plane[0].dst.stride, | 73 xd->plane[0].dst.buf, xd->plane[0].dst.stride, |
| 70 INT_MAX); | 74 INT_MAX); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 93 dst_mv->as_int = 0; | 97 dst_mv->as_int = 0; |
| 94 | 98 |
| 95 // Test last reference frame using the previous best mv as the | 99 // Test last reference frame using the previous best mv as the |
| 96 // starting point (best reference) for the search | 100 // starting point (best reference) for the search |
| 97 tmp_err = do_16x16_motion_iteration(cpi, ref_mv, &tmp_mv, mb_row, mb_col); | 101 tmp_err = do_16x16_motion_iteration(cpi, ref_mv, &tmp_mv, mb_row, mb_col); |
| 98 if (tmp_err < err) { | 102 if (tmp_err < err) { |
| 99 err = tmp_err; | 103 err = tmp_err; |
| 100 dst_mv->as_int = tmp_mv.as_int; | 104 dst_mv->as_int = tmp_mv.as_int; |
| 101 } | 105 } |
| 102 | 106 |
| 103 // If the current best reference mv is not centred on 0,0 then do a 0,0 based
search as well | 107 // If the current best reference mv is not centered on 0,0 then do a 0,0 |
| 108 // based search as well. |
| 104 if (ref_mv->as_int) { | 109 if (ref_mv->as_int) { |
| 105 unsigned int tmp_err; | 110 unsigned int tmp_err; |
| 106 int_mv zero_ref_mv, tmp_mv; | 111 int_mv zero_ref_mv, tmp_mv; |
| 107 | 112 |
| 108 zero_ref_mv.as_int = 0; | 113 zero_ref_mv.as_int = 0; |
| 109 tmp_err = do_16x16_motion_iteration(cpi, &zero_ref_mv, &tmp_mv, | 114 tmp_err = do_16x16_motion_iteration(cpi, &zero_ref_mv, &tmp_mv, |
| 110 mb_row, mb_col); | 115 mb_row, mb_col); |
| 111 if (tmp_err < err) { | 116 if (tmp_err < err) { |
| 112 dst_mv->as_int = tmp_mv.as_int; | 117 dst_mv->as_int = tmp_mv.as_int; |
| 113 err = tmp_err; | 118 err = tmp_err; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 138 MACROBLOCK *const x = &cpi->mb; | 143 MACROBLOCK *const x = &cpi->mb; |
| 139 MACROBLOCKD *const xd = &x->e_mbd; | 144 MACROBLOCKD *const xd = &x->e_mbd; |
| 140 MB_PREDICTION_MODE best_mode = -1, mode; | 145 MB_PREDICTION_MODE best_mode = -1, mode; |
| 141 unsigned int best_err = INT_MAX; | 146 unsigned int best_err = INT_MAX; |
| 142 | 147 |
| 143 // calculate SATD for each intra prediction mode; | 148 // calculate SATD for each intra prediction mode; |
| 144 // we're intentionally not doing 4x4, we just want a rough estimate | 149 // we're intentionally not doing 4x4, we just want a rough estimate |
| 145 for (mode = DC_PRED; mode <= TM_PRED; mode++) { | 150 for (mode = DC_PRED; mode <= TM_PRED; mode++) { |
| 146 unsigned int err; | 151 unsigned int err; |
| 147 | 152 |
| 148 xd->this_mi->mbmi.mode = mode; | 153 xd->mi_8x8[0]->mbmi.mode = mode; |
| 149 vp9_predict_intra_block(xd, 0, 2, TX_16X16, mode, | 154 vp9_predict_intra_block(xd, 0, 2, TX_16X16, mode, |
| 150 x->plane[0].src.buf, x->plane[0].src.stride, | 155 x->plane[0].src.buf, x->plane[0].src.stride, |
| 151 xd->plane[0].dst.buf, xd->plane[0].dst.stride); | 156 xd->plane[0].dst.buf, xd->plane[0].dst.stride); |
| 152 err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride, | 157 err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride, |
| 153 xd->plane[0].dst.buf, xd->plane[0].dst.stride, best_err); | 158 xd->plane[0].dst.buf, xd->plane[0].dst.stride, best_err); |
| 154 | 159 |
| 155 // find best | 160 // find best |
| 156 if (err < best_err) { | 161 if (err < best_err) { |
| 157 best_err = err; | 162 best_err = err; |
| 158 best_mode = mode; | 163 best_mode = mode; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 182 ) { | 187 ) { |
| 183 MACROBLOCK *const x = &cpi->mb; | 188 MACROBLOCK *const x = &cpi->mb; |
| 184 MACROBLOCKD *const xd = &x->e_mbd; | 189 MACROBLOCKD *const xd = &x->e_mbd; |
| 185 int intra_error; | 190 int intra_error; |
| 186 VP9_COMMON *cm = &cpi->common; | 191 VP9_COMMON *cm = &cpi->common; |
| 187 | 192 |
| 188 // FIXME in practice we're completely ignoring chroma here | 193 // FIXME in practice we're completely ignoring chroma here |
| 189 x->plane[0].src.buf = buf->y_buffer + mb_y_offset; | 194 x->plane[0].src.buf = buf->y_buffer + mb_y_offset; |
| 190 x->plane[0].src.stride = buf->y_stride; | 195 x->plane[0].src.stride = buf->y_stride; |
| 191 | 196 |
| 192 xd->plane[0].dst.buf = cm->yv12_fb[cm->new_fb_idx].y_buffer + mb_y_offset; | 197 xd->plane[0].dst.buf = get_frame_new_buffer(cm)->y_buffer + mb_y_offset; |
| 193 xd->plane[0].dst.stride = cm->yv12_fb[cm->new_fb_idx].y_stride; | 198 xd->plane[0].dst.stride = get_frame_new_buffer(cm)->y_stride; |
| 194 | 199 |
| 195 // do intra 16x16 prediction | 200 // do intra 16x16 prediction |
| 196 intra_error = find_best_16x16_intra(cpi, mb_y_offset, | 201 intra_error = find_best_16x16_intra(cpi, mb_y_offset, |
| 197 &stats->ref[INTRA_FRAME].m.mode); | 202 &stats->ref[INTRA_FRAME].m.mode); |
| 198 if (intra_error <= 0) | 203 if (intra_error <= 0) |
| 199 intra_error = 1; | 204 intra_error = 1; |
| 200 stats->ref[INTRA_FRAME].err = intra_error; | 205 stats->ref[INTRA_FRAME].err = intra_error; |
| 201 | 206 |
| 202 // Golden frame MV search, if it exists and is different than last frame | 207 // Golden frame MV search, if it exists and is different than last frame |
| 203 if (golden_ref) { | 208 if (golden_ref) { |
| 204 int g_motion_error; | 209 int g_motion_error; |
| 205 xd->plane[0].pre[0].buf = golden_ref->y_buffer + mb_y_offset; | 210 xd->plane[0].pre[0].buf = golden_ref->y_buffer + mb_y_offset; |
| 206 xd->plane[0].pre[0].stride = golden_ref->y_stride; | 211 xd->plane[0].pre[0].stride = golden_ref->y_stride; |
| 207 g_motion_error = do_16x16_motion_search(cpi, | 212 g_motion_error = do_16x16_motion_search(cpi, |
| 208 prev_golden_ref_mv, | 213 prev_golden_ref_mv, |
| 209 &stats->ref[GOLDEN_FRAME].m.mv, | 214 &stats->ref[GOLDEN_FRAME].m.mv, |
| 210 mb_row, mb_col); | 215 mb_row, mb_col); |
| 211 stats->ref[GOLDEN_FRAME].err = g_motion_error; | 216 stats->ref[GOLDEN_FRAME].err = g_motion_error; |
| 212 } else { | 217 } else { |
| 213 stats->ref[GOLDEN_FRAME].err = INT_MAX; | 218 stats->ref[GOLDEN_FRAME].err = INT_MAX; |
| 214 stats->ref[GOLDEN_FRAME].m.mv.as_int = 0; | 219 stats->ref[GOLDEN_FRAME].m.mv.as_int = 0; |
| 215 } | 220 } |
| 216 | 221 |
| 217 // Alt-ref frame MV search, if it exists and is different than last/golden fra
me | 222 // Do an Alt-ref frame MV search, if it exists and is different than |
| 223 // last/golden frame. |
| 218 if (alt_ref) { | 224 if (alt_ref) { |
| 219 int a_motion_error; | 225 int a_motion_error; |
| 220 xd->plane[0].pre[0].buf = alt_ref->y_buffer + mb_y_offset; | 226 xd->plane[0].pre[0].buf = alt_ref->y_buffer + mb_y_offset; |
| 221 xd->plane[0].pre[0].stride = alt_ref->y_stride; | 227 xd->plane[0].pre[0].stride = alt_ref->y_stride; |
| 222 a_motion_error = do_16x16_zerozero_search(cpi, | 228 a_motion_error = do_16x16_zerozero_search(cpi, |
| 223 &stats->ref[ALTREF_FRAME].m.mv); | 229 &stats->ref[ALTREF_FRAME].m.mv); |
| 224 | 230 |
| 225 stats->ref[ALTREF_FRAME].err = a_motion_error; | 231 stats->ref[ALTREF_FRAME].err = a_motion_error; |
| 226 } else { | 232 } else { |
| 227 stats->ref[ALTREF_FRAME].err = INT_MAX; | 233 stats->ref[ALTREF_FRAME].err = INT_MAX; |
| 228 stats->ref[ALTREF_FRAME].m.mv.as_int = 0; | 234 stats->ref[ALTREF_FRAME].m.mv.as_int = 0; |
| 229 } | 235 } |
| 230 } | 236 } |
| 231 | 237 |
| 232 static void update_mbgraph_frame_stats(VP9_COMP *cpi, | 238 static void update_mbgraph_frame_stats(VP9_COMP *cpi, |
| 233 MBGRAPH_FRAME_STATS *stats, | 239 MBGRAPH_FRAME_STATS *stats, |
| 234 YV12_BUFFER_CONFIG *buf, | 240 YV12_BUFFER_CONFIG *buf, |
| 235 YV12_BUFFER_CONFIG *golden_ref, | 241 YV12_BUFFER_CONFIG *golden_ref, |
| 236 YV12_BUFFER_CONFIG *alt_ref) { | 242 YV12_BUFFER_CONFIG *alt_ref) { |
| 237 MACROBLOCK *const x = &cpi->mb; | 243 MACROBLOCK *const x = &cpi->mb; |
| 238 MACROBLOCKD *const xd = &x->e_mbd; | 244 MACROBLOCKD *const xd = &x->e_mbd; |
| 239 VP9_COMMON *const cm = &cpi->common; | 245 VP9_COMMON *const cm = &cpi->common; |
| 240 | 246 |
| 241 int mb_col, mb_row, offset = 0; | 247 int mb_col, mb_row, offset = 0; |
| 242 int mb_y_offset = 0, arf_y_offset = 0, gld_y_offset = 0; | 248 int mb_y_offset = 0, arf_y_offset = 0, gld_y_offset = 0; |
| 243 int_mv arf_top_mv, gld_top_mv; | 249 int_mv arf_top_mv, gld_top_mv; |
| 244 MODE_INFO mi_local = { { 0 } }; | 250 MODE_INFO mi_local = { { 0 } }; |
| 245 | 251 |
| 246 // Set up limit values for motion vectors to prevent them extending outside th
e UMV borders | 252 // Set up limit values for motion vectors to prevent them extending outside |
| 253 // the UMV borders. |
| 247 arf_top_mv.as_int = 0; | 254 arf_top_mv.as_int = 0; |
| 248 gld_top_mv.as_int = 0; | 255 gld_top_mv.as_int = 0; |
| 249 x->mv_row_min = -(VP9BORDERINPIXELS - 8 - VP9_INTERP_EXTEND); | 256 x->mv_row_min = -BORDER_MV_PIXELS_B16; |
| 250 x->mv_row_max = (cm->mb_rows - 1) * 8 + VP9BORDERINPIXELS | 257 x->mv_row_max = (cm->mb_rows - 1) * 8 + BORDER_MV_PIXELS_B16; |
| 251 - 8 - VP9_INTERP_EXTEND; | |
| 252 xd->up_available = 0; | 258 xd->up_available = 0; |
| 253 xd->plane[0].dst.stride = buf->y_stride; | 259 xd->plane[0].dst.stride = buf->y_stride; |
| 254 xd->plane[0].pre[0].stride = buf->y_stride; | 260 xd->plane[0].pre[0].stride = buf->y_stride; |
| 255 xd->plane[1].dst.stride = buf->uv_stride; | 261 xd->plane[1].dst.stride = buf->uv_stride; |
| 256 xd->this_mi = &mi_local; | 262 xd->mi_8x8[0] = &mi_local; |
| 257 mi_local.mbmi.sb_type = BLOCK_16X16; | 263 mi_local.mbmi.sb_type = BLOCK_16X16; |
| 258 mi_local.mbmi.ref_frame[0] = LAST_FRAME; | 264 mi_local.mbmi.ref_frame[0] = LAST_FRAME; |
| 259 mi_local.mbmi.ref_frame[1] = NONE; | 265 mi_local.mbmi.ref_frame[1] = NONE; |
| 260 | 266 |
| 261 for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) { | 267 for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) { |
| 262 int_mv arf_left_mv, gld_left_mv; | 268 int_mv arf_left_mv, gld_left_mv; |
| 263 int mb_y_in_offset = mb_y_offset; | 269 int mb_y_in_offset = mb_y_offset; |
| 264 int arf_y_in_offset = arf_y_offset; | 270 int arf_y_in_offset = arf_y_offset; |
| 265 int gld_y_in_offset = gld_y_offset; | 271 int gld_y_in_offset = gld_y_offset; |
| 266 | 272 |
| 267 // Set up limit values for motion vectors to prevent them extending outside
the UMV borders | 273 // Set up limit values for motion vectors to prevent them extending outside |
| 274 // the UMV borders. |
| 268 arf_left_mv.as_int = arf_top_mv.as_int; | 275 arf_left_mv.as_int = arf_top_mv.as_int; |
| 269 gld_left_mv.as_int = gld_top_mv.as_int; | 276 gld_left_mv.as_int = gld_top_mv.as_int; |
| 270 x->mv_col_min = -(VP9BORDERINPIXELS - 8 - VP9_INTERP_EXTEND); | 277 x->mv_col_min = -BORDER_MV_PIXELS_B16; |
| 271 x->mv_col_max = (cm->mb_cols - 1) * 8 + VP9BORDERINPIXELS | 278 x->mv_col_max = (cm->mb_cols - 1) * 8 + BORDER_MV_PIXELS_B16; |
| 272 - 8 - VP9_INTERP_EXTEND; | |
| 273 xd->left_available = 0; | 279 xd->left_available = 0; |
| 274 | 280 |
| 275 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { | 281 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { |
| 276 MBGRAPH_MB_STATS *mb_stats = &stats->mb_stats[offset + mb_col]; | 282 MBGRAPH_MB_STATS *mb_stats = &stats->mb_stats[offset + mb_col]; |
| 277 | 283 |
| 278 update_mbgraph_mb_stats(cpi, mb_stats, buf, mb_y_in_offset, | 284 update_mbgraph_mb_stats(cpi, mb_stats, buf, mb_y_in_offset, |
| 279 golden_ref, &gld_left_mv, gld_y_in_offset, | 285 golden_ref, &gld_left_mv, gld_y_in_offset, |
| 280 alt_ref, &arf_left_mv, arf_y_in_offset, | 286 alt_ref, &arf_left_mv, arf_y_in_offset, |
| 281 mb_row, mb_col); | 287 mb_row, mb_col); |
| 282 arf_left_mv.as_int = mb_stats->ref[ALTREF_FRAME].m.mv.as_int; | 288 arf_left_mv.as_int = mb_stats->ref[ALTREF_FRAME].m.mv.as_int; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 300 x->mv_row_min -= 16; | 306 x->mv_row_min -= 16; |
| 301 x->mv_row_max -= 16; | 307 x->mv_row_max -= 16; |
| 302 offset += cm->mb_cols; | 308 offset += cm->mb_cols; |
| 303 } | 309 } |
| 304 } | 310 } |
| 305 | 311 |
| 306 // void separate_arf_mbs_byzz | 312 // void separate_arf_mbs_byzz |
| 307 static void separate_arf_mbs(VP9_COMP *cpi) { | 313 static void separate_arf_mbs(VP9_COMP *cpi) { |
| 308 VP9_COMMON *const cm = &cpi->common; | 314 VP9_COMMON *const cm = &cpi->common; |
| 309 int mb_col, mb_row, offset, i; | 315 int mb_col, mb_row, offset, i; |
| 316 int mi_row, mi_col; |
| 310 int ncnt[4] = { 0 }; | 317 int ncnt[4] = { 0 }; |
| 311 int n_frames = cpi->mbgraph_n_frames; | 318 int n_frames = cpi->mbgraph_n_frames; |
| 312 | 319 |
| 313 int *arf_not_zz; | 320 int *arf_not_zz; |
| 314 | 321 |
| 315 CHECK_MEM_ERROR(cm, arf_not_zz, | 322 CHECK_MEM_ERROR(cm, arf_not_zz, |
| 316 vpx_calloc(cm->mb_rows * cm->mb_cols * sizeof(*arf_not_zz), | 323 vpx_calloc(cm->mb_rows * cm->mb_cols * sizeof(*arf_not_zz), |
| 317 1)); | 324 1)); |
| 318 | 325 |
| 319 // We are not interested in results beyond the alt ref itself. | 326 // We are not interested in results beyond the alt ref itself. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 336 // Test for altref vs intra and gf and that its mv was 0,0. | 343 // Test for altref vs intra and gf and that its mv was 0,0. |
| 337 if (altref_err > 1000 || | 344 if (altref_err > 1000 || |
| 338 altref_err > intra_err || | 345 altref_err > intra_err || |
| 339 altref_err > golden_err) { | 346 altref_err > golden_err) { |
| 340 arf_not_zz[offset + mb_col]++; | 347 arf_not_zz[offset + mb_col]++; |
| 341 } | 348 } |
| 342 } | 349 } |
| 343 } | 350 } |
| 344 } | 351 } |
| 345 | 352 |
| 346 for (offset = 0, mb_row = 0; mb_row < cm->mb_rows; | 353 // arf_not_zz is indexed by MB, but this loop is indexed by MI to avoid out |
| 347 offset += cm->mb_cols, mb_row++) { | 354 // of bound access in segmentation_map |
| 348 for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) { | 355 for (mi_row = 0; mi_row < cm->mi_rows; mi_row++) { |
| 356 for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) { |
| 349 // If any of the blocks in the sequence failed then the MB | 357 // If any of the blocks in the sequence failed then the MB |
| 350 // goes in segment 0 | 358 // goes in segment 0 |
| 351 if (arf_not_zz[offset + mb_col]) { | 359 if (arf_not_zz[mi_row/2*cm->mb_cols + mi_col/2]) { |
| 352 ncnt[0]++; | 360 ncnt[0]++; |
| 353 cpi->segmentation_map[offset * 4 + 2 * mb_col] = 0; | 361 cpi->segmentation_map[mi_row * cm->mi_cols + mi_col] = 0; |
| 354 cpi->segmentation_map[offset * 4 + 2 * mb_col + 1] = 0; | |
| 355 cpi->segmentation_map[offset * 4 + 2 * mb_col + cm->mi_cols] = 0; | |
| 356 cpi->segmentation_map[offset * 4 + 2 * mb_col + cm->mi_cols + 1] = 0; | |
| 357 } else { | 362 } else { |
| 358 cpi->segmentation_map[offset * 4 + 2 * mb_col] = 1; | 363 cpi->segmentation_map[mi_row * cm->mi_cols + mi_col] = 1; |
| 359 cpi->segmentation_map[offset * 4 + 2 * mb_col + 1] = 1; | |
| 360 cpi->segmentation_map[offset * 4 + 2 * mb_col + cm->mi_cols] = 1; | |
| 361 cpi->segmentation_map[offset * 4 + 2 * mb_col + cm->mi_cols + 1] = 1; | |
| 362 ncnt[1]++; | 364 ncnt[1]++; |
| 363 } | 365 } |
| 364 } | 366 } |
| 365 } | 367 } |
| 366 | 368 |
| 367 // Only bother with segmentation if over 10% of the MBs in static segment | 369 // Only bother with segmentation if over 10% of the MBs in static segment |
| 368 // if ( ncnt[1] && (ncnt[0] / ncnt[1] < 10) ) | 370 // if ( ncnt[1] && (ncnt[0] / ncnt[1] < 10) ) |
| 369 if (1) { | 371 if (1) { |
| 370 // Note % of blocks that are marked as static | 372 // Note % of blocks that are marked as static |
| 371 if (cm->MBs) | 373 if (cm->MBs) |
| 372 cpi->static_mb_pct = (ncnt[1] * 100) / cm->MBs; | 374 cpi->static_mb_pct = (ncnt[1] * 100) / (cm->mi_rows * cm->mi_cols); |
| 373 | 375 |
| 374 // This error case should not be reachable as this function should | 376 // This error case should not be reachable as this function should |
| 375 // never be called with the common data structure uninitialized. | 377 // never be called with the common data structure uninitialized. |
| 376 else | 378 else |
| 377 cpi->static_mb_pct = 0; | 379 cpi->static_mb_pct = 0; |
| 378 | 380 |
| 379 cpi->seg0_cnt = ncnt[0]; | 381 cpi->seg0_cnt = ncnt[0]; |
| 380 vp9_enable_segmentation((VP9_PTR)cpi); | 382 vp9_enable_segmentation((VP9_PTR)cpi); |
| 381 } else { | 383 } else { |
| 382 cpi->static_mb_pct = 0; | 384 cpi->static_mb_pct = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 399 return; | 401 return; |
| 400 if (n_frames > (int)cpi->frames_till_alt_ref_frame) | 402 if (n_frames > (int)cpi->frames_till_alt_ref_frame) |
| 401 n_frames = cpi->frames_till_alt_ref_frame; | 403 n_frames = cpi->frames_till_alt_ref_frame; |
| 402 if (n_frames > MAX_LAG_BUFFERS) | 404 if (n_frames > MAX_LAG_BUFFERS) |
| 403 n_frames = MAX_LAG_BUFFERS; | 405 n_frames = MAX_LAG_BUFFERS; |
| 404 | 406 |
| 405 cpi->mbgraph_n_frames = n_frames; | 407 cpi->mbgraph_n_frames = n_frames; |
| 406 for (i = 0; i < n_frames; i++) { | 408 for (i = 0; i < n_frames; i++) { |
| 407 MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i]; | 409 MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i]; |
| 408 vpx_memset(frame_stats->mb_stats, 0, | 410 vpx_memset(frame_stats->mb_stats, 0, |
| 409 cm->mb_rows * cm->mb_cols * sizeof(*cpi->mbgraph_stats[i].mb_stat
s)); | 411 cm->mb_rows * cm->mb_cols * |
| 412 sizeof(*cpi->mbgraph_stats[i].mb_stats)); |
| 410 } | 413 } |
| 411 | 414 |
| 412 // do motion search to find contribution of each reference to data | 415 // do motion search to find contribution of each reference to data |
| 413 // later on in this GF group | 416 // later on in this GF group |
| 414 // FIXME really, the GF/last MC search should be done forward, and | 417 // FIXME really, the GF/last MC search should be done forward, and |
| 415 // the ARF MC search backwards, to get optimal results for MV caching | 418 // the ARF MC search backwards, to get optimal results for MV caching |
| 416 for (i = 0; i < n_frames; i++) { | 419 for (i = 0; i < n_frames; i++) { |
| 417 MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i]; | 420 MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i]; |
| 418 struct lookahead_entry *q_cur = vp9_lookahead_peek(cpi->lookahead, i); | 421 struct lookahead_entry *q_cur = vp9_lookahead_peek(cpi->lookahead, i); |
| 419 | 422 |
| 420 assert(q_cur != NULL); | 423 assert(q_cur != NULL); |
| 421 | 424 |
| 422 update_mbgraph_frame_stats(cpi, frame_stats, &q_cur->img, | 425 update_mbgraph_frame_stats(cpi, frame_stats, &q_cur->img, |
| 423 golden_ref, cpi->Source); | 426 golden_ref, cpi->Source); |
| 424 } | 427 } |
| 425 | 428 |
| 426 vp9_clear_system_state(); // __asm emms; | 429 vp9_clear_system_state(); // __asm emms; |
| 427 | 430 |
| 428 separate_arf_mbs(cpi); | 431 separate_arf_mbs(cpi); |
| 429 } | 432 } |
| OLD | NEW |