Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001-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 | */ |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 11 | |
| 12 | #if !defined(_entdec_H) |
| 13 | #define _entdec_H (1) |
| 14 | #include <limits.h> |
Yaowu Xu | 931bc2a | 2016-10-14 13:53:51 -0700 | [diff] [blame] | 15 | #include "aom_dsp/entcode.h" |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | typedef struct od_ec_dec od_ec_dec; |
| 22 | |
Alex Converse | 64d7ef6 | 2017-03-22 18:09:16 -0700 | [diff] [blame] | 23 | #if defined(OD_ACCOUNTING) && OD_ACCOUNTING |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 24 | #define OD_ACC_STR , char *acc_str |
| 25 | #define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb, str) |
| 26 | #else |
| 27 | #define OD_ACC_STR |
| 28 | #define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb) |
| 29 | #endif |
| 30 | |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 31 | /*The entropy decoder context.*/ |
| 32 | struct od_ec_dec { |
| 33 | /*The start of the current input buffer.*/ |
| 34 | const unsigned char *buf; |
| 35 | /*The read pointer for the raw bits.*/ |
| 36 | const unsigned char *eptr; |
| 37 | /*Bits that will be read from/written at the end.*/ |
| 38 | od_ec_window end_window; |
| 39 | /*Number of valid bits in end_window.*/ |
| 40 | int nend_bits; |
| 41 | /*An offset used to keep track of tell after reaching the end of the stream. |
| 42 | This is constant throughout most of the decoding process, but becomes |
| 43 | important once we hit the end of the buffer and stop incrementing pointers |
| 44 | (and instead pretend cnt/nend_bits have lots of bits).*/ |
| 45 | int32_t tell_offs; |
| 46 | /*The end of the current input buffer.*/ |
| 47 | const unsigned char *end; |
| 48 | /*The read pointer for the entropy-coded bits.*/ |
| 49 | const unsigned char *bptr; |
Timothy B. Terriberry | f9ef4f6 | 2017-08-25 11:24:18 -0700 | [diff] [blame] | 50 | /*The difference between the high end of the current range, (low + rng), and |
| 51 | the coded value, minus 1. |
Timothy B. Terriberry | 881f109 | 2017-03-07 20:03:09 -0800 | [diff] [blame] | 52 | This stores up to OD_EC_WINDOW_SIZE bits of that difference, but the |
| 53 | decoder only uses the top 16 bits of the window to decode the next symbol. |
| 54 | As we shift up during renormalization, if we don't have enough bits left in |
| 55 | the window to fill the top 16, we'll read in more bits of the coded |
| 56 | value.*/ |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 57 | od_ec_window dif; |
| 58 | /*The number of values in the current range.*/ |
| 59 | uint16_t rng; |
| 60 | /*The number of bits of data in the current value.*/ |
| 61 | int16_t cnt; |
| 62 | /*Nonzero if an error occurred.*/ |
| 63 | int error; |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /*See entdec.c for further documentation.*/ |
| 67 | |
| 68 | void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf, uint32_t storage) |
| 69 | OD_ARG_NONNULL(1) OD_ARG_NONNULL(2); |
| 70 | |
Timothy B. Terriberry | ead5287 | 2017-03-07 20:27:34 -0800 | [diff] [blame] | 71 | OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned f) |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 72 | OD_ARG_NONNULL(1); |
Michael Bebenita | 63b44c4 | 2016-08-23 16:03:39 -0700 | [diff] [blame] | 73 | OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15(od_ec_dec *dec, |
| 74 | const uint16_t *cdf, int nsyms) |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 75 | OD_ARG_NONNULL(1) OD_ARG_NONNULL(2); |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 76 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 77 | OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb) |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 78 | OD_ARG_NONNULL(1); |
| 79 | |
Nathan E. Egge | 19698a7 | 2016-08-18 02:34:53 -0400 | [diff] [blame] | 80 | OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec) |
| 81 | OD_ARG_NONNULL(1); |
| 82 | OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_tell_frac(const od_ec_dec *dec) |
| 83 | OD_ARG_NONNULL(1); |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 84 | |
| 85 | #ifdef __cplusplus |
| 86 | } // extern "C" |
| 87 | #endif |
| 88 | |
| 89 | #endif |