OLD: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Kodi Community Development

Moderator: TVJunkie198

Locked
djp952
Posts: 1190
Joined: Wed Oct 01, 2008 8:46 pm
Device ID: 131EB7F7;131ED0E0
Location: Elkridge, MD USA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 »

For the folks with the weird lock up / slowness on Windows when this PVR is enabled, I may have finally duplicated this!

On a hunch, I switched an older PC over from Linux to Windows 10. The PC itself seems fine, but Kodi is killing me. Takes forever to load the channels, blank screens when looking for recordings, no response from the PVR at all after playing a Blu-Ray movie. Running OpenELEC (back a couple revisions), this system was very fast for all things Kodi.

The biggest difference I can think of is that this system has a Celeron CPU (N3050); all my other machines have varying revisions of the Core i series (Two i7s and one i3).

This may be the hint I needed, what kind of CPU(s) are you running on the Windows systems with the weird problems, and what version of Windows? I can't be certain if it's the PC, the OS, Kodi, or the addon yet, but holy cow that is super annoying!!!

fab4272
Posts: 41
Joined: Wed May 17, 2017 5:17 am

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by fab4272 »

Hi. Is there any way to show more than 8 hrs of guide data? Excellent addon BTW.

johnny_swindle
Posts: 29
Joined: Tue Mar 24, 2015 11:38 am

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by johnny_swindle »

17.3 Kodi for windows breaks guide option when streaming
The problem seems to intermittent...........not sure what is going on....but I am certain that 17.3 has some impact on the add-on.
Well drat! Dang you Kodi! It worked for me on an Android 5.0.2 tablet (ARM), let me set up an emulator. For now, I'll revert the main Downloads page back to 17.1.

THANK YOU for the report!!
It is a bothersome bug, but not sever enough to stop me from using the add-on. In due time I am confident that you will uncover the source of the issue.

lovemyram4x4
Posts: 206
Joined: Thu Jun 02, 2011 5:45 pm

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by lovemyram4x4 »

OK, I tried open guide this morning and left Kodi in the locked up state all day to see what would happen. It stayed locked up and log continued to show the same entries as I previously posted but nothing else.

djp952
Posts: 1190
Joined: Wed Oct 01, 2008 8:46 pm
Device ID: 131EB7F7;131ED0E0
Location: Elkridge, MD USA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 »

fab4272 wrote:
Fri May 26, 2017 2:41 pm
Hi. Is there any way to show more than 8 hrs of guide data? Excellent addon BTW.
Yes, but I elected to not enable beyond 8 hours. Here's my reasoning -- in order to get the guide data beyond *4* hours you have to ask the backend for each channel individually and do that in a loop to get all that data. It becomes exponentially slower to accomplish.

The guide data seems designed for the HDHomeRun app (makes sense!), where it can go get the data for one channel if you do the right-arrow trick to expand the channel out. Kodi expects you to be able to produce all the data for every channel when asked since it uses a grid EPG. I think even the HDHomeRun app limits you to about 8 hours, likely for the same reason.

I left the maximum at 8 hours since that only requires a single pass through all the channels, which seems reasonable. It can certainly be expanded, perhaps by having something like a semi-continuous guide updater running in the background, I'm concerned that it would end up as a non-stop process for folks that have a slower internet connection. When I tested getting ALL the guide data that is available (like 2 weeks worth, even on a 50Mb FiOS connection that's pretty much what happened; it's that slow.

Ideally, the HDHomeRun guys could deliver a bulk guide for all channels for an extended period of time like they do for the 4-hour data, but I don't see that happening :)

If you're cool with it taking forever and a day to download and process, I can extend it -- what timeframe are you looking for? 16 hours? 24 hours?

djp952
Posts: 1190
Joined: Wed Oct 01, 2008 8:46 pm
Device ID: 131EB7F7;131ED0E0
Location: Elkridge, MD USA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 »

lovemyram4x4 wrote:
Fri May 26, 2017 3:38 pm
OK, I tried open guide this morning and left Kodi in the locked up state all day to see what would happen. It stayed locked up and log continued to show the same entries as I previously posted but nothing else.
I'm testing a 1.0.9 version tonight that seems to help.

