summaryrefslogtreecommitdiff
path: root/vp9
diff options
context:
space:
mode:
authorDmitry Kovalev <dkovalev@google.com>2013-05-07 15:04:28 -0700
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2013-05-07 15:04:28 -0700
commit847e184011f6b9b0645ad0305e2892910c86d7ea (patch)
treeeac2cf785d5350c564a19487945c89db23b89511 /vp9
parent3cd889762364da9914a136cf8735b8524f3b341e (diff)
parentaea29cd27844b8001ffbe85c820ac76149fb82da (diff)
downloadlibvpx-847e184011f6b9b0645ad0305e2892910c86d7ea.tar
libvpx-847e184011f6b9b0645ad0305e2892910c86d7ea.tar.gz
libvpx-847e184011f6b9b0645ad0305e2892910c86d7ea.tar.bz2
libvpx-847e184011f6b9b0645ad0305e2892910c86d7ea.zip
Merge "General code cleanup inside treewriter-related files." into experimental
Diffstat (limited to 'vp9')
-rw-r--r--vp9/common/vp9_treecoder.c9
-rw-r--r--vp9/encoder/vp9_boolhuff.c12
-rw-r--r--vp9/encoder/vp9_boolhuff.h28
-rw-r--r--vp9/encoder/vp9_treewriter.c42
-rw-r--r--vp9/encoder/vp9_treewriter.h63
5 files changed, 69 insertions, 85 deletions
diff --git a/vp9/common/vp9_treecoder.c b/vp9/common/vp9_treecoder.c
index 3f049b5b3..531fa752b 100644
--- a/vp9/common/vp9_treecoder.c
+++ b/vp9/common/vp9_treecoder.c
@@ -14,7 +14,6 @@
#if defined(CONFIG_DEBUG) && CONFIG_DEBUG
#include <assert.h>
#endif
-#include <stdio.h>
#include "vp9/common/vp9_treecoder.h"
@@ -57,12 +56,12 @@ static unsigned int convert_distribution(unsigned int i,
left = convert_distribution(tree[i], tree, probs, branch_ct,
num_events, tok0_offset);
}
- if (tree[i + 1] <= 0) {
+ if (tree[i + 1] <= 0)
right = num_events[-tree[i + 1] - tok0_offset];
- } else {
+ else
right = convert_distribution(tree[i + 1], tree, probs, branch_ct,
- num_events, tok0_offset);
- }
+ num_events, tok0_offset);
+
probs[i>>1] = get_binary_prob(left, right);
branch_ct[i>>1][0] = left;
branch_ct[i>>1][1] = right;
diff --git a/vp9/encoder/vp9_boolhuff.c b/vp9/encoder/vp9_boolhuff.c
index 213742182..0d8a1b814 100644
--- a/vp9/encoder/vp9_boolhuff.c
+++ b/vp9/encoder/vp9_boolhuff.c
@@ -39,7 +39,7 @@ const unsigned int vp9_prob_cost[256] = {
22, 21, 19, 18, 16, 15, 13, 12, 10, 9, 7, 6, 4, 3, 1, 1
};
-void vp9_start_encode(BOOL_CODER *br, unsigned char *source) {
+void vp9_start_encode(vp9_writer *br, uint8_t *source) {
br->lowvalue = 0;
br->range = 255;
br->value = 0;
@@ -48,7 +48,7 @@ void vp9_start_encode(BOOL_CODER *br, unsigned char *source) {
br->pos = 0;
}
-void vp9_stop_encode(BOOL_CODER *br) {
+void vp9_stop_encode(vp9_writer *br) {
int i;
for (i = 0; i < 32; i++)
@@ -60,14 +60,14 @@ void vp9_stop_encode(BOOL_CODER *br) {
}
-void vp9_encode_value(BOOL_CODER *br, int data, int bits) {
+void vp9_encode_value(vp9_writer *br, int data, int bits) {
int bit;
for (bit = bits - 1; bit >= 0; bit--)
encode_bool(br, (1 & (data >> bit)), 0x80);
}
-void vp9_encode_unsigned_max(BOOL_CODER *br, int data, int max) {
+void vp9_encode_unsigned_max(vp9_writer *br, int data, int max) {
assert(data <= max);
while (max) {
encode_bool(br, data & 1, 128);
@@ -92,7 +92,7 @@ static int get_unsigned_bits(unsigned num_values) {
return cat;
}
-void vp9_encode_uniform(BOOL_CODER *br, int v, int n) {
+void vp9_encode_uniform(vp9_writer *br, int v, int n) {
int l = get_unsigned_bits(n);
int m;
if (l == 0) return;
@@ -116,7 +116,7 @@ int vp9_count_uniform(int v, int n) {
return l;
}
-void vp9_encode_term_subexp(BOOL_CODER *br, int word, int k, int num_syms) {
+void vp9_encode_term_subexp(vp9_writer *br, int word, int k, int num_syms) {
int i = 0;
int mk = 0;
while (1) {
diff --git a/vp9/encoder/vp9_boolhuff.h b/vp9/encoder/vp9_boolhuff.h
index 0be4b53c1..a31e7de1e 100644
--- a/vp9/encoder/vp9_boolhuff.h
+++ b/vp9/encoder/vp9_boolhuff.h
@@ -27,30 +27,34 @@ typedef struct {
unsigned int value;
int count;
unsigned int pos;
- unsigned char *buffer;
+ uint8_t *buffer;
// Variables used to track bit costs without outputing to the bitstream
unsigned int measure_cost;
unsigned long bit_counter;
} BOOL_CODER;
-extern void vp9_start_encode(BOOL_CODER *bc, unsigned char *buffer);
+typedef BOOL_CODER vp9_writer;
-extern void vp9_encode_value(BOOL_CODER *br, int data, int bits);
-extern void vp9_encode_unsigned_max(BOOL_CODER *br, int data, int max);
-extern void vp9_stop_encode(BOOL_CODER *bc);
extern const unsigned int vp9_prob_cost[256];
-extern void vp9_encode_uniform(BOOL_CODER *bc, int v, int n);
-extern void vp9_encode_term_subexp(BOOL_CODER *bc, int v, int k, int n);
-extern int vp9_count_uniform(int v, int n);
-extern int vp9_count_term_subexp(int v, int k, int n);
-extern int vp9_recenter_nonneg(int v, int m);
+void vp9_start_encode(vp9_writer *bc, uint8_t *buffer);
+
+void vp9_encode_value(vp9_writer *br, int data, int bits);
+void vp9_encode_unsigned_max(vp9_writer *br, int data, int max);
+void vp9_stop_encode(vp9_writer *bc);
+
+
+void vp9_encode_uniform(vp9_writer *bc, int v, int n);
+void vp9_encode_term_subexp(vp9_writer *bc, int v, int k, int n);
+int vp9_count_uniform(int v, int n);
+int vp9_count_term_subexp(int v, int k, int n);
+int vp9_recenter_nonneg(int v, int m);
DECLARE_ALIGNED(16, extern const unsigned char, vp9_norm[256]);
-static void encode_bool(BOOL_CODER *br, int bit, int probability) {
+static void encode_bool(vp9_writer *br, int bit, int probability) {
unsigned int split;
int count = br->count;
unsigned int range = br->range;
@@ -89,7 +93,7 @@ static void encode_bool(BOOL_CODER *br, int bit, int probability) {
int x = br->pos - 1;
while (x >= 0 && br->buffer[x] == 0xff) {
- br->buffer[x] = (unsigned char)0;
+ br->buffer[x] = 0;
x--;
}
diff --git a/vp9/encoder/vp9_treewriter.c b/vp9/encoder/vp9_treewriter.c
index 52da3c6ce..e4aed5374 100644
--- a/vp9/encoder/vp9_treewriter.c
+++ b/vp9/encoder/vp9_treewriter.c
@@ -8,35 +8,31 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-
#include "vp9/encoder/vp9_treewriter.h"
-#include "vp9/common/vp9_common.h"
-static void cost(
- int *const C,
- vp9_tree T,
- const vp9_prob *const P,
- int i,
- int c
-) {
- const vp9_prob p = P [i >> 1];
+static void cost(int *costs, vp9_tree tree, const vp9_prob *probs,
+ int i, int c) {
+ const vp9_prob prob = probs[i / 2];
+ int b;
- do {
- const vp9_tree_index j = T[i];
- const int d = c + vp9_cost_bit(p, i & 1);
+ for (b = 0; b <= 1; ++b) {
+ const int cc = c + vp9_cost_bit(prob, b);
+ const vp9_tree_index ii = tree[i + b];
- if (j <= 0)
- C[-j] = d;
+ if (ii <= 0)
+ costs[-ii] = cc;
else
- cost(C, T, P, j, d);
- } while (++i & 1);
+ cost(costs, tree, probs, ii, cc);
+ }
}
-void vp9_cost_tokens(int *c, const vp9_prob *p, vp9_tree t) {
- cost(c, t, p, 0, 0);
+
+void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree) {
+ cost(costs, tree, probs, 0, 0);
}
-void vp9_cost_tokens_skip(int *c, const vp9_prob *p, vp9_tree t) {
- assert(t[1] > 0 && t[0] <= 0);
- c[-t[0]] = vp9_cost_bit(p[0], 0);
- cost(c, t, p, 2, 0);
+void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree) {
+ assert(tree[0] <= 0 && tree[1] > 0);
+
+ costs[-tree[0]] = vp9_cost_bit(probs[0], 0);
+ cost(costs, tree, probs, 2, 0);
}
diff --git a/vp9/encoder/vp9_treewriter.h b/vp9/encoder/vp9_treewriter.h
index af2c122e0..35059365a 100644
--- a/vp9/encoder/vp9_treewriter.h
+++ b/vp9/encoder/vp9_treewriter.h
@@ -19,8 +19,6 @@
#include "vp9/encoder/vp9_boolhuff.h" /* for now */
-typedef BOOL_CODER vp9_writer;
-
#define vp9_write encode_bool
#define vp9_write_literal vp9_encode_value
#define vp9_write_bit(w, v) vp9_write((w), (v), vp9_prob_half)
@@ -39,66 +37,53 @@ typedef BOOL_CODER vp9_writer;
/* Both of these return bits, not scaled bits. */
static INLINE unsigned int cost_branch256(const unsigned int ct[2],
vp9_prob p) {
- /* Imitate existing calculation */
return ct[0] * vp9_cost_zero(p) + ct[1] * vp9_cost_one(p);
}
static INLINE unsigned int cost_branch(const unsigned int ct[2],
vp9_prob p) {
- /* Imitate existing calculation */
return cost_branch256(ct, p) >> 8;
}
-/* Small functions to write explicit values and tokens, as well as
- estimate their lengths. */
-
-static INLINE void treed_write(vp9_writer *const w,
- vp9_tree t,
- const vp9_prob *const p,
- int v,
- /* number of bits in v, assumed nonzero */
- int n) {
+static INLINE void treed_write(vp9_writer *w,
+ vp9_tree tree, const vp9_prob *probs,
+ int bits, int len) {
vp9_tree_index i = 0;
do {
- const int b = (v >> --n) & 1;
- vp9_write(w, b, p[i >> 1]);
- i = t[i + b];
- } while (n);
+ const int bit = (bits >> --len) & 1;
+ vp9_write(w, bit, probs[i >> 1]);
+ i = tree[i + bit];
+ } while (len);
}
-static INLINE void write_token(vp9_writer *w, vp9_tree t, const vp9_prob *p,
- const struct vp9_token *x) {
- treed_write(w, t, p, x->value, x->len);
+static INLINE void write_token(vp9_writer *w, vp9_tree tree,
+ const vp9_prob *probs,
+ const struct vp9_token *token) {
+ treed_write(w, tree, probs, token->value, token->len);
}
-static INLINE int treed_cost(vp9_tree t,
- const vp9_prob *const p,
- int v,
- /* number of bits in v, assumed nonzero */
- int n) {
- int c = 0;
+static INLINE int treed_cost(vp9_tree tree, const vp9_prob *probs,
+ int bits, int len) {
+ int cost = 0;
vp9_tree_index i = 0;
do {
- const int b = (v >> --n) & 1;
- c += vp9_cost_bit(p[i >> 1], b);
- i = t[i + b];
- } while (n);
+ const int bit = (bits >> --len) & 1;
+ cost += vp9_cost_bit(probs[i >> 1], bit);
+ i = tree[i + bit];
+ } while (len);
- return c;
+ return cost;
}
-static INLINE int cost_token(vp9_tree t, const vp9_prob *p,
- const struct vp9_token *x) {
- return treed_cost(t, p, x->value, x->len);
+static INLINE int cost_token(vp9_tree tree, const vp9_prob *probs,
+ const struct vp9_token *token) {
+ return treed_cost(tree, probs, token->value, token->len);
}
-/* Fill array of costs for all possible token values. */
-
-void vp9_cost_tokens(int *Costs, const vp9_prob *, vp9_tree);
-
-void vp9_cost_tokens_skip(int *c, const vp9_prob *p, vp9_tree t);
+void vp9_cost_tokens(int *costs, const vp9_prob *probs, vp9_tree tree);
+void vp9_cost_tokens_skip(int *costs, const vp9_prob *probs, vp9_tree tree);
#endif // VP9_ENCODER_VP9_TREEWRITER_H_