xref: /aosp_15_r20/external/libaom/aom_dsp/entdec.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2001-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 #ifndef AOM_AOM_DSP_ENTDEC_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AOM_DSP_ENTDEC_H_
14*77c1e3ccSAndroid Build Coastguard Worker #include <limits.h>
15*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/entcode.h"
16*77c1e3ccSAndroid Build Coastguard Worker 
17*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
18*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
19*77c1e3ccSAndroid Build Coastguard Worker #endif
20*77c1e3ccSAndroid Build Coastguard Worker 
21*77c1e3ccSAndroid Build Coastguard Worker typedef struct od_ec_dec od_ec_dec;
22*77c1e3ccSAndroid Build Coastguard Worker 
23*77c1e3ccSAndroid Build Coastguard Worker #if defined(OD_ACCOUNTING) && OD_ACCOUNTING
24*77c1e3ccSAndroid Build Coastguard Worker #define OD_ACC_STR , char *acc_str
25*77c1e3ccSAndroid Build Coastguard Worker #define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb, str)
26*77c1e3ccSAndroid Build Coastguard Worker #else
27*77c1e3ccSAndroid Build Coastguard Worker #define OD_ACC_STR
28*77c1e3ccSAndroid Build Coastguard Worker #define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb)
29*77c1e3ccSAndroid Build Coastguard Worker #endif
30*77c1e3ccSAndroid Build Coastguard Worker 
31*77c1e3ccSAndroid Build Coastguard Worker /*The entropy decoder context.*/
32*77c1e3ccSAndroid Build Coastguard Worker struct od_ec_dec {
33*77c1e3ccSAndroid Build Coastguard Worker   /*The start of the current input buffer.*/
34*77c1e3ccSAndroid Build Coastguard Worker   const unsigned char *buf;
35*77c1e3ccSAndroid Build Coastguard Worker   /*An offset used to keep track of tell after reaching the end of the stream.
36*77c1e3ccSAndroid Build Coastguard Worker     This is constant throughout most of the decoding process, but becomes
37*77c1e3ccSAndroid Build Coastguard Worker      important once we hit the end of the buffer and stop incrementing bptr
38*77c1e3ccSAndroid Build Coastguard Worker      (and instead pretend cnt has lots of bits).*/
39*77c1e3ccSAndroid Build Coastguard Worker   int32_t tell_offs;
40*77c1e3ccSAndroid Build Coastguard Worker   /*The end of the current input buffer.*/
41*77c1e3ccSAndroid Build Coastguard Worker   const unsigned char *end;
42*77c1e3ccSAndroid Build Coastguard Worker   /*The read pointer for the entropy-coded bits.*/
43*77c1e3ccSAndroid Build Coastguard Worker   const unsigned char *bptr;
44*77c1e3ccSAndroid Build Coastguard Worker   /*The difference between the high end of the current range, (low + rng), and
45*77c1e3ccSAndroid Build Coastguard Worker      the coded value, minus 1.
46*77c1e3ccSAndroid Build Coastguard Worker     This stores up to OD_EC_WINDOW_SIZE bits of that difference, but the
47*77c1e3ccSAndroid Build Coastguard Worker      decoder only uses the top 16 bits of the window to decode the next symbol.
48*77c1e3ccSAndroid Build Coastguard Worker     As we shift up during renormalization, if we don't have enough bits left in
49*77c1e3ccSAndroid Build Coastguard Worker      the window to fill the top 16, we'll read in more bits of the coded
50*77c1e3ccSAndroid Build Coastguard Worker      value.*/
51*77c1e3ccSAndroid Build Coastguard Worker   od_ec_window dif;
52*77c1e3ccSAndroid Build Coastguard Worker   /*The number of values in the current range.*/
53*77c1e3ccSAndroid Build Coastguard Worker   uint16_t rng;
54*77c1e3ccSAndroid Build Coastguard Worker   /*The number of bits of data in the current value.*/
55*77c1e3ccSAndroid Build Coastguard Worker   int16_t cnt;
56*77c1e3ccSAndroid Build Coastguard Worker };
57*77c1e3ccSAndroid Build Coastguard Worker 
58*77c1e3ccSAndroid Build Coastguard Worker /*See entdec.c for further documentation.*/
59*77c1e3ccSAndroid Build Coastguard Worker 
60*77c1e3ccSAndroid Build Coastguard Worker void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf, uint32_t storage)
61*77c1e3ccSAndroid Build Coastguard Worker     OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
62*77c1e3ccSAndroid Build Coastguard Worker 
63*77c1e3ccSAndroid Build Coastguard Worker OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned f)
64*77c1e3ccSAndroid Build Coastguard Worker     OD_ARG_NONNULL(1);
65*77c1e3ccSAndroid Build Coastguard Worker OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15(od_ec_dec *dec,
66*77c1e3ccSAndroid Build Coastguard Worker                                                const uint16_t *cdf, int nsyms)
67*77c1e3ccSAndroid Build Coastguard Worker     OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
68*77c1e3ccSAndroid Build Coastguard Worker 
69*77c1e3ccSAndroid Build Coastguard Worker OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb)
70*77c1e3ccSAndroid Build Coastguard Worker     OD_ARG_NONNULL(1);
71*77c1e3ccSAndroid Build Coastguard Worker 
72*77c1e3ccSAndroid Build Coastguard Worker OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec)
73*77c1e3ccSAndroid Build Coastguard Worker     OD_ARG_NONNULL(1);
74*77c1e3ccSAndroid Build Coastguard Worker OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_tell_frac(const od_ec_dec *dec)
75*77c1e3ccSAndroid Build Coastguard Worker     OD_ARG_NONNULL(1);
76*77c1e3ccSAndroid Build Coastguard Worker 
77*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
78*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
79*77c1e3ccSAndroid Build Coastguard Worker #endif
80*77c1e3ccSAndroid Build Coastguard Worker 
81*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AOM_DSP_ENTDEC_H_
82