1 /********************************************************************
3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
9 * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
11 ********************************************************************
16 ********************************************************************/
19 #if !defined(_decint_H)
20 # define _decint_H (1)
21 # include "theora/theoradec.h"
27 typedef struct th_setup_info oc_setup_info
;
28 typedef struct oc_dec_opt_vtable oc_dec_opt_vtable
;
29 typedef struct oc_dec_pipeline_state oc_dec_pipeline_state
;
30 typedef struct th_dec_ctx oc_dec_ctx
;
34 /*Decoder-specific accelerated functions.*/
35 # if defined(OC_C64X_ASM)
36 # include "c64x/c64xdec.h"
39 # if !defined(oc_dec_accel_init)
40 # define oc_dec_accel_init oc_dec_accel_init_c
42 # if defined(OC_DEC_USE_VTABLE)
43 # if !defined(oc_dec_dc_unpredict_mcu_plane)
44 # define oc_dec_dc_unpredict_mcu_plane(_dec,_pipe,_pli) \
45 ((*(_dec)->opt_vtable.dc_unpredict_mcu_plane)(_dec,_pipe,_pli))
48 # if !defined(oc_dec_dc_unpredict_mcu_plane)
49 # define oc_dec_dc_unpredict_mcu_plane oc_dec_dc_unpredict_mcu_plane_c
55 /*Constants for the packet-in state machine specific to the decoder.*/
57 /*Next packet to read: Data packet.*/
58 #define OC_PACKET_DATA (0)
63 /*The Huffman codes.*/
64 ogg_int16_t
*huff_tables
[TH_NHUFFMAN_TABLES
];
65 /*The quantization parameters.*/
71 /*Decoder specific functions with accelerated variants.*/
72 struct oc_dec_opt_vtable
{
73 void (*dc_unpredict_mcu_plane
)(oc_dec_ctx
*_dec
,
74 oc_dec_pipeline_state
*_pipe
,int _pli
);
79 struct oc_dec_pipeline_state
{
80 /*Decoded DCT coefficients.
81 These are placed here instead of on the stack so that they can persist
82 between blocks, which makes clearing them back to zero much faster when
83 only a few non-zero coefficients were decoded.
84 It requires at least 65 elements because the zig-zag index array uses the
85 65th element as a dumping ground for out-of-range indices to protect us
87 We make it fully twice as large so that the second half can serve as the
88 reconstruction buffer, which saves passing another parameter to all the
89 acceleration functios.
90 It also solves problems with 16-byte alignment for NEON on ARM.
91 gcc (as of 4.2.1) only seems to be able to give stack variables 8-byte
92 alignment, and silently produces incorrect results if you ask for 16.
93 Finally, keeping it off the stack means there's less likely to be a data
94 hazard beween the NEON co-processor and the regular ARM core, which avoids
96 OC_ALIGN16(ogg_int16_t dct_coeffs
[128]);
97 OC_ALIGN16(signed char bounding_values
[256]);
100 ptrdiff_t eob_runs
[3][64];
101 const ptrdiff_t *coded_fragis
[3];
102 const ptrdiff_t *uncoded_fragis
[3];
103 ptrdiff_t ncoded_fragis
[3];
104 ptrdiff_t nuncoded_fragis
[3];
105 const ogg_uint16_t
*dequant
[3][3][2];
116 /*Shared encoder/decoder state.*/
117 oc_theora_state state
;
118 /*Whether or not packets are ready to be emitted.
119 This takes on negative values while there are remaining header packets to
120 be emitted, reaches 0 when the codec is ready for input, and goes to 1
121 when a frame has been processed and a data packet is ready.*/
123 /*Buffer in which to assemble packets.*/
125 /*Huffman decode trees.*/
126 ogg_int16_t
*huff_tables
[TH_NHUFFMAN_TABLES
];
127 /*The index of the first token in each plane for each coefficient.*/
128 ptrdiff_t ti0
[3][64];
129 /*The number of outstanding EOB runs at the start of each coefficient in each
131 ptrdiff_t eob_runs
[3][64];
132 /*The DCT token lists.*/
133 unsigned char *dct_tokens
;
134 /*The extra bits associated with DCT tokens.*/
135 unsigned char *extra_bits
;
136 /*The number of dct tokens unpacked so far.*/
137 int dct_tokens_count
;
138 /*The out-of-loop post-processing level.*/
140 /*The DC scale used for out-of-loop deblocking.*/
142 /*The sharpen modifier used for out-of-loop deringing.*/
143 int pp_sharp_mod
[64];
144 /*The DC quantization index of each block.*/
145 unsigned char *dc_qis
;
146 /*The variance of each block.*/
148 /*The storage for the post-processed frame buffer.*/
149 unsigned char *pp_frame_data
;
150 /*Whether or not the post-processsed frame buffer has space for chroma.*/
152 /*The buffer used for the post-processed frame.
153 Note that this is _not_ guaranteed to have the same strides and offsets as
154 the reference frame buffers.*/
155 th_ycbcr_buffer pp_frame_buf
;
156 /*The striped decode callback function.*/
157 th_stripe_callback stripe_cb
;
158 oc_dec_pipeline_state pipe
;
159 # if defined(OC_DEC_USE_VTABLE)
160 /*Table for decoder acceleration functions.*/
161 oc_dec_opt_vtable opt_vtable
;
163 # if defined(HAVE_CAIRO)
164 /*Output metrics for debugging.*/
165 int telemetry_mbmode
;
169 int telemetry_frame_bytes
;
170 int telemetry_coding_bytes
;
171 int telemetry_mode_bytes
;
172 int telemetry_mv_bytes
;
173 int telemetry_qi_bytes
;
174 int telemetry_dc_bytes
;
175 unsigned char *telemetry_frame_data
;
179 /*Default pure-C implementations of decoder-specific accelerated functions.*/
180 void oc_dec_accel_init_c(oc_dec_ctx
*_dec
);
182 void oc_dec_dc_unpredict_mcu_plane_c(oc_dec_ctx
*_dec
,
183 oc_dec_pipeline_state
*_pipe
,int _pli
);