v17 Patch for Kodi to disable UPnP/DLNA directory caching
#1
Hello everyone,

Those of you who use Kodi as UPnP client know how frustrating it is that you have to restart Kodi every time the content of your DLNA/UPnP server changes.

I googled this forum and all other places in search for an answer to this issue.

Some users suggested that Kodi expects DLNA/UPnp server to send a notification when content on the server side changes. So, initially I was blaming my DLNA server (I use miniDLNA) for not sending notifications to Kodi. Well, after some modifications I made to miniDLNA, it sends notifications about changed content to all subscribers properly. Still, Kodi didn't update UPnP directory content after notification.

Digging this issue further, I was able to prove that Kodi, after initial query of a specific directory content of UPnP source, was never querying that directory again, even after notification from DLNA server about content change.

So, my next step was to find what is Kodi doing upon receiving notification messages from DLNA server. Kodi does subscribe for notifications for two services, ContentDirectory and ConnectionManager, but the handler for these notifications is not looking for content change message. I believe Kodi doesn't expect directory content notifications, it only looks for changes in parameters like audio volume level, I didn't go into details because it was not related to filesystem notifications.

Thus, the only way to force Kodi to see changes on the DLNA server is to disable its internal directory cache for UPnP sources. This way Kodi would re-read each directory every time you navigate/browse into it. Western Digital LiveTV box does it like this and I never had issues of not being able to see content of DLNA server after content change without restarting UPnP client.

Sorry for very long explanation of why and how I came up with this patch, but maybe some users would be interested.

Here is the patch:
Quote:diff --git a/xbmc/filesystem/UPnPDirectory.h b/xbmc/filesystem/UPnPDirectory.h
index adaf4df..b469172 100644
--- a/xbmc/filesystem/UPnPDirectory.h
+++ b/xbmc/filesystem/UPnPDirectory.h
@@ -40,6 +40,7 @@ public:
// IDirectory methods
virtual bool GetDirectory(const CURL& url, CFileItemList &items);
virtual bool AllowAll() const { return true; }
+ virtual DIR_CACHE_TYPE GetCacheType(const CURL& url) const { return DIR_CACHE_NEVER; };

