GNOME Bugzilla – Bug 737055
audiosink: Setting URI on playbin at about-to-finish when playing AAC and using an alsasink causes delayed playback
Last modified: 2015-03-10 23:13:11 UTC
I setup a playbin with an alsasink. Then assign it an URI pointing to an AAC file. When I get the about-to-finish signal I update the uri to an URI pointing to a non AAC, for instance ape, mp3 or flac. Then I get a strange behaviour where the playbin indicates via state that it is playing. But its quiet and I see by polling the playbin for position that it is 0. Then suddenly after a long while > 30 seconds, the position starts to increase and the song start playing (I hear audio). During the time its quiet I can see that This is 100% reproducible, I use gst-libva for AAC decoding. I switched to using a pulsesink instead, then it works as expected. Also playing let say an MP3 then a FLAC file is also working as expected. So it seems to be the combination of AAC and alsasink. I reproduced this with 1.4.2 and 1.4.0.
Is this delay before the second URI is played around the same duration of the first file?
Very interesting point! I played a song of duration: 200690068027 Then it stalled for 401 half second timeouts -> 200,5 seconds -> The same amount of time! Sounds like you have a clue about this?
By the way I did a test where I seeked in the first file, then the delay was shorter. But as I as wrote earlier; when I played the while file the delay was as long as the first file...
Do you mind checking if it also happens when you play those URIs with gst-play tool from gst-plugins-base?
Just tested, and it indeed fails also with gst-play: gst-play-1.0 --audiosink alsasink --gapless <aac-uri> <mp3-uri> I have seen a similar behavior when doing some other tests. It seems related to either the DISCONT flag handling in audiobasesink, how it deals with late buffers or buffers that have a smaller timestamp than the last one received.
"Good" to hear that you could reproduce the issue as well. But why wont we see this issue in pulsesink if it would be related to the audiobasesink?
pulsesink and alsasink use different ring buffers. Alsasink one seems to reset its writing point to 0 and then it gets requested to write to position X = previous sample last position and it has to wait to actually write and play that. Pulsesink one does the same reset, but it sets the time_offset properly to compensate for it. I'm trying to come up with a fix (this code is dense).
Created attachment 286905 [details] [review] audiosink: compensate for segment restart with clock's time_offset When playing chained data the audio ringbuffer is released and then acquired again. This makes it reset the segbase/segdone variables, but the next sample will be scheduled to play in the next position (right after the sample from the previous media) and, as the segdone is at 0, the audiosink will wait the duration of this previous media before it can write and play the new data. What happens is this: pointer at 0, write to 698-1564, diff 698, segtotal 20, segsize 1764, base 0 it will have to wait the length of 698 samples before being able to write. In a regular sample playback it looks like: pointer at 677, write to 696-1052, diff 19, segtotal 20, segsize 1764, base 0 In this case it will write to the next available position and it doesn't need to wait or fill with silence. This solution is borrowed from pulsesink that resets the clock to start again from 0, which makes it reset the time_offset to the time of the last played sample. This is used to correct the place of writing in the ringbuffer to the new start (0 again)
The fix seem to fix the issue here!
commit 8242676dc20b0a9b5dcac9a0e8048fc672d3b314 Author: Thiago Santos <thiagoss@osg.samsung.com> Date: Tue Sep 23 14:14:36 2014 -0300 audiosink: compensate for segment restart with clock's time_offset
*** Bug 745887 has been marked as a duplicate of this bug. ***