New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create "Buffered" player protocol #581
Create "Buffered" player protocol #581
Conversation
d6d30da
to
9f7c4e9
Compare
I understand that this protocol handler would need to be used by any plugin/code which would want to take advantage of that feature. As it's based on HTTPS, plain text http connections could not be supported this way. Is there any other reason why this wouldn't be the default way of dealing with https connections if proxied streaming was enabled? Ok, disk usage. Some people might not like the idea of writing to their SD cards. Could it optionally be used for those cases? With podcasts? I guess that users (plugins) would need an update to take advantage of this. |
I think we have made now changes so that HTTP url are supported S::P::P::HTTPS is used, but I'll check. If it works, it could be used as the default handler in the LMS core but I'm not sure that all services are always happy by a quick download, I don't know. |
Also, this should really NOT being used with webradio and continuous streams 😅 |
That much even I understood 😉! |
Now, I probably can look for content-length and disable the buffering if none is found |
6d17379
to
266b5d7
Compare
don't buffer if content-length is missing
266b5d7
to
cd5bede
Compare
How are you testing this change? Did you modify any other code to make use of it? If so, anything I could inherit for the testing? |
Yes, you can modify Slim::Player::ProtocolHandler.pm the following way
Which forces usage of "Buffered" very broadly across LMS |
But this wouldn't work with PHs which inherit from S::P::P::HTTP, would it? Eg. for TIDAL I'd have to modify TIDAL's PH? |
You're correct, it would only work with "native" services. For Tidal, you'd have to do what I did for mixcloud, which is simply inheriting from Buffered. This is how I tested your plugin. |
Ok, here's something I'm not sure whether it's related to this change, or SqueezeAMP: I was playing that TIDAL mix on SqueezeAMP. Had been for a few hours. Suddenly it stopped at the end of a track. LMS logged this:
And the player disappeared. I tend to think that the above message was the consequence of the player crashing. It didn't come back automatically. I had to pull the plug on it. Good news: no buffering file was left behind. |
I added a clean fail when the $socket cannot be created by S::P::P::HTTPS |
Toggling the setting would require a LMS restart for TIDAL to pick up the change.
Use pref to enable/disable use of buffered http requests.
With your changes, I think we are ready to give it a try |
Great thanks! |
I haven't been following this PR or its predecessors, so I can't comment sensibly. But a thought occurs: Many "SD Card using people" have learned over the years to mount their system The temporary directory returned by Does this "buffered" temporary directory or its contents need to to persist after reboot ? I guess I'm just wondering if the system's |
Not this buffered is totally temp and in fact is wiped-out at every LMS start, just in case. The choice of not using /tmp is precisely for the reason you describe which is that /tmp can be rather small |
Buffering to the file system currently is off by default. I might change this, depending on the experience we'll have. But I do see your point and actually planned to look into not enabling it on systems running on SD card or similar. If you have a good idea how to discover whether a system is running on a "weak" storage medium, please let me know. |
I thought that might be an issue. I guess an educated user might "learn" to suitably size and mount a "RAM" based directory prior to starting LMS. It will be interesting to find out what the size will need to be in real use.
I wish. On a Linux based system one can look for the obvious candidates Nor does it tell us that the relevant "weak" storage system is actually in point. But perhaps that's secondary. I'll communicate if I find or come up with anything further. |
TBH: I believe the whole "don't write to [put your media here]" is overrated - in particular when it comes to SSD. I've been running LMS on pCP for about 4 years now and haven't had a single SD card failure. |
You may well be right. I was well bitten about ten/twelve years ago by SDHC/MMC, and USB flash, and my outlook has been informed by that experience. So I learned to take “precautions”. And I haven’t had a problem since then. But, I believe that SDHC/MMC technology has improved significantly during the intervening period, and default file system settings are now probably more suited to the media. I suspect the same carries over to USB flash drives. I have no experience of SSD drives, other than one inside my iMac, which seems fine and, I suppose, is as reliable as the accompanying magnetic drive. So perhaps I overestimate the need for caution. |
I might have found a "neat" (please note the use of conditional here 😄) solution for protocol handlers that want to inherit from S::P::P::HTTP(S) but have a problem with servers that do not like long streaming session and would rather prefer the whole file to be downloaded as quickly as possible.
This solution makes use of the recent modifications in Temp directory usage and in the HTTP(S) inheritance process (use of sysread and SUPER::_sysread), so it feels like all adding up nicely.
Basically, the idea is to let the header's acquisition work as usual (blocking read and direct use of HTTP(S)' sysread) in the new() and once this is done, it installs a reader on the socket so that it can read as fast as possible and store body in a file located in "temp". Then the _sysread continues reading from that file instead of direct access to HTTP(S)' sysread. The file is then removed at the end of the streaming session.
I've quiclky tested it with MixCloud and Tidal but it requires more scrutiny at this point but I thought I'd submit it for feedback & opinions.