thanks, it works now kinda
but if i run it in a loop, the memory wont refresh and i have always the same decoded image
do i have to more than the following to clean up my memory?
i call the code below in a loop @DaneLLL
in_buf = nullptr;
in_buf = new unsigned char[in_buf_size];
std:memcpy(in_buf, msg->data.data(), in_buf_size);
status = jpegdec->decodeToFd(fd, in_buf, in_buf_size, pixfmt, width, height);
if(status){
RCLCPP_ERROR(rclcpp::get_logger("ImageResize"), "Failed to decode");
}
delete[] in_buf;
dstCompRect[0].top = 0;
dstCompRect[0].left = 0;
dstCompRect[0].width = width;
dstCompRect[0].height = height;
input_params = {0};
input_params.width = width;
input_params.height = height;
input_params.colorFormat = NVBUF_COLOR_FORMAT_RGBA;
input_params.layout = NVBUF_LAYOUT_PITCH;
input_params.memType = NVBUF_MEM_SURFACE_ARRAY;
m_compositedFrame = 0;
if (NvBufSurf::NvAllocate(&input_params, 1, &m_compositedFrame) != 0) {
RCLCPP_ERROR(rclcpp::get_logger("ImageResize"), "Failed to allocate composite buffer");
}
if (NvBufSurfaceFromFd(m_compositedFrame, reinterpret_cast<void**>(&pdstSurf)) != 0) {
RCLCPP_ERROR(rclcpp::get_logger("ImageResize"), "Failed to map buffer to NvBufSurface");
}
memset(&m_compositeParam, 0, sizeof(m_compositeParam)); // set all element to zero
m_compositeParam.params.composite_blend_flag = NVBUFSURF_TRANSFORM_COMPOSITE;
m_compositeParam.params.input_buf_count = 1;
m_compositeParam.params.composite_blend_filter = NvBufSurfTransformInter_Algo3;
m_compositeParam.dst_comp_rect = static_cast<NvBufSurfTransformRect*>
(malloc(sizeof(NvBufSurfTransformRect) * 1));
m_compositeParam.src_comp_rect = static_cast<NvBufSurfTransformRect*>
(malloc(sizeof(NvBufSurfTransformRect)
* m_compositeParam.params.input_buf_count));
memcpy(m_compositeParam.dst_comp_rect, &dstCompRect[0],
sizeof(NvBufSurfTransformRect) * 1);
m_compositeParam.src_comp_rect[0].top = 0;
m_compositeParam.src_comp_rect[0].left = 0;
m_compositeParam.src_comp_rect[0].width = width;
m_compositeParam.src_comp_rect[0].height = height;
batch_surf = 0;
batch_surf = new NvBufSurface*[1];
//batch_surf[0] = NULL;
m_dmabufs[0] = 0;
memset(m_dmabufs, 0, sizeof(m_dmabufs));
if(NvBufSurfaceFromFd(fd,(void**)(&batch_surf[0])) != 0){
RCLCPP_ERROR(rclcpp::get_logger("ImageResize"), "Failed");
}
if(NvBufSurfTransformMultiInputBufCompositeBlend(batch_surf, pdstSurf, &m_compositeParam) !=0)
{
RCLCPP_ERROR(rclcpp::get_logger("ImageResize"), "Failed Transform");
}
NvBufSurfaceMap(pdstSurf, -1, 0, NVBUF_MAP_READ);
NvBufSurfaceSyncForCpu(pdstSurf, -1, 0);
cv::Mat image(height, width, CV_8UC4, pdstSurf->surfaceList[0].mappedAddr.addr[0], pdstSurf->surfaceList[0].pitch);
NvBufSurfaceSyncForCpu(pdstSurf, -1, 0);
NvBufSurfaceSyncForDevice(pdstSurf, -1, 0);
if(NvBufSurfaceUnMap(pdstSurf, -1, 0) != 0)
{
RCLCPP_ERROR(rclcpp::get_logger("ImageResize"), "Failed to Unmpa");
}
NvBufSurfaceDestroy(pdstSurf);
delete[] m_compositeParam.dst_comp_rect;
delete[] m_compositeParam.src_comp_rect;
m_compositedFrame = 0;