Coverage Report

Created: 2026-05-24 07:45

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
  // width and height here is in the unit of 16x16 block.
154
  int width;
155
  int height;
156
  int mi_rows;
157
  int mi_cols;
158
  int base_rdmult;
159
  uint32_t frame_display_index;
160
  // When set, SAD metric is used for intra and inter mode decision.
161
  int use_pred_sad;
162
} TplDepFrame;
163
164
/*!\endcond */
165
/*!
166
 * \brief Params related to temporal dependency model.
167
 */
168
typedef struct TplParams {
169
  /*!
170
   * Whether the tpl stats is ready.
171
   */
172
  int ready;
173
174
  /*!
175
   * Block granularity of tpl score storage.
176
   */
177
  uint8_t tpl_stats_block_mis_log2;
178
179
  /*!
180
   * Tpl motion estimation block 1d size. tpl_bsize_1d >= 16.
181
   */
182
  uint8_t tpl_bsize_1d;
183
184
  /*!
185
   * Buffer to store the frame level tpl information for each frame in a gf
186
   * group. tpl_stats_buffer[i] stores the tpl information of ith frame in a gf
187
   * group
188
   */
189
  TplDepFrame tpl_stats_buffer[MAX_LENGTH_TPL_FRAME_STATS];
190
191
  /*!
192
   * Buffer to store tpl stats at block granularity.
193
   * tpl_stats_pool[i][j] stores the tpl stats of jth block of ith frame in a gf
194
   * group.
195
   */
196
  TplDepStats *tpl_stats_pool[MAX_LAG_BUFFERS];
197
198
  /*!
199
   * Pointer to the buffer which stores tpl transform stats per frame.
200
   * txfm_stats_list[i] stores the TplTxfmStats of the ith frame in a gf group.
201
   * Memory is allocated dynamically for MAX_LENGTH_TPL_FRAME_STATS frames when
202
   * tpl is enabled.
203
   */
204
  TplTxfmStats *txfm_stats_list;
205
206
  /*!
207
   * Buffer to store tpl reconstructed frame.
208
   * tpl_rec_pool[i] stores the reconstructed frame of ith frame in a gf group.
209
   */
210
  YV12_BUFFER_CONFIG tpl_rec_pool[MAX_LAG_BUFFERS];
211
212
  /*!
213
   * Pointer to tpl_stats_buffer.
214
   */
215
  TplDepFrame *tpl_frame;
216
217
  /*!
218
   * Scale factors for the current frame.
219
   */
220
  struct scale_factors sf;
221
222
  /*!
223
   * GF group index of the current frame.
224
   */
225
  int frame_idx;
226
227
  /*!
228
   * Array of pointers to the frame buffers holding the source frame.
229
   * src_ref_frame[i] stores the pointer to the source frame of the ith
230
   * reference frame type.
231
   */
232
  const YV12_BUFFER_CONFIG *src_ref_frame[INTER_REFS_PER_FRAME];
233
234
  /*!
235
   * Array of pointers to the frame buffers holding the tpl reconstructed frame.
236
   * ref_frame[i] stores the pointer to the tpl reconstructed frame of the ith
237
   * reference frame type.
238
   */
239
  const YV12_BUFFER_CONFIG *ref_frame[INTER_REFS_PER_FRAME];
240
241
  /*!
242
   * The buffer for the past gop's last frame's src.
243
   */
244
  YV12_BUFFER_CONFIG prev_gop_arf_src;
245
246
  /*!
247
   * Display order of the past gop's last frame.
248
   */
249
  int64_t prev_gop_arf_disp_order;
250
251
  /*!
252
   * Parameters related to synchronization for top-right dependency in row based
253
   * multi-threading of tpl
254
   */
255
  AV1TplRowMultiThreadSync tpl_mt_sync;
256
257
  /*!
258
   * Frame border for tpl frame.
259
   */
260
  int border_in_pixels;
261
262
  /*!
263
   * Factor to adjust r0 if TPL uses a subset of frames in the gf group.
264
   */
265
  double r0_adjust_factor;
266
} TplParams;
267
268
#if CONFIG_BITRATE_ACCURACY || CONFIG_RATECTRL_LOG
269
#define VBR_RC_INFO_MAX_FRAMES 500
270
#endif  //  CONFIG_BITRATE_ACCURACY || CONFIG_RATECTRL_LOG
271
272
#if CONFIG_BITRATE_ACCURACY
273
274
/*!
275
 * \brief This structure stores information needed for bitrate accuracy
276
 * experiment.
277
 */
