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

Deepstream sample code snippet - Intelligent Video Analytics / DeepStream SDK - NVIDIA Developer Forums is the only sample available.