Unlinking elements -> "Pipeline manipulation" example not true?

Hello, I am creating a dynamic pipeline, and need to unlink an element in the middle of the pipeline.

Following the “pipeline manipulation” example and adapting it to my program I am facing 2 issues

  1. The example suggests using a blocking probe to wait for EOS before stopping and unlinking an element. But since it returns GST_PAD_PROBE_OK instead of GST_PAD_PROBE_PASS in case of events that are not EOS, the pipeline is never unblocked if the first event is not EOS. Should i use GST_PAD_PROBE_DROP instead?

  2. Trying to stop and unlink elements from inside the probe as in the example produces the following error

You cannot change the state of an element from its streaming thread. Use g_idle_add() or post a GstMessage on the bus to schedule the state change from the main thread

I am not sure if the example is not updated yet but according to it that should work? I was hoping to do this synchronously and not add various glib source. Thank you.

Is there anyone else perhaps that does probe-based linking and unlinking?