// class methods
static const char* GetFriendlyName(const CURL& url);
diff --git a/xbmc/network/upnp/UPnP.cpp b/xbmc/network/upnp/UPnP.cpp
index 2370ee6..1ee6005 100644
--- a/xbmc/network/upnp/UPnP.cpp
+++ b/xbmc/network/upnp/UPnP.cpp
@@ -177,7 +177,7 @@ class CMediaBrowser : public PLT_SyncMediaBrowser,
{
public:
CMediaBrowser(PLT_CtrlPointReference& ctrlPoint)
- : PLT_SyncMediaBrowser(ctrlPoint, true)
+ : PLT_SyncMediaBrowser(ctrlPoint, false)
{
SetContainerListener(this);
}
Sorry, I cannot guide you though steps how to use this patch or how to re-compile Kodi.

With this patch, to update the content of the modified directory, all you have to do is to re-read this directory: go one directory level up and then come back, or go into any subdirectory and then step back.
If parent of your current directory is renamed or moved, then you have to re-start browsing from the root directory.

This patch is made for Kodi v17.3-r1 (Krypton), on a Gentoo Linux. I guess it would be easy to adapt it for other versions of Kodi too.
Ideally, UPnP directory caching should be controlled (enabled/disabled) from user interface, but that would take for me a lot of time to implement as I am not a Kodi developer.

Here is the quick list of the threads on this forum regarding this issue:
Well, thanks for reading this if you've got this far.
Alex.
Reply
#2
(2018-03-31, 18:13)alex033 Wrote: Those of you who use Kodi as UPnP client know how frustrating it is that you have to restart Kodi every time the content of your DLNA/UPnP server changes.

Yes, that's absolutely infuriating.

Why is this the default behavior?

People can't wait the extra 100ms it takes to grab the contents of a directory?  Its connected to the DLNA server with gigabit Ethernet and the box running Kodi has absolutely nothing else to do, why not just show the current directory listing every time it's shown?

Do the contents of most people's DLNA servers never change?

Mine changes many times a day, and having to reboot my Kodi boxes every time I want to watch something is insane.

How do we get an option for "read directory every time" added to Kodi?  Or a "refresh directory" action that can be mapped to a remote key?

I really don't care what was in that folder last month.  I want to know what there now.
Reply
#3
(2019-11-01, 02:36)Grant.Edwards Wrote: Mine changes many times a day, and having to reboot my Kodi boxes every time I want to watch something is insane.
Well, then I suggest you are doing something wrong.

uPNP is not the best way to share your library across multiple instances of Kodi. Do it right and set up Network sharing like SMB.
My Signature
Links to : Forum rules (wiki) | Banned_Add-ons (wiki) | Debug Log (wiki)  
Links to : HOW-TO:Create_Music_Library (wiki) | HOW-TO:Create_Video_Library (wiki)  ||  Artwork (wiki) | Basic controls (wiki) | Import-export library (wiki) | Movie sets (wiki) | Movie universe (wiki) | NFO files (wiki) | Quick start guide (wiki)
Reply
#4
(2019-11-01, 03:18)Karellen Wrote:
(2019-11-01, 02:36)Grant.Edwards Wrote: Mine changes many times a day, and having to reboot my Kodi boxes every time I want to watch something is insane.
Well, then I suggest you are doing something wrong.
Then pray tell what am I'm doing wrong?  I want to watch videos served by a DLNA server, and the content of the DLNA server's folders changes frequently.  Is Kodi a bad choice for that?  That would be unfortunate, since I just bought a vero-4K running OSMC/Kodi specifically for that purpose based on the assumption that Kodi can be used as a DLNA client — did I assume incorrectly?
Quote:uPNP is not the best way to share your library across multiple instances of Kodi. Do it right and set up Network sharing like SMB.

I'm using Kodi as a front-end to watch videos served by a DLNA server.    Setting up SMB or NFS isn't an alternative, because I don't want to browse some underlying filesystem.  I want to browse the hierarchy of folders presented by the DLNA server.  That DLNA folder hierarchy does not represent an underlying Linux or Windows filesystem that can be exported via SMB or NFS.  Even if it did, the underlying filesystem won't keep track of what's not been watched, what's been watched, and what's been partially watched (and allow me to resume watching later) the way the DNLA server does.
Reply
#5
(2019-11-01, 18:34)Grant.Edwards Wrote: based on the assumption that Kodi can be used as a DLNA client — did I assume incorrectly?

No, but I don't think there is a maintainer any more for UPnP so anything that doesn't work isn't likely to get fixed sadly.
(2019-11-01, 18:34)Grant.Edwards Wrote: underlying filesystem won't keep track of what's not been watched, what's been watched, and what's been partially watched (and allow me to resume watching later)

No, but Kodi's database will do exactly that if you scan your smb/nfs shares into the library.  Further, if you use MySQL/MariaDB as a database rather than the local sqlite db that Kodi uses by default, you can share the entire library (including watched status and resume points) to multiple kodi clients.
(2019-11-01, 18:34)Grant.Edwards Wrote: Setting up SMB or NFS isn't an alternative, because I don't want to browse some underlying filesystem

You don't need to.  Kodi's libraries don't work like that.  They amalgamate everything together under different headings (movies, TV shows, Music) which can be further split up by using nodes or smart playlists that can segregate content based on many different 'rules'.  IMHO this is much better than using a DLNA server but hey, horses for courses and all that.

Still, you could at least look into it, instead of just rejecting it out of hand.  You might just be surprised at what is possible.
Learning Linux the hard way !!
Reply
#6
(2019-11-01, 21:21)black_eagle Wrote: Still, you could at least look into it, instead of just rejecting it out of hand.  You might just be surprised at what is possible. 

But I also watch shows with non-Kodi DLNA clients (more often than I do with Kodi clients).  Other DLNA clients that, when you navigate into a folder, show you a list of want's in the folder.  OTOH, Kodi shows you want was in the folder at some undefined point in the past.

The DLNA server already arranges the shows into folders they way I want based on various criteria that Kodi doesn't know anything about.  I'm quite happy with the way that the DLNA server works and with the way the other DLNA clients work (e.g. VLC on Android and Linux desktop).  I just wanted a set-top box DLNA client for the occasions when I want to watch something on a non-smart TV, and I mistakenly thought Kodi could do that.
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Patch for Kodi to disable UPnP/DLNA directory caching00