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

Thank you.
I read the code you mentioned in page " Deepstream sample code snippet - Intelligent Video Analytics / DeepStream SDK - NVIDIA Developer Forums", and changed my code. It doesn’t work out. The function NvBufSurfaceSyncForDevice still returns -1 however.
I find that the surface of your demo code was NVBUF_MAP_READ. Is this need to be writable?

  •  NvBufSurfaceMap (surface, -1, -1, NVBUF_MAP_READ);
    

Is there anything else need to be changed ?