From 32c1b2f18cc6e6d70e5d24ae173ea71894829d2a Mon Sep 17 00:00:00 2001 From: ChenHengming Date: Mon, 17 Aug 2015 09:16:26 +0000 Subject: [PATCH] [mpi]: add basic mpi empty function git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@114 6e48237b-75ef-9749-8fc9-41990f28c85a --- inc/mpp_buffer.h | 66 ++++++++++++++++++++++++++++++++++ inc/mpp_err.h | 3 ++ inc/mpp_frame.h | 41 +++++++++++++++++++++ inc/mpp_packet.h | 39 ++++++++++++++++++++ inc/rk_mpi.h | 70 ++++++++++++++++++++++++++++++++++++ mpp/CMakeLists.txt | 2 ++ mpp/mpi.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++ mpp/mpi_impl.cpp | 24 +++++++++++++ mpp/mpi_impl.h | 53 ++++++++++++++++++++++++++++ 9 files changed, 386 insertions(+) create mode 100644 inc/mpp_buffer.h create mode 100644 inc/mpp_frame.h create mode 100644 inc/mpp_packet.h create mode 100644 mpp/mpi.cpp create mode 100644 mpp/mpi_impl.cpp create mode 100644 mpp/mpi_impl.h diff --git a/inc/mpp_buffer.h b/inc/mpp_buffer.h new file mode 100644 index 00000000..fe7c2bf5 --- /dev/null +++ b/inc/mpp_buffer.h @@ -0,0 +1,66 @@ +/* + * 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 __RK_MPI_BUFFER_H__ +#define __RK_MPI_BUFFER_H__ + +#include "rk_type.h" +#include "mpp_err.h" + +typedef void* MppBuffer; +typedef void* MppBufferPool; + +typedef struct { + RK_U32 api_size; + RK_U32 api_version; + + MPP_RET (*commit)(MppBufferPool pool, MppBuffer buffer); + + MPP_RET (*get_unused)(MppBufferPool pool, MppBuffer *buffer); + MPP_RET (*ref_used)(MppBufferPool pool, MppBuffer buffer); + MPP_RET (*unref_used)(MppBufferPool pool, MppBuffer buffer); + + MPP_RET (*reset)(MppBufferPool pool); + RK_S32 (*get_unsed_num)(MppBufferPool pool); + + RK_U32 reserv[16]; +} MppBufferPoolApi; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * MppBufferPool interface + */ +MPP_RET mpp_buffer_init(MppBuffer *buffer, RK_U32 type, RK_U32 size); +MPP_RET mpp_buffer_deinit(MppBuffer *buffer); +MPP_RET mpp_buffer_inc_ref(MppBuffer buffer); +MPP_RET mpp_buffer_dec_ref(MppBuffer buffer); + +/* + * MppBufferPool interface + */ +MPP_RET mpp_buffer_pool_init(MppBufferPool *pool, RK_U32 count, RK_U32 size); +MPP_RET mpp_buffer_pool_get_api(MppBufferPool pool, MppBufferPoolApi *api); +MPP_RET mpp_buffer_pool_deinit(MppBufferPool *pool); + +#ifdef __cplusplus +} +#endif + +#endif /*__RK_MPI_BUFFER_H__*/ diff --git a/inc/mpp_err.h b/inc/mpp_err.h index 6e7b21a1..7c80d421 100644 --- a/inc/mpp_err.h +++ b/inc/mpp_err.h @@ -25,6 +25,9 @@ typedef enum { MPP_OK = RK_OK, MPP_ERR_UNKNOW = -1, + MPP_ERR_NULL_PTR = -2, + MPP_ERR_MALLOC = -3, + MPP_ERR_BASE = -1000, MPP_ERR_LIST_STREAM = MPP_ERR_BASE - 1, diff --git a/inc/mpp_frame.h b/inc/mpp_frame.h new file mode 100644 index 00000000..bd6d806b --- /dev/null +++ b/inc/mpp_frame.h @@ -0,0 +1,41 @@ +/* + * 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 __MPP_FRAME_H__ +#define __MPP_FRAME_H__ + +#include "rk_type.h" +#include "mpp_err.h" + +typedef void* MppFrame; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * MppFrame interface + */ +MPP_RET mpp_frame_init(MppFrame *frame, RK_U8 *data, RK_U32 size); +MPP_RET mpp_frame_deinit(MppFrame *frame); +MPP_RET mpp_frame_get_info(MppFrame frame); + +#ifdef __cplusplus +} +#endif + +#endif /*__MPP_FRAME_H__*/ diff --git a/inc/mpp_packet.h b/inc/mpp_packet.h new file mode 100644 index 00000000..4c814415 --- /dev/null +++ b/inc/mpp_packet.h @@ -0,0 +1,39 @@ +/* + * 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 __MPP_PACKET_H__ +#define __MPP_PACKET_H__ + +#include "rk_type.h" +#include "mpp_err.h" + +typedef void* MppPacket; + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * MppPacket interface + */ +MPP_RET mpp_packet_init(MppPacket *packet, void *data, RK_U32 size); +MPP_RET mpp_packet_deinit(MppPacket *packet); + +#ifdef __cplusplus +} +#endif + +#endif /*__MPP_PACKET_H__*/ diff --git a/inc/rk_mpi.h b/inc/rk_mpi.h index bd855b50..7fdb7ebc 100644 --- a/inc/rk_mpi.h +++ b/inc/rk_mpi.h @@ -17,5 +17,75 @@ #ifndef __RK_MPI_H__ #define __RK_MPI_H__ +#include "rk_type.h" + +#include "mpp_err.h" +#include "mpp_packet.h" +#include "mpp_buffer.h" +#include "mpp_frame.h" + +typedef enum { + MPI_MPP_CMD_BASE = 0, + MPI_MPP_ENABLE_DEINTERLACE, + + MPI_HAL_CMD_BASE = 0x10000, + + MPI_OSAL_CMD_BASE = 0x20000, + MPI_OSAL_SET_VPUMEM_CONTEXT, + + MPI_CODEC_CMD_BASE = 0x30000, + MPI_CODEC_INFO_CHANGE, + MPI_CODEC_SET_DEFAULT_WIDTH_HEIGH, + + MPI_DEC_CMD_BASE = 0x40000, + MPI_DEC_USE_PRESENT_TIME_ORDER, + + MPI_ENC_CMD_BASE = 0x50000, + MPI_ENC_SETCFG, + MPI_ENC_GETCFG, + MPI_ENC_SETFORMAT, + MPI_ENC_SETIDRFRAME, +} MPI_CMD; + + +typedef void* MppCtx; +typedef void* MppParam; + +typedef struct { + RK_U32 mpi_size; + RK_U32 mpi_version; + + MPP_RET (*init)(MppCtx ctx, MppPacket packet); + // sync interface + MPP_RET (*decode)(MppCtx ctx, MppPacket packet, MppFrame *frame); + MPP_RET (*encode)(MppCtx ctx, MppFrame frame, MppPacket *packet); + + // async interface + MPP_RET (*decode_put_packet)(MppCtx ctx, MppPacket packet); + MPP_RET (*decode_get_frame)(MppCtx ctx, MppFrame *frame); + + MPP_RET (*encode_put_frame)(MppCtx ctx, MppFrame frame); + MPP_RET (*encode_get_packet)(MppCtx ctx, MppPacket *packet); + + MPP_RET (*flush)(MppCtx ctx); + MPP_RET (*control)(MppCtx ctx, MPI_CMD cmd, MppParam param); + + RK_U32 reserv[16]; +} MppApi; + + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * mpp interface + */ +MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi); +MPP_RET mpp_deinit(MppCtx* ctx); + +#ifdef __cplusplus +} +#endif #endif /*__RK_MPI_H__*/ diff --git a/mpp/CMakeLists.txt b/mpp/CMakeLists.txt index f91fe048..be66bf73 100644 --- a/mpp/CMakeLists.txt +++ b/mpp/CMakeLists.txt @@ -21,6 +21,8 @@ add_subdirectory(hal) # ---------------------------------------------------------------------------- add_library(mpp STATIC mpp_info.cpp + mpi_impl.cpp + mpi.cpp ) add_subdirectory(legacy) diff --git a/mpp/mpi.cpp b/mpp/mpi.cpp new file mode 100644 index 00000000..8ea2b58d --- /dev/null +++ b/mpp/mpi.cpp @@ -0,0 +1,88 @@ +/* + * 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 MODULE_TAG "mpi" + +#include + +#include "rk_mpi.h" + +#include "mpp_log.h" +#include "mpp_mem.h" +#include "mpi_impl.h" + + +MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi) +{ + MpiImpl *p; + MppApi *api; + MPI_FUNCTION_ENTER(); + + if (NULL == ctx || NULL == mpi) { + mpp_err("mpp_init input ctx %p mpi %p found null pointer\n", + ctx, mpi); + return MPP_ERR_NULL_PTR; + } + + p = mpp_malloc(MpiImpl, 1); + if (NULL == p) { + mpp_err("mpp_init failed to allocate context\n"); + return MPP_ERR_MALLOC; + } + + api = mpp_malloc(MppApi, 1); + if (NULL == api) { + mpp_err("mpp_init failed to allocate mpi\n"); + mpp_free(p); + return MPP_ERR_MALLOC; + } + + memset(p, 0, sizeof(*p)); + memset(api, 0, sizeof(*api)); + p->api = api; + p->check = p; + *ctx = p; + + MPI_FUNCTION_LEAVE_OK(); + return MPP_OK; +} + +MPP_RET mpp_deinit(MppCtx* ctx) +{ + MpiImpl *p; + MPI_FUNCTION_ENTER(); + + if (NULL == ctx) { + mpp_err("mpp_deinit input ctx %p is null pointer\n", ctx); + return MPP_ERR_NULL_PTR; + } + + p = (MpiImpl*)*ctx; + + if (p->check != p) { + mpp_err("mpp_deinit input invalid MppCtx\n"); + return MPP_ERR_UNKNOW; + } + + if (p->api) + mpp_free(p->api); + if (p) + mpp_free(p->api); + + MPI_FUNCTION_LEAVE(); + return MPP_OK; +} + diff --git a/mpp/mpi_impl.cpp b/mpp/mpi_impl.cpp new file mode 100644 index 00000000..289ab2b3 --- /dev/null +++ b/mpp/mpi_impl.cpp @@ -0,0 +1,24 @@ +/* + * 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 MODULE_TAG "mpi" + +#include "rk_mpi.h" +#include "mpp_log.h" +#include "mpi_impl.h" + +RK_U32 mpi_debug = 0; + diff --git a/mpp/mpi_impl.h b/mpp/mpi_impl.h new file mode 100644 index 00000000..4cd5502e --- /dev/null +++ b/mpp/mpi_impl.h @@ -0,0 +1,53 @@ +/* + * 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 __MPP_IMPL_H__ +#define __MPP_IMPL_H__ + +#include "rk_type.h" +#include "rk_mpi.h" +#include "vpu_api.h" + +#define MPI_DBG_FUNCTION (0x00000001) + + + +#define mpi_dbg(flag, fmt, ...) mpp_dbg(mpi_debug, flag, fmt, ## __VA_ARGS__) + +#define MPI_FUNCTION_ENTER() mpi_dbg(MPI_DBG_FUNCTION, "%s enter\n", __FUNCTION__) +#define MPI_FUNCTION_LEAVE() mpi_dbg(MPI_DBG_FUNCTION, "%s leave\n", __FUNCTION__) +#define MPI_FUNCTION_LEAVE_OK() mpi_dbg(MPI_DBG_FUNCTION, "%s success\n", __FUNCTION__) +#define MPI_FUNCTION_LEAVE_FAIL() mpi_dbg(MPI_DBG_FUNCTION, "%s failed\n", __FUNCTION__) + +typedef struct MpiImpl_t MpiImpl; + +struct MpiImpl_t { + MpiImpl *check; + MppApi *api; + void *ctx; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +extern RK_U32 mpi_debug; + +#ifdef __cplusplus +} +#endif + +#endif /*__MPP_IMPL_H__*/