blob: 6d6e2b51ea40dd974c4b197968eb79f4bddab702 [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
Yushin Cho77bba8d2016-11-04 16:36:56 -070023#if OD_ACCOUNTING
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. 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;
50 /*The difference between the coded value and the low end of the current
51 range.*/
52 od_ec_window dif;
53 /*The number of values in the current range.*/
54 uint16_t rng;
55 /*The number of bits of data in the current value.*/
56 int16_t cnt;
57 /*Nonzero if an error occurred.*/
58 int error;
Nathan E. Egge1078dee2016-03-06 10:59:29 -050059};
60
61/*See entdec.c for further documentation.*/
62
63void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf, uint32_t storage)
64 OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
65
Michael Bebenita63b44c42016-08-23 16:03:39 -070066OD_WARN_UNUSED_RESULT int od_ec_decode_bool(od_ec_dec *dec, unsigned fz,
67 unsigned ft) OD_ARG_NONNULL(1);
68OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned fz)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050069 OD_ARG_NONNULL(1);
Michael Bebenita63b44c42016-08-23 16:03:39 -070070OD_WARN_UNUSED_RESULT int od_ec_decode_cdf(od_ec_dec *dec, const uint16_t *cdf,
71 int nsyms) OD_ARG_NONNULL(1)
72 OD_ARG_NONNULL(2);
73OD_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);
Michael Bebenita63b44c42016-08-23 16:03:39 -070076OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled(od_ec_dec *dec,
77 const uint16_t *cdf,
78 int nsyms) OD_ARG_NONNULL(1)
79 OD_ARG_NONNULL(2);
80OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_unscaled_dyadic(od_ec_dec *dec,
81 const uint16_t *cdf,
82 int nsyms,
83 unsigned _ftb)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050084 OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
85
Michael Bebenita63b44c42016-08-23 16:03:39 -070086OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_uint(od_ec_dec *dec, uint32_t ft)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050087 OD_ARG_NONNULL(1);
88
Yushin Cho77bba8d2016-11-04 16:36:56 -070089OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050090 OD_ARG_NONNULL(1);
91
Nathan E. Egge19698a72016-08-18 02:34:53 -040092OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec)
93 OD_ARG_NONNULL(1);
94OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_tell_frac(const od_ec_dec *dec)
95 OD_ARG_NONNULL(1);
Nathan E. Egge1078dee2016-03-06 10:59:29 -050096
97#ifdef __cplusplus
98} // extern "C"
99#endif
100
101#endif