Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 1 | /* |
| 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. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 11 | |
| 12 | #if !defined(_entenc_H) |
| 13 | #define _entenc_H (1) |
| 14 | #include <stddef.h> |
Yaowu Xu | 931bc2a | 2016-10-14 13:53:51 -0700 | [diff] [blame] | 15 | #include "aom_dsp/entcode.h" |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | typedef struct od_ec_enc od_ec_enc; |
| 22 | |
| 23 | #define OD_MEASURE_EC_OVERHEAD (0) |
| 24 | |
| 25 | /*The entropy encoder context.*/ |
| 26 | struct 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 | |
| 61 | void od_ec_enc_init(od_ec_enc *enc, uint32_t size) OD_ARG_NONNULL(1); |
| 62 | void od_ec_enc_reset(od_ec_enc *enc) OD_ARG_NONNULL(1); |
| 63 | void od_ec_enc_clear(od_ec_enc *enc) OD_ARG_NONNULL(1); |
| 64 | |
Timothy B. Terriberry | 41b4f75 | 2017-03-07 17:45:30 -0800 | [diff] [blame] | 65 | void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned f_q15) |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 66 | OD_ARG_NONNULL(1); |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 67 | void 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. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 69 | |
| 70 | void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb) |
| 71 | OD_ARG_NONNULL(1); |
| 72 | |
| 73 | void od_ec_enc_patch_initial_bits(od_ec_enc *enc, unsigned val, int nbits) |
| 74 | OD_ARG_NONNULL(1); |
| 75 | OD_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. Egge | 19698a7 | 2016-08-18 02:34:53 -0400 | [diff] [blame] | 79 | OD_WARN_UNUSED_RESULT int od_ec_enc_tell(const od_ec_enc *enc) |
| 80 | OD_ARG_NONNULL(1); |
| 81 | 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] | 82 | OD_ARG_NONNULL(1); |
| 83 | |
| 84 | void od_ec_enc_checkpoint(od_ec_enc *dst, const od_ec_enc *src); |
| 85 | void 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 |