Skip to content

Commit

Permalink
add dwa gridinfo
Browse files Browse the repository at this point in the history
Change-Id: I47b86208a9dd9e658f38f5fdcc2d7bb357381771
  • Loading branch information
zhiyuan.zhang authored and yizhou-xu committed Jan 16, 2024
1 parent 7dc7f16 commit 186e544
Show file tree
Hide file tree
Showing 26 changed files with 504 additions and 136 deletions.
2 changes: 1 addition & 1 deletion element/multimedia/decode/src/ff_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion element/tools/blend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions element/tools/blend/include/blend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
149 changes: 71 additions & 78 deletions element/tools/blend/src/blend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::int>();
auto wgt1 = configure.find(CONFIG_INTERNAL_WGT1_FILED)->get<std::string>();
auto wgt2 = configure.find(CONFIG_INTERNAL_WGT2_FILED)->get<std::string>();
Expand Down Expand Up @@ -152,121 +152,113 @@ common::ErrorCode Blend::blend_work(
std::shared_ptr<common::ObjectMetadata> blendObj) {
std::lock_guard<std::mutex> lk(mtx);
IVS_INFO("Now DisplayType is {0}", dis_type);
std::shared_ptr<bm_image> 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<bm_image> blend_image_left = nullptr;
std::shared_ptr<bm_image> 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 {
blend_image_left = leftObj->mFrame->mSpData;
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<bm_image> all_image = nullptr;
all_image.reset(new bm_image, [](bm_image* p) {
if (dis_type == ONLY_RAW_DIS) {
std::shared_ptr<bm_image> 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,
.start_y = 0,
.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<bm_image> 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;
}
Expand Down Expand Up @@ -303,9 +295,10 @@ common::ErrorCode Blend::doWork(int dataPipeId) {
std::make_shared<common::ObjectMetadata>();

blendObj->mFrame = std::make_shared<sophon_stream::common::Frame>();

// 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()
Expand Down
2 changes: 1 addition & 1 deletion element/tools/dpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion element/tools/dpu/include/dpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions element/tools/dpu/src/dpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -665,8 +669,10 @@ common::ErrorCode Dpu::doWork(int dataPipeId) {
std::shared_ptr<common::ObjectMetadata> dpuObj =
std::make_shared<common::ObjectMetadata>();
dpuObj->mFrame = std::make_shared<sophon_stream::common::Frame>();
// 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;
Expand Down
2 changes: 1 addition & 1 deletion element/tools/dwa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 186e544

Please sign in to comment.