blob: 35ac7fe0de1c2a69858d0b168318457356f57065 [file] [log] [blame]
Yushin Cho77bba8d2016-11-04 16:36:56 -07001/*
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. Egge1078dee2016-03-06 10:59:29 -050011
12#if !defined(_entdec_H)
13#define _entdec_H (1)
14#include <limits.h>
Yaowu Xu931bc2a2016-10-14 13:53:51 -070015#include "aom_dsp/entcode.h"
Nathan E. Egge1078dee2016-03-06 10:59:29 -050016
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21typedef struct od_ec_dec od_ec_dec;
22
Alex Converse64d7ef62017-03-22 18:09:16 -070023#if defined(OD_ACCOUNTING) && OD_ACCOUNTING
Yushin Cho77bba8d2016-11-04 16:36:56 -070024#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. Egge1078dee2016-03-06 10:59:29 -050031/*The entropy decoder context.*/
32struct 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. Terriberryf9ef4f62017-08-25 11:24:18 -070050 /*The difference between the high end of the current range, (low + rng), and
51 the coded value, minus 1.
Timothy B. Terriberry881f1092017-03-07 20:03:09 -080052 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. Egge1078dee2016-03-06 10:59:29 -050057 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. Egge1078dee2016-03-06 10:59:29 -050064};
65
66/*See entdec.c for further documentation.*/
67
68void 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. Terriberryead52872017-03-07 20:27:34 -080071OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned f)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050072 OD_ARG_NONNULL(1);
Michael Bebenita63b44c42016-08-23 16:03:39 -070073OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15(od_ec_dec *dec,
74 const uint16_t *cdf, int nsyms)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050075 OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
Nathan E. Egge1078dee2016-03-06 10:59:29 -050076
Yushin Cho77bba8d2016-11-04 16:36:56 -070077OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050078 OD_ARG_NONNULL(1);
79
Nathan E. Egge19698a72016-08-18 02:34:53 -040080OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec)
81 OD_ARG_NONNULL(1);
82OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_tell_frac(const od_ec_dec *dec)
83 OD_ARG_NONNULL(1);
Nathan E. Egge1078dee2016-03-06 10:59:29 -050084
85#ifdef __cplusplus
86} // extern "C"
87#endif
88
89#endif