• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
aom_reader_init(aom_reader * r,const uint8_t * buffer,size_t size)14 int 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 
aom_reader_find_begin(aom_reader * r)27 const uint8_t *aom_reader_find_begin(aom_reader *r) { return r->buffer; }
28 
aom_reader_find_end(aom_reader * r)29 const uint8_t *aom_reader_find_end(aom_reader *r) { return r->buffer_end; }
30 
aom_reader_tell(const aom_reader * r)31 uint32_t aom_reader_tell(const aom_reader *r) { return od_ec_dec_tell(&r->ec); }
32 
aom_reader_tell_frac(const aom_reader * r)33 uint32_t aom_reader_tell_frac(const aom_reader *r) {
34   return od_ec_dec_tell_frac(&r->ec);
35 }
36 
aom_reader_has_overflowed(const aom_reader * r)37 int 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 }
42