Mercurial > libavcodec.hg
diff vp56.h @ 11921:f2007d7c3f1d libavcodec
Native VP8 decoder.
Patch by David Conrad <lessen42 gmail com> and myself.
author | rbultje |
---|---|
date | Tue, 22 Jun 2010 19:24:09 +0000 |
parents | 7d04a6cec75f |
children | 934968bd410d |
line wrap: on
line diff
--- a/vp56.h Tue Jun 22 19:19:13 2010 +0000 +++ b/vp56.h Tue Jun 22 19:24:09 2010 +0000 @@ -237,6 +237,12 @@ return bit; } +// rounding is different than vp56_rac_get, is vp56_rac_get wrong? +static inline int vp8_rac_get(VP56RangeCoder *c) +{ + return vp56_rac_get_prob(c, 128); +} + static inline int vp56_rac_gets(VP56RangeCoder *c, int bits) { int value = 0; @@ -248,12 +254,46 @@ return value; } +static inline int vp8_rac_get_uint(VP56RangeCoder *c, int bits) +{ + int value = 0; + + while (bits--) { + value = (value << 1) | vp8_rac_get(c); + } + + return value; +} + +// fixme: add 1 bit to all the calls to this? +static inline int vp8_rac_get_sint(VP56RangeCoder *c, int bits) +{ + int v; + + if (!vp8_rac_get(c)) + return 0; + + v = vp8_rac_get_uint(c, bits); + + if (vp8_rac_get(c)) + v = -v; + + return v; +} + +// P(7) static inline int vp56_rac_gets_nn(VP56RangeCoder *c, int bits) { int v = vp56_rac_gets(c, 7) << 1; return v + !v; } +static inline int vp8_rac_get_nn(VP56RangeCoder *c) +{ + int v = vp8_rac_get_uint(c, 7) << 1; + return v + !v; +} + static inline int vp56_rac_get_tree(VP56RangeCoder *c, const VP56Tree *tree, const uint8_t *probs) @@ -267,4 +307,39 @@ return -tree->val; } +/** + * This is identical to vp8_rac_get_tree except for the possibility of starting + * on a node other than the root node, needed for coeff decode where this is + * used to save a bit after a 0 token (by disallowing EOB to immediately follow.) + */ +static inline int vp8_rac_get_tree_with_offset(VP56RangeCoder *c, const int8_t (*tree)[2], + const uint8_t *probs, int i) +{ + do { + i = tree[i][vp56_rac_get_prob(c, probs[i])]; + } while (i > 0); + + return -i; +} + +// how probabilities are associated with decisions is different I think +// well, the new scheme fits in the old but this way has one fewer branches per decision +static inline int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2], + const uint8_t *probs) +{ + return vp8_rac_get_tree_with_offset(c, tree, probs, 0); +} + +// DCTextra +static inline int vp8_rac_get_coeff(VP56RangeCoder *c, const uint8_t *prob) +{ + int v = 0; + + do { + v = (v<<1) + vp56_rac_get_prob(c, *prob++); + } while (*prob); + + return v; +} + #endif /* AVCODEC_VP56_H */