[mpi/mpp]: add format check function and modify mpp_dec_test for format check

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@925 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2016-06-16 09:12:30 +00:00
parent f65e805680
commit 4c06405e3d
6 changed files with 97 additions and 46 deletions

View File

@@ -224,6 +224,10 @@ 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);
MPP_RET mpp_destroy(MppCtx ctx); MPP_RET mpp_destroy(MppCtx ctx);
// coding type format function
MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding);
void mpp_show_support_format();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -49,6 +49,7 @@ typedef struct {
MppCodingType coding; MppCodingType coding;
RK_U32 fast_mode; RK_U32 fast_mode;
RK_U32 need_split; RK_U32 need_split;
void *mpp;
} MppDecCfg; } MppDecCfg;
#ifdef __cplusplus #ifdef __cplusplus
@@ -64,7 +65,7 @@ void *mpp_dec_hal_thread(void *data);
/* /*
* *
*/ */
MPP_RET mpp_dec_init(MppDec *dec, MppDecCfg *cfg); MPP_RET mpp_dec_init(MppDec **dec, MppDecCfg *cfg);
MPP_RET mpp_dec_deinit(MppDec *dec); MPP_RET mpp_dec_deinit(MppDec *dec);
MPP_RET mpp_dec_reset(MppDec *dec); MPP_RET mpp_dec_reset(MppDec *dec);

View File

@@ -705,7 +705,7 @@ void *mpp_dec_hal_thread(void *data)
return NULL; return NULL;
} }
MPP_RET mpp_dec_init(MppDec *dec, MppDecCfg *cfg) MPP_RET mpp_dec_init(MppDec **dec, MppDecCfg *cfg)
{ {
MPP_RET ret; MPP_RET ret;
MppCodingType coding; MppCodingType coding;
@@ -714,6 +714,7 @@ MPP_RET mpp_dec_init(MppDec *dec, MppDecCfg *cfg)
Parser parser = NULL; Parser parser = NULL;
MppHal hal = NULL; MppHal hal = NULL;
RK_S32 hal_task_count = 0; RK_S32 hal_task_count = 0;
MppDec *p = NULL;
IOInterruptCB cb = {NULL, NULL}; IOInterruptCB cb = {NULL, NULL};
if (NULL == dec || NULL == cfg) { if (NULL == dec || NULL == cfg) {
@@ -721,6 +722,14 @@ MPP_RET mpp_dec_init(MppDec *dec, MppDecCfg *cfg)
return MPP_ERR_NULL_PTR; return MPP_ERR_NULL_PTR;
} }
*dec = NULL;
p = mpp_calloc(MppDec, 1);
if (NULL == p) {
mpp_err_f("failed to malloc context\n");
return MPP_ERR_NULL_PTR;
}
coding = cfg->coding; coding = cfg->coding;
hal_task_count = (cfg->fast_mode) ? (3) : (2); hal_task_count = (cfg->fast_mode) ? (3) : (2);
@@ -739,7 +748,7 @@ MPP_RET mpp_dec_init(MppDec *dec, MppDecCfg *cfg)
mpp_buf_slot_setup(packet_slots, hal_task_count); mpp_buf_slot_setup(packet_slots, hal_task_count);
cb.callBack = mpp_dec_notify; cb.callBack = mpp_dec_notify;
cb.opaque = dec; cb.opaque = p;
ParserCfg parser_cfg = { ParserCfg parser_cfg = {
coding, coding,
frame_slots, frame_slots,
@@ -776,19 +785,21 @@ MPP_RET mpp_dec_init(MppDec *dec, MppDecCfg *cfg)
break; break;
} }
dec->coding = coding; p->coding = coding;
dec->parser = parser; p->parser = parser;
dec->hal = hal; p->hal = hal;
dec->tasks = hal_cfg.tasks; p->tasks = hal_cfg.tasks;
dec->frame_slots = frame_slots; p->frame_slots = frame_slots;
dec->packet_slots = packet_slots; p->packet_slots = packet_slots;
dec->parser_need_split = cfg->need_split; p->mpp = cfg->mpp;
dec->parser_fast_mode = cfg->fast_mode; p->parser_need_split = cfg->need_split;
p->parser_fast_mode = cfg->fast_mode;
*dec = p;
return MPP_OK; return MPP_OK;
} while (0); } while (0);
mpp_dec_deinit(dec); mpp_dec_deinit(p);
return MPP_NOK; return MPP_NOK;
} }

View File

