/********************************************************************1* *2* THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *3* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *4* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *5* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *6* *7* THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *8* by the Xiph.Org Foundation and contributors *9* https://www.xiph.org/ *10* *11********************************************************************1213function:1415********************************************************************/1617#include <limits.h>18#if !defined(_decint_H)19# define _decint_H (1)20# include "theora/theoradec.h"21# include "state.h"22# include "bitpack.h"23# include "huffdec.h"24# include "dequant.h"2526typedef struct th_setup_info oc_setup_info;27typedef struct oc_dec_opt_vtable oc_dec_opt_vtable;28typedef struct oc_dec_pipeline_state oc_dec_pipeline_state;29typedef struct th_dec_ctx oc_dec_ctx;30313233/*Decoder-specific accelerated functions.*/34# if defined(OC_C64X_ASM)35# include "c64x/c64xdec.h"36# endif3738# if !defined(oc_dec_accel_init)39# define oc_dec_accel_init oc_dec_accel_init_c40# endif41# if defined(OC_DEC_USE_VTABLE)42# if !defined(oc_dec_dc_unpredict_mcu_plane)43# define oc_dec_dc_unpredict_mcu_plane(_dec,_pipe,_pli) \44((*(_dec)->opt_vtable.dc_unpredict_mcu_plane)(_dec,_pipe,_pli))45# endif46# else47# if !defined(oc_dec_dc_unpredict_mcu_plane)48# define oc_dec_dc_unpredict_mcu_plane oc_dec_dc_unpredict_mcu_plane_c49# endif50# endif51525354/*Constants for the packet-in state machine specific to the decoder.*/5556/*Next packet to read: Data packet.*/57#define OC_PACKET_DATA (0)58596061struct th_setup_info{62/*The Huffman codes.*/63ogg_int16_t *huff_tables[TH_NHUFFMAN_TABLES];64/*The quantization parameters.*/65th_quant_info qinfo;66};67686970/*Decoder specific functions with accelerated variants.*/71struct oc_dec_opt_vtable{72void (*dc_unpredict_mcu_plane)(oc_dec_ctx *_dec,73oc_dec_pipeline_state *_pipe,int _pli);74};75767778struct oc_dec_pipeline_state{79/*Decoded DCT coefficients.80These are placed here instead of on the stack so that they can persist81between blocks, which makes clearing them back to zero much faster when82only a few non-zero coefficients were decoded.83It requires at least 65 elements because the zig-zag index array uses the8465th element as a dumping ground for out-of-range indices to protect us85from buffer overflow.86We make it fully twice as large so that the second half can serve as the87reconstruction buffer, which saves passing another parameter to all the88acceleration functions.89It also solves problems with 16-byte alignment for NEON on ARM.90gcc (as of 4.2.1) only seems to be able to give stack variables 8-byte91alignment, and silently produces incorrect results if you ask for 16.92Finally, keeping it off the stack means there's less likely to be a data93hazard between the NEON co-processor and the regular ARM core, which avoids94unnecessary stalls.*/95OC_ALIGN16(ogg_int16_t dct_coeffs[128]);96OC_ALIGN16(signed char bounding_values[256]);97ptrdiff_t ti[3][64];98ptrdiff_t ebi[3][64];99ptrdiff_t eob_runs[3][64];100const ptrdiff_t *coded_fragis[3];101const ptrdiff_t *uncoded_fragis[3];102ptrdiff_t ncoded_fragis[3];103ptrdiff_t nuncoded_fragis[3];104const ogg_uint16_t *dequant[3][3][2];105int fragy0[3];106int fragy_end[3];107int pred_last[3][4];108int mcu_nvfrags;109int loop_filter;110int pp_level;111};112113114struct th_dec_ctx{115/*Shared encoder/decoder state.*/116oc_theora_state state;117/*Whether or not packets are ready to be emitted.118This takes on negative values while there are remaining header packets to119be emitted, reaches 0 when the codec is ready for input, and goes to 1120when a frame has been processed and a data packet is ready.*/121int packet_state;122/*Buffer in which to assemble packets.*/123oc_pack_buf opb;124/*Huffman decode trees.*/125ogg_int16_t *huff_tables[TH_NHUFFMAN_TABLES];126/*The index of the first token in each plane for each coefficient.*/127ptrdiff_t ti0[3][64];128/*The number of outstanding EOB runs at the start of each coefficient in each129plane.*/130ptrdiff_t eob_runs[3][64];131/*The DCT token lists.*/132unsigned char *dct_tokens;133/*The extra bits associated with DCT tokens.*/134unsigned char *extra_bits;135/*The number of dct tokens unpacked so far.*/136int dct_tokens_count;137/*The out-of-loop post-processing level.*/138int pp_level;139/*The DC scale used for out-of-loop deblocking.*/140int pp_dc_scale[64];141/*The sharpen modifier used for out-of-loop deringing.*/142int pp_sharp_mod[64];143/*The DC quantization index of each block.*/144unsigned char *dc_qis;145/*The variance of each block.*/146int *variances;147/*The storage for the post-processed frame buffer.*/148unsigned char *pp_frame_data;149/*Whether or not the post-processsed frame buffer has space for chroma.*/150int pp_frame_state;151/*The buffer used for the post-processed frame.152Note that this is _not_ guaranteed to have the same strides and offsets as153the reference frame buffers.*/154th_ycbcr_buffer pp_frame_buf;155/*The striped decode callback function.*/156th_stripe_callback stripe_cb;157oc_dec_pipeline_state pipe;158# if defined(OC_DEC_USE_VTABLE)159/*Table for decoder acceleration functions.*/160oc_dec_opt_vtable opt_vtable;161# endif162# if defined(HAVE_CAIRO)163/*Output metrics for debugging.*/164int telemetry_mbmode;165int telemetry_mv;166int telemetry_qi;167int telemetry_bits;168int telemetry_frame_bytes;169int telemetry_coding_bytes;170int telemetry_mode_bytes;171int telemetry_mv_bytes;172int telemetry_qi_bytes;173int telemetry_dc_bytes;174unsigned char *telemetry_frame_data;175# endif176};177178/*Default pure-C implementations of decoder-specific accelerated functions.*/179void oc_dec_accel_init_c(oc_dec_ctx *_dec);180181void oc_dec_dc_unpredict_mcu_plane_c(oc_dec_ctx *_dec,182oc_dec_pipeline_state *_pipe,int _pli);183184#endif185186187