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: internal.h 17337 2010-07-19 16:08:54Z tterribe $ |
michael@0 | 15 | |
michael@0 | 16 | ********************************************************************/ |
michael@0 | 17 | #if !defined(_state_H) |
michael@0 | 18 | # define _state_H (1) |
michael@0 | 19 | # include "internal.h" |
michael@0 | 20 | # include "huffman.h" |
michael@0 | 21 | # include "quant.h" |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | |
michael@0 | 25 | /*A single quadrant of the map from a super block to fragment numbers.*/ |
michael@0 | 26 | typedef ptrdiff_t oc_sb_map_quad[4]; |
michael@0 | 27 | /*A map from a super block to fragment numbers.*/ |
michael@0 | 28 | typedef oc_sb_map_quad oc_sb_map[4]; |
michael@0 | 29 | /*A single plane of the map from a macro block to fragment numbers.*/ |
michael@0 | 30 | typedef ptrdiff_t oc_mb_map_plane[4]; |
michael@0 | 31 | /*A map from a macro block to fragment numbers.*/ |
michael@0 | 32 | typedef oc_mb_map_plane oc_mb_map[3]; |
michael@0 | 33 | /*A motion vector.*/ |
michael@0 | 34 | typedef ogg_int16_t oc_mv; |
michael@0 | 35 | |
michael@0 | 36 | typedef struct oc_sb_flags oc_sb_flags; |
michael@0 | 37 | typedef struct oc_border_info oc_border_info; |
michael@0 | 38 | typedef struct oc_fragment oc_fragment; |
michael@0 | 39 | typedef struct oc_fragment_plane oc_fragment_plane; |
michael@0 | 40 | typedef struct oc_base_opt_vtable oc_base_opt_vtable; |
michael@0 | 41 | typedef struct oc_base_opt_data oc_base_opt_data; |
michael@0 | 42 | typedef struct oc_state_dispatch_vtable oc_state_dispatch_vtable; |
michael@0 | 43 | typedef struct oc_theora_state oc_theora_state; |
michael@0 | 44 | |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | /*Shared accelerated functions.*/ |
michael@0 | 48 | # if defined(OC_X86_ASM) |
michael@0 | 49 | # if defined(_MSC_VER) |
michael@0 | 50 | # include "x86_vc/x86int.h" |
michael@0 | 51 | # else |
michael@0 | 52 | # include "x86/x86int.h" |
michael@0 | 53 | # endif |
michael@0 | 54 | # endif |
michael@0 | 55 | # if defined(OC_ARM_ASM) |
michael@0 | 56 | # include "arm/armint.h" |
michael@0 | 57 | # endif |
michael@0 | 58 | # if defined(OC_C64X_ASM) |
michael@0 | 59 | # include "c64x/c64xint.h" |
michael@0 | 60 | # endif |
michael@0 | 61 | |
michael@0 | 62 | # if !defined(oc_state_accel_init) |
michael@0 | 63 | # define oc_state_accel_init oc_state_accel_init_c |
michael@0 | 64 | # endif |
michael@0 | 65 | # if defined(OC_STATE_USE_VTABLE) |
michael@0 | 66 | # if !defined(oc_frag_copy) |
michael@0 | 67 | # define oc_frag_copy(_state,_dst,_src,_ystride) \ |
michael@0 | 68 | ((*(_state)->opt_vtable.frag_copy)(_dst,_src,_ystride)) |
michael@0 | 69 | # endif |
michael@0 | 70 | # if !defined(oc_frag_copy_list) |
michael@0 | 71 | # define oc_frag_copy_list(_state,_dst_frame,_src_frame,_ystride, \ |
michael@0 | 72 | _fragis,_nfragis,_frag_buf_offs) \ |
michael@0 | 73 | ((*(_state)->opt_vtable.frag_copy_list)(_dst_frame,_src_frame,_ystride, \ |
michael@0 | 74 | _fragis,_nfragis,_frag_buf_offs)) |
michael@0 | 75 | # endif |
michael@0 | 76 | # if !defined(oc_frag_recon_intra) |
michael@0 | 77 | # define oc_frag_recon_intra(_state,_dst,_dst_ystride,_residue) \ |
michael@0 | 78 | ((*(_state)->opt_vtable.frag_recon_intra)(_dst,_dst_ystride,_residue)) |
michael@0 | 79 | # endif |
michael@0 | 80 | # if !defined(oc_frag_recon_inter) |
michael@0 | 81 | # define oc_frag_recon_inter(_state,_dst,_src,_ystride,_residue) \ |
michael@0 | 82 | ((*(_state)->opt_vtable.frag_recon_inter)(_dst,_src,_ystride,_residue)) |
michael@0 | 83 | # endif |
michael@0 | 84 | # if !defined(oc_frag_recon_inter2) |
michael@0 | 85 | # define oc_frag_recon_inter2(_state,_dst,_src1,_src2,_ystride,_residue) \ |
michael@0 | 86 | ((*(_state)->opt_vtable.frag_recon_inter2)(_dst, \ |
michael@0 | 87 | _src1,_src2,_ystride,_residue)) |
michael@0 | 88 | # endif |
michael@0 | 89 | # if !defined(oc_idct8x8) |
michael@0 | 90 | # define oc_idct8x8(_state,_y,_x,_last_zzi) \ |
michael@0 | 91 | ((*(_state)->opt_vtable.idct8x8)(_y,_x,_last_zzi)) |
michael@0 | 92 | # endif |
michael@0 | 93 | # if !defined(oc_state_frag_recon) |
michael@0 | 94 | # define oc_state_frag_recon(_state,_fragi, \ |
michael@0 | 95 | _pli,_dct_coeffs,_last_zzi,_dc_quant) \ |
michael@0 | 96 | ((*(_state)->opt_vtable.state_frag_recon)(_state,_fragi, \ |
michael@0 | 97 | _pli,_dct_coeffs,_last_zzi,_dc_quant)) |
michael@0 | 98 | # endif |
michael@0 | 99 | # if !defined(oc_loop_filter_init) |
michael@0 | 100 | # define oc_loop_filter_init(_state,_bv,_flimit) \ |
michael@0 | 101 | ((*(_state)->opt_vtable.loop_filter_init)(_bv,_flimit)) |
michael@0 | 102 | # endif |
michael@0 | 103 | # if !defined(oc_state_loop_filter_frag_rows) |
michael@0 | 104 | # define oc_state_loop_filter_frag_rows(_state, \ |
michael@0 | 105 | _bv,_refi,_pli,_fragy0,_fragy_end) \ |
michael@0 | 106 | ((*(_state)->opt_vtable.state_loop_filter_frag_rows)(_state, \ |
michael@0 | 107 | _bv,_refi,_pli,_fragy0,_fragy_end)) |
michael@0 | 108 | # endif |
michael@0 | 109 | # if !defined(oc_restore_fpu) |
michael@0 | 110 | # define oc_restore_fpu(_state) \ |
michael@0 | 111 | ((*(_state)->opt_vtable.restore_fpu)()) |
michael@0 | 112 | # endif |
michael@0 | 113 | # else |
michael@0 | 114 | # if !defined(oc_frag_copy) |
michael@0 | 115 | # define oc_frag_copy(_state,_dst,_src,_ystride) \ |
michael@0 | 116 | oc_frag_copy_c(_dst,_src,_ystride) |
michael@0 | 117 | # endif |
michael@0 | 118 | # if !defined(oc_frag_copy_list) |
michael@0 | 119 | # define oc_frag_copy_list(_state,_dst_frame,_src_frame,_ystride, \ |
michael@0 | 120 | _fragis,_nfragis,_frag_buf_offs) \ |
michael@0 | 121 | oc_frag_copy_list_c(_dst_frame,_src_frame,_ystride, \ |
michael@0 | 122 | _fragis,_nfragis,_frag_buf_offs) |
michael@0 | 123 | # endif |
michael@0 | 124 | # if !defined(oc_frag_recon_intra) |
michael@0 | 125 | # define oc_frag_recon_intra(_state,_dst,_dst_ystride,_residue) \ |
michael@0 | 126 | oc_frag_recon_intra_c(_dst,_dst_ystride,_residue) |
michael@0 | 127 | # endif |
michael@0 | 128 | # if !defined(oc_frag_recon_inter) |
michael@0 | 129 | # define oc_frag_recon_inter(_state,_dst,_src,_ystride,_residue) \ |
michael@0 | 130 | oc_frag_recon_inter_c(_dst,_src,_ystride,_residue) |
michael@0 | 131 | # endif |
michael@0 | 132 | # if !defined(oc_frag_recon_inter2) |
michael@0 | 133 | # define oc_frag_recon_inter2(_state,_dst,_src1,_src2,_ystride,_residue) \ |
michael@0 | 134 | oc_frag_recon_inter2_c(_dst,_src1,_src2,_ystride,_residue) |
michael@0 | 135 | # endif |
michael@0 | 136 | # if !defined(oc_idct8x8) |
michael@0 | 137 | # define oc_idct8x8(_state,_y,_x,_last_zzi) oc_idct8x8_c(_y,_x,_last_zzi) |
michael@0 | 138 | # endif |
michael@0 | 139 | # if !defined(oc_state_frag_recon) |
michael@0 | 140 | # define oc_state_frag_recon oc_state_frag_recon_c |
michael@0 | 141 | # endif |
michael@0 | 142 | # if !defined(oc_loop_filter_init) |
michael@0 | 143 | # define oc_loop_filter_init(_state,_bv,_flimit) \ |
michael@0 | 144 | oc_loop_filter_init_c(_bv,_flimit) |
michael@0 | 145 | # endif |
michael@0 | 146 | # if !defined(oc_state_loop_filter_frag_rows) |
michael@0 | 147 | # define oc_state_loop_filter_frag_rows oc_state_loop_filter_frag_rows_c |
michael@0 | 148 | # endif |
michael@0 | 149 | # if !defined(oc_restore_fpu) |
michael@0 | 150 | # define oc_restore_fpu(_state) do{}while(0) |
michael@0 | 151 | # endif |
michael@0 | 152 | # endif |
michael@0 | 153 | |
michael@0 | 154 | |
michael@0 | 155 | |
michael@0 | 156 | /*A keyframe.*/ |
michael@0 | 157 | # define OC_INTRA_FRAME (0) |
michael@0 | 158 | /*A predicted frame.*/ |
michael@0 | 159 | # define OC_INTER_FRAME (1) |
michael@0 | 160 | /*A frame of unknown type (frame type decision has not yet been made).*/ |
michael@0 | 161 | # define OC_UNKWN_FRAME (-1) |
michael@0 | 162 | |
michael@0 | 163 | /*The amount of padding to add to the reconstructed frame buffers on all |
michael@0 | 164 | sides. |
michael@0 | 165 | This is used to allow unrestricted motion vectors without special casing. |
michael@0 | 166 | This must be a multiple of 2.*/ |
michael@0 | 167 | # define OC_UMV_PADDING (16) |
michael@0 | 168 | |
michael@0 | 169 | /*Frame classification indices.*/ |
michael@0 | 170 | /*The previous golden frame.*/ |
michael@0 | 171 | # define OC_FRAME_GOLD (0) |
michael@0 | 172 | /*The previous frame.*/ |
michael@0 | 173 | # define OC_FRAME_PREV (1) |
michael@0 | 174 | /*The current frame.*/ |
michael@0 | 175 | # define OC_FRAME_SELF (2) |
michael@0 | 176 | /*Used to mark uncoded fragments (for DC prediction).*/ |
michael@0 | 177 | # define OC_FRAME_NONE (3) |
michael@0 | 178 | |
michael@0 | 179 | /*The input or output buffer.*/ |
michael@0 | 180 | # define OC_FRAME_IO (3) |
michael@0 | 181 | /*Uncompressed prev golden frame.*/ |
michael@0 | 182 | # define OC_FRAME_GOLD_ORIG (4) |
michael@0 | 183 | /*Uncompressed previous frame. */ |
michael@0 | 184 | # define OC_FRAME_PREV_ORIG (5) |
michael@0 | 185 | |
michael@0 | 186 | /*Macroblock modes.*/ |
michael@0 | 187 | /*Macro block is invalid: It is never coded.*/ |
michael@0 | 188 | # define OC_MODE_INVALID (-1) |
michael@0 | 189 | /*Encoded difference from the same macro block in the previous frame.*/ |
michael@0 | 190 | # define OC_MODE_INTER_NOMV (0) |
michael@0 | 191 | /*Encoded with no motion compensated prediction.*/ |
michael@0 | 192 | # define OC_MODE_INTRA (1) |
michael@0 | 193 | /*Encoded difference from the previous frame offset by the given motion |
michael@0 | 194 | vector.*/ |
michael@0 | 195 | # define OC_MODE_INTER_MV (2) |
michael@0 | 196 | /*Encoded difference from the previous frame offset by the last coded motion |
michael@0 | 197 | vector.*/ |
michael@0 | 198 | # define OC_MODE_INTER_MV_LAST (3) |
michael@0 | 199 | /*Encoded difference from the previous frame offset by the second to last |
michael@0 | 200 | coded motion vector.*/ |
michael@0 | 201 | # define OC_MODE_INTER_MV_LAST2 (4) |
michael@0 | 202 | /*Encoded difference from the same macro block in the previous golden |
michael@0 | 203 | frame.*/ |
michael@0 | 204 | # define OC_MODE_GOLDEN_NOMV (5) |
michael@0 | 205 | /*Encoded difference from the previous golden frame offset by the given motion |
michael@0 | 206 | vector.*/ |
michael@0 | 207 | # define OC_MODE_GOLDEN_MV (6) |
michael@0 | 208 | /*Encoded difference from the previous frame offset by the individual motion |
michael@0 | 209 | vectors given for each block.*/ |
michael@0 | 210 | # define OC_MODE_INTER_MV_FOUR (7) |
michael@0 | 211 | /*The number of (coded) modes.*/ |
michael@0 | 212 | # define OC_NMODES (8) |
michael@0 | 213 | |
michael@0 | 214 | /*Determines the reference frame used for a given MB mode.*/ |
michael@0 | 215 | # define OC_FRAME_FOR_MODE(_x) \ |
michael@0 | 216 | OC_UNIBBLE_TABLE32(OC_FRAME_PREV,OC_FRAME_SELF,OC_FRAME_PREV,OC_FRAME_PREV, \ |
michael@0 | 217 | OC_FRAME_PREV,OC_FRAME_GOLD,OC_FRAME_GOLD,OC_FRAME_PREV,(_x)) |
michael@0 | 218 | |
michael@0 | 219 | /*Constants for the packet state machine common between encoder and decoder.*/ |
michael@0 | 220 | |
michael@0 | 221 | /*Next packet to emit/read: Codec info header.*/ |
michael@0 | 222 | # define OC_PACKET_INFO_HDR (-3) |
michael@0 | 223 | /*Next packet to emit/read: Comment header.*/ |
michael@0 | 224 | # define OC_PACKET_COMMENT_HDR (-2) |
michael@0 | 225 | /*Next packet to emit/read: Codec setup header.*/ |
michael@0 | 226 | # define OC_PACKET_SETUP_HDR (-1) |
michael@0 | 227 | /*No more packets to emit/read.*/ |
michael@0 | 228 | # define OC_PACKET_DONE (INT_MAX) |
michael@0 | 229 | |
michael@0 | 230 | |
michael@0 | 231 | |
michael@0 | 232 | #define OC_MV(_x,_y) ((oc_mv)((_x)&0xFF|(_y)<<8)) |
michael@0 | 233 | #define OC_MV_X(_mv) ((signed char)(_mv)) |
michael@0 | 234 | #define OC_MV_Y(_mv) ((_mv)>>8) |
michael@0 | 235 | #define OC_MV_ADD(_mv1,_mv2) \ |
michael@0 | 236 | OC_MV(OC_MV_X(_mv1)+OC_MV_X(_mv2), \ |
michael@0 | 237 | OC_MV_Y(_mv1)+OC_MV_Y(_mv2)) |
michael@0 | 238 | #define OC_MV_SUB(_mv1,_mv2) \ |
michael@0 | 239 | OC_MV(OC_MV_X(_mv1)-OC_MV_X(_mv2), \ |
michael@0 | 240 | OC_MV_Y(_mv1)-OC_MV_Y(_mv2)) |
michael@0 | 241 | |
michael@0 | 242 | |
michael@0 | 243 | |
michael@0 | 244 | /*Super blocks are 32x32 segments of pixels in a single color plane indexed |
michael@0 | 245 | in image order. |
michael@0 | 246 | Internally, super blocks are broken up into four quadrants, each of which |
michael@0 | 247 | contains a 2x2 pattern of blocks, each of which is an 8x8 block of pixels. |
michael@0 | 248 | Quadrants, and the blocks within them, are indexed in a special order called |
michael@0 | 249 | a "Hilbert curve" within the super block. |
michael@0 | 250 | |
michael@0 | 251 | In order to differentiate between the Hilbert-curve indexing strategy and |
michael@0 | 252 | the regular image order indexing strategy, blocks indexed in image order |
michael@0 | 253 | are called "fragments". |
michael@0 | 254 | Fragments are indexed in image order, left to right, then bottom to top, |
michael@0 | 255 | from Y' plane to Cb plane to Cr plane. |
michael@0 | 256 | |
michael@0 | 257 | The co-located fragments in all image planes corresponding to the location |
michael@0 | 258 | of a single quadrant of a luma plane super block form a macro block. |
michael@0 | 259 | Thus there is only a single set of macro blocks for all planes, each of which |
michael@0 | 260 | contains between 6 and 12 fragments, depending on the pixel format. |
michael@0 | 261 | Therefore macro block information is kept in a separate set of arrays from |
michael@0 | 262 | super blocks to avoid unused space in the other planes. |
michael@0 | 263 | The lists are indexed in super block order. |
michael@0 | 264 | That is, the macro block corresponding to the macro block mbi in (luma plane) |
michael@0 | 265 | super block sbi is at index (sbi<<2|mbi). |
michael@0 | 266 | Thus the number of macro blocks in each dimension is always twice the number |
michael@0 | 267 | of super blocks, even when only an odd number fall inside the coded frame. |
michael@0 | 268 | These "extra" macro blocks are just an artifact of our internal data layout, |
michael@0 | 269 | and not part of the coded stream; they are flagged with a negative MB mode.*/ |
michael@0 | 270 | |
michael@0 | 271 | |
michael@0 | 272 | |
michael@0 | 273 | /*Super block information.*/ |
michael@0 | 274 | struct oc_sb_flags{ |
michael@0 | 275 | unsigned char coded_fully:1; |
michael@0 | 276 | unsigned char coded_partially:1; |
michael@0 | 277 | unsigned char quad_valid:4; |
michael@0 | 278 | }; |
michael@0 | 279 | |
michael@0 | 280 | |
michael@0 | 281 | |
michael@0 | 282 | /*Information about a fragment which intersects the border of the displayable |
michael@0 | 283 | region. |
michael@0 | 284 | This marks which pixels belong to the displayable region.*/ |
michael@0 | 285 | struct oc_border_info{ |
michael@0 | 286 | /*A bit mask marking which pixels are in the displayable region. |
michael@0 | 287 | Pixel (x,y) corresponds to bit (y<<3|x).*/ |
michael@0 | 288 | ogg_int64_t mask; |
michael@0 | 289 | /*The number of pixels in the displayable region. |
michael@0 | 290 | This is always positive, and always less than 64.*/ |
michael@0 | 291 | int npixels; |
michael@0 | 292 | }; |
michael@0 | 293 | |
michael@0 | 294 | |
michael@0 | 295 | |
michael@0 | 296 | /*Fragment information.*/ |
michael@0 | 297 | struct oc_fragment{ |
michael@0 | 298 | /*A flag indicating whether or not this fragment is coded.*/ |
michael@0 | 299 | unsigned coded:1; |
michael@0 | 300 | /*A flag indicating that this entire fragment lies outside the displayable |
michael@0 | 301 | region of the frame. |
michael@0 | 302 | Note the contrast with an invalid macro block, which is outside the coded |
michael@0 | 303 | frame, not just the displayable one. |
michael@0 | 304 | There are no fragments outside the coded frame by construction.*/ |
michael@0 | 305 | unsigned invalid:1; |
michael@0 | 306 | /*The index of the quality index used for this fragment's AC coefficients.*/ |
michael@0 | 307 | unsigned qii:4; |
michael@0 | 308 | /*The index of the reference frame this fragment is predicted from.*/ |
michael@0 | 309 | unsigned refi:2; |
michael@0 | 310 | /*The mode of the macroblock this fragment belongs to.*/ |
michael@0 | 311 | unsigned mb_mode:3; |
michael@0 | 312 | /*The index of the associated border information for fragments which lie |
michael@0 | 313 | partially outside the displayable region. |
michael@0 | 314 | For fragments completely inside or outside this region, this is -1. |
michael@0 | 315 | Note that the C standard requires an explicit signed keyword for bitfield |
michael@0 | 316 | types, since some compilers may treat them as unsigned without it.*/ |
michael@0 | 317 | signed int borderi:5; |
michael@0 | 318 | /*The prediction-corrected DC component. |
michael@0 | 319 | Note that the C standard requires an explicit signed keyword for bitfield |
michael@0 | 320 | types, since some compilers may treat them as unsigned without it.*/ |
michael@0 | 321 | signed int dc:16; |
michael@0 | 322 | }; |
michael@0 | 323 | |
michael@0 | 324 | |
michael@0 | 325 | |
michael@0 | 326 | /*A description of each fragment plane.*/ |
michael@0 | 327 | struct oc_fragment_plane{ |
michael@0 | 328 | /*The number of fragments in the horizontal direction.*/ |
michael@0 | 329 | int nhfrags; |
michael@0 | 330 | /*The number of fragments in the vertical direction.*/ |
michael@0 | 331 | int nvfrags; |
michael@0 | 332 | /*The offset of the first fragment in the plane.*/ |
michael@0 | 333 | ptrdiff_t froffset; |
michael@0 | 334 | /*The total number of fragments in the plane.*/ |
michael@0 | 335 | ptrdiff_t nfrags; |
michael@0 | 336 | /*The number of super blocks in the horizontal direction.*/ |
michael@0 | 337 | unsigned nhsbs; |
michael@0 | 338 | /*The number of super blocks in the vertical direction.*/ |
michael@0 | 339 | unsigned nvsbs; |
michael@0 | 340 | /*The offset of the first super block in the plane.*/ |
michael@0 | 341 | unsigned sboffset; |
michael@0 | 342 | /*The total number of super blocks in the plane.*/ |
michael@0 | 343 | unsigned nsbs; |
michael@0 | 344 | }; |
michael@0 | 345 | |
michael@0 | 346 | |
michael@0 | 347 | typedef void (*oc_state_loop_filter_frag_rows_func)( |
michael@0 | 348 | const oc_theora_state *_state,signed char _bv[256],int _refi,int _pli, |
michael@0 | 349 | int _fragy0,int _fragy_end); |
michael@0 | 350 | |
michael@0 | 351 | /*The shared (encoder and decoder) functions that have accelerated variants.*/ |
michael@0 | 352 | struct oc_base_opt_vtable{ |
michael@0 | 353 | void (*frag_copy)(unsigned char *_dst, |
michael@0 | 354 | const unsigned char *_src,int _ystride); |
michael@0 | 355 | void (*frag_copy_list)(unsigned char *_dst_frame, |
michael@0 | 356 | const unsigned char *_src_frame,int _ystride, |
michael@0 | 357 | const ptrdiff_t *_fragis,ptrdiff_t _nfragis,const ptrdiff_t *_frag_buf_offs); |
michael@0 | 358 | void (*frag_recon_intra)(unsigned char *_dst,int _ystride, |
michael@0 | 359 | const ogg_int16_t _residue[64]); |
michael@0 | 360 | void (*frag_recon_inter)(unsigned char *_dst, |
michael@0 | 361 | const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]); |
michael@0 | 362 | void (*frag_recon_inter2)(unsigned char *_dst,const unsigned char *_src1, |
michael@0 | 363 | const unsigned char *_src2,int _ystride,const ogg_int16_t _residue[64]); |
michael@0 | 364 | void (*idct8x8)(ogg_int16_t _y[64],ogg_int16_t _x[64],int _last_zzi); |
michael@0 | 365 | void (*state_frag_recon)(const oc_theora_state *_state,ptrdiff_t _fragi, |
michael@0 | 366 | int _pli,ogg_int16_t _dct_coeffs[128],int _last_zzi,ogg_uint16_t _dc_quant); |
michael@0 | 367 | void (*loop_filter_init)(signed char _bv[256],int _flimit); |
michael@0 | 368 | oc_state_loop_filter_frag_rows_func state_loop_filter_frag_rows; |
michael@0 | 369 | void (*restore_fpu)(void); |
michael@0 | 370 | }; |
michael@0 | 371 | |
michael@0 | 372 | /*The shared (encoder and decoder) tables that vary according to which variants |
michael@0 | 373 | of the above functions are used.*/ |
michael@0 | 374 | struct oc_base_opt_data{ |
michael@0 | 375 | const unsigned char *dct_fzig_zag; |
michael@0 | 376 | }; |
michael@0 | 377 | |
michael@0 | 378 | |
michael@0 | 379 | /*State information common to both the encoder and decoder.*/ |
michael@0 | 380 | struct oc_theora_state{ |
michael@0 | 381 | /*The stream information.*/ |
michael@0 | 382 | th_info info; |
michael@0 | 383 | # if defined(OC_STATE_USE_VTABLE) |
michael@0 | 384 | /*Table for shared accelerated functions.*/ |
michael@0 | 385 | oc_base_opt_vtable opt_vtable; |
michael@0 | 386 | # endif |
michael@0 | 387 | /*Table for shared data used by accelerated functions.*/ |
michael@0 | 388 | oc_base_opt_data opt_data; |
michael@0 | 389 | /*CPU flags to detect the presence of extended instruction sets.*/ |
michael@0 | 390 | ogg_uint32_t cpu_flags; |
michael@0 | 391 | /*The fragment plane descriptions.*/ |
michael@0 | 392 | oc_fragment_plane fplanes[3]; |
michael@0 | 393 | /*The list of fragments, indexed in image order.*/ |
michael@0 | 394 | oc_fragment *frags; |
michael@0 | 395 | /*The the offset into the reference frame buffer to the upper-left pixel of |
michael@0 | 396 | each fragment.*/ |
michael@0 | 397 | ptrdiff_t *frag_buf_offs; |
michael@0 | 398 | /*The motion vector for each fragment.*/ |
michael@0 | 399 | oc_mv *frag_mvs; |
michael@0 | 400 | /*The total number of fragments in a single frame.*/ |
michael@0 | 401 | ptrdiff_t nfrags; |
michael@0 | 402 | /*The list of super block maps, indexed in image order.*/ |
michael@0 | 403 | oc_sb_map *sb_maps; |
michael@0 | 404 | /*The list of super block flags, indexed in image order.*/ |
michael@0 | 405 | oc_sb_flags *sb_flags; |
michael@0 | 406 | /*The total number of super blocks in a single frame.*/ |
michael@0 | 407 | unsigned nsbs; |
michael@0 | 408 | /*The fragments from each color plane that belong to each macro block. |
michael@0 | 409 | Fragments are stored in image order (left to right then top to bottom). |
michael@0 | 410 | When chroma components are decimated, the extra fragments have an index of |
michael@0 | 411 | -1.*/ |
michael@0 | 412 | oc_mb_map *mb_maps; |
michael@0 | 413 | /*The list of macro block modes. |
michael@0 | 414 | A negative number indicates the macro block lies entirely outside the |
michael@0 | 415 | coded frame.*/ |
michael@0 | 416 | signed char *mb_modes; |
michael@0 | 417 | /*The number of macro blocks in the X direction.*/ |
michael@0 | 418 | unsigned nhmbs; |
michael@0 | 419 | /*The number of macro blocks in the Y direction.*/ |
michael@0 | 420 | unsigned nvmbs; |
michael@0 | 421 | /*The total number of macro blocks.*/ |
michael@0 | 422 | size_t nmbs; |
michael@0 | 423 | /*The list of coded fragments, in coded order. |
michael@0 | 424 | Uncoded fragments are stored in reverse order from the end of the list.*/ |
michael@0 | 425 | ptrdiff_t *coded_fragis; |
michael@0 | 426 | /*The number of coded fragments in each plane.*/ |
michael@0 | 427 | ptrdiff_t ncoded_fragis[3]; |
michael@0 | 428 | /*The total number of coded fragments.*/ |
michael@0 | 429 | ptrdiff_t ntotal_coded_fragis; |
michael@0 | 430 | /*The actual buffers used for the reference frames.*/ |
michael@0 | 431 | th_ycbcr_buffer ref_frame_bufs[6]; |
michael@0 | 432 | /*The index of the buffers being used for each OC_FRAME_* reference frame.*/ |
michael@0 | 433 | int ref_frame_idx[6]; |
michael@0 | 434 | /*The storage for the reference frame buffers. |
michael@0 | 435 | This is just ref_frame_bufs[ref_frame_idx[i]][0].data, but is cached here |
michael@0 | 436 | for faster look-up.*/ |
michael@0 | 437 | unsigned char *ref_frame_data[6]; |
michael@0 | 438 | /*The handle used to allocate the reference frame buffers.*/ |
michael@0 | 439 | unsigned char *ref_frame_handle; |
michael@0 | 440 | /*The strides for each plane in the reference frames.*/ |
michael@0 | 441 | int ref_ystride[3]; |
michael@0 | 442 | /*The number of unique border patterns.*/ |
michael@0 | 443 | int nborders; |
michael@0 | 444 | /*The unique border patterns for all border fragments. |
michael@0 | 445 | The borderi field of fragments which straddle the border indexes this |
michael@0 | 446 | list.*/ |
michael@0 | 447 | oc_border_info borders[16]; |
michael@0 | 448 | /*The frame number of the last keyframe.*/ |
michael@0 | 449 | ogg_int64_t keyframe_num; |
michael@0 | 450 | /*The frame number of the current frame.*/ |
michael@0 | 451 | ogg_int64_t curframe_num; |
michael@0 | 452 | /*The granpos of the current frame.*/ |
michael@0 | 453 | ogg_int64_t granpos; |
michael@0 | 454 | /*The type of the current frame.*/ |
michael@0 | 455 | signed char frame_type; |
michael@0 | 456 | /*The bias to add to the frame count when computing granule positions.*/ |
michael@0 | 457 | unsigned char granpos_bias; |
michael@0 | 458 | /*The number of quality indices used in the current frame.*/ |
michael@0 | 459 | unsigned char nqis; |
michael@0 | 460 | /*The quality indices of the current frame.*/ |
michael@0 | 461 | unsigned char qis[3]; |
michael@0 | 462 | /*The dequantization tables, stored in zig-zag order, and indexed by |
michael@0 | 463 | qi, pli, qti, and zzi.*/ |
michael@0 | 464 | ogg_uint16_t *dequant_tables[64][3][2]; |
michael@0 | 465 | OC_ALIGN16(oc_quant_table dequant_table_data[64][3][2]); |
michael@0 | 466 | /*Loop filter strength parameters.*/ |
michael@0 | 467 | unsigned char loop_filter_limits[64]; |
michael@0 | 468 | }; |
michael@0 | 469 | |
michael@0 | 470 | |
michael@0 | 471 | |
michael@0 | 472 | /*The function type used to fill in the chroma plane motion vectors for a |
michael@0 | 473 | macro block when 4 different motion vectors are specified in the luma |
michael@0 | 474 | plane. |
michael@0 | 475 | _cbmvs: The chroma block-level motion vectors to fill in. |
michael@0 | 476 | _lmbmv: The luma macro-block level motion vector to fill in for use in |
michael@0 | 477 | prediction. |
michael@0 | 478 | _lbmvs: The luma block-level motion vectors.*/ |
michael@0 | 479 | typedef void (*oc_set_chroma_mvs_func)(oc_mv _cbmvs[4],const oc_mv _lbmvs[4]); |
michael@0 | 480 | |
michael@0 | 481 | |
michael@0 | 482 | |
michael@0 | 483 | /*A table of functions used to fill in the Cb,Cr plane motion vectors for a |
michael@0 | 484 | macro block when 4 different motion vectors are specified in the luma |
michael@0 | 485 | plane.*/ |
michael@0 | 486 | extern const oc_set_chroma_mvs_func OC_SET_CHROMA_MVS_TABLE[TH_PF_NFORMATS]; |
michael@0 | 487 | |
michael@0 | 488 | |
michael@0 | 489 | |
michael@0 | 490 | int oc_state_init(oc_theora_state *_state,const th_info *_info,int _nrefs); |
michael@0 | 491 | void oc_state_clear(oc_theora_state *_state); |
michael@0 | 492 | void oc_state_accel_init_c(oc_theora_state *_state); |
michael@0 | 493 | void oc_state_borders_fill_rows(oc_theora_state *_state,int _refi,int _pli, |
michael@0 | 494 | int _y0,int _yend); |
michael@0 | 495 | void oc_state_borders_fill_caps(oc_theora_state *_state,int _refi,int _pli); |
michael@0 | 496 | void oc_state_borders_fill(oc_theora_state *_state,int _refi); |
michael@0 | 497 | void oc_state_fill_buffer_ptrs(oc_theora_state *_state,int _buf_idx, |
michael@0 | 498 | th_ycbcr_buffer _img); |
michael@0 | 499 | int oc_state_mbi_for_pos(oc_theora_state *_state,int _mbx,int _mby); |
michael@0 | 500 | int oc_state_get_mv_offsets(const oc_theora_state *_state,int _offsets[2], |
michael@0 | 501 | int _pli,oc_mv _mv); |
michael@0 | 502 | |
michael@0 | 503 | void oc_loop_filter_init_c(signed char _bv[256],int _flimit); |
michael@0 | 504 | void oc_state_loop_filter(oc_theora_state *_state,int _frame); |
michael@0 | 505 | # if defined(OC_DUMP_IMAGES) |
michael@0 | 506 | int oc_state_dump_frame(const oc_theora_state *_state,int _frame, |
michael@0 | 507 | const char *_suf); |
michael@0 | 508 | # endif |
michael@0 | 509 | |
michael@0 | 510 | /*Default pure-C implementations of shared accelerated functions.*/ |
michael@0 | 511 | void oc_frag_copy_c(unsigned char *_dst, |
michael@0 | 512 | const unsigned char *_src,int _src_ystride); |
michael@0 | 513 | void oc_frag_copy_list_c(unsigned char *_dst_frame, |
michael@0 | 514 | const unsigned char *_src_frame,int _ystride, |
michael@0 | 515 | const ptrdiff_t *_fragis,ptrdiff_t _nfragis,const ptrdiff_t *_frag_buf_offs); |
michael@0 | 516 | void oc_frag_recon_intra_c(unsigned char *_dst,int _dst_ystride, |
michael@0 | 517 | const ogg_int16_t _residue[64]); |
michael@0 | 518 | void oc_frag_recon_inter_c(unsigned char *_dst, |
michael@0 | 519 | const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]); |
michael@0 | 520 | void oc_frag_recon_inter2_c(unsigned char *_dst,const unsigned char *_src1, |
michael@0 | 521 | const unsigned char *_src2,int _ystride,const ogg_int16_t _residue[64]); |
michael@0 | 522 | void oc_idct8x8_c(ogg_int16_t _y[64],ogg_int16_t _x[64],int _last_zzi); |
michael@0 | 523 | void oc_state_frag_recon_c(const oc_theora_state *_state,ptrdiff_t _fragi, |
michael@0 | 524 | int _pli,ogg_int16_t _dct_coeffs[128],int _last_zzi,ogg_uint16_t _dc_quant); |
michael@0 | 525 | void oc_state_loop_filter_frag_rows_c(const oc_theora_state *_state, |
michael@0 | 526 | signed char _bv[256],int _refi,int _pli,int _fragy0,int _fragy_end); |
michael@0 | 527 | void oc_restore_fpu_c(void); |
michael@0 | 528 | |
michael@0 | 529 | /*We need a way to call a few encoder functions without introducing a link-time |
michael@0 | 530 | dependency into the decoder, while still allowing the old alpha API which |
michael@0 | 531 | does not distinguish between encoder and decoder objects to be used. |
michael@0 | 532 | We do this by placing a function table at the start of the encoder object |
michael@0 | 533 | which can dispatch into the encoder library. |
michael@0 | 534 | We do a similar thing for the decoder in case we ever decide to split off a |
michael@0 | 535 | common base library.*/ |
michael@0 | 536 | typedef void (*oc_state_clear_func)(theora_state *_th); |
michael@0 | 537 | typedef int (*oc_state_control_func)(theora_state *th,int _req, |
michael@0 | 538 | void *_buf,size_t _buf_sz); |
michael@0 | 539 | typedef ogg_int64_t (*oc_state_granule_frame_func)(theora_state *_th, |
michael@0 | 540 | ogg_int64_t _granulepos); |
michael@0 | 541 | typedef double (*oc_state_granule_time_func)(theora_state *_th, |
michael@0 | 542 | ogg_int64_t _granulepos); |
michael@0 | 543 | |
michael@0 | 544 | |
michael@0 | 545 | struct oc_state_dispatch_vtable{ |
michael@0 | 546 | oc_state_clear_func clear; |
michael@0 | 547 | oc_state_control_func control; |
michael@0 | 548 | oc_state_granule_frame_func granule_frame; |
michael@0 | 549 | oc_state_granule_time_func granule_time; |
michael@0 | 550 | }; |
michael@0 | 551 | |
michael@0 | 552 | #endif |