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