main.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "RuntimeEngine.h"
  2. #include <sys/time.h>
  3. #ifdef EEASY_CHIP
  4. #include "ax_test_utils.h"
  5. int get_frame_data(char *yuv_path, int h, int w, frame_t &input)
  6. {
  7. int y_size = w * h;
  8. int uv_size = y_size / 2;
  9. FILE *input_file = NULL;
  10. input_file = fopen(yuv_path, "rb");
  11. if (input_file == NULL)
  12. {
  13. printf("[%s Line:%d] %s open error.\n", __FUNCTION__, __LINE__, yuv_path);
  14. return -1;
  15. }
  16. memset(&input, 0, sizeof(frame_t));
  17. input.fmt = YUV420SPNV21;
  18. input.w = w;
  19. input.h = h;
  20. input.pVir = ax_malloc_uncache(&input.pPhy, y_size + uv_size);
  21. input.pVir_UV = (void *)((char *)input.pVir + y_size);
  22. input.pPhy_UV = input.pPhy + y_size;
  23. int len;
  24. len = fread(input.pVir, 1, y_size + uv_size, input_file);
  25. if (len != (y_size + uv_size))
  26. {
  27. printf("[%s Line:%d] %s fread error.\n", __FUNCTION__, __LINE__, yuv_path);
  28. return -1;
  29. }
  30. printf("[%s Line:%d] get frame from %s success.\n", __FUNCTION__, __LINE__, yuv_path);
  31. return 0;
  32. }
  33. #elif AXERA_CHIP
  34. int get_frame_data(char *image_path, frame_t &frame_st)
  35. {
  36. std::vector<char> frame;
  37. int read_file_ret = utilities::read_file(image_path, frame);
  38. printf("[%s Line:%d] read_file_ret:%d frame size:%d.\n", __FUNCTION__, __LINE__, read_file_ret, frame.size());
  39. frame_st.pVir = (char *)malloc(frame.size());
  40. std::memcpy((char *)frame_st.pVir, frame.data(), frame.size());
  41. if (read_file_ret)
  42. {
  43. return AIStatus::StatusCode::SUCCESS;
  44. }
  45. else
  46. {
  47. return AIStatus::StatusCode::FAILED;
  48. }
  49. }
  50. #endif
  51. int main()
  52. {
  53. #ifdef AXERA_CHIP
  54. AX_S32 init_ret = AX_SYS_Init();
  55. if (init_ret != AIStatus::StatusCode::SUCCESS)
  56. {
  57. printf("[%s Line:%d] Axera System Init Failed\n", __FUNCTION__, __LINE__);
  58. exit(-1);
  59. }
  60. #endif
  61. RuntimeEngine data_instance;
  62. // 读取配置文件
  63. data_instance.init("config_all.json",false);
  64. data_instance.init("config_all.json",true);
  65. int getFrameFromYuvStatus;
  66. frame_t frame_st;
  67. #ifdef EEASY_CHIP
  68. getFrameFromYuvStatus = get_frame_data((char *)"/share/images/images_YUV420SPNV21.yuv", 288, 512, frame_st);
  69. #elif AXERA_CHIP
  70. getFrameFromYuvStatus = get_frame_data((char *)"/share/images/images_RGB.rgb", frame_st);
  71. #endif
  72. frame_t frame_st2;
  73. #ifdef EEASY_CHIP
  74. getFrameFromYuvStatus = get_frame_data((char *)"/share/images/images_YUV420SPNV21.yuv", 288, 512, frame_st2);
  75. #elif AXERA_CHIP
  76. getFrameFromYuvStatus = get_frame_data((char *)"/share/images/images_RGB.rgb", frame_st2);
  77. #endif
  78. int requestIdA, requestIdB, ret;
  79. requestIdA = data_instance.createRequest(&frame_st);
  80. data_instance.wait(requestIdA);
  81. // ret = data_instance.setPipelineStatus(92, true);
  82. // std::cout << "OPEN 92" << "ret:" << ret << std::endl;
  83. struct timeval start_time, end_time;
  84. gettimeofday(&start_time, NULL);
  85. for (int i = 0; i < 100; i++)
  86. {
  87. int requestIdB = data_instance.createRequest(&frame_st2);
  88. data_instance.wait(requestIdA);
  89. requestIdA = requestIdB;
  90. }
  91. gettimeofday(&end_time, NULL);
  92. long long execution_time = (end_time.tv_sec - start_time.tv_sec) * 1000LL +
  93. (end_time.tv_usec - start_time.tv_usec) / 1000LL;
  94. printf("Sum of execution times: %lld ms\n", execution_time);
  95. printf("Avg of one frame execution times: %lld ms\n", execution_time / 100);
  96. data_instance.cleanup();
  97. printf("[%s Line:%d] -----------\n", __FUNCTION__, __LINE__);
  98. std::cout << "-------Program end--------" << std::endl;
  99. return 0;
  100. }