summaryrefslogtreecommitdiff
path: root/vp8/encoder
diff options
context:
space:
mode:
authorJohn Koleszar <jkoleszar@google.com>2012-10-19 15:35:36 -0700
committerJohn Koleszar <jkoleszar@google.com>2012-10-24 09:41:04 -0700
commit226e55c17d6f732911c1b9282c6dfc334496204d (patch)
tree9a1f273fb299445b9405a397878257a17b402fcd /vp8/encoder
parent6baa2b47ebfb4d8cbbe8e20eceb6a534bc56e1e3 (diff)
downloadlibvpx-226e55c17d6f732911c1b9282c6dfc334496204d.tar
libvpx-226e55c17d6f732911c1b9282c6dfc334496204d.tar.gz
libvpx-226e55c17d6f732911c1b9282c6dfc334496204d.tar.bz2
libvpx-226e55c17d6f732911c1b9282c6dfc334496204d.zip
coef_probs: remove duplicate read/update code
Refactor per-transform copy & paste into a common function update_coef_probs_common() and read_coef_probs_common(). The dry-run and bit-writing loops in the encoder are still obvious candidates to be made common, but they start to diverge a bit in the next commit, so are left as-is for now. Change-Id: I896bd3f4a073a6296eab7e92463fef79d8c6c08c
Diffstat (limited to 'vp8/encoder')
-rw-r--r--vp8/encoder/bitstream.c625
1 files changed, 54 insertions, 571 deletions
diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c
index 36776ab21..758c9736c 100644
--- a/vp8/encoder/bitstream.c
+++ b/vp8/encoder/bitstream.c
@@ -1494,185 +1494,17 @@ void build_coeff_contexts(VP8_COMP *cpi) {
}
}
-#if 0
-static void update_coef_probs2(VP8_COMP *cpi) {
- const vp8_prob grpupd = 192;
- int i, j, k, t;
- vp8_writer *const w = &cpi->bc;
- int update[2];
- int savings;
-
- vp8_clear_system_state(); // __asm emms;
- // Build the cofficient contexts based on counts collected in encode loop
- build_coeff_contexts(cpi);
-
- for (t = 0; t < ENTROPY_NODES; ++t) {
- /* dry run to see if there is any udpate at all needed */
- savings = 0;
- update[0] = update[1] = 0;
- for (i = 0; i < BLOCK_TYPES; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- vp8_prob newp = cpi->frame_coef_probs [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs [i][j][k] + t;
- const vp8_prob upd = COEF_UPDATE_PROB;
- int s;
- int u = 0;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(
- cpi->frame_branch_ct [i][j][k][t], *Pold, &newp, upd);
- if (s > 0 && newp != *Pold) u = 1;
- if (u)
- savings += s - (int)(vp8_cost_zero(upd));
- else
- savings -= (int)(vp8_cost_zero(upd));
-#else
- s = prob_update_savings(
- cpi->frame_branch_ct [i][j][k][t], *Pold, newp, upd);
- if (s > 0) u = 1;
- if (u)
- savings += s;
-#endif
- // printf(" %d %d %d: %d\n", i, j, k, u);
- update[u]++;
- }
- }
- }
- if (update[1] == 0 || savings < 0) {
- vp8_write(w, 0, grpupd);
- continue;
- }
- vp8_write(w, 1, grpupd);
- for (i = 0; i < BLOCK_TYPES; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- vp8_prob newp = cpi->frame_coef_probs [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs [i][j][k] + t;
- const vp8_prob upd = COEF_UPDATE_PROB;
- int s;
- int u = 0;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(
- cpi->frame_branch_ct [i][j][k][t], *Pold, &newp, upd);
- if (s > 0 && newp != *Pold) u = 1;
-#else
- s = prob_update_savings(
- cpi->frame_branch_ct [i][j][k][t], *Pold, newp, upd);
- if (s > 0) u = 1;
-#endif
- // printf(" %d %d %d: %d (%d)\n", i, j, k, u, upd);
- vp8_write(w, u, upd);
-#ifdef ENTROPY_STATS
- ++ tree_update_hist [i][j][k][t] [u];
-#endif
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(w, newp, *Pold);
- *Pold = newp;
- }
- }
- }
- }
- }
-
- if (cpi->common.txfm_mode != ONLY_4X4)
- for (t = 0; t < ENTROPY_NODES; ++t) {
- /* dry run to see if there is any udpate at all needed */
- savings = 0;
- update[0] = update[1] = 0;
- for (i = 0; i < BLOCK_TYPES_8X8; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- vp8_prob newp = cpi->frame_coef_probs_8x8 [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs_8x8 [i][j][k] + t;
- const vp8_prob upd = COEF_UPDATE_PROB_8X8;
- int s;
- int u = 0;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(
- cpi->frame_branch_ct_8x8 [i][j][k][t],
- *Pold, &newp, upd);
- if (s > 0 && newp != *Pold)
- u = 1;
- if (u)
- savings += s - (int)(vp8_cost_zero(upd));
- else
- savings -= (int)(vp8_cost_zero(upd));
-#else
- s = prob_update_savings(
- cpi->frame_branch_ct_8x8 [i][j][k][t],
- *Pold, newp, upd);
- if (s > 0)
- u = 1;
- if (u)
- savings += s;
-#endif
- update[u]++;
- }
- }
- }
- if (update[1] == 0 || savings < 0) {
- vp8_write(w, 0, grpupd);
- continue;
- }
- vp8_write(w, 1, grpupd);
- for (i = 0; i < BLOCK_TYPES_8X8; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- vp8_prob newp = cpi->frame_coef_probs_8x8 [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs_8x8 [i][j][k] + t;
- const vp8_prob upd = COEF_UPDATE_PROB_8X8;
- int s;
- int u = 0;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(
- cpi->frame_branch_ct_8x8 [i][j][k][t],
- *Pold, &newp, upd);
- if (s > 0 && newp != *Pold)
- u = 1;
-#else
- s = prob_update_savings(
- cpi->frame_branch_ct_8x8 [i][j][k][t],
- *Pold, newp, upd);
- if (s > 0)
- u = 1;
-#endif
- vp8_write(w, u, upd);
-#ifdef ENTROPY_STATS
- if (!cpi->dummy_packing)
- ++ tree_update_hist_8x8 [i][j][k][t] [u];
-#endif
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(w, newp, *Pold);
- *Pold = newp;
- }
- }
- }
- }
- }
-}
-#endif
-
-static void update_coef_probs(VP8_COMP* const cpi, vp8_writer* const bc) {
+static void update_coef_probs_common(
+ vp8_writer* const bc,
+ vp8_prob new_frame_coef_probs[BLOCK_TYPES][COEF_BANDS]
+ [PREV_COEF_CONTEXTS][ENTROPY_NODES],
+ vp8_prob old_frame_coef_probs[BLOCK_TYPES][COEF_BANDS]
+ [PREV_COEF_CONTEXTS][ENTROPY_NODES],
+ unsigned int frame_branch_ct[BLOCK_TYPES][COEF_BANDS]
+ [PREV_COEF_CONTEXTS][ENTROPY_NODES][2]) {
int i, j, k, t;
int update[2] = {0, 0};
int savings;
-
- vp8_clear_system_state(); // __asm emms;
-
- // Build the cofficient contexts based on counts collected in encode loop
- build_coeff_contexts(cpi);
-
// vp8_prob bestupd = find_coef_update_prob(cpi);
/* dry run to see if there is any udpate at all needed */
@@ -1682,8 +1514,8 @@ static void update_coef_probs(VP8_COMP* const cpi, vp8_writer* const bc) {
int prev_coef_savings[ENTROPY_NODES] = {0};
for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
for (t = 0; t < ENTROPY_NODES; ++t) {
- vp8_prob newp = cpi->frame_coef_probs [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs [i][j][k] + t;
+ vp8_prob newp = new_frame_coef_probs[i][j][k][t];
+ const vp8_prob oldp = old_frame_coef_probs[i][j][k][t];
const vp8_prob upd = COEF_UPDATE_PROB;
int s = prev_coef_savings[t];
int u = 0;
@@ -1691,9 +1523,9 @@ static void update_coef_probs(VP8_COMP* const cpi, vp8_writer* const bc) {
continue;
#if defined(SEARCH_NEWP)
s = prob_diff_update_savings_search(
- cpi->frame_branch_ct [i][j][k][t],
- *Pold, &newp, upd);
- if (s > 0 && newp != *Pold)
+ frame_branch_ct[i][j][k][t],
+ oldp, &newp, upd);
+ if (s > 0 && newp != oldp)
u = 1;
if (u)
savings += s - (int)(vp8_cost_zero(upd));
@@ -1701,8 +1533,8 @@ static void update_coef_probs(VP8_COMP* const cpi, vp8_writer* const bc) {
savings -= (int)(vp8_cost_zero(upd));
#else
s = prob_update_savings(
- cpi->frame_branch_ct [i][j][k][t],
- *Pold, newp, upd);
+ frame_branch_ct[i][j][k][t],
+ oldp, newp, upd);
if (s > 0)
u = 1;
if (u)
@@ -1727,8 +1559,8 @@ static void update_coef_probs(VP8_COMP* const cpi, vp8_writer* const bc) {
for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
// calc probs and branch cts for this frame only
for (t = 0; t < ENTROPY_NODES; ++t) {
- vp8_prob newp = cpi->frame_coef_probs [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs [i][j][k] + t;
+ vp8_prob newp = new_frame_coef_probs[i][j][k][t];
+ vp8_prob *oldp = old_frame_coef_probs[i][j][k] + t;
const vp8_prob upd = COEF_UPDATE_PROB;
int s = prev_coef_savings[t];
int u = 0;
@@ -1737,14 +1569,14 @@ static void update_coef_probs(VP8_COMP* const cpi, vp8_writer* const bc) {
#if defined(SEARCH_NEWP)
s = prob_diff_update_savings_search(
- cpi->frame_branch_ct [i][j][k][t],
- *Pold, &newp, upd);
- if (s > 0 && newp != *Pold)
+ frame_branch_ct[i][j][k][t],
+ *oldp, &newp, upd);
+ if (s > 0 && newp != *oldp)
u = 1;
#else
s = prob_update_savings(
- cpi->frame_branch_ct [i][j][k][t],
- *Pold, newp, upd);
+ frame_branch_ct[i][j][k][t],
+ *oldp, newp, upd);
if (s > 0)
u = 1;
#endif
@@ -1755,403 +1587,54 @@ static void update_coef_probs(VP8_COMP* const cpi, vp8_writer* const bc) {
#endif
if (u) {
/* send/use new probability */
- write_prob_diff_update(bc, newp, *Pold);
- *Pold = newp;
+ write_prob_diff_update(bc, newp, *oldp);
+ *oldp = newp;
}
}
}
}
}
}
+}
- savings = 0;
- update[0] = update[1] = 0;
- for (i = 0; i < BLOCK_TYPES; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- int prev_coef_savings[ENTROPY_NODES] = {0};
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- for (t = 0; t < ENTROPY_NODES; ++t) {
- vp8_prob newp = cpi->frame_hybrid_coef_probs [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.hybrid_coef_probs [i][j][k] + t;
- const vp8_prob upd = COEF_UPDATE_PROB;
- int s = prev_coef_savings[t];
- int u = 0;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(
- cpi->frame_hybrid_branch_ct [i][j][k][t],
- *Pold, &newp, upd);
- if (s > 0 && newp != *Pold)
- u = 1;
- if (u)
- savings += s - (int)(vp8_cost_zero(upd));
- else
- savings -= (int)(vp8_cost_zero(upd));
-#else
- s = prob_update_savings(
- cpi->frame_hybrid_branch_ct [i][j][k][t],
- *Pold, newp, upd);
- if (s > 0)
- u = 1;
- if (u)
- savings += s;
-#endif
+static void update_coef_probs(VP8_COMP* const cpi, vp8_writer* const bc) {
+ vp8_clear_system_state();
- update[u]++;
- }
- }
- }
- }
+ // Build the cofficient contexts based on counts collected in encode loop
+ build_coeff_contexts(cpi);
- // printf("Update %d %d, savings %d\n", update[0], update[1], savings);
- /* Is coef updated at all */
- if (update[1] == 0 || savings < 0) {
- vp8_write_bit(bc, 0);
- } else {
- vp8_write_bit(bc, 1);
- for (i = 0; i < BLOCK_TYPES; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- int prev_coef_savings[ENTROPY_NODES] = {0};
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- // calc probs and branch cts for this frame only
- for (t = 0; t < ENTROPY_NODES; ++t) {
- vp8_prob newp = cpi->frame_hybrid_coef_probs [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.hybrid_coef_probs [i][j][k] + t;
- const vp8_prob upd = COEF_UPDATE_PROB;
- int s = prev_coef_savings[t];
- int u = 0;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
+ update_coef_probs_common(bc,
+ cpi->frame_coef_probs,
+ cpi->common.fc.coef_probs,
+ cpi->frame_branch_ct);
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(
- cpi->frame_hybrid_branch_ct [i][j][k][t],
- *Pold, &newp, upd);
- if (s > 0 && newp != *Pold)
- u = 1;
-#else
- s = prob_update_savings(
- cpi->frame_hybrid_branch_ct [i][j][k][t],
- *Pold, newp, upd);
- if (s > 0)
- u = 1;
-#endif
- vp8_write(bc, u, upd);
-#ifdef ENTROPY_STATS
- if (!cpi->dummy_packing)
- ++ hybrid_tree_update_hist [i][j][k][t] [u];
-#endif
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(bc, newp, *Pold);
- *Pold = newp;
- }
- }
- }
- }
- }
- }
+ update_coef_probs_common(bc,
+ cpi->frame_hybrid_coef_probs,
+ cpi->common.fc.hybrid_coef_probs,
+ cpi->frame_hybrid_branch_ct);
/* do not do this if not even allowed */
if (cpi->common.txfm_mode != ONLY_4X4) {
- /* dry run to see if update is necessary */
- update[0] = update[1] = 0;
- savings = 0;
- for (i = 0; i < BLOCK_TYPES_8X8; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- // calc probs and branch cts for this frame only
- for (t = 0; t < ENTROPY_NODES; ++t) {
- const unsigned int *ct = cpi->frame_branch_ct_8x8 [i][j][k][t];
- vp8_prob newp = cpi->frame_coef_probs_8x8 [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs_8x8 [i][j][k] + t;
- const vp8_prob oldp = *Pold;
- int s, u;
- const vp8_prob upd = COEF_UPDATE_PROB_8X8;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(ct, oldp, &newp, upd);
- u = s > 0 && newp != oldp ? 1 : 0;
- if (u)
- savings += s - (int)(vp8_cost_zero(upd));
- else
- savings -= (int)(vp8_cost_zero(upd));
-#else
- s = prob_update_savings(ct, oldp, newp, upd);
- u = s > 0 ? 1 : 0;
- if (u)
- savings += s;
-#endif
- update[u]++;
- }
- }
- }
- }
-
- if (update[1] == 0 || savings < 0) {
- vp8_write_bit(bc, 0);
- } else {
- vp8_write_bit(bc, 1);
- for (i = 0; i < BLOCK_TYPES_8X8; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- for (t = 0; t < ENTROPY_NODES; ++t) {
- const unsigned int *ct = cpi->frame_branch_ct_8x8 [i][j][k][t];
- vp8_prob newp = cpi->frame_coef_probs_8x8 [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs_8x8 [i][j][k] + t;
- const vp8_prob oldp = *Pold;
- const vp8_prob upd = COEF_UPDATE_PROB_8X8;
- int s, u;
- if (k >= 3 && ((i == 0 && j == 1) ||
- (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(ct, oldp, &newp, upd);
- u = s > 0 && newp != oldp ? 1 : 0;
-#else
- s = prob_update_savings(ct, oldp, newp, upd);
- u = s > 0 ? 1 : 0;
-#endif
- vp8_write(bc, u, upd);
-#ifdef ENTROPY_STATS
- if (!cpi->dummy_packing)
- ++ tree_update_hist_8x8 [i][j][k][t] [u];
-#endif
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(bc, newp, oldp);
- *Pold = newp;
- }
- }
- }
- }
- }
- }
- update[0] = update[1] = 0;
- savings = 0;
- for (i = 0; i < BLOCK_TYPES_8X8; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- // calc probs and branch cts for this frame only
- for (t = 0; t < ENTROPY_NODES; ++t) {
- const unsigned int *ct = cpi->frame_hybrid_branch_ct_8x8 [i][j][k][t];
- vp8_prob newp = cpi->frame_hybrid_coef_probs_8x8 [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.hybrid_coef_probs_8x8 [i][j][k] + t;
- const vp8_prob oldp = *Pold;
- int s, u;
- const vp8_prob upd = COEF_UPDATE_PROB_8X8;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(ct, oldp, &newp, upd);
- u = s > 0 && newp != oldp ? 1 : 0;
- if (u)
- savings += s - (int)(vp8_cost_zero(upd));
- else
- savings -= (int)(vp8_cost_zero(upd));
-#else
- s = prob_update_savings(ct, oldp, newp, upd);
- u = s > 0 ? 1 : 0;
- if (u)
- savings += s;
-#endif
- update[u]++;
- }
- }
- }
- }
-
- if (update[1] == 0 || savings < 0) {
- vp8_write_bit(bc, 0);
- } else {
- vp8_write_bit(bc, 1);
- for (i = 0; i < BLOCK_TYPES_8X8; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- for (t = 0; t < ENTROPY_NODES; ++t) {
- const unsigned int *ct = cpi->frame_hybrid_branch_ct_8x8 [i][j][k][t];
- vp8_prob newp = cpi->frame_hybrid_coef_probs_8x8 [i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.hybrid_coef_probs_8x8 [i][j][k] + t;
- const vp8_prob oldp = *Pold;
- const vp8_prob upd = COEF_UPDATE_PROB_8X8;
- int s, u;
- if (k >= 3 && ((i == 0 && j == 1) ||
- (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(ct, oldp, &newp, upd);
- u = s > 0 && newp != oldp ? 1 : 0;
-#else
- s = prob_update_savings(ct, oldp, newp, upd);
- u = s > 0 ? 1 : 0;
-#endif
- vp8_write(bc, u, upd);
-#ifdef ENTROPY_STATS
- if (!cpi->dummy_packing)
- ++ hybrid_tree_update_hist_8x8 [i][j][k][t] [u];
-#endif
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(bc, newp, oldp);
- *Pold = newp;
- }
- }
- }
- }
- }
- }
+ update_coef_probs_common(bc,
+ cpi->frame_coef_probs_8x8,
+ cpi->common.fc.coef_probs_8x8,
+ cpi->frame_branch_ct_8x8);
+
+ update_coef_probs_common(bc,
+ cpi->frame_hybrid_coef_probs_8x8,
+ cpi->common.fc.hybrid_coef_probs_8x8,
+ cpi->frame_hybrid_branch_ct_8x8);
}
if (cpi->common.txfm_mode > ALLOW_8X8) {
- /* dry run to see if update is necessary */
- update[0] = update[1] = 0;
- savings = 0;
- for (i = 0; i < BLOCK_TYPES_16X16; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- // calc probs and branch cts for this frame only
- for (t = 0; t < ENTROPY_NODES; ++t) {
- const unsigned int *ct = cpi->frame_branch_ct_16x16[i][j][k][t];
- vp8_prob newp = cpi->frame_coef_probs_16x16[i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs_16x16[i][j][k] + t;
- const vp8_prob oldp = *Pold;
- int s, u;
- const vp8_prob upd = COEF_UPDATE_PROB_16X16;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(ct, oldp, &newp, upd);
- u = s > 0 && newp != oldp ? 1 : 0;
- if (u)
- savings += s - (int)(vp8_cost_zero(upd));
- else
- savings -= (int)(vp8_cost_zero(upd));
-#else
- s = prob_update_savings(ct, oldp, newp, upd);
- u = s > 0 ? 1 : 0;
- if (u)
- savings += s;
-#endif
- update[u]++;
- }
- }
- }
- }
-
- if (update[1] == 0 || savings < 0) {
- vp8_write_bit(bc, 0);
- } else {
- vp8_write_bit(bc, 1);
- for (i = 0; i < BLOCK_TYPES_16X16; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- for (t = 0; t < ENTROPY_NODES; ++t) {
- const unsigned int *ct = cpi->frame_branch_ct_16x16[i][j][k][t];
- vp8_prob newp = cpi->frame_coef_probs_16x16[i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.coef_probs_16x16[i][j][k] + t;
- const vp8_prob oldp = *Pold;
- const vp8_prob upd = COEF_UPDATE_PROB_16X16;
- int s, u;
- if (k >= 3 && ((i == 0 && j == 1) ||
- (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(ct, oldp, &newp, upd);
- u = s > 0 && newp != oldp ? 1 : 0;
-#else
- s = prob_update_savings(ct, oldp, newp, upd);
- u = s > 0 ? 1 : 0;
-#endif
- vp8_write(bc, u, upd);
-#ifdef ENTROPY_STATS
- if (!cpi->dummy_packing)
- ++tree_update_hist_16x16[i][j][k][t][u];
-#endif
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(bc, newp, oldp);
- *Pold = newp;
- }
- }
- }
- }
- }
- }
- update[0] = update[1] = 0;
- savings = 0;
- for (i = 0; i < BLOCK_TYPES_16X16; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- // calc probs and branch cts for this frame only
- for (t = 0; t < ENTROPY_NODES; ++t) {
- const unsigned int *ct = cpi->frame_hybrid_branch_ct_16x16[i][j][k][t];
- vp8_prob newp = cpi->frame_hybrid_coef_probs_16x16[i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.hybrid_coef_probs_16x16[i][j][k] + t;
- const vp8_prob oldp = *Pold;
- int s, u;
- const vp8_prob upd = COEF_UPDATE_PROB_16X16;
- if (k >= 3 && ((i == 0 && j == 1) || (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(ct, oldp, &newp, upd);
- u = s > 0 && newp != oldp ? 1 : 0;
- if (u)
- savings += s - (int)(vp8_cost_zero(upd));
- else
- savings -= (int)(vp8_cost_zero(upd));
-#else
- s = prob_update_savings(ct, oldp, newp, upd);
- u = s > 0 ? 1 : 0;
- if (u)
- savings += s;
-#endif
- update[u]++;
- }
- }
- }
- }
-
- if (update[1] == 0 || savings < 0) {
- vp8_write_bit(bc, 0);
- } else {
- vp8_write_bit(bc, 1);
- for (i = 0; i < BLOCK_TYPES_16X16; ++i) {
- for (j = !i; j < COEF_BANDS; ++j) {
- for (k = 0; k < PREV_COEF_CONTEXTS; ++k) {
- for (t = 0; t < ENTROPY_NODES; ++t) {
- const unsigned int *ct = cpi->frame_hybrid_branch_ct_16x16[i][j][k][t];
- vp8_prob newp = cpi->frame_hybrid_coef_probs_16x16[i][j][k][t];
- vp8_prob *Pold = cpi->common.fc.hybrid_coef_probs_16x16[i][j][k] + t;
- const vp8_prob oldp = *Pold;
- const vp8_prob upd = COEF_UPDATE_PROB_16X16;
- int s, u;
- if (k >= 3 && ((i == 0 && j == 1) ||
- (i > 0 && j == 0)))
- continue;
-#if defined(SEARCH_NEWP)
- s = prob_diff_update_savings_search(ct, oldp, &newp, upd);
- u = s > 0 && newp != oldp ? 1 : 0;
-#else
- s = prob_update_savings(ct, oldp, newp, upd);
- u = s > 0 ? 1 : 0;
-#endif
- vp8_write(bc, u, upd);
-#ifdef ENTROPY_STATS
- if (!cpi->dummy_packing)
- ++hybrid_tree_update_hist_16x16[i][j][k][t][u];
-#endif
- if (u) {
- /* send/use new probability */
- write_prob_diff_update(bc, newp, oldp);
- *Pold = newp;
- }
- }
- }
- }
- }
- }
+ update_coef_probs_common(bc,
+ cpi->frame_coef_probs_16x16,
+ cpi->common.fc.coef_probs_16x16,
+ cpi->frame_branch_ct_16x16);
+ update_coef_probs_common(bc,
+ cpi->frame_hybrid_coef_probs_16x16,
+ cpi->common.fc.hybrid_coef_probs_16x16,
+ cpi->frame_hybrid_branch_ct_16x16);
}
}