vp9_aq_cyclicrefresh.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "vp9/common/vp9_blockd.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. // The segment ids used in cyclic refresh: from base (no boost) to increasing
  17. // boost (higher delta-qp).
  18. #define CR_SEGMENT_ID_BASE 0
  19. #define CR_SEGMENT_ID_BOOST1 1
  20. #define CR_SEGMENT_ID_BOOST2 2
  21. // Maximum rate target ratio for setting segment delta-qp.
  22. #define CR_MAX_RATE_TARGET_RATIO 4.0
  23. // Boost factor for rate target ratio, for segment CR_SEGMENT_ID_BOOST2.
  24. #define CR_BOOST2_FAC 1.7
  25. struct VP9_COMP;
  26. struct CYCLIC_REFRESH;
  27. typedef struct CYCLIC_REFRESH CYCLIC_REFRESH;
  28. CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols);
  29. void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr);
  30. // Estimate the bits, incorporating the delta-q from segment 1, after encoding
  31. // the frame.
  32. int vp9_cyclic_refresh_estimate_bits_at_q(const struct VP9_COMP *cpi,
  33. double correction_factor);
  34. // Estimate the bits per mb, for a given q = i and a corresponding delta-q
  35. // (for segment 1), prior to encoding the frame.
  36. int vp9_cyclic_refresh_rc_bits_per_mb(const struct VP9_COMP *cpi, int i,
  37. double correction_factor);
  38. // Prior to coding a given prediction block, of size bsize at (mi_row, mi_col),
  39. // check if we should reset the segment_id, and update the cyclic_refresh map
  40. // and segmentation map.
  41. void vp9_cyclic_refresh_update_segment(struct VP9_COMP *const cpi,
  42. MB_MODE_INFO *const mbmi,
  43. int mi_row, int mi_col, BLOCK_SIZE bsize,
  44. int64_t rate, int64_t dist, int skip);
  45. // Update the segmentation map, and related quantities: cyclic refresh map,
  46. // refresh sb_index, and target number of blocks to be refreshed.
  47. void vp9_cyclic_refresh_update__map(struct VP9_COMP *const cpi);
  48. // Update the actual number of blocks that were applied the segment delta q.
  49. void vp9_cyclic_refresh_postencode(struct VP9_COMP *const cpi);
  50. // Set golden frame update interval, for non-svc 1 pass CBR mode.
  51. void vp9_cyclic_refresh_set_golden_update(struct VP9_COMP *const cpi);
  52. // Check if we should not update golden reference, based on past refresh stats.
  53. void vp9_cyclic_refresh_check_golden_update(struct VP9_COMP *const cpi);
  54. // Set/update global/frame level refresh parameters.
  55. void vp9_cyclic_refresh_update_parameters(struct VP9_COMP *const cpi);
  56. // Setup cyclic background refresh: set delta q and segmentation map.
  57. void vp9_cyclic_refresh_setup(struct VP9_COMP *const cpi);
  58. int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
  59. static INLINE int cyclic_refresh_segment_id_boosted(int segment_id) {
  60. return segment_id == CR_SEGMENT_ID_BOOST1 ||
  61. segment_id == CR_SEGMENT_ID_BOOST2;
  62. }
  63. static INLINE int cyclic_refresh_segment_id(int segment_id) {
  64. if (segment_id == CR_SEGMENT_ID_BOOST1)
  65. return CR_SEGMENT_ID_BOOST1;
  66. else if (segment_id == CR_SEGMENT_ID_BOOST2)
  67. return CR_SEGMENT_ID_BOOST2;
  68. else
  69. return CR_SEGMENT_ID_BASE;
  70. }
  71. #ifdef __cplusplus
  72. } // extern "C"
  73. #endif
  74. #endif // VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_