FS#10377 - PCM buffer remainder is played under too many conditions

Attached to Project: Rockbox
Opened by Jeffrey Goode (Blue_Dude) - Wednesday, 24 June 2009, 03:38 GMT
Last edited by Thomas Martitz (kugel.) - Monday, 29 June 2009, 19:21 GMT
Task Type Bugs
Category Music playback
Status Closed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version Version 3.3
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


The pcmbuf_play_remainder() routine in pcmbuf.c was intended to ensure that the last samples were played out of the buffer at the end of the playlist. This was done from a call in playback.c, but the placement of that call causes pcmbuf_play_remainder() to be called for all stops. This caused a subtle bug in another patch that could crash the player under certain conditions.

This patch changes the placement of the call so that it's only invoked at the end of the playlist as intended.
This task depends upon

Closed by  Thomas Martitz (kugel.)
Monday, 29 June 2009, 19:21 GMT
Reason for closing:  Accepted
Additional comments about closing:  Commit the last patch in r21569. Thanks.
Comment by Jeffrey Goode (Blue_Dude) - Wednesday, 24 June 2009, 15:25 GMT
Here's a better patch that does the same thing.
Comment by Thomas Martitz (kugel.) - Thursday, 25 June 2009, 10:02 GMT
Can you explain the actual bug and change please? what's the difference between "playing" and "!paused" ?
Comment by Jeffrey Goode (Blue_Dude) - Thursday, 25 June 2009, 12:55 GMT
Yeah, this one was a little weird. The problem was in the changes I made to the pcmbuf_play_remainder() routine in another patch. I added a pcmbuf_request_buffer line to make space at the end of the PCM buffer for the contents of the attack buffer. But during a manual stop, this line would go into an infinite loop waiting on buffer space that wasn't going to appear, and occasionally crash. So in order to discriminate between a manual stop and playing out to the end I changed the condition from "playing" to "!paused". A manual stop at this stage is actually paused but still playing, but it doesn't need the samples because it's not ever going to play them. But if playing to the very end, it's not paused and it needs them, so it gets them.

This change as a standalone patch has no ill effects and actually prevents an unneeded call. If it's not used for now, nothing bad will happen. Consider it a minor cleanup.
Comment by Jeffrey Goode (Blue_Dude) - Friday, 26 June 2009, 18:41 GMT
Same patch with code commentary.
Comment by Jeffrey Goode (Blue_Dude) - Friday, 26 June 2009, 18:46 GMT
A short hedge against something strange happening. This routine should never be called if (!playing) and (!paused), but just in case...
Comment by Jeffrey Goode (Blue_Dude) - Friday, 26 June 2009, 18:56 GMT
Cleaner code.