From 7c671efc7ee2f0782f1450d4818449d0da6aa9a2 Mon Sep 17 00:00:00 2001 From: lxowalle Date: Wed, 17 Jul 2024 17:30:09 +0800 Subject: [PATCH] * supports up to 60fps at 720P --- components/maixcam_lib/CMakeLists.txt | 191 +++++++----------- components/maixcam_lib/component.py | 3 + .../maixcam_lib/include/sophgo_middleware.hpp | 26 +++ .../vision/port/maixcam/maix_camera_mmf.hpp | 24 ++- components/vision/src/maix_camera.cpp | 21 +- 5 files changed, 140 insertions(+), 125 deletions(-) diff --git a/components/maixcam_lib/CMakeLists.txt b/components/maixcam_lib/CMakeLists.txt index 49228f35..b74d6361 100644 --- a/components/maixcam_lib/CMakeLists.txt +++ b/components/maixcam_lib/CMakeLists.txt @@ -45,86 +45,41 @@ if(CONFIG_MAIXCAM_LIB_COMPILE_FROM_SOURCE) list(APPEND ADD_STATIC_LIB ${middleware_static_lib_file}) set_property(SOURCE ${middleware_static_lib_file} PROPERTY GENERATED 1) - if(${middleware_version_str} VERSION_EQUAL "0.0.4") - set(mmf_lib_dir ${middleware_src_path}/v2/lib) - else() - set(mmf_lib_dir ${middleware_src_path}/v2/${CONFIG_SOPHGO_MIDDLEWARE_CHIP}/lib_${CONFIG_SOPHGO_MIDDLEWARE_C_LIBRARY}_riscv64) - endif() + set(mmf_lib_dir ${middleware_src_path}/v2/lib) if(CONFIG_SOPHGO_MIDDLEWARE_C_LIBRARY STREQUAL "musl") - if(${middleware_version_str} VERSION_EQUAL "0.0.4") - set(middleware_dynamic_lib_file ${mmf_lib_dir}/libcvi_ive.so - ${mmf_lib_dir}/libcvi_bin.so - ${mmf_lib_dir}/libaaccomm2.so - ${mmf_lib_dir}/libaacdec2.so - ${mmf_lib_dir}/libaacenc2.so - ${mmf_lib_dir}/libaacsbrdec2.so - ${mmf_lib_dir}/libaacsbrenc2.so - ${mmf_lib_dir}/libae.so - ${mmf_lib_dir}/libaf.so - ${mmf_lib_dir}/libawb.so - ${mmf_lib_dir}/libcvi_audio.so - ${mmf_lib_dir}/libcvi_bin_isp.so - ${mmf_lib_dir}/libcvi_bin.so - ${mmf_lib_dir}/libcvi_ispd2.so - ${mmf_lib_dir}/libcvi_RES1.so - ${mmf_lib_dir}/libcvi_ssp.so - ${mmf_lib_dir}/libcvi_VoiceEngine.so - ${mmf_lib_dir}/libcvi_vqe.so - ${mmf_lib_dir}/libdnvqe.so - ${mmf_lib_dir}/libisp_algo.so - ${mmf_lib_dir}/libisp.so - ${mmf_lib_dir}/libmipi_tx.so - ${mmf_lib_dir}/libmisc.so - ${mmf_lib_dir}/libosdc.so - ${mmf_lib_dir}/libraw_dump.so - ${mmf_lib_dir}/libsys.so - ${mmf_lib_dir}/libvdec.so - ${mmf_lib_dir}/libvenc.so - ${mmf_lib_dir}/libvpu.so - ${mmf_lib_dir}/libjson-c.so.5 - ${mmf_lib_dir}/libtinyalsa.so - ${mmf_lib_dir}/3rd/libcli.so - ${mmf_lib_dir}/3rd/libini.so) - else() - set(middleware_dynamic_lib_file ${mmf_lib_dir}/libcvi_ive.so - ${mmf_lib_dir}/libcvi_bin.so - ${mmf_lib_dir}/libaaccomm2.so - ${mmf_lib_dir}/libaacdec2.so - ${mmf_lib_dir}/libaacenc2.so - ${mmf_lib_dir}/libaacsbrdec2.so - ${mmf_lib_dir}/libaacsbrenc2.so - ${mmf_lib_dir}/libae.so - ${mmf_lib_dir}/libaf.so - ${mmf_lib_dir}/libawb.so - ${mmf_lib_dir}/libcipher.so - ${mmf_lib_dir}/libcvi_audio.so - ${mmf_lib_dir}/libcvi_bin_isp.so - ${mmf_lib_dir}/libcvi_bin.so - ${mmf_lib_dir}/libcvi_ispd2.so - ${mmf_lib_dir}/libcvi_RES1.so - ${mmf_lib_dir}/libcvi_ssp.so - ${mmf_lib_dir}/libcvi_VoiceEngine.so - ${mmf_lib_dir}/libcvi_vqe.so - ${mmf_lib_dir}/libdnvqe.so - ${mmf_lib_dir}/libisp_algo.so - ${mmf_lib_dir}/libisp.so - ${mmf_lib_dir}/libmipi_tx.so - ${mmf_lib_dir}/libmisc.so - ${mmf_lib_dir}/libosdc.so - ${mmf_lib_dir}/libraw_dump.so - # ${mmf_lib_dir}/libraw_replay.so - # ${mmf_lib_dir}/libsns_full.so - # ${mmf_lib_dir}/libsns_gc4653.so - ${mmf_lib_dir}/libsys.so - ${mmf_lib_dir}/libvdec.so - ${mmf_lib_dir}/libvenc.so - ${mmf_lib_dir}/libvpu.so - ${mmf_lib_dir}/libz.so - ${mmf_lib_dir}/libtinyalsa.so - ${mmf_lib_dir}/3rd/libcli.so - ${mmf_lib_dir}/3rd/libini.so - ${mmf_lib_dir}/3rd/libjson-c.so.5) - endif() + set(middleware_dynamic_lib_file ${mmf_lib_dir}/libcvi_ive.so + ${mmf_lib_dir}/libcvi_bin.so + ${mmf_lib_dir}/libaaccomm2.so + ${mmf_lib_dir}/libaacdec2.so + ${mmf_lib_dir}/libaacenc2.so + ${mmf_lib_dir}/libaacsbrdec2.so + ${mmf_lib_dir}/libaacsbrenc2.so + ${mmf_lib_dir}/libae.so + ${mmf_lib_dir}/libaf.so + ${mmf_lib_dir}/libawb.so + ${mmf_lib_dir}/libcvi_audio.so + ${mmf_lib_dir}/libcvi_bin_isp.so + ${mmf_lib_dir}/libcvi_bin.so + ${mmf_lib_dir}/libcvi_ispd2.so + ${mmf_lib_dir}/libcvi_RES1.so + ${mmf_lib_dir}/libcvi_ssp.so + ${mmf_lib_dir}/libcvi_VoiceEngine.so + ${mmf_lib_dir}/libcvi_vqe.so + ${mmf_lib_dir}/libdnvqe.so + ${mmf_lib_dir}/libisp_algo.so + ${mmf_lib_dir}/libisp.so + ${mmf_lib_dir}/libmipi_tx.so + ${mmf_lib_dir}/libmisc.so + ${mmf_lib_dir}/libosdc.so + ${mmf_lib_dir}/libraw_dump.so + ${mmf_lib_dir}/libsys.so + ${mmf_lib_dir}/libvdec.so + ${mmf_lib_dir}/libvenc.so + ${mmf_lib_dir}/libvpu.so + ${mmf_lib_dir}/libjson-c.so.5 + ${mmf_lib_dir}/libtinyalsa.so + ${mmf_lib_dir}/3rd/libcli.so + ${mmf_lib_dir}/3rd/libini.so) elseif(CONFIG_SOPHGO_MIDDLEWARE_C_LIBRARY STREQUAL "glibc") set(middleware_dynamic_lib_file ${mmf_lib_dir}/libcvi_vb.so ${mmf_lib_dir}/libcvi_sys.so @@ -146,47 +101,43 @@ else() list(APPEND ADD_DYNAMIC_LIB "lib/libmaixcam_lib.so") list(APPEND ADD_DIST_LIB_IGNORE "lib/libmaixcam_lib.so") if(CONFIG_SOPHGO_MIDDLEWARE_C_LIBRARY STREQUAL "musl") - if(${middleware_version_str} VERSION_EQUAL "0.0.4") - set(mmf_lib_dir ${middleware_src_path}/v2/lib) - set(middleware_dynamic_lib_file ${mmf_lib_dir}/libcvi_ive.so - ${mmf_lib_dir}/libcvi_bin.so - ${mmf_lib_dir}/libaaccomm2.so - ${mmf_lib_dir}/libaacdec2.so - ${mmf_lib_dir}/libaacenc2.so - ${mmf_lib_dir}/libaacsbrdec2.so - ${mmf_lib_dir}/libaacsbrenc2.so - ${mmf_lib_dir}/libae.so - ${mmf_lib_dir}/libaf.so - ${mmf_lib_dir}/libawb.so - ${mmf_lib_dir}/libcvi_audio.so - ${mmf_lib_dir}/libcvi_bin_isp.so - ${mmf_lib_dir}/libcvi_bin.so - ${mmf_lib_dir}/libcvi_ispd2.so - ${mmf_lib_dir}/libcvi_RES1.so - ${mmf_lib_dir}/libcvi_ssp.so - ${mmf_lib_dir}/libcvi_VoiceEngine.so - ${mmf_lib_dir}/libcvi_vqe.so - ${mmf_lib_dir}/libdnvqe.so - ${mmf_lib_dir}/libisp_algo.so - ${mmf_lib_dir}/libisp.so - ${mmf_lib_dir}/libmipi_tx.so - ${mmf_lib_dir}/libmisc.so - ${mmf_lib_dir}/libosdc.so - ${mmf_lib_dir}/libraw_dump.so - ${mmf_lib_dir}/libsys.so - ${mmf_lib_dir}/libvdec.so - ${mmf_lib_dir}/libvenc.so - ${mmf_lib_dir}/libvpu.so - ${mmf_lib_dir}/libjson-c.so.5 - ${mmf_lib_dir}/libtinyalsa.so - ${mmf_lib_dir}/3rd/libcli.so - ${mmf_lib_dir}/3rd/libini.so - ) - list(APPEND ADD_DYNAMIC_LIB ${middleware_dynamic_lib_file}) - set_property(SOURCE ${ADD_DYNAMIC_LIB} PROPERTY GENERATED 1) - else() - message(FATAL_ERROR "not suppor yet") - endif() + set(mmf_lib_dir ${middleware_src_path}/v2/lib) + set(middleware_dynamic_lib_file ${mmf_lib_dir}/libcvi_ive.so + ${mmf_lib_dir}/libcvi_bin.so + ${mmf_lib_dir}/libaaccomm2.so + ${mmf_lib_dir}/libaacdec2.so + ${mmf_lib_dir}/libaacenc2.so + ${mmf_lib_dir}/libaacsbrdec2.so + ${mmf_lib_dir}/libaacsbrenc2.so + ${mmf_lib_dir}/libae.so + ${mmf_lib_dir}/libaf.so + ${mmf_lib_dir}/libawb.so + ${mmf_lib_dir}/libcvi_audio.so + ${mmf_lib_dir}/libcvi_bin_isp.so + ${mmf_lib_dir}/libcvi_bin.so + ${mmf_lib_dir}/libcvi_ispd2.so + ${mmf_lib_dir}/libcvi_RES1.so + ${mmf_lib_dir}/libcvi_ssp.so + ${mmf_lib_dir}/libcvi_VoiceEngine.so + ${mmf_lib_dir}/libcvi_vqe.so + ${mmf_lib_dir}/libdnvqe.so + ${mmf_lib_dir}/libisp_algo.so + ${mmf_lib_dir}/libisp.so + ${mmf_lib_dir}/libmipi_tx.so + ${mmf_lib_dir}/libmisc.so + ${mmf_lib_dir}/libosdc.so + ${mmf_lib_dir}/libraw_dump.so + ${mmf_lib_dir}/libsys.so + ${mmf_lib_dir}/libvdec.so + ${mmf_lib_dir}/libvenc.so + ${mmf_lib_dir}/libvpu.so + ${mmf_lib_dir}/libjson-c.so.5 + ${mmf_lib_dir}/libtinyalsa.so + ${mmf_lib_dir}/3rd/libcli.so + ${mmf_lib_dir}/3rd/libini.so + ) + list(APPEND ADD_DYNAMIC_LIB ${middleware_dynamic_lib_file}) + set_property(SOURCE ${ADD_DYNAMIC_LIB} PROPERTY GENERATED 1) else() message(FATAL_ERROR "not suppor yet") endif() diff --git a/components/maixcam_lib/component.py b/components/maixcam_lib/component.py index 81c7c0ea..d7df26c4 100644 --- a/components/maixcam_lib/component.py +++ b/components/maixcam_lib/component.py @@ -8,6 +8,9 @@ def add_file_downloads(confs : dict) -> list: if version == "0.0.4": url = "https://github.com/sipeed/MaixCDK/releases/download/v0.0.0/sophgo-middleware-0.0.4.tar.xz" sha256sum = "e239b4be072c3835962a8f73d24dcc88f9258ae9d90edae94419b39823dc4c14" + elif version == "0.0.5": + url = "https://github.com/sipeed/MaixCDK/releases/download/v0.0.0/sophgo-middleware-0.0.5.tar.xz" + sha256sum = "484dd9199f7d8d5d2af34bf76fd2b9e5feb3d47691308e491c68270844adffb9" else: raise Exception(f"version {version} not support") filename = f"sophgo-middleware-${version}.tar.xz" diff --git a/components/maixcam_lib/include/sophgo_middleware.hpp b/components/maixcam_lib/include/sophgo_middleware.hpp index 3893d8ef..8abf838b 100644 --- a/components/maixcam_lib/include/sophgo_middleware.hpp +++ b/components/maixcam_lib/include/sophgo_middleware.hpp @@ -44,15 +44,41 @@ typedef struct { int fmt; } mmf_frame_info_t; +typedef struct { + int chn; + int w; + int h; + int fmt; + int fps; + int depth; +} mmf_vi_cfg_t; + +typedef struct { + struct { + int size; + int count; + /* + VB_REMAP_MODE_NONE = 0, + VB_REMAP_MODE_NOCACHE = 1, + VB_REMAP_MODE_CACHED = 2, + VB_REMAP_MODE_BUTT + */ + int map; + } vb_pool[16]; + int max_pool_cnt; +} mmf_sys_cfg_t; + // init sys int mmf_init(void); int mmf_deinit(void); int mmf_try_deinit(bool force); bool mmf_is_init(void); +void mmf_pre_config_sys(mmf_sys_cfg_t *cfg); // manage vi channels(vi->vpssgroup->vpss->frame) int mmf_get_vi_unused_channel(void); int mmf_vi_init(void); +int mmf_vi_init2(mmf_vi_cfg_t *vi_info); int mmf_vi_deinit(void); int mmf_add_vi_channel_with_enc(int ch, int width, int height, int format); int mmf_add_vi_channel(int ch, int width, int height, int format); diff --git a/components/vision/port/maixcam/maix_camera_mmf.hpp b/components/vision/port/maixcam/maix_camera_mmf.hpp index 82214c3f..d21a92a4 100644 --- a/components/vision/port/maixcam/maix_camera_mmf.hpp +++ b/components/vision/port/maixcam/maix_camera_mmf.hpp @@ -65,7 +65,7 @@ namespace maix::camera class CameraCviMmf final : public CameraBase { public: - CameraCviMmf(const std::string device, int width, int height, image::Format format, int buff_num) + CameraCviMmf(const std::string device, int width, int height, image::Format format, int buff_num, int fps) { this->device = device; this->format = format; @@ -74,11 +74,31 @@ namespace maix::camera this->buffer_num = buff_num; this->ch = -1; + mmf_sys_cfg_t sys_cfg = {0}; + if (width <= 1280 && height <= 720 && fps == 60) { + sys_cfg.vb_pool[0].size = 1280 * 720 * 3 / 2; + sys_cfg.vb_pool[0].count = 5; + sys_cfg.vb_pool[0].map = 2; + sys_cfg.max_pool_cnt = 1; + } else { + sys_cfg.vb_pool[0].size = 2560 * 1440 * 3 / 2; + sys_cfg.vb_pool[0].count = 4; + sys_cfg.vb_pool[0].map = 2; + sys_cfg.max_pool_cnt = 1; + } + mmf_pre_config_sys(&sys_cfg); + if (0 != mmf_init()) { err::check_raise(err::ERR_RUNTIME, "mmf init failed"); } - if (0 != mmf_vi_init()) { + mmf_vi_cfg_t cfg = {0}; + cfg.w = width; + cfg.h = height; + cfg.fmt = mmf_invert_format_to_mmf(format); + cfg.depth = buff_num; + cfg.fps = fps; + if (0 != mmf_vi_init2(&cfg)) { err::check_raise(err::ERR_RUNTIME, "mmf vi init failed"); } } diff --git a/components/vision/src/maix_camera.cpp b/components/vision/src/maix_camera.cpp index 8c9b1c2b..3ba5532d 100644 --- a/components/vision/src/maix_camera.cpp +++ b/components/vision/src/maix_camera.cpp @@ -116,13 +116,28 @@ namespace maix::camera _width = (width == -1) ? 640 : width; _height = (height == -1) ? 480 : height; _format = format; - _fps = (fps == -1) ? 30 : fps; - _buff_num = buff_num; + _buff_num = buff_num; _show_colorbar = false; _open_set_regs = set_regs_flag; _impl = NULL; + if (fps == -1 && _width <= 1280 && _height <= 720) { + _fps = 60; + } else if (fps == -1 && (_width > 1280 || _height > 720)) { + _fps = 30; + } else { + _fps = fps; + } + + if ((_width > 1280 || _height > 720) && _fps > 30) { + log::warn("Current fps is too high, will be be updated to 30fps! Currently only supported up to 720p 60fps or 1440p 30fps.\r\n"); + _fps = 30; + } else if (_width <= 1280 && _height <= 720 && _fps > 30 && _fps != 60) { + log::warn("Currently only supports fixed 30fps and 60fps in 720p configuration, current configuration will be updated to 60fps.\r\n"); + _fps = 60; + } + #ifdef PLATFORM_LINUX _device = _get_device(device); _impl = new CameraV4L2(_device, _width, _height, _format, _buff_num); @@ -130,7 +145,7 @@ namespace maix::camera #ifdef PLATFORM_MAIXCAM _device = ""; - _impl = new CameraCviMmf(_device, _width, _height, _format, _buff_num); + _impl = new CameraCviMmf(_device, _width, _height, _format, _buff_num, _fps); #endif if (open) {