278
typedef struct {
279
  int ready;
280
  double total_bit_budget;  // The total bit budget of the entire video
281
  int show_frame_count;     // Number of show frames in the entire video
282
283
  int gop_showframe_count;  // The number of show frames in the current gop
284
  double gop_bit_budget;    // The bitbudget for the current gop
285
  double scale_factors[FRAME_UPDATE_TYPES];     // Scale factors to improve the
286
                                                // budget estimation
287
  double mv_scale_factors[FRAME_UPDATE_TYPES];  // Scale factors to improve
288
                                                // MV entropy estimation
289
290
  // === Below this line are GOP related data that will be updated per GOP ===
291
  int base_q_index;  // Stores the base q index.
292
  int q_index_list_ready;
293
  int q_index_list[VBR_RC_INFO_MAX_FRAMES];  // q indices for the current
294
                                             // GOP
295
296
  // Array to store qstep_ratio for each frame in a GOP
297
  double qstep_ratio_list[VBR_RC_INFO_MAX_FRAMES];
298
299
#if CONFIG_THREE_PASS
300
  TplTxfmStats txfm_stats_list[VBR_RC_INFO_MAX_FRAMES];
301
  FRAME_UPDATE_TYPE update_type_list[VBR_RC_INFO_MAX_FRAMES];
302
  int gop_start_idx_list[VBR_RC_INFO_MAX_FRAMES];
303
  int gop_length_list[VBR_RC_INFO_MAX_FRAMES];
304
  int cur_gop_idx;
305
  int total_frame_count;
306
  int gop_count;
307
#endif  // CONFIG_THREE_PASS
308
} VBR_RATECTRL_INFO;
309
310
static inline void vbr_rc_reset_gop_data(VBR_RATECTRL_INFO *vbr_rc_info) {
311
  vbr_rc_info->q_index_list_ready = 0;
312
  av1_zero(vbr_rc_info->q_index_list);
313
}
314
315
void av1_vbr_rc_init(VBR_RATECTRL_INFO *vbr_rc_info, double total_bit_budget,
316
                     int show_frame_count);
317
318
int av1_vbr_rc_frame_coding_idx(const VBR_RATECTRL_INFO *vbr_rc_info,
319
                                int gf_frame_index);
320
321
void av1_vbr_rc_append_tpl_info(VBR_RATECTRL_INFO *vbr_rc_info,
322
                                const struct TPL_INFO *tpl_info);
323
324
void av1_vbr_rc_set_gop_bit_budget(VBR_RATECTRL_INFO *vbr_rc_info,
325
                                   int gop_showframe_count);
326
327
void av1_vbr_rc_compute_q_indices(int base_q_index, int frame_count,
328
                                  const double *qstep_ratio_list,
329
                                  aom_bit_depth_t bit_depth, int *q_index_list);
330
331
/*!\brief Update q_index_list in vbr_rc_info based on tpl stats
332
 *
333
 * \param[out]      vbr_rc_info    Rate control info for BITRATE_ACCURACY
334
 *                                 experiment
335
 * \param[in]       tpl_data       TPL struct
336
 * \param[in]       gf_group       GOP struct
337
 * \param[in]       bit_depth      bit depth
338
 */
339
void av1_vbr_rc_update_q_index_list(VBR_RATECTRL_INFO *vbr_rc_info,
340
                                    const TplParams *tpl_data,
341
                                    const struct GF_GROUP *gf_group,
342
                                    aom_bit_depth_t bit_depth);
343
/*
344
 *!\brief Compute the number of bits needed to encode a GOP
345
 *
346
 * \param[in]    base_q_index              base layer q_index
347
 * \param[in]    bit_depth                 bit depth
348
 * \param[in]    update_type_scale_factors array of scale factors for each
349
 *                                         update_type
350
 * \param[in]    frame_count               size of update_type_list,
351
 *                                         qstep_ratio_list stats_list,
352
 *                                         q_index_list and
353
 *                                         estimated_bitrate_byframe
354
 * \param[in]    update_type_list          array of update_type, one per frame
355
 * \param[in]    qstep_ratio_list          array of qstep_ratio, one per frame
356
 * \param[in]    stats_list                array of transform stats, one per
357
 *                                         frame
358
 * \param[out]   q_index_list              array of q_index, one per frame
359
 * \param[out]   estimated_bitrate_byframe array to keep track of frame
360
 *                                         bitrate
361
 *
362
 * \return The estimated GOP bitrate.
363
 *
364
 */
