[vpu_api]: add legacy vpu_api interface and class

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@71 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2015-08-12 02:33:19 +00:00
parent 3ffb7ad699
commit 51b9c7b5ef
6 changed files with 682 additions and 0 deletions

260
inc/vpu_api.h Normal file
View File

@@ -0,0 +1,260 @@
/*
* Copyright 2010 Rockchip Electronics S.LSI Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __VPU_API_LEGACY_H__
#define __VPU_API_LEGACY_H__
#include "rk_type.h"
#include "mpp_err.h"
#define VPU_API_NOPTS_VALUE (0x8000000000000000LL)
typedef enum VPU_API_CMD
{
VPU_API_ENC_SETCFG,
VPU_API_ENC_GETCFG,
VPU_API_ENC_SETFORMAT,
VPU_API_ENC_SETIDRFRAME,
VPU_API_ENABLE_DEINTERLACE,
VPU_API_SET_VPUMEM_CONTEXT,
VPU_API_USE_PRESENT_TIME_ORDER,
VPU_API_SET_DEFAULT_WIDTH_HEIGH,
VPU_API_SET_INFO_CHANGE,
} VPU_API_CMD;
typedef struct VideoPacket {
RK_S64 pts; /* with unit of us*/
RK_S64 dts; /* with unit of us*/
RK_U8 *data;
RK_S32 size;
RK_U32 capability;
RK_U32 nFlags;
} VideoPacket_t;
typedef struct DecoderOut {
RK_U8 *data;
RK_U32 size;
RK_S64 timeUs;
RK_S32 nFlags;
} DecoderOut_t;
typedef struct ParserOut {
RK_U8 *data;
RK_U32 size;
RK_S64 timeUs;
RK_U32 nFlags;
RK_U32 width;
RK_U32 height;
} ParserOut_t;
typedef struct EncInputStream {
RK_U8 *buf;
RK_S32 size;
RK_U32 bufPhyAddr;
RK_S64 timeUs;
RK_U32 nFlags;
} EncInputStream_t;
typedef struct EncoderOut {
RK_U8 *data;
RK_S32 size;
RK_S64 timeUs;
RK_S32 keyFrame;
} EncoderOut_t;
typedef enum
{
VPU_H264ENC_YUV420_PLANAR = 0, /* YYYY... UUUU... VVVV */
VPU_H264ENC_YUV420_SEMIPLANAR = 1, /* YYYY... UVUVUV... */
VPU_H264ENC_YUV422_INTERLEAVED_YUYV = 2, /* YUYVYUYV... */
VPU_H264ENC_YUV422_INTERLEAVED_UYVY = 3, /* UYVYUYVY... */
VPU_H264ENC_RGB565 = 4, /* 16-bit RGB */
VPU_H264ENC_BGR565 = 5, /* 16-bit RGB */
VPU_H264ENC_RGB555 = 6, /* 15-bit RGB */
VPU_H264ENC_BGR555 = 7, /* 15-bit RGB */
VPU_H264ENC_RGB444 = 8, /* 12-bit RGB */
VPU_H264ENC_BGR444 = 9, /* 12-bit RGB */
VPU_H264ENC_RGB888 = 10, /* 24-bit RGB */
VPU_H264ENC_BGR888 = 11, /* 24-bit RGB */
VPU_H264ENC_RGB101010 = 12, /* 30-bit RGB */
VPU_H264ENC_BGR101010 = 13 /* 30-bit RGB */
} H264EncPictureType;
/*
* Enumeration used to define the possible video compression codings.
* NOTE: This essentially refers to file extensions. If the coding is
* being used to specify the ENCODE type, then additional work
* must be done to configure the exact flavor of the compression
* to be used. For decode cases where the user application can
* not differentiate between MPEG-4 and H.264 bit streams, it is
* up to the codec to handle this.
*/
//sync with the omx_video.h
typedef enum OMX_RK_VIDEO_CODINGTYPE {
OMX_RK_VIDEO_CodingUnused, /**< Value when coding is N/A */
OMX_RK_VIDEO_CodingAutoDetect, /**< Autodetection of coding type */
OMX_RK_VIDEO_CodingMPEG2, /**< AKA: H.262 */
OMX_RK_VIDEO_CodingH263, /**< H.263 */
OMX_RK_VIDEO_CodingMPEG4, /**< MPEG-4 */
OMX_RK_VIDEO_CodingWMV, /**< Windows Media Video (WMV1,WMV2,WMV3)*/
OMX_RK_VIDEO_CodingRV, /**< all versions of Real Video */
OMX_RK_VIDEO_CodingAVC, /**< H.264/AVC */
OMX_RK_VIDEO_CodingMJPEG, /**< Motion JPEG */
OMX_RK_VIDEO_CodingVP8, /**< VP8 */
OMX_RK_VIDEO_CodingVP9, /**< VP9 */
OMX_RK_VIDEO_CodingVC1 = 0x01000000, /**< Windows Media Video (WMV1,WMV2,WMV3)*/
OMX_RK_VIDEO_CodingFLV1, /**< Sorenson H.263 */
OMX_RK_VIDEO_CodingDIVX3, /**< DIVX3 */
OMX_RK_VIDEO_CodingVP6,
OMX_RK_VIDEO_CodingHEVC, /**< H.265/HEVC */
OMX_RK_VIDEO_CodingKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_RK_VIDEO_CodingVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_RK_VIDEO_CodingMax = 0x7FFFFFFF
} OMX_RK_VIDEO_CODINGTYPE;
typedef enum CODEC_TYPE {
CODEC_NONE,
CODEC_DECODER,
CODEC_ENCODER,
CODEC_BUTT,
} CODEC_TYPE;
typedef enum VPU_API_ERR{
VPU_API_OK = 0,
VPU_API_ERR_UNKNOW = -1,
VPU_API_ERR_BASE = -1000,
VPU_API_ERR_LIST_STREAM = VPU_API_ERR_BASE -1,
VPU_API_ERR_INIT = VPU_API_ERR_BASE -2,
VPU_API_ERR_VPU_CODEC_INIT = VPU_API_ERR_BASE -3,
VPU_API_ERR_STREAM = VPU_API_ERR_BASE -4,
VPU_API_ERR_FATAL_THREAD = VPU_API_ERR_BASE -5,
VPU_API_EOS_STREAM_REACHED = VPU_API_ERR_BASE -11,
VPU_API_ERR_BUTT,
} VPU_API_ERR;
typedef struct EncParameter
{
RK_S32 width;
RK_S32 height;
RK_S32 rc_mode;
RK_S32 bitRate;
RK_S32 framerate;
RK_S32 qp;
RK_S32 enableCabac;
RK_S32 cabacInitIdc;
RK_S32 format;
RK_S32 intraPicRate;
RK_S32 framerateout;
RK_S32 profileIdc;
RK_S32 levelIdc;
RK_S32 reserved[3];
} EncParameter_t;
typedef struct EXtraCfg {
RK_S32 vc1extra_size;
RK_S32 vp6codeid;
RK_S32 tsformat;
RK_U32 reserved[20];
} EXtraCfg_t;
/**
* @addtogroup rk_vpu_codec
* @{
*/
typedef struct VpuCodecContext {
void* vpuApiObj;
CODEC_TYPE codecType;
OMX_RK_VIDEO_CODINGTYPE videoCoding;
RK_U32 width;
RK_U32 height;
RK_U8 *extradata;
RK_S32 extradata_size;
RK_U8 enableparsing;
RK_S32 no_thread;
EXtraCfg_t extra_cfg;
void* private_data;
/*
** 1: error state(not working) 0: working
*/
RK_S32 decoder_err;
/**
* Allocate and initialize an VpuCodecContext.
*
* @param ctx The context of vpu api, allocated in this function.
* @param extraData The extra data of codec, some codecs need / can
* use extradata like Huffman tables, also live VC1 codec can
* use extradata to initialize itself.
* @param extra_size The size of extra data.
*
* @return 0 for init success, others for failure.
* note: check whether ctx has been allocated success after you do init.
*/
RK_S32 (*init)(struct VpuCodecContext *ctx, RK_U8 *extraData, RK_U32 extra_size);
/**
* @return 0 for decode success, others for failure.
*/
RK_S32 (*decode)(struct VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *aDecOut);
/**
* @return 0 for encode success, others for failure.
*/
RK_S32 (*encode)(struct VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut);
/**
* flush codec while do fast forward playing.
*
* @return 0 for flush success, others for failure.
*/
RK_S32 (*flush)(struct VpuCodecContext *ctx);
RK_S32 (*control)(struct VpuCodecContext *ctx, VPU_API_CMD cmdType, void* param);
/**
*seperate the decode function to two function
*
*/
RK_S32 (*decode_sendstream)(struct VpuCodecContext *ctx, VideoPacket_t *pkt);
RK_S32 (*decode_getframe)(struct VpuCodecContext *ctx, DecoderOut_t *aDecOut);
RK_S32 (*encoder_sendframe)(struct VpuCodecContext *ctx, EncInputStream_t *aEncInStrm);
RK_S32 (*encoder_getstream)(struct VpuCodecContext *ctx, EncoderOut_t *aEncOut);
}VpuCodecContext_t;
/* allocated vpu codec context */
#ifdef __cplusplus
extern "C"
{
#endif
RK_S32 vpu_open_context(struct VpuCodecContext **ctx);
RK_S32 vpu_close_context(struct VpuCodecContext **ctx);
#ifdef __cplusplus
}
#endif
#endif /*__VPU_API_LEGACY_H__*/

