Custom tiler plugin, how to copy object meta

Please provide complete information as applicable to your setup.

• Hardware Platform Jetson Xavier AGX
• DeepStream Version 5.1
• JetPack Version 4.5.1
• TensorRT Version 7.1.3

Hello! I am trying to make a plugin which is similar to tiler but with crops. It works well with just sink but when I add nvdsosd, its giving error:

nvbufsurface: error in mapping
libnvosd (93):(ERROR) : Buffer mapping failed 
ERROR from element nvdsosd0: Unable to draw rectangles
I copy the original object meta as following:
  batch_meta_out = nvds_create_batch_meta(1);    	
  if (batch_meta_out == NULL) {
    GST_ERROR ("Error: Could not create batch meta");
    goto error;
  }
  batch_meta_out->base_meta.batch_meta = batch_meta_out;
  batch_meta_out->base_meta.copy_func = nvds_batch_meta_copy_func;
  batch_meta_out->base_meta.release_func = nvds_batch_meta_release_func;
  batch_meta_out->max_frames_in_batch = 1;
  frame_meta_out = nvds_acquire_frame_meta_from_pool(batch_meta_out);

  for (l_frame = batch_meta->frame_meta_list; l_frame != NULL;
          l_frame = l_frame->next) {
    NvDsFrameMeta *frame_meta = (NvDsFrameMeta *) (l_frame->data);
    for (l_obj = frame_meta->obj_meta_list; l_obj != NULL; l_obj = l_obj->next) {
      obj_meta = (NvDsObjectMeta *) (l_obj->data);
      obj_meta_out = nvds_acquire_obj_meta_from_pool(batch_meta_out);
      obj_meta_out->unique_component_id = obj_meta->unique_component_id;
      obj_meta_out->class_id = obj_meta->class_id;
      obj_meta_out->confidence = obj_meta->confidence;
      obj_meta_out->parent = NULL;
      g_strlcpy(obj_meta_out->obj_label, obj_meta->obj_label, MAX_LABEL_SIZE);
      obj_meta_out->rect_params.top = obj_meta->rect_params.top;
      obj_meta_out->rect_params.left = obj_meta->rect_params.left + offset;
      obj_meta_out->rect_params.width = obj_meta->rect_params.width;
      obj_meta_out->rect_params.height = obj_meta->rect_params.height;
      //g_print("%f %f %f %f\n", obj_meta_out->rect_params.top,
      //    obj_meta_out->rect_params.left,
      //    obj_meta_out->rect_params.width,
      //    obj_meta_out->rect_params.height);
      nvds_add_obj_meta_to_frame(frame_meta_out, obj_meta_out, NULL);
    }
    offset += 1000;
  }
  nvds_add_frame_meta_to_batch(batch_meta_out, frame_meta_out);

Any idea what I am missing here?

If you are doing the same thing with nvmultistreamtiler, your new output meta should only have one frame in the batch.

Yes, I add frame meta only once.

This error means the NvBufSurface has some problem.

Without nvdsosd, nv3dsink visualizes the output well. So I was guessing it was because my copied object meta was incomplete.

nv3dsink is not deepstream plugin. The video can be displayed with nv3dsink does not mean it can be accepted by deepstream plugins. DeepStream SDK FAQ - Intelligent Video Analytics / DeepStream SDK - NVIDIA Developer Forums

When there is no detected object, it runs without issue even with nvdsosd. So I think I am not constructing the object meta well. Is there any reference how nvinfer fills the object meta?

nvbufsurface: error in mapping
libnvosd (93):(ERROR) : Buffer mapping failed 
0:00:03.442893719  6684   0x558aa962d0 WARN                 nvinfer gstnvinfer.cpp:1984:gst_nvinfer_output_loop:<nvinfer0> error: Internal data stream error.
ERROR from element nvdsosd0: Unable to draw rectangles
Error details: /dvs/git/dirty/git-master_linux/deepstream/sdk/src/gst-plugins/gst-nvdsosd/gstnvdsosd.c(498): gst_nvds_osd_transform_ip (): /GstPipeline:object-tracker-pipeline/GstNvDsOsd:nvdsosd0
0:00:03.443055711  6684   0x558aa962d0 WARN                 nvinfer gstnvinfer.cpp:1984:gst_nvinfer_output_loop:<nvinfer0> error: streaming stopped, reason error (-5)
libnvosd (389):(ERROR) : Error in nvll_osd_draw_rectangles_gpuReturned, stopping playback
Segmentation fault (core dumped)

When there is no object, nvosd will do nothing or never touch NvBufSurface.