diff --git a/element/multimedia/decode/src/ff_decode.cc b/element/multimedia/decode/src/ff_decode.cc index 916a3f65..202f6064 100644 --- a/element/multimedia/decode/src/ff_decode.cc +++ b/element/multimedia/decode/src/ff_decode.cc @@ -440,7 +440,7 @@ int VideoDecFFM::openDec(bm_handle_t* dec_handle, const char* input) { if (this->is_camera) { av_dict_set_int(&dict, "v4l2_buffer_num", 8, 0); // v4l2bufnum = 8 - av_dict_set_int(&dict, "use_mw", 0, 0); // int isusemw = 0 + // av_dict_set_int(&dict, "use_mw", 0, 0); // int isusemw = 0 av_dict_set_int(&dict, "use_isp", 0, 0); // int isusemw = 0 } diff --git a/element/tools/blend/CMakeLists.txt b/element/tools/blend/CMakeLists.txt index fde9c3bf..b22bd333 100644 --- a/element/tools/blend/CMakeLists.txt +++ b/element/tools/blend/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -g") if (NOT DEFINED TARGET_ARCH) set(TARGET_ARCH pcie) endif() -set(CMAKE_BUILD_TYPE "DEBUG") +# set(CMAKE_BUILD_TYPE "DEBUG") if (${TARGET_ARCH} STREQUAL "pcie") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -pthread") diff --git a/element/tools/blend/include/blend.h b/element/tools/blend/include/blend.h index 90cf8d2d..3230ed5a 100644 --- a/element/tools/blend/include/blend.h +++ b/element/tools/blend/include/blend.h @@ -21,7 +21,7 @@ namespace sophon_stream { namespace element { namespace blend { -enum DisplayType { RAW_BLEND_DIS = 0, DWA_BLEND_DIS = 1, ONLY_BLEND_DIS = 2 }; +enum DisplayType { ONLY_RAW_DIS =0, DWA_BLEND_DIS = 1 }; class Blend : public ::sophon_stream::framework::Element { public: Blend(); @@ -51,7 +51,7 @@ class Blend : public ::sophon_stream::framework::Element { static constexpr const char* CONFIG_INTERNAL_WET_MODE_FILED = "wgt_mode"; - DisplayType dis_type = RAW_BLEND_DIS; + DisplayType dis_type = DWA_BLEND_DIS; bool isDwa = false; int dev_id = 0; bm_handle_t handle = NULL; diff --git a/element/tools/blend/src/blend.cc b/element/tools/blend/src/blend.cc index 5363fbf0..c802459b 100644 --- a/element/tools/blend/src/blend.cc +++ b/element/tools/blend/src/blend.cc @@ -105,7 +105,7 @@ common::ErrorCode Blend::initInternal(const std::string& json) { bm_status_t ret = bm_dev_request(&handle, dev_id); - src_h = 1080; + src_h = 2240; // src_w = configure.find(CONFIG_INTERNAL_WEIGHT_FILED)->get(); auto wgt1 = configure.find(CONFIG_INTERNAL_WGT1_FILED)->get(); auto wgt2 = configure.find(CONFIG_INTERNAL_WGT2_FILED)->get(); @@ -152,22 +152,11 @@ common::ErrorCode Blend::blend_work( std::shared_ptr blendObj) { std::lock_guard lk(mtx); IVS_INFO("Now DisplayType is {0}", dis_type); - std::shared_ptr blend_image = nullptr; - blend_image.reset(new bm_image, [](bm_image* p) { - bm_image_destroy(*p); - delete p; - p = nullptr; - }); - bm_status_t ret = - bm_image_create(handle, leftObj->mFrame->mSpData->height, - ALIGN(leftObj->mFrame->mSpData->width * 2 - 224, 32), - FORMAT_YUV420P, DATA_TYPE_EXT_1N_BYTE, blend_image.get()); - bm_image_alloc_dev_mem(*blend_image, 1); // select display type std::shared_ptr blend_image_left = nullptr; std::shared_ptr blend_image_right = nullptr; - if (dis_type == ONLY_BLEND_DIS || dis_type == DWA_BLEND_DIS) { + if (dis_type == DWA_BLEND_DIS) { blend_image_left = leftObj->mFrame->mSpDataDwa; blend_image_right = rightObj->mFrame->mSpDataDwa; } else { @@ -175,60 +164,27 @@ common::ErrorCode Blend::blend_work( blend_image_right = rightObj->mFrame->mSpData; } - // - bool need_convert = (blend_image_left->image_format != FORMAT_YUV420P || - blend_image_right->image_format != FORMAT_YUV420P); - - bm_image blend_img[2]; - if (need_convert) { - ret = bm_image_create(leftObj->mFrame->mHandle, blend_image_left->height, - blend_image_left->width, FORMAT_YUV420P, - DATA_TYPE_EXT_1N_BYTE, &blend_img[0], NULL); - ret = bm_image_create(rightObj->mFrame->mHandle, blend_image_right->height, - blend_image_right->width, FORMAT_YUV420P, - DATA_TYPE_EXT_1N_BYTE, &blend_img[1], NULL); - - bm_image_alloc_dev_mem(blend_img[0], 1); - bm_image_alloc_dev_mem(blend_img[1], 1); - - ret = bmcv_image_storage_convert(leftObj->mFrame->mHandle, 1, - blend_image_left.get(), &blend_img[0]); - ret = bmcv_image_storage_convert(rightObj->mFrame->mHandle, 1, - blend_image_right.get(), &blend_img[1]); - } else { - blend_img[0] = *blend_image_left; - blend_img[1] = *blend_image_right; - } - - // blend - - ret = bmcv_blending(handle, input_num, blend_img, *blend_image, blend_config); - // dispaly image - if (dis_type != ONLY_BLEND_DIS) { - std::shared_ptr all_image = nullptr; - all_image.reset(new bm_image, [](bm_image* p) { + if (dis_type == ONLY_RAW_DIS) { + std::shared_ptr two_raw_image = nullptr; + two_raw_image.reset(new bm_image, [](bm_image* p) { bm_image_destroy(*p); delete p; p = nullptr; }); - ret = bm_image_create(handle, blend_image_left->height * 3 + 200, - blend_image->width, FORMAT_YUV420P, - DATA_TYPE_EXT_1N_BYTE, all_image.get()); - bm_image_alloc_dev_mem(*all_image, 1); + bm_image_create(handle, blend_image_left->height, + blend_image_left->width * 2 + 100, + blend_image_left->image_format, DATA_TYPE_EXT_1N_BYTE, + two_raw_image.get()); + bm_image_alloc_dev_mem(*two_raw_image, 1); - bm_device_mem_t blend_mem[3] = {0}; - bm_image_get_device_mem(*all_image, blend_mem); - bm_memset_device(handle, 0, blend_mem[0]); - bm_memset_device(handle, 0, blend_mem[1]); - bm_memset_device(handle, 0, blend_mem[2]); + bm_device_mem_t blend_mem; + bm_image_get_device_mem(*two_raw_image, &blend_mem); + bm_memset_device(handle, 0, blend_mem); - bm_image src_img[3] = {blend_img[0], blend_img[1], *blend_image}; + bm_image src_img[2] = {*blend_image_left, *blend_image_right}; - // bmcv_rect_t rect = {0, 0, all_image->width, all_image->height}; - // ret = bmcv_image_fill_rectangle(handle, *all_image, 1, &rect, 0, 0, 0); - - int input_num = 3; + int input_num = 2; bmcv_rect_t dst_crop[input_num]; dst_crop[0] = {.start_x = 0, @@ -236,37 +192,73 @@ common::ErrorCode Blend::blend_work( .crop_w = (unsigned int)blend_image_left->width, .crop_h = (unsigned int)blend_image_left->height}; - dst_crop[1] = {.start_x = 0, - .start_y = (unsigned int)blend_image_right->height + 100, + dst_crop[1] = {.start_x = (unsigned int)blend_image_left->width + 100, + .start_y = 0, .crop_w = (unsigned int)blend_image_right->width, .crop_h = (unsigned int)blend_image_right->height}; - dst_crop[2] = {.start_x = 0, - .start_y = (unsigned int)blend_image_left->height + - (unsigned int)blend_image_right->height + 200, - .crop_w = (unsigned int)blend_image->width, - .crop_h = (unsigned int)blend_image->height}; - - bmcv_image_vpp_stitch(handle, input_num, src_img, *all_image, dst_crop, + bmcv_image_vpp_stitch(handle, input_num, src_img, *two_raw_image, dst_crop, NULL); - blendObj->mFrame->mSpData = all_image; - blendObj->mFrame->mWidth = all_image->width; - blendObj->mFrame->mHeight = all_image->height; + blendObj->mFrame->mSpData = two_raw_image; + blendObj->mFrame->mWidth = two_raw_image->width; + blendObj->mFrame->mHeight = two_raw_image->height; } else { + std::shared_ptr blend_image = nullptr; + blend_image.reset(new bm_image, [](bm_image* p) { + bm_image_destroy(*p); + delete p; + p = nullptr; + }); + + bm_status_t ret = bm_image_create( + handle, blend_image_left->height, + ALIGN(blend_image_left->width * 2 - 128, 32), FORMAT_YUV420P, + DATA_TYPE_EXT_1N_BYTE, blend_image.get()); + bm_image_alloc_dev_mem(*blend_image, 1); + + bool need_convert = (blend_image_left->image_format != FORMAT_YUV420P || + blend_image_right->image_format != FORMAT_YUV420P); + + bm_image blend_img[2]; + if (need_convert) { + ret = bm_image_create(leftObj->mFrame->mHandle, blend_image_left->height, + blend_image_left->width, FORMAT_YUV420P, + DATA_TYPE_EXT_1N_BYTE, &blend_img[0], NULL); + ret = + bm_image_create(rightObj->mFrame->mHandle, blend_image_right->height, + blend_image_right->width, FORMAT_YUV420P, + DATA_TYPE_EXT_1N_BYTE, &blend_img[1], NULL); + + bm_image_alloc_dev_mem(blend_img[0], 1); + bm_image_alloc_dev_mem(blend_img[1], 1); + + ret = bmcv_image_storage_convert(leftObj->mFrame->mHandle, 1, + blend_image_left.get(), &blend_img[0]); + ret = bmcv_image_storage_convert(rightObj->mFrame->mHandle, 1, + blend_image_right.get(), &blend_img[1]); + } else { + blend_img[0] = *blend_image_left; + blend_img[1] = *blend_image_right; + } + + // blend + ret = + bmcv_blending(handle, input_num, blend_img, *blend_image, blend_config); + blendObj->mFrame->mSpData = blend_image; blendObj->mFrame->mWidth = blend_image->width; blendObj->mFrame->mHeight = blend_image->height; + + if (need_convert) { + bm_image_destroy(&blend_img[0]); + bm_image_destroy(&blend_img[1]); + } } blendObj->mFrame->mChannelId = leftObj->mFrame->mChannelId; blendObj->mFrame->mFrameId = leftObj->mFrame->mFrameId; blendObj->mFrame->mChannelIdInternal = leftObj->mFrame->mChannelIdInternal; blendObj->mFrame->mHandle = leftObj->mFrame->mHandle; - - if (need_convert) { - bm_image_destroy(&blend_img[0]); - bm_image_destroy(&blend_img[1]); - } return common::ErrorCode::SUCCESS; } @@ -303,9 +295,10 @@ common::ErrorCode Blend::doWork(int dataPipeId) { std::make_shared(); blendObj->mFrame = std::make_shared(); - + // bm_image_write_to_bmp(*inputs[0]->mFrame->mSpDataDwa, "left.bmp"); + // bm_image_write_to_bmp(*inputs[1]->mFrame->mSpDataDwa, "right.bmp"); blend_work(inputs[0], inputs[1], blendObj); - + // bm_image_write_to_bmp(*blendObj->mFrame->mSpData, "blend.bmp"); int channel_id_internal = blendObj->mFrame->mChannelIdInternal; int outDataPipeId = getSinkElementFlag() diff --git a/element/tools/dpu/CMakeLists.txt b/element/tools/dpu/CMakeLists.txt index 7fa57b4c..6fc483e6 100644 --- a/element/tools/dpu/CMakeLists.txt +++ b/element/tools/dpu/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -g") if (NOT DEFINED TARGET_ARCH) set(TARGET_ARCH pcie) endif() -set(CMAKE_BUILD_TYPE "debug") +# set(CMAKE_BUILD_TYPE "debug") if (${TARGET_ARCH} STREQUAL "pcie") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -pthread") diff --git a/element/tools/dpu/include/dpu.h b/element/tools/dpu/include/dpu.h index 79f64ca4..5d3bb5d8 100644 --- a/element/tools/dpu/include/dpu.h +++ b/element/tools/dpu/include/dpu.h @@ -45,7 +45,7 @@ class Dpu : public ::sophon_stream::framework::Element { static constexpr const char* CONFIG_INTERNAL_MAPU_FILED = "ive_mapu"; static constexpr const char* CONFIG_INTERNAL_MAPV_FILED = "ive_mapv"; - DisplayType dis_type = RAW_DPU_DIS; + DisplayType dis_type = DWA_DPU_DIS; int subId = 0; int dev_id = 0; diff --git a/element/tools/dpu/src/dpu.cc b/element/tools/dpu/src/dpu.cc index 692b462e..ab50ef0b 100644 --- a/element/tools/dpu/src/dpu.cc +++ b/element/tools/dpu/src/dpu.cc @@ -583,7 +583,7 @@ common::ErrorCode Dpu::dpu_work( p = nullptr; }); ret = bm_image_create(handle, dpu_image_map->height, - dpu_image_map->width *2+100, FORMAT_YUV444P, + dpu_image_map->width *3+200, FORMAT_YUV444P, DATA_TYPE_EXT_1N_BYTE, all_image.get()); bm_image_alloc_dev_mem(*all_image, 1); @@ -593,20 +593,24 @@ common::ErrorCode Dpu::dpu_work( bm_memset_device(handle, 0, dpu_mem[1]); bm_memset_device(handle, 0, dpu_mem[2]); - int input_num = 2; + int input_num = 3; bmcv_rect_t dst_crop[input_num]; dst_crop[0] = {.start_x = 0, .start_y = 0, .crop_w = (unsigned int)dpu_image_left->width, .crop_h = (unsigned int)dpu_image_left->height}; - dst_crop[1] = {.start_x = (unsigned int)dpu_image_left->width + 100, + .start_y = 0, + .crop_w = (unsigned int)dpu_image_left->width, + .crop_h = (unsigned int)dpu_image_left->height}; + + dst_crop[2] = {.start_x = (unsigned int)dpu_image_left->width*2 + 200, .start_y = 0, .crop_w = (unsigned int)dpu_image_map->width, .crop_h = (unsigned int)dpu_image_map->height}; - bm_image src_img[2] = {dpu_img[0], *dpu_image_map}; + bm_image src_img[3] = {dpu_img[0],dpu_img[1], *dpu_image_map}; bmcv_image_vpp_stitch(handle, input_num, src_img, *all_image, dst_crop, NULL); @@ -665,8 +669,10 @@ common::ErrorCode Dpu::doWork(int dataPipeId) { std::shared_ptr dpuObj = std::make_shared(); dpuObj->mFrame = std::make_shared(); + // bm_image_write_to_bmp(*inputs[0]->mFrame->mSpDataDwa, "left.bmp"); + // bm_image_write_to_bmp(*inputs[1]->mFrame->mSpDataDwa, "right.bmp"); dpu_work(inputs[0], inputs[1], dpuObj); - + // bm_image_write_to_bmp(*dpuObj->mFrame->mSpData, "dpuObj.bmp"); IVS_INFO("Now Flag is {0}", dis_type); int channel_id_internal = dpuObj->mFrame->mChannelIdInternal; diff --git a/element/tools/dwa/CMakeLists.txt b/element/tools/dwa/CMakeLists.txt index 89322193..e292a8ea 100644 --- a/element/tools/dwa/CMakeLists.txt +++ b/element/tools/dwa/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -g") if (NOT DEFINED TARGET_ARCH) set(TARGET_ARCH pcie) endif() -set(CMAKE_BUILD_TYPE "debug") +# set(CMAKE_BUILD_TYPE "debug") if (${TARGET_ARCH} STREQUAL "pcie") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -pthread") diff --git a/element/tools/dwa/include/dwa.h b/element/tools/dwa/include/dwa.h index 9c9f720e..1ff98cc2 100644 --- a/element/tools/dwa/include/dwa.h +++ b/element/tools/dwa/include/dwa.h @@ -20,6 +20,12 @@ namespace dwa { #define FFALIGN(x, a) (((x) + (a)-1) & ~((a)-1)) +enum DwaMode { + DWA_GDC_MODE, + DWA_FISHEYE_MODE, +}; + + class Dwa : public ::sophon_stream::framework::Element { public: Dwa(); @@ -29,23 +35,61 @@ class Dwa : public ::sophon_stream::framework::Element { common::ErrorCode doWork(int dataPipeId) override; - common::ErrorCode dwa_work(std::shared_ptr dwaObj); + common::ErrorCode dwa_gdc_work(std::shared_ptr dwaObj); + common::ErrorCode fisheye_work(std::shared_ptr dwaObj); float get_aspect_scaled_ratio(int src_w, int src_h, int dst_w, int dst_h, bool* pIsAligWidth); static constexpr const char* CONFIG_INTERNAL_IS_GRAY_FILED = "is_gray"; static constexpr const char* CONFIG_INTERNAL_IS_RESIZE_FILED = "is_resize"; + static constexpr const char* CONFIG_INTERNAL_DIS_MODE_FILED = "dis_mode"; + static constexpr const char* CONFIG_INTERNAL_GRID_NAME_FILED = "grid_name"; + static constexpr const char* CONFIG_INTERNAL_USE_GRIDE_FILED = "use_grid"; + static constexpr const char* CONFIG_INTERNAL_GRIDE_SIZE_FILED = "grid_size"; + + static constexpr const char* CONFIG_INTERNAL_SRC_H_FILED = "src_h"; + static constexpr const char* CONFIG_INTERNAL_SRC_W_FILED = "src_w"; + static constexpr const char* CONFIG_INTERNAL_DST_H_FILED = "dst_h"; + static constexpr const char* CONFIG_INTERNAL_DST_W_FILED = "dst_w"; + + static constexpr const char* CONFIG_INTERNAL_DWA_MODE_FILED = "dwa_mode"; + + int src_h, src_w, dst_h, dst_w; bm_image_format_ext_ src_fmt; int subId = 0; - bool is_resize = false; - int dst_w = 1920; - int dst_h = 1080; + + bmcv_usage_mode dis_mode; + DwaMode dwa_mode; + + std::string grid_name; + bmcv_gdc_attr ldc_attr = {true, 0, 0, 0, 0, 0, -200}; + bmcv_fisheye_attr_s fisheye_attr = {0}; + std::mutex dwa_lock; private: + + std::unordered_map dwa_mode_map { + {"DWA_GDC_MODE", DwaMode::DWA_GDC_MODE}, + {"DWA_FISHEYE_MODE", DwaMode::DWA_FISHEYE_MODE} +}; + +std::unordered_map fisheye_mode_map{ + {"BMCV_MODE_PANORAMA_360", bmcv_usage_mode::BMCV_MODE_PANORAMA_360}, + {"BMCV_MODE_PANORAMA_180", bmcv_usage_mode::BMCV_MODE_PANORAMA_180}, + {"BMCV_MODE_01_1O", bmcv_usage_mode::BMCV_MODE_01_1O}, + {"BMCV_MODE_02_1O4R", bmcv_usage_mode::BMCV_MODE_02_1O4R}, + {"BMCV_MODE_03_4R", bmcv_usage_mode::BMCV_MODE_03_4R}, + {"BMCV_MODE_04_1P2R", bmcv_usage_mode::BMCV_MODE_04_1P2R}, + {"BMCV_MODE_05_1P2R", bmcv_usage_mode::BMCV_MODE_05_1P2R}, + {"BMCV_MODE_06_1P", bmcv_usage_mode::BMCV_MODE_06_1P}, + {"BMCV_MODE_07_2P", bmcv_usage_mode::BMCV_MODE_07_2P}, + {"BMCV_MODE_STEREO_FIT", bmcv_usage_mode::BMCV_MODE_STEREO_FIT}, + {"BMCV_MODE_MAX", bmcv_usage_mode::BMCV_MODE_MAX}}; + }; } // namespace dwa diff --git a/element/tools/dwa/src/dwa.cc b/element/tools/dwa/src/dwa.cc index 2e1a96d0..bd0e64ab 100644 --- a/element/tools/dwa/src/dwa.cc +++ b/element/tools/dwa/src/dwa.cc @@ -9,15 +9,46 @@ #include "common/common_defs.h" #if BMCV_VERSION_MAJOR > 1 -#include "dwa.h" - #include #include + #include "common/logger.h" +#include "dwa.h" #include "element_factory.h" namespace sophon_stream { namespace element { namespace dwa { + +#define YUV_8BIT(y, u, v) \ + ((((y) & 0xff) << 16) | (((u) & 0xff) << 8) | ((v) & 0xff)) + +bm_status_t set_fish_default_param(bmcv_fisheye_attr_s* fisheye_attr) { + fisheye_attr->bEnable = 1; + fisheye_attr->bBgColor = 1; + fisheye_attr->u32BgColor = YUV_8BIT(0, 128, 128); + fisheye_attr->s32HorOffset = 512; + fisheye_attr->s32VerOffset = 512; + fisheye_attr->u32TrapezoidCoef = 0; + fisheye_attr->s32FanStrength = 0; + fisheye_attr->enMountMode = BMCV_FISHEYE_DESKTOP_MOUNT; + fisheye_attr->enUseMode = BMCV_MODE_PANORAMA_360; + fisheye_attr->enViewMode = BMCV_FISHEYE_VIEW_360_PANORAMA; + fisheye_attr->u32RegionNum = 1; + return BM_SUCCESS; +} + +bm_status_t set_gdc_default_param(bmcv_gdc_attr* gdc_attr) { + gdc_attr->bAspect = 0; + gdc_attr->s32XRatio = 0; + gdc_attr->s32YRatio = 0; + gdc_attr->s32XYRatio = 0; + gdc_attr->s32CenterXOffset = 0; + gdc_attr->s32CenterYOffset = 0; + gdc_attr->s32DistortionRatio = 0; + gdc_attr->grid_info = NULL; + return BM_SUCCESS; +} + Dwa::Dwa() {} Dwa::~Dwa() {} @@ -30,9 +61,83 @@ common::ErrorCode Dwa::initInternal(const std::string& json) { auto is_gray = configure.find(CONFIG_INTERNAL_IS_GRAY_FILED)->get(); is_resize = configure.find(CONFIG_INTERNAL_IS_RESIZE_FILED)->get(); - src_fmt = is_gray ? FORMAT_GRAY : FORMAT_YUV420P; + dst_h = configure.find(CONFIG_INTERNAL_DST_H_FILED)->get(); + dst_w = configure.find(CONFIG_INTERNAL_DST_W_FILED)->get(); + auto dwa_mode_str = + configure.find(CONFIG_INTERNAL_DWA_MODE_FILED)->get(); + dwa_mode = dwa_mode_map[dwa_mode_str]; + + auto use_grid = configure.find(CONFIG_INTERNAL_USE_GRIDE_FILED)->get(); + + if (dwa_mode == DWA_GDC_MODE) { // 用于04a10 dpu 2560x1440 需要resize + + if (use_grid) { + grid_name = + configure.find(CONFIG_INTERNAL_GRID_NAME_FILED)->get(); + int grid_size = + configure.find(CONFIG_INTERNAL_GRIDE_SIZE_FILED)->get(); + char* buffer = (char*)malloc(grid_size); + memset(buffer, 0, grid_size); + + FILE* fp = fopen(grid_name.c_str(), "rb"); + + fseek(fp, 0, SEEK_END); + int fileSize = ftell(fp); + + if (grid_size != (unsigned int)fileSize) { + IVS_DEBUG("load grid_info file:{0} size is not match.", + grid_name.c_str()); + fclose(fp); + return common::ErrorCode::UNKNOWN; + } + + rewind(fp); + fread(buffer, grid_size, 1, fp); + fclose(fp); + ldc_attr.grid_info = buffer; + } + + } else if (dwa_mode == + DWA_FISHEYE_MODE) { // 用于04e10 blend 2240x2240 不需要resize + fisheye_attr = {0}; + // set_fish_default_param(&fisheye_attr); + + auto dis_it = configure.find(CONFIG_INTERNAL_DIS_MODE_FILED); + if (dis_it != configure.end()) { + std::string dis_mode_str = dis_it->get(); + STREAM_CHECK(fisheye_mode_map.count(dis_mode_str) != 0, + "Invalid dis_mode in Config File"); + dis_mode = fisheye_mode_map[dis_mode_str]; + } + if (use_grid) { + grid_name = + configure.find(CONFIG_INTERNAL_GRID_NAME_FILED)->get(); + int grid_size = 446496; + char* buffer = (char*)malloc(grid_size); + memset(buffer, 0, grid_size); + + FILE* fp = fopen(grid_name.c_str(), "rb"); + + fseek(fp, 0, SEEK_END); + int fileSize = ftell(fp); + + if (grid_size != (unsigned int)fileSize) { + IVS_DEBUG("load grid_info file:{0} size is not match.", + grid_name.c_str()); + fclose(fp); + return common::ErrorCode::UNKNOWN; + } + + rewind(fp); + fread(buffer, grid_size, 1, fp); + fclose(fp); + fisheye_attr.grid_info = buffer; + fisheye_attr.bEnable = true; + } + } + return common::ErrorCode::SUCCESS; } @@ -51,7 +156,55 @@ float Dwa::get_aspect_scaled_ratio(int src_w, int src_h, int dst_w, int dst_h, return ratio; } -common::ErrorCode Dwa::dwa_work( +common::ErrorCode Dwa::fisheye_work( + std::shared_ptr fisheyeObj) { + if (fisheyeObj != nullptr) { + std::shared_ptr fisheye_image = nullptr; + fisheye_image.reset(new bm_image, [](bm_image* p) { + bm_image_destroy(*p); + delete p; + p = nullptr; + }); + + bm_status_t ret = + bm_image_create(fisheyeObj->mFrame->mHandle, dst_h, dst_w, src_fmt, + DATA_TYPE_EXT_1N_BYTE, fisheye_image.get()); + bm_image_alloc_dev_mem(*fisheye_image, 1); + + bm_image input; + ret = bm_image_create(fisheyeObj->mFrame->mHandle, dst_h, dst_h, src_fmt, + fisheyeObj->mFrame->mSpData->data_type, &input, NULL); + bm_image_alloc_dev_mem(input, 1); + bmcv_rect_t crop_rect{0, 0, + (unsigned int)fisheyeObj->mFrame->mSpData->width, + (unsigned int)fisheyeObj->mFrame->mSpData->height}; + bmcv_padding_atrr_t padding_attr; + memset(&padding_attr, 0, sizeof(padding_attr)); + padding_attr.dst_crop_sty = + int(dst_h - (unsigned int)fisheyeObj->mFrame->mSpData->height) / 2; + padding_attr.dst_crop_stx = + int(dst_w - (unsigned int)fisheyeObj->mFrame->mSpData->width) / 2; + padding_attr.padding_b = 114; + padding_attr.padding_g = 114; + padding_attr.padding_r = 114; + padding_attr.if_memset = 1; + padding_attr.dst_crop_h = (unsigned int)fisheyeObj->mFrame->mSpData->height; + padding_attr.dst_crop_w = (unsigned int)fisheyeObj->mFrame->mSpData->width; + + ret = bmcv_image_vpp_convert_padding(fisheyeObj->mFrame->mHandle, 1, + *fisheyeObj->mFrame->mSpData, &input, + &padding_attr, &crop_rect); + + bmcv_dwa_fisheye(fisheyeObj->mFrame->mHandle, input, *fisheye_image, + fisheye_attr); + + fisheyeObj->mFrame->mSpDataDwa = fisheye_image; // 是否需要dwa + + bm_image_destroy(input); + } +} + +common::ErrorCode Dwa::dwa_gdc_work( std::shared_ptr dwaObj) { if (dwaObj != nullptr) { // resize @@ -144,8 +297,9 @@ common::ErrorCode Dwa::dwa_work( bm_image_alloc_dev_mem_heap_mask(*dwa_image, 4); #endif + // bm_image_write_to_bmp(*resized_img, "resized_img.bmp"); bmcv_dwa_gdc(dwaObj->mFrame->mHandle, *resized_img, *dwa_image, ldc_attr); - + // bm_image_write_to_bmp(*dwa_image, "dwa_image.bmp"); dwaObj->mFrame->mSpData = resized_img; dwaObj->mFrame->mSpDataDwa = dwa_image; @@ -179,11 +333,13 @@ common::ErrorCode Dwa::dwa_work( bmcv_dwa_gdc(dwaObj->mFrame->mHandle, input, *dwa_image, ldc_attr); - dwaObj->mFrame->mSpDataDwa = dwa_image; // 是否需要dwa,效果不好 + dwaObj->mFrame->mSpDataDwa = dwa_image; // dwa bm_image_destroy(input); } } + // bm_image_write_to_bmp(*dwaObj->mFrame->mSpDataDwa, "dwa_image.bmp"); + // bm_image_write_to_bmp(*dwaObj->mFrame->mSpData, "origin_dwa_image.bmp"); return common::ErrorCode::SUCCESS; } @@ -208,7 +364,11 @@ common::ErrorCode Dwa::doWork(int dataPipeId) { if (objectMetadata->mFrame != nullptr && objectMetadata->mFrame->mSpData != nullptr) { - dwa_work(objectMetadata); + if (dwa_mode == DWA_GDC_MODE) { // 用于04a10 dpu 2560x1440 需要resize + dwa_gdc_work(objectMetadata); + } else if (dwa_mode == DWA_FISHEYE_MODE) { + fisheye_work(objectMetadata); + } } // usleep(10); int channel_id_internal = objectMetadata->mFrame->mChannelIdInternal; diff --git a/samples/dwa_blend_encode/config/blend.json b/samples/dwa_blend_encode/config/blend.json index 976e1249..24aa52a1 100644 --- a/samples/dwa_blend_encode/config/blend.json +++ b/samples/dwa_blend_encode/config/blend.json @@ -1,9 +1,9 @@ { "configure": { - "wgt1": "../dwa_blend_encode/data/wgt/c01_alpha_444p_m2__0_1088x224.bin", - "wgt2": "../dwa_blend_encode/data/wgt/c01_beta_444p_m2__0_1088x224.bin", - "ovlp_lx": 1696, - "ovlp_rx": 1919, + "wgt1": "../dwa_blend_encode/data/wgt/c01_alpha_444p_m2__0_2240x128.bin", + "wgt2": "../dwa_blend_encode/data/wgt/c01_beta_444p_m2__0_2240x128.bin", + "ovlp_lx": 2112, + "ovlp_rx": 2239, "bd_lx0": 0, "bd_rx0": 0, "bd_lx1": 0, diff --git a/samples/dwa_blend_encode/config/camera_dwa_blend_encode_demo.json b/samples/dwa_blend_encode/config/camera_dwa_blend_encode_demo.json new file mode 100644 index 00000000..a90988d1 --- /dev/null +++ b/samples/dwa_blend_encode/config/camera_dwa_blend_encode_demo.json @@ -0,0 +1,22 @@ +{ + "channels": [ + { + "channel_id": 2, + "url": "/dev/video0", + "source_type": "CAMERA", + "loop_num": -1, + "fps": -1, + "decode_idx": 0 + }, + { + "channel_id": 3, + "url": "/dev/video1", + "source_type": "CAMERA", + "loop_num": -1, + "fps": -1, + "decode_idx": 1 + } + ], + "download_image": false, + "engine_config_path": "../dwa_blend_encode/config/engine.json" +} diff --git a/samples/dwa_blend_encode/config/dwa.json b/samples/dwa_blend_encode/config/dwa.json deleted file mode 100644 index 3eebe497..00000000 --- a/samples/dwa_blend_encode/config/dwa.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "configure": { - "is_gray":false, - "is_resize":false - }, - "shared_object": "../../build/lib/libdwa.so", - "name": "dwa", - "side": "sophgo", - "thread_number": 1 - } \ No newline at end of file diff --git a/samples/dwa_blend_encode/config/dwa_L.json b/samples/dwa_blend_encode/config/dwa_L.json new file mode 100644 index 00000000..e3a03271 --- /dev/null +++ b/samples/dwa_blend_encode/config/dwa_L.json @@ -0,0 +1,16 @@ +{ + "configure": { + "is_gray": false, + "is_resize": false, + "dst_h": 2240, + "dst_w": 2240, + "dwa_mode": "DWA_FISHEYE_MODE", + "dis_mode": "BMCV_MODE_PANORAMA_360", + "use_grid": true, + "grid_name": "../dwa_blend_encode/data/gridinfo/L_grid_info_68_68_4624_70_70_dst_2240x2240_src_2240x2240.dat" + }, + "shared_object": "../../build/lib/libdwa.so", + "name": "dwa", + "side": "sophgo", + "thread_number": 1 +} \ No newline at end of file diff --git a/samples/dwa_blend_encode/config/dwa_R.json b/samples/dwa_blend_encode/config/dwa_R.json new file mode 100644 index 00000000..abcd35f7 --- /dev/null +++ b/samples/dwa_blend_encode/config/dwa_R.json @@ -0,0 +1,16 @@ +{ + "configure": { + "is_gray": false, + "is_resize": false, + "dst_h": 2240, + "dst_w": 2240, + "dwa_mode": "DWA_FISHEYE_MODE", + "dis_mode": "BMCV_MODE_PANORAMA_360", + "use_grid": true, + "grid_name": "../dwa_blend_encode/data/gridinfo/R_grid_info_68_68_4624_70_70_dst_2240x2240_src_2240x2240.dat" + }, + "shared_object": "../../build/lib/libdwa.so", + "name": "dwa", + "side": "sophgo", + "thread_number": 1 +} \ No newline at end of file diff --git a/samples/dwa_blend_encode/config/engine.json b/samples/dwa_blend_encode/config/engine.json index da18f26a..e984cc84 100644 --- a/samples/dwa_blend_encode/config/engine.json +++ b/samples/dwa_blend_encode/config/engine.json @@ -32,11 +32,11 @@ }, { "element_id": 5002, - "element_config": "../dwa_blend_encode/config/dwa.json" + "element_config": "../dwa_blend_encode/config/dwa_L.json" }, { "element_id": 5003, - "element_config": "../dwa_blend_encode/config/dwa.json" + "element_config": "../dwa_blend_encode/config/dwa_R.json" }, { "element_id": 5004, diff --git a/samples/dwa_blend_encode/config/engine3.json b/samples/dwa_blend_encode/config/engine3.json new file mode 100644 index 00000000..37478471 --- /dev/null +++ b/samples/dwa_blend_encode/config/engine3.json @@ -0,0 +1,43 @@ +[ + { + "graph_id": 0, + "device_id": 0, + "graph_name": "dwa_blend_encode", + "elements": [ + { + "element_id": 5000, + "element_config": "../dwa_blend_encode/config/decode.json", + "ports": { + "input": [ + { + "port_id": 0, + "is_sink": false, + "is_src": true + } + ] + } + }, + { + "element_id": 5005, + "element_config": "../dwa_blend_encode/config/encode.json", + "ports": { + "output": [ + { + "port_id": 0, + "is_sink": true, + "is_src": false + } + ] + } + } + ], + "connections": [ + { + "src_element_id": 5000, + "src_port": 0, + "dst_element_id": 5005, + "dst_port": 0 + } + ] + } +] diff --git a/samples/dwa_blend_encode/scripts/download.sh b/samples/dwa_blend_encode/scripts/download.sh index 47c1db12..293b5280 100755 --- a/samples/dwa_blend_encode/scripts/download.sh +++ b/samples/dwa_blend_encode/scripts/download.sh @@ -30,6 +30,11 @@ then rm -f wgt.zip mv ./wgt ../data/ + python3 -m dfss --url=open@sophgo.com:/sophon-stream/dwa_blend_encode/gridinfo.zip + unzip gridinfo.zip + rm -f gridinfo.zip + mv ./gridinfo ../data/ + else echo "test image exist!" fi diff --git a/samples/dwa_dpu_encode/config/dwa.json b/samples/dwa_dpu_encode/config/dwa.json index 2f4444c8..11f1300d 100644 --- a/samples/dwa_dpu_encode/config/dwa.json +++ b/samples/dwa_dpu_encode/config/dwa.json @@ -1,7 +1,10 @@ { "configure": { "is_gray":true, - "is_resize":true + "is_resize":true, + "dst_h":1080, + "dst_w":1920, + "dwa_mode":"DWA_GDC_MODE" }, "shared_object": "../../build/lib/libdwa.so", "name": "dwa", diff --git a/samples/dwa_dpu_encode/config/dwa_L.json b/samples/dwa_dpu_encode/config/dwa_L.json new file mode 100644 index 00000000..473a366d --- /dev/null +++ b/samples/dwa_dpu_encode/config/dwa_L.json @@ -0,0 +1,16 @@ +{ + "configure": { + "is_gray":true, + "is_resize":true, + "dst_h":1080, + "dst_w":1920, + "dwa_mode":"DWA_GDC_MODE", + "use_grid": true, + "grid_name": "../dwa_dpu_encode/data/gridinfo/fileGridInfoL.dat", + "grid_size":177440 + }, + "shared_object": "../../build/lib/libdwa.so", + "name": "dwa", + "side": "sophgo", + "thread_number": 1 + } \ No newline at end of file diff --git a/samples/dwa_dpu_encode/config/dwa_R.json b/samples/dwa_dpu_encode/config/dwa_R.json new file mode 100644 index 00000000..e635223d --- /dev/null +++ b/samples/dwa_dpu_encode/config/dwa_R.json @@ -0,0 +1,16 @@ +{ + "configure": { + "is_gray":true, + "is_resize":true, + "dst_h":1080, + "dst_w":1920, + "dwa_mode":"DWA_GDC_MODE", + "use_grid": true, + "grid_name": "../dwa_dpu_encode/data/gridinfo/fileGridInfoR.dat", + "grid_size":171760 + }, + "shared_object": "../../build/lib/libdwa.so", + "name": "dwa", + "side": "sophgo", + "thread_number": 1 + } \ No newline at end of file diff --git a/samples/dwa_dpu_encode/config/engine.json b/samples/dwa_dpu_encode/config/engine.json index 15d7f078..ba82aed7 100644 --- a/samples/dwa_dpu_encode/config/engine.json +++ b/samples/dwa_dpu_encode/config/engine.json @@ -32,11 +32,11 @@ }, { "element_id": 5002, - "element_config": "../dwa_dpu_encode/config/dwa.json" + "element_config": "../dwa_dpu_encode/config/dwa_L.json" }, { "element_id": 5003, - "element_config": "../dwa_dpu_encode/config/dwa.json" + "element_config": "../dwa_dpu_encode/config/dwa_R.json" }, { "element_id": 5004, diff --git a/samples/dwa_dpu_encode/config/engine_only_deocde.json b/samples/dwa_dpu_encode/config/engine2.json similarity index 73% rename from samples/dwa_dpu_encode/config/engine_only_deocde.json rename to samples/dwa_dpu_encode/config/engine2.json index 89189f3f..5957f366 100644 --- a/samples/dwa_dpu_encode/config/engine_only_deocde.json +++ b/samples/dwa_dpu_encode/config/engine2.json @@ -18,17 +18,8 @@ } }, { - "element_id": 5001, - "element_config": "../dwa_dpu_encode/config/decode.json", - "ports": { - "input": [ - { - "port_id": 0, - "is_sink": false, - "is_src": true - } - ] - } + "element_id": 5002, + "element_config": "../dwa_dpu_encode/config/dwa_L.json" }, { "element_id": 5005, @@ -48,11 +39,11 @@ { "src_element_id": 5000, "src_port": 0, - "dst_element_id": 5005, + "dst_element_id": 5002, "dst_port": 0 }, { - "src_element_id": 5001, + "src_element_id": 5002, "src_port": 0, "dst_element_id": 5005, "dst_port": 0 diff --git a/samples/dwa_dpu_encode/config/engine3.json b/samples/dwa_dpu_encode/config/engine3.json new file mode 100644 index 00000000..5da696e2 --- /dev/null +++ b/samples/dwa_dpu_encode/config/engine3.json @@ -0,0 +1,43 @@ +[ + { + "graph_id": 0, + "device_id": 0, + "graph_name": "dwa_dpu_encode", + "elements": [ + { + "element_id": 5000, + "element_config": "../dwa_dpu_encode/config/decode.json", + "ports": { + "input": [ + { + "port_id": 0, + "is_sink": false, + "is_src": true + } + ] + } + }, + { + "element_id": 5005, + "element_config": "../dwa_dpu_encode/config/encode.json", + "ports": { + "output": [ + { + "port_id": 0, + "is_sink": true, + "is_src": false + } + ] + } + } + ], + "connections": [ + { + "src_element_id": 5000, + "src_port": 0, + "dst_element_id": 5005, + "dst_port": 0 + } + ] + } +] diff --git a/samples/dwa_dpu_encode/scripts/download.sh b/samples/dwa_dpu_encode/scripts/download.sh index a9c1f9b1..c4d9344f 100755 --- a/samples/dwa_dpu_encode/scripts/download.sh +++ b/samples/dwa_dpu_encode/scripts/download.sh @@ -30,6 +30,11 @@ then rm -f videos.zip mv ./videos ../data/ + python3 -m dfss --url=open@sophgo.com:/sophon-stream/dwa_dpu_encode/gridinfo.zip + unzip gridinfo.zip + rm -f gridinfo.zip + mv ./gridinfo ../data/ + python3 -m dfss --url=open@sophgo.com:/sophon-stream/dwa_dpu_encode/maps.zip unzip maps.zip rm -f maps.zip diff --git a/samples/dwa_dpu_encode/web/ui/src/components/VideoDisplayBlend/VideoDisplay.js b/samples/dwa_dpu_encode/web/ui/src/components/VideoDisplayBlend/VideoDisplay.js index 019fdf85..9146a864 100644 --- a/samples/dwa_dpu_encode/web/ui/src/components/VideoDisplayBlend/VideoDisplay.js +++ b/samples/dwa_dpu_encode/web/ui/src/components/VideoDisplayBlend/VideoDisplay.js @@ -119,9 +119,8 @@ const VideoDisplayBlend = () => {