blob: 32163f794af1012bd044a340a7d2ce2289e8d530 [file] [log] [blame]
Nathan E. Egge1078dee2016-03-06 10:59:29 -05001/*Daala video codec
2Copyright (c) 2001-2013 Daala project contributors. All rights reserved.
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are met:
6
7- Redistributions of source code must retain the above copyright notice, this
8 list of conditions and the following disclaimer.
9
10- Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13
14THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/
24
25#if !defined(_entenc_H)
26#define _entenc_H (1)
27#include <stddef.h>
Yaowu Xu931bc2a2016-10-14 13:53:51 -070028#include "aom_dsp/entcode.h"
Nathan E. Egge1078dee2016-03-06 10:59:29 -050029
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34typedef struct od_ec_enc od_ec_enc;
35
36#define OD_MEASURE_EC_OVERHEAD (0)
37
38/*The entropy encoder context.*/
39struct od_ec_enc {
40 /*Buffered output.
41 This contains only the raw bits until the final call to od_ec_enc_done(),
42 where all the arithmetic-coded data gets prepended to it.*/
43 unsigned char *buf;
44 /*The size of the buffer.*/
45 uint32_t storage;
46 /*The offset at which the last byte containing raw bits was written.*/
47 uint32_t end_offs;
48 /*Bits that will be read from/written at the end.*/
49 od_ec_window end_window;
50 /*Number of valid bits in end_window.*/
51 int nend_bits;
52 /*A buffer for output bytes with their associated carry flags.*/
53 uint16_t *precarry_buf;
54 /*The size of the pre-carry buffer.*/
55 uint32_t precarry_storage;
56 /*The offset at which the next entropy-coded byte will be written.*/
57 uint32_t offs;
58 /*The low end of the current range.*/
59 od_ec_window low;
60 /*The number of values in the current range.*/
61 uint16_t rng;
62 /*The number of bits of data in the current value.*/
63 int16_t cnt;
64 /*Nonzero if an error occurred.*/
65 int error;
66#if OD_MEASURE_EC_OVERHEAD
67 double entropy;
68 int nb_symbols;
69#endif
70};
71
72/*See entenc.c for further documentation.*/
73
74void od_ec_enc_init(od_ec_enc *enc, uint32_t size) OD_ARG_NONNULL(1);
75void od_ec_enc_reset(od_ec_enc *enc) OD_ARG_NONNULL(1);
76void od_ec_enc_clear(od_ec_enc *enc) OD_ARG_NONNULL(1);
77
78void od_ec_encode_bool(od_ec_enc *enc, int val, unsigned fz, unsigned _ft)
79 OD_ARG_NONNULL(1);
80void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned fz_q15)
81 OD_ARG_NONNULL(1);
82void od_ec_encode_cdf(od_ec_enc *enc, int s, const uint16_t *cdf, int nsyms)
83 OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
84void od_ec_encode_cdf_q15(od_ec_enc *enc, int s, const uint16_t *cdf, int nsyms)
85 OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
86void od_ec_encode_cdf_unscaled(od_ec_enc *enc, int s, const uint16_t *cdf,
87 int nsyms) OD_ARG_NONNULL(1) OD_ARG_NONNULL(3);
88void od_ec_encode_cdf_unscaled_dyadic(od_ec_enc *enc, int s,
89 const uint16_t *cdf, int nsyms,
90 unsigned ftb) OD_ARG_NONNULL(1)
91 OD_ARG_NONNULL(3);
92
93void od_ec_enc_uint(od_ec_enc *enc, uint32_t fl, uint32_t ft) OD_ARG_NONNULL(1);
94
95void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb)
96 OD_ARG_NONNULL(1);
97
98void od_ec_enc_patch_initial_bits(od_ec_enc *enc, unsigned val, int nbits)
99 OD_ARG_NONNULL(1);
100OD_WARN_UNUSED_RESULT unsigned char *od_ec_enc_done(od_ec_enc *enc,
101 uint32_t *nbytes)
102 OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
103
Nathan E. Egge19698a72016-08-18 02:34:53 -0400104OD_WARN_UNUSED_RESULT int od_ec_enc_tell(const od_ec_enc *enc)
105 OD_ARG_NONNULL(1);
106OD_WARN_UNUSED_RESULT uint32_t od_ec_enc_tell_frac(const od_ec_enc *enc)
Nathan E. Egge1078dee2016-03-06 10:59:29 -0500107 OD_ARG_NONNULL(1);
108
109void od_ec_enc_checkpoint(od_ec_enc *dst, const od_ec_enc *src);
110void od_ec_enc_rollback(od_ec_enc *dst, const od_ec_enc *src);
111
112#ifdef __cplusplus
113} // extern "C"
114#endif
115
116#endif