[mpi]: add mpi unit test and rename mpp_env interface

git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@116 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
ChenHengming
2015-08-17 10:09:20 +00:00
parent fa4fbd822c
commit c2544d0f9c
12 changed files with 262 additions and 24 deletions

View File

@@ -52,8 +52,8 @@ typedef void* MppCtx;
typedef void* MppParam; typedef void* MppParam;
typedef struct { typedef struct {
RK_U32 mpi_size; RK_U32 size;
RK_U32 mpi_version; RK_U32 version;
MPP_RET (*init)(MppCtx ctx, MppPacket packet); MPP_RET (*init)(MppCtx ctx, MppPacket packet);
// sync interface // sync interface

View File

@@ -24,6 +24,97 @@
#include "mpp_mem.h" #include "mpp_mem.h"
#include "mpi_impl.h" #include "mpi_impl.h"
static MPP_RET mpi_init(MppCtx ctx, MppPacket packet)
{
(void)ctx;
(void)packet;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
static MPP_RET mpi_decode(MppCtx ctx, MppPacket packet, MppFrame *frame)
{
(void)ctx;
(void)packet;
(void)frame;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
static MPP_RET mpi_encode(MppCtx ctx, MppFrame frame, MppPacket *packet)
{
(void)ctx;
(void)packet;
(void)frame;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
static MPP_RET mpi_decode_put_packet(MppCtx ctx, MppPacket packet)
{
(void)ctx;
(void)packet;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
static MPP_RET mpi_decode_get_frame(MppCtx ctx, MppFrame *frame)
{
(void)ctx;
(void)frame;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
static MPP_RET mpi_encode_put_frame(MppCtx ctx, MppFrame frame)
{
(void)ctx;
(void)frame;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
static MPP_RET mpi_encode_get_packet(MppCtx ctx, MppPacket *packet)
{
(void)ctx;
(void)packet;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
static MPP_RET mpi_flush(MppCtx ctx)
{
(void)ctx;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
static MPP_RET mpi_control(MppCtx ctx, MPI_CMD cmd, MppParam param)
{
(void)ctx;
(void)cmd;
(void)param;
MPI_FUNCTION_ENTER();
MPI_FUNCTION_LEAVE();
return MPP_OK;
}
MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi) MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi)
{ {
@@ -52,9 +143,23 @@ MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi)
memset(p, 0, sizeof(*p)); memset(p, 0, sizeof(*p));
memset(api, 0, sizeof(*api)); memset(api, 0, sizeof(*api));
api->size = sizeof(*api);
api->version = 1;
api->init = mpi_init;
api->decode = mpi_decode;
api->encode = mpi_encode;
api->decode_put_packet = mpi_decode_put_packet;
api->decode_get_frame = mpi_decode_get_frame;
api->encode_put_frame = mpi_encode_put_frame;
api->encode_get_packet = mpi_encode_get_packet;
api->flush = mpi_flush;
api->control = mpi_control;
p->api = api; p->api = api;
p->check = p; p->check = p;
*ctx = p; *ctx = p;
*mpi = api;
get_mpi_debug();
MPI_FUNCTION_LEAVE_OK(); MPI_FUNCTION_LEAVE_OK();
return MPP_OK; return MPP_OK;
@@ -80,7 +185,8 @@ MPP_RET mpp_deinit(MppCtx* ctx)
if (p->api) if (p->api)
mpp_free(p->api); mpp_free(p->api);
if (p) if (p)
mpp_free(p->api); mpp_free(p);
p = NULL;
MPI_FUNCTION_LEAVE(); MPI_FUNCTION_LEAVE();
return MPP_OK; return MPP_OK;

View File

@@ -18,7 +18,13 @@
#include "rk_mpi.h" #include "rk_mpi.h"
#include "mpp_log.h" #include "mpp_log.h"
#include "mpp_env.h"
#include "mpi_impl.h" #include "mpi_impl.h"
RK_U32 mpi_debug = 0; RK_U32 mpi_debug = 0;
void get_mpi_debug()
{
mpp_env_get_u32("mpi_debug", &mpi_debug, 0);
}

View File

@@ -45,6 +45,7 @@ extern "C" {
#endif #endif
extern RK_U32 mpi_debug; extern RK_U32 mpi_debug;
void get_mpi_debug();
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -48,7 +48,7 @@ static RK_CHIP_TYPE chip_version(void)
{ {
RK_CHIP_TYPE type = NONE; RK_CHIP_TYPE type = NONE;
char *value = NULL; char *value = NULL;
RK_S32 ret = mpp_get_env_str("ro.product.board", &value, NULL); RK_S32 ret = mpp_env_get_str("ro.product.board", &value, NULL);
if (0 == ret) { if (0 == ret) {
if (strstr(value, "rk29")) { if (strstr(value, "rk29")) {
@@ -60,7 +60,7 @@ static RK_CHIP_TYPE chip_version(void)
} }
} }
if (NONE == type) { if (NONE == type) {
ret = mpp_get_env_str("ro.board.platform", &value, NULL); ret = mpp_env_get_str("ro.board.platform", &value, NULL);
if (0 == ret) { if (0 == ret) {
if (strstr(value, "rk29")) { if (strstr(value, "rk29")) {
mpp_log("rk29 board found in platform property"); mpp_log("rk29 board found in platform property");

View File

@@ -23,11 +23,11 @@
extern "C" { extern "C" {
#endif #endif
RK_S32 mpp_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value); RK_S32 mpp_env_get_u32(const char *name, RK_U32 *value, RK_U32 default_value);
RK_S32 mpp_get_env_str(const char *name, char **value, char *default_value); RK_S32 mpp_env_get_str(const char *name, char **value, char *default_value);
RK_S32 mpp_set_env_u32(const char *name, RK_U32 value); RK_S32 mpp_env_set_u32(const char *name, RK_U32 value);
RK_S32 mpp_set_env_str(const char *name, char *value); RK_S32 mpp_env_set_str(const char *name, char *value);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -19,22 +19,22 @@
// TODO: add previous value compare to save call times // TODO: add previous value compare to save call times
RK_S32 mpp_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value) RK_S32 mpp_env_get_u32(const char *name, RK_U32 *value, RK_U32 default_value)
{ {
return os_get_env_u32(name, value, default_value); return os_get_env_u32(name, value, default_value);
} }
RK_S32 mpp_get_env_str(const char *name, char **value, char *default_value) RK_S32 mpp_env_get_str(const char *name, char **value, char *default_value)
{ {
return os_get_env_str(name, value, default_value); return os_get_env_str(name, value, default_value);
} }
RK_S32 mpp_set_env_u32(const char *name, RK_U32 value) RK_S32 mpp_env_set_u32(const char *name, RK_U32 value)
{ {
return os_set_env_u32(name, value); return os_set_env_u32(name, value);
} }
RK_S32 mpp_set_env_str(const char *name, char *value) RK_S32 mpp_env_set_str(const char *name, char *value)
{ {
return os_set_env_str(name, value); return os_set_env_str(name, value);
} }

View File

@@ -57,11 +57,11 @@ static void get_osal_mem_flag()
if (osal_mem_flag < 0) { if (osal_mem_flag < 0) {
RK_U32 val; RK_U32 val;
osal_mem_flag = 0; osal_mem_flag = 0;
mpp_get_env_u32(CONFIG_OSAL_MEM_LIST, &val, 0); mpp_env_get_u32(CONFIG_OSAL_MEM_LIST, &val, 0);
if (val) { if (val) {
osal_mem_flag |= OSAL_MEM_LIST_EN; osal_mem_flag |= OSAL_MEM_LIST_EN;
} }
mpp_get_env_u32(CONFIG_OSAL_MEM_STUFF, &val, 0); mpp_env_get_u32(CONFIG_OSAL_MEM_STUFF, &val, 0);
if (val) { if (val) {
osal_mem_flag |= OSAL_MEM_STUFF_EN; osal_mem_flag |= OSAL_MEM_STUFF_EN;
} }

View File

@@ -27,8 +27,8 @@ int main()
RK_U32 env_debug_u32 = 0x100; RK_U32 env_debug_u32 = 0x100;
char *env_string_str = env_test_string; char *env_string_str = env_test_string;
mpp_set_env_u32(env_debug, env_debug_u32); mpp_env_set_u32(env_debug, env_debug_u32);
mpp_set_env_str(env_string, env_string_str); mpp_env_set_str(env_string, env_string_str);
mpp_log("set env: %s to %u\n", env_debug, env_debug_u32); mpp_log("set env: %s to %u\n", env_debug, env_debug_u32);
mpp_log("set env: %s to %s\n", env_string, env_string_str); mpp_log("set env: %s to %s\n", env_string, env_string_str);
@@ -36,8 +36,8 @@ int main()
env_string_str = NULL; env_string_str = NULL;
mpp_log("clear local value to zero\n"); mpp_log("clear local value to zero\n");
mpp_get_env_u32(env_debug, &env_debug_u32, 0); mpp_env_get_u32(env_debug, &env_debug_u32, 0);
mpp_get_env_str(env_string, &env_string_str, NULL); mpp_env_get_str(env_string, &env_string_str, NULL);
mpp_log("get env: %s is %u\n", env_debug, env_debug_u32); mpp_log("get env: %s is %u\n", env_debug, env_debug_u32);
mpp_log("get env: %s is %s\n", env_string, env_string_str); mpp_log("get env: %s is %s\n", env_string, env_string_str);

View File

@@ -26,7 +26,7 @@ int main()
{ {
void *tmp = NULL; void *tmp = NULL;
mpp_set_env_u32("osal_mem_list", 1); mpp_env_set_u32("osal_mem_list", 1);
tmp = mpp_calloc(int, 100); tmp = mpp_calloc(int, 100);
if (tmp) { if (tmp) {
mpp_log("calloc success ptr 0x%p\n", tmp); mpp_log("calloc success ptr 0x%p\n", tmp);

View File

@@ -18,7 +18,8 @@ macro(add_mpp_test module)
endif() endif()
endmacro() endmacro()
# info system unit test # legacy vpu_api unit test
add_mpp_test(vpu_api) add_mpp_test(vpu_api)
# mpi unit test
add_mpp_test(mpi)

124
test/mpi_test.c Normal file
View File

@@ -0,0 +1,124 @@
/*
* 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_test"
#include <string.h>
#include "rk_mpi.h"
#include "mpp_log.h"
#include "mpp_env.h"
int main()
{
MPP_RET ret;
MppCtx ctx = NULL;
MppApi *mpi = NULL;
MppPacket dec_in = NULL;
MppFrame dec_out = NULL;
MppFrame enc_in = NULL;
MppPacket enc_out = NULL;
MPI_CMD cmd = MPI_MPP_CMD_BASE;
MppParam param = NULL;
mpp_log("mpi_test start\n");
mpp_env_set_u32("mpi_debug", 0x1);
mpp_log("mpi_test decoder test start\n");
// decoder demo
ret = mpp_init(&ctx, &mpi);
if (MPP_OK != ret) {
mpp_err("mpp_init failed\n");
goto MPP_TEST_FAILED;
}
ret = mpi->init(ctx, dec_in);
if (MPP_OK != ret) {
mpp_err("mpi->init failed\n");
goto MPP_TEST_FAILED;
}
ret = mpi->control(ctx, cmd, param);
if (MPP_OK != ret) {
mpp_err("mpi->control failed\n");
goto MPP_TEST_FAILED;
}
mpi->decode(ctx, dec_in, &dec_out);
mpi->decode_put_packet(ctx, dec_in);
mpi->decode_get_frame(ctx, &dec_out);
ret = mpi->flush(ctx);
if (MPP_OK != ret) {
mpp_err("mpi->flush failed\n");
goto MPP_TEST_FAILED;
}
mpp_deinit(&ctx);
mpp_log("mpi_test encoder test start\n");
// encoder demo
ret = mpp_init(&ctx, &mpi);
if (MPP_OK != ret) {
mpp_err("mpp_init failed\n");
goto MPP_TEST_FAILED;
}
ret = mpi->init(ctx, dec_in);
if (MPP_OK != ret) {
mpp_err("mpi->init failed\n");
goto MPP_TEST_FAILED;
}
ret = mpi->control(ctx, cmd, param);
if (MPP_OK != ret) {
mpp_err("mpi->control failed\n");
goto MPP_TEST_FAILED;
}
mpi->encode(ctx, enc_in, &enc_out);
mpi->encode_put_frame(ctx, enc_in);
mpi->encode_get_packet(ctx, &dec_out);
ret = mpi->flush(ctx);
if (MPP_OK != ret) {
mpp_err("mpi->flush failed\n");
goto MPP_TEST_FAILED;
}
mpp_deinit(&ctx);
mpp_log("mpi_test success\n");
return 0;
MPP_TEST_FAILED:
if (ctx)
mpp_deinit(ctx);
mpp_log("mpi_test failed\n");
return -1;
}