What I found happening on my slower system was that the Kodi database was taking a long long time to update for whatever reason. The way I send data to Kodi, I run a query against the client database and send the results back to Kodi as they are returned. When Kodi is taking a long time with it's database, it causes hell since my discovery tasks can't run until the read query is finished. Ultimately bad things end up happening.

To combat this concern, I am now querying all of the data from the client database into memory and releasing the client database connection. Once that's done and the database is unblocked I transfer the data from memory over to Kodi, so it no longer matters to the client how long that actually takes.

What I've seen so far with the changes is a much improved experience. I can't control how long Kodi takes to process the data I'm sending it, but I can control the client database contention :)

If this build passes muster, I'm expecting to send it out tomorrow some time. I really hope it helps with the lock-up concerns as well as Kodi 17.3 (which to me seems an order of magnitude slower than 17.1 was).

lovemyram4x4
Posts: 206
Joined: Thu Jun 02, 2011 5:45 pm

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by lovemyram4x4 »

I'm not sure how my Shield TVs would compare with slower PCs, Kodi actually runs better on it than my old gaming capable HTPC. Hopefully whatever you're testing will help. I'm going to try disabling some things to see if maybe they're interfering with PVR client.

As for how much guide data. If open the guide a long time after starting Kodi stops locking it up, ideally I'd like to have all available but even when I was running WMC with 30 days of guide data I only loaded 3-4 days worth into Kodi since it took awhile to load at start up and Kodi didn't always like me doing other things on it while it was still loading. It would cool if Kodi could just download the next chunk of guide data if you scrolled past the data it has already downloaded.

fab4272
Posts: 41
Joined: Wed May 17, 2017 5:17 am

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by fab4272 »

