vp9_firstpass.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_FIRSTPASS_H_
  11. #define VP9_ENCODER_VP9_FIRSTPASS_H_
  12. #include "vp9/encoder/vp9_lookahead.h"
  13. #include "vp9/encoder/vp9_ratectrl.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #if CONFIG_FP_MB_STATS
  18. #define FPMB_DCINTRA_MASK 0x01
  19. #define FPMB_MOTION_ZERO_MASK 0x02
  20. #define FPMB_MOTION_LEFT_MASK 0x04
  21. #define FPMB_MOTION_RIGHT_MASK 0x08
  22. #define FPMB_MOTION_UP_MASK 0x10
  23. #define FPMB_MOTION_DOWN_MASK 0x20
  24. #define FPMB_ERROR_SMALL_MASK 0x40
  25. #define FPMB_ERROR_LARGE_MASK 0x80
  26. #define FPMB_ERROR_SMALL_TH 2000
  27. #define FPMB_ERROR_LARGE_TH 48000
  28. typedef struct {
  29. uint8_t *mb_stats_start;
  30. uint8_t *mb_stats_end;
  31. } FIRSTPASS_MB_STATS;
  32. #endif
  33. #define VLOW_MOTION_THRESHOLD 950
  34. typedef struct {
  35. double frame;
  36. double weight;
  37. double intra_error;
  38. double coded_error;
  39. double sr_coded_error;
  40. double pcnt_inter;
  41. double pcnt_motion;
  42. double pcnt_second_ref;
  43. double pcnt_neutral;
  44. double MVr;
  45. double mvr_abs;
  46. double MVc;
  47. double mvc_abs;
  48. double MVrv;
  49. double MVcv;
  50. double mv_in_out_count;
  51. double new_mv_count;
  52. double duration;
  53. double count;
  54. int64_t spatial_layer_id;
  55. } FIRSTPASS_STATS;
  56. typedef enum {
  57. KF_UPDATE = 0,
  58. LF_UPDATE = 1,
  59. GF_UPDATE = 2,
  60. ARF_UPDATE = 3,
  61. OVERLAY_UPDATE = 4,
  62. FRAME_UPDATE_TYPES = 5
  63. } FRAME_UPDATE_TYPE;
  64. typedef struct {
  65. unsigned char index;
  66. RATE_FACTOR_LEVEL rf_level[(MAX_LAG_BUFFERS * 2) + 1];
  67. FRAME_UPDATE_TYPE update_type[(MAX_LAG_BUFFERS * 2) + 1];
  68. unsigned char arf_src_offset[(MAX_LAG_BUFFERS * 2) + 1];
  69. unsigned char arf_update_idx[(MAX_LAG_BUFFERS * 2) + 1];
  70. unsigned char arf_ref_idx[(MAX_LAG_BUFFERS * 2) + 1];
  71. int bit_allocation[(MAX_LAG_BUFFERS * 2) + 1];
  72. } GF_GROUP;
  73. typedef struct {
  74. unsigned int section_intra_rating;
  75. FIRSTPASS_STATS total_stats;
  76. FIRSTPASS_STATS this_frame_stats;
  77. const FIRSTPASS_STATS *stats_in;
  78. const FIRSTPASS_STATS *stats_in_start;
  79. const FIRSTPASS_STATS *stats_in_end;
  80. FIRSTPASS_STATS total_left_stats;
  81. int first_pass_done;
  82. int64_t bits_left;
  83. double modified_error_min;
  84. double modified_error_max;
  85. double modified_error_left;
  86. double mb_av_energy;
  87. #if CONFIG_FP_MB_STATS
  88. uint8_t *frame_mb_stats_buf;
  89. uint8_t *this_frame_mb_stats;
  90. FIRSTPASS_MB_STATS firstpass_mb_stats;
  91. #endif
  92. // Projected total bits available for a key frame group of frames
  93. int64_t kf_group_bits;
  94. // Error score of frames still to be coded in kf group
  95. int64_t kf_group_error_left;
  96. // The fraction for a kf groups total bits allocated to the inter frames
  97. double kfgroup_inter_fraction;
  98. int sr_update_lag;
  99. int kf_zeromotion_pct;
  100. int last_kfgroup_zeromotion_pct;
  101. int gf_zeromotion_pct;
  102. int active_worst_quality;
  103. int baseline_active_worst_quality;
  104. int extend_minq;
  105. int extend_maxq;
  106. int extend_minq_fast;
  107. GF_GROUP gf_group;
  108. } TWO_PASS;
  109. struct VP9_COMP;
  110. void vp9_init_first_pass(struct VP9_COMP *cpi);
  111. void vp9_rc_get_first_pass_params(struct VP9_COMP *cpi);
  112. void vp9_first_pass(struct VP9_COMP *cpi, const struct lookahead_entry *source);
  113. void vp9_end_first_pass(struct VP9_COMP *cpi);
  114. void vp9_init_second_pass(struct VP9_COMP *cpi);
  115. void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
  116. void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
  117. // Post encode update of the rate control parameters for 2-pass
  118. void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
  119. void vp9_init_subsampling(struct VP9_COMP *cpi);
  120. void calculate_coded_size(struct VP9_COMP *cpi,
  121. int *scaled_frame_width,
  122. int *scaled_frame_height);
  123. #ifdef __cplusplus
  124. } // extern "C"
  125. #endif
  126. #endif // VP9_ENCODER_VP9_FIRSTPASS_H_