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/daalaboolreader.h" 13 aom_daala_reader_init(daala_reader * r,const uint8_t * buffer,int size)14int aom_daala_reader_init(daala_reader *r, const uint8_t *buffer, int 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, size); 21 #if CONFIG_ACCOUNTING 22 r->accounting = NULL; 23 #endif 24 return 0; 25 } 26 aom_daala_reader_find_begin(daala_reader * r)27const uint8_t *aom_daala_reader_find_begin(daala_reader *r) { 28 return r->buffer; 29 } 30 aom_daala_reader_find_end(daala_reader * r)31const uint8_t *aom_daala_reader_find_end(daala_reader *r) { 32 return r->buffer_end; 33 } 34 aom_daala_reader_tell(const daala_reader * r)35uint32_t aom_daala_reader_tell(const daala_reader *r) { 36 return od_ec_dec_tell(&r->ec); 37 } 38 aom_daala_reader_tell_frac(const daala_reader * r)39uint32_t aom_daala_reader_tell_frac(const daala_reader *r) { 40 return od_ec_dec_tell_frac(&r->ec); 41 } 42 aom_daala_reader_has_overflowed(const daala_reader * r)43int aom_daala_reader_has_overflowed(const daala_reader *r) { 44 const uint32_t tell_bits = aom_daala_reader_tell(r); 45 const uint32_t tell_bytes = (tell_bits + 7) >> 3; 46 return ((ptrdiff_t)tell_bytes > r->buffer_end - r->buffer); 47 } 48