2
0

vp9_firstpass.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. typedef struct {
  34. double frame;
  35. double weight;
  36. double intra_error;
  37. double coded_error;
  38. double sr_coded_error;
  39. double frame_noise_energy;
  40. double pcnt_inter;
  41. double pcnt_motion;
  42. double pcnt_second_ref;
  43. double pcnt_neutral;
  44. double intra_skip_pct;
  45. double intra_smooth_pct; // % of blocks that are smooth
  46. double inactive_zone_rows; // Image mask rows top and bottom.
  47. double inactive_zone_cols; // Image mask columns at left and right edges.
  48. double MVr;
  49. double mvr_abs;
  50. double MVc;
  51. double mvc_abs;
  52. double MVrv;
  53. double MVcv;
  54. double mv_in_out_count;
  55. double new_mv_count;
  56. double duration;
  57. double count;
  58. int64_t spatial_layer_id;
  59. } FIRSTPASS_STATS;
  60. typedef enum {
  61. KF_UPDATE = 0,
  62. LF_UPDATE = 1,
  63. GF_UPDATE = 2,
  64. ARF_UPDATE = 3,
  65. OVERLAY_UPDATE = 4,
  66. FRAME_UPDATE_TYPES = 5
  67. } FRAME_UPDATE_TYPE;
  68. #define FC_ANIMATION_THRESH 0.15
  69. typedef enum {
  70. FC_NORMAL = 0,
  71. FC_GRAPHICS_ANIMATION = 1,
  72. FRAME_CONTENT_TYPES = 2
  73. } FRAME_CONTENT_TYPE;
  74. typedef struct {
  75. unsigned char index;
  76. unsigned char first_inter_index;
  77. RATE_FACTOR_LEVEL rf_level[(MAX_LAG_BUFFERS * 2) + 1];
  78. FRAME_UPDATE_TYPE update_type[(MAX_LAG_BUFFERS * 2) + 1];
  79. unsigned char arf_src_offset[(MAX_LAG_BUFFERS * 2) + 1];
  80. unsigned char arf_update_idx[(MAX_LAG_BUFFERS * 2) + 1];
  81. unsigned char arf_ref_idx[(MAX_LAG_BUFFERS * 2) + 1];
  82. int bit_allocation[(MAX_LAG_BUFFERS * 2) + 1];
  83. } GF_GROUP;
  84. typedef struct {
  85. unsigned int section_intra_rating;
  86. FIRSTPASS_STATS total_stats;
  87. FIRSTPASS_STATS this_frame_stats;
  88. const FIRSTPASS_STATS *stats_in;
  89. const FIRSTPASS_STATS *stats_in_start;
  90. const FIRSTPASS_STATS *stats_in_end;
  91. FIRSTPASS_STATS total_left_stats;
  92. int first_pass_done;
  93. int64_t bits_left;
  94. double modified_error_min;
  95. double modified_error_max;
  96. double modified_error_left;
  97. double mb_av_energy;
  98. double mb_smooth_pct;
  99. #if CONFIG_FP_MB_STATS
  100. uint8_t *frame_mb_stats_buf;
  101. uint8_t *this_frame_mb_stats;
  102. FIRSTPASS_MB_STATS firstpass_mb_stats;
  103. #endif
  104. // An indication of the content type of the current frame
  105. FRAME_CONTENT_TYPE fr_content_type;
  106. // Projected total bits available for a key frame group of frames
  107. int64_t kf_group_bits;
  108. // Error score of frames still to be coded in kf group
  109. int64_t kf_group_error_left;
  110. double bpm_factor;
  111. int rolling_arf_group_target_bits;
  112. int rolling_arf_group_actual_bits;
  113. int sr_update_lag;
  114. int kf_zeromotion_pct;
  115. int last_kfgroup_zeromotion_pct;
  116. int active_worst_quality;
  117. int baseline_active_worst_quality;
  118. int extend_minq;
  119. int extend_maxq;
  120. int extend_minq_fast;
  121. int arnr_strength_adjustment;
  122. GF_GROUP gf_group;
  123. } TWO_PASS;
  124. struct VP9_COMP;
  125. void vp9_init_first_pass(struct VP9_COMP *cpi);
  126. void vp9_rc_get_first_pass_params(struct VP9_COMP *cpi);
  127. void vp9_first_pass(struct VP9_COMP *cpi, const struct lookahead_entry *source);
  128. void vp9_end_first_pass(struct VP9_COMP *cpi);
  129. void vp9_init_second_pass(struct VP9_COMP *cpi);
  130. void vp9_rc_get_second_pass_params(struct VP9_COMP *cpi);
  131. void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
  132. // Post encode update of the rate control parameters for 2-pass
  133. void vp9_twopass_postencode_update(struct VP9_COMP *cpi);
  134. void calculate_coded_size(struct VP9_COMP *cpi, int *scaled_frame_width,
  135. int *scaled_frame_height);
  136. #ifdef __cplusplus
  137. } // extern "C"
  138. #endif
  139. #endif // VP9_ENCODER_VP9_FIRSTPASS_H_