vp9_firstpass.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 INVALID_ROW -1
  34. typedef struct {
  35. double frame_mb_intra_factor;
  36. double frame_mb_brightness_factor;
  37. double frame_mb_neutral_count;
  38. } FP_MB_FLOAT_STATS;
  39. typedef struct {
  40. double intra_factor;
  41. double brightness_factor;
  42. int64_t coded_error;
  43. int64_t sr_coded_error;
  44. int64_t frame_noise_energy;
  45. int64_t intra_error;
  46. int intercount;
  47. int second_ref_count;
  48. double neutral_count;
  49. double intra_count_low; // Coded intra but low variance
  50. double intra_count_high; // Coded intra high variance
  51. int intra_skip_count;
  52. int image_data_start_row;
  53. int mvcount;
  54. int sum_mvr;
  55. int sum_mvr_abs;
  56. int sum_mvc;
  57. int sum_mvc_abs;
  58. int64_t sum_mvrs;
  59. int64_t sum_mvcs;
  60. int sum_in_vectors;
  61. int intra_smooth_count;
  62. } FIRSTPASS_DATA;
  63. typedef struct {
  64. double frame;
  65. double weight;
  66. double intra_error;
  67. double coded_error;
  68. double sr_coded_error;
  69. double frame_noise_energy;
  70. double pcnt_inter;
  71. double pcnt_motion;
  72. double pcnt_second_ref;
  73. double pcnt_neutral;
  74. double pcnt_intra_low; // Coded intra but low variance
  75. double pcnt_intra_high; // Coded intra high variance
  76. double intra_skip_pct;
  77. double intra_smooth_pct; // % of blocks that are smooth
  78. double inactive_zone_rows; // Image mask rows top and bottom.
  79. double inactive_zone_cols; // Image mask columns at left and right edges.
  80. double MVr;
  81. double mvr_abs;
  82. double MVc;
  83. double mvc_abs;
  84. double MVrv;
  85. double MVcv;
  86. double mv_in_out_count;
  87. double duration;
  88. double count;
  89. int64_t spatial_layer_id;
  90. } FIRSTPASS_STATS;
  91. typedef enum {
  92. KF_UPDATE = 0,
  93. LF_UPDATE = 1,
  94. GF_UPDATE = 2,
  95. ARF_UPDATE = 3,
  96. OVERLAY_UPDATE = 4,
  97. FRAME_UPDATE_TYPES = 5
  98. } FRAME_UPDATE_TYPE;
  99. #define FC_ANIMATION_THRESH 0.15
  100. typedef enum {
  101. FC_NORMAL = 0,
  102. FC_GRAPHICS_ANIMATION = 1,
  103. FRAME_CONTENT_TYPES = 2
  104. } FRAME_CONTENT_TYPE;
  105. typedef struct {
  106. unsigned char index;
  107. unsigned char first_inter_index;
  108. RATE_FACTOR_LEVEL rf_level[(MAX_LAG_BUFFERS * 2) + 1];
  109. FRAME_UPDATE_TYPE update_type[(MAX_LAG_BUFFERS * 2) + 1];
  110. unsigned char arf_src_offset[(MAX_LAG_BUFFERS * 2) + 1];
  111. unsigned char arf_update_idx[(MAX_LAG_BUFFERS * 2) + 1];
  112. unsigned char arf_ref_idx[(MAX_LAG_BUFFERS * 2) + 1];
  113. int bit_allocation[(MAX_LAG_BUFFERS * 2) + 1];
  114. } GF_GROUP;
  115. typedef struct {
  116. unsigned int section_intra_rating;
  117. FIRSTPASS_STATS total_stats;
  118. FIRSTPASS_STATS this_frame_stats;
  119. const FIRSTPASS_STATS *stats_in;
  120. const FIRSTPASS_STATS *stats_in_start;
  121. const FIRSTPASS_STATS *stats_in_end;
  122. FIRSTPASS_STATS total_left_stats;
  123. int first_pass_done;
  124. int64_t bits_left;
  125. double mean_mod_score;
  126. double normalized_score_left;
  127. double mb_av_energy;
  128. double mb_smooth_pct;
  129. #if CONFIG_FP_MB_STATS
  130. uint8_t *frame_mb_stats_buf;
  131. uint8_t *this_frame_mb_stats;
  132. FIRSTPASS_MB_STATS firstpass_mb_stats;
  133. #endif
  134. FP_MB_FLOAT_STATS *fp_mb_float_stats;
  135. // An indication of the content type of the current frame
  136. FRAME_CONTENT_TYPE fr_content_type;
  137. // Projected total bits available for a key frame group of frames
  138. int64_t kf_group_bits;
  139. // Error score of frames still to be coded in kf group
  140. double kf_group_error_left;
  141. double bpm_factor;
  142. int rolling_arf_group_target_bits;
  143. int rolling_arf_group_actual_bits;
  144. int sr_update_lag;
  145. int kf_zeromotion_pct;
  146. int last_kfgroup_zeromotion_pct;
  147. int active_worst_quality;
  148. int baseline_active_worst_quality;
  149. int extend_minq;
  150. int extend_maxq;
  151. int extend_minq_fast;
  152. int arnr_strength_adjustment;
  153. GF_GROUP gf_group;
  154. } TWO_PASS;
  155. struct VP9_COMP;
  156. struct ThreadData;
  157. struct TileDataEnc;
  158. void vp9_init_first_pass(struct VP9_COMP *cpi);
  159. void vp9_rc_get_first_pass_params(struct VP9_COMP *cpi);
  160. void vp9_first_pass(struct VP9_COMP *cpi, const struct lookahead_entry *source);
  161. void vp9_end_first_pass(struct VP9_COMP *cpi);
  162. void vp9_first_pass_encode_tile_mb_row(struct VP9_COMP *cpi,
  163. struct ThreadData *td,
  164. FIRSTPASS_DATA *fp_acc_data,
  165. struct TileDataEnc *tile_data,
  166. MV *best_ref_mv, int mb_row);
  167. void vp9_init_second_pass(struct VP9_COMP *cpi);
  168. void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
  169. void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
  170. // Post encode update of the rate control parameters for 2-pass
  171. void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
  172. void calculate_coded_size(struct VP9_COMP *cpi, int *scaled_frame_width,
  173. int *scaled_frame_height);
  174. #ifdef __cplusplus
  175. } // extern "C"
  176. #endif
  177. #endif // VP9_ENCODER_VP9_FIRSTPASS_H_