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 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AOM_DSP_ENTDEC_H_ |
| 13 | #define AOM_AOM_DSP_ENTDEC_H_ |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 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; |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 35 | /*An offset used to keep track of tell after reaching the end of the stream. |
| 36 | This is constant throughout most of the decoding process, but becomes |
Wan-Teh Chang | ed997ab | 2018-08-14 12:35:17 -0700 | [diff] [blame] | 37 | important once we hit the end of the buffer and stop incrementing bptr |
Wan-Teh Chang | c8ae568 | 2018-05-08 12:15:36 -0700 | [diff] [blame] | 38 | (and instead pretend cnt has lots of bits).*/ |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 39 | int32_t tell_offs; |
| 40 | /*The end of the current input buffer.*/ |
| 41 | const unsigned char *end; |
| 42 | /*The read pointer for the entropy-coded bits.*/ |
| 43 | const unsigned char *bptr; |
Timothy B. Terriberry | f9ef4f6 | 2017-08-25 11:24:18 -0700 | [diff] [blame] | 44 | /*The difference between the high end of the current range, (low + rng), and |
| 45 | the coded value, minus 1. |
Timothy B. Terriberry | 881f109 | 2017-03-07 20:03:09 -0800 | [diff] [blame] | 46 | This stores up to OD_EC_WINDOW_SIZE bits of that difference, but the |
| 47 | decoder only uses the top 16 bits of the window to decode the next symbol. |
| 48 | As we shift up during renormalization, if we don't have enough bits left in |
| 49 | the window to fill the top 16, we'll read in more bits of the coded |
| 50 | value.*/ |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 51 | od_ec_window dif; |
| 52 | /*The number of values in the current range.*/ |
| 53 | uint16_t rng; |
| 54 | /*The number of bits of data in the current value.*/ |
| 55 | int16_t cnt; |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | /*See entdec.c for further documentation.*/ |
| 59 | |
| 60 | void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf, uint32_t storage) |
| 61 | OD_ARG_NONNULL(1) OD_ARG_NONNULL(2); |
| 62 | |
Timothy B. Terriberry | ead5287 | 2017-03-07 20:27:34 -0800 | [diff] [blame] | 63 | 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] | 64 | OD_ARG_NONNULL(1); |
Michael Bebenita | 63b44c4 | 2016-08-23 16:03:39 -0700 | [diff] [blame] | 65 | OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15(od_ec_dec *dec, |
| 66 | const uint16_t *cdf, int nsyms) |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 67 | OD_ARG_NONNULL(1) OD_ARG_NONNULL(2); |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 68 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 69 | 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] | 70 | OD_ARG_NONNULL(1); |
| 71 | |
Nathan E. Egge | 19698a7 | 2016-08-18 02:34:53 -0400 | [diff] [blame] | 72 | OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec) |
| 73 | OD_ARG_NONNULL(1); |
| 74 | OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_tell_frac(const od_ec_dec *dec) |
| 75 | OD_ARG_NONNULL(1); |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 76 | |
| 77 | #ifdef __cplusplus |
| 78 | } // extern "C" |
| 79 | #endif |
| 80 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 81 | #endif // AOM_AOM_DSP_ENTDEC_H_ |