2
0

blockd.h 8.4 KB

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