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 __RK_MPI_H__ 18 #define __RK_MPI_H__ 19 20 /** 21 * @addtogroup rk_mpi 22 * @brief Rockchip Media Process Interface 23 * @details Media Process Platform(MPP) provides application programming 24 * interface for the application layer, by which applications can 25 * call hardware encode and decode. Current MPP fully supports 26 * chipset RK3288/RK3228/RK3229/RK3399/RK3328/RV1108. Old chipset 27 * like RK29xx/RK30xx/RK31XX/RK3368 is partly supported due to lack 28 * of some hardware register generation module. 29 */ 30 31 #include "rk_mpi_cmd.h" 32 #include "mpp_task.h" 33 34 /** 35 * @ingroup rk_mpi 36 * @brief MPP main work function set 37 * @details all api function are seperated into two sets: data io api set 38 * and control api set 39 * 40 * (1). the data api set is for data input/output flow including: 41 * 42 * (1.1) simple data api set: 43 * 44 * decode : both send video stream packet to decoder and get video frame from 45 * decoder at the same time. 46 * 47 * encode : both send video frame to encoder and get encoded video stream from 48 * encoder at the same time. 49 * 50 * decode_put_packet: send video stream packet to decoder only, async interface 51 * 52 * decode_get_frame : get video frame from decoder only, async interface 53 * 54 * encode_put_frame : send video frame to encoder only, async interface 55 * 56 * encode_get_packet: get encoded video packet from encoder only, async interface 57 * 58 * (1.2) advanced task api set: 59 * 60 * poll : poll port for dequeue 61 * 62 * dequeue : pop a task from mpp task queue 63 * 64 * enqueue : push a task to mpp task queue 65 * 66 * (2). the control api set is for mpp context control including: 67 * 68 * control : similiar to ioctl in kernel driver, setup or get mpp internal parameter 69 * 70 * reset : clear all data in mpp context, discard all packet and frame, 71 * reset all components to initialized status 72 */ 73 typedef struct MppApi_t { 74 /** 75 * @brief size of struct MppApi 76 */ 77 RK_U32 size; 78 /** 79 * @brief mpp api version, generated by Git 80 */ 81 RK_U32 version; 82 83 // simple data flow interface 84 /** 85 * @brief both send video stream packet to decoder and get video frame from 86 * decoder at the same time 87 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 88 * by mpp_init(). 89 * @param[in] packet The input video stream, its usage can refer mpp_packet.h. 90 * @param[out] frame The output picture, its usage can refer mpp_frame.h. 91 * @return 0 and positive for success, negative for failure. The return 92 * value is an error code. For details, please refer mpp_err.h. 93 */ 94 MPP_RET (*decode)(MppCtx ctx, MppPacket packet, MppFrame *frame); 95 /** 96 * @brief send video stream packet to decoder only, async interface 97 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 98 * by mpp_init(). 99 * @param[in] packet The input video stream, its usage can refer mpp_packet.h. 100 * @return 0 and positive for success, negative for failure. The return 101 * value is an error code. For details, please refer mpp_err.h. 102 */ 103 MPP_RET (*decode_put_packet)(MppCtx ctx, MppPacket packet); 104 /** 105 * @brief get video frame from decoder only, async interface 106 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 107 * by mpp_init(). 108 * @param[out] frame The output picture, its usage can refer mpp_frame.h. 109 * @return 0 and positive for success, negative for failure. The return 110 * value is an error code. For details, please refer mpp_err.h. 111 */ 112 MPP_RET (*decode_get_frame)(MppCtx ctx, MppFrame *frame); 113 /** 114 * @brief both send video frame to encoder and get encoded video stream from 115 * encoder at the same time 116 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 117 * by mpp_init(). 118 * @param[in] frame The input video data, its usage can refer mpp_frame.h. 119 * @param[out] packet The output compressed data, its usage can refer mpp_packet.h. 120 * @return 0 and positive for success, negative for failure. The return 121 * value is an error code. For details, please refer mpp_err.h. 122 */ 123 MPP_RET (*encode)(MppCtx ctx, MppFrame frame, MppPacket *packet); 124 /** 125 * @brief send video frame to encoder only, async interface 126 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 127 * by mpp_init(). 128 * @param[in] frame The input video data, its usage can refer mpp_frame.h. 129 * @return 0 and positive for success, negative for failure. The return 130 * value is an error code. For details, please refer mpp_err.h. 131 */ 132 MPP_RET (*encode_put_frame)(MppCtx ctx, MppFrame frame); 133 /** 134 * @brief get encoded video packet from encoder only, async interface 135 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 136 * by mpp_init(). 137 * @param[out] packet The output compressed data, its usage can refer mpp_packet.h. 138 * @return 0 and positive for success, negative for failure. The return 139 * value is an error code. For details, please refer mpp_err.h. 140 */ 141 MPP_RET (*encode_get_packet)(MppCtx ctx, MppPacket *packet); 142 143 /** 144 * @brief ISP interface, will be supported in the future. 145 */ 146 MPP_RET (*isp)(MppCtx ctx, MppFrame dst, MppFrame src); 147 /** 148 * @brief ISP interface, will be supported in the future. 149 */ 150 MPP_RET (*isp_put_frame)(MppCtx ctx, MppFrame frame); 151 /** 152 * @brief ISP interface, will be supported in the future. 153 */ 154 MPP_RET (*isp_get_frame)(MppCtx ctx, MppFrame *frame); 155 156 // advance data flow interface 157 /** 158 * @brief poll port for dequeue 159 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 160 * by mpp_init(). 161 * @param[in] type input port or output port which are both for data transaction 162 * @param[in] timeout mpp poll type, its usage can refer mpp_task.h. 163 * @return 0 and positive for success, negative for failure. The return 164 * value is an error code. For details, please refer mpp_err.h. 165 */ 166 MPP_RET (*poll)(MppCtx ctx, MppPortType type, MppPollType timeout); 167 /** 168 * @brief dequeue MppTask, pop a task from mpp task queue 169 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 170 * by mpp_init(). 171 * @param[in] type input port or output port which are both for data transaction 172 * @param[out] task MppTask popped from mpp task queue, its usage can refer mpp_task.h. 173 * @return 0 and positive for success, negative for failure. The return 174 * value is an error code. For details, please refer mpp_err.h. 175 */ 176 MPP_RET (*dequeue)(MppCtx ctx, MppPortType type, MppTask *task); 177 /** 178 * @brief enqueue MppTask, push a task to mpp task queue 179 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 180 * by mpp_init(). 181 * @param[in] type input port or output port which are both for data transaction 182 * @param[in] task MppTask which is sent to mpp for process, its usage can refer mpp_task.h. 183 * @return 0 and positive for success, negative for failure. The return 184 * value is an error code. For details, please refer mpp_err.h. 185 */ 186 MPP_RET (*enqueue)(MppCtx ctx, MppPortType type, MppTask task); 187 188 // control interface 189 /** 190 * @brief discard all packet and frame, reset all component, 191 * for both decoder and encoder 192 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 193 * by mpp_init(). 194 * @return 0 for success, others for failure. The return value is an 195 * error code. For details, please refer mpp_err.h. 196 */ 197 MPP_RET (*reset)(MppCtx ctx); 198 /** 199 * @brief control function for mpp property setting 200 * @param[in] ctx The context of mpp, created by mpp_create() and initiated 201 * by mpp_init(). 202 * @param[in] cmd The mpi command, its definition can refer rk_mpi_cmd.h. 203 * @param[in,out] param The mpi command parameter 204 * @return 0 for success, others for failure. The return value is an 205 * error code. For details, please refer mpp_err.h. 206 */ 207 MPP_RET (*control)(MppCtx ctx, MpiCmd cmd, MppParam param); 208 209 /** 210 * @brief The reserved segment, may be used in the future 211 */ 212 RK_U32 reserv[16]; 213 } MppApi; 214 215 216 #ifdef __cplusplus 217 extern "C" { 218 #endif 219 220 /** 221 * @ingroup rk_mpi 222 * @brief Create empty context structure and mpi function pointers. 223 * Use functions in MppApi to access mpp services. 224 * @param[in,out] ctx pointer of the mpp context, refer to MpiImpl_t. 225 * @param[in,out] mpi pointer of mpi function, refer to MppApi. 226 * @return 0 for success, others for failure. The return value is an 227 * error code. For details, please refer mpp_err.h. 228 * @note This interface creates base flow context, all function calls 229 * are based on it. 230 */ 231 MPP_RET mpp_create(MppCtx *ctx, MppApi **mpi); 232 /** 233 * @ingroup rk_mpi 234 * @brief Call after mpp_create to setup mpp type and video format. 235 * This function will call internal context init function. 236 * @param[in] ctx The context of mpp, created by mpp_create(). 237 * @param[in] type specify decoder or encoder, refer to MppCtxType. 238 * @param[in] coding specify video compression coding, refer to MppCodingType. 239 * @return 0 for success, others for failure. The return value is an 240 * error code. For details, please refer mpp_err.h. 241 */ 242 MPP_RET mpp_init(MppCtx ctx, MppCtxType type, MppCodingType coding); 243 /** 244 * @ingroup rk_mpi 245 * @brief Destroy mpp context and free both context and mpi structure, 246 * it matches with mpp_init(). 247 * @param[in] ctx The context of mpp, created by mpp_create(). 248 * @return 0 for success, others for failure. The return value is an 249 * error code. For details, please refer mpp_err.h. 250 */ 251 MPP_RET mpp_destroy(MppCtx ctx); 252 /** 253 * @ingroup rk_mpi 254 * @brief judge given format is supported or not by MPP. 255 * @param[in] type specify decoder or encoder, refer to MppCtxType. 256 * @param[in] coding specify video compression coding, refer to MppCodingType. 257 * @return 0 for support, -1 for unsupported. 258 */ 259 MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding); 260 /** 261 * @ingroup rk_mpi 262 * @brief List all formats supported by MPP 263 * @param NULL no need to input parameter 264 * @return No return value. This function just prints format information supported 265 * by MPP on standard output. 266 */ 267 void mpp_show_support_format(void); 268 void mpp_show_color_format(void); 269 270 #ifdef __cplusplus 271 } 272 #endif 273 274 #endif /*__RK_MPI_H__*/ 275