blob: 4c70a91712579125758c1fe6f5f6b1a86a014bac [file] [log] [blame]
Wan-Teh Changd9a824f2020-03-23 20:18:33 -07001/*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12#include "aom_dsp/bitreader.h"
13
14int aom_reader_init(aom_reader *r, const uint8_t *buffer, size_t size) {
15 if (size && !buffer) {
16 return 1;
17 }
18 r->buffer_end = buffer + size;
19 r->buffer = buffer;
20 od_ec_dec_init(&r->ec, buffer, (uint32_t)size);
21#if CONFIG_ACCOUNTING
22 r->accounting = NULL;
23#endif
24 return 0;
25}
26
27const uint8_t *aom_reader_find_begin(aom_reader *r) { return r->buffer; }
28
29const uint8_t *aom_reader_find_end(aom_reader *r) { return r->buffer_end; }
30
31uint32_t aom_reader_tell(const aom_reader *r) { return od_ec_dec_tell(&r->ec); }
32
33uint32_t aom_reader_tell_frac(const aom_reader *r) {
34 return od_ec_dec_tell_frac(&r->ec);
35}
36
37int aom_reader_has_overflowed(const aom_reader *r) {
38 const uint32_t tell_bits = aom_reader_tell(r);
39 const uint32_t tell_bytes = (tell_bits + 7) >> 3;
40 return ((ptrdiff_t)tell_bytes > r->buffer_end - r->buffer);
41}