decint.h 6.8 KB

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