Please provide complete information as applicable to your setup.
• Hardware Platform (Jetson / GPU) Jetson AGX Xavier
• DeepStream Version 5.1
• JetPack Version (valid for Jetson only) 4.5.1
• TensorRT Version 7.1.3
Hello! I am trying to make a batch from 1 input buffer by cropping certain areas. I modified gstexample and my transform_ip looks like:
static GstFlowReturn
gst_batcher_transform_ip (GstBaseTransform * btrans, GstBuffer * inbuf)
{
GstBatcher *batcher = GST_BATCHER (btrans);
GstMapInfo in_map_info;
GstFlowReturn flow_ret = GST_FLOW_ERROR;
gdouble scale_ratio = 1.0;
BatcherOutput *output;
NvBufSurface *surface = NULL;
guint i = 0;
batcher->frame_num++;
CHECK_CUDA_STATUS (cudaSetDevice (batcher->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;
}
nvds_set_input_system_timestamp (inbuf, GST_ELEMENT_NAME (batcher));
surface = (NvBufSurface *) in_map_info.data;
GST_DEBUG_OBJECT (batcher,
"Processing Frame %" G_GUINT64_FORMAT " Surface %p\n",
batcher->frame_num, surface);
if (surface->batchSize != 1) {
GST_ELEMENT_ERROR (batcher, STREAM, FAILED,
("Batch size should be 1"), (NULL));
return GST_FLOW_ERROR;
}
if (CHECK_NVDS_MEMORY_AND_GPUID (batcher, surface))
goto error;
/* Fill the batch transform parameters. */
while (batcher->batch_insurf.numFilled < 4) {
//Memset the memory
NvBufSurfaceMemSet (batcher->inter_buf, batcher->batch_insurf.numFilled, 0, 0);
/* Create temporary src and dest surfaces for NvBufSurfTransform API. */
batcher->batch_insurf.surfaceList[batcher->batch_insurf.numFilled] = *surface->surfaceList;
/* Set the source ROI. Could be entire frame or an object. */
batcher->transform_params.src_rect[batcher->batch_insurf.numFilled] = {
(guint) batcher->rect_params[batcher->batch_insurf.numFilled]->top,
(guint) batcher->rect_params[batcher->batch_insurf.numFilled]->left,
(guint) batcher->rect_params[batcher->batch_insurf.numFilled]->width,
(guint) batcher->rect_params[batcher->batch_insurf.numFilled]->height,
};
/* Set the dest ROI. Could be the entire destination frame or part of it to
* maintain aspect ratio. */
batcher->transform_params.dst_rect[batcher->batch_insurf.numFilled] = {0, 0, 300, 300};
batcher->batch_insurf.numFilled++;
}
NvBufSurfTransform_Error err;
NvBufSurfTransformConfigParams transform_config_params;
// Configure transform session parameters for the transformation
transform_config_params.compute_mode = NvBufSurfTransformCompute_Default;
transform_config_params.gpu_id = batcher->gpu_id;
transform_config_params.cuda_stream = batcher->cuda_stream;
err = NvBufSurfTransformSetSessionParams (&transform_config_params);
if (err != NvBufSurfTransformError_Success) {
GST_ELEMENT_ERROR (batcher, STREAM, FAILED,
("NvBufSurfTransformSetSessionParams failed with error %d", err),
(NULL));
return GST_FLOW_ERROR;
}
/* Batched tranformation. */
err = NvBufSurfTransform (&batcher->batch_insurf, batcher->inter_buf,
&batcher->transform_params);
if (err != NvBufSurfTransformError_Success) {
GST_ELEMENT_ERROR (batcher, STREAM, FAILED,
("NvBufSurfTransform failed with error %d while converting buffer",
err), (NULL));
return GST_FLOW_ERROR;
}
// TODO: copy the inter_buf content to inbuf and fill the metadata here.
batcher->batch_insurf.numFilled = 0;
return GST_FLOW_OK;
error:
nvds_set_output_system_timestamp (inbuf, GST_ELEMENT_NAME (batcher));
gst_buffer_unmap (inbuf, &in_map_info);
return flow_ret;
}
Now I think I have to copy the inter_buf content to inbuf and fill the batch metadata but I am not sure how to do it. Can you please help?