vp9_rd.h 5.5 KB

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