xref: /rockchip-linux_mpp/mpp/codec/rc/rc_ctx.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /*
2  * Copyright 2016 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef __RC_CTX_H__
17 #define __RC_CTX_H__
18 
19 #include "mpp_rc_api.h"
20 #include "rc_base.h"
21 
22 typedef struct RcModelV2Ctx_t {
23     RcCfg           usr_cfg;
24 
25     RK_U32          last_frame_type;
26     RK_S64          gop_total_bits;
27     RK_U32          bit_per_frame;
28     RK_U32          first_frm_flg;
29     RK_S64          avg_gbits;
30     RK_S64          real_gbits;
31 
32     MppDataV2       *i_bit;
33     RK_U32          i_sumbits;
34     RK_U32          i_scale;
35 
36     MppDataV2       *idr_bit;
37     RK_U32          idr_sumbits;
38     RK_U32          idr_scale;
39 
40     MppDataV2       *vi_bit;
41     RK_U32          vi_sumbits;
42     RK_U32          vi_scale;
43     RK_U32          i_refresh_scale;
44     MppDataV2       *p_bit;
45     RK_U32          p_sumbits;
46     RK_U32          i_refresh_sumbits;
47     RK_U32          p_scale;
48 
49     MppDataV2       *pre_p_bit;
50     MppDataV2       *pre_i_bit;
51     MppDataV2       *i_refresh_bit;
52     MppDataV2       *pre_i_mean_qp;
53     MppDataV2       *madi;
54     MppDataV2       *madp;
55     MppDataV2       *motion_level;
56     MppDataV2       *complex_level;
57 
58     RK_S32          target_bps;
59     RK_S32          pre_target_bits;
60     RK_S32          pre_target_bits_fix;
61     RK_S64          pre_target_bits_fix_count;
62     RK_S64          pre_real_bits_count;
63     RK_S32          pre_real_bits;
64     RK_S32          frm_bits_thr;
65     RK_S32          ins_bps;
66     RK_S32          last_inst_bps;
67 
68     RK_U32          motion_sensitivity;
69     RK_U32          min_still_percent;
70     RK_U32          max_still_qp;
71     RK_S32          moving_ratio;
72     RK_U32          pre_mean_qp;
73     RK_U32          pre_i_scale;
74     RK_S32          cur_super_thd;
75     MppDataV2       *stat_bits;
76     MppDataV2       *gop_bits;
77     MppDataV2       *stat_rate;
78     RK_S32          watl_thrd;
79     RK_S32          stat_watl;
80     RK_S32          watl_base;
81 
82     RK_S32          next_i_ratio;      // scale 64
83     RK_S32          next_ratio;        // scale 64
84     RK_S32          pre_i_qp;
85     RK_S32          pre_p_qp;
86     RK_U32          scale_qp;          // scale 64
87     MppDataV2       *means_qp;
88     RK_U32          frm_num;
89 
90     /* qp decision */
91     RK_S32          cur_scale_qp;
92     RK_S32          start_qp;
93     RK_S32          prev_quality;
94     RK_S32          prev_md_prop;
95     RK_S32          gop_qp_sum;
96     RK_S32          gop_frm_cnt;
97     RK_S32          pre_iblk4_prop;
98 
99     RK_S32          reenc_cnt;
100     RK_U32          drop_cnt;
101     RK_S32          on_drop;
102     RK_S32          on_pskip;
103     RK_S32          qp_layer_id;
104     RK_S32          hier_frm_cnt[4];
105 
106     RK_S64          time_base;
107     RK_S64          time_end;
108     RK_S32          frm_cnt;
109     RK_S32          last_fps;
110 
111     MPP_RET         (*calc_ratio)(void* ctx, EncRcTaskInfo *cfg);
112     MPP_RET         (*re_calc_ratio)(void* ctx, EncRcTaskInfo *cfg);
113 } RcModelV2Ctx;
114 
115 
116 #ifdef  __cplusplus
117 extern "C" {
118 #endif
119 
120 /* basic helper function */
121 MPP_RET bits_model_init(RcModelV2Ctx *ctx);
122 MPP_RET bits_model_deinit(RcModelV2Ctx *ctx);
123 
124 MPP_RET bits_model_alloc(RcModelV2Ctx *ctx, EncRcTaskInfo *cfg, RK_S64 total_bits);
125 MPP_RET bits_model_update(RcModelV2Ctx *ctx, EncRcTaskInfo *cfg);
126 
127 MPP_RET calc_next_i_ratio(RcModelV2Ctx *ctx);
128 MPP_RET check_re_enc(RcModelV2Ctx *ctx, EncRcTaskInfo *cfg);
129 
130 #ifdef  __cplusplus
131 }
132 #endif
133 
134 #endif /* __RC_CTX_H__ */
135