xref: /OK3568_Linux_fs/external/mpp/mpp/codec/inc/rc.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 
17 #ifndef __RC_H__
18 #define __RC_H__
19 
20 #include "mpp_err.h"
21 
22 #include "mpp_rc_api.h"
23 
24 /*
25  * Mpp rate control principle
26  *
27  * 1. Rate control information is composed by these parts:
28  *    a. configuration from mpp user.
29  *    b. frame level target bitrate calculated by different RC model.
30  *    c. block level hardware related configuration to hardware.
31  *    d. statistic information from hardware after one frame is encoded.
32  *
33  * 2. All the above informatioin is storaged and managed by RcDataCtx in mpp
34  *    framework. All these information is shared in encoder and hal module.
35  *
36  * 3. User (no matter developer or end user) defined rate control should based
37  *    on these Rate control information and implement its own rate control
38  *    strategy module by providing their own RcImplApi.
39  */
40 
41 /*
42  * Relation between mpp_enc / enc_impl / hal / RcApi / RcImplApi / RcData
43  *
44  *  +-----------+
45  *  |  mpp_enc  |
46  *  +-----+-----+
47  *        |
48  *  +-----+-----+   +-----------+   +-----------+
49  *  |  enc_impl +--->   RcApi   +---> RcImplApi |
50  *  +-----+-----+   +-----+-----+   +-----+-----+
51  *        |      \ /      |               |
52  *        |       +       |               |
53  *        |      / \      |               |
54  *  +-----v-----+   +-----v-----+         |
55  *  |    hal    +--->  RcData   <---------+
56  *  +-----------+   +-----------+
57  */
58 
59 typedef void* RcCtx;
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 MPP_RET rc_init(RcCtx *ctx, MppCodingType type, const char **request_name);
66 MPP_RET rc_deinit(RcCtx ctx);
67 
68 /* update rc control  */
69 MPP_RET rc_update_usr_cfg(RcCtx ctx, RcCfg *cfg);
70 
71 /* Frame rate convertion */
72 MPP_RET rc_frm_check_drop(RcCtx ctx, EncRcTask *task);
73 /* Frame reenc check */
74 MPP_RET rc_frm_check_reenc(RcCtx ctx, EncRcTask *task);
75 
76 /* Frame level rate and quality control */
77 MPP_RET rc_frm_start(RcCtx ctx, EncRcTask *task);
78 MPP_RET rc_frm_end(RcCtx ctx, EncRcTask *task);
79 
80 MPP_RET rc_hal_start(RcCtx ctx, EncRcTask *task);
81 MPP_RET rc_hal_end(RcCtx ctx, EncRcTask *task);
82 
83 #ifdef __cplusplus
84 }
85 #endif
86 
87 #endif /* __RC_H__ */
88