Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /******************************************************************** |
michael@0 | 2 | * * |
michael@0 | 3 | * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 7 | * * |
michael@0 | 8 | * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 * |
michael@0 | 9 | * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * |
michael@0 | 10 | * * |
michael@0 | 11 | ******************************************************************** |
michael@0 | 12 | |
michael@0 | 13 | function: |
michael@0 | 14 | last mod: $Id: decint.h 17457 2010-09-24 02:05:49Z tterribe $ |
michael@0 | 15 | |
michael@0 | 16 | ********************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | #include <limits.h> |
michael@0 | 19 | #if !defined(_decint_H) |
michael@0 | 20 | # define _decint_H (1) |
michael@0 | 21 | # include "theora/theoradec.h" |
michael@0 | 22 | # include "state.h" |
michael@0 | 23 | # include "bitpack.h" |
michael@0 | 24 | # include "huffdec.h" |
michael@0 | 25 | # include "dequant.h" |
michael@0 | 26 | |
michael@0 | 27 | typedef struct th_setup_info oc_setup_info; |
michael@0 | 28 | typedef struct oc_dec_opt_vtable oc_dec_opt_vtable; |
michael@0 | 29 | typedef struct oc_dec_pipeline_state oc_dec_pipeline_state; |
michael@0 | 30 | typedef struct th_dec_ctx oc_dec_ctx; |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | /*Decoder-specific accelerated functions.*/ |
michael@0 | 35 | # if defined(OC_C64X_ASM) |
michael@0 | 36 | # include "c64x/c64xdec.h" |
michael@0 | 37 | # endif |
michael@0 | 38 | |
michael@0 | 39 | # if !defined(oc_dec_accel_init) |
michael@0 | 40 | # define oc_dec_accel_init oc_dec_accel_init_c |
michael@0 | 41 | # endif |
michael@0 | 42 | # if defined(OC_DEC_USE_VTABLE) |
michael@0 | 43 | # if !defined(oc_dec_dc_unpredict_mcu_plane) |
michael@0 | 44 | # define oc_dec_dc_unpredict_mcu_plane(_dec,_pipe,_pli) \ |
michael@0 | 45 | ((*(_dec)->opt_vtable.dc_unpredict_mcu_plane)(_dec,_pipe,_pli)) |
michael@0 | 46 | # endif |
michael@0 | 47 | # else |
michael@0 | 48 | # if !defined(oc_dec_dc_unpredict_mcu_plane) |
michael@0 | 49 | # define oc_dec_dc_unpredict_mcu_plane oc_dec_dc_unpredict_mcu_plane_c |
michael@0 | 50 | # endif |
michael@0 | 51 | # endif |
michael@0 | 52 | |
michael@0 | 53 | |
michael@0 | 54 | |
michael@0 | 55 | /*Constants for the packet-in state machine specific to the decoder.*/ |
michael@0 | 56 | |
michael@0 | 57 | /*Next packet to read: Data packet.*/ |
michael@0 | 58 | #define OC_PACKET_DATA (0) |
michael@0 | 59 | |
michael@0 | 60 | |
michael@0 | 61 | |
michael@0 | 62 | struct th_setup_info{ |
michael@0 | 63 | /*The Huffman codes.*/ |
michael@0 | 64 | ogg_int16_t *huff_tables[TH_NHUFFMAN_TABLES]; |
michael@0 | 65 | /*The quantization parameters.*/ |
michael@0 | 66 | th_quant_info qinfo; |
michael@0 | 67 | }; |
michael@0 | 68 | |
michael@0 | 69 | |
michael@0 | 70 | |
michael@0 | 71 | /*Decoder specific functions with accelerated variants.*/ |
michael@0 | 72 | struct oc_dec_opt_vtable{ |
michael@0 | 73 | void (*dc_unpredict_mcu_plane)(oc_dec_ctx *_dec, |
michael@0 | 74 | oc_dec_pipeline_state *_pipe,int _pli); |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | |
michael@0 | 78 | |
michael@0 | 79 | struct oc_dec_pipeline_state{ |
michael@0 | 80 | /*Decoded DCT coefficients. |
michael@0 | 81 | These are placed here instead of on the stack so that they can persist |
michael@0 | 82 | between blocks, which makes clearing them back to zero much faster when |
michael@0 | 83 | only a few non-zero coefficients were decoded. |
michael@0 | 84 | It requires at least 65 elements because the zig-zag index array uses the |
michael@0 | 85 | 65th element as a dumping ground for out-of-range indices to protect us |
michael@0 | 86 | from buffer overflow. |
michael@0 | 87 | We make it fully twice as large so that the second half can serve as the |
michael@0 | 88 | reconstruction buffer, which saves passing another parameter to all the |
michael@0 | 89 | acceleration functios. |
michael@0 | 90 | It also solves problems with 16-byte alignment for NEON on ARM. |
michael@0 | 91 | gcc (as of 4.2.1) only seems to be able to give stack variables 8-byte |
michael@0 | 92 | alignment, and silently produces incorrect results if you ask for 16. |
michael@0 | 93 | Finally, keeping it off the stack means there's less likely to be a data |
michael@0 | 94 | hazard beween the NEON co-processor and the regular ARM core, which avoids |
michael@0 | 95 | unnecessary stalls.*/ |
michael@0 | 96 | OC_ALIGN16(ogg_int16_t dct_coeffs[128]); |
michael@0 | 97 | OC_ALIGN16(signed char bounding_values[256]); |
michael@0 | 98 | ptrdiff_t ti[3][64]; |
michael@0 | 99 | ptrdiff_t ebi[3][64]; |
michael@0 | 100 | ptrdiff_t eob_runs[3][64]; |
michael@0 | 101 | const ptrdiff_t *coded_fragis[3]; |
michael@0 | 102 | const ptrdiff_t *uncoded_fragis[3]; |
michael@0 | 103 | ptrdiff_t ncoded_fragis[3]; |
michael@0 | 104 | ptrdiff_t nuncoded_fragis[3]; |
michael@0 | 105 | const ogg_uint16_t *dequant[3][3][2]; |
michael@0 | 106 | int fragy0[3]; |
michael@0 | 107 | int fragy_end[3]; |
michael@0 | 108 | int pred_last[3][4]; |
michael@0 | 109 | int mcu_nvfrags; |
michael@0 | 110 | int loop_filter; |
michael@0 | 111 | int pp_level; |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | |
michael@0 | 115 | struct th_dec_ctx{ |
michael@0 | 116 | /*Shared encoder/decoder state.*/ |
michael@0 | 117 | oc_theora_state state; |
michael@0 | 118 | /*Whether or not packets are ready to be emitted. |
michael@0 | 119 | This takes on negative values while there are remaining header packets to |
michael@0 | 120 | be emitted, reaches 0 when the codec is ready for input, and goes to 1 |
michael@0 | 121 | when a frame has been processed and a data packet is ready.*/ |
michael@0 | 122 | int packet_state; |
michael@0 | 123 | /*Buffer in which to assemble packets.*/ |
michael@0 | 124 | oc_pack_buf opb; |
michael@0 | 125 | /*Huffman decode trees.*/ |
michael@0 | 126 | ogg_int16_t *huff_tables[TH_NHUFFMAN_TABLES]; |
michael@0 | 127 | /*The index of the first token in each plane for each coefficient.*/ |
michael@0 | 128 | ptrdiff_t ti0[3][64]; |
michael@0 | 129 | /*The number of outstanding EOB runs at the start of each coefficient in each |
michael@0 | 130 | plane.*/ |
michael@0 | 131 | ptrdiff_t eob_runs[3][64]; |
michael@0 | 132 | /*The DCT token lists.*/ |
michael@0 | 133 | unsigned char *dct_tokens; |
michael@0 | 134 | /*The extra bits associated with DCT tokens.*/ |
michael@0 | 135 | unsigned char *extra_bits; |
michael@0 | 136 | /*The number of dct tokens unpacked so far.*/ |
michael@0 | 137 | int dct_tokens_count; |
michael@0 | 138 | /*The out-of-loop post-processing level.*/ |
michael@0 | 139 | int pp_level; |
michael@0 | 140 | /*The DC scale used for out-of-loop deblocking.*/ |
michael@0 | 141 | int pp_dc_scale[64]; |
michael@0 | 142 | /*The sharpen modifier used for out-of-loop deringing.*/ |
michael@0 | 143 | int pp_sharp_mod[64]; |
michael@0 | 144 | /*The DC quantization index of each block.*/ |
michael@0 | 145 | unsigned char *dc_qis; |
michael@0 | 146 | /*The variance of each block.*/ |
michael@0 | 147 | int *variances; |
michael@0 | 148 | /*The storage for the post-processed frame buffer.*/ |
michael@0 | 149 | unsigned char *pp_frame_data; |
michael@0 | 150 | /*Whether or not the post-processsed frame buffer has space for chroma.*/ |
michael@0 | 151 | int pp_frame_state; |
michael@0 | 152 | /*The buffer used for the post-processed frame. |
michael@0 | 153 | Note that this is _not_ guaranteed to have the same strides and offsets as |
michael@0 | 154 | the reference frame buffers.*/ |
michael@0 | 155 | th_ycbcr_buffer pp_frame_buf; |
michael@0 | 156 | /*The striped decode callback function.*/ |
michael@0 | 157 | th_stripe_callback stripe_cb; |
michael@0 | 158 | oc_dec_pipeline_state pipe; |
michael@0 | 159 | # if defined(OC_DEC_USE_VTABLE) |
michael@0 | 160 | /*Table for decoder acceleration functions.*/ |
michael@0 | 161 | oc_dec_opt_vtable opt_vtable; |
michael@0 | 162 | # endif |
michael@0 | 163 | # if defined(HAVE_CAIRO) |
michael@0 | 164 | /*Output metrics for debugging.*/ |
michael@0 | 165 | int telemetry; |
michael@0 | 166 | int telemetry_mbmode; |
michael@0 | 167 | int telemetry_mv; |
michael@0 | 168 | int telemetry_qi; |
michael@0 | 169 | int telemetry_bits; |
michael@0 | 170 | int telemetry_frame_bytes; |
michael@0 | 171 | int telemetry_coding_bytes; |
michael@0 | 172 | int telemetry_mode_bytes; |
michael@0 | 173 | int telemetry_mv_bytes; |
michael@0 | 174 | int telemetry_qi_bytes; |
michael@0 | 175 | int telemetry_dc_bytes; |
michael@0 | 176 | unsigned char *telemetry_frame_data; |
michael@0 | 177 | # endif |
michael@0 | 178 | }; |
michael@0 | 179 | |
michael@0 | 180 | /*Default pure-C implementations of decoder-specific accelerated functions.*/ |
michael@0 | 181 | void oc_dec_accel_init_c(oc_dec_ctx *_dec); |
michael@0 | 182 | |
michael@0 | 183 | void oc_dec_dc_unpredict_mcu_plane_c(oc_dec_ctx *_dec, |
michael@0 | 184 | oc_dec_pipeline_state *_pipe,int _pli); |
michael@0 | 185 | |
michael@0 | 186 | #endif |