Commit 987451d8 authored by Yaowu Xu's avatar Yaowu Xu Committed by Gerrit Code Review

Merge "vpx_dsp/bitwriter.h: vp9_->vpx_"

parents 41c13ddb 817be1d2
......@@ -50,9 +50,9 @@ TEST(VP9, TestBitIO) {
const int random_seed = 6432;
const int kBufferSize = 10000;
ACMRandom bit_rnd(random_seed);
vp9_writer bw;
vpx_writer bw;
uint8_t bw_buffer[kBufferSize];
vp9_start_encode(&bw, bw_buffer);
vpx_start_encode(&bw, bw_buffer);
int bit = (bit_method == 0) ? 0 : (bit_method == 1) ? 1 : 0;
for (int i = 0; i < kBitsToTest; ++i) {
......@@ -61,10 +61,10 @@ TEST(VP9, TestBitIO) {
} else if (bit_method == 3) {
bit = bit_rnd(2);
}
vp9_write(&bw, bit, static_cast<int>(probas[i]));
vpx_write(&bw, bit, static_cast<int>(probas[i]));
}
vp9_stop_encode(&bw);
vpx_stop_encode(&bw);
// First bit should be zero
GTEST_ASSERT_EQ(bw_buffer[0] & 0x80, 0);
......
This diff is collapsed.
......@@ -29,7 +29,7 @@ void vp9_entropy_mv_init(void) {
vp9_tokens_from_tree(mv_fp_encodings, vp9_mv_fp_tree);
}
static void encode_mv_component(vp9_writer* w, int comp,
static void encode_mv_component(vpx_writer* w, int comp,
const nmv_component* mvcomp, int usehp) {
int offset;
const int sign = comp < 0;
......@@ -42,7 +42,7 @@ static void encode_mv_component(vp9_writer* w, int comp,
assert(comp != 0);
// Sign
vp9_write(w, sign, mvcomp->sign);
vpx_write(w, sign, mvcomp->sign);
// Class
vp9_write_token(w, vp9_mv_class_tree, mvcomp->classes,
......@@ -56,7 +56,7 @@ static void encode_mv_component(vp9_writer* w, int comp,
int i;
const int n = mv_class + CLASS0_BITS - 1; // number of bits
for (i = 0; i < n; ++i)
vp9_write(w, (d >> i) & 1, mvcomp->bits[i]);
vpx_write(w, (d >> i) & 1, mvcomp->bits[i]);
}
// Fractional bits
......@@ -66,7 +66,7 @@ static void encode_mv_component(vp9_writer* w, int comp,
// High precision bit
if (usehp)
vp9_write(w, hp,
vpx_write(w, hp,
mv_class == MV_CLASS_0 ? mvcomp->class0_hp : mvcomp->hp);
}
......@@ -133,15 +133,15 @@ static void build_nmv_component_cost_table(int *mvcost,
}
}
static int update_mv(vp9_writer *w, const unsigned int ct[2], vpx_prob *cur_p,
static int update_mv(vpx_writer *w, const unsigned int ct[2], vpx_prob *cur_p,
vpx_prob upd_p) {
const vpx_prob new_p = get_binary_prob(ct[0], ct[1]) | 1;
const int update = cost_branch256(ct, *cur_p) + vp9_cost_zero(upd_p) >
cost_branch256(ct, new_p) + vp9_cost_one(upd_p) + 7 * 256;
vp9_write(w, update, upd_p);
vpx_write(w, update, upd_p);
if (update) {
*cur_p = new_p;
vp9_write_literal(w, new_p >> 1, 7);
vpx_write_literal(w, new_p >> 1, 7);
}
return update;
}
......@@ -149,7 +149,7 @@ static int update_mv(vp9_writer *w, const unsigned int ct[2], vpx_prob *cur_p,
static void write_mv_update(const vpx_tree_index *tree,
vpx_prob probs[/*n - 1*/],
const unsigned int counts[/*n - 1*/],
int n, vp9_writer *w) {
int n, vpx_writer *w) {
int i;
unsigned int branch_ct[32][2];
......@@ -161,7 +161,7 @@ static void write_mv_update(const vpx_tree_index *tree,
update_mv(w, branch_ct[i], &probs[i], MV_UPDATE_PROB);
}
void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vp9_writer *w,
void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vpx_writer *w,
nmv_context_counts *const counts) {
int i, j;
nmv_context *const mvc = &cm->fc->nmvc;
......@@ -199,7 +199,7 @@ void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vp9_writer *w,
}
}
void vp9_encode_mv(VP9_COMP* cpi, vp9_writer* w,
void vp9_encode_mv(VP9_COMP* cpi, vpx_writer* w,
const MV* mv, const MV* ref,
const nmv_context* mvctx, int usehp) {
const MV diff = {mv->row - ref->row,
......
......@@ -20,10 +20,10 @@ extern "C" {
void vp9_entropy_mv_init(void);
void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vp9_writer *w,
void vp9_write_nmv_probs(VP9_COMMON *cm, int usehp, vpx_writer *w,
nmv_context_counts *const counts);
void vp9_encode_mv(VP9_COMP *cpi, vp9_writer* w, const MV* mv, const MV* ref,
void vp9_encode_mv(VP9_COMP *cpi, vpx_writer* w, const MV* mv, const MV* ref,
const nmv_context* mvctx, int usehp);
void vp9_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
......
......@@ -83,35 +83,35 @@ static int prob_diff_update_cost(vpx_prob newp, vpx_prob oldp) {
return update_bits[delp] * 256;
}
static void encode_uniform(vp9_writer *w, int v) {
static void encode_uniform(vpx_writer *w, int v) {
const int l = 8;
const int m = (1 << l) - 191;
if (v < m) {
vp9_write_literal(w, v, l - 1);
vpx_write_literal(w, v, l - 1);
} else {
vp9_write_literal(w, m + ((v - m) >> 1), l - 1);
vp9_write_literal(w, (v - m) & 1, 1);
vpx_write_literal(w, m + ((v - m) >> 1), l - 1);
vpx_write_literal(w, (v - m) & 1, 1);
}
}
static INLINE int write_bit_gte(vp9_writer *w, int word, int test) {
vp9_write_literal(w, word >= test, 1);
static INLINE int write_bit_gte(vpx_writer *w, int word, int test) {
vpx_write_literal(w, word >= test, 1);
return word >= test;
}
static void encode_term_subexp(vp9_writer *w, int word) {
static void encode_term_subexp(vpx_writer *w, int word) {
if (!write_bit_gte(w, word, 16)) {
vp9_write_literal(w, word, 4);
vpx_write_literal(w, word, 4);
} else if (!write_bit_gte(w, word, 32)) {
vp9_write_literal(w, word - 16, 4);
vpx_write_literal(w, word - 16, 4);
} else if (!write_bit_gte(w, word, 64)) {
vp9_write_literal(w, word - 32, 5);
vpx_write_literal(w, word - 32, 5);
} else {
encode_uniform(w, word - 64);
}
}
void vp9_write_prob_diff_update(vp9_writer *w, vpx_prob newp, vpx_prob oldp) {
void vp9_write_prob_diff_update(vpx_writer *w, vpx_prob newp, vpx_prob oldp) {
const int delp = remap_prob(newp, oldp);
encode_term_subexp(w, delp);
}
......@@ -196,7 +196,7 @@ int vp9_prob_diff_update_savings_search_model(const unsigned int *ct,
return bestsavings;
}
void vp9_cond_prob_diff_update(vp9_writer *w, vpx_prob *oldp,
void vp9_cond_prob_diff_update(vpx_writer *w, vpx_prob *oldp,
const unsigned int ct[2]) {
const vpx_prob upd = DIFF_UPDATE_PROB;
vpx_prob newp = get_binary_prob(ct[0], ct[1]);
......@@ -204,10 +204,10 @@ void vp9_cond_prob_diff_update(vp9_writer *w, vpx_prob *oldp,
upd);
assert(newp >= 1);
if (savings > 0) {
vp9_write(w, 1, upd);
vpx_write(w, 1, upd);
vp9_write_prob_diff_update(w, newp, *oldp);
*oldp = newp;
} else {
vp9_write(w, 0, upd);
vpx_write(w, 0, upd);
}
}
......@@ -18,12 +18,12 @@ extern "C" {
#include "vpx_dsp/prob.h"
struct vp9_writer;
struct vpx_writer;
void vp9_write_prob_diff_update(struct vp9_writer *w,
void vp9_write_prob_diff_update(struct vpx_writer *w,
vpx_prob newp, vpx_prob oldp);
void vp9_cond_prob_diff_update(struct vp9_writer *w, vpx_prob *oldp,
void vp9_cond_prob_diff_update(struct vpx_writer *w, vpx_prob *oldp,
const unsigned int ct[2]);
int vp9_prob_diff_update_savings_search(const unsigned int *ct,
......
......@@ -28,17 +28,17 @@ struct vp9_token {
void vp9_tokens_from_tree(struct vp9_token*, const vpx_tree_index *);
static INLINE void vp9_write_tree(vp9_writer *w, const vpx_tree_index *tree,
static INLINE void vp9_write_tree(vpx_writer *w, const vpx_tree_index *tree,
const vpx_prob *probs, int bits, int len,
vpx_tree_index i) {
do {
const int bit = (bits >> --len) & 1;
vp9_write(w, bit, probs[i >> 1]);
vpx_write(w, bit, probs[i >> 1]);
i = tree[i + bit];
} while (len);
}
static INLINE void vp9_write_token(vp9_writer *w, const vpx_tree_index *tree,
static INLINE void vp9_write_token(vpx_writer *w, const vpx_tree_index *tree,
const vpx_prob *probs,
const struct vp9_token *token) {
vp9_write_tree(w, tree, probs, token->value, token->len, 0);
......
......@@ -12,20 +12,20 @@
#include "./bitwriter.h"
void vp9_start_encode(vp9_writer *br, uint8_t *source) {
void vpx_start_encode(vpx_writer *br, uint8_t *source) {
br->lowvalue = 0;
br->range = 255;
br->count = -24;
br->buffer = source;
br->pos = 0;
vp9_write_bit(br, 0);
vpx_write_bit(br, 0);
}
void vp9_stop_encode(vp9_writer *br) {
void vpx_stop_encode(vpx_writer *br) {
int i;
for (i = 0; i < 32; i++)
vp9_write_bit(br, 0);
vpx_write_bit(br, 0);
// Ensure there's no ambigous collision with any index marker bytes
if ((br->buffer[br->pos - 1] & 0xe0) == 0xc0)
......
......@@ -19,18 +19,18 @@
extern "C" {
#endif
typedef struct vp9_writer {
typedef struct vpx_writer {
unsigned int lowvalue;
unsigned int range;
int count;
unsigned int pos;
uint8_t *buffer;
} vp9_writer;
} vpx_writer;
void vp9_start_encode(vp9_writer *bc, uint8_t *buffer);
void vp9_stop_encode(vp9_writer *bc);
void vpx_start_encode(vpx_writer *bc, uint8_t *buffer);
void vpx_stop_encode(vpx_writer *bc);
static INLINE void vp9_write(vp9_writer *br, int bit, int probability) {
static INLINE void vpx_write(vpx_writer *br, int bit, int probability) {
unsigned int split;
int count = br->count;
unsigned int range = br->range;
......@@ -78,18 +78,18 @@ static INLINE void vp9_write(vp9_writer *br, int bit, int probability) {
br->range = range;
}
static INLINE void vp9_write_bit(vp9_writer *w, int bit) {
vp9_write(w, bit, 128); // vpx_prob_half
static INLINE void vpx_write_bit(vpx_writer *w, int bit) {
vpx_write(w, bit, 128); // vpx_prob_half
}
static INLINE void vp9_write_literal(vp9_writer *w, int data, int bits) {
static INLINE void vpx_write_literal(vpx_writer *w, int data, int bits) {
int bit;
for (bit = bits - 1; bit >= 0; bit--)
vp9_write_bit(w, 1 & (data >> bit));
vpx_write_bit(w, 1 & (data >> bit));
}
#define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8)
#define vpx_write_prob(w, v) vpx_write_literal((w), (v), 8)
#ifdef __cplusplus
} // extern "C"
......
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