2
0

blockd.h 7.7 KB

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