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