blockd.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef VP8_COMMON_BLOCKD_H_
  11. #define VP8_COMMON_BLOCKD_H_
  12. void vpx_log(const char *format, ...);
  13. #include "vpx_config.h"
  14. #include "vpx_scale/yv12config.h"
  15. #include "mv.h"
  16. #include "treecoder.h"
  17. #include "vpx_ports/mem.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /*#define DCPRED 1*/
  22. #define DCPREDSIMTHRESH 0
  23. #define DCPREDCNTTHRESH 3
  24. #define MB_FEATURE_TREE_PROBS 3
  25. #define MAX_MB_SEGMENTS 4
  26. #define MAX_REF_LF_DELTAS 4
  27. #define MAX_MODE_LF_DELTAS 4
  28. /* Segment Feature Masks */
  29. #define SEGMENT_DELTADATA 0
  30. #define SEGMENT_ABSDATA 1
  31. typedef struct
  32. {
  33. int r, c;
  34. } POS;
  35. #define PLANE_TYPE_Y_NO_DC 0
  36. #define PLANE_TYPE_Y2 1
  37. #define PLANE_TYPE_UV 2
  38. #define PLANE_TYPE_Y_WITH_DC 3
  39. typedef char ENTROPY_CONTEXT;
  40. typedef struct
  41. {
  42. ENTROPY_CONTEXT y1[4];
  43. ENTROPY_CONTEXT u[2];
  44. ENTROPY_CONTEXT v[2];
  45. ENTROPY_CONTEXT y2;
  46. } ENTROPY_CONTEXT_PLANES;
  47. extern const unsigned char vp8_block2left[25];
  48. extern const unsigned char vp8_block2above[25];
  49. #define VP8_COMBINEENTROPYCONTEXTS( Dest, A, B) \
  50. Dest = (A)+(B);
  51. typedef enum
  52. {
  53. KEY_FRAME = 0,
  54. INTER_FRAME = 1
  55. } FRAME_TYPE;
  56. typedef enum
  57. {
  58. DC_PRED, /* average of above and left pixels */
  59. V_PRED, /* vertical prediction */
  60. H_PRED, /* horizontal prediction */
  61. TM_PRED, /* Truemotion prediction */
  62. B_PRED, /* block based prediction, each block has its own prediction mode */
  63. NEARESTMV,
  64. NEARMV,
  65. ZEROMV,
  66. NEWMV,
  67. SPLITMV,
  68. MB_MODE_COUNT
  69. } MB_PREDICTION_MODE;
  70. /* Macroblock level features */
  71. typedef enum
  72. {
  73. MB_LVL_ALT_Q = 0, /* Use alternate Quantizer .... */
  74. MB_LVL_ALT_LF = 1, /* Use alternate loop filter value... */
  75. MB_LVL_MAX = 2 /* Number of MB level features supported */
  76. } MB_LVL_FEATURES;
  77. /* Segment Feature Masks */
  78. #define SEGMENT_ALTQ 0x01
  79. #define SEGMENT_ALT_LF 0x02
  80. #define VP8_YMODES (B_PRED + 1)
  81. #define VP8_UV_MODES (TM_PRED + 1)
  82. #define VP8_MVREFS (1 + SPLITMV - NEARESTMV)
  83. typedef enum
  84. {
  85. B_DC_PRED, /* average of above and left pixels */
  86. B_TM_PRED,
  87. B_VE_PRED, /* vertical prediction */
  88. B_HE_PRED, /* horizontal prediction */
  89. B_LD_PRED,
  90. B_RD_PRED,
  91. B_VR_PRED,
  92. B_VL_PRED,
  93. B_HD_PRED,
  94. B_HU_PRED,
  95. LEFT4X4,
  96. ABOVE4X4,
  97. ZERO4X4,
  98. NEW4X4,
  99. B_MODE_COUNT
  100. } B_PREDICTION_MODE;
  101. #define VP8_BINTRAMODES (B_HU_PRED + 1) /* 10 */
  102. #define VP8_SUBMVREFS (1 + NEW4X4 - LEFT4X4)
  103. /* For keyframes, intra block modes are predicted by the (already decoded)
  104. modes for the Y blocks to the left and above us; for interframes, there
  105. is a single probability table. */
  106. union b_mode_info
  107. {
  108. B_PREDICTION_MODE as_mode;
  109. int_mv mv;
  110. };
  111. typedef enum
  112. {
  113. INTRA_FRAME = 0,
  114. LAST_FRAME = 1,
  115. GOLDEN_FRAME = 2,
  116. ALTREF_FRAME = 3,
  117. MAX_REF_FRAMES = 4
  118. } MV_REFERENCE_FRAME;
  119. typedef struct
  120. {
  121. uint8_t mode, uv_mode;
  122. uint8_t ref_frame;
  123. uint8_t is_4x4;
  124. int_mv mv;
  125. uint8_t partitioning;
  126. uint8_t mb_skip_coeff; /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */
  127. uint8_t need_to_clamp_mvs;
  128. uint8_t segment_id; /* Which set of segmentation parameters should be used for this MB */
  129. } MB_MODE_INFO;
  130. typedef struct modeinfo
  131. {
  132. MB_MODE_INFO mbmi;
  133. union b_mode_info bmi[16];
  134. } MODE_INFO;
  135. #if CONFIG_MULTI_RES_ENCODING
  136. /* The mb-level information needed to be stored for higher-resolution encoder */
  137. typedef struct
  138. {
  139. MB_PREDICTION_MODE mode;
  140. MV_REFERENCE_FRAME ref_frame;
  141. int_mv mv;
  142. int dissim; /* dissimilarity level of the macroblock */
  143. } LOWER_RES_MB_INFO;
  144. /* The frame-level information needed to be stored for higher-resolution
  145. * encoder */
  146. typedef struct
  147. {
  148. FRAME_TYPE frame_type;
  149. int is_frame_dropped;
  150. // The frame rate for the lowest resolution.
  151. double low_res_framerate;
  152. /* The frame number of each reference frames */
  153. unsigned int low_res_ref_frames[MAX_REF_FRAMES];
  154. // The video frame counter value for the key frame, for lowest resolution.
  155. unsigned int key_frame_counter_value;
  156. LOWER_RES_MB_INFO *mb_info;
  157. } LOWER_RES_FRAME_INFO;
  158. #endif
  159. typedef struct blockd
  160. {
  161. short *qcoeff;
  162. short *dqcoeff;
  163. unsigned char *predictor;
  164. short *dequant;
  165. int offset;
  166. char *eob;
  167. union b_mode_info bmi;
  168. } BLOCKD;
  169. typedef void (*vp8_subpix_fn_t)(unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch);
  170. typedef struct macroblockd
  171. {
  172. DECLARE_ALIGNED(16, unsigned char, predictor[384]);
  173. DECLARE_ALIGNED(16, short, qcoeff[400]);
  174. DECLARE_ALIGNED(16, short, dqcoeff[400]);
  175. DECLARE_ALIGNED(16, char, eobs[25]);
  176. DECLARE_ALIGNED(16, short, dequant_y1[16]);
  177. DECLARE_ALIGNED(16, short, dequant_y1_dc[16]);
  178. DECLARE_ALIGNED(16, short, dequant_y2[16]);
  179. DECLARE_ALIGNED(16, short, dequant_uv[16]);
  180. /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */
  181. BLOCKD block[25];
  182. int fullpixel_mask;
  183. YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */
  184. YV12_BUFFER_CONFIG dst;
  185. MODE_INFO *mode_info_context;
  186. int mode_info_stride;
  187. FRAME_TYPE frame_type;
  188. int up_available;
  189. int left_available;
  190. unsigned char *recon_above[3];
  191. unsigned char *recon_left[3];
  192. int recon_left_stride[2];
  193. /* Y,U,V,Y2 */
  194. ENTROPY_CONTEXT_PLANES *above_context;
  195. ENTROPY_CONTEXT_PLANES *left_context;
  196. /* 0 indicates segmentation at MB level is not enabled. Otherwise the individual bits indicate which features are active. */
  197. unsigned char segmentation_enabled;
  198. /* 0 (do not update) 1 (update) the macroblock segmentation map. */
  199. unsigned char update_mb_segmentation_map;
  200. /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
  201. unsigned char update_mb_segmentation_data;
  202. /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
  203. unsigned char mb_segement_abs_delta;
  204. /* Per frame flags that define which MB level features (such as quantizer or loop filter level) */
  205. /* are enabled and when enabled the proabilities used to decode the per MB flags in MB_MODE_INFO */
  206. vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS]; /* Probability Tree used to code Segment number */
  207. signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS]; /* Segment parameters */
  208. /* mode_based Loop filter adjustment */
  209. unsigned char mode_ref_lf_delta_enabled;
  210. unsigned char mode_ref_lf_delta_update;
  211. /* Delta values have the range +/- MAX_LOOP_FILTER */
  212. signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */
  213. signed char ref_lf_deltas[MAX_REF_LF_DELTAS]; /* 0 = Intra, Last, GF, ARF */
  214. signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */
  215. signed char mode_lf_deltas[MAX_MODE_LF_DELTAS]; /* 0 = BPRED, ZERO_MV, MV, SPLIT */
  216. /* Distance of MB away from frame edges */
  217. int mb_to_left_edge;
  218. int mb_to_right_edge;
  219. int mb_to_top_edge;
  220. int mb_to_bottom_edge;
  221. vp8_subpix_fn_t subpixel_predict;
  222. vp8_subpix_fn_t subpixel_predict8x4;
  223. vp8_subpix_fn_t subpixel_predict8x8;
  224. vp8_subpix_fn_t subpixel_predict16x16;
  225. void *current_bc;
  226. int corrupted;
  227. #if ARCH_X86 || ARCH_X86_64
  228. /* This is an intermediate buffer currently used in sub-pixel motion search
  229. * to keep a copy of the reference area. This buffer can be used for other
  230. * purpose.
  231. */
  232. DECLARE_ALIGNED(32, unsigned char, y_buf[22*32]);
  233. #endif
  234. } MACROBLOCKD;
  235. extern void vp8_build_block_doffsets(MACROBLOCKD *x);
  236. extern void vp8_setup_block_dptrs(MACROBLOCKD *x);
  237. #ifdef __cplusplus
  238. } // extern "C"
  239. #endif
  240. #endif // VP8_COMMON_BLOCKD_H_