mopidy / mopidy

Mopidy is an extensible music server written in Python
https://mopidy.com
Apache License 2.0
8.08k stars 685 forks source link

Track position is wrong at stream-changed/position changed time #1354

Open adamcik opened 8 years ago

adamcik commented 8 years ago

At the time we handle the new segment indicating track change / seek and the stream changed event the query position we get is typically still being reported as the duration ± a couple hundred milliseconds. This results in players such as ncmpcpp reacting to the player event and still getting the old songs last position instead of new one. This is only problem during EOT. Sadly it also seems to be the case on Gst 1.2 even outside of the playbin. I've also tried moving our event sniffing the the actually sink element and that doesn't help either :(

adamcik commented 8 years ago

Current suggestion for a workaround is to note the position at the of stream changed. Then in in get position we return zero if the position is larger than our stored last position. Problem with this is that we need to reset the stored position, so we probably need to use a GObject timer to trigger the reset a few seconds after the stream changed. Alternatively we solve this on the GStreamer level and send a custom event down the pipeline which triggers the last position reset.

adamcik commented 8 years ago

Triggering stream-changed from the last message we get for this on the bus seems a bit safer.

adamcik commented 8 years ago

GStreamer 1.0 seems to fix this for me. Don't think there is anything to do but to verify this when that branch is merged.

adamcik commented 8 years ago

gst1 is merged. Just needs to be double checked now.

adamcik commented 8 years ago

Think I've found a much better solution to this. Instead of trying to detect this in the tee, which always leaves us a bit off, we need measure as late as possible. So instead of doing pad probes on the output bin, we move it to the permanent fakesink. Additionally we get the position by querying this sink specifically as our reference position. Now sync this sink is synchronized to the same clock as everything else we should be getting the right times.

I've tested this with some quick hacks and this way we do get a position of zero and the duration for the new song from the moment the new segment event comes in.