Refactor segmentation related params in AV1_COMP
This CL groups together segmentation related params in AV1_COMP into
a new struct EncSegmentationInfo, and adds documentation for the
members.
BUG=aomedia:2610
Change-Id: Ib14e451b1f50b5ae7f9f7ef1fa6ec61c66afc8a1
diff --git a/av1/encoder/aq_complexity.c b/av1/encoder/aq_complexity.c
index 1756f46..3658006 100644
--- a/av1/encoder/aq_complexity.c
+++ b/av1/encoder/aq_complexity.c
@@ -71,8 +71,7 @@
aom_clear_system_state();
if (resolution_change) {
- memset(cpi->segmentation_map, 0,
- cm->mi_params.mi_rows * cm->mi_params.mi_cols);
+ memset(cpi->enc_seg.map, 0, cm->mi_params.mi_rows * cm->mi_params.mi_cols);
av1_clearall_segfeatures(seg);
av1_disable_segmentation(seg);
return;
@@ -84,7 +83,7 @@
get_aq_c_strength(base_qindex, cm->seq_params.bit_depth);
// Clear down the segment map.
- memset(cpi->segmentation_map, DEFAULT_AQ2_SEG,
+ memset(cpi->enc_seg.map, DEFAULT_AQ2_SEG,
cm->mi_params.mi_rows * cm->mi_params.mi_cols);
av1_clearall_segfeatures(seg);
@@ -180,8 +179,7 @@
// Fill in the entires in the segment map corresponding to this SB64.
for (y = 0; y < ymis; y++) {
for (x = 0; x < xmis; x++) {
- cpi->segmentation_map[mi_offset + y * cm->mi_params.mi_cols + x] =
- segment;
+ cpi->enc_seg.map[mi_offset + y * cm->mi_params.mi_cols + x] = segment;
}
}
}
diff --git a/av1/encoder/aq_cyclicrefresh.c b/av1/encoder/aq_cyclicrefresh.c
index 835998b..b888494 100644
--- a/av1/encoder/aq_cyclicrefresh.c
+++ b/av1/encoder/aq_cyclicrefresh.c
@@ -201,7 +201,7 @@
for (int x = 0; x < xmis; x++) {
int map_offset = block_index + y * cm->mi_params.mi_cols + x;
cr->map[map_offset] = new_map_value;
- cpi->segmentation_map[map_offset] = mbmi->segment_id;
+ cpi->enc_seg.map[map_offset] = mbmi->segment_id;
}
}
@@ -210,7 +210,7 @@
AV1_COMMON *const cm = &cpi->common;
const CommonModeInfoParams *const mi_params = &cm->mi_params;
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
- unsigned char *const seg_map = cpi->segmentation_map;
+ unsigned char *const seg_map = cpi->enc_seg.map;
cr->cnt_zeromv = 0;
cr->actual_num_seg1_blocks = 0;
cr->actual_num_seg2_blocks = 0;
@@ -263,7 +263,7 @@
AV1_COMMON *const cm = &cpi->common;
const CommonModeInfoParams *const mi_params = &cm->mi_params;
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
- unsigned char *const seg_map = cpi->segmentation_map;
+ unsigned char *const seg_map = cpi->enc_seg.map;
int i, block_count, bl_index, sb_rows, sb_cols, sbs_in_frame;
int xmis, ymis, x, y;
memset(seg_map, CR_SEGMENT_ID_BASE, mi_params->mi_rows * mi_params->mi_cols);
@@ -419,7 +419,7 @@
if (cm->current_frame.frame_number == 0) cr->low_content_avg = 0.0;
if (!cr->apply_cyclic_refresh) {
// Set segmentation map to 0 and disable.
- unsigned char *const seg_map = cpi->segmentation_map;
+ unsigned char *const seg_map = cpi->enc_seg.map;
memset(seg_map, 0, cm->mi_params.mi_rows * cm->mi_params.mi_cols);
av1_disable_segmentation(&cm->seg);
if (cm->current_frame.frame_type == KEY_FRAME) {
diff --git a/av1/encoder/aq_variance.c b/av1/encoder/aq_variance.c
index 89e444d..4176da2 100644
--- a/av1/encoder/aq_variance.c
+++ b/av1/encoder/aq_variance.c
@@ -58,8 +58,7 @@
avg_ratio = rate_ratio[avg_energy];
if (resolution_change) {
- memset(cpi->segmentation_map, 0,
- cm->mi_params.mi_rows * cm->mi_params.mi_cols);
+ memset(cpi->enc_seg.map, 0, cm->mi_params.mi_rows * cm->mi_params.mi_cols);
av1_clearall_segfeatures(seg);
aom_clear_system_state();
av1_disable_segmentation(seg);
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index aafa9fd..daa8ce1 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -455,11 +455,11 @@
// Still need to transmit tx size for intra blocks even if skip is
// true. Changing segment_id may make the tx size become invalid, e.g
// changing from lossless to lossy.
- assert(is_inter_block(mbmi) || !cpi->has_lossless_segment);
+ assert(is_inter_block(mbmi) || !cpi->enc_seg.has_lossless_segment);
set_spatial_segment_id(&cm->mi_params, cm->cur_frame->seg_map,
mbmi->sb_type, mi_row, mi_col, pred);
- set_spatial_segment_id(&cm->mi_params, cpi->segmentation_map, mbmi->sb_type,
+ set_spatial_segment_id(&cm->mi_params, cpi->enc_seg.map, mbmi->sb_type,
mi_row, mi_col, pred);
/* mbmi is read only but we need to update segment_id */
((MB_MODE_INFO *)mbmi)->segment_id = pred;
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index e13bdd9..eb102aa 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -442,7 +442,7 @@
if (seg->enabled) {
if (seg->enabled && !cpi->vaq_refresh) {
const uint8_t *const map =
- seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map;
+ seg->update_map ? cpi->enc_seg.map : cm->last_frame_seg_map;
mbmi->segment_id =
map ? get_segment_id(&cm->mi_params, map, bsize, mi_row, mi_col) : 0;
}
@@ -578,7 +578,7 @@
// For in frame complexity AQ copy the segment id from the segment map.
if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) {
const uint8_t *const map =
- seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map;
+ seg->update_map ? cpi->enc_seg.map : cm->last_frame_seg_map;
mi_addr->segment_id =
map ? get_segment_id(mi_params, map, bsize, mi_row, mi_col) : 0;
reset_tx_size(x, mi_addr, x->tx_mode_search_type);
@@ -4947,7 +4947,7 @@
int seg_skip = 0;
if (seg->enabled) {
const uint8_t *const map =
- seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map;
+ seg->update_map ? cpi->enc_seg.map : cm->last_frame_seg_map;
const int segment_id =
map ? get_segment_id(&cm->mi_params, map, sb_size, mi_row, mi_col)
: 0;
@@ -5733,7 +5733,7 @@
qindex == 0 && quant_params->y_dc_delta_q == 0 &&
quant_params->u_dc_delta_q == 0 && quant_params->u_ac_delta_q == 0 &&
quant_params->v_dc_delta_q == 0 && quant_params->v_ac_delta_q == 0;
- if (xd->lossless[i]) cpi->has_lossless_segment = 1;
+ if (xd->lossless[i]) cpi->enc_seg.has_lossless_segment = 1;
xd->qindex[i] = qindex;
if (xd->lossless[i]) {
cpi->optimize_seg_arr[i] = NO_TRELLIS_OPT;
@@ -6040,7 +6040,7 @@
const int mi_rows = cm->mi_params.mi_rows;
const int mi_cols = cm->mi_params.mi_cols;
const int last_active_segid = cm->seg.last_active_segid;
- uint8_t *map = cpi->segmentation_map;
+ uint8_t *map = cpi->enc_seg.map;
for (int mi_row = 0; mi_row < mi_rows; ++mi_row) {
for (int mi_col = 0; mi_col < mi_cols; ++mi_col) {
map[mi_col] = AOMMIN(map[mi_col], last_active_segid);
@@ -6331,7 +6331,7 @@
// block to be 0, in order to avoid the segment_id to be changed by in
// write_segment_id().
if (!cpi->common.seg.segid_preskip && cpi->common.seg.update_map &&
- cpi->has_lossless_segment)
+ cpi->enc_seg.has_lossless_segment)
mbmi->skip = 0;
xd->cfl.store_y = 0;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 86fb308..026634b 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -399,7 +399,7 @@
// Mark all inactive blocks as active. Other segmentation features may be set
// so memset cannot be used, instead only inactive blocks should be reset.
static void suppress_active_map(AV1_COMP *cpi) {
- unsigned char *const seg_map = cpi->segmentation_map;
+ unsigned char *const seg_map = cpi->enc_seg.map;
int i;
if (cpi->active_map.enabled || cpi->active_map.update)
for (i = 0;
@@ -410,7 +410,7 @@
static void apply_active_map(AV1_COMP *cpi) {
struct segmentation *const seg = &cpi->common.seg;
- unsigned char *const seg_map = cpi->segmentation_map;
+ unsigned char *const seg_map = cpi->enc_seg.map;
const unsigned char *const active_map = cpi->active_map.map;
int i;
@@ -492,7 +492,7 @@
const CommonModeInfoParams *const mi_params = &cpi->common.mi_params;
if (rows == mi_params->mb_rows && cols == mi_params->mb_cols &&
new_map_16x16) {
- unsigned char *const seg_map_8x8 = cpi->segmentation_map;
+ unsigned char *const seg_map_8x8 = cpi->enc_seg.map;
const int mi_rows = mi_params->mi_rows;
const int mi_cols = mi_params->mi_cols;
const int row_scale = mi_size_high[BLOCK_16X16] == 2 ? 1 : 2;
@@ -812,8 +812,8 @@
cpi->tile_data = NULL;
// Delete sementation map
- aom_free(cpi->segmentation_map);
- cpi->segmentation_map = NULL;
+ aom_free(cpi->enc_seg.map);
+ cpi->enc_seg.map = NULL;
av1_cyclic_refresh_free(cpi->cyclic_refresh);
cpi->cyclic_refresh = NULL;
@@ -922,8 +922,7 @@
// Disable and clear down for KF
if (cm->current_frame.frame_type == KEY_FRAME) {
// Clear down the global segmentation map
- memset(cpi->segmentation_map, 0,
- cm->mi_params.mi_rows * cm->mi_params.mi_cols);
+ memset(cpi->enc_seg.map, 0, cm->mi_params.mi_rows * cm->mi_params.mi_cols);
seg->update_map = 0;
seg->update_data = 0;
@@ -935,8 +934,7 @@
} else if (cpi->refresh_alt_ref_frame) {
// If this is an alt ref frame
// Clear down the global segmentation map
- memset(cpi->segmentation_map, 0,
- cm->mi_params.mi_rows * cm->mi_params.mi_cols);
+ memset(cpi->enc_seg.map, 0, cm->mi_params.mi_rows * cm->mi_params.mi_cols);
seg->update_map = 0;
seg->update_data = 0;
@@ -1002,7 +1000,7 @@
av1_disable_segmentation(seg);
- memset(cpi->segmentation_map, 0,
+ memset(cpi->enc_seg.map, 0,
cm->mi_params.mi_rows * cm->mi_params.mi_cols);
seg->update_map = 0;
@@ -2683,8 +2681,8 @@
CommonModeInfoParams *const mi_params = &cm->mi_params;
// Create the encoder segmentation map and set all entries to 0
- aom_free(cpi->segmentation_map);
- CHECK_MEM_ERROR(cm, cpi->segmentation_map,
+ aom_free(cpi->enc_seg.map);
+ CHECK_MEM_ERROR(cm, cpi->enc_seg.map,
aom_calloc(mi_params->mi_rows * mi_params->mi_cols, 1));
// Create a map used for cyclic background refresh.
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 6de08bd..c0cac27 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -1053,6 +1053,17 @@
} FRAME_INFO;
typedef struct {
+ // 3-bit number containing the segment affiliation for each 4x4 block in the
+ // frame. map[y * stride + x] contains the segment id of the 4x4 block at
+ // (x,y) position.
+ uint8_t *map;
+ // Flag to indicate if current frame has lossless segments or not.
+ // 1: frame has at least one lossless segment.
+ // 0: frame has no lossless segments.
+ bool has_lossless_segment;
+} EncSegmentationInfo;
+
+typedef struct {
// Start time stamp of the previous frame
int64_t prev_start_seen;
// End time stamp of the previous frame
@@ -1155,7 +1166,8 @@
int all_one_sided_refs;
- uint8_t *segmentation_map;
+ // Segmentation related information for current frame.
+ EncSegmentationInfo enc_seg;
CYCLIC_REFRESH *cyclic_refresh;
ActiveMap active_map;
@@ -1259,7 +1271,6 @@
int dv_cost[2][MV_VALS];
// TODO(huisu@google.com): we can update dv_joint_cost per SB.
int dv_joint_cost[MV_JOINTS];
- int has_lossless_segment;
// Mark which ref frames can be skipped for encoding current frame druing RDO.
int prune_ref_frame_mask;