Plumbing for tuning new segment features on and off.
Change-Id: If86cd6f103296b73030e8af7cf85c5b9bbffdbaf
// Segment features
signed char segment_feature_data[MAX_MB_SEGMENTS][SEG_LVL_MAX];
+#if CONFIG_SEGFEATURES
+ unsigned int segment_feature_mask[MAX_MB_SEGMENTS];
+#endif
/* mode_based Loop filter adjustment */
unsigned char mode_ref_lf_delta_enabled;
int lvl_seg = default_filt_lvl;
int lvl_ref, lvl_mode;
- /* Note the baseline filter values for each segment */
- if (mbd->segmentation_enabled)
+
+ // Set the baseline filter values for each segment
+#if CONFIG_SEGFEATURES
+ if ( mbd->segmentation_enabled &&
+ ( mbd->segment_feature_mask[seg] & (1 << SEG_LVL_ALT_LF) ) )
+#else
+ if ( mbd->segmentation_enabled )
+#endif
{
/* Abs value */
if (mbd->mb_segement_abs_delta == SEGMENT_ABSDATA)
{
int i;
int QIndex;
- MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
VP8_COMMON *const pc = & pbi->common;
+ int segment_id = xd->mode_info_context->mbmi.segment_id;
- /* Decide whether to use the default or alternate baseline Q value. */
- if (xd->segmentation_enabled)
+
+ // Set the Q baseline allowing for any segment level adjustment
+#if CONFIG_SEGFEATURES
+ if ( xd->segmentation_enabled &&
+ ( xd->segment_feature_mask[segment_id] & (1 << SEG_LVL_ALT_Q) ) )
+#else
+ if ( xd->segmentation_enabled )
+#endif
{
/* Abs Value */
if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA)
- QIndex = xd->segment_feature_data[mbmi->segment_id][SEG_LVL_ALT_Q];
+ QIndex = xd->segment_feature_data[segment_id][SEG_LVL_ALT_Q];
/* Delta Value */
else
{
QIndex = pc->base_qindex +
- xd->segment_feature_data[mbmi->segment_id][SEG_LVL_ALT_Q];
+ xd->segment_feature_data[segment_id][SEG_LVL_ALT_Q];
QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0; /* Clamp to valid range */
}
}
vp8_default_coef_probs(pc);
vp8_kf_default_bmode_probs(pc->kf_bmode_prob);
- /* reset the segment feature data to 0 with delta coding (Default state). */
- vpx_memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data));
+ // Reset the segment feature data to the default stats:
+ // Features disabled, 0, with delta coding (Default state).
+#if CONFIG_SEGFEATURES
+ vpx_memset(xd->segment_feature_mask, 0,
+ sizeof(xd->segment_feature_mask));
+#endif
+ vpx_memset(xd->segment_feature_data, 0,
+ sizeof(xd->segment_feature_data));
+
xd->mb_segement_abs_delta = SEGMENT_DELTADATA;
/* reset the mode ref deltasa for loop filter */
{
xd->mb_segement_abs_delta = (unsigned char)vp8_read_bit(bc);
- vpx_memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data));
+ // Clear down feature data structure
+ vpx_memset(xd->segment_feature_data, 0,
+ sizeof(xd->segment_feature_data));
#if CONFIG_SEGFEATURES
+ // Clear down feature enabled masks
+ vpx_memset(xd->segment_feature_mask, 0,
+ sizeof(xd->segment_feature_mask));
+
// For each segmentation...
for (j = 0; j < MAX_MB_SEGMENTS; j++)
{
for (j = 0; j < MAX_MB_SEGMENTS; j++)
{
#endif
- /* Frame level data */
+ // Is the feature enabled
if (vp8_read_bit(bc))
{
+#if CONFIG_SEGFEATURES
+ // Update the feature data and mask
+ xd->segment_feature_mask[j] |= (1 << i);
+#endif
+
xd->segment_feature_data[j][i] = (signed char)vp8_read_literal(bc, mb_feature_data_bits[i]);
if (vp8_read_bit(bc))
xd->segment_feature_data[j][i] = -xd->segment_feature_data[j][i];
}
else
+ {
xd->segment_feature_data[j][i] = 0;
+ }
}
}
}
vp8_build_block_doffsets(mbd);
mbd->segmentation_enabled = xd->segmentation_enabled;
mbd->mb_segement_abs_delta = xd->mb_segement_abs_delta;
- vpx_memcpy(mbd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data));
+
+ vpx_memcpy(mbd->segment_feature_data,
+ xd->segment_feature_data,
+ sizeof(xd->segment_feature_data));
+#if CONFIG_SEGFEATURES
+ vpx_memcpy(mbd->segment_feature_mask,
+ xd->segment_feature_mask,
+ sizeof(xd->segment_feature_mask));
+#endif
/*signed char ref_lf_deltas[MAX_REF_LF_DELTAS];*/
vpx_memcpy(mbd->ref_lf_deltas, xd->ref_lf_deltas, sizeof(xd->ref_lf_deltas));
{
Data = xd->segment_feature_data[j][i];
- // Frame level data
+#if CONFIG_SEGFEATURES
+ // If the feature is enabled...
+ if ( xd->segment_feature_mask[j] & (0x01 << i))
+#else
+ // If the feature is enabled...Indicated by non zero
+ // value in VP8
if (Data)
+#endif
{
vp8_write_bit(bc, 1);
+ // Encode the relevant feature data
if (Data < 0)
{
Data = - Data;
zd->subpixel_predict16x16 = xd->subpixel_predict16x16;
zd->segmentation_enabled = xd->segmentation_enabled;
zd->mb_segement_abs_delta = xd->mb_segement_abs_delta;
- vpx_memcpy(zd->segment_feature_data, xd->segment_feature_data, sizeof(xd->segment_feature_data));
+
+ vpx_memcpy(zd->segment_feature_data,
+ xd->segment_feature_data,
+ sizeof(xd->segment_feature_data));
+
+#if CONFIG_SEGFEATURES
+ vpx_memcpy(zd->segment_feature_mask,
+ xd->segment_feature_mask,
+ sizeof(xd->segment_feature_mask));
+#endif
for (i = 0; i < 25; i++)
{
static void setup_features(VP8_COMP *cpi)
{
+ MACROBLOCKD *xd = &cpi->mb.e_mbd;
+
// Set up default state for MB feature flags
#if CONFIG_SEGMENTATION
- cpi->mb.e_mbd.segmentation_enabled = 1;
+ xd->segmentation_enabled = 1;
#else
- cpi->mb.e_mbd.segmentation_enabled = 0;
+ xd->segmentation_enabled = 0;
#endif
- cpi->mb.e_mbd.update_mb_segmentation_map = 0;
- cpi->mb.e_mbd.update_mb_segmentation_data = 0;
- vpx_memset(cpi->mb.e_mbd.mb_segment_tree_probs, 255, sizeof(cpi->mb.e_mbd.mb_segment_tree_probs));
- vpx_memset(cpi->mb.e_mbd.segment_feature_data, 0, sizeof(cpi->mb.e_mbd.segment_feature_data));
+ xd->update_mb_segmentation_map = 0;
+ xd->update_mb_segmentation_data = 0;
+ vpx_memset(xd->mb_segment_tree_probs, 255, sizeof(xd->mb_segment_tree_probs));
+ vpx_memset(xd->segment_feature_data, 0, sizeof(xd->segment_feature_data));
- cpi->mb.e_mbd.mode_ref_lf_delta_enabled = 0;
- cpi->mb.e_mbd.mode_ref_lf_delta_update = 0;
- vpx_memset(cpi->mb.e_mbd.ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
- vpx_memset(cpi->mb.e_mbd.mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));
- vpx_memset(cpi->mb.e_mbd.last_ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
- vpx_memset(cpi->mb.e_mbd.last_mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));
+#if CONFIG_SEGFEATURES
+ vpx_memset(xd->segment_feature_mask, 0, sizeof(xd->segment_feature_mask));
+#endif
+
+ xd->mode_ref_lf_delta_enabled = 0;
+ xd->mode_ref_lf_delta_update = 0;
+ vpx_memset(xd->ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
+ vpx_memset(xd->mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
+ vpx_memset(xd->last_ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
+ vpx_memset(xd->last_mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
set_default_lf_deltas(cpi);
VP8_COMP *cpi = (VP8_COMP *)(ptr);
cpi->mb.e_mbd.mb_segement_abs_delta = abs_delta;
- vpx_memcpy(cpi->segment_feature_data, feature_data, sizeof(cpi->segment_feature_data));
+ vpx_memcpy(cpi->segment_feature_data, feature_data,
+ sizeof(cpi->segment_feature_data));
+
+#if CONFIG_SEGFEATURES
+ // TBD ?? Set the feature mask
+ // vpx_memset(xd->segment_feature_mask, 0, sizeof(xd->segment_feature_mask));
+#endif
+
}
// Segment data (can be deltas or absolute values)
signed char segment_feature_data[MAX_MB_SEGMENTS][SEG_LVL_MAX];
+#if CONFIG_SEGFEATURES
+unsigned int segment_feature_mask[MAX_MB_SEGMENTS];
+#endif
// segment threashold for encode breakout
int segment_encode_breakout[MAX_MB_SEGMENTS];
void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val)
{
MACROBLOCKD *mbd = &cpi->mb.e_mbd;
- (void) filt_val;
+ int i;
- mbd->segment_feature_data[0][SEG_LVL_ALT_LF] = cpi->segment_feature_data[0][SEG_LVL_ALT_LF];
- mbd->segment_feature_data[1][SEG_LVL_ALT_LF] = cpi->segment_feature_data[1][SEG_LVL_ALT_LF];
- mbd->segment_feature_data[2][SEG_LVL_ALT_LF] = cpi->segment_feature_data[2][SEG_LVL_ALT_LF];
- mbd->segment_feature_data[3][SEG_LVL_ALT_LF] = cpi->segment_feature_data[3][SEG_LVL_ALT_LF];
+ for ( i = 0; i < MAX_MB_SEGMENTS; i++ )
+ {
+ mbd->segment_feature_data[i][SEG_LVL_ALT_LF] =
+ cpi->segment_feature_data[i][SEG_LVL_ALT_LF];
+
+#if CONFIG_SEGFEATURES
+ mbd->segment_feature_mask[i] &= ~(1 << SEG_LVL_ALT_LF);
+ mbd->segment_feature_mask[i] |=
+ cpi->segment_feature_mask[i] & (1 << SEG_LVL_ALT_LF);
+#endif
+ }
}
void vp8cx_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi)
int QIndex;
MACROBLOCKD *xd = &x->e_mbd;
int zbin_extra;
+ int segment_id = xd->mode_info_context->mbmi.segment_id;
- // Select the baseline MB Q index.
- if (xd->segmentation_enabled)
+ // Select the baseline MB Q index allowing for any segment level change.
+#if CONFIG_SEGFEATURES
+ if ( xd->segmentation_enabled &&
+ ( xd->segment_feature_mask[segment_id] & (0x01 << SEG_LVL_ALT_Q) ) )
+#else
+ if ( xd->segmentation_enabled )
+#endif
{
// Abs Value
if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA)
+ QIndex = xd->segment_feature_data[segment_id][SEG_LVL_ALT_Q];
- QIndex = xd->segment_feature_data[xd->mode_info_context->mbmi.segment_id][SEG_LVL_ALT_Q];
// Delta Value
else
{
- QIndex = cpi->common.base_qindex + xd->segment_feature_data[xd->mode_info_context->mbmi.segment_id][SEG_LVL_ALT_Q];
- QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0; // Clamp to valid range
+ QIndex = cpi->common.base_qindex +
+ xd->segment_feature_data[segment_id][SEG_LVL_ALT_Q];
+
+ // Clamp to valid range
+ QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0;
}
}
else
MACROBLOCKD *mbd = &cpi->mb.e_mbd;
int update = 0;
int new_delta_q;
+ int i;
cm->base_qindex = Q;
/* if any of the delta_q values are changing update flag has to be set */
cm->y2dc_delta_q = new_delta_q;
- // Set Segment specific quatizers
- mbd->segment_feature_data[0][SEG_LVL_ALT_Q] = cpi->segment_feature_data[0][SEG_LVL_ALT_Q];
- mbd->segment_feature_data[1][SEG_LVL_ALT_Q] = cpi->segment_feature_data[1][SEG_LVL_ALT_Q];
- mbd->segment_feature_data[2][SEG_LVL_ALT_Q] = cpi->segment_feature_data[2][SEG_LVL_ALT_Q];
- mbd->segment_feature_data[3][SEG_LVL_ALT_Q] = cpi->segment_feature_data[3][SEG_LVL_ALT_Q];
+ // Set Segment specific quatizers if enabled
+ for ( i = 0; i < MAX_MB_SEGMENTS; i++ )
+ {
+ mbd->segment_feature_data[i][SEG_LVL_ALT_Q] =
+ cpi->segment_feature_data[i][SEG_LVL_ALT_Q];
+
+#if CONFIG_SEGFEATURES
+ mbd->segment_feature_mask[i] &= ~(1 << SEG_LVL_ALT_Q);
+ mbd->segment_feature_mask[i] |=
+ cpi->segment_feature_mask[i] & (1 << SEG_LVL_ALT_Q);
+#endif
+ }
/* quantizer has to be reinitialized for any delta_q changes */
if(update)