Nathan E. Egge | 8043cc4 | 2016-03-06 12:42:47 -0500 | [diff] [blame] | 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 | #ifndef AOM_DSP_DAALABOOLREADER_H_ |
| 13 | #define AOM_DSP_DAALABOOLREADER_H_ |
| 14 | |
| 15 | #include "aom_dsp/entdec.h" |
| 16 | #include "aom_dsp/prob.h" |
| 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
| 22 | struct daala_reader { |
| 23 | const uint8_t *buffer; |
| 24 | const uint8_t *buffer_end; |
| 25 | od_ec_dec ec; |
| 26 | }; |
| 27 | |
| 28 | typedef struct daala_reader daala_reader; |
| 29 | |
| 30 | int aom_daala_reader_init(daala_reader *r, const uint8_t *buffer, int size); |
| 31 | const uint8_t *aom_daala_reader_find_end(daala_reader *r); |
| 32 | |
| 33 | static INLINE int aom_daala_read(daala_reader *r, int prob) { |
| 34 | if (prob == 128) { |
| 35 | return od_ec_dec_bits(&r->ec, 1, "aom_bits"); |
| 36 | } else { |
| 37 | int p = ((prob << 15) + (256 - prob)) >> 8; |
| 38 | return od_ec_decode_bool_q15(&r->ec, p, "aom"); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | static INLINE int aom_daala_read_bit(daala_reader *r) { |
| 43 | return aom_daala_read(r, 128); |
| 44 | } |
| 45 | |
| 46 | static INLINE int aom_daala_reader_has_error(daala_reader *r) { |
| 47 | return r->ec.error; |
| 48 | } |
| 49 | |
Nathan E. Egge | 43acafd | 2016-03-06 13:41:53 -0500 | [diff] [blame] | 50 | static INLINE int daala_read_tree_bits(daala_reader *r, |
| 51 | const aom_tree_index *tree, |
| 52 | const aom_prob *probs) { |
| 53 | aom_tree_index i = 0; |
| 54 | do { |
Nathan E. Egge | 9ac1f7d | 2016-08-19 17:16:31 -0400 | [diff] [blame^] | 55 | aom_cdf_prob cdf[16]; |
Nathan E. Egge | 43acafd | 2016-03-06 13:41:53 -0500 | [diff] [blame] | 56 | aom_tree_index index[16]; |
| 57 | int path[16]; |
| 58 | int dist[16]; |
| 59 | int nsymbs; |
| 60 | int symb; |
| 61 | nsymbs = tree_to_cdf(tree, probs, i, cdf, index, path, dist); |
| 62 | symb = od_ec_decode_cdf_q15(&r->ec, cdf, nsymbs, "aom"); |
| 63 | OD_ASSERT(symb >= 0 && symb < nsymbs); |
| 64 | i = index[symb]; |
| 65 | } while (i > 0); |
| 66 | return -i; |
| 67 | } |
| 68 | |
Nathan E. Egge | 9ac1f7d | 2016-08-19 17:16:31 -0400 | [diff] [blame^] | 69 | static INLINE int daala_read_symbol(daala_reader *r, const aom_cdf_prob *cdf, |
Nathan E. Egge | 45741e9 | 2016-08-19 15:31:43 -0400 | [diff] [blame] | 70 | int nsymbs) { |
Nathan E. Egge | 4446014 | 2016-06-20 13:44:22 -0400 | [diff] [blame] | 71 | return od_ec_decode_cdf_q15(&r->ec, cdf, nsymbs, "aom"); |
| 72 | } |
| 73 | |
Nathan E. Egge | 8043cc4 | 2016-03-06 12:42:47 -0500 | [diff] [blame] | 74 | #ifdef __cplusplus |
| 75 | } // extern "C" |
| 76 | #endif |
| 77 | |
| 78 | #endif |