diff --git a/inc/rk_mpi.h b/inc/rk_mpi.h index 7fdb7ebc..c5bec522 100644 --- a/inc/rk_mpi.h +++ b/inc/rk_mpi.h @@ -52,8 +52,8 @@ typedef void* MppCtx; typedef void* MppParam; typedef struct { - RK_U32 mpi_size; - RK_U32 mpi_version; + RK_U32 size; + RK_U32 version; MPP_RET (*init)(MppCtx ctx, MppPacket packet); // sync interface diff --git a/mpp/mpi.cpp b/mpp/mpi.cpp index 8ea2b58d..35e1b8cb 100644 --- a/mpp/mpi.cpp +++ b/mpp/mpi.cpp @@ -24,6 +24,97 @@ #include "mpp_mem.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) { @@ -52,9 +143,23 @@ MPP_RET mpp_init(MppCtx *ctx, MppApi **mpi) memset(p, 0, sizeof(*p)); memset(api, 0, sizeof(*api)); - p->api = api; - p->check = p; + 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->check = p; *ctx = p; + *mpi = api; + + get_mpi_debug(); MPI_FUNCTION_LEAVE_OK(); return MPP_OK; @@ -80,7 +185,8 @@ MPP_RET mpp_deinit(MppCtx* ctx) if (p->api) mpp_free(p->api); if (p) - mpp_free(p->api); + mpp_free(p); + p = NULL; MPI_FUNCTION_LEAVE(); return MPP_OK; diff --git a/mpp/mpi_impl.cpp b/mpp/mpi_impl.cpp index 289ab2b3..cdf17dda 100644 --- a/mpp/mpi_impl.cpp +++ b/mpp/mpi_impl.cpp @@ -18,7 +18,13 @@ #include "rk_mpi.h" #include "mpp_log.h" +#include "mpp_env.h" #include "mpi_impl.h" RK_U32 mpi_debug = 0; +void get_mpi_debug() +{ + mpp_env_get_u32("mpi_debug", &mpi_debug, 0); +} + diff --git a/mpp/mpi_impl.h b/mpp/mpi_impl.h index 4cd5502e..81cb2408 100644 --- a/mpp/mpi_impl.h +++ b/mpp/mpi_impl.h @@ -45,6 +45,7 @@ extern "C" { #endif extern RK_U32 mpi_debug; +void get_mpi_debug(); #ifdef __cplusplus } diff --git a/mpp/mpp_info.cpp b/mpp/mpp_info.cpp index b21edfc6..117216a8 100644 --- a/mpp/mpp_info.cpp +++ b/mpp/mpp_info.cpp @@ -48,7 +48,7 @@ static RK_CHIP_TYPE chip_version(void) { RK_CHIP_TYPE type = NONE; 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 (strstr(value, "rk29")) { @@ -60,7 +60,7 @@ static RK_CHIP_TYPE chip_version(void) } } 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 (strstr(value, "rk29")) { mpp_log("rk29 board found in platform property"); diff --git a/osal/inc/mpp_env.h b/osal/inc/mpp_env.h index a0f0d041..c22ba481 100644 --- a/osal/inc/mpp_env.h +++ b/osal/inc/mpp_env.h @@ -23,11 +23,11 @@ extern "C" { #endif -RK_S32 mpp_get_env_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_u32(const char *name, RK_U32 *value, RK_U32 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_set_env_str(const char *name, char *value); +RK_S32 mpp_env_set_u32(const char *name, RK_U32 value); +RK_S32 mpp_env_set_str(const char *name, char *value); #ifdef __cplusplus } diff --git a/osal/mpp_env.cpp b/osal/mpp_env.cpp index 9aaa1ef4..76e2081d 100644 --- a/osal/mpp_env.cpp +++ b/osal/mpp_env.cpp @@ -19,22 +19,22 @@ // 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); } -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); } -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); } -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); } diff --git a/osal/mpp_mem.cpp b/osal/mpp_mem.cpp index 1c296eef..7d604a0f 100644 --- a/osal/mpp_mem.cpp +++ b/osal/mpp_mem.cpp @@ -57,11 +57,11 @@ static void get_osal_mem_flag() if (osal_mem_flag < 0) { RK_U32 val; 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) { 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) { osal_mem_flag |= OSAL_MEM_STUFF_EN; } diff --git a/osal/test/mpp_env_test.c b/osal/test/mpp_env_test.c index 5fbb1a64..b4590b3b 100644 --- a/osal/test/mpp_env_test.c +++ b/osal/test/mpp_env_test.c @@ -27,8 +27,8 @@ int main() RK_U32 env_debug_u32 = 0x100; char *env_string_str = env_test_string; - mpp_set_env_u32(env_debug, env_debug_u32); - mpp_set_env_str(env_string, env_string_str); + mpp_env_set_u32(env_debug, env_debug_u32); + 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 %s\n", env_string, env_string_str); @@ -36,8 +36,8 @@ int main() env_string_str = NULL; mpp_log("clear local value to zero\n"); - mpp_get_env_u32(env_debug, &env_debug_u32, 0); - mpp_get_env_str(env_string, &env_string_str, NULL); + mpp_env_get_u32(env_debug, &env_debug_u32, 0); + 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 %s\n", env_string, env_string_str); diff --git a/osal/test/mpp_mem_test.c b/osal/test/mpp_mem_test.c index 6b213f10..9d142dae 100644 --- a/osal/test/mpp_mem_test.c +++ b/osal/test/mpp_mem_test.c @@ -26,7 +26,7 @@ int main() { void *tmp = NULL; - mpp_set_env_u32("osal_mem_list", 1); + mpp_env_set_u32("osal_mem_list", 1); tmp = mpp_calloc(int, 100); if (tmp) { mpp_log("calloc success ptr 0x%p\n", tmp); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 63d1365a..2efcaf6d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,7 +18,8 @@ macro(add_mpp_test module) endif() endmacro() -# info system unit test +# legacy vpu_api unit test add_mpp_test(vpu_api) - +# mpi unit test +add_mpp_test(mpi) diff --git a/test/mpi_test.c b/test/mpi_test.c new file mode 100644 index 00000000..d969fa5a --- /dev/null +++ b/test/mpi_test.c @@ -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 + +#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; +} +