Refactor GlobalMotionInfo from AV1_COMP This CL groups global motion related variables from AV1_COMP into a new struct GlobalMotionInfo, adds documentation for the members, and cleans up function interfaces. BUG=aomedia:2610 Change-Id: I5817a55867f18a9d203e6981a375cea52f1b06cb
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c index 2f23751..3240c54 100644 --- a/av1/encoder/encodeframe.c +++ b/av1/encoder/encodeframe.c
@@ -5453,7 +5453,7 @@ // Skip global motion estimation for invalid ref frames if (buf == NULL || (ref_disabled && cpi->sf.hl_sf.recode_loop != DISALLOW_RECODE)) { - cpi->gmparams_cost[frame] = 0; + cpi->gm_info.params_cost[frame] = 0; continue; } else { ref_buf[frame] = &buf->buf; @@ -5491,6 +5491,7 @@ MotionModel *params_by_motion, uint8_t *segment_map, const int segment_map_w, const int segment_map_h) { AV1_COMMON *const cm = &cpi->common; + GlobalMotionInfo *const gm_info = &cpi->gm_info; const WarpedMotionParams *ref_params = cm->prev_frame ? &cm->prev_frame->global_motion[frame] : &default_warp_params; @@ -5499,11 +5500,11 @@ cpi, ref_buf, frame, num_frm_corners, frm_corners, frm_buffer, params_by_motion, segment_map, segment_map_w, segment_map_h, ref_params); - cpi->gmparams_cost[frame] = + gm_info->params_cost[frame] = gm_get_params_cost(&cm->global_motion[frame], ref_params, cm->features.allow_high_precision_mv) + - cpi->gmtype_cost[cm->global_motion[frame].wmtype] - - cpi->gmtype_cost[IDENTITY]; + gm_info->type_cost[cm->global_motion[frame].wmtype] - + gm_info->type_cost[IDENTITY]; } static int compare_distance(const void *a, const void *b) { @@ -5606,6 +5607,7 @@ FeatureFlags *const features = &cm->features; MACROBLOCKD *const xd = &x->e_mbd; RD_COUNTS *const rdc = &cpi->td.rd_counts; + GlobalMotionInfo *const gm_info = &cpi->gm_info; int i; if (!cpi->sf.rt_sf.use_nonrd_pick_mode) { @@ -5787,9 +5789,9 @@ start_timing(cpi, av1_compute_global_motion_time); #endif av1_zero(rdc->global_motion_used); - av1_zero(cpi->gmparams_cost); + av1_zero(gm_info->params_cost); if (cpi->common.current_frame.frame_type == INTER_FRAME && cpi->source && - cpi->oxcf.enable_global_motion && !cpi->global_motion_search_done) { + cpi->oxcf.enable_global_motion && !gm_info->search_done) { YV12_BUFFER_CONFIG *ref_buf[REF_FRAMES]; MotionModel params_by_motion[RANSAC_NUM_MOTIONS]; for (int m = 0; m < RANSAC_NUM_MOTIONS; m++) { @@ -5857,7 +5859,7 @@ aom_free(segment_map); - cpi->global_motion_search_done = 1; + gm_info->search_done = 1; for (int m = 0; m < RANSAC_NUM_MOTIONS; m++) { aom_free(params_by_motion[m].inliers); }
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c index 3e91c03..d894fa4 100644 --- a/av1/encoder/encoder.c +++ b/av1/encoder/encoder.c
@@ -3812,18 +3812,18 @@ #endif // OUTPUT_YUV_REC #define GM_RECODE_LOOP_NUM4X4_FACTOR 192 -static int recode_loop_test_global_motion(AV1_COMP *cpi) { +static int recode_loop_test_global_motion( + WarpedMotionParams *const global_motion, + const int *const global_motion_used, int *const gm_params_cost) { int i; int recode = 0; - RD_COUNTS *const rdc = &cpi->td.rd_counts; - AV1_COMMON *const cm = &cpi->common; for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { - if (cm->global_motion[i].wmtype != IDENTITY && - rdc->global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < - cpi->gmparams_cost[i]) { - cm->global_motion[i] = default_warp_params; - assert(cm->global_motion[i].wmtype == IDENTITY); - cpi->gmparams_cost[i] = 0; + if (global_motion[i].wmtype != IDENTITY && + global_motion_used[i] * GM_RECODE_LOOP_NUM4X4_FACTOR < + gm_params_cost[i]) { + global_motion[i] = default_warp_params; + assert(global_motion[i].wmtype == IDENTITY); + gm_params_cost[i] = 0; recode = 1; // TODO(sarahparker): The earlier condition for recoding here was: // "recode |= (rdc->global_motion_used[i] > 0);". Can we bring something @@ -4048,7 +4048,7 @@ for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { cm->global_motion[i] = default_warp_params; } - cpi->global_motion_search_done = 0; + cpi->gm_info.search_done = 0; if (frame_is_intra_only(cm)) set_screen_content_options(cpi, features); cpi->is_screen_content_type = (features->allow_screen_content_tools != 0); @@ -5366,6 +5366,7 @@ static int encode_with_recode_loop(AV1_COMP *cpi, size_t *size, uint8_t *dest) { AV1_COMMON *const cm = &cpi->common; RATE_CONTROL *const rc = &cpi->rc; + GlobalMotionInfo *const gm_info = &cpi->gm_info; const int allow_recode = (cpi->sf.hl_sf.recode_loop != DISALLOW_RECODE); // Must allow recode if minimum compression ratio is set. assert(IMPLIES(cpi->oxcf.min_cr > 0, allow_recode)); @@ -5465,10 +5466,10 @@ // if frame was scaled calculate global_motion_search again if already // done - if (loop_count > 0 && cpi->source && cpi->global_motion_search_done) { + if (loop_count > 0 && cpi->source && gm_info->search_done) { if (cpi->source->y_crop_width != cm->width || cpi->source->y_crop_height != cm->height) { - cpi->global_motion_search_done = 0; + gm_info->search_done = 0; } } cpi->source = @@ -5549,7 +5550,7 @@ // then we need to reset the global motion vectors if (loop_count > 0 && cm->features.allow_high_precision_mv != last_loop_allow_hp) { - cpi->global_motion_search_done = 0; + gm_info->search_done = 0; } last_loop_allow_hp = cm->features.allow_high_precision_mv; } @@ -5607,7 +5608,9 @@ } if (allow_recode && !cpi->sf.gm_sf.gm_disable_recode && - recode_loop_test_global_motion(cpi)) { + recode_loop_test_global_motion(cm->global_motion, + cpi->td.rd_counts.global_motion_used, + gm_info->params_cost)) { loop = 1; }
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h index 4048842..c12d48b 100644 --- a/av1/encoder/encoder.h +++ b/av1/encoder/encoder.h
@@ -820,6 +820,20 @@ #define MAX_INTERNAL_ARFS (REF_FRAMES - BWDREF_FRAME - 1) typedef struct { + // Array to store the cost for signalling each global motion model. + // gmtype_cost[i] stores the cost of signalling the ith Global Motion model. + int type_cost[TRANS_TYPES]; + + // Array to store the cost for signalling a particular global motion model for + // each reference frame. gmparams_cost[i] stores the cost of signalling global + // motion for the ith reference frame. + int params_cost[REF_FRAMES]; + + // Flag to indicate if global motion search needs to be rerun. + bool search_done; +} GlobalMotionInfo; + +typedef struct { int arf_stack[FRAME_BUFFERS]; int arf_stack_size; int lst_stack[FRAME_BUFFERS]; @@ -946,8 +960,8 @@ CODING_CONTEXT coding_context; - int gmtype_cost[TRANS_TYPES]; - int gmparams_cost[REF_FRAMES]; + // Parameters related to global motion search. + GlobalMotionInfo gm_info; int64_t last_time_stamp_seen; int64_t last_end_time_stamp_seen; @@ -1090,7 +1104,6 @@ AVxWorker *workers; struct EncWorkerData *tile_thr_data; int existing_fb_idx_to_show; - int global_motion_search_done; int internal_altref_allowed; // A flag to indicate if intrabc is ever used in current frame. int intrabc_used;
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c index 21b75bd..3d13cda 100644 --- a/av1/encoder/rd.c +++ b/av1/encoder/rd.c
@@ -616,8 +616,8 @@ // TRANSLATION: 3 bits // ROTZOOM: 2 bits // AFFINE: 3 bits - cpi->gmtype_cost[i] = (1 + (i > 0 ? (i == ROTZOOM ? 1 : 2) : 0)) - << AV1_PROB_COST_SHIFT; + cpi->gm_info.type_cost[i] = (1 + (i > 0 ? (i == ROTZOOM ? 1 : 2) : 0)) + << AV1_PROB_COST_SHIFT; } }