Commit cf8af867 authored by Paul Wilkins's avatar Paul Wilkins
Browse files

Merge COMPRED

Merged in most of the current common prediction changes
that were under the #if CONFIG_COMPRED option.

Change-Id: If4e6f61dbe7b86dd449f6effbe93b5eb7e893885
parent 8266abfe
......@@ -193,10 +193,7 @@ typedef struct
// Flags used for prediction status of various bistream signals
unsigned char seg_id_predicted;
#if CONFIG_COMPRED
unsigned char ref_predicted;
#endif
// Indicates if the mb is part of the image (1) vs border (0)
// This can be useful in determining whether the MB provides
......
......@@ -49,11 +49,7 @@ void vp8_initialize_common(void);
#define MAX_PARTITIONS 9
#if CONFIG_DUALPRED
#if CONFIG_COMPRED
#define DUAL_PRED_CONTEXTS 2
#else
#define DUAL_PRED_CONTEXTS 3
#endif
#endif /* CONFIG_DUALPRED */
typedef struct frame_contexts
......@@ -242,12 +238,10 @@ typedef struct VP8Common
vp8_prob segment_pred_probs[PREDICTION_PROBS];
unsigned char temporal_update;
#if CONFIG_COMPRED
// Context probabilities for reference frame prediction
unsigned char ref_scores[MAX_REF_FRAMES];
vp8_prob ref_pred_probs[PREDICTION_PROBS];
vp8_prob mod_refprobs[MAX_REF_FRAMES][PREDICTION_PROBS];
#endif
#if CONFIG_DUALPRED
vp8_prob prob_dualpred[DUAL_PRED_CONTEXTS];
......
......@@ -32,7 +32,6 @@ unsigned char get_pred_context( VP8_COMMON *const cm,
break;
#if CONFIG_COMPRED
case PRED_REF:
pred_context = (m - 1)->mbmi.ref_predicted +
(m - cm->mode_info_stride)->mbmi.ref_predicted;
......@@ -58,7 +57,6 @@ unsigned char get_pred_context( VP8_COMMON *const cm,
pred_context = 1;
break;
#endif
default:
// TODO *** add error trap code.
......@@ -87,7 +85,6 @@ vp8_prob get_pred_prob( VP8_COMMON *const cm,
pred_probability = cm->segment_pred_probs[pred_context];
break;
#if CONFIG_COMPRED
case PRED_REF:
pred_probability = cm->ref_pred_probs[pred_context];
break;
......@@ -98,7 +95,6 @@ vp8_prob get_pred_prob( VP8_COMMON *const cm,
// probability of dual pred off.
pred_probability = cm->prob_dualpred[pred_context];
break;
#endif
default:
// TODO *** add error trap code.
......@@ -122,12 +118,9 @@ unsigned char get_pred_flag( MACROBLOCKD *const xd,
pred_flag = xd->mode_info_context->mbmi.seg_id_predicted;
break;
#if CONFIG_COMPRED
case PRED_REF:
pred_flag = xd->mode_info_context->mbmi.ref_predicted;
break;
#endif
default:
// TODO *** add error trap code.
......@@ -150,12 +143,9 @@ void set_pred_flag( MACROBLOCKD *const xd,
xd->mode_info_context->mbmi.seg_id_predicted = pred_flag;
break;
#if CONFIG_COMPRED
case PRED_REF:
xd->mode_info_context->mbmi.ref_predicted = pred_flag;
break;
#endif
default:
// TODO *** add error trap code.
......@@ -175,7 +165,6 @@ unsigned char get_pred_mb_segid( VP8_COMMON *const cm, int MbIndex )
return cm->last_frame_seg_map[MbIndex];
}
#if CONFIG_COMPRED
MV_REFERENCE_FRAME get_pred_ref( VP8_COMMON *const cm,
MACROBLOCKD *const xd )
{
......@@ -348,4 +337,3 @@ void compute_mod_refprobs( VP8_COMMON *const cm )
cm->ref_scores[GOLDEN_FRAME] = 1 + (gf_count * 16 / 255);
cm->ref_scores[ALTREF_FRAME] = 1 + (arf_count * 16 / 255);
}
#endif
......@@ -20,11 +20,8 @@
typedef enum
{
PRED_SEG_ID = 0, // Segment identifier
#if CONFIG_COMPRED
PRED_REF = 1,
PRED_DUAL = 2
#endif
} PRED_ID;
......@@ -47,11 +44,8 @@ extern void set_pred_flag( MACROBLOCKD *const xd,
extern unsigned char get_pred_mb_segid( VP8_COMMON *const cm, int MbIndex );
#if CONFIG_COMPRED
extern MV_REFERENCE_FRAME get_pred_ref( VP8_COMMON *const cm,
MACROBLOCKD *const xd );
extern void compute_mod_refprobs( VP8_COMMON *const cm );
#endif
#endif /* __INC_PRED_COMMON_H__ */
......@@ -246,9 +246,6 @@ static MV_REFERENCE_FRAME read_ref_frame( VP8D_COMP *pbi,
segment_id,
SEG_LVL_REF_FRAME );
#if CONFIG_COMPRED
// If segment coding enabled does the segment allow for more than one
// possible reference frame
if ( seg_ref_active )
......@@ -262,11 +259,7 @@ static MV_REFERENCE_FRAME read_ref_frame( VP8D_COMP *pbi,
// Segment reference frame features not available or allows for
// multiple reference frame options
if ( !seg_ref_active || (seg_ref_count > 1) )
#else
if ( !seg_ref_active )
#endif
{
#if CONFIG_COMPRED
// Values used in prediction model coding
unsigned char prediction_flag;
vp8_prob pred_prob;
......@@ -350,102 +343,17 @@ static MV_REFERENCE_FRAME read_ref_frame( VP8D_COMP *pbi,
}
}
}
#else
ref_frame =
(MV_REFERENCE_FRAME) vp8_read(bc, cm->prob_intra_coded);
if (ref_frame)
{
if (vp8_read(bc, cm->prob_last_coded))
{
ref_frame = (MV_REFERENCE_FRAME)((int)ref_frame +
(int)(1 + vp8_read(bc, cm->prob_gf_coded)));
}
}
#endif
}
//#if CONFIG_SEGFEATURES
// Segment reference frame features are enabled
else
{
#if CONFIG_COMPRED
// The reference frame for the mb is considered as correclty predicted
// if it is signaled at the segment level for the purposes of the
// common prediction model
set_pred_flag( xd, PRED_REF, 1 );
ref_frame = get_pred_ref( cm, xd );
#else
// If there are no inter reference frames enabled we can set INTRA
if ( !check_segref_inter(xd, segment_id) )
{
ref_frame = INTRA_FRAME;
}
else
{
// Else if there are both intra and inter options we need to read
// the inter / intra flag, else mark as inter.
if ( check_segref( xd, segment_id, INTRA_FRAME ) )
ref_frame =
(MV_REFERENCE_FRAME) vp8_read(bc, cm->prob_intra_coded);
else
ref_frame = LAST_FRAME;
if ( ref_frame == LAST_FRAME )
{
// Now consider last vs (golden or alt) flag....
// If Last is not enabled
if ( !check_segref( xd, segment_id, LAST_FRAME ) )
{
// If not golden then it must be altref
if (!check_segref( xd, segment_id, GOLDEN_FRAME ))
{
ref_frame = ALTREF_FRAME;
}
// Not Altref therefore must be Golden
else if (!check_segref( xd, segment_id,
ALTREF_FRAME ))
{
ref_frame = GOLDEN_FRAME;
}
// Else we must read bit to decide.
else
{
ref_frame =
(MV_REFERENCE_FRAME)((int)ref_frame +
(int)(1 + vp8_read(bc, cm->prob_gf_coded)));
}
}
// Both last and at least one of alt or golden are enabled
else if ( check_segref( xd, segment_id, GOLDEN_FRAME ) ||
check_segref( xd, segment_id, ALTREF_FRAME ) )
{
// Read flag to indicate (golden or altref) vs last
if (vp8_read(bc, cm->prob_last_coded))
{
// If not golden then it must be altref
if (!check_segref( xd, segment_id, GOLDEN_FRAME ))
{
ref_frame = ALTREF_FRAME;
}
// Not Altref therefore must be Golden
else if (!check_segref( xd, segment_id,
ALTREF_FRAME ))
{
ref_frame = GOLDEN_FRAME;
}
else
{
ref_frame =
(MV_REFERENCE_FRAME)((int)ref_frame +
(int)(1 + vp8_read(bc, cm->prob_gf_coded)));
}
}
// ELSE LAST
}
}
}
#endif
}
return (MV_REFERENCE_FRAME)ref_frame;
......@@ -509,11 +417,9 @@ static void mb_mode_mv_init(VP8D_COMP *pbi)
cm->prob_last_coded = (vp8_prob)vp8_read_literal(bc, 8);
cm->prob_gf_coded = (vp8_prob)vp8_read_literal(bc, 8);
#if CONFIG_COMPRED
// Computes a modified set of probabilities for use when reference
// frame prediction fails.
compute_mod_refprobs( cm );
#endif
#if CONFIG_DUALPRED
pbi->common.dual_pred_mode = vp8_read(bc, 128);
......@@ -837,12 +743,7 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
#if CONFIG_DUALPRED
if ( cm->dual_pred_mode == DUAL_PREDICTION_ONLY ||
(cm->dual_pred_mode == HYBRID_PREDICTION &&
#if CONFIG_COMPRED
vp8_read(bc, get_pred_prob( cm, xd, PRED_DUAL ))) )
#else
vp8_read(bc, cm->prob_dualpred[(mi[-1].mbmi.second_ref_frame != INTRA_FRAME) +
(mi[-mis].mbmi.second_ref_frame != INTRA_FRAME)])))
#endif
{
mbmi->second_ref_frame = mbmi->ref_frame + 1;
if (mbmi->second_ref_frame == 4)
......
......@@ -1239,7 +1239,6 @@ int vp8_decode_frame(VP8D_COMP *pbi)
}
}
#if CONFIG_COMPRED
// Read common prediction model status flag probability updates for the
// reference frame
if ( pc->frame_type == KEY_FRAME )
......@@ -1257,7 +1256,6 @@ int vp8_decode_frame(VP8D_COMP *pbi)
pc->ref_pred_probs[i] = (vp8_prob)vp8_read_literal(bc, 8);
}
}
#endif
/* Read the loop filter level and type */
pc->filter_type = (LOOPFILTERTYPE) vp8_read_bit(bc);
......
......@@ -849,7 +849,6 @@ static void encode_ref_frame( vp8_writer *const w,
segment_id,
SEG_LVL_REF_FRAME );
#if CONFIG_COMPRED
if ( seg_ref_active )
{
seg_ref_count = check_segref( xd, segment_id, INTRA_FRAME ) +
......@@ -861,11 +860,7 @@ static void encode_ref_frame( vp8_writer *const w,
// If segment level coding of this signal is disabled...
// or the segment allows multiple reference frame options
if ( !seg_ref_active || (seg_ref_count > 1) )
#else
if ( !seg_ref_active )
#endif
{
#if CONFIG_COMPRED
// Values used in prediction model coding
unsigned char prediction_flag;
vp8_prob pred_prob;
......@@ -927,77 +922,10 @@ static void encode_ref_frame( vp8_writer *const w,
}
}
}
#else
if (rf == INTRA_FRAME)
{
vp8_write(w, 0, cm->prob_intra_coded);
}
else /* inter coded */
{
vp8_write(w, 1, cm->prob_intra_coded);
if (rf == LAST_FRAME)
{
vp8_write(w, 0, cm->prob_last_coded);
}
else
{
vp8_write(w, 1, cm->prob_last_coded);
vp8_write(w, (rf == GOLDEN_FRAME) ? 0 : 1, cm->prob_gf_coded);
}
}
#endif
}
// if using the prediction mdoel we have nothing further to do because
// the reference frame is fully coded by the segment
//#if CONFIG_SEGFEATURES
#if !CONFIG_COMPRED
// Else use the segment
else
{
if (rf == INTRA_FRAME)
{
// This MB intra coded. If inter also allowed we must code
// an explicit inter/intra flag.
if ( check_segref_inter( xd, segment_id ) )
vp8_write(w, 0, cm->prob_intra_coded);
}
else /* inter coded */
{
// If intra also allowed we must code an explicit intra/inter flag.
if ( check_segref( xd, segment_id, INTRA_FRAME ) )
vp8_write(w, 1, cm->prob_intra_coded);
if (rf == LAST_FRAME)
{
// If GOLDEN or ALTREF allowed we must code explicit flag.
if ( check_segref( xd, segment_id, GOLDEN_FRAME ) ||
check_segref( xd, segment_id, ALTREF_FRAME ) )
{
vp8_write(w, 0, cm->prob_last_coded);
}
}
else
{
// if LAST is allowed we must code explicit flag
if ( check_segref( xd, segment_id, LAST_FRAME ) )
{
vp8_write(w, 1, cm->prob_last_coded);
}
// if GOLDEN and ALTREF allowed we must code an explicit flag
if ( check_segref( xd, segment_id, GOLDEN_FRAME ) &&
check_segref( xd, segment_id, ALTREF_FRAME ) )
{
vp8_write(w, (rf == GOLDEN_FRAME) ? 0 : 1, cm->prob_gf_coded);
}
}
}
}
#endif
}
// Update the probabilities used to encode reference frame data
......@@ -1029,11 +957,9 @@ static void update_ref_probs( VP8_COMP *const cpi )
if (!cm->prob_gf_coded)
cm->prob_gf_coded = 1;
#if CONFIG_COMPRED
// Compute a modified set of probabilities to use when prediction of the
// reference frame fails
compute_mod_refprobs( cm );
#endif
}
#if CONFIG_SUPERBLOCKS
......@@ -1058,12 +984,6 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
int prob_skip_false = 0;
#if CONFIG_DUALPRED
#if !CONFIG_COMPRED
int prob_dual_pred[DUAL_PRED_CONTEXTS];
#endif
#endif /* CONFIG_DUALPRED */
// Values used in prediction model coding
vp8_prob pred_prob;
unsigned char prediction_flag;
......@@ -1114,7 +1034,6 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
{
if (cpi->single_pred_count[i] + cpi->dual_pred_count[i])
{
#if CONFIG_COMPRED
pc->prob_dualpred[i] = cpi->single_pred_count[i] * 255 /
(cpi->single_pred_count[i] + cpi->dual_pred_count[i]);
if (pc->prob_dualpred[i] < 1)
......@@ -1125,20 +1044,6 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
pc->prob_dualpred[i] = 128;
}
vp8_write_literal(w, pc->prob_dualpred[i], 8);
#else
prob_dual_pred[i] = cpi->single_pred_count[i] * 256 /
(cpi->single_pred_count[i] + cpi->dual_pred_count[i]);
if (prob_dual_pred[i] < 1)
prob_dual_pred[i] = 1;
else if (prob_dual_pred[i] > 255)
prob_dual_pred[i] = 255;
}
else
{
prob_dual_pred[i] = 128;
}
vp8_write_literal(w, prob_dual_pred[i], 8);
#endif
}
}
else if (cpi->common.dual_pred_mode == SINGLE_PREDICTION_ONLY)
......@@ -1324,17 +1229,9 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
#if CONFIG_DUALPRED
if (cpi->common.dual_pred_mode == HYBRID_PREDICTION)
{
#if CONFIG_COMPRED
vp8_write(w,
mi->second_ref_frame != INTRA_FRAME,
get_pred_prob( pc, xd, PRED_DUAL ) );
#else
int t = m[-mis].mbmi.second_ref_frame != INTRA_FRAME;
int l = m[-1 ].mbmi.second_ref_frame != INTRA_FRAME;
vp8_write(w, mi->second_ref_frame != INTRA_FRAME,
prob_dual_pred[t + l]);
#endif
}
if (mi->second_ref_frame)
{
......@@ -1400,17 +1297,9 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
#if CONFIG_DUALPRED
if (cpi->common.dual_pred_mode == HYBRID_PREDICTION)
{
#if CONFIG_COMPRED
vp8_write(w,
mi->second_ref_frame != INTRA_FRAME,
get_pred_prob( pc, xd, PRED_DUAL ) );
#else
int t = m[-mis].mbmi.second_ref_frame != INTRA_FRAME;
int l = m[-1 ].mbmi.second_ref_frame != INTRA_FRAME;
vp8_write(w, mi->second_ref_frame != INTRA_FRAME,
prob_dual_pred[t + l]);
#endif
}
#endif /* CONFIG_DUALPRED */
break;
......@@ -1434,17 +1323,6 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
m += mis + (1- (pc->mb_cols & 0x1));
cpi->mb.partition_info += mis + (1- (pc->mb_cols & 0x1));
}
#if !CONFIG_COMPRED
#if CONFIG_DUALPRED
if (cpi->common.dual_pred_mode == HYBRID_PREDICTION)
{
pc->prob_dualpred[0] = (prob_dual_pred[0] + pc->prob_dualpred[0] + 1) >> 1;
pc->prob_dualpred[1] = (prob_dual_pred[1] + pc->prob_dualpred[1] + 1) >> 1;
pc->prob_dualpred[2] = (prob_dual_pred[2] + pc->prob_dualpred[2] + 1) >> 1;
}
#endif /* CONFIG_DUALPRED */
#endif
}
#else
static void pack_inter_mode_mvs(VP8_COMP *const cpi)
......@@ -1468,12 +1346,6 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
int prob_skip_false = 0;
#if CONFIG_DUALPRED
#if !CONFIG_COMPRED
int prob_dual_pred[DUAL_PRED_CONTEXTS];
#endif
#endif /* CONFIG_DUALPRED */
// Values used in prediction model coding
vp8_prob pred_prob;
unsigned char prediction_flag;
......@@ -1521,7 +1393,6 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
{
if (cpi->single_pred_count[i] + cpi->dual_pred_count[i])
{
#if CONFIG_COMPRED
pc->prob_dualpred[i] = cpi->single_pred_count[i] * 255 /
(cpi->single_pred_count[i] + cpi->dual_pred_count[i]);
if (pc->prob_dualpred[i] < 1)
......@@ -1532,20 +1403,6 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
pc->prob_dualpred[i] = 128;
}
vp8_write_literal(w, pc->prob_dualpred[i], 8);
#else
prob_dual_pred[i] = cpi->single_pred_count[i] * 256 /
(cpi->single_pred_count[i] + cpi->dual_pred_count[i]);
if (prob_dual_pred[i] < 1)
prob_dual_pred[i] = 1;
else if (prob_dual_pred[i] > 255)
prob_dual_pred[i] = 255;
}
else
{
prob_dual_pred[i] = 128;
}
vp8_write_literal(w, prob_dual_pred[i], 8);
#endif
}
}
else if (cpi->common.dual_pred_mode == SINGLE_PREDICTION_ONLY)
......@@ -1711,16 +1568,8 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
#if CONFIG_DUALPRED
if (cpi->common.dual_pred_mode == HYBRID_PREDICTION)
{
#if CONFIG_COMPRED
vp8_write(w, mi->second_ref_frame != INTRA_FRAME,
get_pred_prob( pc, xd, PRED_DUAL ) );
#else
int t = m[-mis].mbmi.second_ref_frame != INTRA_FRAME;
int l = m[-1 ].mbmi.second_ref_frame != INTRA_FRAME;
vp8_write(w, mi->second_ref_frame != INTRA_FRAME,
prob_dual_pred[t + l]);
#endif
}
if (mi->second_ref_frame)
{
......@@ -1785,16 +1634,8 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
#if CONFIG_DUALPRED
if (cpi->common.dual_pred_mode == HYBRID_PREDICTION)
{
#if CONFIG_COMPRED
vp8_write(w, mi->second_ref_frame != INTRA_FRAME,
get_pred_prob( pc, xd, PRED_DUAL ) );
#else
int t = m[-mis].mbmi.second_ref_frame != INTRA_FRAME;
int l = m[-1 ].mbmi.second_ref_frame != INTRA_FRAME;
vp8_write(w, mi->second_ref_frame != INTRA_FRAME,
prob_dual_pred[t + l]);
#endif
}
#endif /* CONFIG_DUALPRED */
break;
......@@ -1813,17 +1654,6 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
++prev_m;
cpi->mb.partition_info++;
}
#if !CONFIG_COMPRED
#if CONFIG_DUALPRED
if (cpi->common.dual_pred_mode == HYBRID_PREDICTION)
{
pc->prob_dualpred[0] = (prob_dual_pred[0] + pc->prob_dualpred[0] + 1) >> 1;
pc->prob_dualpred[1] = (prob_dual_pred[1] + pc->prob_dualpred[1] + 1) >> 1;
pc->prob_dualpred[2] = (prob_dual_pred[2] + pc->prob_dualpred[2] + 1) >> 1;
}
#endif /* CONFIG_DUALPRED */
#endif
}
#endif // CONFIG_SUPERBLOCKS
......@@ -2258,9 +2088,6 @@ static int default_coef_context_savings(VP8_COMP *cpi)
return savings;
}
#if CONFIG_COMPRED
// TODO... this will all need changing for new reference frame coding model
#endif
int vp8_estimate_entropy_savings(VP8_COMP *cpi)
{
int savings = 0;
......@@ -2851,7 +2678,6 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
}
}
#if CONFIG_COMPRED
// Encode the common prediction model status flag probability updates for
// the reference frame
if ( pc->frame_type != KEY_FRAME )
......@@ -2867,7 +2693,6 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
vp8_write_bit(bc, 0);
}
}
#endif
// Encode the loop filter level and type
vp8_write_bit(bc, pc->filter_type);
......
......@@ -1181,12 +1181,10 @@ static void encode_frame_internal(VP8_COMP *cpi)
TOKENEXTRA *tp = cpi->tok;
int totalrate;
#if CONFIG_COMPRED
// Compute a modified set of reference frame probabilities to use when
// prediction fails. These are based on the current genreal estimates for
// this frame which may be updated with each itteration of the recode loop.
compute_mod_refprobs( cm );
#endif
//#if CONFIG_SEGFEATURES
// debug output
......@@ -1785,9 +1783,7 @@ int vp8cx_encode_inter_macroblock
int distortion;
unsigned char *segment_id = &xd->mode_info_context->mbmi.segment_id;
int seg_ref_active;