vp9_rd.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #define RDDIV_BITS 7
  20. #define RDCOST(RM, DM, R, D) \
  21. (((128 + ((int64_t)R) * (RM)) >> 8) + (D << DM))
  22. #define QIDX_SKIP_THRESH 115
  23. #define MV_COST_WEIGHT 108
  24. #define MV_COST_WEIGHT_SUB 120
  25. #define INVALID_MV 0x80008000
  26. #define MAX_MODES 30
  27. #define MAX_REFS 6
  28. #define RD_THRESH_MAX_FACT 64
  29. #define RD_THRESH_INC 1
  30. // This enumerator type needs to be kept aligned with the mode order in
  31. // const MODE_DEFINITION vp9_mode_order[MAX_MODES] used in the rd code.
  32. typedef enum {
  33. THR_NEARESTMV,
  34. THR_NEARESTA,
  35. THR_NEARESTG,
  36. THR_DC,
  37. THR_NEWMV,
  38. THR_NEWA,
  39. THR_NEWG,
  40. THR_NEARMV,
  41. THR_NEARA,
  42. THR_NEARG,
  43. THR_ZEROMV,
  44. THR_ZEROG,
  45. THR_ZEROA,
  46. THR_COMP_NEARESTLA,
  47. THR_COMP_NEARESTGA,
  48. THR_TM,
  49. THR_COMP_NEARLA,
  50. THR_COMP_NEWLA,
  51. THR_COMP_NEARGA,
  52. THR_COMP_NEWGA,
  53. THR_COMP_ZEROLA,
  54. THR_COMP_ZEROGA,
  55. THR_H_PRED,
  56. THR_V_PRED,
  57. THR_D135_PRED,
  58. THR_D207_PRED,
  59. THR_D153_PRED,
  60. THR_D63_PRED,
  61. THR_D117_PRED,
  62. THR_D45_PRED,
  63. } THR_MODES;
  64. typedef enum {
  65. THR_LAST,
  66. THR_GOLD,
  67. THR_ALTR,
  68. THR_COMP_LA,
  69. THR_COMP_GA,
  70. THR_INTRA,
  71. } THR_MODES_SUB8X8;
  72. typedef struct RD_OPT {
  73. // Thresh_mult is used to set a threshold for the rd score. A higher value
  74. // means that we will accept the best mode so far more often. This number
  75. // is used in combination with the current block size, and thresh_freq_fact
  76. // to pick a threshold.
  77. int thresh_mult[MAX_MODES];
  78. int thresh_mult_sub8x8[MAX_REFS];
  79. int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
  80. int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
  81. // TODO(agrange): can this overflow?
  82. int tx_select_threshes[MAX_REF_FRAMES][TX_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,
  105. int64_t *dist);
  106. int vp9_get_switchable_rate(const struct VP9_COMP *cpi,
  107. const MACROBLOCKD *const xd);
  108. int vp9_raster_block_offset(BLOCK_SIZE plane_bsize,
  109. int raster_block, int stride);
  110. int16_t* vp9_raster_block_offset_int16(BLOCK_SIZE plane_bsize,
  111. int raster_block, int16_t *base);
  112. YV12_BUFFER_CONFIG *vp9_get_scaled_ref_frame(const struct VP9_COMP *cpi,
  113. int ref_frame);
  114. void vp9_init_me_luts(void);
  115. void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
  116. const struct macroblockd_plane *pd,
  117. ENTROPY_CONTEXT t_above[16],
  118. ENTROPY_CONTEXT t_left[16]);
  119. void vp9_set_rd_speed_thresholds(struct VP9_COMP *cpi);
  120. void vp9_set_rd_speed_thresholds_sub8x8(struct VP9_COMP *cpi);
  121. void vp9_update_rd_thresh_fact(int (*fact)[MAX_MODES], int rd_thresh,
  122. int bsize, int best_mode_index);
  123. static INLINE int rd_less_than_thresh(int64_t best_rd, int thresh,
  124. int thresh_fact) {
  125. return best_rd < ((int64_t)thresh * thresh_fact >> 5) || thresh == INT_MAX;
  126. }
  127. void vp9_mv_pred(struct VP9_COMP *cpi, MACROBLOCK *x,
  128. uint8_t *ref_y_buffer, int ref_y_stride,
  129. int ref_frame, BLOCK_SIZE block_size);
  130. void vp9_setup_pred_block(const MACROBLOCKD *xd,
  131. struct buf_2d dst[MAX_MB_PLANE],
  132. const YV12_BUFFER_CONFIG *src,
  133. int mi_row, int mi_col,
  134. const struct scale_factors *scale,
  135. const struct scale_factors *scale_uv);
  136. int vp9_get_intra_cost_penalty(int qindex, int qdelta,
  137. vpx_bit_depth_t bit_depth);
  138. #ifdef __cplusplus
  139. } // extern "C"
  140. #endif
  141. #endif // VP9_ENCODER_VP9_RD_H_