static GstPadProbeReturn
test_pad_buffer_probe (GstPad * pad, GstPadProbeInfo * info, gpointer u_data)
{
GstBuffer *buf = (GstBuffer *) info->data;
GstMapInfo in_map_info;
memset (&in_map_info, 0, sizeof (in_map_info));
if (gst_buffer_map (buf, &in_map_info, GST_MAP_READWRITE))
{
gint idx = 0;
NvBufSurface *surface = NULL;
NvBufSurface surface_idx;
NvBufSurfTransformRect src_rect, dst_rect;
surface = (NvBufSurface *) in_map_info.data;
surface_idx = *surface;
surface_idx.surfaceList = &(surface->surfaceList[idx]);
surface_idx.numFilled = surface->batchSize = 1;
int batch_size = surface->batchSize;
src_rect.top = 0;
src_rect.left = 0;
src_rect.width = (guint) surface->surfaceList[idx].width;
src_rect.height= (guint) surface->surfaceList[idx].height;
dst_rect.top = 0;
dst_rect.left = 0;
dst_rect.width = (guint) surface->surfaceList[idx].width;
dst_rect.height= (guint) surface->surfaceList[idx].height;
NvBufSurfTransformParams nvbufsurface_params;
nvbufsurface_params.src_rect = &src_rect;
nvbufsurface_params.dst_rect = &dst_rect;
nvbufsurface_params.transform_flag = NVBUFSURF_TRANSFORM_CROP_SRC | NVBUFSURF_TRANSFORM_CROP_DST;
nvbufsurface_params.transform_filter = NvBufSurfTransformInter_Default;
NvBufSurfaceCreateParams nvbufsurface_create_params;
nvbufsurface_create_params.gpuId = surface->gpuId;
nvbufsurface_create_params.width = (guint) surface->surfaceList[idx].width;
nvbufsurface_create_params.height = (guint) surface->surfaceList[idx].height;
nvbufsurface_create_params.size = 0;
nvbufsurface_create_params.colorFormat = NVBUF_COLOR_FORMAT_RGBA;
nvbufsurface_create_params.layout = NVBUF_LAYOUT_PITCH;
#ifdef PLATFORM_TEGRA
nvbufsurface_create_params.memType = NVBUF_MEM_DEFAULT;
#else
nvbufsurface_create_params.memType = NVBUF_MEM_CUDA_UNIFIED;
#endif
if (NvBufSurfaceCreate(&surface, batch_size, &nvbufsurface_create_params) != 0){
g_print ("NvBufSurfaceCreate failed\n");
return GST_PAD_PROBE_DROP;
}
NvBufSurfaceMemSet (surface, 0, 0, 0);
if (NvBufSurfTransform (&surface_idx, surface, &nvbufsurface_params) != NvBufSurfTransformError_Success) {
g_print ("NvBufSurfTransform failed with error while converting buffer\n");
return GST_PAD_PROBE_DROP;
}
NvBufSurfaceMap (surface, 0, 0, NVBUF_MAP_READ);
NvBufSurfaceSyncForCpu (surface, 0, 0);
cv::Mat bgr_frame = cv::Mat( cv::Size((guint) surface->surfaceList[idx].width,
(guint) surface->surfaceList[idx].height), CV_8UC3 );
cv::Mat in_mat = cv::Mat( (guint) surface->surfaceList[idx].height,
(guint) surface->surfaceList[idx].width,
CV_8UC4,
surface->surfaceList[idx].mappedAddr.addr[0],
surface->surfaceList[idx].pitch );
cv::circle(in_mat, cv::Point(100,200), 30, cv::Scalar(255,0,255), 2.0);
cv::cvtColor (in_mat, bgr_frame, cv::COLOR_RGBA2BGR);
cv::imwrite("test_1111.jpg", bgr_frame);
NvBufSurfaceUnMap(surface, 0 , 0);
NvBufSurfaceSyncForDevice (surface, 0, 0);
}
return GST_PAD_PROBE_OK;
}
Hi, this is my function that i modified. It can solve above problem. However, my target change data in in_mat that can show by sink. when I remove from “NvBufSurface surface_idx” to “return GST_PAD_PROBE_DROP;
}” line it can change in_mat and show change on sink, but otherwise it dont change anything.
How can i do it ?
thanks