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_H__ 18 #define __MPP_H__ 19 20 #include "mpp_queue.h" 21 #include "mpp_task_impl.h" 22 23 #include "mpp_dec.h" 24 #include "mpp_enc.h" 25 #include "mpp_impl.h" 26 27 #define MPP_DBG_FUNCTION (0x00000001) 28 #define MPP_DBG_PACKET (0x00000002) 29 #define MPP_DBG_FRAME (0x00000004) 30 #define MPP_DBG_BUFFER (0x00000008) 31 32 /* 33 * mpp notify event flags 34 * When event happens mpp will signal deocder / encoder with different flag. 35 * These event will wake up the codec thread or hal thread 36 */ 37 #define MPP_INPUT_ENQUEUE (0x00000001) 38 #define MPP_OUTPUT_DEQUEUE (0x00000002) 39 #define MPP_INPUT_DEQUEUE (0x00000004) 40 #define MPP_OUTPUT_ENQUEUE (0x00000008) 41 #define MPP_RESET (0xFFFFFFFF) 42 43 /* mpp dec event flags */ 44 #define MPP_DEC_NOTIFY_PACKET_ENQUEUE (MPP_INPUT_ENQUEUE) 45 #define MPP_DEC_NOTIFY_FRAME_DEQUEUE (MPP_OUTPUT_DEQUEUE) 46 #define MPP_DEC_NOTIFY_EXT_BUF_GRP_READY (0x00000010) 47 #define MPP_DEC_NOTIFY_INFO_CHG_DONE (0x00000020) 48 #define MPP_DEC_NOTIFY_BUFFER_VALID (0x00000040) 49 #define MPP_DEC_NOTIFY_TASK_ALL_DONE (0x00000080) 50 #define MPP_DEC_NOTIFY_TASK_HND_VALID (0x00000100) 51 #define MPP_DEC_NOTIFY_TASK_PREV_DONE (0x00000200) 52 #define MPP_DEC_NOTIFY_BUFFER_MATCH (0x00000400) 53 #define MPP_DEC_NOTIFY_SLOT_VALID (0x00004000) 54 #define MPP_DEC_CONTROL (0x00010000) 55 #define MPP_DEC_RESET (MPP_RESET) 56 57 /* mpp enc event flags */ 58 #define MPP_ENC_NOTIFY_FRAME_ENQUEUE (MPP_INPUT_ENQUEUE) 59 #define MPP_ENC_NOTIFY_PACKET_DEQUEUE (MPP_OUTPUT_DEQUEUE) 60 #define MPP_ENC_NOTIFY_FRAME_DEQUEUE (MPP_INPUT_DEQUEUE) 61 #define MPP_ENC_NOTIFY_PACKET_ENQUEUE (MPP_OUTPUT_ENQUEUE) 62 #define MPP_ENC_CONTROL (0x00000010) 63 #define MPP_ENC_RESET (MPP_RESET) 64 65 typedef enum MppIOMode_e { 66 MPP_IO_MODE_DEFAULT = -1, 67 MPP_IO_MODE_NORMAL = 0, 68 MPP_IO_MODE_TASK = 1, 69 MPP_IO_MODE_BUTT, 70 } MppIoMode; 71 72 /* 73 * mpp hierarchy 74 * 75 * mpp layer create mpp_dec or mpp_dec instance 76 * mpp_dec create its parser and hal module 77 * mpp_enc create its control and hal module 78 * 79 * +-------+ 80 * | | 81 * +-------------+ mpp +-------------+ 82 * | | | | 83 * | +-------+ | 84 * | | 85 * | | 86 * | | 87 * +-----+-----+ +-----+-----+ 88 * | | | | 89 * +---+ mpp_dec +--+ +--+ mpp_enc +---+ 90 * | | | | | | | | 91 * | +-----------+ | | +-----------+ | 92 * | | | | 93 * | | | | 94 * | | | | 95 * +-------v------+ +-----v-----+ +-----v-----+ +------v-------+ 96 * | | | | | | | | 97 * | dec_parser | | dec_hal | | enc_hal | | enc_control | 98 * | | | | | | | | 99 * +--------------+ +-----------+ +-----------+ +--------------+ 100 */ 101 102 #ifdef __cplusplus 103 104 class Mpp 105 { 106 public: 107 Mpp(MppCtx ctx = NULL); 108 ~Mpp(); 109 MPP_RET init(MppCtxType type, MppCodingType coding); 110 111 MPP_RET start(); 112 MPP_RET stop(); 113 114 MPP_RET pause(); 115 MPP_RET resume(); 116 117 MPP_RET put_packet(MppPacket packet); 118 MPP_RET get_frame(MppFrame *frame); 119 MPP_RET get_frame_noblock(MppFrame *frame); 120 121 MPP_RET put_frame(MppFrame frame); 122 MPP_RET get_packet(MppPacket *packet); 123 124 MPP_RET poll(MppPortType type, MppPollType timeout); 125 MPP_RET dequeue(MppPortType type, MppTask *task); 126 MPP_RET enqueue(MppPortType type, MppTask task); 127 128 MPP_RET decode(MppPacket packet, MppFrame *frame); 129 130 MPP_RET reset(); 131 MPP_RET control(MpiCmd cmd, MppParam param); 132 133 MPP_RET notify(RK_U32 flag); 134 MPP_RET notify(MppBufferGroup group); 135 136 mpp_list *mPktIn; 137 mpp_list *mPktOut; 138 mpp_list *mFrmIn; 139 mpp_list *mFrmOut; 140 /* counters for debug */ 141 RK_U32 mPacketPutCount; 142 RK_U32 mPacketGetCount; 143 RK_U32 mFramePutCount; 144 RK_U32 mFrameGetCount; 145 RK_U32 mTaskPutCount; 146 RK_U32 mTaskGetCount; 147 148 /* 149 * packet buffer group 150 * - packets in I/O, can be ion buffer or normal buffer 151 * frame buffer group 152 * - frames in I/O, normally should be a ion buffer group 153 */ 154 MppBufferGroup mPacketGroup; 155 MppBufferGroup mFrameGroup; 156 RK_U32 mExternalFrameGroup; 157 158 /* 159 * Mpp task queue for advance task mode 160 */ 161 /* 162 * Task data flow: 163 * | 164 * user | mpp 165 * mInputTaskQueue 166 * mUsrInPort -> | -> mMppInPort 167 * | | 168 * | v 169 * | process 170 * | | 171 * | v 172 * mUsrOutPort <- | <- mMppOutPort 173 * mOutputTaskQueue 174 */ 175 MppPort mUsrInPort; 176 MppPort mUsrOutPort; 177 MppPort mMppInPort; 178 MppPort mMppOutPort; 179 MppTaskQueue mInputTaskQueue; 180 MppTaskQueue mOutputTaskQueue; 181 182 MppPollType mInputTimeout; 183 MppPollType mOutputTimeout; 184 185 MppTask mInputTask; 186 MppTask mEosTask; 187 188 MppCtx mCtx; 189 MppDec mDec; 190 MppEnc mEnc; 191 192 RK_U32 mEncAyncIo; 193 RK_U32 mEncAyncProc; 194 MppIoMode mIoMode; 195 RK_U32 mDisableThread; 196 197 /* dump info for debug */ 198 MppDump mDump; 199 200 private: 201 void clear(); 202 203 MppCtxType mType; 204 MppCodingType mCoding; 205 206 RK_U32 mInitDone; 207 208 RK_U32 mStatus; 209 210 /* decoder paramter before init */ 211 MppDecCfgSet mDecInitcfg; 212 RK_U32 mParserFastMode; 213 RK_U32 mParserNeedSplit; 214 RK_U32 mParserInternalPts; /* for MPEG2/MPEG4 */ 215 RK_U32 mImmediateOut; 216 /* backup extra packet for seek */ 217 MppPacket mExtraPacket; 218 219 MPP_RET control_mpp(MpiCmd cmd, MppParam param); 220 MPP_RET control_osal(MpiCmd cmd, MppParam param); 221 MPP_RET control_codec(MpiCmd cmd, MppParam param); 222 MPP_RET control_dec(MpiCmd cmd, MppParam param); 223 MPP_RET control_enc(MpiCmd cmd, MppParam param); 224 MPP_RET control_isp(MpiCmd cmd, MppParam param); 225 226 /* for special encoder async io mode */ 227 MPP_RET put_frame_async(MppFrame frame); 228 MPP_RET get_packet_async(MppPacket *packet); 229 230 void set_io_mode(MppIoMode mode); 231 232 Mpp(const Mpp &); 233 Mpp &operator=(const Mpp &); 234 }; 235 236 237 extern "C" { 238 } 239 #endif 240 241 #endif /*__MPP_H__*/ 242