Use GStreamer bus watch or futures stream for collecting messages instead of polling
Currently you poll for pending messages every 250ms, that's not really needed. The bus watch allows you to automatically get a callback whenever a message is available, already on your main loop. add_watch_local()
is probably what you're looking for.
Similarly there's also a futures Stream
that gives you messages whenever they are available.
Also you're currently not removing the timeout (later: do the same with the bus watch) when the backend is destroyed, so they will accumulate over time with every new player.