xref: /aosp_15_r20/external/libaom/av1/encoder/tpl_model.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2019, 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_TPL_MODEL_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_ENCODER_TPL_MODEL_H_
14*77c1e3ccSAndroid Build Coastguard Worker 
15*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
16*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
17*77c1e3ccSAndroid Build Coastguard Worker #endif
18*77c1e3ccSAndroid Build Coastguard Worker 
19*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
20*77c1e3ccSAndroid Build Coastguard Worker 
21*77c1e3ccSAndroid Build Coastguard Worker struct AV1_PRIMARY;
22*77c1e3ccSAndroid Build Coastguard Worker struct AV1_COMP;
23*77c1e3ccSAndroid Build Coastguard Worker struct AV1_SEQ_CODING_TOOLS;
24*77c1e3ccSAndroid Build Coastguard Worker struct EncodeFrameParams;
25*77c1e3ccSAndroid Build Coastguard Worker struct EncodeFrameInput;
26*77c1e3ccSAndroid Build Coastguard Worker struct GF_GROUP;
27*77c1e3ccSAndroid Build Coastguard Worker struct ThreadData;
28*77c1e3ccSAndroid Build Coastguard Worker struct TPL_INFO;
29*77c1e3ccSAndroid Build Coastguard Worker 
30*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
31*77c1e3ccSAndroid Build Coastguard Worker 
32*77c1e3ccSAndroid Build Coastguard Worker #include "aom_scale/yv12config.h"
33*77c1e3ccSAndroid Build Coastguard Worker #include "aom_util/aom_pthread.h"
34*77c1e3ccSAndroid Build Coastguard Worker 
35*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/mv.h"
36*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/scale.h"
37*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/block.h"
38*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/lookahead.h"
39*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/ratectrl.h"
40*77c1e3ccSAndroid Build Coastguard Worker 
convert_length_to_bsize(int length)41*77c1e3ccSAndroid Build Coastguard Worker static inline BLOCK_SIZE convert_length_to_bsize(int length) {
42*77c1e3ccSAndroid Build Coastguard Worker   switch (length) {
43*77c1e3ccSAndroid Build Coastguard Worker     case 64: return BLOCK_64X64;
44*77c1e3ccSAndroid Build Coastguard Worker     case 32: return BLOCK_32X32;
45*77c1e3ccSAndroid Build Coastguard Worker     case 16: return BLOCK_16X16;
46*77c1e3ccSAndroid Build Coastguard Worker     case 8: return BLOCK_8X8;
47*77c1e3ccSAndroid Build Coastguard Worker     case 4: return BLOCK_4X4;
48*77c1e3ccSAndroid Build Coastguard Worker     default:
49*77c1e3ccSAndroid Build Coastguard Worker       assert(0 && "Invalid block size for tpl model");
50*77c1e3ccSAndroid Build Coastguard Worker       return BLOCK_16X16;
51*77c1e3ccSAndroid Build Coastguard Worker   }
52*77c1e3ccSAndroid Build Coastguard Worker }
53*77c1e3ccSAndroid Build Coastguard Worker 
54*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1TplRowMultiThreadSync {
55*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
56*77c1e3ccSAndroid Build Coastguard Worker   // Synchronization objects for top-right dependency.
57*77c1e3ccSAndroid Build Coastguard Worker   pthread_mutex_t *mutex_;
58*77c1e3ccSAndroid Build Coastguard Worker   pthread_cond_t *cond_;
59*77c1e3ccSAndroid Build Coastguard Worker #endif
60*77c1e3ccSAndroid Build Coastguard Worker   // Buffer to store the macroblock whose encoding is complete.
61*77c1e3ccSAndroid Build Coastguard Worker   // num_finished_cols[i] stores the number of macroblocks which finished
62*77c1e3ccSAndroid Build Coastguard Worker   // encoding in the ith macroblock row.
63*77c1e3ccSAndroid Build Coastguard Worker   int *num_finished_cols;
64*77c1e3ccSAndroid Build Coastguard Worker   // Number of extra macroblocks of the top row to be complete for encoding
65*77c1e3ccSAndroid Build Coastguard Worker   // of the current macroblock to start. A value of 1 indicates top-right
66*77c1e3ccSAndroid Build Coastguard Worker   // dependency.
67*77c1e3ccSAndroid Build Coastguard Worker   int sync_range;
68*77c1e3ccSAndroid Build Coastguard Worker   // Number of macroblock rows.
69*77c1e3ccSAndroid Build Coastguard Worker   int rows;
70*77c1e3ccSAndroid Build Coastguard Worker   // Number of threads processing the current tile.
71*77c1e3ccSAndroid Build Coastguard Worker   int num_threads_working;
72*77c1e3ccSAndroid Build Coastguard Worker } AV1TplRowMultiThreadSync;
73*77c1e3ccSAndroid Build Coastguard Worker 
74*77c1e3ccSAndroid Build Coastguard Worker typedef struct AV1TplRowMultiThreadInfo {
75*77c1e3ccSAndroid Build Coastguard Worker   // Initialized to false, set to true by the worker thread that encounters an
76*77c1e3ccSAndroid Build Coastguard Worker   // error in order to abort the processing of other worker threads.
77*77c1e3ccSAndroid Build Coastguard Worker   bool tpl_mt_exit;
78*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_MULTITHREAD
79*77c1e3ccSAndroid Build Coastguard Worker   // Mutex lock object used for error handling.
80*77c1e3ccSAndroid Build Coastguard Worker   pthread_mutex_t *mutex_;
81*77c1e3ccSAndroid Build Coastguard Worker #endif
82*77c1e3ccSAndroid Build Coastguard Worker   // Row synchronization related function pointers.
83*77c1e3ccSAndroid Build Coastguard Worker   void (*sync_read_ptr)(AV1TplRowMultiThreadSync *tpl_mt_sync, int r, int c);
84*77c1e3ccSAndroid Build Coastguard Worker   void (*sync_write_ptr)(AV1TplRowMultiThreadSync *tpl_mt_sync, int r, int c,
85*77c1e3ccSAndroid Build Coastguard Worker                          int cols);
86*77c1e3ccSAndroid Build Coastguard Worker } AV1TplRowMultiThreadInfo;
87*77c1e3ccSAndroid Build Coastguard Worker 
88*77c1e3ccSAndroid Build Coastguard Worker // TODO(jingning): This needs to be cleaned up next.
89*77c1e3ccSAndroid Build Coastguard Worker 
90*77c1e3ccSAndroid Build Coastguard Worker // TPL stats buffers are prepared for every frame in the GOP,
91*77c1e3ccSAndroid Build Coastguard Worker // including (internal) overlays and (internal) arfs.
92*77c1e3ccSAndroid Build Coastguard Worker // In addition, frames in the lookahead that are outside of the GOP
93*77c1e3ccSAndroid Build Coastguard Worker // are also used.
94*77c1e3ccSAndroid Build Coastguard Worker // Thus it should use
95*77c1e3ccSAndroid Build Coastguard Worker // (gop_length) + (# overlays) + (MAX_LAG_BUFFERS - gop_len) =
96*77c1e3ccSAndroid Build Coastguard Worker // MAX_LAG_BUFFERS + (# overlays)
97*77c1e3ccSAndroid Build Coastguard Worker // 2 * MAX_LAG_BUFFERS is therefore a safe estimate.
98*77c1e3ccSAndroid Build Coastguard Worker // TODO(bohanli): test setting it to 1.5 * MAX_LAG_BUFFER
99*77c1e3ccSAndroid Build Coastguard Worker #define MAX_TPL_FRAME_IDX (2 * MAX_LAG_BUFFERS)
100*77c1e3ccSAndroid Build Coastguard Worker // The first REF_FRAMES + 1 buffers are reserved.
101*77c1e3ccSAndroid Build Coastguard Worker // tpl_data->tpl_frame starts after REF_FRAMES + 1
102*77c1e3ccSAndroid Build Coastguard Worker #define MAX_LENGTH_TPL_FRAME_STATS (MAX_TPL_FRAME_IDX + REF_FRAMES + 1)
103*77c1e3ccSAndroid Build Coastguard Worker #define TPL_DEP_COST_SCALE_LOG2 4
104*77c1e3ccSAndroid Build Coastguard Worker 
105*77c1e3ccSAndroid Build Coastguard Worker #define TPL_EPSILON 0.0000001
106*77c1e3ccSAndroid Build Coastguard Worker 
107*77c1e3ccSAndroid Build Coastguard Worker typedef struct TplTxfmStats {
108*77c1e3ccSAndroid Build Coastguard Worker   int ready;                  // Whether abs_coeff_mean is ready
109*77c1e3ccSAndroid Build Coastguard Worker   double abs_coeff_sum[256];  // Assume we are using 16x16 transform block
110*77c1e3ccSAndroid Build Coastguard Worker   double abs_coeff_mean[256];
111*77c1e3ccSAndroid Build Coastguard Worker   int txfm_block_count;
112*77c1e3ccSAndroid Build Coastguard Worker   int coeff_num;
113*77c1e3ccSAndroid Build Coastguard Worker } TplTxfmStats;
114*77c1e3ccSAndroid Build Coastguard Worker 
115*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
116*77c1e3ccSAndroid Build Coastguard Worker   uint8_t *predictor8;
117*77c1e3ccSAndroid Build Coastguard Worker   int16_t *src_diff;
118*77c1e3ccSAndroid Build Coastguard Worker   tran_low_t *coeff;
119*77c1e3ccSAndroid Build Coastguard Worker   tran_low_t *qcoeff;
120*77c1e3ccSAndroid Build Coastguard Worker   tran_low_t *dqcoeff;
121*77c1e3ccSAndroid Build Coastguard Worker } TplBuffers;
122*77c1e3ccSAndroid Build Coastguard Worker 
123*77c1e3ccSAndroid Build Coastguard Worker typedef struct TplDepStats {
124*77c1e3ccSAndroid Build Coastguard Worker   int64_t srcrf_sse;
125*77c1e3ccSAndroid Build Coastguard Worker   int64_t srcrf_dist;
126*77c1e3ccSAndroid Build Coastguard Worker   int64_t recrf_sse;
127*77c1e3ccSAndroid Build Coastguard Worker   int64_t recrf_dist;
128*77c1e3ccSAndroid Build Coastguard Worker   int64_t intra_sse;
129*77c1e3ccSAndroid Build Coastguard Worker   int64_t intra_dist;
130*77c1e3ccSAndroid Build Coastguard Worker   int64_t cmp_recrf_dist[2];
131*77c1e3ccSAndroid Build Coastguard Worker   int64_t mc_dep_rate;
132*77c1e3ccSAndroid Build Coastguard Worker   int64_t mc_dep_dist;
133*77c1e3ccSAndroid Build Coastguard Worker   int64_t pred_error[INTER_REFS_PER_FRAME];
134*77c1e3ccSAndroid Build Coastguard Worker   int32_t intra_cost;
135*77c1e3ccSAndroid Build Coastguard Worker   int32_t inter_cost;
136*77c1e3ccSAndroid Build Coastguard Worker   int32_t srcrf_rate;
137*77c1e3ccSAndroid Build Coastguard Worker   int32_t recrf_rate;
138*77c1e3ccSAndroid Build Coastguard Worker   int32_t intra_rate;
139*77c1e3ccSAndroid Build Coastguard Worker   int32_t cmp_recrf_rate[2];
140*77c1e3ccSAndroid Build Coastguard Worker   int_mv mv[INTER_REFS_PER_FRAME];
141*77c1e3ccSAndroid Build Coastguard Worker   int8_t ref_frame_index[2];
142*77c1e3ccSAndroid Build Coastguard Worker } TplDepStats;
143*77c1e3ccSAndroid Build Coastguard Worker 
144*77c1e3ccSAndroid Build Coastguard Worker typedef struct TplDepFrame {
145*77c1e3ccSAndroid Build Coastguard Worker   uint8_t is_valid;
146*77c1e3ccSAndroid Build Coastguard Worker   TplDepStats *tpl_stats_ptr;
147*77c1e3ccSAndroid Build Coastguard Worker   const YV12_BUFFER_CONFIG *gf_picture;
148*77c1e3ccSAndroid Build Coastguard Worker   YV12_BUFFER_CONFIG *rec_picture;
149*77c1e3ccSAndroid Build Coastguard Worker   int ref_map_index[REF_FRAMES];
150*77c1e3ccSAndroid Build Coastguard Worker   int stride;
151*77c1e3ccSAndroid Build Coastguard Worker   int width;
152*77c1e3ccSAndroid Build Coastguard Worker   int height;
153*77c1e3ccSAndroid Build Coastguard Worker   int mi_rows;
154*77c1e3ccSAndroid Build Coastguard Worker   int mi_cols;
155*77c1e3ccSAndroid Build Coastguard Worker   int base_rdmult;
156*77c1e3ccSAndroid Build Coastguard Worker   uint32_t frame_display_index;
157*77c1e3ccSAndroid Build Coastguard Worker   // When set, SAD metric is used for intra and inter mode decision.
158*77c1e3ccSAndroid Build Coastguard Worker   int use_pred_sad;
159*77c1e3ccSAndroid Build Coastguard Worker } TplDepFrame;
160*77c1e3ccSAndroid Build Coastguard Worker 
161*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
162*77c1e3ccSAndroid Build Coastguard Worker /*!
163*77c1e3ccSAndroid Build Coastguard Worker  * \brief Params related to temporal dependency model.
164*77c1e3ccSAndroid Build Coastguard Worker  */
165*77c1e3ccSAndroid Build Coastguard Worker typedef struct TplParams {
166*77c1e3ccSAndroid Build Coastguard Worker   /*!
167*77c1e3ccSAndroid Build Coastguard Worker    * Whether the tpl stats is ready.
168*77c1e3ccSAndroid Build Coastguard Worker    */
169*77c1e3ccSAndroid Build Coastguard Worker   int ready;
170*77c1e3ccSAndroid Build Coastguard Worker 
171*77c1e3ccSAndroid Build Coastguard Worker   /*!
172*77c1e3ccSAndroid Build Coastguard Worker    * Block granularity of tpl score storage.
173*77c1e3ccSAndroid Build Coastguard Worker    */
174*77c1e3ccSAndroid Build Coastguard Worker   uint8_t tpl_stats_block_mis_log2;
175*77c1e3ccSAndroid Build Coastguard Worker 
176*77c1e3ccSAndroid Build Coastguard Worker   /*!
177*77c1e3ccSAndroid Build Coastguard Worker    * Tpl motion estimation block 1d size. tpl_bsize_1d >= 16.
178*77c1e3ccSAndroid Build Coastguard Worker    */
179*77c1e3ccSAndroid Build Coastguard Worker   uint8_t tpl_bsize_1d;
180*77c1e3ccSAndroid Build Coastguard Worker 
181*77c1e3ccSAndroid Build Coastguard Worker   /*!
182*77c1e3ccSAndroid Build Coastguard Worker    * Buffer to store the frame level tpl information for each frame in a gf
183*77c1e3ccSAndroid Build Coastguard Worker    * group. tpl_stats_buffer[i] stores the tpl information of ith frame in a gf
184*77c1e3ccSAndroid Build Coastguard Worker    * group
185*77c1e3ccSAndroid Build Coastguard Worker    */
186*77c1e3ccSAndroid Build Coastguard Worker   TplDepFrame tpl_stats_buffer[MAX_LENGTH_TPL_FRAME_STATS];
187*77c1e3ccSAndroid Build Coastguard Worker 
188*77c1e3ccSAndroid Build Coastguard Worker   /*!
189*77c1e3ccSAndroid Build Coastguard Worker    * Buffer to store tpl stats at block granularity.
190*77c1e3ccSAndroid Build Coastguard Worker    * tpl_stats_pool[i][j] stores the tpl stats of jth block of ith frame in a gf
191*77c1e3ccSAndroid Build Coastguard Worker    * group.
192*77c1e3ccSAndroid Build Coastguard Worker    */
193*77c1e3ccSAndroid Build Coastguard Worker   TplDepStats *tpl_stats_pool[MAX_LAG_BUFFERS];
194*77c1e3ccSAndroid Build Coastguard Worker 
195*77c1e3ccSAndroid Build Coastguard Worker   /*!
196*77c1e3ccSAndroid Build Coastguard Worker    * Pointer to the buffer which stores tpl transform stats per frame.
197*77c1e3ccSAndroid Build Coastguard Worker    * txfm_stats_list[i] stores the TplTxfmStats of the ith frame in a gf group.
198*77c1e3ccSAndroid Build Coastguard Worker    * Memory is allocated dynamically for MAX_LENGTH_TPL_FRAME_STATS frames when
199*77c1e3ccSAndroid Build Coastguard Worker    * tpl is enabled.
200*77c1e3ccSAndroid Build Coastguard Worker    */
201*77c1e3ccSAndroid Build Coastguard Worker   TplTxfmStats *txfm_stats_list;
202*77c1e3ccSAndroid Build Coastguard Worker 
203*77c1e3ccSAndroid Build Coastguard Worker   /*!
204*77c1e3ccSAndroid Build Coastguard Worker    * Buffer to store tpl reconstructed frame.
205*77c1e3ccSAndroid Build Coastguard Worker    * tpl_rec_pool[i] stores the reconstructed frame of ith frame in a gf group.
206*77c1e3ccSAndroid Build Coastguard Worker    */
207*77c1e3ccSAndroid Build Coastguard Worker   YV12_BUFFER_CONFIG tpl_rec_pool[MAX_LAG_BUFFERS];
208*77c1e3ccSAndroid Build Coastguard Worker 
209*77c1e3ccSAndroid Build Coastguard Worker   /*!
210*77c1e3ccSAndroid Build Coastguard Worker    * Pointer to tpl_stats_buffer.
211*77c1e3ccSAndroid Build Coastguard Worker    */
212*77c1e3ccSAndroid Build Coastguard Worker   TplDepFrame *tpl_frame;
213*77c1e3ccSAndroid Build Coastguard Worker 
214*77c1e3ccSAndroid Build Coastguard Worker   /*!
215*77c1e3ccSAndroid Build Coastguard Worker    * Scale factors for the current frame.
216*77c1e3ccSAndroid Build Coastguard Worker    */
217*77c1e3ccSAndroid Build Coastguard Worker   struct scale_factors sf;
218*77c1e3ccSAndroid Build Coastguard Worker 
219*77c1e3ccSAndroid Build Coastguard Worker   /*!
220*77c1e3ccSAndroid Build Coastguard Worker    * GF group index of the current frame.
221*77c1e3ccSAndroid Build Coastguard Worker    */
222*77c1e3ccSAndroid Build Coastguard Worker   int frame_idx;
223*77c1e3ccSAndroid Build Coastguard Worker 
224*77c1e3ccSAndroid Build Coastguard Worker   /*!
225*77c1e3ccSAndroid Build Coastguard Worker    * Array of pointers to the frame buffers holding the source frame.
226*77c1e3ccSAndroid Build Coastguard Worker    * src_ref_frame[i] stores the pointer to the source frame of the ith
227*77c1e3ccSAndroid Build Coastguard Worker    * reference frame type.
228*77c1e3ccSAndroid Build Coastguard Worker    */
229*77c1e3ccSAndroid Build Coastguard Worker   const YV12_BUFFER_CONFIG *src_ref_frame[INTER_REFS_PER_FRAME];
230*77c1e3ccSAndroid Build Coastguard Worker 
231*77c1e3ccSAndroid Build Coastguard Worker   /*!
232*77c1e3ccSAndroid Build Coastguard Worker    * Array of pointers to the frame buffers holding the tpl reconstructed frame.
233*77c1e3ccSAndroid Build Coastguard Worker    * ref_frame[i] stores the pointer to the tpl reconstructed frame of the ith
234*77c1e3ccSAndroid Build Coastguard Worker    * reference frame type.
235*77c1e3ccSAndroid Build Coastguard Worker    */
236*77c1e3ccSAndroid Build Coastguard Worker   const YV12_BUFFER_CONFIG *ref_frame[INTER_REFS_PER_FRAME];
237*77c1e3ccSAndroid Build Coastguard Worker 
238*77c1e3ccSAndroid Build Coastguard Worker   /*!
239*77c1e3ccSAndroid Build Coastguard Worker    * Parameters related to synchronization for top-right dependency in row based
240*77c1e3ccSAndroid Build Coastguard Worker    * multi-threading of tpl
241*77c1e3ccSAndroid Build Coastguard Worker    */
242*77c1e3ccSAndroid Build Coastguard Worker   AV1TplRowMultiThreadSync tpl_mt_sync;
243*77c1e3ccSAndroid Build Coastguard Worker 
244*77c1e3ccSAndroid Build Coastguard Worker   /*!
245*77c1e3ccSAndroid Build Coastguard Worker    * Frame border for tpl frame.
246*77c1e3ccSAndroid Build Coastguard Worker    */
247*77c1e3ccSAndroid Build Coastguard Worker   int border_in_pixels;
248*77c1e3ccSAndroid Build Coastguard Worker 
249*77c1e3ccSAndroid Build Coastguard Worker   /*!
250*77c1e3ccSAndroid Build Coastguard Worker    * Factor to adjust r0 if TPL uses a subset of frames in the gf group.
251*77c1e3ccSAndroid Build Coastguard Worker    */
252*77c1e3ccSAndroid Build Coastguard Worker   double r0_adjust_factor;
253*77c1e3ccSAndroid Build Coastguard Worker } TplParams;
254*77c1e3ccSAndroid Build Coastguard Worker 
255*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_BITRATE_ACCURACY || CONFIG_RATECTRL_LOG
256*77c1e3ccSAndroid Build Coastguard Worker #define VBR_RC_INFO_MAX_FRAMES 500
257*77c1e3ccSAndroid Build Coastguard Worker #endif  //  CONFIG_BITRATE_ACCURACY || CONFIG_RATECTRL_LOG
258*77c1e3ccSAndroid Build Coastguard Worker 
259*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_BITRATE_ACCURACY
260*77c1e3ccSAndroid Build Coastguard Worker 
261*77c1e3ccSAndroid Build Coastguard Worker /*!
262*77c1e3ccSAndroid Build Coastguard Worker  * \brief This structure stores information needed for bitrate accuracy
263*77c1e3ccSAndroid Build Coastguard Worker  * experiment.
264*77c1e3ccSAndroid Build Coastguard Worker  */
265*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
266*77c1e3ccSAndroid Build Coastguard Worker   int ready;
267*77c1e3ccSAndroid Build Coastguard Worker   double total_bit_budget;  // The total bit budget of the entire video
268*77c1e3ccSAndroid Build Coastguard Worker   int show_frame_count;     // Number of show frames in the entire video
269*77c1e3ccSAndroid Build Coastguard Worker 
270*77c1e3ccSAndroid Build Coastguard Worker   int gop_showframe_count;  // The number of show frames in the current gop
271*77c1e3ccSAndroid Build Coastguard Worker   double gop_bit_budget;    // The bitbudget for the current gop
272*77c1e3ccSAndroid Build Coastguard Worker   double scale_factors[FRAME_UPDATE_TYPES];     // Scale factors to improve the
273*77c1e3ccSAndroid Build Coastguard Worker                                                 // budget estimation
274*77c1e3ccSAndroid Build Coastguard Worker   double mv_scale_factors[FRAME_UPDATE_TYPES];  // Scale factors to improve
275*77c1e3ccSAndroid Build Coastguard Worker                                                 // MV entropy estimation
276*77c1e3ccSAndroid Build Coastguard Worker 
277*77c1e3ccSAndroid Build Coastguard Worker   // === Below this line are GOP related data that will be updated per GOP ===
278*77c1e3ccSAndroid Build Coastguard Worker   int base_q_index;  // Stores the base q index.
279*77c1e3ccSAndroid Build Coastguard Worker   int q_index_list_ready;
280*77c1e3ccSAndroid Build Coastguard Worker   int q_index_list[VBR_RC_INFO_MAX_FRAMES];  // q indices for the current
281*77c1e3ccSAndroid Build Coastguard Worker                                              // GOP
282*77c1e3ccSAndroid Build Coastguard Worker 
283*77c1e3ccSAndroid Build Coastguard Worker   // Array to store qstep_ratio for each frame in a GOP
284*77c1e3ccSAndroid Build Coastguard Worker   double qstep_ratio_list[VBR_RC_INFO_MAX_FRAMES];
285*77c1e3ccSAndroid Build Coastguard Worker 
286*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_THREE_PASS
287*77c1e3ccSAndroid Build Coastguard Worker   TplTxfmStats txfm_stats_list[VBR_RC_INFO_MAX_FRAMES];
288*77c1e3ccSAndroid Build Coastguard Worker   FRAME_UPDATE_TYPE update_type_list[VBR_RC_INFO_MAX_FRAMES];
289*77c1e3ccSAndroid Build Coastguard Worker   int gop_start_idx_list[VBR_RC_INFO_MAX_FRAMES];
290*77c1e3ccSAndroid Build Coastguard Worker   int gop_length_list[VBR_RC_INFO_MAX_FRAMES];
291*77c1e3ccSAndroid Build Coastguard Worker   int cur_gop_idx;
292*77c1e3ccSAndroid Build Coastguard Worker   int total_frame_count;
293*77c1e3ccSAndroid Build Coastguard Worker   int gop_count;
294*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_THREE_PASS
295*77c1e3ccSAndroid Build Coastguard Worker } VBR_RATECTRL_INFO;
296*77c1e3ccSAndroid Build Coastguard Worker 
vbr_rc_reset_gop_data(VBR_RATECTRL_INFO * vbr_rc_info)297*77c1e3ccSAndroid Build Coastguard Worker static inline void vbr_rc_reset_gop_data(VBR_RATECTRL_INFO *vbr_rc_info) {
298*77c1e3ccSAndroid Build Coastguard Worker   vbr_rc_info->q_index_list_ready = 0;
299*77c1e3ccSAndroid Build Coastguard Worker   av1_zero(vbr_rc_info->q_index_list);
300*77c1e3ccSAndroid Build Coastguard Worker }
301*77c1e3ccSAndroid Build Coastguard Worker 
302*77c1e3ccSAndroid Build Coastguard Worker void av1_vbr_rc_init(VBR_RATECTRL_INFO *vbr_rc_info, double total_bit_budget,
303*77c1e3ccSAndroid Build Coastguard Worker                      int show_frame_count);
304*77c1e3ccSAndroid Build Coastguard Worker 
305*77c1e3ccSAndroid Build Coastguard Worker int av1_vbr_rc_frame_coding_idx(const VBR_RATECTRL_INFO *vbr_rc_info,
306*77c1e3ccSAndroid Build Coastguard Worker                                 int gf_frame_index);
307*77c1e3ccSAndroid Build Coastguard Worker 
308*77c1e3ccSAndroid Build Coastguard Worker void av1_vbr_rc_append_tpl_info(VBR_RATECTRL_INFO *vbr_rc_info,
309*77c1e3ccSAndroid Build Coastguard Worker                                 const struct TPL_INFO *tpl_info);
310*77c1e3ccSAndroid Build Coastguard Worker 
311*77c1e3ccSAndroid Build Coastguard Worker void av1_vbr_rc_set_gop_bit_budget(VBR_RATECTRL_INFO *vbr_rc_info,
312*77c1e3ccSAndroid Build Coastguard Worker                                    int gop_showframe_count);
313*77c1e3ccSAndroid Build Coastguard Worker 
314*77c1e3ccSAndroid Build Coastguard Worker void av1_vbr_rc_compute_q_indices(int base_q_index, int frame_count,
315*77c1e3ccSAndroid Build Coastguard Worker                                   const double *qstep_ratio_list,
316*77c1e3ccSAndroid Build Coastguard Worker                                   aom_bit_depth_t bit_depth, int *q_index_list);
317*77c1e3ccSAndroid Build Coastguard Worker 
318*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Update q_index_list in vbr_rc_info based on tpl stats
319*77c1e3ccSAndroid Build Coastguard Worker  *
320*77c1e3ccSAndroid Build Coastguard Worker  * \param[out]      vbr_rc_info    Rate control info for BITRATE_ACCURACY
321*77c1e3ccSAndroid Build Coastguard Worker  *                                 experiment
322*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       tpl_data       TPL struct
323*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       gf_group       GOP struct
324*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       bit_depth      bit depth
325*77c1e3ccSAndroid Build Coastguard Worker  */
326*77c1e3ccSAndroid Build Coastguard Worker void av1_vbr_rc_update_q_index_list(VBR_RATECTRL_INFO *vbr_rc_info,
327*77c1e3ccSAndroid Build Coastguard Worker                                     const TplParams *tpl_data,
328*77c1e3ccSAndroid Build Coastguard Worker                                     const struct GF_GROUP *gf_group,
329*77c1e3ccSAndroid Build Coastguard Worker                                     aom_bit_depth_t bit_depth);
330*77c1e3ccSAndroid Build Coastguard Worker /*
331*77c1e3ccSAndroid Build Coastguard Worker  *!\brief Compute the number of bits needed to encode a GOP
332*77c1e3ccSAndroid Build Coastguard Worker  *
333*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    base_q_index              base layer q_index
334*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    bit_depth                 bit depth
335*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    update_type_scale_factors array of scale factors for each
336*77c1e3ccSAndroid Build Coastguard Worker  *                                         update_type
337*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    frame_count               size of update_type_list,
338*77c1e3ccSAndroid Build Coastguard Worker  *                                         qstep_ratio_list stats_list,
339*77c1e3ccSAndroid Build Coastguard Worker  *                                         q_index_list and
340*77c1e3ccSAndroid Build Coastguard Worker  *                                         estimated_bitrate_byframe
341*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    update_type_list          array of update_type, one per frame
342*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    qstep_ratio_list          array of qstep_ratio, one per frame
343*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    stats_list                array of transform stats, one per
344*77c1e3ccSAndroid Build Coastguard Worker  *                                         frame
345*77c1e3ccSAndroid Build Coastguard Worker  * \param[out]   q_index_list              array of q_index, one per frame
346*77c1e3ccSAndroid Build Coastguard Worker  * \param[out]   estimated_bitrate_byframe array to keep track of frame
347*77c1e3ccSAndroid Build Coastguard Worker  *                                         bitrate
348*77c1e3ccSAndroid Build Coastguard Worker  *
349*77c1e3ccSAndroid Build Coastguard Worker  * \return The estimated GOP bitrate.
350*77c1e3ccSAndroid Build Coastguard Worker  *
351*77c1e3ccSAndroid Build Coastguard Worker  */
352*77c1e3ccSAndroid Build Coastguard Worker double av1_vbr_rc_info_estimate_gop_bitrate(
353*77c1e3ccSAndroid Build Coastguard Worker     int base_q_index, aom_bit_depth_t bit_depth,
354*77c1e3ccSAndroid Build Coastguard Worker     const double *update_type_scale_factors, int frame_count,
355*77c1e3ccSAndroid Build Coastguard Worker     const FRAME_UPDATE_TYPE *update_type_list, const double *qstep_ratio_list,
356*77c1e3ccSAndroid Build Coastguard Worker     const TplTxfmStats *stats_list, int *q_index_list,
357*77c1e3ccSAndroid Build Coastguard Worker     double *estimated_bitrate_byframe);
358*77c1e3ccSAndroid Build Coastguard Worker 
359*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Estimate the optimal base q index for a GOP.
360*77c1e3ccSAndroid Build Coastguard Worker  *
361*77c1e3ccSAndroid Build Coastguard Worker  * This function uses a binary search to find base layer q index to
362*77c1e3ccSAndroid Build Coastguard Worker  * achieve the specified bit budget.
363*77c1e3ccSAndroid Build Coastguard Worker  *
364*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    bit_budget        target bit budget
365*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    bit_depth         bit depth
366*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    update_type_scale_factors array of scale factors for each
367*77c1e3ccSAndroid Build Coastguard Worker  *                                 update_type
368*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    frame_count       size of update_type_list, qstep_ratio_list
369*77c1e3ccSAndroid Build Coastguard Worker  *                                 stats_list, q_index_list and
370*77c1e3ccSAndroid Build Coastguard Worker  *                                 estimated_bitrate_byframe
371*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    update_type_list  array of update_type, one per frame
372*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    qstep_ratio_list  array of qstep_ratio, one per frame
373*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    stats_list        array of transform stats, one per frame
374*77c1e3ccSAndroid Build Coastguard Worker  * \param[out]   q_index_list      array of q_index, one per frame
375*77c1e3ccSAndroid Build Coastguard Worker  * \param[out]   estimated_bitrate_byframe Array to keep track of frame
376*77c1e3ccSAndroid Build Coastguard Worker  * bitrate
377*77c1e3ccSAndroid Build Coastguard Worker  *
378*77c1e3ccSAndroid Build Coastguard Worker  * \return Returns the optimal base q index to use.
379*77c1e3ccSAndroid Build Coastguard Worker  */
380*77c1e3ccSAndroid Build Coastguard Worker int av1_vbr_rc_info_estimate_base_q(
381*77c1e3ccSAndroid Build Coastguard Worker     double bit_budget, aom_bit_depth_t bit_depth,
382*77c1e3ccSAndroid Build Coastguard Worker     const double *update_type_scale_factors, int frame_count,
383*77c1e3ccSAndroid Build Coastguard Worker     const FRAME_UPDATE_TYPE *update_type_list, const double *qstep_ratio_list,
384*77c1e3ccSAndroid Build Coastguard Worker     const TplTxfmStats *stats_list, int *q_index_list,
385*77c1e3ccSAndroid Build Coastguard Worker     double *estimated_bitrate_byframe);
386*77c1e3ccSAndroid Build Coastguard Worker 
387*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_BITRATE_ACCURACY
388*77c1e3ccSAndroid Build Coastguard Worker 
389*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_RD_COMMAND
390*77c1e3ccSAndroid Build Coastguard Worker typedef enum {
391*77c1e3ccSAndroid Build Coastguard Worker   RD_OPTION_NONE,
392*77c1e3ccSAndroid Build Coastguard Worker   RD_OPTION_SET_Q,
393*77c1e3ccSAndroid Build Coastguard Worker   RD_OPTION_SET_Q_RDMULT
394*77c1e3ccSAndroid Build Coastguard Worker } RD_OPTION;
395*77c1e3ccSAndroid Build Coastguard Worker 
396*77c1e3ccSAndroid Build Coastguard Worker typedef struct RD_COMMAND {
397*77c1e3ccSAndroid Build Coastguard Worker   RD_OPTION option_ls[MAX_LENGTH_TPL_FRAME_STATS];
398*77c1e3ccSAndroid Build Coastguard Worker   int q_index_ls[MAX_LENGTH_TPL_FRAME_STATS];
399*77c1e3ccSAndroid Build Coastguard Worker   int rdmult_ls[MAX_LENGTH_TPL_FRAME_STATS];
400*77c1e3ccSAndroid Build Coastguard Worker   int frame_count;
401*77c1e3ccSAndroid Build Coastguard Worker   int frame_index;
402*77c1e3ccSAndroid Build Coastguard Worker } RD_COMMAND;
403*77c1e3ccSAndroid Build Coastguard Worker 
404*77c1e3ccSAndroid Build Coastguard Worker void av1_read_rd_command(const char *filepath, RD_COMMAND *rd_command);
405*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_RD_COMMAND
406*77c1e3ccSAndroid Build Coastguard Worker 
407*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Allocate buffers used by tpl model
408*77c1e3ccSAndroid Build Coastguard Worker  *
409*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    Top-level encode/decode structure
410*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    lag_in_frames  number of lookahead frames
411*77c1e3ccSAndroid Build Coastguard Worker  *
412*77c1e3ccSAndroid Build Coastguard Worker  * \param[out]   tpl_data  tpl data structure
413*77c1e3ccSAndroid Build Coastguard Worker  */
414*77c1e3ccSAndroid Build Coastguard Worker 
415*77c1e3ccSAndroid Build Coastguard Worker void av1_setup_tpl_buffers(struct AV1_PRIMARY *const ppi,
416*77c1e3ccSAndroid Build Coastguard Worker                            CommonModeInfoParams *const mi_params, int width,
417*77c1e3ccSAndroid Build Coastguard Worker                            int height, int byte_alignment, int lag_in_frames);
418*77c1e3ccSAndroid Build Coastguard Worker 
tpl_dealloc_temp_buffers(TplBuffers * tpl_tmp_buffers)419*77c1e3ccSAndroid Build Coastguard Worker static inline void tpl_dealloc_temp_buffers(TplBuffers *tpl_tmp_buffers) {
420*77c1e3ccSAndroid Build Coastguard Worker   aom_free(tpl_tmp_buffers->predictor8);
421*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->predictor8 = NULL;
422*77c1e3ccSAndroid Build Coastguard Worker   aom_free(tpl_tmp_buffers->src_diff);
423*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->src_diff = NULL;
424*77c1e3ccSAndroid Build Coastguard Worker   aom_free(tpl_tmp_buffers->coeff);
425*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->coeff = NULL;
426*77c1e3ccSAndroid Build Coastguard Worker   aom_free(tpl_tmp_buffers->qcoeff);
427*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->qcoeff = NULL;
428*77c1e3ccSAndroid Build Coastguard Worker   aom_free(tpl_tmp_buffers->dqcoeff);
429*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->dqcoeff = NULL;
430*77c1e3ccSAndroid Build Coastguard Worker }
431*77c1e3ccSAndroid Build Coastguard Worker 
tpl_alloc_temp_buffers(TplBuffers * tpl_tmp_buffers,uint8_t tpl_bsize_1d)432*77c1e3ccSAndroid Build Coastguard Worker static inline bool tpl_alloc_temp_buffers(TplBuffers *tpl_tmp_buffers,
433*77c1e3ccSAndroid Build Coastguard Worker                                           uint8_t tpl_bsize_1d) {
434*77c1e3ccSAndroid Build Coastguard Worker   // Number of pixels in a tpl block
435*77c1e3ccSAndroid Build Coastguard Worker   const int tpl_block_pels = tpl_bsize_1d * tpl_bsize_1d;
436*77c1e3ccSAndroid Build Coastguard Worker 
437*77c1e3ccSAndroid Build Coastguard Worker   // Allocate temporary buffers used in mode estimation.
438*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->predictor8 = (uint8_t *)aom_memalign(
439*77c1e3ccSAndroid Build Coastguard Worker       32, tpl_block_pels * 2 * sizeof(*tpl_tmp_buffers->predictor8));
440*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->src_diff = (int16_t *)aom_memalign(
441*77c1e3ccSAndroid Build Coastguard Worker       32, tpl_block_pels * sizeof(*tpl_tmp_buffers->src_diff));
442*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->coeff = (tran_low_t *)aom_memalign(
443*77c1e3ccSAndroid Build Coastguard Worker       32, tpl_block_pels * sizeof(*tpl_tmp_buffers->coeff));
444*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->qcoeff = (tran_low_t *)aom_memalign(
445*77c1e3ccSAndroid Build Coastguard Worker       32, tpl_block_pels * sizeof(*tpl_tmp_buffers->qcoeff));
446*77c1e3ccSAndroid Build Coastguard Worker   tpl_tmp_buffers->dqcoeff = (tran_low_t *)aom_memalign(
447*77c1e3ccSAndroid Build Coastguard Worker       32, tpl_block_pels * sizeof(*tpl_tmp_buffers->dqcoeff));
448*77c1e3ccSAndroid Build Coastguard Worker 
449*77c1e3ccSAndroid Build Coastguard Worker   if (!(tpl_tmp_buffers->predictor8 && tpl_tmp_buffers->src_diff &&
450*77c1e3ccSAndroid Build Coastguard Worker         tpl_tmp_buffers->coeff && tpl_tmp_buffers->qcoeff &&
451*77c1e3ccSAndroid Build Coastguard Worker         tpl_tmp_buffers->dqcoeff)) {
452*77c1e3ccSAndroid Build Coastguard Worker     tpl_dealloc_temp_buffers(tpl_tmp_buffers);
453*77c1e3ccSAndroid Build Coastguard Worker     return false;
454*77c1e3ccSAndroid Build Coastguard Worker   }
455*77c1e3ccSAndroid Build Coastguard Worker   return true;
456*77c1e3ccSAndroid Build Coastguard Worker }
457*77c1e3ccSAndroid Build Coastguard Worker 
458*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Implements temporal dependency modelling for a GOP (GF/ARF
459*77c1e3ccSAndroid Build Coastguard Worker  * group) and selects between 16 and 32 frame GOP structure.
460*77c1e3ccSAndroid Build Coastguard Worker  *
461*77c1e3ccSAndroid Build Coastguard Worker  *\ingroup tpl_modelling
462*77c1e3ccSAndroid Build Coastguard Worker  *
463*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    cpi           Top - level encoder instance structure
464*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    gop_eval      Flag if it is in the GOP length decision stage
465*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    frame_params  Per frame encoding parameters
466*77c1e3ccSAndroid Build Coastguard Worker  *
467*77c1e3ccSAndroid Build Coastguard Worker  * \return Indicates whether or not we should use a longer GOP length.
468*77c1e3ccSAndroid Build Coastguard Worker  */
469*77c1e3ccSAndroid Build Coastguard Worker int av1_tpl_setup_stats(struct AV1_COMP *cpi, int gop_eval,
470*77c1e3ccSAndroid Build Coastguard Worker                         const struct EncodeFrameParams *const frame_params);
471*77c1e3ccSAndroid Build Coastguard Worker 
472*77c1e3ccSAndroid Build Coastguard Worker /*!\cond */
473*77c1e3ccSAndroid Build Coastguard Worker 
474*77c1e3ccSAndroid Build Coastguard Worker void av1_tpl_preload_rc_estimate(
475*77c1e3ccSAndroid Build Coastguard Worker     struct AV1_COMP *cpi, const struct EncodeFrameParams *const frame_params);
476*77c1e3ccSAndroid Build Coastguard Worker 
477*77c1e3ccSAndroid Build Coastguard Worker int av1_tpl_ptr_pos(int mi_row, int mi_col, int stride, uint8_t right_shift);
478*77c1e3ccSAndroid Build Coastguard Worker 
479*77c1e3ccSAndroid Build Coastguard Worker void av1_init_tpl_stats(TplParams *const tpl_data);
480*77c1e3ccSAndroid Build Coastguard Worker 
481*77c1e3ccSAndroid Build Coastguard Worker int av1_tpl_stats_ready(const TplParams *tpl_data, int gf_frame_index);
482*77c1e3ccSAndroid Build Coastguard Worker 
483*77c1e3ccSAndroid Build Coastguard Worker void av1_tpl_rdmult_setup(struct AV1_COMP *cpi);
484*77c1e3ccSAndroid Build Coastguard Worker 
485*77c1e3ccSAndroid Build Coastguard Worker void av1_tpl_rdmult_setup_sb(struct AV1_COMP *cpi, MACROBLOCK *const x,
486*77c1e3ccSAndroid Build Coastguard Worker                              BLOCK_SIZE sb_size, int mi_row, int mi_col);
487*77c1e3ccSAndroid Build Coastguard Worker 
488*77c1e3ccSAndroid Build Coastguard Worker void av1_mc_flow_dispenser_row(struct AV1_COMP *cpi,
489*77c1e3ccSAndroid Build Coastguard Worker                                TplTxfmStats *tpl_txfm_stats,
490*77c1e3ccSAndroid Build Coastguard Worker                                TplBuffers *tpl_tmp_buffers, MACROBLOCK *x,
491*77c1e3ccSAndroid Build Coastguard Worker                                int mi_row, BLOCK_SIZE bsize, TX_SIZE tx_size);
492*77c1e3ccSAndroid Build Coastguard Worker 
493*77c1e3ccSAndroid Build Coastguard Worker /*!\brief  Compute the entropy of an exponential probability distribution
494*77c1e3ccSAndroid Build Coastguard Worker  * function (pdf) subjected to uniform quantization.
495*77c1e3ccSAndroid Build Coastguard Worker  *
496*77c1e3ccSAndroid Build Coastguard Worker  * pdf(x) = b*exp(-b*x)
497*77c1e3ccSAndroid Build Coastguard Worker  *
498*77c1e3ccSAndroid Build Coastguard Worker  *\ingroup tpl_modelling
499*77c1e3ccSAndroid Build Coastguard Worker  *
500*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    q_step        quantizer step size
501*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    b             parameter of exponential distribution
502*77c1e3ccSAndroid Build Coastguard Worker  *
503*77c1e3ccSAndroid Build Coastguard Worker  * \return entropy cost
504*77c1e3ccSAndroid Build Coastguard Worker  */
505*77c1e3ccSAndroid Build Coastguard Worker double av1_exponential_entropy(double q_step, double b);
506*77c1e3ccSAndroid Build Coastguard Worker 
507*77c1e3ccSAndroid Build Coastguard Worker /*!\brief  Compute the entropy of a Laplace probability distribution
508*77c1e3ccSAndroid Build Coastguard Worker  * function (pdf) subjected to non-uniform quantization.
509*77c1e3ccSAndroid Build Coastguard Worker  *
510*77c1e3ccSAndroid Build Coastguard Worker  * pdf(x) = 0.5*b*exp(-0.5*b*|x|)
511*77c1e3ccSAndroid Build Coastguard Worker  *
512*77c1e3ccSAndroid Build Coastguard Worker  *\ingroup tpl_modelling
513*77c1e3ccSAndroid Build Coastguard Worker  *
514*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    q_step          quantizer step size for non-zero bins
515*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    b               parameter of Laplace distribution
516*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    zero_bin_ratio  zero bin's size is zero_bin_ratio * q_step
517*77c1e3ccSAndroid Build Coastguard Worker  *
518*77c1e3ccSAndroid Build Coastguard Worker  * \return entropy cost
519*77c1e3ccSAndroid Build Coastguard Worker  */
520*77c1e3ccSAndroid Build Coastguard Worker double av1_laplace_entropy(double q_step, double b, double zero_bin_ratio);
521*77c1e3ccSAndroid Build Coastguard Worker 
522*77c1e3ccSAndroid Build Coastguard Worker /*!\brief  Compute the frame rate using transform block stats
523*77c1e3ccSAndroid Build Coastguard Worker  *
524*77c1e3ccSAndroid Build Coastguard Worker  * Assume each position i in the transform block is of Laplace distribution
525*77c1e3ccSAndroid Build Coastguard Worker  * with mean absolute deviation abs_coeff_mean[i]
526*77c1e3ccSAndroid Build Coastguard Worker  *
527*77c1e3ccSAndroid Build Coastguard Worker  * Then we can use av1_laplace_entropy() to compute the expected frame
528*77c1e3ccSAndroid Build Coastguard Worker  * rate.
529*77c1e3ccSAndroid Build Coastguard Worker  *
530*77c1e3ccSAndroid Build Coastguard Worker  *\ingroup tpl_modelling
531*77c1e3ccSAndroid Build Coastguard Worker  *
532*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    q_index         quantizer index
533*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    block_count     number of transform blocks
534*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    abs_coeff_mean  array of mean absolute deviation
535*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    coeff_num       number of coefficients per transform block
536*77c1e3ccSAndroid Build Coastguard Worker  *
537*77c1e3ccSAndroid Build Coastguard Worker  * \return expected frame rate
538*77c1e3ccSAndroid Build Coastguard Worker  */
539*77c1e3ccSAndroid Build Coastguard Worker double av1_laplace_estimate_frame_rate(int q_index, int block_count,
540*77c1e3ccSAndroid Build Coastguard Worker                                        const double *abs_coeff_mean,
541*77c1e3ccSAndroid Build Coastguard Worker                                        int coeff_num);
542*77c1e3ccSAndroid Build Coastguard Worker 
543*77c1e3ccSAndroid Build Coastguard Worker /*
544*77c1e3ccSAndroid Build Coastguard Worker  *!\brief Init TplTxfmStats
545*77c1e3ccSAndroid Build Coastguard Worker  *
546*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    tpl_txfm_stats  a structure for storing transform stats
547*77c1e3ccSAndroid Build Coastguard Worker  *
548*77c1e3ccSAndroid Build Coastguard Worker  */
549*77c1e3ccSAndroid Build Coastguard Worker void av1_init_tpl_txfm_stats(TplTxfmStats *tpl_txfm_stats);
550*77c1e3ccSAndroid Build Coastguard Worker 
551*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_BITRATE_ACCURACY
552*77c1e3ccSAndroid Build Coastguard Worker /*
553*77c1e3ccSAndroid Build Coastguard Worker  *!\brief Accumulate TplTxfmStats
554*77c1e3ccSAndroid Build Coastguard Worker  *
555*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]  sub_stats          a structure for storing sub transform stats
556*77c1e3ccSAndroid Build Coastguard Worker  * \param[out] accumulated_stats  a structure for storing accumulated
557*77c1e3ccSAndroid Build Coastguard Worker  *transform stats
558*77c1e3ccSAndroid Build Coastguard Worker  *
559*77c1e3ccSAndroid Build Coastguard Worker  */
560*77c1e3ccSAndroid Build Coastguard Worker void av1_accumulate_tpl_txfm_stats(const TplTxfmStats *sub_stats,
561*77c1e3ccSAndroid Build Coastguard Worker                                    TplTxfmStats *accumulated_stats);
562*77c1e3ccSAndroid Build Coastguard Worker 
563*77c1e3ccSAndroid Build Coastguard Worker /*
564*77c1e3ccSAndroid Build Coastguard Worker  *!\brief Record a transform block into  TplTxfmStats
565*77c1e3ccSAndroid Build Coastguard Worker  *
566*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]  tpl_txfm_stats     A structure for storing transform stats
567*77c1e3ccSAndroid Build Coastguard Worker  * \param[out] coeff              An array of transform coefficients. Its size
568*77c1e3ccSAndroid Build Coastguard Worker  *                                should equal to tpl_txfm_stats.coeff_num.
569*77c1e3ccSAndroid Build Coastguard Worker  *
570*77c1e3ccSAndroid Build Coastguard Worker  */
571*77c1e3ccSAndroid Build Coastguard Worker void av1_record_tpl_txfm_block(TplTxfmStats *tpl_txfm_stats,
572*77c1e3ccSAndroid Build Coastguard Worker                                const tran_low_t *coeff);
573*77c1e3ccSAndroid Build Coastguard Worker 
574*77c1e3ccSAndroid Build Coastguard Worker /*
575*77c1e3ccSAndroid Build Coastguard Worker  *!\brief Update abs_coeff_mean and ready of txfm_stats
576*77c1e3ccSAndroid Build Coastguard Worker  * If txfm_block_count > 0, this function will use abs_coeff_sum and
577*77c1e3ccSAndroid Build Coastguard Worker  * txfm_block_count to compute abs_coeff_mean. Moreover, reday flag
578*77c1e3ccSAndroid Build Coastguard Worker  * will be set to one.
579*77c1e3ccSAndroid Build Coastguard Worker  *
580*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]  txfm_stats     A structure for storing transform stats
581*77c1e3ccSAndroid Build Coastguard Worker  */
582*77c1e3ccSAndroid Build Coastguard Worker void av1_tpl_txfm_stats_update_abs_coeff_mean(TplTxfmStats *txfm_stats);
583*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_BITRATE_ACCURACY
584*77c1e3ccSAndroid Build Coastguard Worker 
585*77c1e3ccSAndroid Build Coastguard Worker /*!\brief  Estimate coefficient entropy using Laplace dsitribution
586*77c1e3ccSAndroid Build Coastguard Worker  *
587*77c1e3ccSAndroid Build Coastguard Worker  *\ingroup tpl_modelling
588*77c1e3ccSAndroid Build Coastguard Worker  *
589*77c1e3ccSAndroid Build Coastguard Worker  * This function is equivalent to -log2(laplace_prob()), where laplace_prob()
590*77c1e3ccSAndroid Build Coastguard Worker  *is defined in tpl_model_test.cc
591*77c1e3ccSAndroid Build Coastguard Worker  *
592*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    q_step          quantizer step size without any scaling
593*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    b               mean absolute deviation of Laplace
594*77c1e3ccSAndroid Build Coastguard Worker  *distribution \param[in]    zero_bin_ratio  zero bin's size is zero_bin_ratio
595*77c1e3ccSAndroid Build Coastguard Worker  ** q_step \param[in]    qcoeff          quantized coefficient
596*77c1e3ccSAndroid Build Coastguard Worker  *
597*77c1e3ccSAndroid Build Coastguard Worker  * \return estimated coefficient entropy
598*77c1e3ccSAndroid Build Coastguard Worker  *
599*77c1e3ccSAndroid Build Coastguard Worker  */
600*77c1e3ccSAndroid Build Coastguard Worker double av1_estimate_coeff_entropy(double q_step, double b,
601*77c1e3ccSAndroid Build Coastguard Worker                                   double zero_bin_ratio, int qcoeff);
602*77c1e3ccSAndroid Build Coastguard Worker 
603*77c1e3ccSAndroid Build Coastguard Worker // TODO(angiebird): Add doxygen description here.
604*77c1e3ccSAndroid Build Coastguard Worker int64_t av1_delta_rate_cost(int64_t delta_rate, int64_t recrf_dist,
605*77c1e3ccSAndroid Build Coastguard Worker                             int64_t srcrf_dist, int pix_num);
606*77c1e3ccSAndroid Build Coastguard Worker 
607*77c1e3ccSAndroid Build Coastguard Worker /*!\brief  Compute the overlap area between two blocks with the same size
608*77c1e3ccSAndroid Build Coastguard Worker  *
609*77c1e3ccSAndroid Build Coastguard Worker  *\ingroup tpl_modelling
610*77c1e3ccSAndroid Build Coastguard Worker  *
611*77c1e3ccSAndroid Build Coastguard Worker  * If there is no overlap, this function should return zero.
612*77c1e3ccSAndroid Build Coastguard Worker  *
613*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    row_a  row position of the first block
614*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    col_a  column position of the first block
615*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    row_b  row position of the second block
616*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    col_b  column position of the second block
617*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    width  width shared by the two blocks
618*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]    height height shared by the two blocks
619*77c1e3ccSAndroid Build Coastguard Worker  *
620*77c1e3ccSAndroid Build Coastguard Worker  * \return overlap area of the two blocks
621*77c1e3ccSAndroid Build Coastguard Worker  */
622*77c1e3ccSAndroid Build Coastguard Worker int av1_get_overlap_area(int row_a, int col_a, int row_b, int col_b, int width,
623*77c1e3ccSAndroid Build Coastguard Worker                          int height);
624*77c1e3ccSAndroid Build Coastguard Worker 
625*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Get current frame's q_index from tpl stats and leaf_qindex
626*77c1e3ccSAndroid Build Coastguard Worker  *
627*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       tpl_data          TPL struct
628*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       gf_frame_index    current frame index in the GOP
629*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       leaf_qindex       q index of leaf frame
630*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       bit_depth         bit depth
631*77c1e3ccSAndroid Build Coastguard Worker  *
632*77c1e3ccSAndroid Build Coastguard Worker  * \return q_index
633*77c1e3ccSAndroid Build Coastguard Worker  */
634*77c1e3ccSAndroid Build Coastguard Worker int av1_tpl_get_q_index(const TplParams *tpl_data, int gf_frame_index,
635*77c1e3ccSAndroid Build Coastguard Worker                         int leaf_qindex, aom_bit_depth_t bit_depth);
636*77c1e3ccSAndroid Build Coastguard Worker 
637*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Compute the frame importance from TPL stats
638*77c1e3ccSAndroid Build Coastguard Worker  *
639*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       tpl_data          TPL struct
640*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       gf_frame_index    current frame index in the GOP
641*77c1e3ccSAndroid Build Coastguard Worker  *
642*77c1e3ccSAndroid Build Coastguard Worker  * \return frame_importance
643*77c1e3ccSAndroid Build Coastguard Worker  */
644*77c1e3ccSAndroid Build Coastguard Worker double av1_tpl_get_frame_importance(const TplParams *tpl_data,
645*77c1e3ccSAndroid Build Coastguard Worker                                     int gf_frame_index);
646*77c1e3ccSAndroid Build Coastguard Worker 
647*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Compute the ratio between arf q step and the leaf q step based on
648*77c1e3ccSAndroid Build Coastguard Worker  * TPL stats
649*77c1e3ccSAndroid Build Coastguard Worker  *
650*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       tpl_data          TPL struct
651*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       gf_frame_index    current frame index in the GOP
652*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       leaf_qindex       q index of leaf frame
653*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       bit_depth         bit depth
654*77c1e3ccSAndroid Build Coastguard Worker  *
655*77c1e3ccSAndroid Build Coastguard Worker  * \return qstep_ratio
656*77c1e3ccSAndroid Build Coastguard Worker  */
657*77c1e3ccSAndroid Build Coastguard Worker double av1_tpl_get_qstep_ratio(const TplParams *tpl_data, int gf_frame_index);
658*77c1e3ccSAndroid Build Coastguard Worker 
659*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Find a q index whose step size is near qstep_ratio * leaf_qstep
660*77c1e3ccSAndroid Build Coastguard Worker  *
661*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       leaf_qindex       q index of leaf frame
662*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       qstep_ratio       step ratio between target q index and
663*77c1e3ccSAndroid Build Coastguard Worker  * leaf q index \param[in]       bit_depth         bit depth
664*77c1e3ccSAndroid Build Coastguard Worker  *
665*77c1e3ccSAndroid Build Coastguard Worker  * \return q_index
666*77c1e3ccSAndroid Build Coastguard Worker  */
667*77c1e3ccSAndroid Build Coastguard Worker int av1_get_q_index_from_qstep_ratio(int leaf_qindex, double qstep_ratio,
668*77c1e3ccSAndroid Build Coastguard Worker                                      aom_bit_depth_t bit_depth);
669*77c1e3ccSAndroid Build Coastguard Worker 
670*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Improve the motion vector estimation by taking neighbors into
671*77c1e3ccSAndroid Build Coastguard Worker  * account.
672*77c1e3ccSAndroid Build Coastguard Worker  *
673*77c1e3ccSAndroid Build Coastguard Worker  * Use the upper and left neighbor block as the reference MVs.
674*77c1e3ccSAndroid Build Coastguard Worker  * Compute the minimum difference between current MV and reference MV.
675*77c1e3ccSAndroid Build Coastguard Worker  *
676*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       tpl_frame         Tpl frame struct
677*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       row               Current row
678*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       col               Current column
679*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       step              Step parameter for av1_tpl_ptr_pos
680*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       tpl_stride        Stride parameter for av1_tpl_ptr_pos
681*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       right_shift       Right shift parameter for
682*77c1e3ccSAndroid Build Coastguard Worker  * av1_tpl_ptr_pos
683*77c1e3ccSAndroid Build Coastguard Worker  */
684*77c1e3ccSAndroid Build Coastguard Worker int_mv av1_compute_mv_difference(const TplDepFrame *tpl_frame, int row, int col,
685*77c1e3ccSAndroid Build Coastguard Worker                                  int step, int tpl_stride, int right_shift);
686*77c1e3ccSAndroid Build Coastguard Worker 
687*77c1e3ccSAndroid Build Coastguard Worker /*!\brief Compute the entropy of motion vectors for a single frame.
688*77c1e3ccSAndroid Build Coastguard Worker  *
689*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       tpl_frame         TPL frame struct
690*77c1e3ccSAndroid Build Coastguard Worker  * \param[in]       right_shift       right shift value for step
691*77c1e3ccSAndroid Build Coastguard Worker  *
692*77c1e3ccSAndroid Build Coastguard Worker  * \return Bits used by the motion vectors for one frame.
693*77c1e3ccSAndroid Build Coastguard Worker  */
694*77c1e3ccSAndroid Build Coastguard Worker double av1_tpl_compute_frame_mv_entropy(const TplDepFrame *tpl_frame,
695*77c1e3ccSAndroid Build Coastguard Worker                                         uint8_t right_shift);
696*77c1e3ccSAndroid Build Coastguard Worker 
697*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_RATECTRL_LOG
698*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
699*77c1e3ccSAndroid Build Coastguard Worker   int coding_frame_count;
700*77c1e3ccSAndroid Build Coastguard Worker   int base_q_index;
701*77c1e3ccSAndroid Build Coastguard Worker 
702*77c1e3ccSAndroid Build Coastguard Worker   // Encode decision
703*77c1e3ccSAndroid Build Coastguard Worker   int q_index_list[VBR_RC_INFO_MAX_FRAMES];
704*77c1e3ccSAndroid Build Coastguard Worker   double qstep_ratio_list[VBR_RC_INFO_MAX_FRAMES];
705*77c1e3ccSAndroid Build Coastguard Worker   FRAME_UPDATE_TYPE update_type_list[VBR_RC_INFO_MAX_FRAMES];
706*77c1e3ccSAndroid Build Coastguard Worker 
707*77c1e3ccSAndroid Build Coastguard Worker   // Frame stats
708*77c1e3ccSAndroid Build Coastguard Worker   TplTxfmStats txfm_stats_list[VBR_RC_INFO_MAX_FRAMES];
709*77c1e3ccSAndroid Build Coastguard Worker 
710*77c1e3ccSAndroid Build Coastguard Worker   // Estimated encode results
711*77c1e3ccSAndroid Build Coastguard Worker   double est_coeff_rate_list[VBR_RC_INFO_MAX_FRAMES];
712*77c1e3ccSAndroid Build Coastguard Worker 
713*77c1e3ccSAndroid Build Coastguard Worker   // Actual encode results
714*77c1e3ccSAndroid Build Coastguard Worker   double act_rate_list[VBR_RC_INFO_MAX_FRAMES];
715*77c1e3ccSAndroid Build Coastguard Worker   double act_coeff_rate_list[VBR_RC_INFO_MAX_FRAMES];
716*77c1e3ccSAndroid Build Coastguard Worker } RATECTRL_LOG;
717*77c1e3ccSAndroid Build Coastguard Worker 
rc_log_init(RATECTRL_LOG * rc_log)718*77c1e3ccSAndroid Build Coastguard Worker static inline void rc_log_init(RATECTRL_LOG *rc_log) { av1_zero(*rc_log); }
719*77c1e3ccSAndroid Build Coastguard Worker 
rc_log_frame_stats(RATECTRL_LOG * rc_log,int coding_index,const TplTxfmStats * txfm_stats)720*77c1e3ccSAndroid Build Coastguard Worker static inline void rc_log_frame_stats(RATECTRL_LOG *rc_log, int coding_index,
721*77c1e3ccSAndroid Build Coastguard Worker                                       const TplTxfmStats *txfm_stats) {
722*77c1e3ccSAndroid Build Coastguard Worker   rc_log->txfm_stats_list[coding_index] = *txfm_stats;
723*77c1e3ccSAndroid Build Coastguard Worker }
724*77c1e3ccSAndroid Build Coastguard Worker 
rc_log_frame_encode_param(RATECTRL_LOG * rc_log,int coding_index,double qstep_ratio,int q_index,FRAME_UPDATE_TYPE update_type)725*77c1e3ccSAndroid Build Coastguard Worker static inline void rc_log_frame_encode_param(RATECTRL_LOG *rc_log,
726*77c1e3ccSAndroid Build Coastguard Worker                                              int coding_index,
727*77c1e3ccSAndroid Build Coastguard Worker                                              double qstep_ratio, int q_index,
728*77c1e3ccSAndroid Build Coastguard Worker                                              FRAME_UPDATE_TYPE update_type) {
729*77c1e3ccSAndroid Build Coastguard Worker   rc_log->qstep_ratio_list[coding_index] = qstep_ratio;
730*77c1e3ccSAndroid Build Coastguard Worker   rc_log->q_index_list[coding_index] = q_index;
731*77c1e3ccSAndroid Build Coastguard Worker   rc_log->update_type_list[coding_index] = update_type;
732*77c1e3ccSAndroid Build Coastguard Worker   const TplTxfmStats *txfm_stats = &rc_log->txfm_stats_list[coding_index];
733*77c1e3ccSAndroid Build Coastguard Worker   rc_log->est_coeff_rate_list[coding_index] = 0;
734*77c1e3ccSAndroid Build Coastguard Worker   if (txfm_stats->ready) {
735*77c1e3ccSAndroid Build Coastguard Worker     rc_log->est_coeff_rate_list[coding_index] = av1_laplace_estimate_frame_rate(
736*77c1e3ccSAndroid Build Coastguard Worker         q_index, txfm_stats->txfm_block_count, txfm_stats->abs_coeff_mean,
737*77c1e3ccSAndroid Build Coastguard Worker         txfm_stats->coeff_num);
738*77c1e3ccSAndroid Build Coastguard Worker   }
739*77c1e3ccSAndroid Build Coastguard Worker }
740*77c1e3ccSAndroid Build Coastguard Worker 
rc_log_frame_entropy(RATECTRL_LOG * rc_log,int coding_index,double act_rate,double act_coeff_rate)741*77c1e3ccSAndroid Build Coastguard Worker static inline void rc_log_frame_entropy(RATECTRL_LOG *rc_log, int coding_index,
742*77c1e3ccSAndroid Build Coastguard Worker                                         double act_rate,
743*77c1e3ccSAndroid Build Coastguard Worker                                         double act_coeff_rate) {
744*77c1e3ccSAndroid Build Coastguard Worker   rc_log->act_rate_list[coding_index] = act_rate;
745*77c1e3ccSAndroid Build Coastguard Worker   rc_log->act_coeff_rate_list[coding_index] = act_coeff_rate;
746*77c1e3ccSAndroid Build Coastguard Worker }
747*77c1e3ccSAndroid Build Coastguard Worker 
rc_log_record_chunk_info(RATECTRL_LOG * rc_log,int base_q_index,int coding_frame_count)748*77c1e3ccSAndroid Build Coastguard Worker static inline void rc_log_record_chunk_info(RATECTRL_LOG *rc_log,
749*77c1e3ccSAndroid Build Coastguard Worker                                             int base_q_index,
750*77c1e3ccSAndroid Build Coastguard Worker                                             int coding_frame_count) {
751*77c1e3ccSAndroid Build Coastguard Worker   rc_log->base_q_index = base_q_index;
752*77c1e3ccSAndroid Build Coastguard Worker   rc_log->coding_frame_count = coding_frame_count;
753*77c1e3ccSAndroid Build Coastguard Worker }
754*77c1e3ccSAndroid Build Coastguard Worker 
rc_log_show(const RATECTRL_LOG * rc_log)755*77c1e3ccSAndroid Build Coastguard Worker static inline void rc_log_show(const RATECTRL_LOG *rc_log) {
756*77c1e3ccSAndroid Build Coastguard Worker   printf("= chunk 1\n");
757*77c1e3ccSAndroid Build Coastguard Worker   printf("coding_frame_count %d base_q_index %d\n", rc_log->coding_frame_count,
758*77c1e3ccSAndroid Build Coastguard Worker          rc_log->base_q_index);
759*77c1e3ccSAndroid Build Coastguard Worker   printf("= frame %d\n", rc_log->coding_frame_count);
760*77c1e3ccSAndroid Build Coastguard Worker   for (int coding_idx = 0; coding_idx < rc_log->coding_frame_count;
761*77c1e3ccSAndroid Build Coastguard Worker        coding_idx++) {
762*77c1e3ccSAndroid Build Coastguard Worker     printf(
763*77c1e3ccSAndroid Build Coastguard Worker         "coding_idx %d update_type %d q %d qstep_ratio %f est_coeff_rate %f "
764*77c1e3ccSAndroid Build Coastguard Worker         "act_coeff_rate %f act_rate %f\n",
765*77c1e3ccSAndroid Build Coastguard Worker         coding_idx, rc_log->update_type_list[coding_idx],
766*77c1e3ccSAndroid Build Coastguard Worker         rc_log->q_index_list[coding_idx], rc_log->qstep_ratio_list[coding_idx],
767*77c1e3ccSAndroid Build Coastguard Worker         rc_log->est_coeff_rate_list[coding_idx],
768*77c1e3ccSAndroid Build Coastguard Worker         rc_log->act_coeff_rate_list[coding_idx],
769*77c1e3ccSAndroid Build Coastguard Worker         rc_log->act_rate_list[coding_idx]);
770*77c1e3ccSAndroid Build Coastguard Worker   }
771*77c1e3ccSAndroid Build Coastguard Worker }
772*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_RATECTRL_LOG
773*77c1e3ccSAndroid Build Coastguard Worker 
774*77c1e3ccSAndroid Build Coastguard Worker /*!\endcond */
775*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
776*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
777*77c1e3ccSAndroid Build Coastguard Worker #endif
778*77c1e3ccSAndroid Build Coastguard Worker 
779*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AV1_ENCODER_TPL_MODEL_H_
780