djp952 wrote:
Fri May 26, 2017 8:14 pm
fab4272 wrote:
Fri May 26, 2017 2:41 pm
Hi. Is there any way to show more than 8 hrs of guide data? Excellent addon BTW.
[/quote

If you're cool with it taking forever and a day to download and process, I can extend it -- what timeframe are you looking for? 16 hours? 24 hours?
I understand. Was hoping for at least a days worth of guide data, but if it's going to cause issues leave it. I'll get used to it. Great app mate.

djp952
Posts: 1190
Joined: Wed Oct 01, 2008 8:46 pm
Device ID: 131EB7F7;131ED0E0
Location: Elkridge, MD USA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 »

fab4272 wrote:
Sat May 27, 2017 2:07 am
djp952 wrote:
Fri May 26, 2017 8:14 pm
fab4272 wrote:
Fri May 26, 2017 2:41 pm
Hi. Is there any way to show more than 8 hrs of guide data? Excellent addon BTW.
[/quote

If you're cool with it taking forever and a day to download and process, I can extend it -- what timeframe are you looking for? 16 hours? 24 hours?
I understand. Was hoping for at least a days worth of guide data, but if it's going to cause issues leave it. I'll get used to it. Great app mate.
Eh, no worries! I'll play around with it some maybe I can find a way that it won't be too awful. I didn't put a great deal of effort into it the first time around :)

djp952
Posts: 1190
Joined: Wed Oct 01, 2008 8:46 pm
Device ID: 131EB7F7;131ED0E0
Location: Elkridge, MD USA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 »

I think I finally have an explanation for the weird lockups, and yes it appears to be my fault :D It's hard to prove, but here's where I think I'm making the mistake.

I do all the HDHomeRun 'discovery' tasks in the background and trigger updates in Kodi when things have changed. Normally this works OK, but where I believe it may be falling apart for some folks is on startup. I'm actually trying to trigger updates when the PVR is starting up, which depending on how the system is behaving can occur before Kodi has ever asked for the data in the first place. I can see how this could cause some weirdness, and it's certainly a design flaw on my part. I'm also not preparing the data in the order in which Kodi will ask for it, so even if things are clicking and all good it's causing some extra work on Kodi's part.

I'm looking at keeping some flags to check whether or not Kodi has asked for an individual set of data (channel groups, channels, recordings, EPG and timers) yet, either from startup or wake from sleep, and not try to force it to ingest anything new until after that set of data has been asked for at least once. I may go so far as to not send it anything until it's asked for everything at least once, but that's not likely necessary.

I'm also going to reorder the discovery tasks a bit to get them in the same order as Kodi will ask for them, and shorten the amount of time between them during startup/wake. Right now the final task is run six seconds after startup/wake (episode timers), which is way too long. My intent was to be sure they ran in a specified order by staggering them all by one second, but most won't take an entire second to run so it's just wasting precious time, and causing Kodi to have to ask for things at least twice.

Need some more time to implement all this, hang tight!

(For what it's worth the Celeron system I said was having problems with was switched back to Linux anyway, family kinda wanted to use it again. I ultimately tracked the bulk of my problems to the wimpy system itself, between Kodi and Defender and all the other Windows 10 stuff on there, it was constantly pegged out at 100% CPU. So my 'observations' above are really just from a static analysis of both Kodi and the PVR code, but I think it's a real problem that needs to be addressed regardless).

lovemyram4x4
Posts: 206
Joined: Thu Jun 02, 2011 5:45 pm

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by lovemyram4x4 »

I'm not sure if this will be any help with what's going on but something I noticed that might be related to the PVR lock up. I have the ticker set up to show what's currently recording and once Kodi got to the point that opening the guide(also appears that open recordings and likely timers) would lock up Kodi, the ticker stopped updating.

Since I noticed the ticker stopped updating for a show at 15:00 I checked the logs fro around this time and in the middle of the PVR line up discovers I noticed an error: CPVRTimerType::createfromattributes unable to resolve timer type then error: previous line repeats 7XX times. I noticed this on the few times the lineup discovery lines showed during about 30min around 15:00, the later line up discoveries after the point of open PVR related stuff would cause a lock up didn't show the error anymore.

lovemyram4x4
Posts: 206
Joined: Thu Jun 02, 2011 5:45 pm

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by lovemyram4x4 »

It appears that when I restarted Kodi after my last post the PVR client got the same error right away. This time I tried to open timers and Kodi locked up.

djp952
Posts: 1190
Joined: Wed Oct 01, 2008 8:46 pm
Device ID: 131EB7F7;131ED0E0
Location: Elkridge, MD USA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 »

lovemyram4x4 wrote:
Tue May 30, 2017 12:50 pm
It appears that when I restarted Kodi after my last post the PVR client got the same error right away. This time I tried to open timers and Kodi locked up.
That particular error is sadly normal, I couldn't implement one of the timer types Kodi supports (Manual time-based) as there is no way to do that with the HDHomeRun backend. Well, it kinda/sorta would be possible if I were to search on that date and time and channel and found what program was airing and picked that instead, but then your start/end times won't match :)

I finished up the next version (1.0.9) last night, I've done a lot of things differently that I hope will help. It's actually a pretty big set of changes so I need to test it as much as I can before letting it loose :)

Not to jump the gun too much or promise vapor-ware, but here's a summarized version of things I've changed that might help. My fingers are crossed that one or more of these do the trick for ya. There is a lot more, these are just the items that may be relevant:

- Updated SQLite and cURL to latest versions -- there were LEFT JOIN optimization bugs in SQLite that may be relevant here, but I seriously doubt it.

- Always perform device, channel and recording discovery immediately on startup and don't try to queue change triggers for Kodi for them -- I was asking Kodi to update things before the PVR Manager was fully up and running which seems to be benign but perhaps was the reason it is going into la-la land. It was clearly a mistake regardless, so now I get the data for everything on the local network immediately so when Kodi comes asking for it the first time it's ready. Bonus: Recordings got bumped up in priority so they all show up right away instead of a couple seconds after Kodi starts up.

- Load all data from the PVR database into memory first then send it to Kodi to reduce database contention -- this is the change I think will have the most impact. What I was doing before made a silly assumption that Kodi was always super fast. I was sending data (pick one - channels, timers, recordings, everything) to Kodi as it was read from the PVR database, which makes it harder for the background discovery tasks to do their job since they want to write to the database. So now I read the PVR data into memory as quickly as possible, close that connection, and THEN send the data to Kodi. If it takes Kodi 1/10th of a second or 10 minutes to accept it all, shouldn't matter now.