@@ -25,6 +25,22 @@
#include "mpi_impl.h" #include "mpi_impl.h"
#include "mpp.h" #include "mpp.h"
#include "mpp_info.h" #include "mpp_info.h"
#include "mpp_common.h"
typedef struct {
MppCtxType type;
MppCodingType coding;
const char *type_name;
const char *coding_name;
} MppCodingTypeInfo;
static MppCodingTypeInfo support_list[] = {
{ MPP_CTX_DEC, MPP_VIDEO_CodingMPEG2, "dec", "mpeg2", },
{ MPP_CTX_DEC, MPP_VIDEO_CodingAVC, "dec", "h.264/AVC", },
{ MPP_CTX_DEC, MPP_VIDEO_CodingHEVC, "dec", "h.265/HEVC", },
{ MPP_CTX_DEC, MPP_VIDEO_CodingVP9, "dec", "VP9", },
{ MPP_CTX_DEC, MPP_VIDEO_CodingAVS, "dec", "avs+", },
};
#define check_mpp_ctx(ctx) _check_mpp_ctx(ctx, __FUNCTION__) #define check_mpp_ctx(ctx) _check_mpp_ctx(ctx, __FUNCTION__)
@@ -328,13 +344,13 @@ MPP_RET mpp_init(MppCtx ctx, MppCtxType type, MppCodingType coding)
return MPP_ERR_UNKNOW; return MPP_ERR_UNKNOW;
} }
p->ctx->init(type, coding); ret = p->ctx->init(type, coding);
p->type = type; p->type = type;
p->coding = coding; p->coding = coding;
get_mpi_debug(); get_mpi_debug();
MPI_FUNCTION_LEAVE_OK(); MPI_FUNCTION_LEAVE_OK();
return MPP_OK; return ret;
} }
MPP_RET mpp_destroy(MppCtx ctx) MPP_RET mpp_destroy(MppCtx ctx)
@@ -355,3 +371,33 @@ MPP_RET mpp_destroy(MppCtx ctx)
return MPP_OK; return MPP_OK;
} }
MPP_RET mpp_check_support_format(MppCtxType type, MppCodingType coding)
{
MPP_RET ret = MPP_NOK;
RK_U32 i = 0;
for (i = 0; i < MPP_ARRAY_ELEMS(support_list); i++) {
MppCodingTypeInfo *info = &support_list[i];
if (type == info->type &&
coding == info->coding) {
ret = MPP_OK;
break;
}
}
return ret;
}
void mpp_show_support_format()
{
RK_U32 i = 0;
mpp_log("mpp coding type support list:");
for (i = 0; i < MPP_ARRAY_ELEMS(support_list); i++) {
MppCodingTypeInfo *info = &support_list[i];
mpp_log("type: %s id %d coding: %-16s id %d\n",
info->type_name, info->type,
info->coding_name, info->coding);
}
}

View File

@@ -63,17 +63,15 @@ Mpp::Mpp()
MPP_RET Mpp::init(MppCtxType type, MppCodingType coding) MPP_RET Mpp::init(MppCtxType type, MppCodingType coding)
{ {
if (mpp_check_support_format(type, coding)) {
mpp_err("unable to create unsupported type %d coding %d\n", type, coding);
return MPP_NOK;
}
mType = type; mType = type;
mCoding = coding; mCoding = coding;
switch (mType) { switch (mType) {
case MPP_CTX_DEC : { case MPP_CTX_DEC : {
mDec = mpp_calloc(MppDec, 1);
if (NULL == mDec) {
mpp_err_f("failed to malloc context\n");
return MPP_ERR_NULL_PTR;
}
mPackets = new mpp_list((node_destructor)mpp_packet_deinit); mPackets = new mpp_list((node_destructor)mpp_packet_deinit);
mFrames = new mpp_list((node_destructor)mpp_frame_deinit); mFrames = new mpp_list((node_destructor)mpp_frame_deinit);
mTasks = new mpp_list((node_destructor)NULL); mTasks = new mpp_list((node_destructor)NULL);
@@ -82,9 +80,9 @@ MPP_RET Mpp::init(MppCtxType type, MppCodingType coding)
coding, coding,
mParserFastMode, mParserFastMode,
mParserNeedSplit, mParserNeedSplit,
this,
}; };
mDec->mpp = this; mpp_dec_init(&mDec, &cfg);
mpp_dec_init(mDec, &cfg);
mThreadCodec = new MppThread(mpp_dec_parser_thread, this, "mpp_dec_parser"); mThreadCodec = new MppThread(mpp_dec_parser_thread, this, "mpp_dec_parser");
mThreadHal = new MppThread(mpp_dec_hal_thread, this, "mpp_dec_hal"); mThreadHal = new MppThread(mpp_dec_hal_thread, this, "mpp_dec_hal");
@@ -116,12 +114,12 @@ MPP_RET Mpp::init(MppCtxType type, MppCodingType coding)
mPacketGroup) { mPacketGroup) {
mThreadCodec->start(); mThreadCodec->start();
mThreadHal->start(); mThreadHal->start();
mInitDone = 1;
} else { } else {
mpp_err("error found on mpp initialization\n"); mpp_err("error found on mpp initialization\n");
clear(); clear();
} }
mInitDone = 1;
mpp_env_get_u32("mpp_debug", &mpp_debug, 0); mpp_env_get_u32("mpp_debug", &mpp_debug, 0);
return MPP_OK; return MPP_OK;
} }

