2016-11-05 02:36:56 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
|
|
|
|
*
|
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
|
|
|
*/
|
2016-03-06 18:59:29 +03:00
|
|
|
|
|
|
|
#if !defined(_entdec_H)
|
|
|
|
#define _entdec_H (1)
|
|
|
|
#include <limits.h>
|
2016-10-14 23:53:51 +03:00
|
|
|
#include "aom_dsp/entcode.h"
|
2016-03-06 18:59:29 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct od_ec_dec od_ec_dec;
|
|
|
|
|
2017-03-23 04:09:16 +03:00
|
|
|
#if defined(OD_ACCOUNTING) && OD_ACCOUNTING
|
2016-11-05 02:36:56 +03:00
|
|
|
#define OD_ACC_STR , char *acc_str
|
|
|
|
#define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb, str)
|
|
|
|
#else
|
|
|
|
#define OD_ACC_STR
|
|
|
|
#define od_ec_dec_bits(dec, ftb, str) od_ec_dec_bits_(dec, ftb)
|
|
|
|
#endif
|
|
|
|
|
2016-03-06 18:59:29 +03:00
|
|
|
/*The entropy decoder context.*/
|
|
|
|
struct od_ec_dec {
|
|
|
|
/*The start of the current input buffer.*/
|
|
|
|
const unsigned char *buf;
|
|
|
|
/*The read pointer for the raw bits.*/
|
|
|
|
const unsigned char *eptr;
|
|
|
|
/*Bits that will be read from/written at the end.*/
|
|
|
|
od_ec_window end_window;
|
|
|
|
/*Number of valid bits in end_window.*/
|
|
|
|
int nend_bits;
|
|
|
|
/*An offset used to keep track of tell after reaching the end of the stream.
|
|
|
|
This is constant throughout most of the decoding process, but becomes
|
|
|
|
important once we hit the end of the buffer and stop incrementing pointers
|
|
|
|
(and instead pretend cnt/nend_bits have lots of bits).*/
|
|
|
|
int32_t tell_offs;
|
|
|
|
/*The end of the current input buffer.*/
|
|
|
|
const unsigned char *end;
|
|
|
|
/*The read pointer for the entropy-coded bits.*/
|
|
|
|
const unsigned char *bptr;
|
|
|
|
/*The difference between the coded value and the low end of the current
|
2017-03-08 07:03:09 +03:00
|
|
|
range.
|
|
|
|
{EC_SMALLMUL} The difference between the high end of the current range,
|
|
|
|
(low + rng), and the coded value, minus 1.
|
|
|
|
This stores up to OD_EC_WINDOW_SIZE bits of that difference, but the
|
|
|
|
decoder only uses the top 16 bits of the window to decode the next symbol.
|
|
|
|
As we shift up during renormalization, if we don't have enough bits left in
|
|
|
|
the window to fill the top 16, we'll read in more bits of the coded
|
|
|
|
value.*/
|
2016-03-06 18:59:29 +03:00
|
|
|
od_ec_window dif;
|
|
|
|
/*The number of values in the current range.*/
|
|
|
|
uint16_t rng;
|
|
|
|
/*The number of bits of data in the current value.*/
|
|
|
|
int16_t cnt;
|
|
|
|
/*Nonzero if an error occurred.*/
|
|
|
|
int error;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*See entdec.c for further documentation.*/
|
|
|
|
|
|
|
|
void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf, uint32_t storage)
|
|
|
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
|
|
|
|
2017-03-08 07:27:34 +03:00
|
|
|
OD_WARN_UNUSED_RESULT int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned f)
|
2016-03-06 18:59:29 +03:00
|
|
|
OD_ARG_NONNULL(1);
|
2016-08-24 02:03:39 +03:00
|
|
|
OD_WARN_UNUSED_RESULT int od_ec_decode_cdf_q15(od_ec_dec *dec,
|
|
|
|
const uint16_t *cdf, int nsyms)
|
2016-03-06 18:59:29 +03:00
|
|
|
OD_ARG_NONNULL(1) OD_ARG_NONNULL(2);
|
|
|
|
|
2016-11-05 02:36:56 +03:00
|
|
|
OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_bits_(od_ec_dec *dec, unsigned ftb)
|
2016-03-06 18:59:29 +03:00
|
|
|
OD_ARG_NONNULL(1);
|
|
|
|
|
2016-08-18 09:34:53 +03:00
|
|
|
OD_WARN_UNUSED_RESULT int od_ec_dec_tell(const od_ec_dec *dec)
|
|
|
|
OD_ARG_NONNULL(1);
|
|
|
|
OD_WARN_UNUSED_RESULT uint32_t od_ec_dec_tell_frac(const od_ec_dec *dec)
|
|
|
|
OD_ARG_NONNULL(1);
|
2016-03-06 18:59:29 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|