xref: /OK3568_Linux_fs/external/mpp/mpp/codec/inc/mpp_dec_impl.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright 2015 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_DEC_IMPL_H__
18 #define __MPP_DEC_IMPL_H__
19 
20 #include "mpp_time.h"
21 #include "mpp_mem_pool.h"
22 #include "mpp_lock.h"
23 #include "hal_info.h"
24 
25 #include "mpp.h"
26 #include "mpp_dec_cfg.h"
27 #include "mpp_callback.h"
28 
29 #include "mpp_parser.h"
30 #include "mpp_hal.h"
31 
32 // for timing record
33 typedef enum MppDecTimingType_e {
34     DEC_PRS_TOTAL,
35     DEC_PRS_WAIT,
36     DEC_PRS_PROC,
37     DEC_PRS_PREPARE,
38     DEC_PRS_PARSE,
39     DEC_HAL_GEN_REG,
40     DEC_HW_START,
41 
42     DEC_HAL_TOTAL,
43     DEC_HAL_WAIT,
44     DEC_HAL_PROC,
45     DEC_HW_WAIT,
46     DEC_TIMING_BUTT,
47 } MppDecTimingType;
48 
49 
50 typedef enum MppDecMode_e {
51     MPP_DEC_MODE_DEFAULT,
52     MPP_DEC_MODE_NO_THREAD,
53 
54     MPP_DEC_MODE_BUTT,
55 } MppDecMode;
56 
57 typedef struct MppDecImpl_t MppDecImpl;
58 
59 typedef struct MppDecModeApi_t {
60     MPP_RET (*start)(MppDecImpl *dec);
61     MPP_RET (*stop)(MppDecImpl *dec);
62     MPP_RET (*reset)(MppDecImpl *dec);
63     MPP_RET (*notify)(MppDecImpl *dec, RK_U32 flag);
64     MPP_RET (*control)(MppDecImpl *dec, MpiCmd cmd, void *param);
65 } MppDecModeApi;
66 
67 struct MppDecImpl_t {
68     MppCodingType       coding;
69 
70     MppDecMode          mode;
71     MppDecModeApi       *api;
72 
73     Parser              parser;
74     MppHal              hal;
75 
76     // worker thread
77     MppThread           *thread_parser;
78     MppThread           *thread_hal;
79 
80     // common resource
81     MppBufSlots         frame_slots;
82     MppBufSlots         packet_slots;
83     MppCbCtx            dec_cb;
84     const MppDecHwCap   *hw_info;
85     MppDev              dev;
86     HalInfo             hal_info;
87     RK_U32              info_updated;
88 
89     HalTaskGroup        tasks;
90     HalTaskGroup        vproc_tasks;
91 
92     // runtime configure set
93     MppDecCfgSet        cfg;
94 
95     /* control process */
96     MppMutexCond        *cmd_lock;
97     RK_U32              cmd_send;
98     RK_U32              cmd_recv;
99     MpiCmd              cmd;
100     void                *param;
101     MPP_RET             *cmd_ret;
102     sem_t               cmd_start;
103     sem_t               cmd_done;
104 
105     // status flags
106     RK_U32              parser_work_count;
107     RK_U32              parser_wait_count;
108     RK_U32              parser_status_flag;
109     RK_U32              parser_wait_flag;
110     RK_U32              parser_notify_flag;
111     RK_U32              hal_notify_flag;
112 
113     // reset process:
114     // 1. mpp_dec set reset flag and signal parser
115     // 2. mpp_dec wait on parser_reset sem
116     // 3. parser wait hal reset done
117     // 4. hal wait vproc reset done
118     // 5. vproc do reset and signal hal
119     // 6. hal do reset and signal parser
120     // 7. parser do reset and signal mpp_dec
121     // 8. mpp_dec reset done
122     RK_U32              reset_flag;
123 
124     RK_U32              hal_reset_post;
125     RK_U32              hal_reset_done;
126     sem_t               parser_reset;
127     sem_t               hal_reset;
128 
129     // work mode flags
130     RK_U32              parser_fast_mode;
131     RK_U32              disable_error;
132     RK_U32              enable_deinterlace;
133 
134     // dec parser thread runtime resource context
135     MppPacket           mpp_pkt_in;
136     void                *mpp;
137     void                *vproc;
138 
139     // statistics data
140     RK_U32              statistics_en;
141     MppClock            clocks[DEC_TIMING_BUTT];
142 
143     // query data
144     RK_U32              dec_in_pkt_count;
145     RK_U32              dec_hw_run_count;
146     RK_U32              dec_out_frame_count;
147 
148     MppMemPool          ts_pool;
149     struct list_head    ts_link;
150     spinlock_t          ts_lock;
151     void                *task_single;
152 };
153 
154 /* external wait state */
155 #define MPP_DEC_WAIT_PKT_IN             (0x00000001)    /* input packet not ready */
156 #define MPP_DEC_WAIT_FRM_OUT            (0x00000002)    /* frame output queue full */
157 
158 #define MPP_DEC_WAIT_INFO_CHG           (0x00000020)    /* wait info change ready */
159 #define MPP_DEC_WAIT_BUF_RDY            (0x00000040)    /* wait valid frame buffer */
160 #define MPP_DEC_WAIT_TSK_ALL_DONE       (0x00000080)    /* wait all task done */
161 
162 #define MPP_DEC_WAIT_TSK_HND_RDY        (0x00000100)    /* wait task handle ready */
163 #define MPP_DEC_WAIT_TSK_PREV_DONE      (0x00000200)    /* wait previous task done */
164 #define MPP_DEC_WAIT_BUF_GRP_RDY        (0x00000200)    /* wait buffer group change ready */
165 
166 /* internal wait state */
167 #define MPP_DEC_WAIT_BUF_SLOT_RDY       (0x00001000)    /* wait buffer slot ready */
168 #define MPP_DEC_WAIT_PKT_BUF_RDY        (0x00002000)    /* wait packet buffer ready */
169 #define MPP_DEC_WAIT_BUF_SLOT_KEEP      (0x00004000)    /* wait buffer slot reservation */
170 
171 typedef union PaserTaskWait_u {
172     RK_U32          val;
173     struct {
174         RK_U32      dec_pkt_in      : 1;   // 0x0001 MPP_DEC_NOTIFY_PACKET_ENQUEUE
175         RK_U32      dis_que_full    : 1;   // 0x0002 MPP_DEC_NOTIFY_FRAME_DEQUEUE
176         RK_U32      reserv0004      : 1;   // 0x0004
177         RK_U32      reserv0008      : 1;   // 0x0008
178 
179         RK_U32      ext_buf_grp     : 1;   // 0x0010 MPP_DEC_NOTIFY_EXT_BUF_GRP_READY
180         RK_U32      info_change     : 1;   // 0x0020 MPP_DEC_NOTIFY_INFO_CHG_DONE
181         RK_U32      dec_pic_unusd   : 1;   // 0x0040 MPP_DEC_NOTIFY_BUFFER_VALID
182         RK_U32      dec_all_done    : 1;   // 0x0080 MPP_DEC_NOTIFY_TASK_ALL_DONE
183 
184         RK_U32      task_hnd        : 1;   // 0x0100 MPP_DEC_NOTIFY_TASK_HND_VALID
185         RK_U32      prev_task       : 1;   // 0x0200 MPP_DEC_NOTIFY_TASK_PREV_DONE
186         RK_U32      dec_pic_match   : 1;   // 0x0400 MPP_DEC_NOTIFY_BUFFER_MATCH
187         RK_U32      reserv0800      : 1;   // 0x0800
188 
189         RK_U32      dec_pkt_idx     : 1;   // 0x1000
190         RK_U32      dec_pkt_buf     : 1;   // 0x2000
191         RK_U32      dec_slot_idx    : 1;   // 0x4000 MPP_DEC_NOTIFY_SLOT_VALID
192     };
193 } PaserTaskWait;
194 
195 typedef union DecTaskStatus_u {
196     RK_U32          val;
197     struct {
198         RK_U32      task_hnd_rdy      : 1;
199         RK_U32      mpp_pkt_in_rdy    : 1;
200         RK_U32      dec_pkt_idx_rdy   : 1;
201         RK_U32      dec_pkt_buf_rdy   : 1;
202         RK_U32      task_valid_rdy    : 1;
203         RK_U32      dec_pkt_copy_rdy  : 1;
204         RK_U32      prev_task_rdy     : 1;
205         RK_U32      info_task_gen_rdy : 1;
206         RK_U32      curr_task_rdy     : 1;
207         RK_U32      task_parsed_rdy   : 1;
208     };
209 } DecTaskStatus;
210 
211 typedef struct MppPktTimestamp_t {
212     struct list_head link;
213     RK_S64  pts;
214     RK_S64  dts;
215 } MppPktTs;
216 
217 typedef struct DecTask_t {
218     HalTaskHnd      hnd;
219 
220     DecTaskStatus   status;
221     PaserTaskWait   wait;
222 
223     HalTaskInfo     info;
224     MppPktTs        ts_cur;
225 
226     MppBuffer       hal_pkt_buf_in;
227     MppBuffer       hal_frm_buf_out;
228 } DecTask;
229 
230 #ifdef __cplusplus
231 extern "C" {
232 #endif
233 
234 MPP_RET dec_task_info_init(HalTaskInfo *task);
235 void dec_task_init(DecTask *task);
236 
237 MPP_RET mpp_dec_proc_cfg(MppDecImpl *dec, MpiCmd cmd, void *param);
238 
239 MPP_RET update_dec_hal_info(MppDecImpl *dec, MppFrame frame);
240 void mpp_dec_put_frame(Mpp *mpp, RK_S32 index, HalDecTaskFlag flags);
241 RK_S32 mpp_dec_push_display(Mpp *mpp, HalDecTaskFlag flags);
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 #endif /*__MPP_DEC_IMPL_H__*/
248