Commit 80f99632 authored by Dmitry Kovalev's avatar Dmitry Kovalev Committed by Gerrit Code Review

Merge "Replacing vp9_{write, write_literal, bit} macros with functions." into experimental

parents a0b6b8a7 cd5113ce
......@@ -52,7 +52,7 @@ TEST(VP9, TestBitIO) {
const int random_seed = 6432;
const int buffer_size = 10000;
ACMRandom bit_rnd(random_seed);
BOOL_CODER bw;
vp9_writer bw;
uint8_t bw_buffer[buffer_size];
vp9_start_encode(&bw, bw_buffer);
......@@ -63,7 +63,7 @@ TEST(VP9, TestBitIO) {
} else if (bit_method == 3) {
bit = bit_rnd(2);
}
encode_bool(&bw, bit, static_cast<int>(probas[i]));
vp9_write(&bw, bit, static_cast<int>(probas[i]));
}
vp9_stop_encode(&bw);
......
......@@ -52,7 +52,7 @@ void vp9_stop_encode(vp9_writer *br) {
int i;
for (i = 0; i < 32; i++)
encode_bool(br, 0, 128);
vp9_write_bit(br, 0);
// Ensure there's no ambigous collision with any index marker bytes
if ((br->buffer[br->pos - 1] & 0xe0) == 0xc0)
......@@ -60,17 +60,10 @@ void vp9_stop_encode(vp9_writer *br) {
}
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(vp9_writer *br, int data, int max) {
assert(data <= max);
while (max) {
encode_bool(br, data & 1, 128);
vp9_write_bit(br, data & 1);
data >>= 1;
max >>= 1;
}
......@@ -98,10 +91,10 @@ void vp9_encode_uniform(vp9_writer *br, int v, int n) {
if (l == 0) return;
m = (1 << l) - n;
if (v < m)
vp9_encode_value(br, v, l - 1);
vp9_write_literal(br, v, l - 1);
else {
vp9_encode_value(br, m + ((v - m) >> 1), l - 1);
vp9_encode_value(br, (v - m) & 1, 1);
vp9_write_literal(br, m + ((v - m) >> 1), l - 1);
vp9_write_literal(br, (v - m) & 1, 1);
}
}
......@@ -127,12 +120,12 @@ void vp9_encode_term_subexp(vp9_writer *br, int word, int k, int num_syms) {
break;
} else {
int t = (word >= mk + a);
vp9_encode_value(br, t, 1);
vp9_write_literal(br, t, 1);
if (t) {
i = i + 1;
mk += a;
} else {
vp9_encode_value(br, word - mk, b);
vp9_write_literal(br, word - mk, b);
break;
}
}
......
......@@ -32,15 +32,11 @@ typedef struct {
// Variables used to track bit costs without outputing to the bitstream
unsigned int measure_cost;
unsigned long bit_counter;
} BOOL_CODER;
typedef BOOL_CODER vp9_writer;
} vp9_writer;
extern const unsigned int vp9_prob_cost[256];
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);
......@@ -54,7 +50,7 @@ int vp9_recenter_nonneg(int v, int m);
DECLARE_ALIGNED(16, extern const unsigned char, vp9_norm[256]);
static void encode_bool(vp9_writer *br, int bit, int probability) {
static void vp9_write(vp9_writer *br, int bit, int probability) {
unsigned int split;
int count = br->count;
unsigned int range = br->range;
......@@ -113,4 +109,16 @@ static void encode_bool(vp9_writer *br, int bit, int probability) {
br->range = range;
}
static void vp9_write_bit(vp9_writer *w, int bit) {
vp9_write(w, bit, 128); // vp9_prob_half
}
static void vp9_write_literal(vp9_writer *w, int data, int bits) {
int bit;
for (bit = bits - 1; bit >= 0; bit--)
vp9_write_bit(w, 1 & (data >> bit));
}
#endif // VP9_ENCODER_VP9_BOOLHUFF_H_
......@@ -19,9 +19,7 @@
#include "vp9/encoder/vp9_boolhuff.h" /* for now */
#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)
#define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8)
/* Approximate length of an encoded bool in 256ths of a bit at given prob */
......
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