ref: 198dbeaf038e03ce3b50b0689c73540ed5dd36c1
parent: 4f8eda3603fe14e0e5dfa04cf64b46be239faee5
author: Angie Chiang <angiebird@google.com>
date: Wed Dec 12 07:37:49 EST 2018
Add build_motion_field() Move the related code into the function. This is to facilitate of building pyramid motion field. Change-Id: I879db2271e227af63c5eac76b0c70c985b86a2da
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -6183,6 +6183,79 @@
}
#endif // USE_PQSORT
#endif // CHANGE_MV_SEARCH_ORDER
+
+static void build_motion_field(VP9_COMP *cpi, MACROBLOCKD *xd, int frame_idx,
+ YV12_BUFFER_CONFIG *ref_frame[3],
+ BLOCK_SIZE bsize) {
+ VP9_COMMON *cm = &cpi->common;
+ ThreadData *td = &cpi->td;
+ TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx];
+ const int mi_height = num_8x8_blocks_high_lookup[bsize];
+ const int mi_width = num_8x8_blocks_wide_lookup[bsize];
+ int fs_loc_sort_size;
+ int fs_loc_heap_size;
+ int mi_row, mi_col;
+
+ tpl_frame->lambda = 250;
+
+ fs_loc_sort_size = 0;
+ for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) {
+ for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) {
+ const int mb_y_offset =
+ mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE;
+ const int bw = 4 << b_width_log2_lookup[bsize];
+ const int bh = 4 << b_height_log2_lookup[bsize];
+ TplDepStats *tpl_stats =
+ &tpl_frame->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col];
+ FEATURE_SCORE_LOC *fs_loc =
+ &cpi->feature_score_loc_arr[mi_row * tpl_frame->stride + mi_col];
+ tpl_stats->feature_score = get_feature_score(
+ xd->cur_buf->y_buffer + mb_y_offset, xd->cur_buf->y_stride, bw, bh);
+ fs_loc->visited = 0;
+ fs_loc->feature_score = tpl_stats->feature_score;
+ fs_loc->mi_row = mi_row;
+ fs_loc->mi_col = mi_col;
+ cpi->feature_score_loc_sort[fs_loc_sort_size] = fs_loc;
+ ++fs_loc_sort_size;
+ }
+ }
+
+ qsort(cpi->feature_score_loc_sort, fs_loc_sort_size,
+ sizeof(*cpi->feature_score_loc_sort), compare_feature_score);
+
+#if CHANGE_MV_SEARCH_ORDER
+#if !USE_PQSORT
+ for (i = 0; i < fs_loc_sort_size; ++i) {
+ FEATURE_SCORE_LOC *fs_loc = cpi->feature_score_loc_sort[i];
+ do_motion_search(cpi, td, frame_idx, ref_frame, bsize, fs_loc->mi_row,
+ fs_loc->mi_col);
+ }
+#else // !USE_PQSORT
+ fs_loc_heap_size = 0;
+ max_heap_push(cpi->feature_score_loc_heap, &fs_loc_heap_size,
+ cpi->feature_score_loc_sort[0]);
+
+ while (fs_loc_heap_size > 0) {
+ FEATURE_SCORE_LOC *fs_loc;
+ max_heap_pop(cpi->feature_score_loc_heap, &fs_loc_heap_size, &fs_loc);
+
+ fs_loc->visited = 1;
+
+ do_motion_search(cpi, td, frame_idx, ref_frame, bsize, fs_loc->mi_row,
+ fs_loc->mi_col);
+
+ add_nb_blocks_to_heap(cpi, tpl_frame, bsize, fs_loc->mi_row, fs_loc->mi_col,
+ &fs_loc_heap_size);
+ }
+#endif // !USE_PQSORT
+#else // CHANGE_MV_SEARCH_ORDER
+ for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) {
+ for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) {
+ do_motion_search(cpi, td, frame_idx, ref_frame, bsize, mi_row, mi_col);
+ }
+ }
+#endif // CHANGE_MV_SEARCH_ORDER
+}
#endif // CONFIG_NON_GREEDY_MV
void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, int frame_idx,
@@ -6215,17 +6288,6 @@
const int mi_height = num_8x8_blocks_high_lookup[bsize];
const int mi_width = num_8x8_blocks_wide_lookup[bsize];
int64_t recon_error, sse;
-#if CONFIG_NON_GREEDY_MV
- int rf_idx;
- int fs_loc_sort_size;
-#if CHANGE_MV_SEARCH_ORDER
-#if USE_PQSORT
- int fs_loc_heap_size;
-#else
- int i;
-#endif // USE_PQSORT
-#endif // CHANGE_MV_SEARCH_ORDER
-#endif // CONFIG_NON_GREEDY_MV
// Setup scaling factor
#if CONFIG_VP9_HIGHBITDEPTH
@@ -6266,68 +6328,11 @@
vp9_frame_init_quantizer(cpi);
#if CONFIG_NON_GREEDY_MV
- tpl_frame->lambda = 250;
- fs_loc_sort_size = 0;
+ build_motion_field(cpi, xd, frame_idx, ref_frame, bsize);
+#endif
for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) {
for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) {
- const int mb_y_offset =
- mi_row * MI_SIZE * xd->cur_buf->y_stride + mi_col * MI_SIZE;
- const int bw = 4 << b_width_log2_lookup[bsize];
- const int bh = 4 << b_height_log2_lookup[bsize];
- TplDepStats *tpl_stats =
- &tpl_frame->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col];
- FEATURE_SCORE_LOC *fs_loc =
- &cpi->feature_score_loc_arr[mi_row * tpl_frame->stride + mi_col];
- tpl_stats->feature_score = get_feature_score(
- xd->cur_buf->y_buffer + mb_y_offset, xd->cur_buf->y_stride, bw, bh);
- fs_loc->visited = 0;
- fs_loc->feature_score = tpl_stats->feature_score;
- fs_loc->mi_row = mi_row;
- fs_loc->mi_col = mi_col;
- cpi->feature_score_loc_sort[fs_loc_sort_size] = fs_loc;
- ++fs_loc_sort_size;
- }
- }
-
- qsort(cpi->feature_score_loc_sort, fs_loc_sort_size,
- sizeof(*cpi->feature_score_loc_sort), compare_feature_score);
-
-#if CHANGE_MV_SEARCH_ORDER
-#if !USE_PQSORT
- for (i = 0; i < fs_loc_sort_size; ++i) {
- FEATURE_SCORE_LOC *fs_loc = cpi->feature_score_loc_sort[i];
- do_motion_search(cpi, td, frame_idx, ref_frame, bsize, fs_loc->mi_row,
- fs_loc->mi_col);
- }
-#else // !USE_PQSORT
- fs_loc_heap_size = 0;
- max_heap_push(cpi->feature_score_loc_heap, &fs_loc_heap_size,
- cpi->feature_score_loc_sort[0]);
-
- while (fs_loc_heap_size > 0) {
- FEATURE_SCORE_LOC *fs_loc;
- max_heap_pop(cpi->feature_score_loc_heap, &fs_loc_heap_size, &fs_loc);
-
- fs_loc->visited = 1;
-
- do_motion_search(cpi, td, frame_idx, ref_frame, bsize, fs_loc->mi_row,
- fs_loc->mi_col);
-
- add_nb_blocks_to_heap(cpi, tpl_frame, bsize, fs_loc->mi_row, fs_loc->mi_col,
- &fs_loc_heap_size);
- }
-#endif // !USE_PQSORT
-#else // CHANGE_MV_SEARCH_ORDER
- for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) {
- for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) {
- do_motion_search(cpi, td, frame_idx, ref_frame, bsize, mi_row, mi_col);
- }
- }
-#endif // CHANGE_MV_SEARCH_ORDER
-#endif // CONFIG_NON_GREEDY_MV
- for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) {
- for (mi_col = 0; mi_col < cm->mi_cols; mi_col += mi_width) {
mode_estimation(cpi, x, xd, &sf, gf_picture, frame_idx, tpl_frame,
src_diff, coeff, qcoeff, dqcoeff, mi_row, mi_col, bsize,
tx_size, ref_frame, predictor, &recon_error, &sse);
@@ -6339,6 +6344,7 @@
bsize);
#if CONFIG_NON_GREEDY_MV
{
+ int rf_idx;
TplDepStats *this_tpl_stats =
&tpl_frame->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col];
for (rf_idx = 0; rf_idx < 3; ++rf_idx) {