vp9_rd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 VP9_ENCODER_VP9_RD_H_
  11. #define VP9_ENCODER_VP9_RD_H_
  12. #include <limits.h>
  13. #include "vp9/common/vp9_blockd.h"
  14. #include "vp9/encoder/vp9_block.h"
  15. #include "vp9/encoder/vp9_context_tree.h"
  16. #include "vp9/encoder/vp9_cost.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #define RDDIV_BITS 7
  21. #define RD_EPB_SHIFT 6
  22. #define RDCOST(RM, DM, R, D) \
  23. (ROUND_POWER_OF_TWO(((int64_t)R) * (RM), VP9_PROB_COST_SHIFT) + (D << DM))
  24. #define QIDX_SKIP_THRESH 115
  25. #define MV_COST_WEIGHT 108
  26. #define MV_COST_WEIGHT_SUB 120
  27. #define INVALID_MV 0x80008000
  28. #define MAX_MODES 30
  29. #define MAX_REFS 6
  30. #define RD_THRESH_INIT_FACT 32
  31. #define RD_THRESH_MAX_FACT 64
  32. #define RD_THRESH_INC 1
  33. // This enumerator type needs to be kept aligned with the mode order in
  34. // const MODE_DEFINITION vp9_mode_order[MAX_MODES] used in the rd code.
  35. typedef enum {
  36. THR_NEARESTMV,
  37. THR_NEARESTA,
  38. THR_NEARESTG,
  39. THR_DC,
  40. THR_NEWMV,
  41. THR_NEWA,
  42. THR_NEWG,
  43. THR_NEARMV,
  44. THR_NEARA,
  45. THR_NEARG,
  46. THR_ZEROMV,
  47. THR_ZEROG,
  48. THR_ZEROA,
  49. THR_COMP_NEARESTLA,
  50. THR_COMP_NEARESTGA,
  51. THR_TM,
  52. THR_COMP_NEARLA,
  53. THR_COMP_NEWLA,
  54. THR_COMP_NEARGA,
  55. THR_COMP_NEWGA,
  56. THR_COMP_ZEROLA,
  57. THR_COMP_ZEROGA,
  58. THR_H_PRED,
  59. THR_V_PRED,
  60. THR_D135_PRED,
  61. THR_D207_PRED,
  62. THR_D153_PRED,
  63. THR_D63_PRED,
  64. THR_D117_PRED,
  65. THR_D45_PRED,
  66. } THR_MODES;
  67. typedef enum {
  68. THR_LAST,
  69. THR_GOLD,
  70. THR_ALTR,
  71. THR_COMP_LA,
  72. THR_COMP_GA,
  73. THR_INTRA,
  74. } THR_MODES_SUB8X8;
  75. typedef struct RD_OPT {
  76. // Thresh_mult is used to set a threshold for the rd score. A higher value
  77. // means that we will accept the best mode so far more often. This number
  78. // is used in combination with the current block size, and thresh_freq_fact
  79. // to pick a threshold.
  80. int thresh_mult[MAX_MODES];
  81. int thresh_mult_sub8x8[MAX_REFS];
  82. int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
  83. int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
  84. int64_t filter_threshes[MAX_REF_FRAMES][SWITCHABLE_FILTER_CONTEXTS];
  85. int RDMULT;
  86. int RDDIV;
  87. } RD_OPT;
  88. typedef struct RD_COST {
  89. int rate;
  90. int64_t dist;
  91. int64_t rdcost;
  92. } RD_COST;
  93. // Reset the rate distortion cost values to maximum (invalid) value.
  94. void vp9_rd_cost_reset(RD_COST *rd_cost);
  95. // Initialize the rate distortion cost values to zero.
  96. void vp9_rd_cost_init(RD_COST *rd_cost);
  97. struct TileInfo;
  98. struct TileDataEnc;
  99. struct VP9_COMP;
  100. struct macroblock;
  101. int64_t vp9_compute_rd_mult_based_on_qindex(const struct VP9_COMP *cpi,
  102. int qindex);
  103. int vp9_compute_rd_mult(const struct VP9_COMP *cpi, int qindex);
  104. void vp9_initialize_rd_consts(struct VP9_COMP *cpi);
  105. void vp9_initialize_me_consts(struct VP9_COMP *cpi, MACROBLOCK *x, int qindex);
  106. void vp9_model_rd_from_var_lapndz(unsigned int var, unsigned int n,
  107. unsigned int qstep, int *rate, int64_t *dist);
  108. void vp9_model_rd_from_var_lapndz_vec(unsigned int var[MAX_MB_PLANE],
  109. unsigned int n_log2[MAX_MB_PLANE],
  110. unsigned int qstep[MAX_MB_PLANE],
  111. int64_t *rate_sum, int64_t *dist_sum);
  112. int vp9_get_switchable_rate(const struct VP9_COMP *cpi,
  113. const MACROBLOCKD *const xd);
  114. int vp9_raster_block_offset(BLOCK_SIZE plane_bsize, int raster_block,
  115. int stride);
  116. int16_t *vp9_raster_block_offset_int16(BLOCK_SIZE plane_bsize, int raster_block,
  117. int16_t *base);
  118. YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const struct VP9_COMP *cpi,
  119. int ref_frame);
  120. void vp9_init_me_luts(void);
  121. void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
  122. const struct macroblockd_plane *pd,
  123. ENTROPY_CONTEXT t_above[16],
  124. ENTROPY_CONTEXT t_left[16]);
  125. void vp9_set_rd_speed_thresholds(struct VP9_COMP *cpi);
  126. void vp9_set_rd_speed_thresholds_sub8x8(struct VP9_COMP *cpi);
  127. void vp9_update_rd_thresh_fact(int (*fact)[MAX_MODES], int rd_thresh, int bsize,
  128. int best_mode_index);
  129. static INLINE int rd_less_than_thresh(int64_t best_rd, int thresh,
  130. const int *const thresh_fact) {
  131. return best_rd < ((int64_t)thresh * (*thresh_fact) >> 5) || thresh == INT_MAX;
  132. }
  133. static INLINE void set_error_per_bit(MACROBLOCK *x, int rdmult) {
  134. x->errorperbit = rdmult >> RD_EPB_SHIFT;
  135. x->errorperbit += (x->errorperbit == 0);
  136. }
  137. void vp9_mv_pred(struct VP9_COMP *cpi, MACROBLOCK *x, uint8_t *ref_y_buffer,
  138. int ref_y_stride, int ref_frame, BLOCK_SIZE block_size);
  139. void vp9_setup_pred_block(const MACROBLOCKD *xd,
  140. struct buf_2d dst[MAX_MB_PLANE],
  141. const YV12_BUFFER_CONFIG *src, int mi_row, int mi_col,
  142. const struct scale_factors *scale,
  143. const struct scale_factors *scale_uv);
  144. int vp9_get_intra_cost_penalty(const struct VP9_COMP *const cpi,
  145. BLOCK_SIZE bsize, int qindex, int qdelta);
  146. unsigned int vp9_get_sby_perpixel_variance(struct VP9_COMP *cpi,
  147. const struct buf_2d *ref,
  148. BLOCK_SIZE bs);
  149. #if CONFIG_VP9_HIGHBITDEPTH
  150. unsigned int vp9_high_get_sby_perpixel_variance(struct VP9_COMP *cpi,
  151. const struct buf_2d *ref,
  152. BLOCK_SIZE bs, int bd);
  153. #endif
  154. #ifdef __cplusplus
  155. } // extern "C"
  156. #endif
  157. #endif // VP9_ENCODER_VP9_RD_H_