slimserver-tools icon indicating copy to clipboard operation
slimserver-tools copied to clipboard

Fix: songs not playing fully/skipping to next before the end

Open sle118 opened this issue 6 years ago • 14 comments

This Fix is to limit the watchdog's actions on remote stream read operations only. The watchdog will no longer stop the worker thread when waiting for LMS to read data.

On windows, when streaming remote sources (e.g. spotty), playback buffer (stream controller, player, etc) would fill quickly and not request more data for a duration that caused the socketwrapper's WDT mechanism to trigger. This is a simple fix that introduces a new boolean indicator inside of the stage structure: ` BOOL bIsWriting;

Stage threads update the flag during both the read phase (bIsWriting=false) and the writing phase (bIsWriting=true). This allows the main socketwrapper's thread to figure out if a given stage thread is reading from a remote socket, where the wdt applies, or if it is waiting for the stage thread to write back to LMS., where the wdt should not apply.

if (info[i].fIsWorkerThread) {
 if (0 == info[i].WatchDog _**&& !info[i].bIsWriting**_) {
  stderrMsg("Watchdog expired - Thread for step %i stalled.\n", i);
  if (bWatchdogEnabled) fDie = true;
 }
 info[i].WatchDog = 0;
}

sle118 avatar Oct 27 '19 20:10 sle118

Thanks @sle118 - this does indeed look like an easy enough change. Could we risk to run into situations where the watchdog would indeed have had to kick in? I'm not too familiar with this code... what would happen if LMS disappeared while socketwrapper was active?

mherger avatar Oct 28 '19 05:10 mherger

It's been over 10 years but I think the watchdog was added when using mplayer and AlienBBC. IIRC It was added because under some conditions would be i/o blocked and so processes were not shutdown. This left zombie Mplayer & socketwrapper instances. I think the the conditions were either (i) changing live station and (ii) pausing live streams.

I'm surprised that a watchdog problem has started now. Mplayer had been used to be play RealAudio BBC live and "Listen again" streams for many years even newer player with large buffers such as Touch.

I'll have a look at the code later. In the meantime I suggest checking that the fix doesn't affect playback of live streams (e.g. transcoding a radio station) where

  • users plays a stations for a few minutes and then changes station to another live one. Make sure all transcoding processes are shut down.
  • Pause a live stream (transcoding) for say 15 minutes.

bpa-code avatar Oct 28 '19 15:10 bpa-code

Minor point - SW_ID needs to be updated to "1.12"

bpa-code avatar Oct 28 '19 15:10 bpa-code

I'm still working my way back into the code. However, AFAICT the new flag is also set when I/O is between processes when there are more than 2 exe in transcoding. Is that deliberate ? Why not the following which just affects LMS input. if (!pS->fOutputIsSocket){ pS->bIsWriting = true;

bpa-code avatar Oct 28 '19 15:10 bpa-code

I'm still working my way back into the code. However, AFAICT the new flag is also set when I/O is between processes when there are more than 2 exe in transcoding. Is that deliberate ? Why not the following which just affects LMS input. if (!pS->fOutputIsSocket){ pS->bIsWriting = true;

Good point; this is something I missed during my analysis of the code, as I didn't have all the possible scenarios in mind. Thanks for spotting that.

Alternatively, and to preserve the semantics meaning of the new status variable, I could leave seeing/removing the flag as is, and add another condition in the wdt itself.

if (info[i].fIsWorkerThread && (!info[i].bIsWriting || info[i].fOutputIsSocket)) {

Let me know your thoughts

sle118 avatar Oct 31 '19 02:10 sle118

So I went ahead and changed the version string to 1.12beta. I also implemented the additional criteria which keeps the wdt active during writes if the output is a socket. I haven't tested yet, but I suspect that this will circumvent the fix altogether, at least for Spotty. Typical command line to wrap Spotty is as follow:

-i 0 -o 51681 -c "C:\ProgramData\Squeezebox\Cache\InstalledPlugins\Plugins\Spotty\Bin\MSWin32-x86-multi-thread\spotty.exe" -n Squeezebox -c "C:\ProgramData\Squeezebox\Cache\spotty\8ba0b816" --verbose --single-track "spotify://track:6lhDKRxI7fjL1Jao6erY1n" --bitrate 320 --disable-discovery --disable-audio-cache --pass-through

This line shows that fOutputIsSocket will be true for the output side of Spotty, and that adding the new condition will end up maintaining the wdt active. I would thus recommend against having the wdt active on the output side for any scenario (i.e. aligned with my initial PR logic).

sle118 avatar Nov 05 '19 01:11 sle118

With the complex "if", maintenance of this code may not be easy - two flags tested by logical OR of them NOTed (especially if I have to look at it after 5 years).

Please add more detail to your 1.12 comment especially noting the flag you introduced.

I've done a quick test of your original mod and watchdog still seems to work (albeit a bit slower) with stalled streams with STDIN. I have yet to test with URL input but Spotty uses URL so I'm hoping you already tested that watchdog still works with Spotty.

I don't know of any current application which needs the #PIPE# construct so I have not tested it.

As socketwrapper is used in various transcoding situations on Windows from XP to 10 - we'll need to be vigilant to see if users see odd Windows problems - possibly excess memory / processes if socketwrapper does not tidy up.

bpa-code avatar Nov 05 '19 09:11 bpa-code

@sle118 I know it's been a while but do you still have your last changes for this PR? Your final comment on Nov. 4 indicates that you made additional changes after the PR commit on Oct 27. We've started working on updating the windows build of LMS to use a recent perl and I thought it would be a good opportunity to apply your changes to socketwrapper. Here's the thread. https://forums.slimdevices.com/showthread.php?115740-LMS-for-Windows-using-Strawberry-Perl Thanks.

ralph-irving avatar Jan 12 '22 19:01 ralph-irving

It's been a long time. I don't read into my Nov 5 comment about another change. Windows is not my main system so I'll have to see if I have a backup of socketwrapper dev from 2019.

bpa-code avatar Jan 12 '22 21:01 bpa-code

Thanks bpa. I was referring to the comment Sebastien (sle118) posted on Nov 4th just above yours, which mentions that he went ahead and made additional changes. I know it's been a long time thanks for checking.

ralph-irving avatar Jan 12 '22 21:01 ralph-irving

In a forum PM discussion with @sle118 he confirmed that the dropped brace was an error and unfortunately the PR doesn't compile as a result. I've attached a complete patch for review. PR3-revised.patch.txt and I have built 32 and 64-bit binaries for testing. https://sourceforge.net/projects/lmsclients/files/utility/socketwrapper-1.12beta.zip/download

ralph-irving avatar Mar 04 '22 19:03 ralph-irving

I've been testing socketwrapper.exe 1.12beta here: https://forums.slimdevices.com/showthread.php?111923-Announce-Spotty-4-0-integrate-local-library-with-your-Spotify-collection-(LMS-8-)&p=1049763&viewfull=1#post1049763

Unfortunately I am getting problems. I don't know if I am doing something wrong but I wanted to point it out here in case somebody can chime in with things to test, logs to activate, etc. I am willing to test whatever you need me to (except a complete reformat of my machine, that is).

gorman42 avatar Mar 06 '22 17:03 gorman42

I've opened a testing discussion on this: https://forums.slimdevices.com/showthread.php?116078-Spotty-and-socketwrapper-1-12beta&p=1049809#post1049809

gorman42 avatar Mar 07 '22 13:03 gorman42

(sorry, posted in wrong thread, now I can't delete it...)

pupvogel avatar Apr 25 '22 08:04 pupvogel