View File

@@ -72,7 +72,7 @@ int mpi_dec_test(MpiDecTestCmd *cmd)
MpiCmd mpi_cmd = MPP_CMD_BASE; MpiCmd mpi_cmd = MPP_CMD_BASE;
MppParam param = NULL; MppParam param = NULL;
RK_U32 output_block = 1; RK_U32 need_split = 1;
// paramter for resource malloc // paramter for resource malloc
RK_U32 width = cmd->width; RK_U32 width = cmd->width;
@@ -123,21 +123,22 @@ int mpi_dec_test(MpiDecTestCmd *cmd)
mpp_err("mpp_create failed\n"); mpp_err("mpp_create failed\n");
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
ret = mpp_init(ctx, MPP_CTX_DEC, type);
if (MPP_OK != ret) {
mpp_err("mpp_init failed\n");
goto MPP_TEST_OUT;
}
// NOTE: decoder do not need control function // NOTE: decoder split mode need to be set before init
mpi_cmd = MPP_SET_OUTPUT_BLOCK; mpi_cmd = MPP_DEC_SET_PARSER_SPLIT_MODE;
param = &output_block; param = &need_split;
ret = mpi->control(ctx, mpi_cmd, param); ret = mpi->control(ctx, mpi_cmd, param);
if (MPP_OK != ret) { if (MPP_OK != ret) {
mpp_err("mpi->control failed\n"); mpp_err("mpi->control failed\n");
goto MPP_TEST_OUT; goto MPP_TEST_OUT;
} }
ret = mpp_init(ctx, MPP_CTX_DEC, type);
if (MPP_OK != ret) {
mpp_err("mpp_init failed\n");
goto MPP_TEST_OUT;
}
while (!found_eos) { while (!found_eos) {
read_size = fread(buf, 1, packet_size, fp_input); read_size = fread(buf, 1, packet_size, fp_input);
mpp_log("read packet length %u\n", read_size); mpp_log("read packet length %u\n", read_size);
@@ -218,23 +219,12 @@ MPP_TEST_OUT:
return ret; return ret;
} }
static void mpi_dec_test_help() static void mpi_dec_test_help()
{ {
mpp_log("usage: mpi_dec_test [options]\n"); mpp_log("usage: mpi_dec_test [options]\n");
show_options(mpi_dec_cmd); show_options(mpi_dec_cmd);
} mpp_show_support_format();
static MPP_RET check_decoder_support_format(MppCodingType type)
{
if (type == MPP_VIDEO_CodingMPEG2 ||
type == MPP_VIDEO_CodingMPEG4 ||
type == MPP_VIDEO_CodingAVC ||
type == MPP_VIDEO_CodingVP9 ||
type == MPP_VIDEO_CodingHEVC ||
type == MPP_VIDEO_CodingAVS)
return MPP_OK;
return MPP_OK;
} }
static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* cmd) static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* cmd)
@@ -319,7 +309,7 @@ static RK_S32 mpi_dec_test_parse_options(int argc, char **argv, MpiDecTestCmd* c
case 't': case 't':
if (next) { if (next) {
cmd->type = (MppCodingType)atoi(next); cmd->type = (MppCodingType)atoi(next);
err = check_decoder_support_format(cmd->type); err = mpp_check_support_format(MPP_CTX_DEC, cmd->type);
} }
if (!next || err) { if (!next || err) {
@@ -349,6 +339,7 @@ static void mpi_dec_test_show_options(MpiDecTestCmd* cmd)
mpp_log("output file name: %s\n", cmd->file_output); mpp_log("output file name: %s\n", cmd->file_output);
mpp_log("width : %4d\n", cmd->width); mpp_log("width : %4d\n", cmd->width);
mpp_log("height : %4d\n", cmd->height); mpp_log("height : %4d\n", cmd->height);
mpp_log("type : %d\n", cmd->type);
mpp_log("debug flag : %x\n", cmd->debug); mpp_log("debug flag : %x\n", cmd->debug);
} }