hi this is function of my custom plugin based on dsexample
static GstFlowReturn
gst_menudraw_prepare_output_buffer(GstBaseTransform * btrans, GstBuffer * inbuf, GstBuffer ** outbuf)
{
GstMenuDraw *menudraw = GST_MENUDRAW (btrans);
GstFlowReturn flow_ret = GST_FLOW_ERROR;
GstMapInfo out_map_info;
DrawParam DrawParam;
NvBufSurface *outsurface = NULL;
NvBufSurfaceCreateParams create_params;
NvDsBatchMeta *batch_meta = NULL;
NvDsFrameMeta *frame_meta = NULL;
NvDsMeta *meta = NULL;//g_print (âPrepare start\nâ);
//*outbuf = inbuf;
//return GST_FLOW_OK;if (menudraw->inter_buf)
NvBufSurfaceDestroy (menudraw->inter_buf);
menudraw->inter_buf = NULL;/* An intermediate buffer for NV12/RGBA to BGR conversion will be
- required. Can be skipped if custom algorithm can work directly on NV12/RGBA. */
create_params.gpuId = menudraw->gpu_id;
create_params.width = menudraw->processing_width;
create_params.height = menudraw->processing_height;
create_params.size = 0;
create_params.colorFormat = NVBUF_COLOR_FORMAT_RGBA;
create_params.layout = NVBUF_LAYOUT_PITCH;
ifdef aarch64
create_params.memType = NVBUF_MEM_DEFAULT;
//g_print(âset surface memtype nvbuf_mem_dafault\nâ);
else
create_params.memType = NVBUF_MEM_CUDA_UNIFIED;
endif
//Make GST Buffer
if (NvBufSurfaceCreate (&(menudraw->inter_buf), 1,
&create_params) != 0) {
GST_ERROR (âError: Could not allocate internal buffer for menudrawâ);
goto error;
}
menudraw->inter_buf->numFilled = 1;*outbuf = NULL;
*outbuf = gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_ZERO_PREFIXED, menudraw->inter_buf, sizeof(NvBufSurface), 0, sizeof(NvBufSurface), NULL, NULL);
//g_print(âm1\nâ);
batch_meta = nvds_create_batch_meta(1);
//g_print(âm2\nâ);
meta = gst_buffer_add_nvds_meta (*outbuf , batch_meta, NULL, copy_user_meta, release_user_meta);
//g_print(âm3\nâ);
meta->meta_type = NVDS_BATCH_GST_META;
batch_meta->base_meta.batch_meta = batch_meta;
batch_meta->base_meta.copy_func = copy_user_meta;
batch_meta->base_meta.release_func = release_user_meta;
batch_meta->max_frames_in_batch = 1;
frame_meta = nvds_acquire_frame_meta_from_pool(batch_meta);
//g_print(âm4\nâ);
nvds_add_frame_meta_to_batch(batch_meta, frame_meta);
//g_print(âm5\nâ);
// Some important parameters to fill
frame_meta->pad_index = 0;
frame_meta->source_id = 0;
frame_meta->buf_pts = 0;
frame_meta->ntp_timestamp = 0;
frame_meta->frame_num = 0;
frame_meta->batch_id = 0;
frame_meta->source_frame_width = 1024;
frame_meta->source_frame_height = 600;
frame_meta->num_surfaces_per_frame = 1 ;CHECK_CUDA_STATUS (cudaSetDevice (menudraw->gpu_id),
âUnable to set cuda deviceâ);memset (&out_map_info, 0, sizeof (out_map_info));
if (!gst_buffer_map (*outbuf, &out_map_info, GST_MAP_READWRITE)) {
g_print (âError: Failed to out map gst buffer\nâ);
goto error;
}
outsurface = (NvBufSurface *) out_map_info.data;
GST_DEBUG_OBJECT (menudraw,âProcessing Frame Surface %p\nâ,outsurface);
if (CHECK_NVDS_MEMORY_AND_GPUID (menudraw, outsurface))
{
g_print (âError: Check NVDS Memory And Gpu id\nâ);
goto error;
}
//NvBufSurfaceMemSet(outsurface, 0, 0, 0);/*g_print(âdebug surface batchsize %u\nâ, outsurface->batchSize);
g_print(âdebug surface numfilled %u\nâ, outsurface->numFilled);
g_print(âdebug surface gpuid %u\nâ, outsurface->gpuId);g_print(âdebug surface0 num planes %u\nâ, outsurface->surfaceList[0].planeParams.num_planes);
g_print(âdebug surface0 width %u\nâ, outsurface->surfaceList[0].planeParams.width[0]);
g_print(âdebug surface0 height %u\nâ, outsurface->surfaceList[0].planeParams.height[0]);
g_print(âdebug surface0 pitch %u\nâ, outsurface->surfaceList[0].planeParams.pitch[0]);
g_print(âdebug surface0 offset %u\nâ, outsurface->surfaceList[0].planeParams.offset[0]);
g_print(âdebug surface0 psize %u\nâ, outsurface->surfaceList[0].planeParams.psize[0]);
g_print(âdebug surface0 mapaddr %u\nâ, outsurface->surfaceList[0].mappedAddr.addr[0]);g_print(âdebug surface0 bytesPerPix %u\nâ, outsurface->surfaceList[0].planeParams.bytesPerPix[0]); */
if (NvBufSurfaceMap (outsurface, 0, 0, NVBUF_MAP_READ_WRITE) != 0){
g_print(âDraw surface map Error\nâ);
return GST_FLOW_ERROR;
}
NvBufSurfaceSyncForCpu (outsurface, 0,0);//DrawParam = Process_Draw_Update_Func[menudraw->page_num](menudraw, inbuf);
//Process_Draw_Menu(outsurface, &DrawParam );
NvBufSurfaceSyncForDevice (outsurface, 0,0);
if (NvBufSurfaceUnMap (outsurface, 0,0)){
g_print(âDraw surface unmap Error\nâ);
goto error;
}//g_print (âPrepare OK\nâ);
flow_ret = GST_FLOW_OK;
error:
gst_buffer_unmap (*outbuf, &out_map_info);return flow_ret;
}
this seems to be throw some memory leak but i donât know why & where occur memory leak
can you help me ??
gstmenudraw.cpp (81.6 KB)
here is my source
I posted a similar question before, but the thread didnât work, so I wrote it again.
information
input source : 30fps
memory leak
total used free shared buff/cache available
Mem: 4058400 1636060 1078028 28668 1344312 2431384
Swap: 2029184 0 2029184total used free shared buff/cache available
Mem: 4058400 1637608 1076480 28668 1344312 2437772
Swap: 2029184 0 2029184total used free shared buff/cache available
Mem: 4058400 1638384 1075704 28668 1344312 2439428
Swap: 2029184 0 2029184total used free shared buff/cache available
Mem: 4058400 1639756 1074328 28668 1344316 2427688
Swap: 2029184 0 2029184total used free shared buff/cache available
Mem: 4058400 1640936 1073148 28668 1344316 2426508
Swap: 2029184 0 2029184total used free shared buff/cache available
Mem: 4058400 1641756 1072328 28668 1344316 2428120
Swap: 2029184 0 2029184total used free shared buff/cache available
Mem: 4058400 1642248 1071832 28668 1344320 2427624
Swap: 2029184 0 2029184total used free shared buff/cache available
Mem: 4058400 1642032 1072048 28668 1344320 2427840
Swap: 2029184 0 2029184total used free shared buff/cache available
Mem: 4058400 1642368 1071708 28668 1344324 2427504
Swap: 2029184 0 2029184