jellyfin / jellyfin-kodi

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

Enabling Kodi Sync Queue in jf4k causes adverse video playback performance #830

Open wohali opened 7 months ago

wohali commented 7 months ago

Describe the bug

It seems that having the Jellyfin plugin loaded with the Sync Queue activated leads to extremely poor performance in certain situations, especially where the platform on which Kodi runs is nearing its performance limits without Jellyfin loaded. Note that this is for locally stored media, not indexed by Jellyfin, browsed to via the Files menu.

In marginal cases this issue results in skipped frames every so often. In more extreme ones, it results in only half the frame rate - and not even on extremely taxing files (in one extreme case: NVidia Shield Pro 2019, 1080p H.264 24fps with AAC 2.0 audio played back at under 11fps.)

In debugging and isolating this issue, the "trying to load setting definitions from the old format" logging seen by @TrueTechy in #116 appeared to be spamming the logs during playback. That issue was closed by @mcarlton00 because Kodi upstream stopped logging that info except when debug logging was activated. However, I believe this may have wallpapered over the issue, and now that the transition to the new format is done, the underlying point should be revisited.

As the video being played in this test case was not being played thru Jellyfin, the Sync queue plugin had run once and had found no changes, and no other Jellyfin activity should have been ongoing, the spammed logging suggests that whatever is going on with setting definition loading is preventing the Sync Queue plugin from being suspended -- even when it has been disabled during playback!

To Reproduce On a system with limited resources (or with a video file that's taxing for the system under test):

  1. Enable Jellyfin Kodi Sync Queue. Ensure "Enable sync during playback" is disabled. Allow the Sync Queue process to run to completion.
  2. Enable Kodi Debug Logging.
  3. Navigate to a video using "Files" and play it. Look for dropped frames, stuttering, etc.
  4. View the debug log.
  5. See the repeated errors of the form shown in the Logs section below.
  6. Disable the Jellyfin Kodi Sync Queue.
  7. Play a video again and notice a dramatic performance improvement.

Expected behaviour Performance with the Jellyfin plugin loaded and the Sync Queue enabled should be roughly equivalent to the performance without it loaded.

Logs

2024-02-27 02:26:59.790 T:5592    debug <CAddonSettings[0@plugin.video.jellyfin]>: trying to load setting definitions from old format...
2024-02-27 02:26:59.794 T:5592    debug <CSettingsManager>: requested setting (LastIncrementalSync) was not found.
2024-02-27 02:26:59.794 T:5592    debug <CSettingsManager>: requested setting (SyncInstallRunDone) was not found.
2024-02-27 02:26:59.794 T:5592    debug <CSettingsManager>: requested setting (groupedSets) was not found.
2024-02-27 02:26:59.795 T:5592    debug <CSettingsManager>: requested setting (platformDetected) was not found.

These 5 lines appear roughly every 2s during playback. Video stuttering continues to occur immediately.

System (please complete the following information):

Additional context Perhaps it is time to revisit https://kodi.wiki/view/Add-on_settings_conversion ? At the very least, figure out why CAddonSettings / CSettingsManager continues to spin during video playback.

mcarlton00 commented 7 months ago

Your terminology is confusing, but I can understand what the issue is at least. First off

Note that this is for locally stored media, not indexed by Jellyfin, browsed to via the Files menu.

This is really not a supported use case. The docs explicitly state

However, it also tends to consume the database and not share well, so if you have local media or something else that interacts with the database directly, you will have conflicts and it will not be happy.

Because of how the addon is currently designed, trying to do this is far more likely to encounter issues than other situations. That's (probably) not directly related to what's happening here, but it's worth pointing out you're playing with fire.


Just so everybody is on the same page, the Sync Queue is not a client side thing. It's a plugin that lives in the server and has exactly 0 effect on the Kodi client except when Kodi first starts. The addon installed into Kodi is named jellyfin-kodi, or Jellyfin for Kodi. We sometimes abbreviate this to jf4k if we're feeling lazy. It's not a huge deal, but it greatly helps if everybody is using the same terminology to avoid confusion.


The actual issue, the settings stuff, and this is where things get fun. None of those are actual settings. This is a side effect of previous developers of this addon using the in-memory settings storage of Kodi as a temporary variable store. Kinda gross, but it is what it is right now. I also have significant doubts that this is what's causing your performance issues. imo, it's annoying but harmless, which is why I haven't redesigned that part of it yet. Those log messages aren't even coming from our code directly.

If I had to guess, it's more likely the addon trying to do processing in the background and send playback status to the server, while failing miserably because you're playing files that aren't on jellyfin (again, not really a supported use case currently). Without checking the code, I suspect it's just trying to ship playback progress for everything instead of properly trying to scope itself to only things that's playing from jellyfin. Previous design decisions have led to the assumption that the jellyfin-kodi addon is your only real source of media on this playback device. Disabling the "sync during playback" probably means that it's not retrieving new data from the server during that time period (new episodes/movies, updated watch status, etc), but I doubt it disabled all current status reporting.

wohali commented 7 months ago

Hey @mcarlton00 thanks again for looking at this, and sorry about the confusion.

Just so everybody is on the same page, the Sync Queue is not a client side thing.

The setting in jf4k calls itself "Enable Kodi Sync Queue," which is to what I was referring. Of course, this requires having the plugin installed on the server as well.

This is really not a supported use case

For the record, the problem occurs also when playing the same video, indexed by Jellyfin, with no change in the symptomology. I was simply trying to show that when interacting with a file that is not in the Kodi DB - just by browsing to it with the file browser, the same problem occurs. I guess I should have left it at "it doesn't matter if the video is being served to Kodi by Jellyfin or not."

None of those are actual settings. This is a side effect of previous developers of this addon using the in-memory settings storage of Kodi as a temporary variable store.

Ugh.

If I had to guess, it's more likely the addon trying to do processing in the background and send playback status to the server, while failing miserably because you're playing files that aren't on jellyfin

Sorry for misleading you. This problem occurs even when the file is indexed by Jellyfin, with the exact same symptoms and results. And, again, disabling the jf4k "Enable Kodi Sync Queue" setting restores Kodi performance to normal levels for the system in question.

Let me know what more I can do to help.