• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*!\endcond */
25 /*!
26  * \brief accumulated stats and features in a gf group
27  */
28 typedef struct {
29   /*!\cond */
30   double gf_group_err;
31   double gf_group_raw_error;
32   double gf_group_skip_pct;
33   double gf_group_inactive_zone_rows;
34 
35   double mv_ratio_accumulator;
36   double decay_accumulator;
37   double zero_motion_accumulator;
38   double loop_decay_rate;
39   double last_loop_decay_rate;
40   double this_frame_mv_in_out;
41   double mv_in_out_accumulator;
42   double abs_mv_in_out_accumulator;
43 
44   double avg_sr_coded_error;
45   double avg_pcnt_second_ref;
46   double avg_new_mv_count;
47   double avg_wavelet_energy;
48   double avg_raw_err_stdev;
49   int non_zero_stdev_count;
50   /*!\endcond */
51 } GF_GROUP_STATS;
52 
53 /*!
54  * \brief accumulated stats and features for a frame
55  */
56 typedef struct {
57   /*!\cond */
58   double frame_err;
59   double frame_coded_error;
60   double frame_sr_coded_error;
61   /*!\endcond */
62 } GF_FRAME_STATS;
63 /*!cond */
64 
65 void av1_init_second_pass(struct AV1_COMP *cpi);
66 
67 void av1_init_single_pass_lap(AV1_COMP *cpi);
68 
69 /*!\endcond */
70 /*!\brief Main per frame entry point for second pass of two pass encode
71  *
72  *\ingroup rate_control
73  *
74  * This function is called for each frame in the second pass of a two pass
75  * encode. It checks the frame type and if a new KF or GF/ARF is due.
76  * When a KF is due it calls find_next_key_frame() to work out how long
77  * this key frame group will be and assign bits to the key frame.
78  * At the start of a new GF/ARF group it calls calculate_gf_length()
79  * and define_gf_group() which are the main functions responsible for
80  * defining the size and structure of the new GF/ARF group.
81  *
82  * \param[in]    cpi           Top - level encoder instance structure
83  * \param[in]    frame_params  Per frame encoding parameters
84  * \param[in]    frame_input   Current and last input frame buffers
85  * \param[in]    frame_flags   Frame type and coding flags
86  *
87  * \return No return but analyses first pass stats and assigns a target
88  *         number of bits to the current frame and a target Q range.
89  */
90 void av1_get_second_pass_params(struct AV1_COMP *cpi,
91                                 struct EncodeFrameParams *const frame_params,
92                                 const EncodeFrameInput *const frame_input,
93                                 unsigned int frame_flags);
94 
95 /*!\brief Adjustments to two pass and rate control after each frame.
96  *
97  *\ingroup rate_control
98  *
99  * This function is called after each frame to make adjustments to
100  * heuristics and data structures that relate to rate control.
101  *
102  * \param[in]    cpi       Top - level encoder instance structure
103  *
104  * \return No return value but this function updates various rate control
105  *         related data structures that for example track overshoot and
106  *         undershoot.
107  */
108 void av1_twopass_postencode_update(struct AV1_COMP *cpi);
109 
110 /*!\brief Distributes bits to frames in a group
111  *
112  *\ingroup rate_control
113  *
114  * This function decides on the allocation of bits between the different
115  * frames and types of frame in a GF/ARF group.
116  *
117  * \param[in]   cpi           Top - level encoder instance structure
118  * \param[in]   rc            Rate control data
119  * \param[in]   gf_group      GF/ARF group data structure
120  * \param[in]   is_key_frame  Indicates if the first frame in the group is
121  *                            also a key frame.
122  * \param[in]   use_arf       Are ARF frames enabled or is this a GF only
123  *                            uni-directional group.
124  * \param[in]   gf_group_bits Bits available to be allocated.
125  *
126  * \return No return but updates the rate control and group data structures
127  *         to reflect the allocation of bits.
128  */
129 void av1_gop_bit_allocation(const AV1_COMP *cpi, RATE_CONTROL *const rc,
130                             GF_GROUP *gf_group, int is_key_frame, int use_arf,
131                             int64_t gf_group_bits);
132 
133 #ifdef __cplusplus
134 }  // extern "C"
135 #endif
136 
137 #endif  // AOM_AV1_ENCODER_PASS2_STRATEGY_H_
138