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