v20 [inputstream.adaptive] Kodi Nexus buffering and adaptive bitrate switching support

Thanks to the wonderful work started last year of @peak3d and the GSOC student @mtahir we now have a working release in the v20.0.1 version for Nexus.
This release adds support for:
  • Segment buffering - Previously streams played with inputstream.adaptive would only ever have Kodi's 8 second internal buffer along with up to 1 extra segment stored at a time. Kodi's internal buffer is not really meant to be a buffer for streaming and increasing this was never a solution, so the buffer has to be held on inputstream.adaptive's side of the fence. There are some new add-on settings to go with this: assured buffer length and maximum buffer length. I have not tested changing these settings much but the defaults seem to work fine.
  • Adaptive bitrate switching - Previously manual video stream switching could be performed (with the stream selection setting set to 'manual') using the OSD, otherwise the 'auto' setting would pick a 'best' stream initially but all other streams were discarded. Now the 'automatically select streams' option will reevaluate the current stream's bandwidth vs the actual download speed and move across the separate bandwidth streams as needed. There is sometimes a slight glitch when stream change occurs.

  • 'manual' stream selection setting shows the different streams in the OSD, but automatic stream switching still occurs.
  • Possible deadlocking of threads (I was unable to solve this, I believe there is a rewrite needed of the worker thread)
  • Maybe more that I'm not thinking of atm...

Features still missing:
  • adjusting streams based on CPU load e.g reduce from 1080p to 720p if CPU cannot handle
  • adjusting streams based on window size - currently window size is only inspected on playback start and there is not yet the required changes inside Kodi to allow this to happen mid-stream

  • the stream selection algorithm and default settings may require tweaking
  • improvements may be needed around how the segment buffer is filled and whether to shed any segments when the stream is switched. Currently on stream switch, segments from the new stream will get added to the end of the buffer. Depending on the length of the buffer this can mean quite a long time before the new segments are 'seen' by the viewer, and in some situations it may be preferable to bring this change closer to the start of the buffer.
Hoping for some feedback here, and any detailed issues to be posted to the GitHub page.
I've been running Kodi Nexus nightlies for a while, but since this new version of IS:A I'm having trouble with the Netflix addon.

Streams are stuttering regularly and sometimes the screen goes black for a bit and some kind of handshake is performed again (I can see this because my TV shows the Dolby Vision logo again).

As stated above, manual stream selection doesn't work properly, because the switching still occurs.

I'm using a Shield Pro 2019, Denon AVR-X2300W receiver and Philips 48OLED935 TV.
I've been playing with this for a while and I think the buffering is a real improvement but the adaptive switching isn't great.

A live stream will play with occasional buffering on 19.3 on a good quality connection. With V20 it'll start with the highest bitrate but then gradually reduce to the lowest level over time and get stuck there. If I pause the live stream and allow it to timeshift by a few minutes the player will switch to the highest bit rate and play very well.

I've also found it very glitchy with a low quality network connection (the worse the connection the more stuttering/ freezing/ fast-forwarding/ crashing). Not sure how to help fault find, I could generate a ton of log files but they'll be hard to replicate as the behaviour is very inconsistent.
Sorry for the late replies:

@MrMagic There's been a lot of improvements lately thanks to @CastagnaIT making some gargantuan contributions.
Coming in the next release (within the next week hopefully) will be multiple methods for stream selection such as:
* Adaptive - switches streams as outlined above
* Fixed resolution - tries to find closest resolution to your preference
* Ask - provides a dialog box to select. Some Python add-ons already do this but this implementation is native to inputstream.adaptive and allows all add-ons to use it

@konel thanks for the feedback. As mentioned there's been lots of improvements and also cleaning up of the code, fixing potential bugs.
At the moment live streams will start around 16 seconds from the live edge - this doesn't give too much room to be able to buffer ahead. I wonder if you'd have more consistent results if you rewound say 20 seconds once playback starts. Also it would be interesting to find out where the official app/player for your streaming service plays the stream - does it play even closer to the live edge/the same/further back? I've seen some players give a minute back from live edge... In any case the new adaptive selector coming has much better debug logging which should help expose if there's any weird behaviour.
I'm using Sky Sport Now (NZ) and the native Android TV player is 22s further from the live edge than Kodi (I just checked this by comparing the time on screen between Kodi and the native player).

The Kodi experience is overall better than the native player as once I timeshift - either pause or skip back - by a couple of minutes it plays at the maximum bitrate flawlessly. Whereas the native player will occasionally buffer/ drop quality (it doesn't allow timeshift).

Exactly how big a timeshift I need to get it working smoothly I'm not sure. I usually skip back three minutes and after a few minutes of jumping between bitrates it'll settle at the maximum quality and remain there reliably.

I look forward to the next version, looks like it'll be a good improvement and if there's any testing you want done let me know, thanks.
Ok cool, thanks for the extra info.
Well, I tried one of the latest v20 nightlies that has the new version (20.2.0) of VideoPlayer InputStream, but it was not a great success...

I tried the Disney+, HBO Max and Netflix add-ons and none of them played any 4K / H.265 videos. Starting a video made Kodi crash back to the Shield home screen (running a Shield 2019 Pro with SE 9.0.2).

In the HBO Max addon I could start an H.264 1080p video, but it was choppy.


After some further testing I was able to get an episode to play in the Netflix addon, but it didn't trigger Dolby Vision on my TV, so the colors were all off (green/purple effect).

I tried all this on a fresh install of the latest nightly (kodi-20220505-47e2b1dc-master-22661-arm64-v8a.apk) with only those three addons installed, but still ran into the same issues.
Thanks for the report @MrMagic 

Is there a chance you could post an issue on the inputstream.adaptive github repo?
A full debug log would be great, and also Android logcat snippet showing the stack trace would be awesome.
@glennguy I did some more testing today after updating to the 20220507 nightly and the IS:A version that @CastagnaIT linked to here: https://jenkins.kodi.tv/blue/organizatio.../artifacts

This made things a little better and I could get H.265 videos to play now in the HBO Max addon (although the unofficial KodiNerds Nexus build from Maven still crashes).

The Dolby Vision issue persists though.

I will try to collect some logs tomorrow and create an issue on github.
Created two issues:


Note: Somehow yesterday I was able to play an H.265 stream, but when I tried today it made Kodi crash again.
Thanks for that MrMagic, much appreciated.
(2022-05-08, 13:42)MrMagic Wrote: Created two issues:


FYI for those who don't follow GitHub: Both issues are fixed now thanks to @glennguy and @CastagnaIT so thanks guys!

Logout Mark Read Team Forum Stats Members Help
[inputstream.adaptive] Kodi Nexus buffering and adaptive bitrate switching support0
This forum uses Lukasz Tkacz MyBB addons.