So far what I'm seeing is Kodi is a bit snappier starting up than it was, but otherwise honestly .. nothing remarkable. Sadly I'm still kinda guessing here, but you never know which tweak will be the one that unbreaks the camel's back :)

djp952
Posts: 1190
Joined: Wed Oct 01, 2008 8:46 pm
Device ID: 131EB7F7;131ED0E0
Location: Elkridge, MD USA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 »

It looks good to me, so ... version 1.0.9 has been posted to the usual location on GitHub:

https://github.com/djp952/pvr.hdhomerun ... /Downloads

It has a lot of little changes, nothing I'd consider exceptional. The main goal of this release was to optimize some things in the hopes that the people still having problems with lock-ups can finally get some relief :D

  • Update SQLite database engine to version 3.19.2
  • Update cURL library to version 7.54.0
  • Perform immediate discovery of all local network resources (devices, lineups, recordings) during addon startup
  • Clear pending scheduled discovery tasks during addon stop and destroy operations
  • Prevent PVR triggers from being signaled by background discovery tasks still running during addon stop and destroy operations
  • Filter out DRM channels from Electronic Program Guide discovery change triggers; resolves CEpgContainer errors in log
  • Fix internal exception handling and return values returned from menu hooks
  • Reduce database contention during operations that transfer data back to Kodi via callback functions
  • Reduce SQLite busy handler wait period from 30 seconds to 5 seconds
  • Add "Reset discovery database" PVR Client Specific setting
At this point, if you are still experiencing the Kodi UI lock-ups, I think I will have to send you a special build with some things removed to see if we can put a close to that problem once and for all. Please PM me with a reminder on which platform you are running on, and I'll crank out some test builds for ya with various pieces crippled so we can nail that down.

Enjoy!

djp952
Posts: 1190
Joined: Wed Oct 01, 2008 8:46 pm
Device ID: 131EB7F7;131ED0E0
Location: Elkridge, MD USA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 »

Good news for the lock-up problem; I found it (at least one of them). I had to add a bunch of waits into the code and then I managed to get the Kodi UI to lock up repeatably. I also found the deadlock that occurs in Kodi when you add/remove PVRs with at least one PVR already installed.

The bad news is that both the deadlocks are in Kodi. I'm not sure yet if I can work around these or if I need to propose fixes for Kodi. I think I can work around the bulk of the problem we're seeing, but not necessarily for every possible situation.

The underlying cause seems to be that the Kodi UI accesses guide data to populate various elements and when doing so, it's taking a lock (mutex/critical section) to protect some attributes of the channel it's looking at (hidden, enabled, etc). But, when the EPG happens to in the process of being updated, that lock also gets held by the updater and doesn't release until the update is complete, and the UI deadlocks. There will be a third piece to this puzzle (what's preventing the update from completing), but that's the basic gist.

The reason Kodi locks up when adding/removing a PVR client with at least one already installed is a similar problem, that will have to be fixed in Kodi, nothing I can do there and it's definitely not unique to this PVR client.

What I'm thinking for us is to put a workaround in that prevents anything new from being sent to Kodi until it's made at least one pass through everything (Guide, Timers, etc), since the problem is most prevalent on startup. There is no "hey, PVR is ready, go ahead and send me stuff" notification (but I may propose one), so I will find out what the last thing Kodi asks for is (I believe it's the timers) and defer all the background tasks until that has happened at least once. I'll probably put back the "fast startup" I removed in 1.0.9 as well, where if there is data already in the database don't go looking for anything right away to try and account for the delay. We'll see!

For Kodi itself I am going to ultimately propose three things: a fix for the UI deadlock, a fix for the install/remove deadlock, and an enhancement to notify the PVR clients when it's safe to trigger data updates. Even if they accept the proposed changes it's not likely we would see them implemented before Kodi 18.

Sorry for talking your ears off like usual.

Locked