tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

entdec.h (2945B)


      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_ENTDEC_H_
     13 #define AOM_AOM_DSP_ENTDEC_H_
     14 #include <limits.h>
     15 #include "aom_dsp/entcode.h"
     16 
     17 #ifdef __cplusplus
     18 extern "C" {
     19 #endif
     20 
     21 typedef struct od_ec_dec od_ec_dec;
     22 
     23 #if defined(OD_ACCOUNTING) && OD_ACCOUNTING
     24 #define OD_ACC_STR , char *acc_str
     25 #define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb, str)
     26 #else
     27 #define OD_ACC_STR
     28 #define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb)
     29 #endif
     30 
     31 /*The entropy decoder context.*/
     32 struct od_ec_dec {
     33  /*The start of the current input buffer.*/
     34  const unsigned char *buf;
     35  /*An offset used to keep track of tell after reaching the end of the stream.
     36    This is constant throughout most of the decoding process, but becomes
     37     important once we hit the end of the buffer and stop incrementing bptr
     38     (and instead pretend cnt has lots of bits).*/
     39  int32_t tell_offs;
     40  /*The end of the current input buffer.*/
     41  const unsigned char *end;
     42  /*The read pointer for the entropy-coded bits.*/
     43  const unsigned char *bptr;
     44  /*The difference between the high end of the current range, (low + rng), and
     45     the coded value, minus 1.
     46    This stores up to OD_EC_WINDOW_SIZE bits of that difference, but the
     47     decoder only uses the top 16 bits of the window to decode the next symbol.
     48    As we shift up during renormalization, if we don't have enough bits left in
     49     the window to fill the top 16, we'll read in more bits of the coded
     50     value.*/
     51  od_ec_window dif;
     52  /*The number of values in the current range.*/
     53  uint16_t rng;
     54  /*The number of bits of data in the current value.*/
     55  int16_t cnt;
     56 };
     57 
     58 /*See entdec.c for further documentation.*/
     59 
     60 void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf, uint32_t storage)
     61    OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
     62 
     63 OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned f)
     64    OD_ARG_NONNULL(1);
     65 OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15(od_ec_dec *dec,
     66                                               const uint16_t *cdf, int nsyms)
     67    OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
     68 
     69 OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb)
     70    OD_ARG_NONNULL(1);
     71 
     72 OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec)
     73    OD_ARG_NONNULL(1);
     74 OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_tell_frac(const od_ec_dec *dec)
     75    OD_ARG_NONNULL(1);
     76 
     77 #ifdef __cplusplus
     78 }  // extern "C"
     79 #endif
     80 
     81 #endif  // AOM_AOM_DSP_ENTDEC_H_