vp9_block.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_VP9_ENCODER_VP9_BLOCK_H_
  11. #define VPX_VP9_ENCODER_VP9_BLOCK_H_
  12. #include "vpx_util/vpx_thread.h"
  13. #include "vp9/common/vp9_entropymv.h"
  14. #include "vp9/common/vp9_entropy.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. typedef struct {
  19. unsigned int sse;
  20. int sum;
  21. unsigned int var;
  22. } diff;
  23. struct macroblock_plane {
  24. DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
  25. tran_low_t *qcoeff;
  26. tran_low_t *coeff;
  27. uint16_t *eobs;
  28. struct buf_2d src;
  29. // Quantizer setings
  30. DECLARE_ALIGNED(16, int16_t, round_fp[8]);
  31. int16_t *quant_fp;
  32. int16_t *quant;
  33. int16_t *quant_shift;
  34. int16_t *zbin;
  35. int16_t *round;
  36. int64_t quant_thred[2];
  37. };
  38. /* The [2] dimension is for whether we skip the EOB node (i.e. if previous
  39. * coefficient in this block was zero) or not. */
  40. typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2]
  41. [COEFF_CONTEXTS][ENTROPY_TOKENS];
  42. typedef struct {
  43. int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
  44. uint8_t mode_context[MAX_REF_FRAMES];
  45. } MB_MODE_INFO_EXT;
  46. typedef struct {
  47. int col_min;
  48. int col_max;
  49. int row_min;
  50. int row_max;
  51. } MvLimits;
  52. typedef struct macroblock MACROBLOCK;
  53. struct macroblock {
  54. // cf. https://bugs.chromium.org/p/webm/issues/detail?id=1054
  55. #if defined(_MSC_VER) && _MSC_VER < 1900
  56. int64_t bsse[MAX_MB_PLANE << 2];
  57. #endif
  58. struct macroblock_plane plane[MAX_MB_PLANE];
  59. MACROBLOCKD e_mbd;
  60. MB_MODE_INFO_EXT *mbmi_ext;
  61. MB_MODE_INFO_EXT *mbmi_ext_base;
  62. int skip_block;
  63. int select_tx_size;
  64. int skip_recode;
  65. int skip_optimize;
  66. int q_index;
  67. int block_qcoeff_opt;
  68. int block_tx_domain;
  69. // The equivalent error at the current rdmult of one whole bit (not one
  70. // bitcost unit).
  71. int errorperbit;
  72. // The equivalend SAD error of one (whole) bit at the current quantizer
  73. // for large blocks.
  74. int sadperbit16;
  75. // The equivalend SAD error of one (whole) bit at the current quantizer
  76. // for sub-8x8 blocks.
  77. int sadperbit4;
  78. int rddiv;
  79. int rdmult;
  80. int cb_rdmult;
  81. int segment_id;
  82. int mb_energy;
  83. // These are set to their default values at the beginning, and then adjusted
  84. // further in the encoding process.
  85. BLOCK_SIZE min_partition_size;
  86. BLOCK_SIZE max_partition_size;
  87. int mv_best_ref_index[MAX_REF_FRAMES];
  88. unsigned int max_mv_context[MAX_REF_FRAMES];
  89. unsigned int source_variance;
  90. unsigned int pred_sse[MAX_REF_FRAMES];
  91. int pred_mv_sad[MAX_REF_FRAMES];
  92. int nmvjointcost[MV_JOINTS];
  93. int *nmvcost[2];
  94. int *nmvcost_hp[2];
  95. int **mvcost;
  96. int nmvjointsadcost[MV_JOINTS];
  97. int *nmvsadcost[2];
  98. int *nmvsadcost_hp[2];
  99. int **mvsadcost;
  100. // sharpness is used to disable skip mode and change rd_mult
  101. int sharpness;
  102. // aq mode is used to adjust rd based on segment.
  103. int adjust_rdmult_by_segment;
  104. // These define limits to motion vector components to prevent them
  105. // from extending outside the UMV borders
  106. MvLimits mv_limits;
  107. // Notes transform blocks where no coefficents are coded.
  108. // Set during mode selection. Read during block encoding.
  109. uint8_t zcoeff_blk[TX_SIZES][256];
  110. // Accumulate the tx block eobs in a partition block.
  111. int32_t sum_y_eobs[TX_SIZES];
  112. int skip;
  113. int encode_breakout;
  114. // note that token_costs is the cost when eob node is skipped
  115. vp9_coeff_cost token_costs[TX_SIZES];
  116. int optimize;
  117. // indicate if it is in the rd search loop or encoding process
  118. int use_lp32x32fdct;
  119. int skip_encode;
  120. // In first pass, intra prediction is done based on source pixels
  121. // at tile boundaries
  122. int fp_src_pred;
  123. // use fast quantization process
  124. int quant_fp;
  125. // skip forward transform and quantization
  126. uint8_t skip_txfm[MAX_MB_PLANE << 2];
  127. #define SKIP_TXFM_NONE 0
  128. #define SKIP_TXFM_AC_DC 1
  129. #define SKIP_TXFM_AC_ONLY 2
  130. // cf. https://bugs.chromium.org/p/webm/issues/detail?id=1054
  131. #if !defined(_MSC_VER) || _MSC_VER >= 1900
  132. int64_t bsse[MAX_MB_PLANE << 2];
  133. #endif
  134. // Used to store sub partition's choices.
  135. MV pred_mv[MAX_REF_FRAMES];
  136. // Strong color activity detection. Used in RTC coding mode to enhance
  137. // the visual quality at the boundary of moving color objects.
  138. uint8_t color_sensitivity[2];
  139. uint8_t sb_is_skin;
  140. uint8_t skip_low_source_sad;
  141. uint8_t lowvar_highsumdiff;
  142. uint8_t last_sb_high_content;
  143. int sb_use_mv_part;
  144. int sb_mvcol_part;
  145. int sb_mvrow_part;
  146. int sb_pickmode_part;
  147. int zero_temp_sad_source;
  148. // For each superblock: saves the content value (e.g., low/high sad/sumdiff)
  149. // based on source sad, prior to encoding the frame.
  150. uint8_t content_state_sb;
  151. // Used to save the status of whether a block has a low variance in
  152. // choose_partitioning. 0 for 64x64, 1~2 for 64x32, 3~4 for 32x64, 5~8 for
  153. // 32x32, 9~24 for 16x16.
  154. uint8_t variance_low[25];
  155. uint8_t arf_frame_usage;
  156. uint8_t lastgolden_frame_usage;
  157. void (*fwd_txfm4x4)(const int16_t *input, tran_low_t *output, int stride);
  158. void (*inv_txfm_add)(const tran_low_t *input, uint8_t *dest, int stride,
  159. int eob);
  160. #if CONFIG_VP9_HIGHBITDEPTH
  161. void (*highbd_inv_txfm_add)(const tran_low_t *input, uint16_t *dest,
  162. int stride, int eob, int bd);
  163. #endif
  164. DECLARE_ALIGNED(16, uint8_t, est_pred[64 * 64]);
  165. struct scale_factors *me_sf;
  166. };
  167. #ifdef __cplusplus
  168. } // extern "C"
  169. #endif
  170. #endif // VPX_VP9_ENCODER_VP9_BLOCK_H_