jellyfin / jellyfin-kodi

Jellyfin Plugin for Kodi
https://jellyfin.org
GNU General Public License v3.0
833 stars 113 forks source link

Kodi-Jellyfin constant buffering when connecting to server via https #471

Closed absolution1 closed 3 years ago

absolution1 commented 3 years ago

Describe the bug Running Jellyfin 10.6.4 on a W10 PC and serving a Sony XH95 TV (Android 9) running Kodi (v18.9) + Jellyfin add-on (0.7.0). W10 PC runs a caddy server with a reverse proxy pointing to the Jellyfin server. The Caddy server fetches Let's Encrypt certs. My DDNS is registered via my Asus router. Hooking up kodi to the jellyfin server via HTTPS and playing my media results in constantly buffering playback (this is particularly true for high bitrate media). I have confirmed that my PC is --not-- transcoding in these cases.
Connecting Kodi to the server via http/direct IP does not have this problem. Confusingly, this hasn't always been a problem. I used to get smooth playback via https as well. It suddenly started being problematic one day...

To Reproduce

  1. Install Jellyfin on W10
  2. Setup caddy server with a reverse proxy, pointing to jellyfin server
  3. Install kodi + Jellyfin Addon on Android 9 TV
  4. Play media (preferably high bitrate [60Mbps])
  5. See constant buffering media

Expected behavior Smooth playback, as observed when connecting kodi to Jellyfin server via http

Logs [relevant snippet showing unverified https] 2021-02-14 19:58:53.014 T:18413 NOTICE: JELLYFIN.monitor -> INFO::jellyfin_kodi/monitor.py:42 -->[ kodi scan/video ] 2021-02-14 19:58:53.026 T:18413 NOTICE: JELLYFIN.monitor -> INFO::jellyfin_kodi/monitor.py:45 --<[ kodi scan/video ] 2021-02-14 19:59:02.282 T:18076 NOTICE: Trying to open: samplerate: 44100, channelMask: 12, encoding: 4 2021-02-14 19:59:02.288 T:18076 NOTICE: CAESinkAUDIOTRACK::Initializing with: m_sampleRate: 44100 format: AE_FMT_FLOAT (AE) method: PCM stream-type: PCM-STREAM min_buffer_size: 60416 m_frames: 3776 m_frameSize: 8 channels: 2 2021-02-14 19:59:03.745 T:18628 ERROR: DoWork - Direct texture file loading failed for resource://resource.images.studios.coloured/HBO.png 2021-02-14 19:59:04.086 T:18625 NOTICE: script.tv.show.next.aired: ### TV Show - Next Aired starting GUI proc (6.0.15) 2021-02-14 19:59:06.004 T:18606 ERROR: DoWork - Direct texture file loading failed for resource://resource.images.studios.coloured/ 2021-02-14 19:59:06.496 T:18628 ERROR: DoWork - Direct texture file loading failed for resource://resource.images.studios.coloured/HBO.png 2021-02-14 19:59:16.320 T:18656 NOTICE: JELLYFIN -> INFO::jellyfin_kodi/jellyfin/init.py:100 ---[ START JELLYFINCLIENT ]--- 2021-02-14 19:59:16.327 T:18656 NOTICE: JELLYFIN.entrypoint.default -> INFO::jellyfin_kodi/entrypoint/default.py:73 path: ?dbid=1416&mode=play&id=f0f9379a3758127a5d5a5052a72b2a4f&filename=Westworld.S03E07.mkv params: { "dbid": "1416", "filename": "Westworld.S03E07.mkv", "mode": "play", "id": "f0f9379a3758127a5d5a5052a72b2a4f" } 2021-02-14 19:59:16.406 T:18656 ERROR: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.module.urllib3/lib/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning, 2021-02-14 19:59:16.597 T:18656 NOTICE: JELLYFIN.objects.actions -> INFO::jellyfin_kodi/objects/actions.py:69 [ play/f0f9379a3758127a5d5a5052a72b2a4f ] Passed Pawn 2021-02-14 19:59:16.707 T:18656 ERROR: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.module.urllib3/lib/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

Screenshots NA

System (please complete the following information):

Additional context N/A

Happy to provide any other logs/try whatever to help with debugging.

oddstr13 commented 3 years ago

I expect this to be an issue with routing – the data going via at least the router, and quite possibly also up to your ISP and back down. See https://en.wikipedia.org/wiki/Hairpinning

