blob: c746167775e2bf1374acd5982f61a122a2cf04a3 [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
James Zerne1cbb132018-08-22 14:10:36 -070012#ifndef AOM_AOM_DSP_ENTDEC_H_
13#define AOM_AOM_DSP_ENTDEC_H_
Nathan E. Egge1078dee2016-03-06 10:59:29 -050014#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;
Nathan E. Egge1078dee2016-03-06 10:59:29 -050035 /*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 Changed997ab2018-08-14 12:35:17 -070037 important once we hit the end of the buffer and stop incrementing bptr
Wan-Teh Changc8ae5682018-05-08 12:15:36 -070038 (and instead pretend cnt has lots of bits).*/
Nathan E. Egge1078dee2016-03-06 10:59:29 -050039 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. Terriberryf9ef4f62017-08-25 11:24:18 -070044 /*The difference between the high end of the current range, (low + rng), and
45 the coded value, minus 1.
Timothy B. Terriberry881f1092017-03-07 20:03:09 -080046 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. Egge1078dee2016-03-06 10:59:29 -050051 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. Egge1078dee2016-03-06 10:59:29 -050056};
57
58/*See entdec.c for further documentation.*/
59
60void 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. Terriberryead52872017-03-07 20:27:34 -080063OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned f)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050064 OD_ARG_NONNULL(1);
Michael Bebenita63b44c42016-08-23 16:03:39 -070065OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15(od_ec_dec *dec,
66 const uint16_t *cdf, int nsyms)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050067 OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
Nathan E. Egge1078dee2016-03-06 10:59:29 -050068
Yushin Cho77bba8d2016-11-04 16:36:56 -070069OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050070 OD_ARG_NONNULL(1);
71
Nathan E. Egge19698a72016-08-18 02:34:53 -040072OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec)
73 OD_ARG_NONNULL(1);
74OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_tell_frac(const od_ec_dec *dec)
75 OD_ARG_NONNULL(1);
Nathan E. Egge1078dee2016-03-06 10:59:29 -050076
77#ifdef __cplusplus
78} // extern "C"
79#endif
80
James Zerne1cbb132018-08-22 14:10:36 -070081#endif // AOM_AOM_DSP_ENTDEC_H_