I'm assuming you're using PulseAudio 1.0 or above. For both the player and recorder streams, you need to set the "filter.want" property to "echo-cancel". We don't expose a way to do this using the simple API, so you will need to take a the slightly uglier route of setting the PULSE_PROP environment variable like this before you create the stream would do the trick:
setenv("PULSE_PROP", "filter.want=echo-cancel", 1);
p.s.: For really high quality echo cancelling, you want PulseAudio 2.0 or above, with the webrtc-audio-processing support built -- how easy it is to get this depends on whether your distribution already has this packaged up or not.