#include "RuntimeEngine.h" #include #ifdef EEASY_CHIP #include "ax_test_utils.h" int get_frame_data(char *yuv_path, int h, int w, frame_t &input) { int y_size = w * h; int uv_size = y_size / 2; FILE *input_file = NULL; input_file = fopen(yuv_path, "rb"); if (input_file == NULL) { printf("[%s Line:%d] %s open error.\n", __FUNCTION__, __LINE__, yuv_path); return -1; } memset(&input, 0, sizeof(frame_t)); input.fmt = YUV420SPNV21; input.w = w; input.h = h; input.pVir = ax_malloc_uncache(&input.pPhy, y_size + uv_size); input.pVir_UV = (void *)((char *)input.pVir + y_size); input.pPhy_UV = input.pPhy + y_size; int len; len = fread(input.pVir, 1, y_size + uv_size, input_file); if (len != (y_size + uv_size)) { printf("[%s Line:%d] %s fread error.\n", __FUNCTION__, __LINE__, yuv_path); return -1; } printf("[%s Line:%d] get frame from %s success.\n", __FUNCTION__, __LINE__, yuv_path); return 0; } #elif AXERA_CHIP int get_frame_data(char *image_path, frame_t &frame_st) { std::vector frame; int read_file_ret = utilities::read_file(image_path, frame); printf("[%s Line:%d] read_file_ret:%d frame size:%d.\n", __FUNCTION__, __LINE__, read_file_ret, frame.size()); frame_st.pVir = (char *)malloc(frame.size()); std::memcpy((char *)frame_st.pVir, frame.data(), frame.size()); if (read_file_ret) { return AIStatus::StatusCode::SUCCESS; } else { return AIStatus::StatusCode::FAILED; } } #endif int main() { #ifdef AXERA_CHIP AX_S32 init_ret = AX_SYS_Init(); if (init_ret != AIStatus::StatusCode::SUCCESS) { printf("[%s Line:%d] Axera System Init Failed\n", __FUNCTION__, __LINE__); exit(-1); } #endif RuntimeEngine data_instance; // 读取配置文件 data_instance.init("config_all.json",false); data_instance.init("config_all.json",true); int getFrameFromYuvStatus; frame_t frame_st; #ifdef EEASY_CHIP getFrameFromYuvStatus = get_frame_data((char *)"/share/images/images_YUV420SPNV21.yuv", 288, 512, frame_st); #elif AXERA_CHIP getFrameFromYuvStatus = get_frame_data((char *)"/share/images/images_RGB.rgb", frame_st); #endif frame_t frame_st2; #ifdef EEASY_CHIP getFrameFromYuvStatus = get_frame_data((char *)"/share/images/images_YUV420SPNV21.yuv", 288, 512, frame_st2); #elif AXERA_CHIP getFrameFromYuvStatus = get_frame_data((char *)"/share/images/images_RGB.rgb", frame_st2); #endif int requestIdA, requestIdB, ret; requestIdA = data_instance.createRequest(&frame_st); data_instance.wait(requestIdA); // ret = data_instance.setPipelineStatus(92, true); // std::cout << "OPEN 92" << "ret:" << ret << std::endl; struct timeval start_time, end_time; gettimeofday(&start_time, NULL); for (int i = 0; i < 100; i++) { int requestIdB = data_instance.createRequest(&frame_st2); data_instance.wait(requestIdA); requestIdA = requestIdB; } gettimeofday(&end_time, NULL); long long execution_time = (end_time.tv_sec - start_time.tv_sec) * 1000LL + (end_time.tv_usec - start_time.tv_usec) / 1000LL; printf("Sum of execution times: %lld ms\n", execution_time); printf("Avg of one frame execution times: %lld ms\n", execution_time / 100); data_instance.cleanup(); printf("[%s Line:%d] -----------\n", __FUNCTION__, __LINE__); std::cout << "-------Program end--------" << std::endl; return 0; }