summaryrefslogtreecommitdiff
path: root/vp9/decoder/vp9_dboolhuff.c
diff options
context:
space:
mode:
Diffstat (limited to 'vp9/decoder/vp9_dboolhuff.c')
-rw-r--r--vp9/decoder/vp9_dboolhuff.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/vp9/decoder/vp9_dboolhuff.c b/vp9/decoder/vp9_dboolhuff.c
index df77d650d..31b1ae2b0 100644
--- a/vp9/decoder/vp9_dboolhuff.c
+++ b/vp9/decoder/vp9_dboolhuff.c
@@ -13,6 +13,12 @@
#include "vp9/decoder/vp9_dboolhuff.h"
+// 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 VP9_LOTS_OF_BITS 0x40000000
+
+
int vp9_reader_init(vp9_reader *r, const uint8_t *buffer, size_t size) {
int marker_bit;
@@ -67,3 +73,20 @@ const uint8_t *vp9_reader_find_end(vp9_reader *r) {
return r->buffer;
}
+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 VP9_LOTS_OF_BITS. So when
+ // count == VP9_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 > VP9_BD_VALUE_SIZE && r->count < VP9_LOTS_OF_BITS;
+}