Commit d0cbdf38 authored by Thomas Daede's avatar Thomas Daede

Implement decoder

Change-Id: Ic233cdb4b765d8bbe8228c0482a3ca7a6c6d0258
parent 17ae3e1b
......@@ -30,11 +30,17 @@ int vpx_reader_init(vpx_reader *r, const uint8_t *buffer, size_t size,
r->range = 255;
r->decrypt_cb = decrypt_cb;
r->decrypt_state = decrypt_state;
#if DAALA_ENTROPY_CODER
od_ec_dec_init(&r->ec, buffer, size);
return 0;
#else
vpx_reader_fill(r);
return vpx_read_bit(r) != 0; // marker bit
#endif
}
}
#if !DAALA_ENTROPY_CODER
void vpx_reader_fill(vpx_reader *r) {
const uint8_t *const buffer_end = r->buffer_end;
const uint8_t *buffer = r->buffer;
......@@ -89,7 +95,13 @@ void vpx_reader_fill(vpx_reader *r) {
r->value = value;
r->count = count;
}
#endif
#if DAALA_ENTROPY_CODER
const uint8_t *vpx_reader_find_end(vpx_reader *r) {
return r->buffer_end;
}
#else
const uint8_t *vpx_reader_find_end(vpx_reader *r) {
// Find the end of the coded buffer
while (r->count > CHAR_BIT && r->count < BD_VALUE_SIZE) {
......@@ -98,3 +110,4 @@ const uint8_t *vpx_reader_find_end(vpx_reader *r) {
}
return r->buffer;
}
#endif
......@@ -19,6 +19,7 @@
#include "vpx/vp8dx.h"
#include "vpx/vpx_integer.h"
#include "vpx_dsp/prob.h"
#include "entdec.h"
#ifdef __cplusplus
extern "C" {
......@@ -43,6 +44,9 @@ typedef struct {
vpx_decrypt_cb decrypt_cb;
void *decrypt_state;
uint8_t clear_buffer[sizeof(BD_VALUE) + 1];
#ifdef DAALA_ENTROPY_CODER
od_ec_dec ec;
#endif
} vpx_reader;
int vpx_reader_init(vpx_reader *r, const uint8_t *buffer, size_t size,
......@@ -70,6 +74,15 @@ static INLINE int vpx_reader_has_error(vpx_reader *r) {
return r->count > BD_VALUE_SIZE && r->count < LOTS_OF_BITS;
}
#if DAALA_ENTROPY_CODER
static INLINE int vpx_read(vpx_reader *r, int prob) {
if (prob == 128) {
return od_ec_dec_bits(&r->ec, 1, "vpx_bits");
} else {
return od_ec_decode_bool_q15(&r->ec, prob * 128, "vpx");
}
}
#else
static INLINE int vpx_read(vpx_reader *r, int prob) {
unsigned int bit = 0;
BD_VALUE value;
......@@ -105,6 +118,7 @@ static INLINE int vpx_read(vpx_reader *r, int prob) {
return bit;
}
#endif
static INLINE int vpx_read_bit(vpx_reader *r) {
return vpx_read(r, 128); // vpx_prob_half
......
......@@ -13,27 +13,34 @@
#include "./bitwriter.h"
#include "entenc.h"
#include <stdio.h>
#include <string.h>
void vpx_start_encode(vpx_writer *br, uint8_t *source) {
od_ec_enc_init(&br->ec, 1000000);
br->lowvalue = 0;
br->range = 255;
br->count = -24;
br->buffer = source;
br->pos = 0;
#if DAALA_ENTROPY_CODER
od_ec_enc_init(&br->ec, 1000000);
#else
vpx_write_bit(br, 0);
#endif
}
void vpx_stop_encode(vpx_writer *br) {
int i;
#if DAALA_ENTROPY_CODER
uint32_t daala_bytes;
od_ec_enc_done(&br->ec, &daala_bytes);
fprintf(stderr, "vpx coder: %d daala coder: %d\n", br->pos, daala_bytes);
unsigned char *daala_data;
daala_data = od_ec_enc_done(&br->ec, &daala_bytes);
memcpy(br->buffer, daala_data, daala_bytes);
br->pos = daala_bytes;
od_ec_enc_clear(&br->ec);
#else
int i;
for (i = 0; i < 32; i++)
vpx_write_bit(br, 0);
// Leaks memory but somewhere vpx_write_bit is being called after stop_encode
od_ec_enc_reset(&br->ec);
#endif
// Ensure there's no ambigous collision with any index marker bytes
if ((br->buffer[br->pos - 1] & 0xe0) == 0xc0) br->buffer[br->pos++] = 0;
}
......@@ -21,8 +21,6 @@
extern "C" {
#endif
#define DAALA_ENTROPY_CODER (1)
typedef struct vpx_writer {
unsigned int lowvalue;
unsigned int range;
......@@ -37,20 +35,21 @@ typedef struct vpx_writer {
void vpx_start_encode(vpx_writer *bc, uint8_t *buffer);
void vpx_stop_encode(vpx_writer *bc);
static INLINE void vpx_write(vpx_writer *br, int bit, int probability) {
unsigned int split;
int count = br->count;
unsigned int range = br->range;
unsigned int lowvalue = br->lowvalue;
register int shift;
#if DAALA_ENTROPY_CODER
static INLINE void vpx_write(vpx_writer *br, int bit, int probability) {
if (probability == 128) {
od_ec_enc_bits(&br->ec, bit, 1);
} else {
od_ec_encode_bool_q15(&br->ec, bit, probability * 128);
}
#endif
}
#else
static INLINE void vpx_write(vpx_writer *br, int bit, int probability) {
unsigned int split;
int count = br->count;
unsigned int range = br->range;
unsigned int lowvalue = br->lowvalue;
register int shift;
split = 1 + (((range - 1) * probability) >> 8);
......@@ -92,6 +91,7 @@ static INLINE void vpx_write(vpx_writer *br, int bit, int probability) {
br->lowvalue = lowvalue;
br->range = range;
}
#endif
static INLINE void vpx_write_bit(vpx_writer *w, int bit) {
vpx_write(w, bit, 128); // vpx_prob_half
......
......@@ -28,6 +28,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
# include <stddef.h>
# include <stdint.h>
#define DAALA_ENTROPY_CODER (1)
/*Enable special features for gcc and compatible compilers.*/
# if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
# define OD_GNUC_PREREQ(maj, min, pat) \
......
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