mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-06 17:46:50 +08:00
[mpi]: add mpp context check to mpi functions
git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@542 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
150
mpp/mpi.cpp
150
mpp/mpi.cpp
@@ -26,11 +26,26 @@
|
|||||||
#include "mpp.h"
|
#include "mpp.h"
|
||||||
#include "mpp_info.h"
|
#include "mpp_info.h"
|
||||||
|
|
||||||
|
#define check_mpp_ctx(ctx) _check_mpp_ctx(ctx, __FUNCTION__)
|
||||||
|
|
||||||
|
static MPP_RET _check_mpp_ctx(MpiImpl *p, const char *caller)
|
||||||
|
{
|
||||||
|
if (NULL == p || p->check != p || NULL == p->ctx) {
|
||||||
|
_mpp_err(MODULE_TAG, "found invalid context %p\n", caller, p);
|
||||||
|
return MPP_ERR_UNKNOW;
|
||||||
|
}
|
||||||
|
return MPP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static MPP_RET mpi_config(MppCtx ctx, MppEncConfig cfg)
|
static MPP_RET mpi_config(MppCtx ctx, MppEncConfig cfg)
|
||||||
{
|
{
|
||||||
(void)ctx;
|
|
||||||
(void)cfg;
|
(void)cfg;
|
||||||
|
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
@@ -38,10 +53,14 @@ static MPP_RET mpi_config(MppCtx ctx, MppEncConfig cfg)
|
|||||||
|
|
||||||
static MPP_RET mpi_decode(MppCtx ctx, MppPacket packet, MppFrame *frame)
|
static MPP_RET mpi_decode(MppCtx ctx, MppPacket packet, MppFrame *frame)
|
||||||
{
|
{
|
||||||
(void)ctx;
|
|
||||||
(void)packet;
|
(void)packet;
|
||||||
(void)frame;
|
(void)frame;
|
||||||
|
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
@@ -49,10 +68,14 @@ static MPP_RET mpi_decode(MppCtx ctx, MppPacket packet, MppFrame *frame)
|
|||||||
|
|
||||||
static MPP_RET mpi_encode(MppCtx ctx, MppFrame frame, MppPacket *packet)
|
static MPP_RET mpi_encode(MppCtx ctx, MppFrame frame, MppPacket *packet)
|
||||||
{
|
{
|
||||||
(void)ctx;
|
|
||||||
(void)packet;
|
(void)packet;
|
||||||
(void)frame;
|
(void)frame;
|
||||||
|
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return MPP_OK;
|
return MPP_OK;
|
||||||
@@ -61,15 +84,18 @@ static MPP_RET mpi_encode(MppCtx ctx, MppFrame frame, MppPacket *packet)
|
|||||||
static MPP_RET mpi_decode_put_packet(MppCtx ctx, MppPacket packet)
|
static MPP_RET mpi_decode_put_packet(MppCtx ctx, MppPacket packet)
|
||||||
{
|
{
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
MpiImpl *p = (MpiImpl *)ctx;
|
|
||||||
|
|
||||||
if (NULL == p || p->check != p || NULL == p->ctx || NULL == packet) {
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
mpp_err_f("found invalid context input ctx %p packet %p\n",
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
ctx, packet);
|
if (ret)
|
||||||
return MPP_ERR_UNKNOW;
|
return ret;
|
||||||
|
|
||||||
|
if (NULL == packet) {
|
||||||
|
mpp_err_f("found NULL input packet\n", packet);
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
MPP_RET ret = p->ctx->put_packet(packet);
|
ret = p->ctx->put_packet(packet);
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return ret;
|
return ret;
|
||||||
@@ -78,15 +104,18 @@ static MPP_RET mpi_decode_put_packet(MppCtx ctx, MppPacket packet)
|
|||||||
static MPP_RET mpi_decode_get_frame(MppCtx ctx, MppFrame *frame)
|
static MPP_RET mpi_decode_get_frame(MppCtx ctx, MppFrame *frame)
|
||||||
{
|
{
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
MpiImpl *p = (MpiImpl *)ctx;
|
|
||||||
|
|
||||||
if (NULL == p || p->check != p || NULL == p->ctx || NULL == frame) {
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
mpp_err_f("found invalid context input ctx %p frame %p\n",
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
ctx, frame);
|
if (ret)
|
||||||
return MPP_ERR_UNKNOW;
|
return ret;
|
||||||
|
|
||||||
|
if (NULL == frame) {
|
||||||
|
mpp_err_f("found NULL input frame\n", frame);
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
MPP_RET ret = p->ctx->get_frame(frame);
|
ret = p->ctx->get_frame(frame);
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return ret;
|
return ret;
|
||||||
@@ -95,15 +124,18 @@ static MPP_RET mpi_decode_get_frame(MppCtx ctx, MppFrame *frame)
|
|||||||
static MPP_RET mpi_encode_put_frame(MppCtx ctx, MppFrame frame)
|
static MPP_RET mpi_encode_put_frame(MppCtx ctx, MppFrame frame)
|
||||||
{
|
{
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
MpiImpl *p = (MpiImpl *)ctx;
|
|
||||||
|
|
||||||
if (NULL == p || p->check != p || NULL == p->ctx || NULL == frame) {
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
mpp_err_f("found invalid context input ctx %p frame %p\n",
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
ctx, frame);
|
if (ret)
|
||||||
return MPP_ERR_UNKNOW;
|
return ret;
|
||||||
|
|
||||||
|
if (NULL == frame) {
|
||||||
|
mpp_err_f("found NULL input frame\n", frame);
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
MPP_RET ret = p->ctx->put_frame(frame);
|
ret = p->ctx->put_frame(frame);
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return ret;
|
return ret;
|
||||||
@@ -112,15 +144,18 @@ static MPP_RET mpi_encode_put_frame(MppCtx ctx, MppFrame frame)
|
|||||||
static MPP_RET mpi_encode_get_packet(MppCtx ctx, MppPacket *packet)
|
static MPP_RET mpi_encode_get_packet(MppCtx ctx, MppPacket *packet)
|
||||||
{
|
{
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
MpiImpl *p = (MpiImpl *)ctx;
|
|
||||||
|
|
||||||
if (NULL == p || p->check != p || NULL == p->ctx || NULL == packet) {
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
mpp_err_f("found invalid context input ctx %p packet %p\n",
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
ctx, packet);
|
if (ret)
|
||||||
return MPP_ERR_UNKNOW;
|
return ret;
|
||||||
|
|
||||||
|
if (NULL == packet) {
|
||||||
|
mpp_err_f("found NULL input packet\n", packet);
|
||||||
|
return MPP_ERR_NULL_PTR;
|
||||||
}
|
}
|
||||||
|
|
||||||
MPP_RET ret = p->ctx->get_packet(packet);
|
ret = p->ctx->get_packet(packet);
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return ret;
|
return ret;
|
||||||
@@ -128,10 +163,20 @@ static MPP_RET mpi_encode_get_packet(MppCtx ctx, MppPacket *packet)
|
|||||||
|
|
||||||
static MPP_RET mpi_reset(MppCtx ctx)
|
static MPP_RET mpi_reset(MppCtx ctx)
|
||||||
{
|
{
|
||||||
MpiImpl *p = (MpiImpl *)ctx;
|
|
||||||
MPP_RET ret = MPP_OK;
|
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
|
||||||
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (NULL == p || p->check != p || NULL == p->ctx) {
|
||||||
|
mpp_err_f("found invalid context input ctx %p\n", ctx);
|
||||||
|
return MPP_ERR_UNKNOW;
|
||||||
|
}
|
||||||
|
|
||||||
ret = p->ctx->reset();
|
ret = p->ctx->reset();
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -139,8 +184,19 @@ static MPP_RET mpi_reset(MppCtx ctx)
|
|||||||
static MPP_RET mpi_control(MppCtx ctx, MpiCmd cmd, MppParam param)
|
static MPP_RET mpi_control(MppCtx ctx, MpiCmd cmd, MppParam param)
|
||||||
{
|
{
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
|
||||||
MpiImpl *p = (MpiImpl *)ctx;
|
MpiImpl *p = (MpiImpl *)ctx;
|
||||||
MPP_RET ret = p->ctx->control(cmd, param);
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (NULL == p || p->check != p || NULL == p->ctx) {
|
||||||
|
mpp_err_f("found invalid context input ctx %p\n", ctx);
|
||||||
|
return MPP_ERR_UNKNOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = p->ctx->control(cmd, param);
|
||||||
|
|
||||||
MPI_FUNCTION_LEAVE();
|
MPI_FUNCTION_LEAVE();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -162,8 +218,6 @@ static MppApi mpp_api = {
|
|||||||
|
|
||||||
MPP_RET mpp_create(MppCtx *ctx, MppApi **mpi)
|
MPP_RET mpp_create(MppCtx *ctx, MppApi **mpi)
|
||||||
{
|
{
|
||||||
MpiImpl *p;
|
|
||||||
|
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
|
||||||
if (NULL == ctx || NULL == mpi) {
|
if (NULL == ctx || NULL == mpi) {
|
||||||
@@ -174,7 +228,7 @@ MPP_RET mpp_create(MppCtx *ctx, MppApi **mpi)
|
|||||||
*ctx = NULL;
|
*ctx = NULL;
|
||||||
*mpi = NULL;
|
*mpi = NULL;
|
||||||
|
|
||||||
p = mpp_malloc(MpiImpl, 1);
|
MpiImpl *p = mpp_malloc(MpiImpl, 1);
|
||||||
if (NULL == p) {
|
if (NULL == p) {
|
||||||
mpp_err_f("failed to allocate context\n");
|
mpp_err_f("failed to allocate context\n");
|
||||||
return MPP_ERR_MALLOC;
|
return MPP_ERR_MALLOC;
|
||||||
@@ -202,15 +256,17 @@ MPP_RET mpp_create(MppCtx *ctx, MppApi **mpi)
|
|||||||
|
|
||||||
MPP_RET mpp_init(MppCtx ctx, MppCtxType type, MppCodingType coding)
|
MPP_RET mpp_init(MppCtx ctx, MppCtxType type, MppCodingType coding)
|
||||||
{
|
{
|
||||||
MpiImpl *p = (MpiImpl*)ctx;
|
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
|
||||||
if (NULL == ctx ||
|
MpiImpl *p = (MpiImpl*)ctx;
|
||||||
type >= MPP_CTX_BUTT ||
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (type >= MPP_CTX_BUTT ||
|
||||||
coding >= MPP_VIDEO_CodingMax) {
|
coding >= MPP_VIDEO_CodingMax) {
|
||||||
mpp_err_f("invalid input ctx %p type %d coding %d\n",
|
mpp_err_f("invalid input type %d coding %d\n", type, coding);
|
||||||
ctx, type, coding);
|
return MPP_ERR_UNKNOW;
|
||||||
return MPP_ERR_NULL_PTR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p->ctx->init(type, coding);
|
p->ctx->init(type, coding);
|
||||||
@@ -224,20 +280,12 @@ MPP_RET mpp_init(MppCtx ctx, MppCtxType type, MppCodingType coding)
|
|||||||
|
|
||||||
MPP_RET mpp_destroy(MppCtx ctx)
|
MPP_RET mpp_destroy(MppCtx ctx)
|
||||||
{
|
{
|
||||||
MpiImpl *p;
|
|
||||||
MPI_FUNCTION_ENTER();
|
MPI_FUNCTION_ENTER();
|
||||||
|
|
||||||
if (NULL == ctx) {
|
MpiImpl *p = (MpiImpl*)ctx;
|
||||||
mpp_err_f("input ctx %p is null pointer\n", ctx);
|
MPP_RET ret = check_mpp_ctx(p);
|
||||||
return MPP_ERR_NULL_PTR;
|
if (ret)
|
||||||
}
|
return ret;
|
||||||
|
|
||||||
p = (MpiImpl*)ctx;
|
|
||||||
|
|
||||||
if (p->check != p) {
|
|
||||||
mpp_err_f("input invalid MppCtx\n");
|
|
||||||
return MPP_ERR_UNKNOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p->ctx)
|
if (p->ctx)
|
||||||
delete p->ctx;
|
delete p->ctx;
|
||||||
|
Reference in New Issue
Block a user