Commit 7131b48b authored by Thomas Daede's avatar Thomas Daede Committed by Sebastien Alaiwan

Remove tree reader and writer.

Change-Id: I7a3bf44323d5a5cbc172210c23428855f7d57db9
parent 6934c786
......@@ -25,7 +25,6 @@ set(AOM_DSP_COMMON_SOURCES
"${AOM_ROOT}/aom_dsp/intrapred.c"
"${AOM_ROOT}/aom_dsp/intrapred_common.h"
"${AOM_ROOT}/aom_dsp/loopfilter.c"
"${AOM_ROOT}/aom_dsp/prob.c"
"${AOM_ROOT}/aom_dsp/prob.h"
"${AOM_ROOT}/aom_dsp/simd/v128_intrinsics.h"
"${AOM_ROOT}/aom_dsp/simd/v128_intrinsics_c.h"
......
......@@ -19,7 +19,6 @@ DSP_SRCS-$(ARCH_X86)$(ARCH_X86_64) += x86/synonyms.h
# bit reader
DSP_SRCS-yes += prob.h
DSP_SRCS-yes += prob.c
ifeq ($(CONFIG_AV1_ENCODER),yes)
DSP_SRCS-yes += entenc.c
......
......@@ -169,35 +169,6 @@ static INLINE int aom_read_bin_(aom_reader *r, aom_cdf_prob *cdf,
}
#endif
static INLINE int aom_read_tree_as_cdf(aom_reader *r,
const aom_tree_index *tree,
const aom_prob *probs) {
aom_tree_index i = 0;
do {
aom_cdf_prob cdf[16];
aom_tree_index index[16];
int path[16];
int dist[16];
int nsymbs;
int symb;
nsymbs = tree_to_cdf(tree, probs, i, cdf, index, path, dist);
symb = aom_read_cdf(r, cdf, nsymbs, NULL);
OD_ASSERT(symb >= 0 && symb < nsymbs);
i = index[symb];
} while (i > 0);
return -i;
}
static INLINE int aom_read_tree_(aom_reader *r, const aom_tree_index *tree,
const aom_prob *probs ACCT_STR_PARAM) {
int ret;
ret = aom_read_tree_as_cdf(r, tree, probs);
#if CONFIG_ACCOUNTING
if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME);
#endif
return ret;
}
#ifdef __cplusplus
} // extern "C"
#endif
......
......@@ -116,60 +116,6 @@ static INLINE void aom_write_bin(aom_writer *w, int symb, aom_cdf_prob *cdf,
}
#endif
static INLINE void aom_write_tree_as_cdf(aom_writer *w,
const aom_tree_index *tree,
const aom_prob *probs, int bits,
int len, aom_tree_index i) {
aom_tree_index root;
root = i;
do {
aom_cdf_prob cdf[16];
aom_tree_index index[16];
int path[16];
int dist[16];
int nsymbs;
int symb;
int j;
/* Compute the CDF of the binary tree using the given probabilities. */
nsymbs = tree_to_cdf(tree, probs, root, cdf, index, path, dist);
/* Find the symbol to code. */
symb = -1;
for (j = 0; j < nsymbs; j++) {
/* If this symbol codes a leaf node, */
if (index[j] <= 0) {
if (len == dist[j] && path[j] == bits) {
symb = j;
break;
}
} else {
if (len > dist[j] && path[j] == bits >> (len - dist[j])) {
symb = j;
break;
}
}
}
OD_ASSERT(symb != -1);
aom_write_cdf(w, symb, cdf, nsymbs);
bits &= (1 << (len - dist[symb])) - 1;
len -= dist[symb];
} while (len);
}
static INLINE void aom_write_tree(aom_writer *w, const aom_tree_index *tree,
const aom_prob *probs, int bits, int len,
aom_tree_index i) {
aom_write_tree_as_cdf(w, tree, probs, bits, len, i);
}
static INLINE void aom_write_tree_record(aom_writer *w,
const aom_tree_index *tree,
const aom_prob *probs, int bits,
int len, aom_tree_index i,
TOKEN_STATS *token_stats) {
(void)token_stats;
aom_write_tree_as_cdf(w, tree, probs, bits, len, i);
}
#ifdef __cplusplus
} // extern "C"
#endif
......
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#include "./aom_config.h"
#include <string.h>
#include "aom_dsp/prob.h"
static unsigned int tree_merge_probs_impl(unsigned int i,
const aom_tree_index *tree,
const aom_prob *pre_probs,
const unsigned int *counts,
aom_prob *probs) {
const int l = tree[i];
const unsigned int left_count =
(l <= 0) ? counts[-l]
: tree_merge_probs_impl(l, tree, pre_probs, counts, probs);
const int r = tree[i + 1];
const unsigned int right_count =
(r <= 0) ? counts[-r]
: tree_merge_probs_impl(r, tree, pre_probs, counts, probs);
const unsigned int ct[2] = { left_count, right_count };
probs[i >> 1] = mode_mv_merge_probs(pre_probs[i >> 1], ct);
return left_count + right_count;
}
void aom_tree_merge_probs(const aom_tree_index *tree, const aom_prob *pre_probs,
const unsigned int *counts, aom_prob *probs) {
tree_merge_probs_impl(0, tree, pre_probs, counts, probs);
}
typedef struct tree_node tree_node;
struct tree_node {
aom_tree_index index;
uint8_t probs[16];
uint8_t prob;
int path;
int len;
int l;
int r;
aom_cdf_prob pdf;
};
/* Compute the probability of this node in Q23 */
static uint32_t tree_node_prob(tree_node n, int i) {
uint32_t prob;
/* 1.0 in Q23 */
prob = 16777216;
for (; i < n.len; i++) {
prob = prob * n.probs[i] >> 8;
}
return prob;
}
static int tree_node_cmp(tree_node a, tree_node b) {
int i;
uint32_t pa;
uint32_t pb;
for (i = 0; i < AOMMIN(a.len, b.len) && a.probs[i] == b.probs[i]; i++) {
}
pa = tree_node_prob(a, i);
pb = tree_node_prob(b, i);
return pa > pb ? 1 : pa < pb ? -1 : 0;
}
/* Given a Q15 probability for symbol subtree rooted at tree[n], this function
computes the probability of each symbol (defined as a node that has no
children). */
static aom_cdf_prob tree_node_compute_probs(tree_node *tree, int n,
aom_cdf_prob pdf) {
if (tree[n].l == 0) {
/* This prevents probability computations in Q15 that underflow from
producing a symbol that has zero probability. */
if (pdf == 0) pdf = 1;
tree[n].pdf = pdf;
return pdf;
} else {
/* We process the smaller probability first, */
if (tree[n].prob < 128) {
aom_cdf_prob lp;
aom_cdf_prob rp;
lp = (((uint32_t)pdf) * tree[n].prob + 128) >> 8;
lp = tree_node_compute_probs(tree, tree[n].l, lp);
rp = tree_node_compute_probs(tree, tree[n].r, lp > pdf ? 0 : pdf - lp);
return lp + rp;
} else {
aom_cdf_prob rp;
aom_cdf_prob lp;
rp = (((uint32_t)pdf) * (256 - tree[n].prob) + 128) >> 8;
rp = tree_node_compute_probs(tree, tree[n].r, rp);
lp = tree_node_compute_probs(tree, tree[n].l, rp > pdf ? 0 : pdf - rp);
return lp + rp;
}
}
}
static int tree_node_extract(tree_node *tree, int n, int symb,
aom_cdf_prob *pdf, aom_tree_index *index,
int *path, int *len) {
if (tree[n].l == 0) {
pdf[symb] = tree[n].pdf;
if (index != NULL) index[symb] = tree[n].index;
if (path != NULL) path[symb] = tree[n].path;
if (len != NULL) len[symb] = tree[n].len;
return symb + 1;
} else {
symb = tree_node_extract(tree, tree[n].l, symb, pdf, index, path, len);
return tree_node_extract(tree, tree[n].r, symb, pdf, index, path, len);
}
}
int tree_to_cdf(const aom_tree_index *tree, const aom_prob *probs,
aom_tree_index root, aom_cdf_prob *cdf, aom_tree_index *index,
int *path, int *len) {
tree_node symb[2 * 16 - 1];
int nodes;
int next[16];
int size;
int nsymbs;
int i;
/* Create the root node with probability 1 in Q15. */
symb[0].index = root;
symb[0].path = 0;
symb[0].len = 0;
symb[0].l = symb[0].r = 0;
nodes = 1;
next[0] = 0;
size = 1;
nsymbs = 1;
while (size > 0 && nsymbs < 16) {
int m;
tree_node n;
aom_tree_index j;
uint8_t prob;
m = 0;
/* Find the internal node with the largest probability. */
for (i = 1; i < size; i++) {
if (tree_node_cmp(symb[next[i]], symb[next[m]]) > 0) m = i;
}
i = next[m];
memmove(&next[m], &next[m + 1], sizeof(*next) * (size - (m + 1)));
size--;
/* Split this symbol into two symbols */
n = symb[i];
j = n.index;
prob = probs[j >> 1];
/* Left */
n.index = tree[j];
n.path <<= 1;
n.len++;
n.probs[n.len - 1] = prob;
symb[nodes] = n;
if (n.index > 0) {
next[size++] = nodes;
}
/* Right */
n.index = tree[j + 1];
n.path += 1;
n.probs[n.len - 1] = 256 - prob;
symb[nodes + 1] = n;
if (n.index > 0) {
next[size++] = nodes + 1;
}
symb[i].prob = prob;
symb[i].l = nodes;
symb[i].r = nodes + 1;
nodes += 2;
nsymbs++;
}
/* Compute the probabilities of each symbol in Q15 */
tree_node_compute_probs(symb, 0, CDF_PROB_TOP);
/* Extract the cdf, index, path and length */
tree_node_extract(symb, 0, 0, cdf, index, path, len);
/* Convert to CDF */
cdf[0] = AOM_ICDF(cdf[0]);
for (i = 1; i < nsymbs; i++) {
cdf[i] = AOM_ICDF(AOM_ICDF(cdf[i - 1]) + cdf[i]);
}
// Store symbol count at the end of the CDF
cdf[nsymbs] = 0;
return nsymbs;
}
/* This code assumes that tree contains as unique leaf nodes the integer values
0 to len - 1 and produces the forward and inverse mapping tables in ind[]
and inv[] respectively. */
static void tree_to_index(int *stack_index, int *ind, int *inv,
const aom_tree_index *tree, int value, int index) {
value *= 2;
do {
const aom_tree_index content = tree[index];
++index;
if (content <= 0) {
inv[*stack_index] = -content;
ind[-content] = *stack_index;
++(*stack_index);
} else {
tree_to_index(stack_index, ind, inv, tree, value, content);
}
} while (++value & 1);
}
void av1_indices_from_tree(int *ind, int *inv, const aom_tree_index *tree) {
int stack_index = 0;
tree_to_index(&stack_index, ind, inv, tree, 0, 0);
}
......@@ -169,42 +169,6 @@ static INLINE aom_prob mode_mv_merge_probs(aom_prob pre_prob,
}
}
void aom_tree_merge_probs(const aom_tree_index *tree, const aom_prob *pre_probs,
const unsigned int *counts, aom_prob *probs);
int tree_to_cdf(const aom_tree_index *tree, const aom_prob *probs,
aom_tree_index root, aom_cdf_prob *cdf, aom_tree_index *ind,
int *pth, int *len);
static INLINE void av1_tree_to_cdf(const aom_tree_index *tree,
const aom_prob *probs, aom_cdf_prob *cdf) {
aom_tree_index index[16];
int path[16];
int dist[16];
tree_to_cdf(tree, probs, 0, cdf, index, path, dist);
}
#define av1_tree_to_cdf_1D(tree, probs, cdf, u) \
do { \
int i; \
for (i = 0; i < u; i++) { \
av1_tree_to_cdf(tree, probs[i], cdf[i]); \
} \
} while (0)
#define av1_tree_to_cdf_2D(tree, probs, cdf, v, u) \
do { \
int j; \
int i; \
for (j = 0; j < v; j++) { \
for (i = 0; i < u; i++) { \
av1_tree_to_cdf(tree, probs[j][i], cdf[j][i]); \
} \
} \
} while (0)
void av1_indices_from_tree(int *ind, int *inv, const aom_tree_index *tree);
static INLINE void update_cdf(aom_cdf_prob *cdf, int val, int nsymbs) {
int rate;
const int rate2 = 5;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment