michael@0: /******************************************************************** michael@0: * * michael@0: * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * michael@0: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * michael@0: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * michael@0: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * michael@0: * * michael@0: * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 * michael@0: * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * michael@0: * * michael@0: ******************************************************************** michael@0: michael@0: function: michael@0: last mod: $Id: decint.h 17457 2010-09-24 02:05:49Z tterribe $ michael@0: michael@0: ********************************************************************/ michael@0: michael@0: #include michael@0: #if !defined(_decint_H) michael@0: # define _decint_H (1) michael@0: # include "theora/theoradec.h" michael@0: # include "state.h" michael@0: # include "bitpack.h" michael@0: # include "huffdec.h" michael@0: # include "dequant.h" michael@0: michael@0: typedef struct th_setup_info oc_setup_info; michael@0: typedef struct oc_dec_opt_vtable oc_dec_opt_vtable; michael@0: typedef struct oc_dec_pipeline_state oc_dec_pipeline_state; michael@0: typedef struct th_dec_ctx oc_dec_ctx; michael@0: michael@0: michael@0: michael@0: /*Decoder-specific accelerated functions.*/ michael@0: # if defined(OC_C64X_ASM) michael@0: # include "c64x/c64xdec.h" michael@0: # endif michael@0: michael@0: # if !defined(oc_dec_accel_init) michael@0: # define oc_dec_accel_init oc_dec_accel_init_c michael@0: # endif michael@0: # if defined(OC_DEC_USE_VTABLE) michael@0: # if !defined(oc_dec_dc_unpredict_mcu_plane) michael@0: # define oc_dec_dc_unpredict_mcu_plane(_dec,_pipe,_pli) \ michael@0: ((*(_dec)->opt_vtable.dc_unpredict_mcu_plane)(_dec,_pipe,_pli)) michael@0: # endif michael@0: # else michael@0: # if !defined(oc_dec_dc_unpredict_mcu_plane) michael@0: # define oc_dec_dc_unpredict_mcu_plane oc_dec_dc_unpredict_mcu_plane_c michael@0: # endif michael@0: # endif michael@0: michael@0: michael@0: michael@0: /*Constants for the packet-in state machine specific to the decoder.*/ michael@0: michael@0: /*Next packet to read: Data packet.*/ michael@0: #define OC_PACKET_DATA (0) michael@0: michael@0: michael@0: michael@0: struct th_setup_info{ michael@0: /*The Huffman codes.*/ michael@0: ogg_int16_t *huff_tables[TH_NHUFFMAN_TABLES]; michael@0: /*The quantization parameters.*/ michael@0: th_quant_info qinfo; michael@0: }; michael@0: michael@0: michael@0: michael@0: /*Decoder specific functions with accelerated variants.*/ michael@0: struct oc_dec_opt_vtable{ michael@0: void (*dc_unpredict_mcu_plane)(oc_dec_ctx *_dec, michael@0: oc_dec_pipeline_state *_pipe,int _pli); michael@0: }; michael@0: michael@0: michael@0: michael@0: struct oc_dec_pipeline_state{ michael@0: /*Decoded DCT coefficients. michael@0: These are placed here instead of on the stack so that they can persist michael@0: between blocks, which makes clearing them back to zero much faster when michael@0: only a few non-zero coefficients were decoded. michael@0: It requires at least 65 elements because the zig-zag index array uses the michael@0: 65th element as a dumping ground for out-of-range indices to protect us michael@0: from buffer overflow. michael@0: We make it fully twice as large so that the second half can serve as the michael@0: reconstruction buffer, which saves passing another parameter to all the michael@0: acceleration functios. michael@0: It also solves problems with 16-byte alignment for NEON on ARM. michael@0: gcc (as of 4.2.1) only seems to be able to give stack variables 8-byte michael@0: alignment, and silently produces incorrect results if you ask for 16. michael@0: Finally, keeping it off the stack means there's less likely to be a data michael@0: hazard beween the NEON co-processor and the regular ARM core, which avoids michael@0: unnecessary stalls.*/ michael@0: OC_ALIGN16(ogg_int16_t dct_coeffs[128]); michael@0: OC_ALIGN16(signed char bounding_values[256]); michael@0: ptrdiff_t ti[3][64]; michael@0: ptrdiff_t ebi[3][64]; michael@0: ptrdiff_t eob_runs[3][64]; michael@0: const ptrdiff_t *coded_fragis[3]; michael@0: const ptrdiff_t *uncoded_fragis[3]; michael@0: ptrdiff_t ncoded_fragis[3]; michael@0: ptrdiff_t nuncoded_fragis[3]; michael@0: const ogg_uint16_t *dequant[3][3][2]; michael@0: int fragy0[3]; michael@0: int fragy_end[3]; michael@0: int pred_last[3][4]; michael@0: int mcu_nvfrags; michael@0: int loop_filter; michael@0: int pp_level; michael@0: }; michael@0: michael@0: michael@0: struct th_dec_ctx{ michael@0: /*Shared encoder/decoder state.*/ michael@0: oc_theora_state state; michael@0: /*Whether or not packets are ready to be emitted. michael@0: This takes on negative values while there are remaining header packets to michael@0: be emitted, reaches 0 when the codec is ready for input, and goes to 1 michael@0: when a frame has been processed and a data packet is ready.*/ michael@0: int packet_state; michael@0: /*Buffer in which to assemble packets.*/ michael@0: oc_pack_buf opb; michael@0: /*Huffman decode trees.*/ michael@0: ogg_int16_t *huff_tables[TH_NHUFFMAN_TABLES]; michael@0: /*The index of the first token in each plane for each coefficient.*/ michael@0: ptrdiff_t ti0[3][64]; michael@0: /*The number of outstanding EOB runs at the start of each coefficient in each michael@0: plane.*/ michael@0: ptrdiff_t eob_runs[3][64]; michael@0: /*The DCT token lists.*/ michael@0: unsigned char *dct_tokens; michael@0: /*The extra bits associated with DCT tokens.*/ michael@0: unsigned char *extra_bits; michael@0: /*The number of dct tokens unpacked so far.*/ michael@0: int dct_tokens_count; michael@0: /*The out-of-loop post-processing level.*/ michael@0: int pp_level; michael@0: /*The DC scale used for out-of-loop deblocking.*/ michael@0: int pp_dc_scale[64]; michael@0: /*The sharpen modifier used for out-of-loop deringing.*/ michael@0: int pp_sharp_mod[64]; michael@0: /*The DC quantization index of each block.*/ michael@0: unsigned char *dc_qis; michael@0: /*The variance of each block.*/ michael@0: int *variances; michael@0: /*The storage for the post-processed frame buffer.*/ michael@0: unsigned char *pp_frame_data; michael@0: /*Whether or not the post-processsed frame buffer has space for chroma.*/ michael@0: int pp_frame_state; michael@0: /*The buffer used for the post-processed frame. michael@0: Note that this is _not_ guaranteed to have the same strides and offsets as michael@0: the reference frame buffers.*/ michael@0: th_ycbcr_buffer pp_frame_buf; michael@0: /*The striped decode callback function.*/ michael@0: th_stripe_callback stripe_cb; michael@0: oc_dec_pipeline_state pipe; michael@0: # if defined(OC_DEC_USE_VTABLE) michael@0: /*Table for decoder acceleration functions.*/ michael@0: oc_dec_opt_vtable opt_vtable; michael@0: # endif michael@0: # if defined(HAVE_CAIRO) michael@0: /*Output metrics for debugging.*/ michael@0: int telemetry; michael@0: int telemetry_mbmode; michael@0: int telemetry_mv; michael@0: int telemetry_qi; michael@0: int telemetry_bits; michael@0: int telemetry_frame_bytes; michael@0: int telemetry_coding_bytes; michael@0: int telemetry_mode_bytes; michael@0: int telemetry_mv_bytes; michael@0: int telemetry_qi_bytes; michael@0: int telemetry_dc_bytes; michael@0: unsigned char *telemetry_frame_data; michael@0: # endif michael@0: }; michael@0: michael@0: /*Default pure-C implementations of decoder-specific accelerated functions.*/ michael@0: void oc_dec_accel_init_c(oc_dec_ctx *_dec); michael@0: michael@0: void oc_dec_dc_unpredict_mcu_plane_c(oc_dec_ctx *_dec, michael@0: oc_dec_pipeline_state *_pipe,int _pli); michael@0: michael@0: #endif