One way to work around this is to have the router respond with the caddy server's internal IP for the DDNS domain. How to do this, if possible, depends on your router.

absolution1 commented 3 years ago

Hi @oddstr13 thank you for the info. I should have added, I'm using split DNS on my Asus router (not NAT loopback), so I think I'm already doing what you've suggested. All of my other clients (including the ones running Kodi) successfully connect (locally) to the Jellyfin server through https and play files without constant buffering.

The data is definitely going via the router though, as my TV connects wirelessly to the network. I do have other kodi clients connected wirelessly that don't have this problem however.

absolution1 commented 3 years ago

Hi @oddstr13 I've done a quick test to see if the issue is with the router or something weird with the authentication. I've connected Kodi (on my TV) to my Jellyfin server using my DDNS address BUT using http, rather than https. Everything plays perfectly when doing this (no buffering like with https) So, I'm feeling like the issue isn't with my video stream getting hairpinned by the router. What do you think?

pdf commented 3 years ago

Make sure you don't have gzip enabled in your reverse proxy for the jellyfin vhost. Though, if you have other clients that work fine, this is almost certainly an issue with the local net, proxy, or client, so unlikely there's anything that can be done on the Jellyfin side to help.

oddstr13 commented 3 years ago

Only thing I can think of is that it could be possible that the device running Kodi may not be able to handle both decryption of https and decode of the video stream fast enough at higher bitrates. Going over WiFi (which is also usually encrypted) would also not help.

This is all just a wild guess on my part however, and would only be possible to check if you're able to extract system load from your TV.

I do not think there is anything that can be done in our codebase to help improve this – we basically just pass the https link to Kodi.

mcarlton00 commented 3 years ago

It sounds like the TV can't handle decoding HTTPS traffic and video at the same time and there's not going to be anything we can do to optimize it, since we're piggybacking off Kodi's playback and network capabilities for the most part. Closing for now until somebody can show otherwise.

absolution1 commented 3 years ago

Hi everyone, Apologies for letting this go silent.

I forgot to add originally that this --used-- to work as expected. One day, it just kind of stopped working... The TV is new (a 2020 Sony XH95) so I'd really hope that it does have enough horse power to handle https + decoding (it has an onboard HEVC decoder I believe).

One thing that jumped out at me in the kodi log was this (posted above and copied below): 2021-02-14 19:59:16.406 T:18656 ERROR: /storage/emulated/0/Android/data/org.xbmc.kodi/files/.kodi/addons/script.module.urllib3/lib/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

Is something going wrong between the Android client and my Caddy server?

mcarlton00 commented 3 years ago

There's a couple places that we make requests to the server and each can be marked as either verify = True or verify = False. It should be using the addon settings and defaulting to True, but it's possible that something slipped through the cracks or that logic is flipped somewhere. More importantly, having it not doing SSL verification should actually be faster because that's less work that the client needs to do. So that message is likely a bug in the addon, but one that's inadvertently helping some people on low power devices.

absolution1 commented 3 years ago

I see. Thanks for the info and getting back so quickly.

