xref: /OK3568_Linux_fs/external/mpp/mpp/codec/rc/rc_ctx.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 
56     RK_S32          target_bps;
57     RK_S32          pre_target_bits;
58     RK_S32          pre_real_bits;
59     RK_S32          frm_bits_thr;
60     RK_S32          ins_bps;
61     RK_S32          last_inst_bps;
62 
63     RK_U32          motion_sensitivity;
64     RK_U32          min_still_percent;
65     RK_U32          max_still_qp;
66     RK_S32          moving_ratio;
67     RK_U32          pre_mean_qp;
68     RK_U32          pre_i_scale;
69     RK_S32          cur_super_thd;
70     MppDataV2       *stat_bits;
71     MppDataV2       *gop_bits;
72     MppDataV2       *stat_rate;
73     RK_S32          watl_thrd;
74     RK_S32          stat_watl;
75     RK_S32          watl_base;
76 
77     RK_S32          next_i_ratio;      // scale 64
78     RK_S32          next_ratio;        // scale 64
79     RK_S32          pre_i_qp;
80     RK_S32          pre_p_qp;
81     RK_U32          scale_qp;          // scale 64
82     MppDataV2       *means_qp;
83     RK_U32          frm_num;
84 
85     /* qp decision */
86     RK_S32          cur_scale_qp;
87     RK_S32          start_qp;
88     RK_S32          prev_quality;
89     RK_S32          prev_md_prop;
90     RK_S32          gop_qp_sum;
91     RK_S32          gop_frm_cnt;
92     RK_S32          pre_iblk4_prop;
93 
94     RK_S32          reenc_cnt;
95     RK_U32          drop_cnt;
96     RK_S32          on_drop;
97     RK_S32          on_pskip;
98     RK_S32          qp_layer_id;
99     RK_S32          hier_frm_cnt[4];
100 
101     MPP_RET         (*calc_ratio)(void* ctx, EncRcTaskInfo *cfg);
102     MPP_RET         (*re_calc_ratio)(void* ctx, EncRcTaskInfo *cfg);
103 } RcModelV2Ctx;
104 
105 
106 #ifdef  __cplusplus
107 extern "C" {
108 #endif
109 
110 /* basic helper function */
111 MPP_RET bits_model_init(RcModelV2Ctx *ctx);
112 MPP_RET bits_model_deinit(RcModelV2Ctx *ctx);
113 
114 MPP_RET bits_model_alloc(RcModelV2Ctx *ctx, EncRcTaskInfo *cfg, RK_S64 total_bits);
115 MPP_RET bits_model_update(RcModelV2Ctx *ctx, EncRcTaskInfo *cfg);
116 
117 MPP_RET calc_next_i_ratio(RcModelV2Ctx *ctx);
118 MPP_RET check_re_enc(RcModelV2Ctx *ctx, EncRcTaskInfo *cfg);
119 
120 #ifdef  __cplusplus
121 }
122 #endif
123 
124 #endif /* __RC_CTX_H__ */
125