1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AV1_ENCODER_FIRSTPASS_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_ENCODER_FIRSTPASS_H_
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include <stdbool.h>
16*77c1e3ccSAndroid Build Coastguard Worker
17*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/av1_common_int.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/enums.h"
19*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/lookahead.h"
20*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/ratectrl.h"
21*77c1e3ccSAndroid Build Coastguard Worker
22*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
23*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
24*77c1e3ccSAndroid Build Coastguard Worker #endif
25*77c1e3ccSAndroid Build Coastguard Worker
26*77c1e3ccSAndroid Build Coastguard Worker #define DOUBLE_DIVIDE_CHECK(x) ((x) < 0 ? (x)-0.000001 : (x) + 0.000001)
27*77c1e3ccSAndroid Build Coastguard Worker
28*77c1e3ccSAndroid Build Coastguard Worker #define MIN_ZERO_MOTION 0.95
29*77c1e3ccSAndroid Build Coastguard Worker #define MAX_SR_CODED_ERROR 40
30*77c1e3ccSAndroid Build Coastguard Worker #define MAX_RAW_ERR_VAR 2000
31*77c1e3ccSAndroid Build Coastguard Worker #define MIN_MV_IN_OUT 0.4
32*77c1e3ccSAndroid Build Coastguard Worker
33*77c1e3ccSAndroid Build Coastguard Worker #define VLOW_MOTION_THRESHOLD 950
34*77c1e3ccSAndroid Build Coastguard Worker struct ThreadData;
35*77c1e3ccSAndroid Build Coastguard Worker
36*77c1e3ccSAndroid Build Coastguard Worker /*!
37*77c1e3ccSAndroid Build Coastguard Worker * \brief The stucture of acummulated frame stats in the first pass.
38*77c1e3ccSAndroid Build Coastguard Worker *
39*77c1e3ccSAndroid Build Coastguard Worker * Errors (coded_error, intra_error, etc.) and counters (new_mv_count) are
40*77c1e3ccSAndroid Build Coastguard Worker * normalized to each MB. MV related stats (MVc, MVr, etc.) are normalized to
41*77c1e3ccSAndroid Build Coastguard Worker * the frame width and height. See function normalize_firstpass_stats.
42*77c1e3ccSAndroid Build Coastguard Worker */
43*77c1e3ccSAndroid Build Coastguard Worker typedef struct FIRSTPASS_STATS {
44*77c1e3ccSAndroid Build Coastguard Worker /*!
45*77c1e3ccSAndroid Build Coastguard Worker * Frame number in display order, if stats are for a single frame.
46*77c1e3ccSAndroid Build Coastguard Worker * No real meaning for a collection of frames.
47*77c1e3ccSAndroid Build Coastguard Worker */
48*77c1e3ccSAndroid Build Coastguard Worker double frame;
49*77c1e3ccSAndroid Build Coastguard Worker /*!
50*77c1e3ccSAndroid Build Coastguard Worker * Weight assigned to this frame (or total weight for the collection of
51*77c1e3ccSAndroid Build Coastguard Worker * frames) currently based on intra factor and brightness factor. This is used
52*77c1e3ccSAndroid Build Coastguard Worker * to distribute bits betweeen easier and harder frames.
53*77c1e3ccSAndroid Build Coastguard Worker */
54*77c1e3ccSAndroid Build Coastguard Worker double weight;
55*77c1e3ccSAndroid Build Coastguard Worker /*!
56*77c1e3ccSAndroid Build Coastguard Worker * Intra prediction error.
57*77c1e3ccSAndroid Build Coastguard Worker */
58*77c1e3ccSAndroid Build Coastguard Worker double intra_error;
59*77c1e3ccSAndroid Build Coastguard Worker /*!
60*77c1e3ccSAndroid Build Coastguard Worker * Average wavelet energy computed using Discrete Wavelet Transform (DWT).
61*77c1e3ccSAndroid Build Coastguard Worker */
62*77c1e3ccSAndroid Build Coastguard Worker double frame_avg_wavelet_energy;
63*77c1e3ccSAndroid Build Coastguard Worker /*!
64*77c1e3ccSAndroid Build Coastguard Worker * Best of intra pred error and inter pred error using last frame as ref.
65*77c1e3ccSAndroid Build Coastguard Worker */
66*77c1e3ccSAndroid Build Coastguard Worker double coded_error;
67*77c1e3ccSAndroid Build Coastguard Worker /*!
68*77c1e3ccSAndroid Build Coastguard Worker * Best of intra pred error and inter pred error using golden frame as ref.
69*77c1e3ccSAndroid Build Coastguard Worker */
70*77c1e3ccSAndroid Build Coastguard Worker double sr_coded_error;
71*77c1e3ccSAndroid Build Coastguard Worker /*!
72*77c1e3ccSAndroid Build Coastguard Worker * Percentage of blocks with inter pred error < intra pred error.
73*77c1e3ccSAndroid Build Coastguard Worker */
74*77c1e3ccSAndroid Build Coastguard Worker double pcnt_inter;
75*77c1e3ccSAndroid Build Coastguard Worker /*!
76*77c1e3ccSAndroid Build Coastguard Worker * Percentage of blocks using (inter prediction and) non-zero motion vectors.
77*77c1e3ccSAndroid Build Coastguard Worker */
78*77c1e3ccSAndroid Build Coastguard Worker double pcnt_motion;
79*77c1e3ccSAndroid Build Coastguard Worker /*!
80*77c1e3ccSAndroid Build Coastguard Worker * Percentage of blocks where golden frame was better than last or intra:
81*77c1e3ccSAndroid Build Coastguard Worker * inter pred error using golden frame < inter pred error using last frame and
82*77c1e3ccSAndroid Build Coastguard Worker * inter pred error using golden frame < intra pred error
83*77c1e3ccSAndroid Build Coastguard Worker */
84*77c1e3ccSAndroid Build Coastguard Worker double pcnt_second_ref;
85*77c1e3ccSAndroid Build Coastguard Worker /*!
86*77c1e3ccSAndroid Build Coastguard Worker * Percentage of blocks where intra and inter prediction errors were very
87*77c1e3ccSAndroid Build Coastguard Worker * close. Note that this is a 'weighted count', that is, the so blocks may be
88*77c1e3ccSAndroid Build Coastguard Worker * weighted by how close the two errors were.
89*77c1e3ccSAndroid Build Coastguard Worker */
90*77c1e3ccSAndroid Build Coastguard Worker double pcnt_neutral;
91*77c1e3ccSAndroid Build Coastguard Worker /*!
92*77c1e3ccSAndroid Build Coastguard Worker * Percentage of blocks that have almost no intra error residual
93*77c1e3ccSAndroid Build Coastguard Worker * (i.e. are in effect completely flat and untextured in the intra
94*77c1e3ccSAndroid Build Coastguard Worker * domain). In natural videos this is uncommon, but it is much more
95*77c1e3ccSAndroid Build Coastguard Worker * common in animations, graphics and screen content, so may be used
96*77c1e3ccSAndroid Build Coastguard Worker * as a signal to detect these types of content.
97*77c1e3ccSAndroid Build Coastguard Worker */
98*77c1e3ccSAndroid Build Coastguard Worker double intra_skip_pct;
99*77c1e3ccSAndroid Build Coastguard Worker /*!
100*77c1e3ccSAndroid Build Coastguard Worker * Image mask rows top and bottom.
101*77c1e3ccSAndroid Build Coastguard Worker */
102*77c1e3ccSAndroid Build Coastguard Worker double inactive_zone_rows;
103*77c1e3ccSAndroid Build Coastguard Worker /*!
104*77c1e3ccSAndroid Build Coastguard Worker * Image mask columns at left and right edges.
105*77c1e3ccSAndroid Build Coastguard Worker */
106*77c1e3ccSAndroid Build Coastguard Worker double inactive_zone_cols;
107*77c1e3ccSAndroid Build Coastguard Worker /*!
108*77c1e3ccSAndroid Build Coastguard Worker * Average of row motion vectors.
109*77c1e3ccSAndroid Build Coastguard Worker */
110*77c1e3ccSAndroid Build Coastguard Worker double MVr;
111*77c1e3ccSAndroid Build Coastguard Worker /*!
112*77c1e3ccSAndroid Build Coastguard Worker * Mean of absolute value of row motion vectors.
113*77c1e3ccSAndroid Build Coastguard Worker */
114*77c1e3ccSAndroid Build Coastguard Worker double mvr_abs;
115*77c1e3ccSAndroid Build Coastguard Worker /*!
116*77c1e3ccSAndroid Build Coastguard Worker * Mean of column motion vectors.
117*77c1e3ccSAndroid Build Coastguard Worker */
118*77c1e3ccSAndroid Build Coastguard Worker double MVc;
119*77c1e3ccSAndroid Build Coastguard Worker /*!
120*77c1e3ccSAndroid Build Coastguard Worker * Mean of absolute value of column motion vectors.
121*77c1e3ccSAndroid Build Coastguard Worker */
122*77c1e3ccSAndroid Build Coastguard Worker double mvc_abs;
123*77c1e3ccSAndroid Build Coastguard Worker /*!
124*77c1e3ccSAndroid Build Coastguard Worker * Variance of row motion vectors.
125*77c1e3ccSAndroid Build Coastguard Worker */
126*77c1e3ccSAndroid Build Coastguard Worker double MVrv;
127*77c1e3ccSAndroid Build Coastguard Worker /*!
128*77c1e3ccSAndroid Build Coastguard Worker * Variance of column motion vectors.
129*77c1e3ccSAndroid Build Coastguard Worker */
130*77c1e3ccSAndroid Build Coastguard Worker double MVcv;
131*77c1e3ccSAndroid Build Coastguard Worker /*!
132*77c1e3ccSAndroid Build Coastguard Worker * Value in range [-1,1] indicating fraction of row and column motion vectors
133*77c1e3ccSAndroid Build Coastguard Worker * that point inwards (negative MV value) or outwards (positive MV value).
134*77c1e3ccSAndroid Build Coastguard Worker * For example, value of 1 indicates, all row/column MVs are inwards.
135*77c1e3ccSAndroid Build Coastguard Worker */
136*77c1e3ccSAndroid Build Coastguard Worker double mv_in_out_count;
137*77c1e3ccSAndroid Build Coastguard Worker /*!
138*77c1e3ccSAndroid Build Coastguard Worker * Count of unique non-zero motion vectors.
139*77c1e3ccSAndroid Build Coastguard Worker */
140*77c1e3ccSAndroid Build Coastguard Worker double new_mv_count;
141*77c1e3ccSAndroid Build Coastguard Worker /*!
142*77c1e3ccSAndroid Build Coastguard Worker * Duration of the frame / collection of frames.
143*77c1e3ccSAndroid Build Coastguard Worker */
144*77c1e3ccSAndroid Build Coastguard Worker double duration;
145*77c1e3ccSAndroid Build Coastguard Worker /*!
146*77c1e3ccSAndroid Build Coastguard Worker * 1.0 if stats are for a single frame, OR
147*77c1e3ccSAndroid Build Coastguard Worker * Number of frames in this collection for which the stats are accumulated.
148*77c1e3ccSAndroid Build Coastguard Worker */
149*77c1e3ccSAndroid Build Coastguard Worker double count;
150*77c1e3ccSAndroid Build Coastguard Worker /*!
151*77c1e3ccSAndroid Build Coastguard Worker * standard deviation for (0, 0) motion prediction error
152*77c1e3ccSAndroid Build Coastguard Worker */
153*77c1e3ccSAndroid Build Coastguard Worker double raw_error_stdev;
154*77c1e3ccSAndroid Build Coastguard Worker /*!
155*77c1e3ccSAndroid Build Coastguard Worker * Whether the frame contains a flash
156*77c1e3ccSAndroid Build Coastguard Worker */
157*77c1e3ccSAndroid Build Coastguard Worker int64_t is_flash;
158*77c1e3ccSAndroid Build Coastguard Worker /*!
159*77c1e3ccSAndroid Build Coastguard Worker * Estimated noise variance
160*77c1e3ccSAndroid Build Coastguard Worker */
161*77c1e3ccSAndroid Build Coastguard Worker double noise_var;
162*77c1e3ccSAndroid Build Coastguard Worker /*!
163*77c1e3ccSAndroid Build Coastguard Worker * Correlation coefficient with the previous frame
164*77c1e3ccSAndroid Build Coastguard Worker */
165*77c1e3ccSAndroid Build Coastguard Worker double cor_coeff;
166*77c1e3ccSAndroid Build Coastguard Worker /*!
167*77c1e3ccSAndroid Build Coastguard Worker * log of intra_error
168*77c1e3ccSAndroid Build Coastguard Worker */
169*77c1e3ccSAndroid Build Coastguard Worker double log_intra_error;
170*77c1e3ccSAndroid Build Coastguard Worker /*!
171*77c1e3ccSAndroid Build Coastguard Worker * log of coded_error
172*77c1e3ccSAndroid Build Coastguard Worker */
173*77c1e3ccSAndroid Build Coastguard Worker double log_coded_error;
174*77c1e3ccSAndroid Build Coastguard Worker } FIRSTPASS_STATS;
175*77c1e3ccSAndroid Build Coastguard Worker
176*77c1e3ccSAndroid Build Coastguard Worker // We want to keep one past stats for key frame detection
177*77c1e3ccSAndroid Build Coastguard Worker // in test_candidate_kf()
178*77c1e3ccSAndroid Build Coastguard Worker #define FIRSTPASS_INFO_STATS_PAST_MIN 1
179*77c1e3ccSAndroid Build Coastguard Worker
180*77c1e3ccSAndroid Build Coastguard Worker // The size of static buffer used in FIRSTPASS_INFO.
181*77c1e3ccSAndroid Build Coastguard Worker #define FIRSTPASS_INFO_STATIC_BUF_SIZE \
182*77c1e3ccSAndroid Build Coastguard Worker (MAX_LAP_BUFFERS + FIRSTPASS_INFO_STATS_PAST_MIN)
183*77c1e3ccSAndroid Build Coastguard Worker
184*77c1e3ccSAndroid Build Coastguard Worker /*!
185*77c1e3ccSAndroid Build Coastguard Worker * \brief Data structure used for managing first pass stats
186*77c1e3ccSAndroid Build Coastguard Worker */
187*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
188*77c1e3ccSAndroid Build Coastguard Worker /*!
189*77c1e3ccSAndroid Build Coastguard Worker * A static buffer that will be used when no ext_stats_buf is assigned. The
190*77c1e3ccSAndroid Build Coastguard Worker * ext_stats_buf is assigned through av1_firstpass_info_init() when the user
191*77c1e3ccSAndroid Build Coastguard Worker * already has a pre-existing firstpass stats that is stored in an external
192*77c1e3ccSAndroid Build Coastguard Worker * buffer. The ext_stats_buf is usually used in two pass mode. When using one
193*77c1e3ccSAndroid Build Coastguard Worker * pass mode, we generate "firstpass" stats and encode the video in the same
194*77c1e3ccSAndroid Build Coastguard Worker * pass. In this scenario, the stats will be pushed and popped from
195*77c1e3ccSAndroid Build Coastguard Worker * static_stats_buf.
196*77c1e3ccSAndroid Build Coastguard Worker */
197*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS static_stats_buf[FIRSTPASS_INFO_STATIC_BUF_SIZE];
198*77c1e3ccSAndroid Build Coastguard Worker /*!
199*77c1e3ccSAndroid Build Coastguard Worker * A pointer to first pass stats.
200*77c1e3ccSAndroid Build Coastguard Worker * Note that this buffer will be used as ring buffer.
201*77c1e3ccSAndroid Build Coastguard Worker */
202*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS *stats_buf;
203*77c1e3ccSAndroid Build Coastguard Worker /*!
204*77c1e3ccSAndroid Build Coastguard Worker * size of stats_buf
205*77c1e3ccSAndroid Build Coastguard Worker */
206*77c1e3ccSAndroid Build Coastguard Worker int stats_buf_size;
207*77c1e3ccSAndroid Build Coastguard Worker /*!
208*77c1e3ccSAndroid Build Coastguard Worker * start index of the available frame stats
209*77c1e3ccSAndroid Build Coastguard Worker * Note that start_index doesn't always point to
210*77c1e3ccSAndroid Build Coastguard Worker * current frame's stats because we need to
211*77c1e3ccSAndroid Build Coastguard Worker * keep past stats as well. To access current
212*77c1e3ccSAndroid Build Coastguard Worker * frame's stats, please use cur_index.
213*77c1e3ccSAndroid Build Coastguard Worker */
214*77c1e3ccSAndroid Build Coastguard Worker int start_index;
215*77c1e3ccSAndroid Build Coastguard Worker
216*77c1e3ccSAndroid Build Coastguard Worker /*!
217*77c1e3ccSAndroid Build Coastguard Worker * count available stats stored in stats_buf
218*77c1e3ccSAndroid Build Coastguard Worker * the following condition should stay true
219*77c1e3ccSAndroid Build Coastguard Worker * stats_count = future_stats_count + past_stats_count
220*77c1e3ccSAndroid Build Coastguard Worker */
221*77c1e3ccSAndroid Build Coastguard Worker int stats_count;
222*77c1e3ccSAndroid Build Coastguard Worker
223*77c1e3ccSAndroid Build Coastguard Worker /*!
224*77c1e3ccSAndroid Build Coastguard Worker * index of the current frame's stats
225*77c1e3ccSAndroid Build Coastguard Worker */
226*77c1e3ccSAndroid Build Coastguard Worker int cur_index;
227*77c1e3ccSAndroid Build Coastguard Worker
228*77c1e3ccSAndroid Build Coastguard Worker /*!
229*77c1e3ccSAndroid Build Coastguard Worker * count available future stats including current stats
230*77c1e3ccSAndroid Build Coastguard Worker */
231*77c1e3ccSAndroid Build Coastguard Worker int future_stats_count;
232*77c1e3ccSAndroid Build Coastguard Worker
233*77c1e3ccSAndroid Build Coastguard Worker /*!
234*77c1e3ccSAndroid Build Coastguard Worker * count available past stats EXCLUDING current stats
235*77c1e3ccSAndroid Build Coastguard Worker */
236*77c1e3ccSAndroid Build Coastguard Worker int past_stats_count;
237*77c1e3ccSAndroid Build Coastguard Worker
238*77c1e3ccSAndroid Build Coastguard Worker /*!
239*77c1e3ccSAndroid Build Coastguard Worker * Accumulation of the stats being pushed into firstpass_info
240*77c1e3ccSAndroid Build Coastguard Worker */
241*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS total_stats;
242*77c1e3ccSAndroid Build Coastguard Worker } FIRSTPASS_INFO;
243*77c1e3ccSAndroid Build Coastguard Worker
244*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Init firstpass_info
245*77c1e3ccSAndroid Build Coastguard Worker *
246*77c1e3ccSAndroid Build Coastguard Worker * If using ext_stats_buf, the buffer needs to stay available during encoding
247*77c1e3ccSAndroid Build Coastguard Worker * process.
248*77c1e3ccSAndroid Build Coastguard Worker *
249*77c1e3ccSAndroid Build Coastguard Worker * \ingroup rate_control
250*77c1e3ccSAndroid Build Coastguard Worker * \param[out] firstpass_info struct of firstpass_info.
251*77c1e3ccSAndroid Build Coastguard Worker * \param[in] ext_stats_buf external stats buffer. Pass in NULL if
252*77c1e3ccSAndroid Build Coastguard Worker * choose to use internal static_stats_buf.
253*77c1e3ccSAndroid Build Coastguard Worker * \param[in] ext_stats_buf_size external stats buffer size. Pass in 0 if
254*77c1e3ccSAndroid Build Coastguard Worker * choose to use internal static_stats_buf. \return status
255*77c1e3ccSAndroid Build Coastguard Worker */
256*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t av1_firstpass_info_init(FIRSTPASS_INFO *firstpass_info,
257*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS *ext_stats_buf,
258*77c1e3ccSAndroid Build Coastguard Worker int ext_stats_buf_size);
259*77c1e3ccSAndroid Build Coastguard Worker
260*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Move cur_index by 1
261*77c1e3ccSAndroid Build Coastguard Worker *
262*77c1e3ccSAndroid Build Coastguard Worker * \ingroup rate_control
263*77c1e3ccSAndroid Build Coastguard Worker * \param[out] firstpass_info struct of firstpass_info.
264*77c1e3ccSAndroid Build Coastguard Worker * \return status
265*77c1e3ccSAndroid Build Coastguard Worker */
266*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t av1_firstpass_info_move_cur_index(
267*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_INFO *firstpass_info);
268*77c1e3ccSAndroid Build Coastguard Worker
269*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Pop a stats from firstpass_info
270*77c1e3ccSAndroid Build Coastguard Worker *
271*77c1e3ccSAndroid Build Coastguard Worker * \ingroup rate_control
272*77c1e3ccSAndroid Build Coastguard Worker * \param[out] firstpass_info struct of firstpass_info.
273*77c1e3ccSAndroid Build Coastguard Worker * \return status
274*77c1e3ccSAndroid Build Coastguard Worker */
275*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t av1_firstpass_info_pop(FIRSTPASS_INFO *firstpass_info);
276*77c1e3ccSAndroid Build Coastguard Worker
277*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Move cur_index by 1 and pop a stats from firstpass_info
278*77c1e3ccSAndroid Build Coastguard Worker *
279*77c1e3ccSAndroid Build Coastguard Worker * \ingroup rate_control
280*77c1e3ccSAndroid Build Coastguard Worker * \param[out] firstpass_info struct of firstpass_info.
281*77c1e3ccSAndroid Build Coastguard Worker * \return status
282*77c1e3ccSAndroid Build Coastguard Worker */
283*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t av1_firstpass_info_move_cur_index_and_pop(
284*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_INFO *firstpass_info);
285*77c1e3ccSAndroid Build Coastguard Worker
286*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Push a stats into firstpass_info
287*77c1e3ccSAndroid Build Coastguard Worker *
288*77c1e3ccSAndroid Build Coastguard Worker * Note that the input stats will be copied into firstpass_info.
289*77c1e3ccSAndroid Build Coastguard Worker * \ingroup rate_control
290*77c1e3ccSAndroid Build Coastguard Worker * \param[out] firstpass_info struct of firstpass_info.
291*77c1e3ccSAndroid Build Coastguard Worker * \param[in] input_stats input stats
292*77c1e3ccSAndroid Build Coastguard Worker * \return status
293*77c1e3ccSAndroid Build Coastguard Worker */
294*77c1e3ccSAndroid Build Coastguard Worker aom_codec_err_t av1_firstpass_info_push(FIRSTPASS_INFO *firstpass_info,
295*77c1e3ccSAndroid Build Coastguard Worker const FIRSTPASS_STATS *input_stats);
296*77c1e3ccSAndroid Build Coastguard Worker
297*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Peek at a stats from firstpass_info
298*77c1e3ccSAndroid Build Coastguard Worker *
299*77c1e3ccSAndroid Build Coastguard Worker * The target index is as follows.
300*77c1e3ccSAndroid Build Coastguard Worker * (cur_index + offset_from_cur) % firstpass_info->stats_buf_size
301*77c1e3ccSAndroid Build Coastguard Worker *
302*77c1e3ccSAndroid Build Coastguard Worker * \ingroup rate_control
303*77c1e3ccSAndroid Build Coastguard Worker * \param[in] firstpass_info struct of firstpass_info.
304*77c1e3ccSAndroid Build Coastguard Worker * \param[in] offset_from_cur index offset from cur_index.
305*77c1e3ccSAndroid Build Coastguard Worker * \return pointer to the stats. The pointer will be NULL if
306*77c1e3ccSAndroid Build Coastguard Worker * stats_index_offset is invalid.
307*77c1e3ccSAndroid Build Coastguard Worker */
308*77c1e3ccSAndroid Build Coastguard Worker const FIRSTPASS_STATS *av1_firstpass_info_peek(
309*77c1e3ccSAndroid Build Coastguard Worker const FIRSTPASS_INFO *firstpass_info, int offset_from_cur);
310*77c1e3ccSAndroid Build Coastguard Worker
311*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Count the future stats from the target in firstpass_info
312*77c1e3ccSAndroid Build Coastguard Worker * Note that the target stats will be counted as well.
313*77c1e3ccSAndroid Build Coastguard Worker * The target index is as follows.
314*77c1e3ccSAndroid Build Coastguard Worker * (cur_index + offset_from_cur) % firstpass_info->stats_buf_size
315*77c1e3ccSAndroid Build Coastguard Worker *
316*77c1e3ccSAndroid Build Coastguard Worker * \ingroup rate_control
317*77c1e3ccSAndroid Build Coastguard Worker * \param[in] firstpass_info struct of firstpass_info.
318*77c1e3ccSAndroid Build Coastguard Worker * \param[in] offset_from_cur target stats's inffset
319*77c1e3ccSAndroid Build Coastguard Worker * from cur_index.
320*77c1e3ccSAndroid Build Coastguard Worker * \return Number of stats in the future after the target stats
321*77c1e3ccSAndroid Build Coastguard Worker * including itself.
322*77c1e3ccSAndroid Build Coastguard Worker */
323*77c1e3ccSAndroid Build Coastguard Worker int av1_firstpass_info_future_count(const FIRSTPASS_INFO *firstpass_info,
324*77c1e3ccSAndroid Build Coastguard Worker int offset_from_cur);
325*77c1e3ccSAndroid Build Coastguard Worker
326*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
327*77c1e3ccSAndroid Build Coastguard Worker #define FC_ANIMATION_THRESH 0.15
328*77c1e3ccSAndroid Build Coastguard Worker enum {
329*77c1e3ccSAndroid Build Coastguard Worker FC_NORMAL = 0,
330*77c1e3ccSAndroid Build Coastguard Worker FC_GRAPHICS_ANIMATION = 1,
331*77c1e3ccSAndroid Build Coastguard Worker FRAME_CONTENT_TYPES = 2
332*77c1e3ccSAndroid Build Coastguard Worker } UENUM1BYTE(FRAME_CONTENT_TYPE);
333*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
334*77c1e3ccSAndroid Build Coastguard Worker
335*77c1e3ccSAndroid Build Coastguard Worker /*!
336*77c1e3ccSAndroid Build Coastguard Worker * \brief Data related to the current GF/ARF group and the
337*77c1e3ccSAndroid Build Coastguard Worker * individual frames within the group
338*77c1e3ccSAndroid Build Coastguard Worker */
339*77c1e3ccSAndroid Build Coastguard Worker typedef struct GF_GROUP {
340*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
341*77c1e3ccSAndroid Build Coastguard Worker // Frame update type, e.g. ARF/GF/LF/Overlay
342*77c1e3ccSAndroid Build Coastguard Worker FRAME_UPDATE_TYPE update_type[MAX_STATIC_GF_GROUP_LENGTH];
343*77c1e3ccSAndroid Build Coastguard Worker unsigned char arf_src_offset[MAX_STATIC_GF_GROUP_LENGTH];
344*77c1e3ccSAndroid Build Coastguard Worker // The number of frames displayed so far within the GOP at a given coding
345*77c1e3ccSAndroid Build Coastguard Worker // frame.
346*77c1e3ccSAndroid Build Coastguard Worker unsigned char cur_frame_idx[MAX_STATIC_GF_GROUP_LENGTH];
347*77c1e3ccSAndroid Build Coastguard Worker int layer_depth[MAX_STATIC_GF_GROUP_LENGTH];
348*77c1e3ccSAndroid Build Coastguard Worker int arf_boost[MAX_STATIC_GF_GROUP_LENGTH];
349*77c1e3ccSAndroid Build Coastguard Worker int max_layer_depth;
350*77c1e3ccSAndroid Build Coastguard Worker int max_layer_depth_allowed;
351*77c1e3ccSAndroid Build Coastguard Worker // This is currently only populated for AOM_Q mode
352*77c1e3ccSAndroid Build Coastguard Worker int q_val[MAX_STATIC_GF_GROUP_LENGTH];
353*77c1e3ccSAndroid Build Coastguard Worker int rdmult_val[MAX_STATIC_GF_GROUP_LENGTH];
354*77c1e3ccSAndroid Build Coastguard Worker int bit_allocation[MAX_STATIC_GF_GROUP_LENGTH];
355*77c1e3ccSAndroid Build Coastguard Worker // The frame coding type - inter/intra frame
356*77c1e3ccSAndroid Build Coastguard Worker FRAME_TYPE frame_type[MAX_STATIC_GF_GROUP_LENGTH];
357*77c1e3ccSAndroid Build Coastguard Worker // The reference frame buffer control - update or reset
358*77c1e3ccSAndroid Build Coastguard Worker REFBUF_STATE refbuf_state[MAX_STATIC_GF_GROUP_LENGTH];
359*77c1e3ccSAndroid Build Coastguard Worker int arf_index; // the index in the gf group of ARF, if no arf, then -1
360*77c1e3ccSAndroid Build Coastguard Worker int size; // The total length of a GOP
361*77c1e3ccSAndroid Build Coastguard Worker
362*77c1e3ccSAndroid Build Coastguard Worker // The offset into lookahead_ctx for choosing
363*77c1e3ccSAndroid Build Coastguard Worker // source of frame parallel encodes.
364*77c1e3ccSAndroid Build Coastguard Worker int src_offset[MAX_STATIC_GF_GROUP_LENGTH];
365*77c1e3ccSAndroid Build Coastguard Worker // Stores the display order hint of each frame in the current GF_GROUP.
366*77c1e3ccSAndroid Build Coastguard Worker int display_idx[MAX_STATIC_GF_GROUP_LENGTH];
367*77c1e3ccSAndroid Build Coastguard Worker
368*77c1e3ccSAndroid Build Coastguard Worker // The reference frame list maps the reference frame indexes to its
369*77c1e3ccSAndroid Build Coastguard Worker // buffer index in the decoded buffer. A value of -1 means the
370*77c1e3ccSAndroid Build Coastguard Worker // corresponding reference frame index doesn't point towards any
371*77c1e3ccSAndroid Build Coastguard Worker // previously decoded frame.
372*77c1e3ccSAndroid Build Coastguard Worker int8_t ref_frame_list[MAX_STATIC_GF_GROUP_LENGTH][REF_FRAMES];
373*77c1e3ccSAndroid Build Coastguard Worker // Update frame index
374*77c1e3ccSAndroid Build Coastguard Worker int update_ref_idx[MAX_STATIC_GF_GROUP_LENGTH];
375*77c1e3ccSAndroid Build Coastguard Worker // The map_idx of primary reference
376*77c1e3ccSAndroid Build Coastguard Worker int primary_ref_idx[MAX_STATIC_GF_GROUP_LENGTH];
377*77c1e3ccSAndroid Build Coastguard Worker
378*77c1e3ccSAndroid Build Coastguard Worker // Indicates the level of parallelism in frame parallel encodes.
379*77c1e3ccSAndroid Build Coastguard Worker // 0 : frame is independently encoded (not part of parallel encodes).
380*77c1e3ccSAndroid Build Coastguard Worker // 1 : frame is the first in encode order in a given parallel encode set.
381*77c1e3ccSAndroid Build Coastguard Worker // 2 : frame occurs later in encode order in a given parallel encode set.
382*77c1e3ccSAndroid Build Coastguard Worker int frame_parallel_level[MAX_STATIC_GF_GROUP_LENGTH];
383*77c1e3ccSAndroid Build Coastguard Worker // Indicates whether a frame should act as non-reference frame.
384*77c1e3ccSAndroid Build Coastguard Worker bool is_frame_non_ref[MAX_STATIC_GF_GROUP_LENGTH];
385*77c1e3ccSAndroid Build Coastguard Worker // Indicates whether a frame is dropped.
386*77c1e3ccSAndroid Build Coastguard Worker bool is_frame_dropped[MAX_STATIC_GF_GROUP_LENGTH];
387*77c1e3ccSAndroid Build Coastguard Worker
388*77c1e3ccSAndroid Build Coastguard Worker // Stores the display order hint of the frames not to be
389*77c1e3ccSAndroid Build Coastguard Worker // refreshed by the current frame.
390*77c1e3ccSAndroid Build Coastguard Worker int skip_frame_refresh[MAX_STATIC_GF_GROUP_LENGTH][REF_FRAMES];
391*77c1e3ccSAndroid Build Coastguard Worker // Stores the display order hint of the frame to be excluded during reference
392*77c1e3ccSAndroid Build Coastguard Worker // assignment.
393*77c1e3ccSAndroid Build Coastguard Worker int skip_frame_as_ref[MAX_STATIC_GF_GROUP_LENGTH];
394*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
395*77c1e3ccSAndroid Build Coastguard Worker } GF_GROUP;
396*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
397*77c1e3ccSAndroid Build Coastguard Worker
398*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
399*77c1e3ccSAndroid Build Coastguard Worker // Track if the last frame in a GOP has higher quality.
400*77c1e3ccSAndroid Build Coastguard Worker int arf_gf_boost_lst;
401*77c1e3ccSAndroid Build Coastguard Worker } GF_STATE;
402*77c1e3ccSAndroid Build Coastguard Worker
403*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
404*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS *stats_in_start;
405*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS *stats_in_end;
406*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS *stats_in_buf_end;
407*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS *total_stats;
408*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS *total_left_stats;
409*77c1e3ccSAndroid Build Coastguard Worker } STATS_BUFFER_CTX;
410*77c1e3ccSAndroid Build Coastguard Worker
411*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
412*77c1e3ccSAndroid Build Coastguard Worker
413*77c1e3ccSAndroid Build Coastguard Worker /*!
414*77c1e3ccSAndroid Build Coastguard Worker * \brief Two pass status and control data.
415*77c1e3ccSAndroid Build Coastguard Worker */
416*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
417*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
418*77c1e3ccSAndroid Build Coastguard Worker unsigned int section_intra_rating;
419*77c1e3ccSAndroid Build Coastguard Worker // Circular queue of first pass stats stored for most recent frames.
420*77c1e3ccSAndroid Build Coastguard Worker // cpi->output_pkt_list[i].data.twopass_stats.buf points to actual data stored
421*77c1e3ccSAndroid Build Coastguard Worker // here.
422*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_STATS *frame_stats_arr[MAX_LAP_BUFFERS + 1];
423*77c1e3ccSAndroid Build Coastguard Worker int frame_stats_next_idx; // Index to next unused element in frame_stats_arr.
424*77c1e3ccSAndroid Build Coastguard Worker STATS_BUFFER_CTX *stats_buf_ctx;
425*77c1e3ccSAndroid Build Coastguard Worker FIRSTPASS_INFO firstpass_info; // This is the first pass data structure
426*77c1e3ccSAndroid Build Coastguard Worker // intended to replace stats_in
427*77c1e3ccSAndroid Build Coastguard Worker int first_pass_done;
428*77c1e3ccSAndroid Build Coastguard Worker int64_t bits_left;
429*77c1e3ccSAndroid Build Coastguard Worker double modified_error_min;
430*77c1e3ccSAndroid Build Coastguard Worker double modified_error_max;
431*77c1e3ccSAndroid Build Coastguard Worker double modified_error_left;
432*77c1e3ccSAndroid Build Coastguard Worker
433*77c1e3ccSAndroid Build Coastguard Worker // Projected total bits available for a key frame group of frames
434*77c1e3ccSAndroid Build Coastguard Worker int64_t kf_group_bits;
435*77c1e3ccSAndroid Build Coastguard Worker
436*77c1e3ccSAndroid Build Coastguard Worker // Error score of frames still to be coded in kf group
437*77c1e3ccSAndroid Build Coastguard Worker double kf_group_error_left;
438*77c1e3ccSAndroid Build Coastguard Worker
439*77c1e3ccSAndroid Build Coastguard Worker // Over time correction for bits per macro block estimation
440*77c1e3ccSAndroid Build Coastguard Worker double bpm_factor;
441*77c1e3ccSAndroid Build Coastguard Worker
442*77c1e3ccSAndroid Build Coastguard Worker // Record of target and actual bits spent in current ARF group
443*77c1e3ccSAndroid Build Coastguard Worker int rolling_arf_group_target_bits;
444*77c1e3ccSAndroid Build Coastguard Worker int rolling_arf_group_actual_bits;
445*77c1e3ccSAndroid Build Coastguard Worker
446*77c1e3ccSAndroid Build Coastguard Worker int sr_update_lag;
447*77c1e3ccSAndroid Build Coastguard Worker
448*77c1e3ccSAndroid Build Coastguard Worker int kf_zeromotion_pct;
449*77c1e3ccSAndroid Build Coastguard Worker int last_kfgroup_zeromotion_pct;
450*77c1e3ccSAndroid Build Coastguard Worker int extend_minq;
451*77c1e3ccSAndroid Build Coastguard Worker int extend_maxq;
452*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
453*77c1e3ccSAndroid Build Coastguard Worker } TWO_PASS;
454*77c1e3ccSAndroid Build Coastguard Worker
455*77c1e3ccSAndroid Build Coastguard Worker /*!
456*77c1e3ccSAndroid Build Coastguard Worker * \brief Frame level Two pass status and control data.
457*77c1e3ccSAndroid Build Coastguard Worker */
458*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
459*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
460*77c1e3ccSAndroid Build Coastguard Worker const FIRSTPASS_STATS *stats_in;
461*77c1e3ccSAndroid Build Coastguard Worker // Pointer to the stats of the current frame.
462*77c1e3ccSAndroid Build Coastguard Worker const FIRSTPASS_STATS *this_frame;
463*77c1e3ccSAndroid Build Coastguard Worker double mb_av_energy;
464*77c1e3ccSAndroid Build Coastguard Worker // An indication of the content type of the current frame
465*77c1e3ccSAndroid Build Coastguard Worker FRAME_CONTENT_TYPE fr_content_type;
466*77c1e3ccSAndroid Build Coastguard Worker double frame_avg_haar_energy;
467*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
468*77c1e3ccSAndroid Build Coastguard Worker } TWO_PASS_FRAME;
469*77c1e3ccSAndroid Build Coastguard Worker
470*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
471*77c1e3ccSAndroid Build Coastguard Worker
472*77c1e3ccSAndroid Build Coastguard Worker // This structure contains several key parameters to be accumulated for this
473*77c1e3ccSAndroid Build Coastguard Worker // frame.
474*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
475*77c1e3ccSAndroid Build Coastguard Worker // Intra prediction error.
476*77c1e3ccSAndroid Build Coastguard Worker int64_t intra_error;
477*77c1e3ccSAndroid Build Coastguard Worker // Average wavelet energy computed using Discrete Wavelet Transform (DWT).
478*77c1e3ccSAndroid Build Coastguard Worker int64_t frame_avg_wavelet_energy;
479*77c1e3ccSAndroid Build Coastguard Worker // Best of intra pred error and inter pred error using last frame as ref.
480*77c1e3ccSAndroid Build Coastguard Worker int64_t coded_error;
481*77c1e3ccSAndroid Build Coastguard Worker // Best of intra pred error and inter pred error using golden frame as ref.
482*77c1e3ccSAndroid Build Coastguard Worker int64_t sr_coded_error;
483*77c1e3ccSAndroid Build Coastguard Worker // Count of motion vector.
484*77c1e3ccSAndroid Build Coastguard Worker int mv_count;
485*77c1e3ccSAndroid Build Coastguard Worker // Count of blocks that pick inter prediction (inter pred error is smaller
486*77c1e3ccSAndroid Build Coastguard Worker // than intra pred error).
487*77c1e3ccSAndroid Build Coastguard Worker int inter_count;
488*77c1e3ccSAndroid Build Coastguard Worker // Count of blocks that pick second ref (golden frame).
489*77c1e3ccSAndroid Build Coastguard Worker int second_ref_count;
490*77c1e3ccSAndroid Build Coastguard Worker // Count of blocks where the inter and intra are very close and very low.
491*77c1e3ccSAndroid Build Coastguard Worker double neutral_count;
492*77c1e3ccSAndroid Build Coastguard Worker // Count of blocks where intra error is very small.
493*77c1e3ccSAndroid Build Coastguard Worker int intra_skip_count;
494*77c1e3ccSAndroid Build Coastguard Worker // Start row.
495*77c1e3ccSAndroid Build Coastguard Worker int image_data_start_row;
496*77c1e3ccSAndroid Build Coastguard Worker // Count of unique non-zero motion vectors.
497*77c1e3ccSAndroid Build Coastguard Worker int new_mv_count;
498*77c1e3ccSAndroid Build Coastguard Worker // Sum of inward motion vectors.
499*77c1e3ccSAndroid Build Coastguard Worker int sum_in_vectors;
500*77c1e3ccSAndroid Build Coastguard Worker // Sum of motion vector row.
501*77c1e3ccSAndroid Build Coastguard Worker int sum_mvr;
502*77c1e3ccSAndroid Build Coastguard Worker // Sum of motion vector column.
503*77c1e3ccSAndroid Build Coastguard Worker int sum_mvc;
504*77c1e3ccSAndroid Build Coastguard Worker // Sum of absolute value of motion vector row.
505*77c1e3ccSAndroid Build Coastguard Worker int sum_mvr_abs;
506*77c1e3ccSAndroid Build Coastguard Worker // Sum of absolute value of motion vector column.
507*77c1e3ccSAndroid Build Coastguard Worker int sum_mvc_abs;
508*77c1e3ccSAndroid Build Coastguard Worker // Sum of the square of motion vector row.
509*77c1e3ccSAndroid Build Coastguard Worker int64_t sum_mvrs;
510*77c1e3ccSAndroid Build Coastguard Worker // Sum of the square of motion vector column.
511*77c1e3ccSAndroid Build Coastguard Worker int64_t sum_mvcs;
512*77c1e3ccSAndroid Build Coastguard Worker // A factor calculated using intra pred error.
513*77c1e3ccSAndroid Build Coastguard Worker double intra_factor;
514*77c1e3ccSAndroid Build Coastguard Worker // A factor that measures brightness.
515*77c1e3ccSAndroid Build Coastguard Worker double brightness_factor;
516*77c1e3ccSAndroid Build Coastguard Worker } FRAME_STATS;
517*77c1e3ccSAndroid Build Coastguard Worker
518*77c1e3ccSAndroid Build Coastguard Worker // This structure contains first pass data.
519*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
520*77c1e3ccSAndroid Build Coastguard Worker // Buffer holding frame stats for all MACROBLOCKs.
521*77c1e3ccSAndroid Build Coastguard Worker // mb_stats[i] stores the FRAME_STATS of the ith
522*77c1e3ccSAndroid Build Coastguard Worker // MB in raster scan order.
523*77c1e3ccSAndroid Build Coastguard Worker FRAME_STATS *mb_stats;
524*77c1e3ccSAndroid Build Coastguard Worker // Buffer to store the prediction error of the (0,0) motion
525*77c1e3ccSAndroid Build Coastguard Worker // vector using the last source frame as the reference.
526*77c1e3ccSAndroid Build Coastguard Worker // raw_motion_err_list[i] stores the raw_motion_err of
527*77c1e3ccSAndroid Build Coastguard Worker // the ith MB in raster scan order.
528*77c1e3ccSAndroid Build Coastguard Worker int *raw_motion_err_list;
529*77c1e3ccSAndroid Build Coastguard Worker } FirstPassData;
530*77c1e3ccSAndroid Build Coastguard Worker
531*77c1e3ccSAndroid Build Coastguard Worker struct AV1_COMP;
532*77c1e3ccSAndroid Build Coastguard Worker struct EncodeFrameParams;
533*77c1e3ccSAndroid Build Coastguard Worker struct AV1EncoderConfig;
534*77c1e3ccSAndroid Build Coastguard Worker struct TileDataEnc;
535*77c1e3ccSAndroid Build Coastguard Worker
is_fp_wavelet_energy_invalid(const FIRSTPASS_STATS * fp_stats)536*77c1e3ccSAndroid Build Coastguard Worker static inline int is_fp_wavelet_energy_invalid(
537*77c1e3ccSAndroid Build Coastguard Worker const FIRSTPASS_STATS *fp_stats) {
538*77c1e3ccSAndroid Build Coastguard Worker assert(fp_stats != NULL);
539*77c1e3ccSAndroid Build Coastguard Worker return (fp_stats->frame_avg_wavelet_energy < 0);
540*77c1e3ccSAndroid Build Coastguard Worker }
541*77c1e3ccSAndroid Build Coastguard Worker
get_fp_block_size(int is_screen_content_type)542*77c1e3ccSAndroid Build Coastguard Worker static inline BLOCK_SIZE get_fp_block_size(int is_screen_content_type) {
543*77c1e3ccSAndroid Build Coastguard Worker return (is_screen_content_type ? BLOCK_8X8 : BLOCK_16X16);
544*77c1e3ccSAndroid Build Coastguard Worker }
545*77c1e3ccSAndroid Build Coastguard Worker
546*77c1e3ccSAndroid Build Coastguard Worker int av1_get_unit_rows_in_tile(const TileInfo *tile,
547*77c1e3ccSAndroid Build Coastguard Worker const BLOCK_SIZE fp_block_size);
548*77c1e3ccSAndroid Build Coastguard Worker int av1_get_unit_cols_in_tile(const TileInfo *tile,
549*77c1e3ccSAndroid Build Coastguard Worker const BLOCK_SIZE fp_block_size);
550*77c1e3ccSAndroid Build Coastguard Worker
551*77c1e3ccSAndroid Build Coastguard Worker void av1_first_pass_row(struct AV1_COMP *cpi, struct ThreadData *td,
552*77c1e3ccSAndroid Build Coastguard Worker struct TileDataEnc *tile_data, const int mb_row,
553*77c1e3ccSAndroid Build Coastguard Worker const BLOCK_SIZE fp_block_size);
554*77c1e3ccSAndroid Build Coastguard Worker void av1_end_first_pass(struct AV1_COMP *cpi);
555*77c1e3ccSAndroid Build Coastguard Worker
556*77c1e3ccSAndroid Build Coastguard Worker void av1_free_firstpass_data(FirstPassData *firstpass_data);
557*77c1e3ccSAndroid Build Coastguard Worker
558*77c1e3ccSAndroid Build Coastguard Worker void av1_twopass_zero_stats(FIRSTPASS_STATS *section);
559*77c1e3ccSAndroid Build Coastguard Worker void av1_accumulate_stats(FIRSTPASS_STATS *section,
560*77c1e3ccSAndroid Build Coastguard Worker const FIRSTPASS_STATS *frame);
561*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
562*77c1e3ccSAndroid Build Coastguard Worker
563*77c1e3ccSAndroid Build Coastguard Worker /*!\brief AV1 first pass encoding.
564*77c1e3ccSAndroid Build Coastguard Worker *
565*77c1e3ccSAndroid Build Coastguard Worker * \ingroup rate_control
566*77c1e3ccSAndroid Build Coastguard Worker * This function is the first encoding pass for the two pass encoding mode.
567*77c1e3ccSAndroid Build Coastguard Worker * It encodes the whole video and collect essential information.
568*77c1e3ccSAndroid Build Coastguard Worker * Two pass encoding is an encoding mode in the reference software (libaom)
569*77c1e3ccSAndroid Build Coastguard Worker * of AV1 for high performance encoding. The first pass is a fast encoding
570*77c1e3ccSAndroid Build Coastguard Worker * process to collect essential information to help the second pass make
571*77c1e3ccSAndroid Build Coastguard Worker * encoding decisions and improve coding quality. The collected stats is used
572*77c1e3ccSAndroid Build Coastguard Worker * in rate control, for example, to determine frame cut, the position of
573*77c1e3ccSAndroid Build Coastguard Worker * alternative reference frame (ARF), etc.
574*77c1e3ccSAndroid Build Coastguard Worker *
575*77c1e3ccSAndroid Build Coastguard Worker * \param[in] cpi Top-level encoder structure
576*77c1e3ccSAndroid Build Coastguard Worker * \param[in] ts_duration Duration of the frame / collection of frames
577*77c1e3ccSAndroid Build Coastguard Worker *
578*77c1e3ccSAndroid Build Coastguard Worker * \remark Nothing is returned. Instead, the "TWO_PASS" structure inside "cpi"
579*77c1e3ccSAndroid Build Coastguard Worker * is modified to store information computed in this function.
580*77c1e3ccSAndroid Build Coastguard Worker */
581*77c1e3ccSAndroid Build Coastguard Worker void av1_first_pass(struct AV1_COMP *cpi, const int64_t ts_duration);
582*77c1e3ccSAndroid Build Coastguard Worker
583*77c1e3ccSAndroid Build Coastguard Worker void av1_noop_first_pass_frame(struct AV1_COMP *cpi, const int64_t ts_duration);
584*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
585*77c1e3ccSAndroid Build Coastguard Worker } // extern "C"
586*77c1e3ccSAndroid Build Coastguard Worker #endif
587*77c1e3ccSAndroid Build Coastguard Worker
588*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_AV1_ENCODER_FIRSTPASS_H_
589