blob: 314b3631867df72a67ff2a2b9ab9fac7054c7753 [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(_entenc_H)
13#define _entenc_H (1)
14#include <stddef.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_enc od_ec_enc;
22
23#define OD_MEASURE_EC_OVERHEAD (0)
24
25/*The entropy encoder context.*/
26struct od_ec_enc {
27 /*Buffered output.
28 This contains only the raw bits until the final call to od_ec_enc_done(),
29 where all the arithmetic-coded data gets prepended to it.*/
30 unsigned char *buf;
31 /*The size of the buffer.*/
32 uint32_t storage;
33 /*The offset at which the last byte containing raw bits was written.*/
34 uint32_t end_offs;
35 /*Bits that will be read from/written at the end.*/
36 od_ec_window end_window;
37 /*Number of valid bits in end_window.*/
38 int nend_bits;
39 /*A buffer for output bytes with their associated carry flags.*/
40 uint16_t *precarry_buf;
41 /*The size of the pre-carry buffer.*/
42 uint32_t precarry_storage;
43 /*The offset at which the next entropy-coded byte will be written.*/
44 uint32_t offs;
45 /*The low end of the current range.*/
46 od_ec_window low;
47 /*The number of values in the current range.*/
48 uint16_t rng;
49 /*The number of bits of data in the current value.*/
50 int16_t cnt;
51 /*Nonzero if an error occurred.*/
52 int error;
53#if OD_MEASURE_EC_OVERHEAD
54 double entropy;
55 int nb_symbols;
56#endif
57};
58
59/*See entenc.c for further documentation.*/
60
61void od_ec_enc_init(od_ec_enc *enc, uint32_t size) OD_ARG_NONNULL(1);
62void od_ec_enc_reset(od_ec_enc *enc) OD_ARG_NONNULL(1);
63void od_ec_enc_clear(od_ec_enc *enc) OD_ARG_NONNULL(1);
64
Timothy B. Terriberry41b4f752017-03-07 17:45:30 -080065void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned f_q15)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050066 OD_ARG_NONNULL(1);
Nathan E. Egge1078dee2016-03-06 10:59:29 -050067void od_ec_encode_cdf_q15(od_ec_enc *enc, int s, const uint16_t *cdf, int nsyms)
68 OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
Nathan E. Egge1078dee2016-03-06 10:59:29 -050069
70void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb)
71 OD_ARG_NONNULL(1);
72
73void od_ec_enc_patch_initial_bits(od_ec_enc *enc, unsigned val, int nbits)
74 OD_ARG_NONNULL(1);
75OD_WARN_UNUSED_RESULT unsigned char *od_ec_enc_done(od_ec_enc *enc,
76 uint32_t *nbytes)
77 OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
78
Nathan E. Egge19698a72016-08-18 02:34:53 -040079OD_WARN_UNUSED_RESULT int od_ec_enc_tell(const od_ec_enc *enc)
80 OD_ARG_NONNULL(1);
81OD_WARN_UNUSED_RESULT uint32_t od_ec_enc_tell_frac(const od_ec_enc *enc)
Nathan E. Egge1078dee2016-03-06 10:59:29 -050082 OD_ARG_NONNULL(1);
83
84void od_ec_enc_checkpoint(od_ec_enc *dst, const od_ec_enc *src);
85void od_ec_enc_rollback(od_ec_enc *dst, const od_ec_enc *src);
86
87#ifdef __cplusplus
88} // extern "C"
89#endif
90
91#endif