vp9_aq_cyclicrefresh.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2014 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_AQ_CYCLICREFRESH_H_
  11. #define VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
  12. #include "vpx/vpx_integer.h"
  13. #include "vp9/common/vp9_blockd.h"
  14. #include "vp9/encoder/vp9_block.h"
  15. #include "vp9/encoder/vp9_skin_detection.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. // The segment ids used in cyclic refresh: from base (no boost) to increasing
  20. // boost (higher delta-qp).
  21. #define CR_SEGMENT_ID_BASE 0
  22. #define CR_SEGMENT_ID_BOOST1 1
  23. #define CR_SEGMENT_ID_BOOST2 2
  24. // Maximum rate target ratio for setting segment delta-qp.
  25. #define CR_MAX_RATE_TARGET_RATIO 4.0
  26. struct CYCLIC_REFRESH {
  27. // Percentage of blocks per frame that are targeted as candidates
  28. // for cyclic refresh.
  29. int percent_refresh;
  30. // Maximum q-delta as percentage of base q.
  31. int max_qdelta_perc;
  32. // Superblock starting index for cycling through the frame.
  33. int sb_index;
  34. // Controls how long block will need to wait to be refreshed again, in
  35. // excess of the cycle time, i.e., in the case of all zero motion, block
  36. // will be refreshed every (100/percent_refresh + time_for_refresh) frames.
  37. int time_for_refresh;
  38. // Target number of (8x8) blocks that are set for delta-q.
  39. int target_num_seg_blocks;
  40. // Actual number of (8x8) blocks that were applied delta-q.
  41. int actual_num_seg1_blocks;
  42. int actual_num_seg2_blocks;
  43. // RD mult. parameters for segment 1.
  44. int rdmult;
  45. // Cyclic refresh map.
  46. signed char *map;
  47. // Map of the last q a block was coded at.
  48. uint8_t *last_coded_q_map;
  49. // Thresholds applied to the projected rate/distortion of the coding block,
  50. // when deciding whether block should be refreshed.
  51. int64_t thresh_rate_sb;
  52. int64_t thresh_dist_sb;
  53. // Threshold applied to the motion vector (in units of 1/8 pel) of the
  54. // coding block, when deciding whether block should be refreshed.
  55. int16_t motion_thresh;
  56. // Rate target ratio to set q delta.
  57. double rate_ratio_qdelta;
  58. // Boost factor for rate target ratio, for segment CR_SEGMENT_ID_BOOST2.
  59. int rate_boost_fac;
  60. double low_content_avg;
  61. int qindex_delta[3];
  62. int reduce_refresh;
  63. };
  64. struct VP9_COMP;
  65. typedef struct CYCLIC_REFRESH CYCLIC_REFRESH;
  66. CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols);
  67. void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr);
  68. // Estimate the bits, incorporating the delta-q from segment 1, after encoding
  69. // the frame.
  70. int vp9_cyclic_refresh_estimate_bits_at_q(const struct VP9_COMP *cpi,
  71. double correction_factor);
  72. // Estimate the bits per mb, for a given q = i and a corresponding delta-q
  73. // (for segment 1), prior to encoding the frame.
  74. int vp9_cyclic_refresh_rc_bits_per_mb(const struct VP9_COMP *cpi, int i,
  75. double correction_factor);
  76. // Prior to coding a given prediction block, of size bsize at (mi_row, mi_col),
  77. // check if we should reset the segment_id, and update the cyclic_refresh map
  78. // and segmentation map.
  79. void vp9_cyclic_refresh_update_segment(struct VP9_COMP *const cpi,
  80. MODE_INFO *const mi, int mi_row,
  81. int mi_col, BLOCK_SIZE bsize,
  82. int64_t rate, int64_t dist, int skip,
  83. struct macroblock_plane *const p);
  84. void vp9_cyclic_refresh_update_sb_postencode(struct VP9_COMP *const cpi,
  85. const MODE_INFO *const mi,
  86. int mi_row, int mi_col,
  87. BLOCK_SIZE bsize);
  88. // Update the segmentation map, and related quantities: cyclic refresh map,
  89. // refresh sb_index, and target number of blocks to be refreshed.
  90. void vp9_cyclic_refresh_update__map(struct VP9_COMP *const cpi);
  91. // Update the actual number of blocks that were applied the segment delta q.
  92. void vp9_cyclic_refresh_postencode(struct VP9_COMP *const cpi);
  93. // Set golden frame update interval, for non-svc 1 pass CBR mode.
  94. void vp9_cyclic_refresh_set_golden_update(struct VP9_COMP *const cpi);
  95. // Check if we should not update golden reference, based on past refresh stats.
  96. void vp9_cyclic_refresh_check_golden_update(struct VP9_COMP *const cpi);
  97. // Set/update global/frame level refresh parameters.
  98. void vp9_cyclic_refresh_update_parameters(struct VP9_COMP *const cpi);
  99. // Setup cyclic background refresh: set delta q and segmentation map.
  100. void vp9_cyclic_refresh_setup(struct VP9_COMP *const cpi);
  101. int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
  102. void vp9_cyclic_refresh_reset_resize(struct VP9_COMP *const cpi);
  103. static INLINE int cyclic_refresh_segment_id_boosted(int segment_id) {
  104. return segment_id == CR_SEGMENT_ID_BOOST1 ||
  105. segment_id == CR_SEGMENT_ID_BOOST2;
  106. }
  107. static INLINE int cyclic_refresh_segment_id(int segment_id) {
  108. if (segment_id == CR_SEGMENT_ID_BOOST1)
  109. return CR_SEGMENT_ID_BOOST1;
  110. else if (segment_id == CR_SEGMENT_ID_BOOST2)
  111. return CR_SEGMENT_ID_BOOST2;
  112. else
  113. return CR_SEGMENT_ID_BASE;
  114. }
  115. #ifdef __cplusplus
  116. } // extern "C"
  117. #endif
  118. #endif // VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_