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