1 /* 2 * Copyright (c) 2019, Alliance for Open Media. All rights reserved. 3 * 4 * This source code is subject to the terms of the BSD 2 Clause License and 5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License 6 * was not distributed with this source code in the LICENSE file, you can 7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open 8 * Media Patent License 1.0 was not distributed with this source code in the 9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent. 10 */ 11 12 #ifndef AOM_AV1_ENCODER_PASS2_STRATEGY_H_ 13 #define AOM_AV1_ENCODER_PASS2_STRATEGY_H_ 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 struct AV1_COMP; 20 struct EncodeFrameParams; 21 22 #include "av1/encoder/encoder.h" 23 24 /*! 25 * \brief accumulated stats and features in a gf group 26 */ 27 typedef struct { 28 /*!\cond */ 29 double gf_group_err; 30 double gf_group_raw_error; 31 double gf_group_skip_pct; 32 double gf_group_inactive_zone_rows; 33 34 double mv_ratio_accumulator; 35 double decay_accumulator; 36 double zero_motion_accumulator; 37 double loop_decay_rate; 38 double last_loop_decay_rate; 39 double this_frame_mv_in_out; 40 double mv_in_out_accumulator; 41 double abs_mv_in_out_accumulator; 42 43 double avg_sr_coded_error; 44 double avg_pcnt_second_ref; 45 double avg_new_mv_count; 46 double avg_wavelet_energy; 47 double avg_raw_err_stdev; 48 int non_zero_stdev_count; 49 /*!\endcond */ 50 } GF_GROUP_STATS; 51 52 /*! 53 * \brief accumulated stats and features for a frame 54 */ 55 typedef struct { 56 /*!\cond */ 57 double frame_err; 58 double frame_coded_error; 59 double frame_sr_coded_error; 60 /*!\endcond */ 61 } GF_FRAME_STATS; 62 /*!\cond */ 63 64 void av1_init_second_pass(struct AV1_COMP *cpi); 65 66 void av1_init_single_pass_lap(AV1_COMP *cpi); 67 68 /*!\endcond */ 69 /*!\brief Main per frame entry point for second pass of two pass encode 70 * 71 *\ingroup rate_control 72 * 73 * This function is called for each frame in the second pass of a two pass 74 * encode. It checks the frame type and if a new KF or GF/ARF is due. 75 * When a KF is due it calls find_next_key_frame() to work out how long 76 * this key frame group will be and assign bits to the key frame. 77 * At the start of a new GF/ARF group it calls calculate_gf_length() 78 * and define_gf_group() which are the main functions responsible for 79 * defining the size and structure of the new GF/ARF group. 80 * 81 * \param[in] cpi Top - level encoder instance structure 82 * \param[in] frame_params Per frame encoding parameters 83 * \param[in] frame_flags Frame type and coding flags 84 * 85 * \remark No return but analyses first pass stats and assigns a target 86 * number of bits to the current frame and a target Q range. 87 */ 88 void av1_get_second_pass_params(struct AV1_COMP *cpi, 89 struct EncodeFrameParams *const frame_params, 90 unsigned int frame_flags); 91 92 /*!\brief Adjustments to two pass and rate control after each frame. 93 * 94 *\ingroup rate_control 95 * 96 * This function is called after each frame to make adjustments to 97 * heuristics and data structures that relate to rate control. 98 * 99 * \param[in] cpi Top - level encoder instance structure 100 * 101 * \remark No return value but this function updates various rate control 102 * related data structures that for example track overshoot and 103 * undershoot. 104 */ 105 void av1_twopass_postencode_update(struct AV1_COMP *cpi); 106 107 int av1_calc_arf_boost(const TWO_PASS *twopass, 108 const TWO_PASS_FRAME *twopass_frame, 109 const PRIMARY_RATE_CONTROL *p_rc, FRAME_INFO *frame_info, 110 int offset, int f_frames, int b_frames, 111 int *num_fpstats_used, int *num_fpstats_required, 112 int project_gfu_boost); 113 #ifdef __cplusplus 114 } // extern "C" 115 #endif 116 117 #endif // AOM_AV1_ENCODER_PASS2_STRATEGY_H_ 118