Coverage Report

Created: 2026-04-01 07:49

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