View File

@@ -25,4 +25,6 @@ add_library(mpp STATIC
target_link_libraries(mpp osal)
add_subdirectory(legacy)
add_subdirectory(test)

12
mpp/legacy/CMakeLists.txt Normal file
View File

@@ -0,0 +1,12 @@
# vim: syntax=cmake
include_directories(.)
# ----------------------------------------------------------------------------
# add mpp implement
# ----------------------------------------------------------------------------
add_library(mpp_legacy STATIC
vpu_api.cpp
vpu_api_legacy.cpp
)
target_link_libraries(mpp_legacy osal)

242
mpp/legacy/vpu_api.cpp Normal file
View File

@@ -0,0 +1,242 @@
/*
* Copyright 2010 Rockchip Electronics S.LSI Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "vpu_api_legacy"
#include <string.h>
#include "mpp_log.h"
#include "mpp_mem.h"
#include "vpu_api_legacy.h"
#include "vpu_api.h"
static RK_S32 vpu_api_init(VpuCodecContext *ctx, RK_U8 *extraData, RK_U32 extra_size)
{
mpp_log("vpu_api_init in, extra_size: %d", extra_size);
if (ctx == NULL) {
mpp_log("vpu_api_init fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_init fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->init(ctx, extraData, extra_size);
}
static RK_S32 vpu_api_decode(VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *aDecOut)
{
if (ctx == NULL) {
mpp_log("vpu_api_decode fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_decode fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->decode(ctx, pkt, aDecOut);
}
static RK_S32 vpu_api_sendstream(VpuCodecContext *ctx, VideoPacket_t *pkt)
{
if (ctx == NULL) {
mpp_log("vpu_api_decode fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_sendstream fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->decode_sendstream(ctx, pkt);
}
static RK_S32 vpu_api_getframe(VpuCodecContext *ctx, DecoderOut_t *aDecOut)
{
if (ctx == NULL) {
mpp_log("vpu_api_decode fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_getframe fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->decode_getoutframe(ctx,aDecOut);
}
static RK_S32 vpu_api_sendframe(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm)
{
if (ctx == NULL) {
mpp_log("vpu_api_decode fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_sendframe fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->encoder_sendframe(ctx, aEncInStrm);
}
static RK_S32 vpu_api_getstream(VpuCodecContext *ctx, EncoderOut_t *aEncOut)
{
if (ctx == NULL) {
mpp_log("vpu_api_decode fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_getframe fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->encoder_getstream(ctx,aEncOut);
}
static RK_S32 vpu_api_encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut)
{
if (ctx == NULL) {
mpp_log("vpu_api_encode fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_encode fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->encode(ctx, aEncInStrm, aEncOut);
}
static RK_S32 vpu_api_flush(VpuCodecContext *ctx)
{
if (ctx == NULL) {
mpp_log("vpu_api_encode fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_flush fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->flush(ctx);
}
static RK_S32 vpu_api_control(VpuCodecContext *ctx, VPU_API_CMD cmdType,void *param)
{
if (ctx == NULL) {
mpp_log("vpu_api_decode fail, input invalid");
return VPU_API_ERR_UNKNOW;
}
VpuApi* api = (VpuApi*)(ctx->vpuApiObj);
if (api == NULL) {
mpp_log("vpu_api_decode fail, vpu api invalid");
return VPU_API_ERR_UNKNOW;
}
return api->control(ctx, cmdType, param);
}
RK_S32 vpu_open_context(VpuCodecContext **ctx)
{
mpp_log("vpu_open_context in");
VpuCodecContext *s = *ctx;
if (!s) {
s = mpp_malloc(VpuCodecContext, 1);
if (!s) {
mpp_err("Input context has not been properly allocated");
return -1;
}
memset(s, 0, sizeof(VpuCodecContext));
s->enableparsing = 1;
VpuApi* api = new VpuApi();
if (api == NULL) {
mpp_err("Vpu api object has not been properly allocated");
return -1;
}
s->vpuApiObj = (void*)api;
s->init = vpu_api_init;
s->decode = vpu_api_decode;
s->encode = vpu_api_encode;
s->flush = vpu_api_flush;
s->control = vpu_api_control;
s->decode_sendstream = vpu_api_sendstream;
s->decode_getframe = vpu_api_getframe;
s->encoder_sendframe = vpu_api_sendframe;
s->encoder_getstream = vpu_api_getstream;
*ctx = s;
return 0;
}
if (!s->vpuApiObj){
mpp_err("Input context has not been properly allocated and is not NULL either");
return -1;
}
return 0;
}
RK_S32 vpu_close_context(VpuCodecContext **ctx)
{
mpp_log("vpu_close_context in");
VpuCodecContext *s = *ctx;
if (s) {
VpuApi* api = (VpuApi*)(s->vpuApiObj);
if (s->vpuApiObj) {
delete api;
s->vpuApiObj = NULL;
}
if (s->extradata) {
mpp_free(s->extradata);
s->extradata = NULL;
}
if(s->private_data){
mpp_free(s->private_data);
s->private_data = NULL;
}
mpp_free(s);
*ctx = s = NULL;
mpp_log("vpu_close_context ok");
}
return 0;
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright 2010 Rockchip Electronics S.LSI Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "vpu_api"
#include "mpp_log.h"
#include "vpu_api_legacy.h"
VpuApi::VpuApi()
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
}
VpuApi::~VpuApi()
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
}
RK_S32 VpuApi::init(VpuCodecContext *ctx, RK_U8 *extraData, RK_U32 extra_size)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::send_stream(RK_U8* buf, RK_U32 size, RK_S64 timestamp, RK_S32 usePts)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::get_frame(DecoderOut_t *aDecOut)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::flush(VpuCodecContext *ctx)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::decode(VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *aDecOut)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::decode_sendstream(VpuCodecContext *ctx, VideoPacket_t *pkt)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi:: decode_getoutframe(VpuCodecContext *ctx, DecoderOut_t *aDecOut)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::encoder_getstream(VpuCodecContext *ctx,EncoderOut_t *aEncOut)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::perform(RK_U32 cmd, RK_U32 *data)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}
RK_S32 VpuApi::control(VpuCodecContext *ctx, VPU_API_CMD cmd, void *param)
{
mpp_log("%s in\n", __FUNCTION__);
mpp_log("%s ok\n", __FUNCTION__);
return 0;
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2010 Rockchip Electronics S.LSI Co. LTD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _VPU_API_H_
#define _VPU_API_H_
#include "vpu_api.h"
class VpuApi {
public:
VpuApi();
~VpuApi();
RK_S32 init(VpuCodecContext *ctx, RK_U8 *extraData, RK_U32 extra_size);
RK_S32 flush(VpuCodecContext *ctx);
RK_S32 decode(VpuCodecContext *ctx, VideoPacket_t *pkt, DecoderOut_t *aDecOut);
RK_S32 decode_sendstream(VpuCodecContext *ctx, VideoPacket_t *pkt);
RK_S32 decode_getoutframe(VpuCodecContext *ctx,DecoderOut_t *aDecOut);
RK_S32 preProcessPacket(VpuCodecContext *ctx, VideoPacket_t *pkt);
RK_S32 encode(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm, EncoderOut_t *aEncOut);
RK_S32 encoder_sendframe(VpuCodecContext *ctx, EncInputStream_t *aEncInStrm);
RK_S32 encoder_getstream(VpuCodecContext *ctx, EncoderOut_t *aEncOut);
RK_S32 send_stream(RK_U8* buf, RK_U32 size, RK_S64 timestamp, RK_S32 usePts);
RK_S32 get_frame(DecoderOut_t *aDecOut);
RK_S32 perform(RK_U32 cmd, RK_U32 *data);
RK_S32 control(VpuCodecContext *ctx, VPU_API_CMD cmd, void *param);
};
#endif /*_VPU_API_H_*/