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_PASS2_STRATEGY_H_
13 #define AOM_AV1_ENCODER_PASS2_STRATEGY_H_
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 struct AV1_COMP;
20 struct EncodeFrameParams;
21 // structure of accumulated stats and features in a gf group
22 typedef struct {
23   double gf_group_err;
24   double gf_group_raw_error;
25   double gf_group_skip_pct;
26   double gf_group_inactive_zone_rows;
27 
28   double mv_ratio_accumulator;
29   double decay_accumulator;
30   double zero_motion_accumulator;
31   double loop_decay_rate;
32   double last_loop_decay_rate;
33   double this_frame_mv_in_out;
34   double mv_in_out_accumulator;
35   double abs_mv_in_out_accumulator;
36 
37   double avg_sr_coded_error;
38   double avg_tr_coded_error;
39   double avg_pcnt_second_ref;
40   double avg_pcnt_third_ref;
41   double avg_pcnt_third_ref_nolast;
42   double avg_new_mv_count;
43   double avg_wavelet_energy;
44   double avg_raw_err_stdev;
45   int non_zero_stdev_count;
46 
47   unsigned int allow_alt_ref;
48 } GF_GROUP_STATS;
49 
50 typedef struct {
51   double frame_err;
52   double frame_coded_error;
53   double frame_sr_coded_error;
54   double frame_tr_coded_error;
55 } GF_FRAME_STATS;
56 
57 void av1_init_second_pass(struct AV1_COMP *cpi);
58 
59 void av1_init_single_pass_lap(AV1_COMP *cpi);
60 
61 void av1_get_second_pass_params(struct AV1_COMP *cpi,
62                                 struct EncodeFrameParams *const frame_params,
63                                 const EncodeFrameInput *const frame_input,
64                                 unsigned int frame_flags);
65 
66 void av1_twopass_postencode_update(struct AV1_COMP *cpi);
67 
68 void av1_gop_bit_allocation(const AV1_COMP *cpi, RATE_CONTROL *const rc,
69                             GF_GROUP *gf_group, int is_key_frame, int use_arf,
70                             int64_t gf_group_bits);
71 
72 #ifdef __cplusplus
73 }  // extern "C"
74 #endif
75 
76 #endif  // AOM_AV1_ENCODER_PASS2_STRATEGY_H_
77