In gstdsexample.cpp, i have added below code
static gpointer meta_copy_func (gpointer data, gpointer user_data)
{
NvDsUserMeta *user_meta = (NvDsUserMeta *) data;
NvDsEventMsgMeta *srcMeta = (NvDsEventMsgMeta *) user_meta->user_meta_data;
NvDsEventMsgMeta *dstMeta = (NvDsEventMsgMeta *) g_malloc (sizeof (NvDsEventMsgMeta));
//dstMeta = g_memdup (srcMeta, sizeof (NvDsEventMsgMeta));
if (srcMeta->frame_image){
dstMeta->frame_image = g_strdup (srcMeta->frame_image); }
return dstMeta;
}
static void meta_free_func (gpointer data, gpointer user_data)
{
NvDsUserMeta *user_meta = (NvDsUserMeta *) data;
NvDsEventMsgMeta *srcMeta = (NvDsEventMsgMeta *) user_meta->user_meta_data;
user_meta->user_meta_data = NULL;
if (srcMeta->frame_image) {
g_free (srcMeta->frame_image);
}
delete srcMeta;
}
static GstFlowReturn
gst_dsexample_transform_ip (GstBaseTransform * btrans, GstBuffer * inbuf)
{
GstDsExample *dsexample = GST_DSEXAMPLE (btrans);
GstMapInfo in_map_info;
GstFlowReturn flow_ret = GST_FLOW_ERROR;
gdouble scale_ratio = 1.0;
// DsExampleOutput *output;
NvBufSurface *surface = NULL;
NvDsBatchMeta *batch_meta = NULL;
NvDsFrameMeta *frame_meta = NULL;
NvDsMetaList * l_frame = NULL;
guint i = 0;
NvDsUserMeta *user_meta = NULL;
NvDsMetaType user_meta_type = NVDS_USER_FRAME_META_EXAMPLE;
dsexample->frame_num++;
CHECK_CUDA_STATUS (cudaSetDevice (dsexample->gpu_id),
"Unable to set cuda device");
memset (&in_map_info, 0, sizeof (in_map_info));
if (!gst_buffer_map (inbuf, &in_map_info, GST_MAP_READ)) {
g_print ("Error: Failed to map gst buffer\n");
goto error;
}
surface = (NvBufSurface *) in_map_info.data;
GST_DEBUG_OBJECT (dsexample,
"Processing Frame %" G_GUINT64_FORMAT " Surface %p\n",
dsexample->frame_num, surface);
if (CHECK_NVDS_MEMORY_AND_GPUID (dsexample, surface))
goto error;
batch_meta = gst_buffer_get_nvds_batch_meta (inbuf);
if (batch_meta == nullptr) {
GST_ELEMENT_ERROR (dsexample, STREAM, FAILED,
("NvDsBatchMeta not found for input buffer."), (NULL));
return GST_FLOW_ERROR;
}
if (dsexample->process_full_frame) {
NvDsMetaList * l_obj = NULL;
NvDsObjectMeta *obj_meta = NULL;
for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
l_frame = l_frame->next)
{
frame_meta = (NvDsFrameMeta *) (l_frame->data);
NvOSD_RectParams rect_params;
/* Scale the entire frame to processing resolution */
rect_params.left = 0;
rect_params.top = 0;
rect_params.width = dsexample->video_info.width;
rect_params.height = dsexample->video_info.height;
/* Scale and convert the frame */
if (get_converted_mat (dsexample, surface, i, &rect_params,
scale_ratio, dsexample->video_info.width,
dsexample->video_info.height, frame_meta, batch_meta, user_meta, user_meta_type) != GST_FLOW_OK) {
goto error;
}
for (l_obj = frame_meta->obj_meta_list; l_obj != NULL;
l_obj = l_obj->next)
{
obj_meta = (NvDsObjectMeta *) (l_obj->data);
/** Generate NvDsEventMsgMeta for every object */
NvDsEventMsgMeta *msg_meta =
(NvDsEventMsgMeta *) g_malloc0 (sizeof (NvDsEventMsgMeta));
char *fileNameString = new char [128];
snprintf (fileNameString, 128, "d.jpg");
msg_meta->frame_image = (gchar *) g_malloc0 (128);
strncpy (msg_meta->frame_image, fileNameString, 128);
NvDsUserMeta *user_event_meta =
nvds_acquire_user_meta_from_pool (batch_meta);
if (user_event_meta) {
/*
* Since generated event metadata has custom objects for
* Vehicle / Person which are allocated dynamically, we are
* setting copy and free function to handle those fields when
* metadata copy happens between two components.
*/
user_event_meta->user_meta_data = (void *) msg_meta;
user_event_meta->base_meta.batch_meta = batch_meta;
user_event_meta->base_meta.meta_type = NVDS_EVENT_MSG_META;
user_event_meta->base_meta.copy_func = (NvDsMetaCopyFunc) meta_copy_func;
user_event_meta->base_meta.release_func = (NvDsMetaReleaseFunc) meta_free_func;
nvds_add_user_meta_to_frame (frame_meta, user_event_meta);
} else {
g_print ("Error in attaching event meta to buffer\n");
}
}
}
}
flow_ret = GST_FLOW_OK;
error:
gst_buffer_unmap (inbuf, &in_map_info);
return flow_ret;
}
In nvdsmeta_schema.h,
typedef struct NvDsEventMsgMeta {
gchar *frame_image;
.......
.......
.......
}
I am not able to fetch frame_image from nvmsgconv.cpp
if (events[0].metadata->frame_image){
json_object_set_string_member (rootObj, "frame_image", events[0].metadata->frame_image);
cout << "\n frame_image --> "<< events[0].metadata->frame_image ;
}
else{
cout << "\n#frame_image \n " ;
json_object_set_string_member (rootObj, "frame_image", "");}