I came up with a way to test whether the TV is struggling with SSL+media decoding; I played a movie through the TV's web browser, logged into the jellyfin web UI via https.
I did not try the very high bitrate HEVC file through the webUI (I'd assumed jellyfin would force a transcode) but I was able to play a 1080p file just fine (the same 1080p file struggled with https through Kodi+Jellyfin).

So, I'm inclined to say that the TV should be able to handle SSL+media decoding simultaneously.

It's a bit frustrating that I can't easily dig into this myself as I'm very unfamiliar with the codebase. Is there anything (logs etc) that you think might be useful to dig out?


Completely separately, playing a movie on Kodi-Jellyfin from my Mac (connected to the jellyfin server via https) I see a similar error message in the log, but the movie plays just fine (masked my details):

2021-04-09 22:56:06.549 T:7640247 ERROR : /Users/MYUSER/Library/Application Support/Kodi/addons/script.module.urllib3/lib/urllib3/connectionpool.py:997: InsecureRequestWarning: Unverified HTTPS request is being made to host 'SERVER.NAME.COM'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings warnings.warn(

sPOiDar commented 3 years ago

one that's inadvertently helping some people on low power devices.

I wouldn't expect this to have any measurable impact - the cert will only be checked once at connection setup time.


@absolution1 try playing a representative video file in kodi directly via HTTPS from the same webserver you're doing your reverse-proxy on. Make sure hardware decoding is actually working in Kodi on your device. Enable debug logging in Kodi for more information. Also, as mentioned earlier, ensure that gzip is not enabled in Caddy. One way or another, I'd be quite surprised if this is a Jellyfin problem.

absolution1 commented 3 years ago

@sPOiDar the PC hosting the jellyfin server also runs the reverse proxy already. Or, do you mean to play the movie directly on the web server?

I've already checked for gzip.

Yeah, something just feels incredibly weird here. As I mentioned above, playing a movie on the TV's web browser via HTTPS (and jellyfin's webUI) worked great. So, that kind of narrows the problem down to being somewhere within the kodi setup? I have completely reinstalled kodi (I've also factory reset my TV) and then setup from scratch but the problem did not go away...

sPOiDar commented 3 years ago

Right, I'm suggesting you narrow the factors at play, so playing a file directly from the same webserver, try it in the browser, and try it in kodi, see if there's a difference. Use the Kodi debug logs for more information, and try to confirm that hardware decoding is actually working in Kodi.

mcarlton00 commented 3 years ago

At this point, the only thing I can figure is that it's something within Kodi on that specific device. Maybe the browser's network code is more efficient than Kodi's. Maybe it hasn't been optimized for the hardware properly, or it needs a setting changed somewhere (video cache seems a good starting point). Maybe there's some tuning options you can play with. I know back in the day there were a lot of guides floating around for tuning Kodi to work more efficiently on raspberry pi's.

absolution1 commented 3 years ago

At this point, the only thing I can figure is that it's something within Kodi on that specific device. Maybe the browser's network code is more efficient than Kodi's. Maybe it hasn't been optimized for the hardware properly, or it needs a setting changed somewhere (video cache seems a good starting point). Maybe there's some tuning options you can play with. I know back in the day there were a lot of guides floating around for tuning Kodi to work more efficiently on raspberry pi's.

I'm inclined to agree.
As I mentioned above everything used to work correctly. One day, awhile ago, it just stopped working (I think Kodi might have crashed immediately before it stopped working). The only thing that makes me think it isn't just a kodi problem is that I have factory reset/wiped the TV hard drive and reinstalled everything fresh, but the problem didn't go away. Is it possible that Kodi has installed files on a system partition which isn't wiped during a factory reset?

I'll start fiddling with some Kodi settings to see, starting with hardware acceleration.

absolution1 commented 3 years ago

teeny update: The CPU usage (CPU-KODI) is quite high (>150%) while the buffering is going on when using https. I don't see the same hefty CPU usage when using http (or its too quick to be visible).

Looking in the video menu, I can see hardware acceleration is enabled...

sPOiDar commented 3 years ago

Time to take this over to the Kodi forums I think - they're much more likely to be able to help you over there.

absolution1 commented 3 years ago

Yeah, I think you're right. Hopefully they don't say that it's a Jellyfin issue and send me back ;)

Thanks so much for the help.

sPOiDar commented 3 years ago

That's why I suggest doing direct streaming tests from your web server within Kodi, removing Jellyfin from the equation entirely.

absolution1 commented 3 years ago

Maybe I didn't quite understand your suggestion before. Stream a movie from my server (through the reverse proxy) to my TV via HTTPS but without using Jellyfin. Is that what you mean?

sPOiDar commented 3 years ago

Correct.

dstar4138 commented 3 years ago

If you find a solution, please post forum link or something since I'm running into the same issue.

onthecliff commented 2 years ago

Any updates on this? I believe I am having this exact issue with Kodi and Jellyfin right now. I've tried nearly everything but HTTPS still doesn't work in Kodi (only HTTP), while every other Jellyfin client plays perfectly.

onthecliff commented 2 years ago

If you find a solution, please post forum link or something since I'm running into the same issue.

Did you find a solution?

absolution1 commented 2 years ago

Hey I kind of sidestepped this. I started using an ethernet connection from my tv to my network. HTTPS over eth was fine. I eventually ran into a separate issue where dolby vision files would buffer with https, even with using eth. In the end I opted to drop https as I didn't have time to debug. @sPOiDar 's suggestion is still a good one though: try streaming via https outside of jellyfin.

onthecliff commented 2 years ago

Actually now that you said that, I think this probably is a problem with Jellyfin. I can stream content over HTTPS in Kodi with Seren + Real-Debrid just fine.... The strange part is that with Jellyfin + HTTPS I can stream directly from a web browser or the Jellyfin desktop app just fine, but when I try to do it with Kodi that's where the problem starts... weird.