NvBufSurfaceSyncForDevice return -1 and how to replace frame in pipeline?

The dsexample plugin works in ‘in-place’ mode(GstBaseTransform). The input buffer caps should be exactly the same to the output buffer caps. You can not use a different format buffer(data) to replace the original buffer (data).
We have a sample of replace the buffer with the same format.
Deepstream sample code snippet - Intelligent Video Analytics / DeepStream SDK - NVIDIA Developer Forums