Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 1 | /*Daala video codec |
| 2 | Copyright (c) 2001-2013 Daala project contributors. All rights reserved. |
| 3 | |
| 4 | Redistribution and use in source and binary forms, with or without |
| 5 | modification, 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 | |
| 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | OF 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 Xu | 931bc2a | 2016-10-14 13:53:51 -0700 | [diff] [blame] | 28 | #include "aom_dsp/entcode.h" |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 29 | |
| 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | typedef struct od_ec_enc od_ec_enc; |
| 35 | |
| 36 | #define OD_MEASURE_EC_OVERHEAD (0) |
| 37 | |
| 38 | /*The entropy encoder context.*/ |
| 39 | struct 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 | |
| 74 | void od_ec_enc_init(od_ec_enc *enc, uint32_t size) OD_ARG_NONNULL(1); |
| 75 | void od_ec_enc_reset(od_ec_enc *enc) OD_ARG_NONNULL(1); |
| 76 | void od_ec_enc_clear(od_ec_enc *enc) OD_ARG_NONNULL(1); |
| 77 | |
| 78 | void od_ec_encode_bool(od_ec_enc *enc, int val, unsigned fz, unsigned _ft) |
| 79 | OD_ARG_NONNULL(1); |
| 80 | void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned fz_q15) |
| 81 | OD_ARG_NONNULL(1); |
| 82 | void 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); |
| 84 | void 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); |
| 86 | void 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); |
| 88 | void 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 | |
| 93 | void od_ec_enc_uint(od_ec_enc *enc, uint32_t fl, uint32_t ft) OD_ARG_NONNULL(1); |
| 94 | |
| 95 | void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb) |
| 96 | OD_ARG_NONNULL(1); |
| 97 | |
| 98 | void od_ec_enc_patch_initial_bits(od_ec_enc *enc, unsigned val, int nbits) |
| 99 | OD_ARG_NONNULL(1); |
| 100 | OD_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. Egge | 19698a7 | 2016-08-18 02:34:53 -0400 | [diff] [blame] | 104 | OD_WARN_UNUSED_RESULT int od_ec_enc_tell(const od_ec_enc *enc) |
| 105 | OD_ARG_NONNULL(1); |
| 106 | OD_WARN_UNUSED_RESULT uint32_t od_ec_enc_tell_frac(const od_ec_enc *enc) |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 107 | OD_ARG_NONNULL(1); |
| 108 | |
| 109 | void od_ec_enc_checkpoint(od_ec_enc *dst, const od_ec_enc *src); |
| 110 | void 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 |