365
double av1_vbr_rc_info_estimate_gop_bitrate(
366
    int base_q_index, aom_bit_depth_t bit_depth,
367
    const double *update_type_scale_factors, int frame_count,
368
    const FRAME_UPDATE_TYPE *update_type_list, const double *qstep_ratio_list,
369
    const TplTxfmStats *stats_list, int *q_index_list,
370
    double *estimated_bitrate_byframe);
371
372
/*!\brief Estimate the optimal base q index for a GOP.
373
 *
374
 * This function uses a binary search to find base layer q index to
375
 * achieve the specified bit budget.
376
 *
377
 * \param[in]    bit_budget        target bit budget
378
 * \param[in]    bit_depth         bit depth
379
 * \param[in]    update_type_scale_factors array of scale factors for each
380
 *                                 update_type
381
 * \param[in]    frame_count       size of update_type_list, qstep_ratio_list
382
 *                                 stats_list, q_index_list and
383
 *                                 estimated_bitrate_byframe
384
 * \param[in]    update_type_list  array of update_type, one per frame
385
 * \param[in]    qstep_ratio_list  array of qstep_ratio, one per frame
386
 * \param[in]    stats_list        array of transform stats, one per frame
387
 * \param[out]   q_index_list      array of q_index, one per frame
388
 * \param[out]   estimated_bitrate_byframe Array to keep track of frame
389
 * bitrate
390
 *
391
 * \return Returns the optimal base q index to use.
392
 */
393
int av1_vbr_rc_info_estimate_base_q(
394
    double bit_budget, aom_bit_depth_t bit_depth,
395
    const double *update_type_scale_factors, int frame_count,
396
    const FRAME_UPDATE_TYPE *update_type_list, const double *qstep_ratio_list,
397
    const TplTxfmStats *stats_list, int *q_index_list,
398
    double *estimated_bitrate_byframe);
