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 */ 11 12 #ifndef AOM_AOM_DSP_ENTENC_H_ 13 #define AOM_AOM_DSP_ENTENC_H_ 14 #include <stddef.h> 15 #include "aom_dsp/entcode.h" 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 /*A buffer for output bytes with their associated carry flags.*/ 34 uint16_t *precarry_buf; 35 /*The size of the pre-carry buffer.*/ 36 uint32_t precarry_storage; 37 /*The offset at which the next entropy-coded byte will be written.*/ 38 uint32_t offs; 39 /*The low end of the current range.*/ 40 od_ec_window low; 41 /*The number of values in the current range.*/ 42 uint16_t rng; 43 /*The number of bits of data in the current value.*/ 44 int16_t cnt; 45 /*Nonzero if an error occurred.*/ 46 int error; 47 #if OD_MEASURE_EC_OVERHEAD 48 double entropy; 49 int nb_symbols; 50 #endif 51 }; 52 53 /*See entenc.c for further documentation.*/ 54 55 void od_ec_enc_init(od_ec_enc *enc, uint32_t size) OD_ARG_NONNULL(1); 56 void od_ec_enc_reset(od_ec_enc *enc) OD_ARG_NONNULL(1); 57 void od_ec_enc_clear(od_ec_enc *enc) OD_ARG_NONNULL(1); 58 59 void od_ec_encode_bool_q15(od_ec_enc *enc, int val, unsigned f_q15) 60 OD_ARG_NONNULL(1); 61 void od_ec_encode_cdf_q15(od_ec_enc *enc, int s, const uint16_t *cdf, int nsyms) 62 OD_ARG_NONNULL(1) OD_ARG_NONNULL(3); 63 64 void od_ec_enc_bits(od_ec_enc *enc, uint32_t fl, unsigned ftb) 65 OD_ARG_NONNULL(1); 66 67 void od_ec_enc_patch_initial_bits(od_ec_enc *enc, unsigned val, int nbits) 68 OD_ARG_NONNULL(1); 69 OD_WARN_UNUSED_RESULT unsigned char *od_ec_enc_done(od_ec_enc *enc, 70 uint32_t *nbytes) 71 OD_ARG_NONNULL(1) OD_ARG_NONNULL(2); 72 73 OD_WARN_UNUSED_RESULT int od_ec_enc_tell(const od_ec_enc *enc) 74 OD_ARG_NONNULL(1); 75 OD_WARN_UNUSED_RESULT uint32_t od_ec_enc_tell_frac(const od_ec_enc *enc) 76 OD_ARG_NONNULL(1); 77 78 void od_ec_enc_checkpoint(od_ec_enc *dst, const od_ec_enc *src); 79 void od_ec_enc_rollback(od_ec_enc *dst, const od_ec_enc *src); 80 81 #ifdef __cplusplus 82 } // extern "C" 83 #endif 84 85 #endif // AOM_AOM_DSP_ENTENC_H_ 86