summaryrefslogtreecommitdiff
path: root/vp9/encoder/vp9_bitstream.c
diff options
context:
space:
mode:
authorDeb Mukherjee <debargha@google.com>2013-06-06 00:07:06 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2013-06-06 00:07:06 -0700
commit9504f5fac7cce0a7e0df4b7de597e58fa2174c61 (patch)
treeaa95236fd04a8d6a7635e05efcdc0e057aaf4e51 /vp9/encoder/vp9_bitstream.c
parent61e65862308aa8de88fb4eca93195d3c4f461265 (diff)
parent2693704621785ca9f6f722a1de118bb05e7bf2d0 (diff)
downloadlibvpx-9504f5fac7cce0a7e0df4b7de597e58fa2174c61.tar
libvpx-9504f5fac7cce0a7e0df4b7de597e58fa2174c61.tar.gz
libvpx-9504f5fac7cce0a7e0df4b7de597e58fa2174c61.tar.bz2
libvpx-9504f5fac7cce0a7e0df4b7de597e58fa2174c61.zip
Merge "Fix in forward updates for INTRA modes/partitions" into experimental
Diffstat (limited to 'vp9/encoder/vp9_bitstream.c')
-rw-r--r--vp9/encoder/vp9_bitstream.c174
1 files changed, 80 insertions, 94 deletions
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index ff709508f..d8ec293cf 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]