diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index d91a319c0d6039d14b8e1240eccbc73db0cbbd1d..7e2f69105a030155b3145f70ddb0c350e6313eb7 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -404,14 +404,20 @@ static void mb_mode_mv_init(VP9D_COMP *pbi, vp9_reader *r) { cm->prob_comppred[i] = vp9_read_prob(r); // VP9_INTRA_MODES - if (vp9_read_bit(r)) - for (i = 0; i < VP9_INTRA_MODES - 1; ++i) - cm->fc.y_mode_prob[i] = vp9_read_prob(r); - - for (j = 0; j < NUM_PARTITION_CONTEXTS; ++j) - if (vp9_read_bit(r)) - for (i = 0; i < PARTITION_TYPES - 1; ++i) - cm->fc.partition_prob[j][i] = vp9_read_prob(r); + for (i = 0; i < VP9_INTRA_MODES - 1; ++i) { + if (vp9_read(r, VP9_DEF_UPDATE_PROB)) { + cm->fc.y_mode_prob[i] = + vp9_read_prob_diff_update(r, cm->fc.y_mode_prob[i]); + } + } + for (j = 0; j < NUM_PARTITION_CONTEXTS; ++j) { + for (i = 0; i < PARTITION_TYPES - 1; ++i) { + if (vp9_read(r, VP9_DEF_UPDATE_PROB)) { + cm->fc.partition_prob[j][i] = + vp9_read_prob_diff_update(r, cm->fc.partition_prob[j][i]); + } + } + } read_nmvprobs(r, nmvc, xd->allow_high_precision_mv); } diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 2f6d4ad2df4d617511d265a92632196fc595b2ec..97034ebb605932546d663dce0ee5655501a774e6 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -203,100 +203,6 @@ static int prob_diff_update_cost(vp9_prob newp, vp9_prob oldp) { return update_bits[delp] * 256; } -static void update_mode( - vp9_writer *w, - int n, - const struct vp9_token tok[/* n */], - vp9_tree tree, - vp9_prob Pnew [/* n-1 */], - vp9_prob Pcur [/* n-1 */], - unsigned int bct [/* n-1 */] [2], - const unsigned int num_events[/* n */] -) { - unsigned int new_b = 0, old_b = 0; - int i = 0; - - vp9_tree_probs_from_distribution(tree, Pnew, bct, num_events, 0); - n--; - - do { - new_b += cost_branch(bct[i], Pnew[i]); - old_b += cost_branch(bct[i], Pcur[i]); - } while (++i < n); - - if (new_b + (n << 8) < old_b) { - int i = 0; - - vp9_write_bit(w, 1); - - do { - const vp9_prob p = Pnew[i]; - - vp9_write_literal(w, Pcur[i] = p ? p : 1, 8); - } while (++i < n); - } else - vp9_write_bit(w, 0); -} - -static void update_mbintra_mode_probs(VP9_COMP* const cpi, - vp9_writer* const bc) { - VP9_COMMON *const cm = &cpi->common; - - vp9_prob pnew[VP9_INTRA_MODES - 1]; - unsigned int bct[VP9_INTRA_MODES - 1][2]; - - update_mode(bc, VP9_INTRA_MODES, vp9_intra_mode_encodings, - vp9_intra_mode_tree, pnew, - cm->fc.y_mode_prob, bct, (unsigned int *)cpi->y_mode_count); -} - -void vp9_update_skip_probs(VP9_COMP *cpi) { - VP9_COMMON *const pc = &cpi->common; - int k; - - for (k = 0; k < MBSKIP_CONTEXTS; ++k) - pc->mbskip_pred_probs[k] = get_binary_prob(cpi->skip_false_count[k], - cpi->skip_true_count[k]); -} - -// This function updates the reference frame prediction stats -static void update_refpred_stats(VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; - int i; - vp9_prob new_pred_probs[PREDICTION_PROBS]; - int old_cost, new_cost; - - // Set the prediction probability structures to defaults - if (cm->frame_type != KEY_FRAME) { - // From the prediction counts set the probabilities for each context - for (i = 0; i < PREDICTION_PROBS; i++) { - const int c0 = cpi->ref_pred_count[i][0]; - const int c1 = cpi->ref_pred_count[i][1]; - - new_pred_probs[i] = get_binary_prob(c0, c1); - - // Decide whether or not to update the reference frame probs. - // Returned costs are in 1/256 bit units. - old_cost = c0 * vp9_cost_zero(cm->ref_pred_probs[i]) + - c1 * vp9_cost_one(cm->ref_pred_probs[i]); - - new_cost = c0 * vp9_cost_zero(new_pred_probs[i]) + - c1 * vp9_cost_one(new_pred_probs[i]); - - // Cost saving must be >= 8 bits (2048 in these units) - if ((old_cost - new_cost) >= 2048) { - cpi->ref_pred_probs_update[i] = 1; - cm->ref_pred_probs[i] = new_pred_probs[i]; - } else - cpi->ref_pred_probs_update[i] = 0; - } - } -} - -static void write_intra_mode(vp9_writer *bc, int m, const vp9_prob *p) { - write_token(bc, vp9_intra_mode_tree, p, vp9_intra_mode_encodings + m); -} - static int prob_update_savings(const unsigned int *ct, const vp9_prob oldp, const vp9_prob newp, const vp9_prob upd) { @@ -401,6 +307,86 @@ static void vp9_cond_prob_diff_update(vp9_writer *bc, vp9_prob *oldp, } } +static void update_mode( + vp9_writer *w, + int n, + const struct vp9_token tok[/* n */], + vp9_tree tree, + vp9_prob Pnew[/* n-1 */], + vp9_prob Pcur[/* n-1 */], + unsigned int bct[/* n-1 */] [2], + const unsigned int num_events[/* n */] +) { + int i = 0; + + vp9_tree_probs_from_distribution(tree, Pnew, bct, num_events, 0); + n--; + + for (i = 0; i < n; ++i) { + vp9_cond_prob_diff_update(w, &Pcur[i], VP9_DEF_UPDATE_PROB, bct[i]); + } +} + +static void update_mbintra_mode_probs(VP9_COMP* const cpi, + vp9_writer* const bc) { + VP9_COMMON *const cm = &cpi->common; + + vp9_prob pnew[VP9_INTRA_MODES - 1]; + unsigned int bct[VP9_INTRA_MODES - 1][2]; + + update_mode(bc, VP9_INTRA_MODES, vp9_intra_mode_encodings, + vp9_intra_mode_tree, pnew, + cm->fc.y_mode_prob, bct, (unsigned int *)cpi->y_mode_count); +} + +void vp9_update_skip_probs(VP9_COMP *cpi) { + VP9_COMMON *const pc = &cpi->common; + int k; + + for (k = 0; k < MBSKIP_CONTEXTS; ++k) + pc->mbskip_pred_probs[k] = get_binary_prob(cpi->skip_false_count[k], + cpi->skip_true_count[k]); +} + +// This function updates the reference frame prediction stats +static void update_refpred_stats(VP9_COMP *cpi) { + VP9_COMMON *const cm = &cpi->common; + int i; + vp9_prob new_pred_probs[PREDICTION_PROBS]; + int old_cost, new_cost; + + // Set the prediction probability structures to defaults + if (cm->frame_type != KEY_FRAME) { + // From the prediction counts set the probabilities for each context + for (i = 0; i < PREDICTION_PROBS; i++) { + const int c0 = cpi->ref_pred_count[i][0]; + const int c1 = cpi->ref_pred_count[i][1]; + + new_pred_probs[i] = get_binary_prob(c0, c1); + + // Decide whether or not to update the reference frame probs. + // Returned costs are in 1/256 bit units. + old_cost = c0 * vp9_cost_zero(cm->ref_pred_probs[i]) + + c1 * vp9_cost_one(cm->ref_pred_probs[i]); + + new_cost = c0 * vp9_cost_zero(new_pred_probs[i]) + + c1 * vp9_cost_one(new_pred_probs[i]); + + // Cost saving must be >= 8 bits (2048 in these units) + if ((old_cost - new_cost) >= 2048) { + cpi->ref_pred_probs_update[i] = 1; + cm->ref_pred_probs[i] = new_pred_probs[i]; + } else { + cpi->ref_pred_probs_update[i] = 0; + } + } + } +} + +static void write_intra_mode(vp9_writer *bc, int m, const vp9_prob *p) { + write_token(bc, vp9_intra_mode_tree, p, vp9_intra_mode_encodings + m); +} + static void update_switchable_interp_probs(VP9_COMMON *const pc, vp9_writer* const bc) { unsigned int branch_ct[VP9_SWITCHABLE_FILTERS + 1]