summaryrefslogtreecommitdiff
path: root/vp9/encoder/vp9_writer.h
diff options
context:
space:
mode:
authorDmitry Kovalev <dkovalev@google.com>2013-12-20 11:10:24 -0800
committerDmitry Kovalev <dkovalev@google.com>2013-12-20 11:10:24 -0800
commit4084566554452537e008e6b1065084e7402e50c1 (patch)
treeeb2e13209420701dd1fc5caa6ce6af73306d5a53 /vp9/encoder/vp9_writer.h
parentc67ee5ea24e6c4549c9929ef0e9cb3838a851fcf (diff)
downloadlibvpx-4084566554452537e008e6b1065084e7402e50c1.tar
libvpx-4084566554452537e008e6b1065084e7402e50c1.tar.gz
libvpx-4084566554452537e008e6b1065084e7402e50c1.tar.bz2
libvpx-4084566554452537e008e6b1065084e7402e50c1.zip
Renaming vp9_boolcoder.{h, c} to vp9_writer.{h, c}.
Change-Id: I9b9a5fcce8530284df0f270706ee060a0edc1517
Diffstat (limited to 'vp9/encoder/vp9_writer.h')
-rw-r--r--vp9/encoder/vp9_writer.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/vp9/encoder/vp9_writer.h b/vp9/encoder/vp9_writer.h
new file mode 100644
index 000000000..9cac7a84f
--- /dev/null
+++ b/vp9/encoder/vp9_writer.h
@@ -0,0 +1,108 @@
+/*
+ * 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_ENCODER_VP9_WRITER_H_
+#define VP9_ENCODER_VP9_WRITER_H_
+
+#include "vpx_ports/mem.h"
+
+#include "vp9/common/vp9_prob.h"
+
+typedef struct {
+ unsigned int lowvalue;
+ unsigned int range;
+ unsigned int value;
+ int count;
+ unsigned int pos;
+ uint8_t *buffer;
+
+ // Variables used to track bit costs without outputing to the bitstream
+ unsigned int measure_cost;
+ uint64_t bit_counter;
+} vp9_writer;
+
+extern const unsigned int vp9_prob_cost[256];
+
+void vp9_start_encode(vp9_writer *bc, uint8_t *buffer);
+void vp9_stop_encode(vp9_writer *bc);
+
+static void vp9_write(vp9_writer *br, int bit, int probability) {
+ unsigned int split;
+ int count = br->count;
+ unsigned int range = br->range;
+ unsigned int lowvalue = br->lowvalue;
+ register unsigned int shift;
+
+#ifdef ENTROPY_STATS
+#if defined(SECTIONBITS_OUTPUT)
+
+ if (bit)
+ Sectionbits[active_section] += vp9_prob_cost[255 - probability];
+ else
+ Sectionbits[active_section] += vp9_prob_cost[probability];
+
+#endif
+#endif
+
+ split = 1 + (((range - 1) * probability) >> 8);
+
+ range = split;
+
+ if (bit) {
+ lowvalue += split;
+ range = br->range - split;
+ }
+
+ shift = vp9_norm[range];
+
+ range <<= shift;
+ count += shift;
+
+ if (count >= 0) {
+ int offset = shift - count;
+
+ if ((lowvalue << (offset - 1)) & 0x80000000) {
+ int x = br->pos - 1;
+
+ while (x >= 0 && br->buffer[x] == 0xff) {
+ br->buffer[x] = 0;
+ x--;
+ }
+
+ br->buffer[x] += 1;
+ }
+
+ br->buffer[br->pos++] = (lowvalue >> (24 - offset));
+ lowvalue <<= offset;
+ shift = count;
+ lowvalue &= 0xffffff;
+ count -= 8;
+ }
+
+ lowvalue <<= shift;
+ br->count = count;
+ br->lowvalue = lowvalue;
+ 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));
+}
+
+#define vp9_write_prob(w, v) vp9_write_literal((w), (v), 8)
+
+#endif // VP9_ENCODER_VP9_WRITER_H_