xref: /rockchip-linux_mpp/mpp/codec/inc/mpp_enc_impl.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /*
2  * Copyright 2020 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 __MPP_ENC_IMPL_H__
18 #define __MPP_ENC_IMPL_H__
19 
20 #include "enc_impl.h"
21 #include "mpp_enc_hal.h"
22 #include "mpp_enc_ref.h"
23 #include "mpp_enc_refs.h"
24 #include "mpp_device.h"
25 #include "mpp_task_impl.h"
26 
27 #include "rc.h"
28 #include "hal_info.h"
29 
30 #define HDR_ADDED_MASK  0xe
31 
32 typedef struct MppPskipMode_t {
33     RK_S32 pskip_is_ref;
34     RK_S32 pskip_is_non_ref;
35 } MppPskipMode;
36 
37 typedef union MppEncHeaderStatus_u {
38     RK_U32 val;
39     struct {
40         RK_U32          ready           : 1;
41 
42         RK_U32          added_by_ctrl   : 1;
43         RK_U32          added_by_mode   : 1;
44         RK_U32          added_by_change : 1;
45     };
46 } MppEncHeaderStatus;
47 
48 typedef struct RcApiStatus_t {
49     RK_U32              rc_api_inited   : 1;
50     RK_U32              rc_api_updated  : 1;
51     RK_U32              rc_api_user_cfg : 1;
52 } RcApiStatus;
53 
54 typedef struct MppEncImpl_t {
55     MppCodingType       coding;
56     EncImpl             impl;
57     MppEncHal           enc_hal;
58 
59     /* device from hal */
60     MppDev              dev;
61     HalInfo             hal_info;
62     RK_S64              time_base;
63     RK_S64              time_end;
64     RK_S32              frame_count;
65     RK_S32              hal_info_updated;
66 
67     /*
68      * Rate control plugin parameters
69      */
70     RcApiStatus         rc_status;
71     RK_S32              rc_api_updated;
72     RK_S32              rc_cfg_updated;
73     RcApiBrief          rc_brief;
74     RcCtx               rc_ctx;
75 
76     /*
77      * thread input / output context
78      */
79     MppThread           *thread_enc;
80     void                *mpp;
81 
82     MppPort             input;
83     MppPort             output;
84     MppTask             task_in;
85     MppTask             task_out;
86     MppFrame            frame;
87     MppPacket           packet;
88     RK_U32              low_delay_part_mode;
89     RK_U32              low_delay_output;
90     /* output callback for slice output */
91     MppCbCtx            output_cb;
92 
93     /* base task information */
94     HalTaskGroup        tasks;
95     HalTaskHnd          hnd;
96     EncAsyncTaskInfo    *async;
97     RK_U32              task_idx;
98     RK_S64              task_pts;
99     MppBuffer           frm_buf;
100     MppBuffer           pkt_buf;
101     MppBuffer           md_info;
102 
103     // internal status and protection
104     MppMutex            lock;
105     RK_U32              reset_flag;
106     sem_t               enc_reset;
107 
108     RK_U32              wait_count;
109     RK_U32              work_count;
110     RK_U32              status_flag;
111     RK_U32              notify_flag;
112     RK_U32              enc_failed_drop;
113 
114     /* control process */
115     RK_U32              cmd_send;
116     RK_U32              cmd_recv;
117     MpiCmd              cmd;
118     void                *param;
119     MPP_RET             *cmd_ret;
120     sem_t               cmd_start;
121     sem_t               cmd_done;
122 
123     // legacy support for MPP_ENC_GET_EXTRA_INFO
124     MppPacket           hdr_pkt;
125     void                *hdr_buf;
126     RK_U32              hdr_len;
127     MppEncHeaderStatus  hdr_status;
128     MppEncHeaderMode    hdr_mode;
129     MppEncSeiMode       sei_mode;
130 
131     /* information for debug prefix */
132     const char          *version_info;
133     RK_S32              version_length;
134     char                *rc_cfg_info;
135     RK_S32              rc_cfg_pos;
136     RK_S32              rc_cfg_length;
137     RK_S32              rc_cfg_size;
138 
139     /* cpb parameters */
140     MppEncRefs          refs;
141     MppEncRefFrmUsrCfg  frm_cfg;
142 
143     /* two-pass deflicker parameters */
144     RK_U32              support_hw_deflicker;
145     EncRcTaskInfo       rc_info_prev;
146 
147     /* encoder config object for external setup */
148     MppEncCfg           set_obj;
149     MppEncCfgSet        *set;
150     /* encoder config object for internal usage */
151     MppEncCfg           cfg_obj;
152     MppEncCfgSet        *cfg;
153 } MppEncImpl;
154 
155 extern RK_U8 uuid_refresh_cfg[16];
156 
157 #ifdef __cplusplus
158 extern "C" {
159 #endif
160 
161 void *mpp_enc_thread(void *data);
162 void *mpp_enc_async_thread(void *data);
163 MPP_RET mpp_enc_callback(const char *caller, void *ctx, RK_S32 cmd, void *param);
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /*__MPP_ENC_IMPL_H__*/
170