399
400
#endif  // CONFIG_BITRATE_ACCURACY
401
402
#if CONFIG_RD_COMMAND
403
typedef enum {
404
  RD_OPTION_NONE,
405
  RD_OPTION_SET_Q,
406
  RD_OPTION_SET_Q_RDMULT
407
} RD_OPTION;
408
409
typedef struct RD_COMMAND {
410
  RD_OPTION option_ls[MAX_LENGTH_TPL_FRAME_STATS];
411
  int q_index_ls[MAX_LENGTH_TPL_FRAME_STATS];
412
  int rdmult_ls[MAX_LENGTH_TPL_FRAME_STATS];
413
  int frame_count;
414
  int frame_index;
415
} RD_COMMAND;
416
417
void av1_read_rd_command(const char *filepath, RD_COMMAND *rd_command);
418
#endif  // CONFIG_RD_COMMAND
419
420
0
static inline bool av1_use_tpl_for_extrc(AOM_EXT_RATECTRL const *ext_rc) {
421
0
  return ext_rc->ready && ext_rc->funcs.send_tpl_gop_stats != NULL;
422
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
423
424
/*!\brief Allocate buffers used by tpl model
425
 *
426
 * \param[in]    Top-level encode/decode structure
427
 * \param[in]    lag_in_frames  number of lookahead frames
428
 *
429
 * \param[out]   tpl_data  tpl data structure
430
 */
431
432
void av1_setup_tpl_buffers(struct AV1_PRIMARY *const ppi,
433
                           CommonModeInfoParams *const mi_params, int width,
434
                           int height, int byte_alignment, int lag_in_frames);
435
436
0
static inline void tpl_dealloc_temp_buffers(TplBuffers *tpl_tmp_buffers) {
437
0
  aom_free(tpl_tmp_buffers->predictor8);
438
0
  tpl_tmp_buffers->predictor8 = NULL;
439
0
  aom_free(tpl_tmp_buffers->src_diff);
440
0
  tpl_tmp_buffers->src_diff = NULL;
441
0
  aom_free(tpl_tmp_buffers->coeff);
442
0
  tpl_tmp_buffers->coeff = NULL;
443
0
  aom_free(tpl_tmp_buffers->qcoeff);
444
0
  tpl_tmp_buffers->qcoeff = NULL;
445
0
  aom_free(tpl_tmp_buffers->dqcoeff);
446
0
  tpl_tmp_buffers->dqcoeff = NULL;
447
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
448
449
static inline bool tpl_alloc_temp_buffers(TplBuffers *tpl_tmp_buffers,
450
0
                                          uint8_t tpl_bsize_1d) {
451
  // Number of pixels in a tpl block
452
0
  const int tpl_block_pels = tpl_bsize_1d * tpl_bsize_1d;
453
454
  // Allocate temporary buffers used in mode estimation.
455
0
  tpl_tmp_buffers->predictor8 = (uint8_t *)aom_memalign(
456
0
      32, tpl_block_pels * 2 * sizeof(*tpl_tmp_buffers->predictor8));
457
0
  tpl_tmp_buffers->src_diff = (int16_t *)aom_memalign(
458
0
      32, tpl_block_pels * sizeof(*tpl_tmp_buffers->src_diff));
459
0
  tpl_tmp_buffers->coeff = (tran_low_t *)aom_memalign(
460
0
      32, tpl_block_pels * sizeof(*tpl_tmp_buffers->coeff));
461
0
  tpl_tmp_buffers->qcoeff = (tran_low_t *)aom_memalign(
462
0
      32, tpl_block_pels * sizeof(*tpl_tmp_buffers->qcoeff));
463
0
  tpl_tmp_buffers->dqcoeff = (tran_low_t *)aom_memalign(
464
0
      32, tpl_block_pels * sizeof(*tpl_tmp_buffers->dqcoeff));
465
466
0
  if (!(tpl_tmp_buffers->predictor8 && tpl_tmp_buffers->src_diff &&
467
0
        tpl_tmp_buffers->coeff && tpl_tmp_buffers->qcoeff &&
468
0
        tpl_tmp_buffers->dqcoeff)) {
469
0
    tpl_dealloc_temp_buffers(tpl_tmp_buffers);
470
0
    return false;
471
0
  }
472
0
  return true;
473
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
474
475
/*!\brief Implements temporal dependency modelling for a GOP (GF/ARF
476
 * group) and selects between 16 and 32 frame GOP structure.
477
 *
478
 *\ingroup tpl_modelling
479
 *
480
 * \param[in]    cpi           Top - level encoder instance structure
481
 * \param[in]    gop_eval      Flag if it is in the GOP length decision stage
482
 * \param[in]    frame_params  Per frame encoding parameters
483
 *
484
 * \return Indicates whether or not we should use a longer GOP length.
485
 */
486
int av1_tpl_setup_stats(struct AV1_COMP *cpi, int gop_eval,
487
                        const struct EncodeFrameParams *const frame_params);
488
489
/*!\cond */
490
491
void av1_tpl_preload_rc_estimate(
492
    struct AV1_COMP *cpi, const struct EncodeFrameParams *const frame_params);
493
494
int av1_tpl_ptr_pos(int mi_row, int mi_col, int stride, uint8_t right_shift);
495
496
void av1_init_tpl_stats(TplParams *const tpl_data);
497
498
int av1_tpl_stats_ready(const TplParams *tpl_data, int gf_frame_index);
499
500
void av1_tpl_rdmult_setup(struct AV1_COMP *cpi);
501
502
void av1_tpl_rdmult_setup_sb(struct AV1_COMP *cpi, MACROBLOCK *const x,
503
                             BLOCK_SIZE sb_size, int mi_row, int mi_col);
504
505
void av1_mc_flow_dispenser_row(struct AV1_COMP *cpi,
506
                               TplTxfmStats *tpl_txfm_stats,
507
                               TplBuffers *tpl_tmp_buffers, MACROBLOCK *x,
508
                               int mi_row, BLOCK_SIZE bsize, TX_SIZE tx_size);
509
510
/*!\brief  Compute the entropy of an exponential probability distribution
511
 * function (pdf) subjected to uniform quantization.
512
 *
513
 * pdf(x) = b*exp(-b*x)
514
 *
515
 *\ingroup tpl_modelling
516
 *
517
 * \param[in]    q_step        quantizer step size
518
 * \param[in]    b             parameter of exponential distribution
519
 *
520
 * \return entropy cost
521
 */
522
double av1_exponential_entropy(double q_step, double b);
523
524
/*!\brief  Compute the entropy of a Laplace probability distribution
525
 * function (pdf) subjected to non-uniform quantization.
526
 *
527
 * pdf(x) = 0.5*b*exp(-0.5*b*|x|)
528
 *
529
 *\ingroup tpl_modelling
530
 *
531
 * \param[in]    q_step          quantizer step size for non-zero bins
532
 * \param[in]    b               parameter of Laplace distribution
533
 * \param[in]    zero_bin_ratio  zero bin's size is zero_bin_ratio * q_step
534
 *
535
 * \return entropy cost
536
 */
537
double av1_laplace_entropy(double q_step, double b, double zero_bin_ratio);
538
539
#if CONFIG_BITRATE_ACCURACY
540
/*!\brief  Compute the frame rate using transform block stats
541
 *
542
 * Assume each position i in the transform block is of Laplace distribution
543
 * with mean absolute deviation abs_coeff_mean[i]
544
 *
545
 * Then we can use av1_laplace_entropy() to compute the expected frame
546
 * rate.
547
 *
548
 *\ingroup tpl_modelling
549
 *
550
 * \param[in]    q_index         quantizer index
551
 * \param[in]    block_count     number of transform blocks
552
 * \param[in]    abs_coeff_mean  array of mean absolute deviation
553
 * \param[in]    coeff_num       number of coefficients per transform block
554
 *
555
 * \return expected frame rate
556
 */
557
double av1_laplace_estimate_frame_rate(int q_index, int block_count,
558
                                       const double *abs_coeff_mean,
559
                                       int coeff_num);
560
#endif  // CONFIG_BITRATE_ACCURACY
561
562
/*
563
 *!\brief Init TplTxfmStats
564
 *
565
 * \param[in]    tpl_txfm_stats  a structure for storing transform stats
566
 *
567
 */
568
void av1_init_tpl_txfm_stats(TplTxfmStats *tpl_txfm_stats);
569
570
#if CONFIG_BITRATE_ACCURACY
571
/*
572
 *!\brief Accumulate TplTxfmStats
573
 *
574
 * \param[in]  sub_stats          a structure for storing sub transform stats
575
 * \param[out] accumulated_stats  a structure for storing accumulated
576
 *transform stats
577
 *
578
 */
579
void av1_accumulate_tpl_txfm_stats(const TplTxfmStats *sub_stats,
580
                                   TplTxfmStats *accumulated_stats);
581
582
/*
583
 *!\brief Record a transform block into  TplTxfmStats
584
 *
585
 * \param[in]  tpl_txfm_stats     A structure for storing transform stats
586
 * \param[out] coeff              An array of transform coefficients. Its size
587
 *                                should equal to tpl_txfm_stats.coeff_num.
588
 *
589
 */
590
void av1_record_tpl_txfm_block(TplTxfmStats *tpl_txfm_stats,
591
                               const tran_low_t *coeff);
592
593
/*
594
 *!\brief Update abs_coeff_mean and ready of txfm_stats
595
 * If txfm_block_count > 0, this function will use abs_coeff_sum and
596
 * txfm_block_count to compute abs_coeff_mean. Moreover, reday flag
597
 * will be set to one.
598
 *
599
 * \param[in]  txfm_stats     A structure for storing transform stats
600
 */
601
void av1_tpl_txfm_stats_update_abs_coeff_mean(TplTxfmStats *txfm_stats);
602
#endif  // CONFIG_BITRATE_ACCURACY
603
604
/*!\brief  Estimate coefficient entropy using Laplace dsitribution
605
 *
606
 *\ingroup tpl_modelling
607
 *
608
 * This function is equivalent to -log2(laplace_prob()), where laplace_prob()
609
 *is defined in tpl_model_test.cc
610
 *
611
 * \param[in]    q_step          quantizer step size without any scaling
612
 * \param[in]    b               mean absolute deviation of Laplace
613
 *distribution \param[in]    zero_bin_ratio  zero bin's size is zero_bin_ratio
614
 ** q_step \param[in]    qcoeff          quantized coefficient
615
 *
616
 * \return estimated coefficient entropy
617
 *
618
 */
619
double av1_estimate_coeff_entropy(double q_step, double b,
620
                                  double zero_bin_ratio, int qcoeff);
621
622
// TODO(angiebird): Add doxygen description here.
623
int64_t av1_delta_rate_cost(int64_t delta_rate, int64_t recrf_dist,
624
                            int64_t srcrf_dist, int pix_num);
625
626
/*!\brief  Compute the overlap area between two blocks with the same size
627
 *
628
 *\ingroup tpl_modelling
629
 *
630
 * If there is no overlap, this function should return zero.
631
 *
632
 * \param[in]    row_a  row position of the first block
633
 * \param[in]    col_a  column position of the first block
634
 * \param[in]    row_b  row position of the second block
635
 * \param[in]    col_b  column position of the second block
636
 * \param[in]    width  width shared by the two blocks
637
 * \param[in]    height height shared by the two blocks
638
 *
639
 * \return overlap area of the two blocks
640
 */
641
int av1_get_overlap_area(int row_a, int col_a, int row_b, int col_b, int width,
642
                         int height);
643
644
/*!\brief Get current frame's q_index from tpl stats and leaf_qindex
645
 *
646
 * \param[in]       tpl_data          TPL struct
647
 * \param[in]       gf_frame_index    current frame index in the GOP
648
 * \param[in]       leaf_qindex       q index of leaf frame
649
 * \param[in]       bit_depth         bit depth
650
 *
651
 * \return q_index
652
 */
653
int av1_tpl_get_q_index(const TplParams *tpl_data, int gf_frame_index,
654
                        int leaf_qindex, aom_bit_depth_t bit_depth);
655
656
/*!\brief Compute the ratio between arf q step and the leaf q step based on
657
 * TPL stats
658
 *
659
 * \param[in]       tpl_data          TPL struct
660
 * \param[in]       gf_frame_index    current frame index in the GOP
661
 * \param[in]       leaf_qindex       q index of leaf frame
662
 * \param[in]       bit_depth         bit depth
663
 *
664
 * \return qstep_ratio
665
 */
666
double av1_tpl_get_qstep_ratio(const TplParams *tpl_data, int gf_frame_index);
667
668
/*!\brief Find a q index whose step size is near qstep_ratio * leaf_qstep
669
 *
670
 * \param[in]       leaf_qindex       q index of leaf frame
671
 * \param[in]       qstep_ratio       step ratio between target q index and
672
 * leaf q index \param[in]       bit_depth         bit depth
673
 *
674
 * \return q_index
675
 */
676
int av1_get_q_index_from_qstep_ratio(int leaf_qindex, double qstep_ratio,
677
                                     aom_bit_depth_t bit_depth);
678
679
/*!\brief Improve the motion vector estimation by taking neighbors into
680
 * account.
681
 *
682
 * Use the upper and left neighbor block as the reference MVs.
683
 * Compute the minimum difference between current MV and reference MV.
684
 *
685
 * \param[in]       tpl_frame         Tpl frame struct
686
 * \param[in]       row               Current row
687
 * \param[in]       col               Current column
688
 * \param[in]       step              Step parameter for av1_tpl_ptr_pos
689
 * \param[in]       tpl_stride        Stride parameter for av1_tpl_ptr_pos
690
 * \param[in]       right_shift       Right shift parameter for
691
 * av1_tpl_ptr_pos
692
 */
693
int_mv av1_compute_mv_difference(const TplDepFrame *tpl_frame, int row, int col,
694
                                 int step, int tpl_stride, int right_shift);
695
696
/*!\brief Compute the entropy of motion vectors for a single frame.
697
 *
698
 * \param[in]       tpl_frame         TPL frame struct
699
 * \param[in]       right_shift       right shift value for step
700
 *
701
 * \return Bits used by the motion vectors for one frame.
702
 */
703
double av1_tpl_compute_frame_mv_entropy(const TplDepFrame *tpl_frame,
704
                                        uint8_t right_shift);
705
706
/*!\brief Free the memory allocated for cpi->extrc_tpl_gop_stats.
707
 *
708
 * \param[in] extrc_tpl_gop_stats TPL stats for the GOP used for external RC.
709
 */
710
void av1_free_tpl_gop_stats(AomTplGopStats *extrc_tpl_gop_stats);
711
712
#if CONFIG_RATECTRL_LOG
713
typedef struct {
714
  int coding_frame_count;
715
  int base_q_index;
716
717
  // Encode decision
718
  int q_index_list[VBR_RC_INFO_MAX_FRAMES];
719
  double qstep_ratio_list[VBR_RC_INFO_MAX_FRAMES];
720
  FRAME_UPDATE_TYPE update_type_list[VBR_RC_INFO_MAX_FRAMES];
721
722
  // Frame stats
723
  TplTxfmStats txfm_stats_list[VBR_RC_INFO_MAX_FRAMES];
724
725
  // Estimated encode results
726
  double est_coeff_rate_list[VBR_RC_INFO_MAX_FRAMES];
727
728
  // Actual encode results
729
  double act_rate_list[VBR_RC_INFO_MAX_FRAMES];
730
  double act_coeff_rate_list[VBR_RC_INFO_MAX_FRAMES];
731
} RATECTRL_LOG;
732
733
static inline void rc_log_init(RATECTRL_LOG *rc_log) { av1_zero(*rc_log); }
734
735
static inline void rc_log_frame_stats(RATECTRL_LOG *rc_log, int coding_index,
736
                                      const TplTxfmStats *txfm_stats) {
737
  rc_log->txfm_stats_list[coding_index] = *txfm_stats;
738
}
739
740
#if CONFIG_RATECTRL_LOG && CONFIG_THREE_PASS && CONFIG_BITRATE_ACCURACY
741
static inline void rc_log_frame_encode_param(RATECTRL_LOG *rc_log,
742
                                             int coding_index,
743
                                             double qstep_ratio, int q_index,
744
                                             FRAME_UPDATE_TYPE update_type) {
745
  rc_log->qstep_ratio_list[coding_index] = qstep_ratio;
746
  rc_log->q_index_list[coding_index] = q_index;
747
  rc_log->update_type_list[coding_index] = update_type;
748
  const TplTxfmStats *txfm_stats = &rc_log->txfm_stats_list[coding_index];
749
  rc_log->est_coeff_rate_list[coding_index] = 0;
750
  if (txfm_stats->ready) {
751
    rc_log->est_coeff_rate_list[coding_index] = av1_laplace_estimate_frame_rate(
752
        q_index, txfm_stats->txfm_block_count, txfm_stats->abs_coeff_mean,
753
        txfm_stats->coeff_num);
754
  }
755
}
756
#endif  // CONFIG_RATECTRL_LOG && CONFIG_THREE_PASS && CONFIG_BITRATE_ACCURACY
757
758
static inline void rc_log_frame_entropy(RATECTRL_LOG *rc_log, int coding_index,
759
                                        double act_rate,
760
                                        double act_coeff_rate) {
761
  rc_log->act_rate_list[coding_index] = act_rate;
762
  rc_log->act_coeff_rate_list[coding_index] = act_coeff_rate;
763
}
764
765
static inline void rc_log_record_chunk_info(RATECTRL_LOG *rc_log,
766
                                            int base_q_index,
767
                                            int coding_frame_count) {
768
  rc_log->base_q_index = base_q_index;
769
  rc_log->coding_frame_count = coding_frame_count;
770
}
771
772
static inline void rc_log_show(const RATECTRL_LOG *rc_log) {
773
  printf("= chunk 1\n");
774
  printf("coding_frame_count %d base_q_index %d\n", rc_log->coding_frame_count,
775
         rc_log->base_q_index);
776
  printf("= frame %d\n", rc_log->coding_frame_count);
777
  for (int coding_idx = 0; coding_idx < rc_log->coding_frame_count;
778
       coding_idx++) {
779
    printf(
780
        "coding_idx %d update_type %d q %d qstep_ratio %f est_coeff_rate %f "
781
        "act_coeff_rate %f act_rate %f\n",
782
        coding_idx, rc_log->update_type_list[coding_idx],
783
        rc_log->q_index_list[coding_idx], rc_log->qstep_ratio_list[coding_idx],
784
        rc_log->est_coeff_rate_list[coding_idx],
785
        rc_log->act_coeff_rate_list[coding_idx],
786
        rc_log->act_rate_list[coding_idx]);
787
  }
788
}
789
#endif  // CONFIG_RATECTRL_LOG
790
791
/*!\endcond */
792
#ifdef __cplusplus
793
}  // extern "C"
794
#endif
795
796
#endif  // AOM_AV1_ENCODER_TPL_MODEL_H_