[test]: Remove vpu_api_test's dependence on mpp

Remove all mpp object from vpu.so
NOTE: link_directories should be before add_library or add_executable.

Change-Id: Idee25e1ccc2c3182f7b8c26c277d396e28654f3e
Signed-off-by: Herman Chen <herman.chen@rock-chips.com>
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
This commit is contained in:
Herman Chen
2020-05-20 19:54:06 +08:00
parent 6e6f9733ef
commit 2005ed4f42
3 changed files with 102 additions and 91 deletions

View File

@@ -17,7 +17,11 @@ set (MPP_LEGACY_SRC
set(VPU_VERSION "0") set(VPU_VERSION "0")
set(VPU_ABI_VERSION "1") set(VPU_ABI_VERSION "1")
# NOTE: link_directories should be before add_library or add_executable
link_directories(${CMAKE_BINARY_DIR}/mpp)
add_library(${VPU_SHARED} SHARED ${MPP_LEGACY_SRC}) add_library(${VPU_SHARED} SHARED ${MPP_LEGACY_SRC})
add_dependencies(${VPU_SHARED} ${MPP_SHARED})
set_target_properties(${VPU_SHARED} PROPERTIES FOLDER "mpp/legacy") set_target_properties(${VPU_SHARED} PROPERTIES FOLDER "mpp/legacy")
set_target_properties(${VPU_SHARED} PROPERTIES CLEAN_DIRECT_OUTPUT 1) set_target_properties(${VPU_SHARED} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(${VPU_SHARED} PROPERTIES C_VISIBILITY_PRESET default) set_target_properties(${VPU_SHARED} PROPERTIES C_VISIBILITY_PRESET default)
@@ -29,6 +33,7 @@ set_target_properties(${VPU_SHARED} PROPERTIES VERSION ${MPP_VERSION})
set_target_properties(${VPU_SHARED} PROPERTIES SOVERSION ${MPP_ABI_VERSION}) set_target_properties(${VPU_SHARED} PROPERTIES SOVERSION ${MPP_ABI_VERSION})
endif() endif()
target_link_libraries(${VPU_SHARED} dl ${MPP_SHARED}) # force dynamic link
target_link_libraries(${VPU_SHARED} -Wl,-Bdynamic dl lib${MPP_SHARED}.so)
install(TARGETS ${VPU_SHARED} LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(TARGETS ${VPU_SHARED} LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")

View File

@@ -57,7 +57,7 @@ macro(add_legacy_test module)
option(${test_tag} "Build legacy ${module} unit test" ON) option(${test_tag} "Build legacy ${module} unit test" ON)
if(${test_tag}) if(${test_tag})
add_executable(${test_name} ${test_name}.c) add_executable(${test_name} ${test_name}.c)
target_link_libraries(${test_name} -ldl utils) target_link_libraries(${test_name} dl)
set_target_properties(${test_name} PROPERTIES FOLDER "test") set_target_properties(${test_name} PROPERTIES FOLDER "test")
install(TARGETS ${test_name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS ${test_name} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif() endif()

View File

@@ -14,18 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
#define MODULE_TAG "vpu_api_demo"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <unistd.h>
#include "mpp_log.h"
#include "mpp_time.h"
#include "vpu_api.h" #include "vpu_api.h"
#include "utils.h"
#define FOR_TEST_ENCODE 1 #define FOR_TEST_ENCODE 1
@@ -37,7 +32,6 @@
#define DECODE_ERR_RET(err) do { ret = err; goto DECODE_OUT; } while (0) #define DECODE_ERR_RET(err) do { ret = err; goto DECODE_OUT; } while (0)
#define ENCODE_ERR_RET(err) do { ret = err; goto ENCODE_OUT; } while (0) #define ENCODE_ERR_RET(err) do { ret = err; goto ENCODE_OUT; } while (0)
typedef enum VPU_API_DEMO_RET { typedef enum VPU_API_DEMO_RET {
VPU_DEMO_OK = 0, VPU_DEMO_OK = 0,
VPU_DEMO_PARSE_HELP_OK = 1, VPU_DEMO_PARSE_HELP_OK = 1,
@@ -70,7 +64,13 @@ typedef struct VpuApiEncInput {
RK_U32 capability; RK_U32 capability;
} VpuApiEncInput; } VpuApiEncInput;
static OptionInfo vpuApiCmd[] = { typedef struct VpuApiOptionInfo_t {
const char* name;
const char* argname;
const char* help;
} VpuApiOptionInfo;
static VpuApiOptionInfo vpuApiCmd[] = {
{ "i", "input_file", "input bitstream file" }, { "i", "input_file", "input bitstream file" },
{ "o", "output_file", "output bitstream file, " }, { "o", "output_file", "output bitstream file, " },
{ "w", "width", "the width of input bitstream" }, { "w", "width", "the width of input bitstream" },
@@ -91,16 +91,22 @@ RK_S32 (*vpuapi_mem_free)(VPUMemLinear_t *p);
static void show_usage() static void show_usage()
{ {
mpp_log("usage: vpu_apiDemo [options] input_file, \n\n"); printf("usage: vpu_apiDemo [options] input_file, \n\n");
mpp_log("Getting help:\n"); printf("Getting help:\n");
mpp_log("-help --print options of vpu api demo\n"); printf("-help --print options of vpu api demo\n");
} }
static RK_S32 show_help() static RK_S32 show_help()
{ {
mpp_log("usage: vpu_apiDemo [options] input_file, \n\n"); RK_S32 i;
show_options(vpuApiCmd); RK_S32 count = sizeof(vpuApiCmd) / sizeof(vpuApiCmd[0]);
VpuApiOptionInfo *opt = vpuApiCmd;
printf("usage: vpu_apiDemo [opt] input_file, \n\n");
for (i = 0; i < count; i++)
printf("-%s %-16s\t%s\n", opt[i].name, opt[i].argname, opt[i].help);
return 0; return 0;
} }
@@ -110,7 +116,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t *cmdCx
RK_S32 optindex, handleoptions = 1, ret = 0; RK_S32 optindex, handleoptions = 1, ret = 0;
if ((argc < 2) || (cmdCxt == NULL)) { if ((argc < 2) || (cmdCxt == NULL)) {
mpp_log("vpu api demo, input parameter invalid\n"); printf("vpu api demo, input parameter invalid\n");
show_usage(); show_usage();
return ERROR_INVALID_PARAM; return ERROR_INVALID_PARAM;
} }
@@ -139,7 +145,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t *cmdCx
cmdCxt->input_file[strlen(argv[optindex])] = '\0'; cmdCxt->input_file[strlen(argv[optindex])] = '\0';
cmdCxt->have_input = 1; cmdCxt->have_input = 1;
} else { } else {
mpp_log("input file is invalid\n"); printf("input file is invalid\n");
ret = -1; ret = -1;
goto PARSE_OPINIONS_OUT; goto PARSE_OPINIONS_OUT;
} }
@@ -151,7 +157,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t *cmdCx
cmdCxt->have_output = 1; cmdCxt->have_output = 1;
break; break;
} else { } else {
mpp_log("out file is invalid\n"); printf("out file is invalid\n");
ret = -1; ret = -1;
goto PARSE_OPINIONS_OUT; goto PARSE_OPINIONS_OUT;
} }
@@ -160,7 +166,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t *cmdCx
cmdCxt->width = atoi(argv[optindex]); cmdCxt->width = atoi(argv[optindex]);
break; break;
} else { } else {
mpp_log("input width is invalid\n"); printf("input width is invalid\n");
ret = -1; ret = -1;
goto PARSE_OPINIONS_OUT; goto PARSE_OPINIONS_OUT;
} }
@@ -172,7 +178,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t *cmdCx
} else if (argv[optindex]) { } else if (argv[optindex]) {
cmdCxt->height = atoi(argv[optindex]); cmdCxt->height = atoi(argv[optindex]);
} else { } else {
mpp_log("input height is invalid\n"); printf("input height is invalid\n");
ret = -1; ret = -1;
goto PARSE_OPINIONS_OUT; goto PARSE_OPINIONS_OUT;
} }
@@ -182,7 +188,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t *cmdCx
cmdCxt->codec_type = atoi(argv[optindex]); cmdCxt->codec_type = atoi(argv[optindex]);
break; break;
} else { } else {
mpp_log("input codec_type is invalid\n"); printf("input codec_type is invalid\n");
ret = -1; ret = -1;
goto PARSE_OPINIONS_OUT; goto PARSE_OPINIONS_OUT;
} }
@@ -190,8 +196,8 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t *cmdCx
default: default:
if ((*(opt + 1) != '\0') && argv[optindex]) { if ((*(opt + 1) != '\0') && argv[optindex]) {
if (!strncmp(opt, "coding", 6)) { if (!strncmp(opt, "coding", 6)) {
mpp_log("coding, argv[optindex]: %s", printf("coding, argv[optindex]: %s",
argv[optindex]); argv[optindex]);
cmdCxt->coding = atoi(argv[optindex]); cmdCxt->coding = atoi(argv[optindex]);
} else if (!strncmp(opt, "vframes", 7)) { } else if (!strncmp(opt, "vframes", 7)) {
cmdCxt->record_frames = atoi(argv[optindex]); cmdCxt->record_frames = atoi(argv[optindex]);
@@ -214,7 +220,7 @@ static RK_S32 parse_options(int argc, char **argv, VpuApiDemoCmdContext_t *cmdCx
PARSE_OPINIONS_OUT: PARSE_OPINIONS_OUT:
if (ret < 0) { if (ret < 0) {
mpp_log("vpu api demo, input parameter invalid\n"); printf("vpu api demo, input parameter invalid\n");
show_usage(); show_usage();
return ERROR_INVALID_PARAM; return ERROR_INVALID_PARAM;
} }
@@ -231,7 +237,7 @@ static RK_S32 readBytesFromFile(RK_U8 *buf, RK_S32 aBytes, FILE *file)
ret = (RK_S32)fread(buf, 1, aBytes, file); ret = (RK_S32)fread(buf, 1, aBytes, file);
if (ret != aBytes) { if (ret != aBytes) {
mpp_log("read %d bytes from file fail\n", aBytes); printf("read %d bytes from file fail\n", aBytes);
return -1; return -1;
} }
@@ -265,31 +271,31 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
if ((cmd->have_input == 0) || (cmd->width <= 0) || (cmd->height <= 0) if ((cmd->have_input == 0) || (cmd->width <= 0) || (cmd->height <= 0)
|| (cmd->coding <= OMX_RK_VIDEO_CodingAutoDetect)) { || (cmd->coding <= OMX_RK_VIDEO_CodingAutoDetect)) {
mpp_log("Warning: missing needed parameters for vpu api demo\n"); printf("Warning: missing needed parameters for vpu api demo\n");
} }
if (cmd->have_input) { if (cmd->have_input) {
mpp_log("input bitstream w: %d, h: %d, coding: %d(%s), path: %s\n", printf("input bitstream w: %d, h: %d, coding: %d(%s), path: %s\n",
cmd->width, cmd->height, cmd->coding, cmd->width, cmd->height, cmd->coding,
cmd->codec_type == CODEC_DECODER ? "decode" : "encode", cmd->codec_type == CODEC_DECODER ? "decode" : "encode",
cmd->input_file); cmd->input_file);
pInFile = fopen(cmd->input_file, "rb"); pInFile = fopen(cmd->input_file, "rb");
if (pInFile == NULL) { if (pInFile == NULL) {
mpp_log("input file not exsist\n"); printf("input file not exsist\n");
ENCODE_ERR_RET(ERROR_INVALID_PARAM); ENCODE_ERR_RET(ERROR_INVALID_PARAM);
} }
} else { } else {
mpp_log("please set input bitstream file\n"); printf("please set input bitstream file\n");
ENCODE_ERR_RET(ERROR_INVALID_PARAM); ENCODE_ERR_RET(ERROR_INVALID_PARAM);
} }
if (cmd->have_output) { if (cmd->have_output) {
mpp_log("vpu api demo output file: %s\n", printf("vpu api demo output file: %s\n",
cmd->output_file); cmd->output_file);
pOutFile = fopen(cmd->output_file, "wb"); pOutFile = fopen(cmd->output_file, "wb");
if (pOutFile == NULL) { if (pOutFile == NULL) {
mpp_log("can not write output file\n"); printf("can not write output file\n");
ENCODE_ERR_RET(ERROR_INVALID_PARAM); ENCODE_ERR_RET(ERROR_INVALID_PARAM);
} }
} }
@@ -297,7 +303,7 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
#ifdef FOR_TEST_ENCODE #ifdef FOR_TEST_ENCODE
ctx = (struct VpuCodecContext *)malloc(sizeof(struct VpuCodecContext)); ctx = (struct VpuCodecContext *)malloc(sizeof(struct VpuCodecContext));
if (!ctx) { if (!ctx) {
mpp_err("Input context has not been properly allocated"); printf("Input context has not been properly allocated");
return -1; return -1;
} }
memset(ctx, 0, sizeof(struct VpuCodecContext)); memset(ctx, 0, sizeof(struct VpuCodecContext));
@@ -355,7 +361,7 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
enc_param->levelIdc = 40; enc_param->levelIdc = 40;
if ((ret = ctx->init(ctx, NULL, 0)) != 0) { if ((ret = ctx->init(ctx, NULL, 0)) != 0) {
mpp_log("init vpu api context fail, ret: 0x%X\n", ret); printf("init vpu api context fail, ret: 0x%X\n", ret);
ENCODE_ERR_RET(ERROR_INIT_VPU); ENCODE_ERR_RET(ERROR_INIT_VPU);
} }
@@ -364,10 +370,10 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
** sps and pps of encoder output, you need to save sps and pps ** sps and pps of encoder output, you need to save sps and pps
** after init. ** after init.
*/ */
mpp_log("encode init ok, sps len: %d\n", ctx->extradata_size); printf("encode init ok, sps len: %d\n", ctx->extradata_size);
if (pOutFile && (ctx->extradata_size > 0)) { if (pOutFile && (ctx->extradata_size > 0)) {
mpp_log("dump %d bytes enc output stream to file\n", printf("dump %d bytes enc output stream to file\n",
ctx->extradata_size); ctx->extradata_size);
/* save sps and pps */ /* save sps and pps */
fwrite(ctx->extradata, 1, ctx->extradata_size, pOutFile); fwrite(ctx->extradata, 1, ctx->extradata_size, pOutFile);
@@ -376,32 +382,32 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
ret = ctx->control(ctx, VPU_API_ENC_SETFORMAT, &Format); ret = ctx->control(ctx, VPU_API_ENC_SETFORMAT, &Format);
if (ret) if (ret)
mpp_err("VPU_API_ENC_SETFORMAT ret %d\n", ret); printf("VPU_API_ENC_SETFORMAT ret %d\n", ret);
ret = ctx->control(ctx, VPU_API_ENC_GETCFG, enc_param); ret = ctx->control(ctx, VPU_API_ENC_GETCFG, enc_param);
if (ret) if (ret)
mpp_log("VPU_API_ENC_GETCFG ret %d\n", ret); printf("VPU_API_ENC_GETCFG ret %d\n", ret);
enc_param->rc_mode = 1; enc_param->rc_mode = 1;
ret = ctx->control(ctx, VPU_API_ENC_SETCFG, enc_param); ret = ctx->control(ctx, VPU_API_ENC_SETCFG, enc_param);
if (ret) if (ret)
mpp_log("VPU_API_ENC_SETCFG ret %d\n", ret); printf("VPU_API_ENC_SETCFG ret %d\n", ret);
/* /*
** vpu api encode process. ** vpu api encode process.
*/ */
mpp_log("init vpu api context ok, input yuv stream file size: %d\n", fileSize); printf("init vpu api context ok, input yuv stream file size: %d\n", fileSize);
w_align = ((ctx->width + 15) & (~15)); w_align = ((ctx->width + 15) & (~15));
h_align = ((ctx->height + 15) & (~15)); h_align = ((ctx->height + 15) & (~15));
size = w_align * h_align * 3 / 2; size = w_align * h_align * 3 / 2;
readOneFrameSize = ctx->width * ctx->height * 3 / 2; readOneFrameSize = ctx->width * ctx->height * 3 / 2;
mpp_log("%d %d %d %d %d", ctx->width, ctx->height, w_align, h_align, size); printf("%d %d %d %d %d", ctx->width, ctx->height, w_align, h_align, size);
nal = BSWAP32(nal); nal = BSWAP32(nal);
do { do {
if (ftell(pInFile) >= fileSize) { if (ftell(pInFile) >= fileSize) {
mpp_log("read end of file, complete\n"); printf("read end of file, complete\n");
break; break;
} }
@@ -430,16 +436,16 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
fakeTimeUs += 40000; fakeTimeUs += 40000;
} }
mpp_log("read one frame, size: %d, timeUs: %lld, filePos: %ld\n", printf("read one frame, size: %d, timeUs: %lld, filePos: %ld\n",
enc_in->size, enc_in->timeUs, ftell(pInFile)); enc_in->size, enc_in->timeUs, ftell(pInFile));
} }
if ((ret = ctx->encode(ctx, enc_in, enc_out)) < 0) { if ((ret = ctx->encode(ctx, enc_in, enc_out)) < 0) {
ENCODE_ERR_RET(ERROR_VPU_DECODE); ENCODE_ERR_RET(ERROR_VPU_DECODE);
} else { } else {
enc_in->size = 0; // TODO encode completely, and set enc_in->size to 0 enc_in->size = 0; // TODO encode completely, and set enc_in->size to 0
mpp_log("vpu encode one frame, out len: %d, left size: %d\n", printf("vpu encode one frame, out len: %d, left size: %d\n",
enc_out->size, enc_in->size); enc_out->size, enc_in->size);
/* /*
** encoder output stream is raw bitstream, you need to add nal ** encoder output stream is raw bitstream, you need to add nal
@@ -447,8 +453,8 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
*/ */
if ((enc_out->size) && (enc_out->data)) { if ((enc_out->size) && (enc_out->data)) {
if (pOutFile) { if (pOutFile) {
mpp_log("dump %d bytes enc output stream to file\n", printf("dump %d bytes enc output stream to file\n",
enc_out->size); enc_out->size);
//fwrite((RK_U8*)&nal, 1, 4, pOutFile); // because output stream have start code, so here mask this code //fwrite((RK_U8*)&nal, 1, 4, pOutFile); // because output stream have start code, so here mask this code
fwrite(enc_out->data, 1, enc_out->size, pOutFile); fwrite(enc_out->data, 1, enc_out->size, pOutFile);
fflush(pOutFile); fflush(pOutFile);
@@ -458,7 +464,7 @@ static RK_S32 vpu_encode_demo(VpuApiDemoCmdContext_t *cmd)
} }
} }
msleep(3); usleep(3000);
} while (1); } while (1);
ENCODE_OUT: ENCODE_OUT:
@@ -488,9 +494,9 @@ ENCODE_OUT:
} }
if (ret) { if (ret) {
mpp_log("encode demo fail, err: %d\n", ret); printf("encode demo fail, err: %d\n", ret);
} else { } else {
mpp_log("encode demo complete OK.\n"); printf("encode demo complete OK.\n");
} }
return ret; return ret;
@@ -521,31 +527,31 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
if ((cmd->have_input == 0) || (cmd->width <= 0) || (cmd->height <= 0) if ((cmd->have_input == 0) || (cmd->width <= 0) || (cmd->height <= 0)
|| (cmd->coding <= OMX_RK_VIDEO_CodingAutoDetect)) { || (cmd->coding <= OMX_RK_VIDEO_CodingAutoDetect)) {
mpp_log("Warning: missing needed parameters for vpu api demo\n"); printf("Warning: missing needed parameters for vpu api demo\n");
} }
if (cmd->have_input) { if (cmd->have_input) {
mpp_log("input bitstream w: %d, h: %d, coding: %d(%s), path: %s\n", printf("input bitstream w: %d, h: %d, coding: %d(%s), path: %s\n",
cmd->width, cmd->height, cmd->coding, cmd->width, cmd->height, cmd->coding,
cmd->codec_type == CODEC_DECODER ? "decode" : "encode", cmd->codec_type == CODEC_DECODER ? "decode" : "encode",
cmd->input_file); cmd->input_file);
pInFile = fopen(cmd->input_file, "rb"); pInFile = fopen(cmd->input_file, "rb");
if (pInFile == NULL) { if (pInFile == NULL) {
mpp_log("input file not exsist\n"); printf("input file not exsist\n");
DECODE_ERR_RET(ERROR_INVALID_PARAM); DECODE_ERR_RET(ERROR_INVALID_PARAM);
} }
} else { } else {
mpp_log("please set input bitstream file\n"); printf("please set input bitstream file\n");
DECODE_ERR_RET(ERROR_INVALID_PARAM); DECODE_ERR_RET(ERROR_INVALID_PARAM);
} }
if (cmd->have_output) { if (cmd->have_output) {
mpp_log("vpu api demo output file: %s\n", printf("vpu api demo output file: %s\n",
cmd->output_file); cmd->output_file);
pOutFile = fopen(cmd->output_file, "wb"); pOutFile = fopen(cmd->output_file, "wb");
if (pOutFile == NULL) { if (pOutFile == NULL) {
mpp_log("can not write output file\n"); printf("can not write output file\n");
DECODE_ERR_RET(ERROR_INVALID_PARAM); DECODE_ERR_RET(ERROR_INVALID_PARAM);
} }
if (cmd->record_frames == 0) if (cmd->record_frames == 0)
@@ -577,7 +583,7 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
DECODE_ERR_RET(ERROR_IO); DECODE_ERR_RET(ERROR_IO);
} }
mpp_log("codec extra data size: %d\n", extraSize); printf("codec extra data size: %d\n", extraSize);
pExtra = (RK_U8 *)(malloc)(extraSize); pExtra = (RK_U8 *)(malloc)(extraSize);
if (pExtra == NULL) { if (pExtra == NULL) {
@@ -600,18 +606,18 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
ctx->no_thread = 1; ctx->no_thread = 1;
if ((ret = ctx->init(ctx, pExtra, extraSize)) != 0) { if ((ret = ctx->init(ctx, pExtra, extraSize)) != 0) {
mpp_log("init vpu api context fail, ret: 0x%X\n", ret); printf("init vpu api context fail, ret: 0x%X\n", ret);
DECODE_ERR_RET(ERROR_INIT_VPU); DECODE_ERR_RET(ERROR_INIT_VPU);
} }
/* /*
** vpu api decoder process. ** vpu api decoder process.
*/ */
mpp_log("init vpu api context ok, fileSize: %d\n", fileSize); printf("init vpu api context ok, fileSize: %d\n", fileSize);
do { do {
if (ftell(pInFile) >= fileSize) { if (ftell(pInFile) >= fileSize) {
mpp_log("read end of file, complete\n"); printf("read end of file, complete\n");
break; break;
} }
@@ -644,25 +650,25 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
fakeTimeUs += 40000; fakeTimeUs += 40000;
} }
mpp_log("read one packet, size: %d, pts: %lld, filePos: %ld\n", printf("read one packet, size: %d, pts: %lld, filePos: %ld\n",
pkt->size, pkt->pts, ftell(pInFile)); pkt->size, pkt->pts, ftell(pInFile));
} }
/* note: must set out put size to 0 before do decoder. */ /* note: must set out put size to 0 before do decoder. */
pOut->size = 0; pOut->size = 0;
if (ctx->decode_sendstream(ctx, pkt) != 0) { if (ctx->decode_sendstream(ctx, pkt) != 0) {
mpp_log("send packet failed"); printf("send packet failed");
DECODE_ERR_RET(ERROR_VPU_DECODE); DECODE_ERR_RET(ERROR_VPU_DECODE);
} }
if ((ret = ctx->decode_getframe(ctx, pOut)) != 0) { if ((ret = ctx->decode_getframe(ctx, pOut)) != 0) {
mpp_log("get decoded data failed\n"); printf("get decoded data failed\n");
DECODE_ERR_RET(ERROR_VPU_DECODE); DECODE_ERR_RET(ERROR_VPU_DECODE);
} else { } else {
mpp_log("vpu decode one frame, out len: %d, left size: %d\n", printf("vpu decode one frame, out len: %d, left size: %d\n",
pOut->size, pkt->size); pOut->size, pkt->size);
/* /*
** both virtual and physical address of the decoded frame are contained ** both virtual and physical address of the decoded frame are contained
@@ -677,8 +683,8 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
frameSize = wAlign16 * hAlign16 * 3 / 2; frameSize = wAlign16 * hAlign16 * 3 / 2;
if (pOutFile && (frame_count++ < cmd->record_frames)) { if (pOutFile && (frame_count++ < cmd->record_frames)) {
mpp_log("write %d frame(yuv420sp) data, %d bytes to file\n", printf("write %d frame(yuv420sp) data, %d bytes to file\n",
frame_count, frameSize); frame_count, frameSize);
fwrite((RK_U8 *)(frame->vpumem.vir_addr), 1, frameSize, pOutFile); fwrite((RK_U8 *)(frame->vpumem.vir_addr), 1, frameSize, pOutFile);
fflush(pOutFile); fflush(pOutFile);
@@ -696,7 +702,7 @@ static RK_S32 vpu_decode_demo(VpuApiDemoCmdContext_t *cmd)
} }
} }
msleep(3); usleep(3000);
} while (!(ctx->decoder_err)); } while (!(ctx->decoder_err));
DECODE_OUT: DECODE_OUT:
@@ -726,9 +732,9 @@ DECODE_OUT:
} }
if (ret) { if (ret) {
mpp_log("decode demo fail, err: %d\n", ret); printf("decode demo fail, err: %d\n", ret);
} else { } else {
mpp_log("encode demo complete OK.\n"); printf("encode demo complete OK.\n");
} }
return ret; return ret;
} }
@@ -740,7 +746,7 @@ int main(int argc, char **argv)
VpuApiDemoCmdContext_t demoCmdCtx; VpuApiDemoCmdContext_t demoCmdCtx;
VpuApiDemoCmdContext_t *cmd = NULL; VpuApiDemoCmdContext_t *cmd = NULL;
mpp_log("/******* vpu api demo in *******/\n"); printf("/******* vpu api demo in *******/\n");
if (argc == 1) { if (argc == 1) {
show_usage(); show_usage();
return 0; return 0;
@@ -749,7 +755,7 @@ int main(int argc, char **argv)
/* open library for access */ /* open library for access */
vpuapi_hdl = dlopen("libvpu.so", RTLD_LAZY | RTLD_GLOBAL); vpuapi_hdl = dlopen("libvpu.so", RTLD_LAZY | RTLD_GLOBAL);
if (NULL == vpuapi_hdl) { if (NULL == vpuapi_hdl) {
mpp_log("failed to open libvpu.so\n"); printf("failed to open libvpu.so\n");
ret = -1; ret = -1;
goto DEMO_OUT; goto DEMO_OUT;
} }
@@ -761,16 +767,16 @@ int main(int argc, char **argv)
if (NULL == vpuapi_open_ctx || NULL == vpuapi_close_ctx || if (NULL == vpuapi_open_ctx || NULL == vpuapi_close_ctx ||
NULL == vpuapi_mem_link || NULL == vpuapi_mem_free) { NULL == vpuapi_mem_link || NULL == vpuapi_mem_free) {
mpp_log("failed to open vpu_open_context %p vpu_close_context %p\n", printf("failed to open vpu_open_context %p vpu_close_context %p\n",
vpuapi_open_ctx, vpuapi_close_ctx); vpuapi_open_ctx, vpuapi_close_ctx);
mpp_log("failed to open VPUMemLink %p VPUFreeLinear %p\n", printf("failed to open VPUMemLink %p VPUFreeLinear %p\n",
vpuapi_mem_link, vpuapi_mem_free); vpuapi_mem_link, vpuapi_mem_free);
ret = -1; ret = -1;
goto DEMO_OUT; goto DEMO_OUT;
} }
mpp_log("get vpuapi handle %p vpu_open_context %p vpu_close_context %p\n", printf("get vpuapi handle %p vpu_open_context %p vpu_close_context %p\n",
vpuapi_hdl, vpuapi_open_ctx, vpuapi_close_ctx); vpuapi_hdl, vpuapi_open_ctx, vpuapi_close_ctx);
cmd = &demoCmdCtx; cmd = &demoCmdCtx;
memset(cmd, 0, sizeof(VpuApiDemoCmdContext_t)); memset(cmd, 0, sizeof(VpuApiDemoCmdContext_t));
@@ -780,7 +786,7 @@ int main(int argc, char **argv)
return 0; return 0;
} }
mpp_log("parse_options fail\n\n"); printf("parse_options fail\n\n");
show_usage(); show_usage();
DEMO_ERR_RET(ERROR_INVALID_PARAM); DEMO_ERR_RET(ERROR_INVALID_PARAM);
} }
@@ -799,13 +805,13 @@ int main(int argc, char **argv)
DEMO_OUT: DEMO_OUT:
if (ret) { if (ret) {
mpp_log("vpu api demo fail, err: %d\n", ret); printf("vpu api demo fail, err: %d\n", ret);
if (vpuapi_hdl) { if (vpuapi_hdl) {
dlclose(vpuapi_hdl); dlclose(vpuapi_hdl);
vpuapi_hdl = NULL; vpuapi_hdl = NULL;
} }
} else { } else {
mpp_log("vpu api demo complete OK.\n"); printf("vpu api demo complete OK.\n");
} }
return ret; return ret;
} }