ref: 87d2c3c063efe76a5646ed15425dd91b0e23ce40
parent: 97279ed2e2c03d0fb31e2361ed9a25276a9247d5
author: Yaowu Xu <[email protected]>
date: Fri Jul 17 10:09:05 EDT 2015
Removed vp9_ prefix from vpx_dsp/bitreader file names Change-Id: I0426126d0a65f13f9250983e44cc366b1b1a9c4a
--- a/test/vp9_boolcoder_test.cc
+++ b/test/vp9_boolcoder_test.cc
@@ -15,7 +15,7 @@
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "vpx/vpx_integer.h"
-#include "vpx_dsp/vp9_reader.h"
+#include "vpx_dsp/bitreader.h"
#include "vp9/encoder/vp9_writer.h"
--- a/vp9/common/vp9_entropy.h
+++ b/vp9/common/vp9_entropy.h
@@ -12,7 +12,7 @@
#define VP9_COMMON_VP9_ENTROPY_H_
#include "vpx/vpx_integer.h"
-#include "vpx_dsp/vp9_prob.h"
+#include "vpx_dsp/prob.h"
#include "vp9/common/vp9_common.h"
#include "vp9/common/vp9_enums.h"
--- a/vp9/common/vp9_entropymv.h
+++ b/vp9/common/vp9_entropymv.h
@@ -14,7 +14,7 @@
#include "./vpx_config.h"
-#include "vpx_dsp/vp9_prob.h"
+#include "vpx_dsp/prob.h"
#include "vp9/common/vp9_mv.h"
--- a/vp9/common/vp9_seg_common.h
+++ b/vp9/common/vp9_seg_common.h
@@ -11,7 +11,7 @@
#ifndef VP9_COMMON_VP9_SEG_COMMON_H_
#define VP9_COMMON_VP9_SEG_COMMON_H_
-#include "vpx_dsp/vp9_prob.h"
+#include "vpx_dsp/prob.h"
#ifdef __cplusplus
extern "C" {
--- a/vp9/decoder/vp9_decodeframe.c
+++ b/vp9/decoder/vp9_decodeframe.c
@@ -14,8 +14,8 @@
#include "./vp9_rtcd.h"
#include "./vpx_scale_rtcd.h"
-#include "vpx_dsp/vp9_read_bit_buffer.h"
-#include "vpx_dsp/vp9_reader.h"
+#include "vpx_dsp/bitreader_buffer.h"
+#include "vpx_dsp/bitreader.h"
#include "vpx_mem/vpx_mem.h"
#include "vpx_ports/mem.h"
#include "vpx_ports/mem_ops.h"
--- a/vp9/decoder/vp9_decodemv.h
+++ b/vp9/decoder/vp9_decodemv.h
@@ -11,7 +11,7 @@
#ifndef VP9_DECODER_VP9_DECODEMV_H_
#define VP9_DECODER_VP9_DECODEMV_H_
-#include "vpx_dsp/vp9_reader.h"
+#include "vpx_dsp/bitreader.h"
#include "vp9/decoder/vp9_decoder.h"
--- a/vp9/decoder/vp9_decoder.h
+++ b/vp9/decoder/vp9_decoder.h
@@ -14,7 +14,7 @@
#include "./vpx_config.h"
#include "vpx/vpx_codec.h"
-#include "vpx_dsp/vp9_reader.h"
+#include "vpx_dsp/bitreader.h"
#include "vpx_scale/yv12config.h"
#include "vpx_util/vpx_thread.h"
--- a/vp9/decoder/vp9_detokenize.h
+++ b/vp9/decoder/vp9_detokenize.h
@@ -12,8 +12,7 @@
#ifndef VP9_DECODER_VP9_DETOKENIZE_H_
#define VP9_DECODER_VP9_DETOKENIZE_H_
-#include "vpx_dsp/vp9_reader.h"
-
+#include "vpx_dsp/bitreader.h"
#include "vp9/decoder/vp9_decoder.h"
#include "vp9/common/vp9_scan.h"
--- a/vp9/decoder/vp9_dsubexp.h
+++ b/vp9/decoder/vp9_dsubexp.h
@@ -12,7 +12,7 @@
#ifndef VP9_DECODER_VP9_DSUBEXP_H_
#define VP9_DECODER_VP9_DSUBEXP_H_
-#include "vpx_dsp/vp9_reader.h"
+#include "vpx_dsp/bitreader.h"
#ifdef __cplusplus
extern "C" {
--- a/vp9/encoder/vp9_cost.h
+++ b/vp9/encoder/vp9_cost.h
@@ -11,7 +11,7 @@
#ifndef VP9_ENCODER_VP9_COST_H_
#define VP9_ENCODER_VP9_COST_H_
-#include "vpx_dsp/vp9_prob.h"
+#include "vpx_dsp/prob.h"
#ifdef __cplusplus
extern "C" {
--- a/vp9/encoder/vp9_subexp.h
+++ b/vp9/encoder/vp9_subexp.h
@@ -16,7 +16,7 @@
extern "C" {
#endif
-#include "vpx_dsp/vp9_prob.h"
+#include "vpx_dsp/prob.h"
struct vp9_writer;
--- a/vp9/encoder/vp9_writer.h
+++ b/vp9/encoder/vp9_writer.h
@@ -13,7 +13,7 @@
#include "vpx_ports/mem.h"
-#include "vpx_dsp/vp9_prob.h"
+#include "vpx_dsp/prob.h"
#ifdef __cplusplus
extern "C" {
--- a/vp9/vp9_dx_iface.c
+++ b/vp9/vp9_dx_iface.c
@@ -17,7 +17,7 @@
#include "vpx/internal/vpx_codec_internal.h"
#include "vpx/vp8dx.h"
#include "vpx/vpx_decoder.h"
-#include "vpx_dsp/vp9_read_bit_buffer.h"
+#include "vpx_dsp/bitreader_buffer.h"
#include "vpx_util/vpx_thread.h"
#include "vp9/common/vp9_alloccommon.h"
--- /dev/null
+++ b/vpx_dsp/bitreader.c
@@ -1,0 +1,83 @@
+/*
+ * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "./bitreader.h"
+#include "./prob.h"
+
+#include "vpx_ports/mem.h"
+#include "vpx_mem/vpx_mem.h"
+
+int vp9_reader_init(vp9_reader *r,
+ const uint8_t *buffer,
+ size_t size,
+ vpx_decrypt_cb decrypt_cb,
+ void *decrypt_state) {
+ if (size && !buffer) {
+ return 1;
+ } else {
+ r->buffer_end = buffer + size;
+ r->buffer = buffer;
+ r->value = 0;
+ r->count = -8;
+ r->range = 255;
+ r->decrypt_cb = decrypt_cb;
+ r->decrypt_state = decrypt_state;
+ vp9_reader_fill(r);
+ return vp9_read_bit(r) != 0; // marker bit
+ }
+}
+
+void vp9_reader_fill(vp9_reader *r) {
+ const uint8_t *const buffer_end = r->buffer_end;
+ const uint8_t *buffer = r->buffer;
+ const uint8_t *buffer_start = buffer;
+ BD_VALUE value = r->value;
+ int count = r->count;
+ int shift = BD_VALUE_SIZE - CHAR_BIT - (count + CHAR_BIT);
+ int loop_end = 0;
+ const size_t bytes_left = buffer_end - buffer;
+ const size_t bits_left = bytes_left * CHAR_BIT;
+ const int x = (int)(shift + CHAR_BIT - bits_left);
+
+ if (r->decrypt_cb) {
+ size_t n = MIN(sizeof(r->clear_buffer), bytes_left);
+ r->decrypt_cb(r->decrypt_state, buffer, r->clear_buffer, (int)n);
+ buffer = r->clear_buffer;
+ buffer_start = r->clear_buffer;
+ }
+
+ if (x >= 0) {
+ count += LOTS_OF_BITS;
+ loop_end = x;
+ }
+
+ if (x < 0 || bits_left) {
+ while (shift >= loop_end) {
+ count += CHAR_BIT;
+ value |= (BD_VALUE)*buffer++ << shift;
+ shift -= CHAR_BIT;
+ }
+ }
+
+ // NOTE: Variable 'buffer' may not relate to 'r->buffer' after decryption,
+ // so we increase 'r->buffer' by the amount that 'buffer' moved, rather than
+ // assign 'buffer' to 'r->buffer'.
+ r->buffer += buffer - buffer_start;
+ r->value = value;
+ r->count = count;
+}
+
+const uint8_t *vp9_reader_find_end(vp9_reader *r) {
+ // Find the end of the coded buffer
+ while (r->count > CHAR_BIT && r->count < BD_VALUE_SIZE) {
+ r->count -= CHAR_BIT;
+ r->buffer--;
+ }
+ return r->buffer;
+}
--- /dev/null
+++ b/vpx_dsp/bitreader.h
@@ -1,0 +1,140 @@
+/*
+ * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef VPX_DSP_BITREADER_H_
+#define VPX_DSP_BITREADER_H_
+
+#include <stddef.h>
+#include <limits.h>
+
+#include "./vpx_config.h"
+#include "vpx_ports/mem.h"
+#include "vpx/vp8dx.h"
+#include "vpx/vpx_integer.h"
+#include "vpx_dsp/prob.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef size_t BD_VALUE;
+
+#define BD_VALUE_SIZE ((int)sizeof(BD_VALUE) * CHAR_BIT)
+
+// This is meant to be a large, positive constant that can still be efficiently
+// loaded as an immediate (on platforms like ARM, for example).
+// Even relatively modest values like 100 would work fine.
+#define LOTS_OF_BITS 0x40000000
+
+typedef struct {
+ // Be careful when reordering this struct, it may impact the cache negatively.
+ BD_VALUE value;
+ unsigned int range;
+ int count;
+ const uint8_t *buffer_end;
+ const uint8_t *buffer;
+ vpx_decrypt_cb decrypt_cb;
+ void *decrypt_state;
+ uint8_t clear_buffer[sizeof(BD_VALUE) + 1];
+} vp9_reader;
+
+int vp9_reader_init(vp9_reader *r,
+ const uint8_t *buffer,
+ size_t size,
+ vpx_decrypt_cb decrypt_cb,
+ void *decrypt_state);
+
+void vp9_reader_fill(vp9_reader *r);
+
+const uint8_t *vp9_reader_find_end(vp9_reader *r);
+
+static INLINE int vp9_reader_has_error(vp9_reader *r) {
+ // Check if we have reached the end of the buffer.
+ //
+ // Variable 'count' stores the number of bits in the 'value' buffer, minus
+ // 8. The top byte is part of the algorithm, and the remainder is buffered
+ // to be shifted into it. So if count == 8, the top 16 bits of 'value' are
+ // occupied, 8 for the algorithm and 8 in the buffer.
+ //
+ // When reading a byte from the user's buffer, count is filled with 8 and
+ // one byte is filled into the value buffer. When we reach the end of the
+ // data, count is additionally filled with LOTS_OF_BITS. So when
+ // count == LOTS_OF_BITS - 1, the user's data has been exhausted.
+ //
+ // 1 if we have tried to decode bits after the end of stream was encountered.
+ // 0 No error.
+ return r->count > BD_VALUE_SIZE && r->count < LOTS_OF_BITS;
+}
+
+static INLINE int vp9_read(vp9_reader *r, int prob) {
+ unsigned int bit = 0;
+ BD_VALUE value;
+ BD_VALUE bigsplit;
+ int count;
+ unsigned int range;
+ unsigned int split = (r->range * prob + (256 - prob)) >> CHAR_BIT;
+
+ if (r->count < 0)
+ vp9_reader_fill(r);
+
+ value = r->value;
+ count = r->count;
+
+ bigsplit = (BD_VALUE)split << (BD_VALUE_SIZE - CHAR_BIT);
+
+ range = split;
+
+ if (value >= bigsplit) {
+ range = r->range - split;
+ value = value - bigsplit;
+ bit = 1;
+ }
+
+ {
+ register unsigned int shift = vp9_norm[range];
+ range <<= shift;
+ value <<= shift;
+ count -= shift;
+ }
+ r->value = value;
+ r->count = count;
+ r->range = range;
+
+ return bit;
+}
+
+static INLINE int vp9_read_bit(vp9_reader *r) {
+ return vp9_read(r, 128); // vp9_prob_half
+}
+
+static INLINE int vp9_read_literal(vp9_reader *r, int bits) {
+ int literal = 0, bit;
+
+ for (bit = bits - 1; bit >= 0; bit--)
+ literal |= vp9_read_bit(r) << bit;
+
+ return literal;
+}
+
+static INLINE int vp9_read_tree(vp9_reader *r, const vp9_tree_index *tree,
+ const vp9_prob *probs) {
+ vp9_tree_index i = 0;
+
+ while ((i = tree[i + vp9_read(r, probs[i >> 1])]) > 0)
+ continue;
+
+ return -i;
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // VPX_DSP_BITREADER_H_
--- /dev/null
+++ b/vpx_dsp/bitreader_buffer.c
@@ -1,0 +1,41 @@
+/*
+ * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "./bitreader_buffer.h"
+
+size_t vp9_rb_bytes_read(struct vp9_read_bit_buffer *rb) {
+ return (rb->bit_offset + 7) >> 3;
+}
+
+int vp9_rb_read_bit(struct vp9_read_bit_buffer *rb) {
+ const size_t off = rb->bit_offset;
+ const size_t p = off >> 3;
+ const int q = 7 - (int)(off & 0x7);
+ if (rb->bit_buffer + p < rb->bit_buffer_end) {
+ const int bit = (rb->bit_buffer[p] >> q) & 1;
+ rb->bit_offset = off + 1;
+ return bit;
+ } else {
+ rb->error_handler(rb->error_handler_data);
+ return 0;
+ }
+}
+
+int vp9_rb_read_literal(struct vp9_read_bit_buffer *rb, int bits) {
+ int value = 0, bit;
+ for (bit = bits - 1; bit >= 0; bit--)
+ value |= vp9_rb_read_bit(rb) << bit;
+ return value;
+}
+
+int vp9_rb_read_signed_literal(struct vp9_read_bit_buffer *rb,
+ int bits) {
+ const int value = vp9_rb_read_literal(rb, bits);
+ return vp9_rb_read_bit(rb) ? -value : value;
+}
--- /dev/null
+++ b/vpx_dsp/bitreader_buffer.h
@@ -1,0 +1,45 @@
+/*
+ * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef VPX_DSP_BITREADER_BUFFER_H_
+#define VPX_DSP_BITREADER_BUFFER_H_
+
+#include <limits.h>
+
+#include "vpx/vpx_integer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*vp9_rb_error_handler)(void *data);
+
+struct vp9_read_bit_buffer {
+ const uint8_t *bit_buffer;
+ const uint8_t *bit_buffer_end;
+ size_t bit_offset;
+
+ void *error_handler_data;
+ vp9_rb_error_handler error_handler;
+};
+
+size_t vp9_rb_bytes_read(struct vp9_read_bit_buffer *rb);
+
+int vp9_rb_read_bit(struct vp9_read_bit_buffer *rb);
+
+int vp9_rb_read_literal(struct vp9_read_bit_buffer *rb, int bits);
+
+int vp9_rb_read_signed_literal(struct vp9_read_bit_buffer *rb, int bits);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // VPX_DSP_BITREADER_BUFFER_H_
--- /dev/null
+++ b/vpx_dsp/prob.c
@@ -1,0 +1,53 @@
+/*
+ * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "./prob.h"
+
+const uint8_t vp9_norm[256] = {
+ 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+static unsigned int tree_merge_probs_impl(unsigned int i,
+ const vp9_tree_index *tree,
+ const vp9_prob *pre_probs,
+ const unsigned int *counts,
+ vp9_prob *probs) {
+ const int l = tree[i];
+ const unsigned int left_count = (l <= 0)
+ ? counts[-l]
+ : tree_merge_probs_impl(l, tree, pre_probs, counts, probs);
+ const int r = tree[i + 1];
+ const unsigned int right_count = (r <= 0)
+ ? counts[-r]
+ : tree_merge_probs_impl(r, tree, pre_probs, counts, probs);
+ const unsigned int ct[2] = { left_count, right_count };
+ probs[i >> 1] = mode_mv_merge_probs(pre_probs[i >> 1], ct);
+ return left_count + right_count;
+}
+
+void vp9_tree_merge_probs(const vp9_tree_index *tree, const vp9_prob *pre_probs,
+ const unsigned int *counts, vp9_prob *probs) {
+ tree_merge_probs_impl(0, tree, pre_probs, counts, probs);
+}
--- /dev/null
+++ b/vpx_dsp/prob.h
@@ -1,0 +1,103 @@
+/*
+ * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef VPX_DSP_PROB_H_
+#define VPX_DSP_PROB_H_
+
+#include "./vpx_config.h"
+#include "./vpx_dsp_common.h"
+
+#include "vpx_ports/mem.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef uint8_t vp9_prob;
+
+#define MAX_PROB 255
+
+#define vp9_prob_half ((vp9_prob) 128)
+
+typedef int8_t vp9_tree_index;
+
+#define TREE_SIZE(leaf_count) (2 * (leaf_count) - 2)
+
+#define vp9_complement(x) (255 - x)
+
+#define MODE_MV_COUNT_SAT 20
+
+/* We build coding trees compactly in arrays.
+ Each node of the tree is a pair of vp9_tree_indices.
+ Array index often references a corresponding probability table.
+ Index <= 0 means done encoding/decoding and value = -Index,
+ Index > 0 means need another bit, specification at index.
+ Nonnegative indices are always even; processing begins at node 0. */
+
+typedef const vp9_tree_index vp9_tree[];
+
+static INLINE vp9_prob clip_prob(int p) {
+ return (p > 255) ? 255 : (p < 1) ? 1 : p;
+}
+
+static INLINE vp9_prob get_prob(int num, int den) {
+ return (den == 0) ? 128u : clip_prob(((int64_t)num * 256 + (den >> 1)) / den);
+}
+
+static INLINE vp9_prob get_binary_prob(int n0, int n1) {
+ return get_prob(n0, n0 + n1);
+}
+
+/* This function assumes prob1 and prob2 are already within [1,255] range. */
+static INLINE vp9_prob weighted_prob(int prob1, int prob2, int factor) {
+ return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8);
+}
+
+static INLINE vp9_prob merge_probs(vp9_prob pre_prob,
+ const unsigned int ct[2],
+ unsigned int count_sat,
+ unsigned int max_update_factor) {
+ const vp9_prob prob = get_binary_prob(ct[0], ct[1]);
+ const unsigned int count = MIN(ct[0] + ct[1], count_sat);
+ const unsigned int factor = max_update_factor * count / count_sat;
+ return weighted_prob(pre_prob, prob, factor);
+}
+
+// MODE_MV_MAX_UPDATE_FACTOR (128) * count / MODE_MV_COUNT_SAT;
+static const int count_to_update_factor[MODE_MV_COUNT_SAT + 1] = {
+ 0, 6, 12, 19, 25, 32, 38, 44, 51, 57, 64,
+ 70, 76, 83, 89, 96, 102, 108, 115, 121, 128
+};
+
+static INLINE vp9_prob mode_mv_merge_probs(vp9_prob pre_prob,
+ const unsigned int ct[2]) {
+ const unsigned int den = ct[0] + ct[1];
+ if (den == 0) {
+ return pre_prob;
+ } else {
+ const unsigned int count = MIN(den, MODE_MV_COUNT_SAT);
+ const unsigned int factor = count_to_update_factor[count];
+ const vp9_prob prob =
+ clip_prob(((int64_t)(ct[0]) * 256 + (den >> 1)) / den);
+ return weighted_prob(pre_prob, prob, factor);
+ }
+}
+
+void vp9_tree_merge_probs(const vp9_tree_index *tree, const vp9_prob *pre_probs,
+ const unsigned int *counts, vp9_prob *probs);
+
+
+DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // VPX_DSP_PROB_H_
--- a/vpx_dsp/vp9_prob.c
+++ /dev/null
@@ -1,53 +1,0 @@
-/*
- * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "./vp9_prob.h"
-
-const uint8_t vp9_norm[256] = {
- 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-static unsigned int tree_merge_probs_impl(unsigned int i,
- const vp9_tree_index *tree,
- const vp9_prob *pre_probs,
- const unsigned int *counts,
- vp9_prob *probs) {
- const int l = tree[i];
- const unsigned int left_count = (l <= 0)
- ? counts[-l]
- : tree_merge_probs_impl(l, tree, pre_probs, counts, probs);
- const int r = tree[i + 1];
- const unsigned int right_count = (r <= 0)
- ? counts[-r]
- : tree_merge_probs_impl(r, tree, pre_probs, counts, probs);
- const unsigned int ct[2] = { left_count, right_count };
- probs[i >> 1] = mode_mv_merge_probs(pre_probs[i >> 1], ct);
- return left_count + right_count;
-}
-
-void vp9_tree_merge_probs(const vp9_tree_index *tree, const vp9_prob *pre_probs,
- const unsigned int *counts, vp9_prob *probs) {
- tree_merge_probs_impl(0, tree, pre_probs, counts, probs);
-}
--- a/vpx_dsp/vp9_prob.h
+++ /dev/null
@@ -1,103 +1,0 @@
-/*
- * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef VP9_COMMON_VP9_PROB_H_
-#define VP9_COMMON_VP9_PROB_H_
-
-#include "./vpx_config.h"
-#include "./vpx_dsp_common.h"
-
-#include "vpx_ports/mem.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef uint8_t vp9_prob;
-
-#define MAX_PROB 255
-
-#define vp9_prob_half ((vp9_prob) 128)
-
-typedef int8_t vp9_tree_index;
-
-#define TREE_SIZE(leaf_count) (2 * (leaf_count) - 2)
-
-#define vp9_complement(x) (255 - x)
-
-#define MODE_MV_COUNT_SAT 20
-
-/* We build coding trees compactly in arrays.
- Each node of the tree is a pair of vp9_tree_indices.
- Array index often references a corresponding probability table.
- Index <= 0 means done encoding/decoding and value = -Index,
- Index > 0 means need another bit, specification at index.
- Nonnegative indices are always even; processing begins at node 0. */
-
-typedef const vp9_tree_index vp9_tree[];
-
-static INLINE vp9_prob clip_prob(int p) {
- return (p > 255) ? 255 : (p < 1) ? 1 : p;
-}
-
-static INLINE vp9_prob get_prob(int num, int den) {
- return (den == 0) ? 128u : clip_prob(((int64_t)num * 256 + (den >> 1)) / den);
-}
-
-static INLINE vp9_prob get_binary_prob(int n0, int n1) {
- return get_prob(n0, n0 + n1);
-}
-
-/* This function assumes prob1 and prob2 are already within [1,255] range. */
-static INLINE vp9_prob weighted_prob(int prob1, int prob2, int factor) {
- return ROUND_POWER_OF_TWO(prob1 * (256 - factor) + prob2 * factor, 8);
-}
-
-static INLINE vp9_prob merge_probs(vp9_prob pre_prob,
- const unsigned int ct[2],
- unsigned int count_sat,
- unsigned int max_update_factor) {
- const vp9_prob prob = get_binary_prob(ct[0], ct[1]);
- const unsigned int count = MIN(ct[0] + ct[1], count_sat);
- const unsigned int factor = max_update_factor * count / count_sat;
- return weighted_prob(pre_prob, prob, factor);
-}
-
-// MODE_MV_MAX_UPDATE_FACTOR (128) * count / MODE_MV_COUNT_SAT;
-static const int count_to_update_factor[MODE_MV_COUNT_SAT + 1] = {
- 0, 6, 12, 19, 25, 32, 38, 44, 51, 57, 64,
- 70, 76, 83, 89, 96, 102, 108, 115, 121, 128
-};
-
-static INLINE vp9_prob mode_mv_merge_probs(vp9_prob pre_prob,
- const unsigned int ct[2]) {
- const unsigned int den = ct[0] + ct[1];
- if (den == 0) {
- return pre_prob;
- } else {
- const unsigned int count = MIN(den, MODE_MV_COUNT_SAT);
- const unsigned int factor = count_to_update_factor[count];
- const vp9_prob prob =
- clip_prob(((int64_t)(ct[0]) * 256 + (den >> 1)) / den);
- return weighted_prob(pre_prob, prob, factor);
- }
-}
-
-void vp9_tree_merge_probs(const vp9_tree_index *tree, const vp9_prob *pre_probs,
- const unsigned int *counts, vp9_prob *probs);
-
-
-DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif // VP9_COMMON_VP9_PROB_H_
--- a/vpx_dsp/vp9_read_bit_buffer.c
+++ /dev/null
@@ -1,41 +1,0 @@
-/*
- * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-#include "./vp9_read_bit_buffer.h"
-
-size_t vp9_rb_bytes_read(struct vp9_read_bit_buffer *rb) {
- return (rb->bit_offset + 7) >> 3;
-}
-
-int vp9_rb_read_bit(struct vp9_read_bit_buffer *rb) {
- const size_t off = rb->bit_offset;
- const size_t p = off >> 3;
- const int q = 7 - (int)(off & 0x7);
- if (rb->bit_buffer + p < rb->bit_buffer_end) {
- const int bit = (rb->bit_buffer[p] >> q) & 1;
- rb->bit_offset = off + 1;
- return bit;
- } else {
- rb->error_handler(rb->error_handler_data);
- return 0;
- }
-}
-
-int vp9_rb_read_literal(struct vp9_read_bit_buffer *rb, int bits) {
- int value = 0, bit;
- for (bit = bits - 1; bit >= 0; bit--)
- value |= vp9_rb_read_bit(rb) << bit;
- return value;
-}
-
-int vp9_rb_read_signed_literal(struct vp9_read_bit_buffer *rb,
- int bits) {
- const int value = vp9_rb_read_literal(rb, bits);
- return vp9_rb_read_bit(rb) ? -value : value;
-}
--- a/vpx_dsp/vp9_read_bit_buffer.h
+++ /dev/null
@@ -1,45 +1,0 @@
-/*
- * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef VP9_DECODER_VP9_READ_BIT_BUFFER_H_
-#define VP9_DECODER_VP9_READ_BIT_BUFFER_H_
-
-#include <limits.h>
-
-#include "vpx/vpx_integer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*vp9_rb_error_handler)(void *data);
-
-struct vp9_read_bit_buffer {
- const uint8_t *bit_buffer;
- const uint8_t *bit_buffer_end;
- size_t bit_offset;
-
- void *error_handler_data;
- vp9_rb_error_handler error_handler;
-};
-
-size_t vp9_rb_bytes_read(struct vp9_read_bit_buffer *rb);
-
-int vp9_rb_read_bit(struct vp9_read_bit_buffer *rb);
-
-int vp9_rb_read_literal(struct vp9_read_bit_buffer *rb, int bits);
-
-int vp9_rb_read_signed_literal(struct vp9_read_bit_buffer *rb, int bits);
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif // VP9_DECODER_VP9_READ_BIT_BUFFER_H_
--- a/vpx_dsp/vp9_reader.c
+++ /dev/null
@@ -1,83 +1,0 @@
-/*
- * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-#include "./vp9_prob.h"
-#include "./vp9_reader.h"
-
-#include "vpx_ports/mem.h"
-#include "vpx_mem/vpx_mem.h"
-
-int vp9_reader_init(vp9_reader *r,
- const uint8_t *buffer,
- size_t size,
- vpx_decrypt_cb decrypt_cb,
- void *decrypt_state) {
- if (size && !buffer) {
- return 1;
- } else {
- r->buffer_end = buffer + size;
- r->buffer = buffer;
- r->value = 0;
- r->count = -8;
- r->range = 255;
- r->decrypt_cb = decrypt_cb;
- r->decrypt_state = decrypt_state;
- vp9_reader_fill(r);
- return vp9_read_bit(r) != 0; // marker bit
- }
-}
-
-void vp9_reader_fill(vp9_reader *r) {
- const uint8_t *const buffer_end = r->buffer_end;
- const uint8_t *buffer = r->buffer;
- const uint8_t *buffer_start = buffer;
- BD_VALUE value = r->value;
- int count = r->count;
- int shift = BD_VALUE_SIZE - CHAR_BIT - (count + CHAR_BIT);
- int loop_end = 0;
- const size_t bytes_left = buffer_end - buffer;
- const size_t bits_left = bytes_left * CHAR_BIT;
- const int x = (int)(shift + CHAR_BIT - bits_left);
-
- if (r->decrypt_cb) {
- size_t n = MIN(sizeof(r->clear_buffer), bytes_left);
- r->decrypt_cb(r->decrypt_state, buffer, r->clear_buffer, (int)n);
- buffer = r->clear_buffer;
- buffer_start = r->clear_buffer;
- }
-
- if (x >= 0) {
- count += LOTS_OF_BITS;
- loop_end = x;
- }
-
- if (x < 0 || bits_left) {
- while (shift >= loop_end) {
- count += CHAR_BIT;
- value |= (BD_VALUE)*buffer++ << shift;
- shift -= CHAR_BIT;
- }
- }
-
- // NOTE: Variable 'buffer' may not relate to 'r->buffer' after decryption,
- // so we increase 'r->buffer' by the amount that 'buffer' moved, rather than
- // assign 'buffer' to 'r->buffer'.
- r->buffer += buffer - buffer_start;
- r->value = value;
- r->count = count;
-}
-
-const uint8_t *vp9_reader_find_end(vp9_reader *r) {
- // Find the end of the coded buffer
- while (r->count > CHAR_BIT && r->count < BD_VALUE_SIZE) {
- r->count -= CHAR_BIT;
- r->buffer--;
- }
- return r->buffer;
-}
--- a/vpx_dsp/vp9_reader.h
+++ /dev/null
@@ -1,140 +1,0 @@
-/*
- * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef VP9_DECODER_VP9_READER_H_
-#define VP9_DECODER_VP9_READER_H_
-
-#include <stddef.h>
-#include <limits.h>
-
-#include "./vpx_config.h"
-#include "vpx_ports/mem.h"
-#include "vpx/vp8dx.h"
-#include "vpx/vpx_integer.h"
-#include "vpx_dsp/vp9_prob.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef size_t BD_VALUE;
-
-#define BD_VALUE_SIZE ((int)sizeof(BD_VALUE) * CHAR_BIT)
-
-// This is meant to be a large, positive constant that can still be efficiently
-// loaded as an immediate (on platforms like ARM, for example).
-// Even relatively modest values like 100 would work fine.
-#define LOTS_OF_BITS 0x40000000
-
-typedef struct {
- // Be careful when reordering this struct, it may impact the cache negatively.
- BD_VALUE value;
- unsigned int range;
- int count;
- const uint8_t *buffer_end;
- const uint8_t *buffer;
- vpx_decrypt_cb decrypt_cb;
- void *decrypt_state;
- uint8_t clear_buffer[sizeof(BD_VALUE) + 1];
-} vp9_reader;
-
-int vp9_reader_init(vp9_reader *r,
- const uint8_t *buffer,
- size_t size,
- vpx_decrypt_cb decrypt_cb,
- void *decrypt_state);
-
-void vp9_reader_fill(vp9_reader *r);
-
-const uint8_t *vp9_reader_find_end(vp9_reader *r);
-
-static INLINE int vp9_reader_has_error(vp9_reader *r) {
- // Check if we have reached the end of the buffer.
- //
- // Variable 'count' stores the number of bits in the 'value' buffer, minus
- // 8. The top byte is part of the algorithm, and the remainder is buffered
- // to be shifted into it. So if count == 8, the top 16 bits of 'value' are
- // occupied, 8 for the algorithm and 8 in the buffer.
- //
- // When reading a byte from the user's buffer, count is filled with 8 and
- // one byte is filled into the value buffer. When we reach the end of the
- // data, count is additionally filled with LOTS_OF_BITS. So when
- // count == LOTS_OF_BITS - 1, the user's data has been exhausted.
- //
- // 1 if we have tried to decode bits after the end of stream was encountered.
- // 0 No error.
- return r->count > BD_VALUE_SIZE && r->count < LOTS_OF_BITS;
-}
-
-static INLINE int vp9_read(vp9_reader *r, int prob) {
- unsigned int bit = 0;
- BD_VALUE value;
- BD_VALUE bigsplit;
- int count;
- unsigned int range;
- unsigned int split = (r->range * prob + (256 - prob)) >> CHAR_BIT;
-
- if (r->count < 0)
- vp9_reader_fill(r);
-
- value = r->value;
- count = r->count;
-
- bigsplit = (BD_VALUE)split << (BD_VALUE_SIZE - CHAR_BIT);
-
- range = split;
-
- if (value >= bigsplit) {
- range = r->range - split;
- value = value - bigsplit;
- bit = 1;
- }
-
- {
- register unsigned int shift = vp9_norm[range];
- range <<= shift;
- value <<= shift;
- count -= shift;
- }
- r->value = value;
- r->count = count;
- r->range = range;
-
- return bit;
-}
-
-static INLINE int vp9_read_bit(vp9_reader *r) {
- return vp9_read(r, 128); // vp9_prob_half
-}
-
-static INLINE int vp9_read_literal(vp9_reader *r, int bits) {
- int literal = 0, bit;
-
- for (bit = bits - 1; bit >= 0; bit--)
- literal |= vp9_read_bit(r) << bit;
-
- return literal;
-}
-
-static INLINE int vp9_read_tree(vp9_reader *r, const vp9_tree_index *tree,
- const vp9_prob *probs) {
- vp9_tree_index i = 0;
-
- while ((i = tree[i + vp9_read(r, probs[i >> 1])]) > 0)
- continue;
-
- return -i;
-}
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif // VP9_DECODER_VP9_READER_H_
--- a/vpx_dsp/vpx_dsp.mk
+++ b/vpx_dsp/vpx_dsp.mk
@@ -14,14 +14,14 @@
DSP_SRCS-$(HAVE_MSA) += mips/macros_msa.h
# bit reader
-DSP_SRCS-yes += vp9_prob.h
-DSP_SRCS-yes += vp9_prob.c
+DSP_SRCS-yes += prob.h
+DSP_SRCS-yes += prob.c
ifeq ($(CONFIG_DECODERS),yes)
-DSP_SRCS-yes += vp9_reader.h
-DSP_SRCS-yes += vp9_reader.c
-DSP_SRCS-yes += vp9_read_bit_buffer.c
-DSP_SRCS-yes += vp9_read_bit_buffer.h
+DSP_SRCS-yes += bitreader.h
+DSP_SRCS-yes += bitreader.c
+DSP_SRCS-yes += bitreader_buffer.c
+DSP_SRCS-yes += bitreader_buffer.h
endif
# loop filters