xref: /aosp_15_r20/external/libaom/av1/encoder/aq_cyclicrefresh.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
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_AQ_CYCLICREFRESH_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_ENCODER_AQ_CYCLICREFRESH_H_
14*77c1e3ccSAndroid Build Coastguard Worker 
15*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/blockd.h"
16*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/block.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/tokenize.h"
18*77c1e3ccSAndroid Build Coastguard Worker 
19*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
20*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
21*77c1e3ccSAndroid Build Coastguard Worker #endif
22*77c1e3ccSAndroid Build Coastguard Worker 
23*77c1e3ccSAndroid Build Coastguard Worker // The segment ids used in cyclic refresh: from base (no boost) to increasing
24*77c1e3ccSAndroid Build Coastguard Worker // boost (higher delta-qp).
25*77c1e3ccSAndroid Build Coastguard Worker #define CR_SEGMENT_ID_BASE 0
26*77c1e3ccSAndroid Build Coastguard Worker #define CR_SEGMENT_ID_BOOST1 1
27*77c1e3ccSAndroid Build Coastguard Worker #define CR_SEGMENT_ID_BOOST2 2
28*77c1e3ccSAndroid Build Coastguard Worker 
29*77c1e3ccSAndroid Build Coastguard Worker // Maximum rate target ratio for setting segment delta-qp.
30*77c1e3ccSAndroid Build Coastguard Worker #define CR_MAX_RATE_TARGET_RATIO 4.0
31*77c1e3ccSAndroid Build Coastguard Worker 
32*77c1e3ccSAndroid Build Coastguard Worker /*!
33*77c1e3ccSAndroid Build Coastguard Worker  * \brief The stucture of CYCLIC_REFRESH.
34*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
35*77c1e3ccSAndroid Build Coastguard Worker  */
36*77c1e3ccSAndroid Build Coastguard Worker struct CYCLIC_REFRESH {
37*77c1e3ccSAndroid Build Coastguard Worker   /*!
38*77c1e3ccSAndroid Build Coastguard Worker    * Percentage of blocks per frame that are targeted as candidates
39*77c1e3ccSAndroid Build Coastguard Worker    * for cyclic refresh.
40*77c1e3ccSAndroid Build Coastguard Worker    */
41*77c1e3ccSAndroid Build Coastguard Worker   int percent_refresh;
42*77c1e3ccSAndroid Build Coastguard Worker 
43*77c1e3ccSAndroid Build Coastguard Worker   /*!
44*77c1e3ccSAndroid Build Coastguard Worker    * Active adjustment delta for cyclic refresh for rate control.
45*77c1e3ccSAndroid Build Coastguard Worker    */
46*77c1e3ccSAndroid Build Coastguard Worker   int percent_refresh_adjustment;
47*77c1e3ccSAndroid Build Coastguard Worker 
48*77c1e3ccSAndroid Build Coastguard Worker   /*!
49*77c1e3ccSAndroid Build Coastguard Worker    * Maximum q-delta as percentage of base q.
50*77c1e3ccSAndroid Build Coastguard Worker    */
51*77c1e3ccSAndroid Build Coastguard Worker   int max_qdelta_perc;
52*77c1e3ccSAndroid Build Coastguard Worker   /*!
53*77c1e3ccSAndroid Build Coastguard Worker    *Superblock starting index for cycling through the frame.
54*77c1e3ccSAndroid Build Coastguard Worker    */
55*77c1e3ccSAndroid Build Coastguard Worker   int sb_index;
56*77c1e3ccSAndroid Build Coastguard Worker   /*!
57*77c1e3ccSAndroid Build Coastguard Worker    *Superblock index cyclic refresh index last frame
58*77c1e3ccSAndroid Build Coastguard Worker    */
59*77c1e3ccSAndroid Build Coastguard Worker   int last_sb_index;
60*77c1e3ccSAndroid Build Coastguard Worker   /*!
61*77c1e3ccSAndroid Build Coastguard Worker    * Controls how long block will need to wait to be refreshed again, in
62*77c1e3ccSAndroid Build Coastguard Worker    * excess of the cycle time, i.e., in the case of all zero motion, block
63*77c1e3ccSAndroid Build Coastguard Worker    * will be refreshed every (100/percent_refresh + time_for_refresh) frames.
64*77c1e3ccSAndroid Build Coastguard Worker    */
65*77c1e3ccSAndroid Build Coastguard Worker   int time_for_refresh;
66*77c1e3ccSAndroid Build Coastguard Worker   /*!
67*77c1e3ccSAndroid Build Coastguard Worker    * Target number of (4x4) blocks that are set for delta-q.
68*77c1e3ccSAndroid Build Coastguard Worker    */
69*77c1e3ccSAndroid Build Coastguard Worker   int target_num_seg_blocks;
70*77c1e3ccSAndroid Build Coastguard Worker   /*!
71*77c1e3ccSAndroid Build Coastguard Worker    * Actual number of (4x4) blocks that were applied delta-q,
72*77c1e3ccSAndroid Build Coastguard Worker    * for segment 1.
73*77c1e3ccSAndroid Build Coastguard Worker    */
74*77c1e3ccSAndroid Build Coastguard Worker   int actual_num_seg1_blocks;
75*77c1e3ccSAndroid Build Coastguard Worker   /*!
76*77c1e3ccSAndroid Build Coastguard Worker    * Actual number of (4x4) blocks that were applied delta-q,
77*77c1e3ccSAndroid Build Coastguard Worker    * for segment 2.
78*77c1e3ccSAndroid Build Coastguard Worker    */
79*77c1e3ccSAndroid Build Coastguard Worker   int actual_num_seg2_blocks;
80*77c1e3ccSAndroid Build Coastguard Worker   /*!
81*77c1e3ccSAndroid Build Coastguard Worker    * RD mult. parameters for segment 1.
82*77c1e3ccSAndroid Build Coastguard Worker    */
83*77c1e3ccSAndroid Build Coastguard Worker   int rdmult;
84*77c1e3ccSAndroid Build Coastguard Worker   /*!
85*77c1e3ccSAndroid Build Coastguard Worker    * Cyclic refresh map.
86*77c1e3ccSAndroid Build Coastguard Worker    */
87*77c1e3ccSAndroid Build Coastguard Worker   int8_t *map;
88*77c1e3ccSAndroid Build Coastguard Worker   /*!
89*77c1e3ccSAndroid Build Coastguard Worker    * Threshold applied to the projected rate of the coding block,
90*77c1e3ccSAndroid Build Coastguard Worker    * when deciding whether block should be refreshed.
91*77c1e3ccSAndroid Build Coastguard Worker    */
92*77c1e3ccSAndroid Build Coastguard Worker   int64_t thresh_rate_sb;
93*77c1e3ccSAndroid Build Coastguard Worker   /*!
94*77c1e3ccSAndroid Build Coastguard Worker    * Threshold applied to the projected distortion of the coding block,
95*77c1e3ccSAndroid Build Coastguard Worker    * when deciding whether block should be refreshed.
96*77c1e3ccSAndroid Build Coastguard Worker    */
97*77c1e3ccSAndroid Build Coastguard Worker   int64_t thresh_dist_sb;
98*77c1e3ccSAndroid Build Coastguard Worker   /*!
99*77c1e3ccSAndroid Build Coastguard Worker    * Threshold applied to the motion vector (in units of 1/8 pel) of the
100*77c1e3ccSAndroid Build Coastguard Worker    * coding block, when deciding whether block should be refreshed.
101*77c1e3ccSAndroid Build Coastguard Worker    */
102*77c1e3ccSAndroid Build Coastguard Worker   int16_t motion_thresh;
103*77c1e3ccSAndroid Build Coastguard Worker   /*!
104*77c1e3ccSAndroid Build Coastguard Worker    * Rate target ratio to set q delta.
105*77c1e3ccSAndroid Build Coastguard Worker    */
106*77c1e3ccSAndroid Build Coastguard Worker   double rate_ratio_qdelta;
107*77c1e3ccSAndroid Build Coastguard Worker 
108*77c1e3ccSAndroid Build Coastguard Worker   /*!
109*77c1e3ccSAndroid Build Coastguard Worker    * Active adjustment of qdelta rate ratio for enhanced rate control
110*77c1e3ccSAndroid Build Coastguard Worker    */
111*77c1e3ccSAndroid Build Coastguard Worker   double rate_ratio_qdelta_adjustment;
112*77c1e3ccSAndroid Build Coastguard Worker 
113*77c1e3ccSAndroid Build Coastguard Worker   /*!
114*77c1e3ccSAndroid Build Coastguard Worker    * Boost factor for rate target ratio, for segment CR_SEGMENT_ID_BOOST2.
115*77c1e3ccSAndroid Build Coastguard Worker    */
116*77c1e3ccSAndroid Build Coastguard Worker   int rate_boost_fac;
117*77c1e3ccSAndroid Build Coastguard Worker 
118*77c1e3ccSAndroid Build Coastguard Worker   /*!\cond */
119*77c1e3ccSAndroid Build Coastguard Worker   int qindex_delta[3];
120*77c1e3ccSAndroid Build Coastguard Worker   int apply_cyclic_refresh;
121*77c1e3ccSAndroid Build Coastguard Worker   int skip_over4x4;
122*77c1e3ccSAndroid Build Coastguard Worker   int counter_encode_maxq_scene_change;
123*77c1e3ccSAndroid Build Coastguard Worker   int use_block_sad_scene_det;
124*77c1e3ccSAndroid Build Coastguard Worker   /*!\endcond */
125*77c1e3ccSAndroid Build Coastguard Worker };
126*77c1e3ccSAndroid Build Coastguard Worker 
127*77c1e3ccSAndroid Build Coastguard Worker struct AV1_COMP;
128*77c1e3ccSAndroid Build Coastguard Worker 
129*77c1e3ccSAndroid Build Coastguard Worker typedef struct CYCLIC_REFRESH CYCLIC_REFRESH;
130*77c1e3ccSAndroid Build Coastguard Worker 
131*77c1e3ccSAndroid Build Coastguard Worker CYCLIC_REFRESH *av1_cyclic_refresh_alloc(int mi_rows, int mi_cols);
132*77c1e3ccSAndroid Build Coastguard Worker 
133*77c1e3ccSAndroid Build Coastguard Worker void av1_cyclic_refresh_free(CYCLIC_REFRESH *cr);
134*77c1e3ccSAndroid Build Coastguard Worker 
135*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Estimate the bits, incorporating the delta-q from the segments.
136*77c1e3ccSAndroid Build Coastguard Worker  *
137*77c1e3ccSAndroid Build Coastguard Worker  * For the just encoded frame, estimate the bits, incorporating the delta-q
138*77c1e3ccSAndroid Build Coastguard Worker  * from non-base segment(s). Note this function is called in the postencode
139*77c1e3ccSAndroid Build Coastguard Worker  * (called from rc_update_rate_correction_factors()).
140*77c1e3ccSAndroid Build Coastguard Worker  *
141*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
142*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
143*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
144*77c1e3ccSAndroid Build Coastguard Worker  *
145*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       cpi               Top level encoder structure
146*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       correction_factor rate correction factor
147*77c1e3ccSAndroid Build Coastguard Worker  *
148*77c1e3ccSAndroid Build Coastguard Worker  * \return Return the estimated bits at given q.
149*77c1e3ccSAndroid Build Coastguard Worker  */
150*77c1e3ccSAndroid Build Coastguard Worker int av1_cyclic_refresh_estimate_bits_at_q(const struct AV1_COMP *cpi,
151*77c1e3ccSAndroid Build Coastguard Worker                                           double correction_factor);
152*77c1e3ccSAndroid Build Coastguard Worker 
153*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Estimate the bits per mb, for given q = i and delta-q.
154*77c1e3ccSAndroid Build Coastguard Worker  *
155*77c1e3ccSAndroid Build Coastguard Worker  * Prior to encoding the frame, estimate the bits per mb, for a given q = i and
156*77c1e3ccSAndroid Build Coastguard Worker  * a corresponding delta-q (for segment 1). This function is called in the
157*77c1e3ccSAndroid Build Coastguard Worker  * rc_regulate_q() to set the base qp index. Note: the segment map is set to
158*77c1e3ccSAndroid Build Coastguard Worker  * either 0/CR_SEGMENT_ID_BASE (no refresh) or to 1/CR_SEGMENT_ID_BOOST1
159*77c1e3ccSAndroid Build Coastguard Worker  * (refresh) for each superblock, prior to encoding.
160*77c1e3ccSAndroid Build Coastguard Worker  *
161*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
162*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
163*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
164*77c1e3ccSAndroid Build Coastguard Worker  *
165*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       cpi               Top level encoder structure
166*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       i                 q index
167*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       correction_factor rate correction factor
168*77c1e3ccSAndroid Build Coastguard Worker  *
169*77c1e3ccSAndroid Build Coastguard Worker  * \return Return the estimated bits for q = i and delta-q (segment 1).
170*77c1e3ccSAndroid Build Coastguard Worker  */
171*77c1e3ccSAndroid Build Coastguard Worker int av1_cyclic_refresh_rc_bits_per_mb(const struct AV1_COMP *cpi, int i,
172*77c1e3ccSAndroid Build Coastguard Worker                                       double correction_factor);
173*77c1e3ccSAndroid Build Coastguard Worker 
174*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Update segment_id for blocks are skipped.
175*77c1e3ccSAndroid Build Coastguard Worker  *
176*77c1e3ccSAndroid Build Coastguard Worker  * After encoding a given prediction block, of size bsize at (mi_row, mi_col),
177*77c1e3ccSAndroid Build Coastguard Worker  * check if we should reset the segment_id based on skip_txfm,
178*77c1e3ccSAndroid Build Coastguard Worker  * and update the cyclic_refresh map and segmentation counters.
179*77c1e3ccSAndroid Build Coastguard Worker  *
180*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
181*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
182*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
183*77c1e3ccSAndroid Build Coastguard Worker  *
184*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   cpi       Top level encoder structure
185*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   x         Pointer to MACROBLOCK structure
186*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   mi_row    Row coordinate of the block in a step size of MI_SIZE
187*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   mi_col    Col coordinate of the block in a step size of MI_SIZE
188*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   bsize     Block size
189*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   dry_run   A code indicating whether it is part of the final
190*77c1e3ccSAndroid Build Coastguard Worker  *                        pass for reconstructing the superblock
191*77c1e3ccSAndroid Build Coastguard Worker  *
192*77c1e3ccSAndroid Build Coastguard Worker  * \remark Update the \c mbmi->segment_id, the \c cpi->cyclic_refresh and
193*77c1e3ccSAndroid Build Coastguard Worker  * the \c cm->cpi->enc_seg.map.
194*77c1e3ccSAndroid Build Coastguard Worker  */
195*77c1e3ccSAndroid Build Coastguard Worker 
196*77c1e3ccSAndroid Build Coastguard Worker void av1_cyclic_reset_segment_skip(const struct AV1_COMP *cpi,
197*77c1e3ccSAndroid Build Coastguard Worker                                    MACROBLOCK *const x, int mi_row, int mi_col,
198*77c1e3ccSAndroid Build Coastguard Worker                                    BLOCK_SIZE bsize, RUN_TYPE dry_run);
199*77c1e3ccSAndroid Build Coastguard Worker 
200*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Update segment_id for block based on mode selected.
201*77c1e3ccSAndroid Build Coastguard Worker  *
202*77c1e3ccSAndroid Build Coastguard Worker  * Prior to coding a given prediction block, of size bsize at (mi_row, mi_col),
203*77c1e3ccSAndroid Build Coastguard Worker  * check if we should reset the segment_id (based on mode/motion/skip selected
204*77c1e3ccSAndroid Build Coastguard Worker  * for that block) and update the cyclic_refresh map and segmentation map.
205*77c1e3ccSAndroid Build Coastguard Worker  *
206*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
207*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
208*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
209*77c1e3ccSAndroid Build Coastguard Worker  *
210*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   cpi       Top level encoder structure
211*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   x         Pointer to MACROBLOCK structure
212*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   mi_row    Row coordinate of the block in a step size of MI_SIZE
213*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   mi_col    Col coordinate of the block in a step size of MI_SIZE
214*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   bsize     Block size
215*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   rate      Projected block rate from pickmode
216*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   dist      Projected block dist from pickmode
217*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   skip      Skip flag set from picmode
218*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   dry_run   A code indicating whether it is part of the final
219*77c1e3ccSAndroid Build Coastguard Worker  *                         pass for reconstructing the superblock
220*77c1e3ccSAndroid Build Coastguard Worker  *
221*77c1e3ccSAndroid Build Coastguard Worker  * \remark Update the \c mbmi->segment_id, the \c cpi->cyclic_refresh and
222*77c1e3ccSAndroid Build Coastguard Worker  * the \c cm->cpi->enc_seg.map.
223*77c1e3ccSAndroid Build Coastguard Worker  */
224*77c1e3ccSAndroid Build Coastguard Worker void av1_cyclic_refresh_update_segment(const struct AV1_COMP *cpi,
225*77c1e3ccSAndroid Build Coastguard Worker                                        MACROBLOCK *const x, int mi_row,
226*77c1e3ccSAndroid Build Coastguard Worker                                        int mi_col, BLOCK_SIZE bsize,
227*77c1e3ccSAndroid Build Coastguard Worker                                        int64_t rate, int64_t dist, int skip,
228*77c1e3ccSAndroid Build Coastguard Worker                                        RUN_TYPE dry_run);
229*77c1e3ccSAndroid Build Coastguard Worker 
230*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Initialize counters used for cyclic refresh.
231*77c1e3ccSAndroid Build Coastguard Worker  *
232*77c1e3ccSAndroid Build Coastguard Worker  * Initializes cyclic refresh counters actual_num_seg1_blocks and
233*77c1e3ccSAndroid Build Coastguard Worker  * actual_num_seg2_blocks.
234*77c1e3ccSAndroid Build Coastguard Worker  *
235*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
236*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
237*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
238*77c1e3ccSAndroid Build Coastguard Worker  *
239*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   x         Pointer to MACROBLOCK structure
240*77c1e3ccSAndroid Build Coastguard Worker  *
241*77c1e3ccSAndroid Build Coastguard Worker  * \remark Update the \c x->actual_num_seg1_blocks and the
242*77c1e3ccSAndroid Build Coastguard Worker  * \c x->actual_num_seg2_blocks.
243*77c1e3ccSAndroid Build Coastguard Worker  */
244*77c1e3ccSAndroid Build Coastguard Worker void av1_init_cyclic_refresh_counters(MACROBLOCK *const x);
245*77c1e3ccSAndroid Build Coastguard Worker 
246*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Accumulate cyclic refresh counters.
247*77c1e3ccSAndroid Build Coastguard Worker  *
248*77c1e3ccSAndroid Build Coastguard Worker  * Accumulates cyclic refresh counters actual_num_seg1_blocks and
249*77c1e3ccSAndroid Build Coastguard Worker  * actual_num_seg2_blocks from MACROBLOCK strcture to CYCLIC_REFRESH strcture.
250*77c1e3ccSAndroid Build Coastguard Worker  *
251*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
252*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
253*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
254*77c1e3ccSAndroid Build Coastguard Worker  *
255*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   cyclic_refresh Pointer to CYCLIC_REFRESH structure
256*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   x              Pointer to MACROBLOCK structure
257*77c1e3ccSAndroid Build Coastguard Worker  *
258*77c1e3ccSAndroid Build Coastguard Worker  * \remark Update the \c cyclic_refresh->actual_num_seg1_blocks and the
259*77c1e3ccSAndroid Build Coastguard Worker  * \c cyclic_refresh->actual_num_seg2_blocks.
260*77c1e3ccSAndroid Build Coastguard Worker  */
261*77c1e3ccSAndroid Build Coastguard Worker void av1_accumulate_cyclic_refresh_counters(
262*77c1e3ccSAndroid Build Coastguard Worker     CYCLIC_REFRESH *const cyclic_refresh, const MACROBLOCK *const x);
263*77c1e3ccSAndroid Build Coastguard Worker 
264*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Set golden frame update interval nased on cyclic refresh.
265*77c1e3ccSAndroid Build Coastguard Worker  *
266*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
267*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
268*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
269*77c1e3ccSAndroid Build Coastguard Worker  *
270*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]   cpi       Top level encoder structure
271*77c1e3ccSAndroid Build Coastguard Worker  *
272*77c1e3ccSAndroid Build Coastguard Worker  * \remark Returns the interval in \c cpi->rc.baseline_gf_interval.
273*77c1e3ccSAndroid Build Coastguard Worker  */
274*77c1e3ccSAndroid Build Coastguard Worker void av1_cyclic_refresh_set_golden_update(struct AV1_COMP *const cpi);
275*77c1e3ccSAndroid Build Coastguard Worker 
276*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Set the global/frame level parameters for cyclic refresh.
277*77c1e3ccSAndroid Build Coastguard Worker  *
278*77c1e3ccSAndroid Build Coastguard Worker  * First call to the cyclic refresh, before encoding the frame.
279*77c1e3ccSAndroid Build Coastguard Worker  * Sets the flag on whether cyclic refresh should be applied, sets
280*77c1e3ccSAndroid Build Coastguard Worker  * the amount/percent of refresh, and the amount of boost applied to
281*77c1e3ccSAndroid Build Coastguard Worker  * the two segments (set by rate_ratio_qdelta and rate_boost_fac).
282*77c1e3ccSAndroid Build Coastguard Worker  *
283*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
284*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
285*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
286*77c1e3ccSAndroid Build Coastguard Worker  *
287*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       cpi          Top level encoder structure
288*77c1e3ccSAndroid Build Coastguard Worker  *
289*77c1e3ccSAndroid Build Coastguard Worker  * \remark Updates the \c cpi->cyclic_refresh with the settings.
290*77c1e3ccSAndroid Build Coastguard Worker  */
291*77c1e3ccSAndroid Build Coastguard Worker void av1_cyclic_refresh_update_parameters(struct AV1_COMP *const cpi);
292*77c1e3ccSAndroid Build Coastguard Worker 
293*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Setup the cyclic background refresh.
294*77c1e3ccSAndroid Build Coastguard Worker  *
295*77c1e3ccSAndroid Build Coastguard Worker  * Set the delta q for the segment(s), and set the segmentation map.
296*77c1e3ccSAndroid Build Coastguard Worker  *
297*77c1e3ccSAndroid Build Coastguard Worker  * \ingroup cyclic_refresh
298*77c1e3ccSAndroid Build Coastguard Worker  * \callgraph
299*77c1e3ccSAndroid Build Coastguard Worker  * \callergraph
300*77c1e3ccSAndroid Build Coastguard Worker  *
301*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       cpi          Top level encoder structure
302*77c1e3ccSAndroid Build Coastguard Worker  *
303*77c1e3ccSAndroid Build Coastguard Worker  * \remark Updates the \c cpi->cyclic_refresh with the cyclic refresh
304*77c1e3ccSAndroid Build Coastguard Worker  * parameters and the \c cm->seg with the segmentation data.
305*77c1e3ccSAndroid Build Coastguard Worker  */
306*77c1e3ccSAndroid Build Coastguard Worker void av1_cyclic_refresh_setup(struct AV1_COMP *const cpi);
307*77c1e3ccSAndroid Build Coastguard Worker 
308*77c1e3ccSAndroid Build Coastguard Worker int av1_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
309*77c1e3ccSAndroid Build Coastguard Worker 
310*77c1e3ccSAndroid Build Coastguard Worker int av1_cyclic_refresh_disable_lf_cdef(struct AV1_COMP *const cpi);
311*77c1e3ccSAndroid Build Coastguard Worker 
cyclic_refresh_segment_id_boosted(int segment_id)312*77c1e3ccSAndroid Build Coastguard Worker static inline int cyclic_refresh_segment_id_boosted(int segment_id) {
313*77c1e3ccSAndroid Build Coastguard Worker   return segment_id == CR_SEGMENT_ID_BOOST1 ||
314*77c1e3ccSAndroid Build Coastguard Worker          segment_id == CR_SEGMENT_ID_BOOST2;
315*77c1e3ccSAndroid Build Coastguard Worker }
316*77c1e3ccSAndroid Build Coastguard Worker 
cyclic_refresh_segment_id(int segment_id)317*77c1e3ccSAndroid Build Coastguard Worker static inline int cyclic_refresh_segment_id(int segment_id) {
318*77c1e3ccSAndroid Build Coastguard Worker   if (segment_id == CR_SEGMENT_ID_BOOST1)
319*77c1e3ccSAndroid Build Coastguard Worker     return CR_SEGMENT_ID_BOOST1;
320*77c1e3ccSAndroid Build Coastguard Worker   else if (segment_id == CR_SEGMENT_ID_BOOST2)
321*77c1e3ccSAndroid Build Coastguard Worker     return CR_SEGMENT_ID_BOOST2;
322*77c1e3ccSAndroid Build Coastguard Worker   else
323*77c1e3ccSAndroid Build Coastguard Worker     return CR_SEGMENT_ID_BASE;
324*77c1e3ccSAndroid Build Coastguard Worker }
325*77c1e3ccSAndroid Build Coastguard Worker 
326*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
327*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
328*77c1e3ccSAndroid Build Coastguard Worker #endif
329*77c1e3ccSAndroid Build Coastguard Worker 
330*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AV1_ENCODER_AQ_CYCLICREFRESH_H_
331