xref: /rockchip-linux_mpp/mpp/codec/inc/mpp_dec_impl.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
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     MppDecCfg           cfg_obj;
94     MppDecCfgSet        *cfg;
95 
96     /* control process */
97     MppMutexCond        cmd_lock;
98     RK_U32              cmd_send;
99     RK_U32              cmd_recv;
100     MpiCmd              cmd;
101     void                *param;
102     MPP_RET             *cmd_ret;
103     sem_t               cmd_start;
104     sem_t               cmd_done;
105 
106     // status flags
107     RK_U32              parser_work_count;
108     RK_U32              parser_wait_count;
109     RK_U32              parser_status_flag;
110     RK_U32              parser_wait_flag;
111     RK_U32              parser_notify_flag;
112     RK_U32              hal_notify_flag;
113 
114     // reset process:
115     // 1. mpp_dec set reset flag and signal parser
116     // 2. mpp_dec wait on parser_reset sem
117     // 3. parser wait hal reset done
118     // 4. hal wait vproc reset done
119     // 5. vproc do reset and signal hal
120     // 6. hal do reset and signal parser
121     // 7. parser do reset and signal mpp_dec
122     // 8. mpp_dec reset done
123     RK_U32              reset_flag;
124 
125     RK_U32              hal_reset_post;
126     RK_U32              hal_reset_done;
127     sem_t               parser_reset;
128     sem_t               hal_reset;
129 
130     // work mode flags
131     RK_U32              parser_fast_mode;
132     RK_U32              disable_error;
133     RK_U32              dis_err_clr_mark;
134     RK_U32              enable_deinterlace;
135 
136     // dec parser thread runtime resource context
137     MppPacket           mpp_pkt_in;
138     void                *mpp;
139     void                *vproc;
140 
141     // statistics data
142     RK_U32              statistics_en;
143     MppClock            clocks[DEC_TIMING_BUTT];
144 
145     // query data
146     RK_U32              dec_in_pkt_count;
147     RK_U32              dec_hw_run_count;
148     RK_U32              dec_out_frame_count;
149 
150     MppMemPool          ts_pool;
151     struct list_head    ts_link;
152     spinlock_t          ts_lock;
153     void                *task_single;
154 };
155 
156 /* external wait state */
157 #define MPP_DEC_WAIT_PKT_IN             (0x00000001)    /* input packet not ready */
158 #define MPP_DEC_WAIT_FRM_OUT            (0x00000002)    /* frame output queue full */
159 
160 #define MPP_DEC_WAIT_INFO_CHG           (0x00000020)    /* wait info change ready */
161 #define MPP_DEC_WAIT_BUF_RDY            (0x00000040)    /* wait valid frame buffer */
162 #define MPP_DEC_WAIT_TSK_ALL_DONE       (0x00000080)    /* wait all task done */
163 
164 #define MPP_DEC_WAIT_TSK_HND_RDY        (0x00000100)    /* wait task handle ready */
165 #define MPP_DEC_WAIT_TSK_PREV_DONE      (0x00000200)    /* wait previous task done */
166 #define MPP_DEC_WAIT_BUF_GRP_RDY        (0x00000200)    /* wait buffer group change ready */
167 
168 /* internal wait state */
169 #define MPP_DEC_WAIT_BUF_SLOT_RDY       (0x00001000)    /* wait buffer slot ready */
170 #define MPP_DEC_WAIT_PKT_BUF_RDY        (0x00002000)    /* wait packet buffer ready */
171 #define MPP_DEC_WAIT_BUF_SLOT_KEEP      (0x00004000)    /* wait buffer slot reservation */
172 
173 typedef union PaserTaskWait_u {
174     RK_U32          val;
175     struct {
176         RK_U32      dec_pkt_in      : 1;   // 0x0001 MPP_DEC_NOTIFY_PACKET_ENQUEUE
177         RK_U32      dis_que_full    : 1;   // 0x0002 MPP_DEC_NOTIFY_FRAME_DEQUEUE
178         RK_U32      reserv0004      : 1;   // 0x0004
179         RK_U32      reserv0008      : 1;   // 0x0008
180 
181         RK_U32      ext_buf_grp     : 1;   // 0x0010 MPP_DEC_NOTIFY_EXT_BUF_GRP_READY
182         RK_U32      info_change     : 1;   // 0x0020 MPP_DEC_NOTIFY_INFO_CHG_DONE
183         RK_U32      dec_pic_unusd   : 1;   // 0x0040 MPP_DEC_NOTIFY_BUFFER_VALID
184         RK_U32      dec_all_done    : 1;   // 0x0080 MPP_DEC_NOTIFY_TASK_ALL_DONE
185 
186         RK_U32      task_hnd        : 1;   // 0x0100 MPP_DEC_NOTIFY_TASK_HND_VALID
187         RK_U32      prev_task       : 1;   // 0x0200 MPP_DEC_NOTIFY_TASK_PREV_DONE
188         RK_U32      dec_pic_match   : 1;   // 0x0400 MPP_DEC_NOTIFY_BUFFER_MATCH
189         RK_U32      reserv0800      : 1;   // 0x0800
190 
191         RK_U32      dec_pkt_idx     : 1;   // 0x1000
192         RK_U32      dec_pkt_buf     : 1;   // 0x2000
193         RK_U32      dec_slot_idx    : 1;   // 0x4000 MPP_DEC_NOTIFY_SLOT_VALID
194     };
195 } PaserTaskWait;
196 
197 typedef union DecTaskStatus_u {
198     RK_U32          val;
199     struct {
200         RK_U32      task_hnd_rdy      : 1;
201         RK_U32      mpp_pkt_in_rdy    : 1;
202         RK_U32      dec_pkt_idx_rdy   : 1;
203         RK_U32      dec_pkt_buf_rdy   : 1;
204         RK_U32      task_valid_rdy    : 1;
205         RK_U32      dec_pkt_copy_rdy  : 1;
206         RK_U32      prev_task_rdy     : 1;
207         RK_U32      info_task_gen_rdy : 1;
208         RK_U32      curr_task_rdy     : 1;
209         RK_U32      task_parsed_rdy   : 1;
210         RK_U32      mpp_in_frm_at_pkt : 1;
211     };
212 } DecTaskStatus;
213 
214 typedef struct MppPktTimestamp_t {
215     struct list_head link;
216     RK_S64  pts;
217     RK_S64  dts;
218 } MppPktTs;
219 
220 typedef struct DecTask_t {
221     HalTaskHnd      hnd;
222 
223     DecTaskStatus   status;
224     PaserTaskWait   wait;
225 
226     HalTaskInfo     info;
227     MppPktTs        ts_cur;
228 
229     MppBuffer       hal_pkt_buf_in;
230     MppBuffer       hal_frm_buf_out;
231 } DecTask;
232 
233 #ifdef __cplusplus
234 extern "C" {
235 #endif
236 
237 MPP_RET dec_task_info_init(HalTaskInfo *task);
238 void dec_task_init(DecTask *task);
239 
240 MPP_RET mpp_dec_proc_cfg(MppDecImpl *dec, MpiCmd cmd, void *param);
241 
242 MPP_RET update_dec_hal_info(MppDecImpl *dec, MppFrame frame);
243 void mpp_dec_put_frame(Mpp *mpp, RK_S32 index, HalDecTaskFlag flags);
244 RK_S32 mpp_dec_push_display(Mpp *mpp, HalDecTaskFlag flags);
245 
246 #ifdef __cplusplus
247 }
248 #endif
249 
250 #endif /*__MPP_DEC_IMPL_H__*/
251