(OLD) Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Kodi Community Development

Moderator: TVJunkie198

Locked
Ken.F
Posts: 2151
Joined: Fri Apr 05, 2013 9:20 am
Device ID: 1041A706, 1043EB32, 104BAD9E, 13168DC5, 1322A7AC
Location: West Rockhill, PA

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by Ken.F » Tue Jul 17, 2018 4:13 am

djp952 wrote:
Mon Jul 16, 2018 8:28 pm
Update on the 'next' release. As indicated I've been working on redoing the HTTP stream implementation based on all our lessons learned to date. While I haven't found any smoking guns for the stream stalling or getting 'poppy' or 'jittery' audio on some channels then they start, I am pleased to say that by simplifying things I have indeed improved the performance significantly (to me, anyway).
Have you looked at the ServerWMC PVR add-on? Maybe it has some ideas you can borrow. They have commercial skipping working with Comskip .txt files. I really like how it has two seek bars. The lower one tracks the progress of the live TV stream and the upper one tracks your position in the buffer. The grey color is a bit hard to see during bright scenes so I paused on a black frame to show it better.

Image

Hardax
Posts: 48
Joined: Wed Aug 09, 2017 11:01 am

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by Hardax » Tue Jul 17, 2018 4:58 am

djp952 wrote:
Mon Jul 16, 2018 8:13 pm
Hardax wrote:
Sun Jul 15, 2018 9:37 am
Playback just stopped. (v17) Log here:

https://pastebin.com/jQeJ907f
This looks so far like the stream is stalling on us here. What can happen here is that I have a timeout set on how long the PVR client will wait to get enough data to send back to Kodi. If that timeout is reached, it's handled by saying "I've got no more data to give you". Another thing that may be happening is that there could be a bug/defect with how I'm handing the case where the input buffer actually fills up (I would consider this far-fetched for a stream being played, I think it would be more akin to pausing it).

I need to go through your logs a bit more (THANK YOU for posting them!!), but I think I may not have the required level of logging/error support built in to find out exactly what's happening. I'm working on that part - the inability to diagnose people's problems easily has been bothering me :)
Cool beans that I might have been able to help some!

All of my testing so far in v17 & v18 have been with just the add-on enabled. I had NOT installed the record engine during these tests as I didnt want to add another layer while trouble shooting. Last night I did install the record engine and watched live tv all night and did not experience a single stall using the v18 APK.

One other observation that I wanted to bring back up, when using the 1.2.8 APK I do get random video stalling when playing local files (streaming over local smb share). I know this sounds like it should be unrelated but as soon as I switched back to a native Kodi build the stalling stopped.

Hardax
Posts: 48
Joined: Wed Aug 09, 2017 11:01 am

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by Hardax » Tue Jul 17, 2018 4:59 am

Ken.F wrote:
Tue Jul 17, 2018 4:13 am
djp952 wrote:
Mon Jul 16, 2018 8:28 pm
Update on the 'next' release. As indicated I've been working on redoing the HTTP stream implementation based on all our lessons learned to date. While I haven't found any smoking guns for the stream stalling or getting 'poppy' or 'jittery' audio on some channels then they start, I am pleased to say that by simplifying things I have indeed improved the performance significantly (to me, anyway).
Have you looked at the ServerWMC PVR add-on? Maybe it has some ideas you can borrow. They have commercial skipping working with Comskip .txt files. I really like how it has two seek bars. The lower one tracks the progress of the live TV stream and the upper one tracks your position in the buffer. The grey color is a bit hard to see during bright scenes so I paused on a black frame to show it better.

Image
Just wanted to chime in that I love this idea if its doable. Having a more **** like experience would be fantastic!

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

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 » Tue Jul 17, 2018 4:15 pm

Hardax wrote:
Tue Jul 17, 2018 4:59 am
Ken.F wrote:
Tue Jul 17, 2018 4:13 am
djp952 wrote:
Mon Jul 16, 2018 8:28 pm
Update on the 'next' release. As indicated I've been working on redoing the HTTP stream implementation based on all our lessons learned to date. While I haven't found any smoking guns for the stream stalling or getting 'poppy' or 'jittery' audio on some channels then they start, I am pleased to say that by simplifying things I have indeed improved the performance significantly (to me, anyway).
Have you looked at the ServerWMC PVR add-on? Maybe it has some ideas you can borrow. They have commercial skipping working with Comskip .txt files. I really like how it has two seek bars. The lower one tracks the progress of the live TV stream and the upper one tracks your position in the buffer. The grey color is a bit hard to see during bright scenes so I paused on a black frame to show it better.

Image
Just wanted to chime in that I love this idea if its doable. Having a more **** like experience would be fantastic!
It's definitely doable, the double seek bar is a Kodi feature. You just have to tell it that you are timeshifting a real-time stream. I don't recall exactly why I couldn't get that to work to my satisfaction, I think it had something to do with needing to know where in the live stream you are. Originally I used to track the 'last seen' position of the live stream rather than just telling Kodi it's infinite, that could be why it never worked right.

I'll look at it again!

edit: oh wait, I remember now, I had problems determining when timeshifting stopped, so once that bar was up it was always up. I do recall it being related to the length -- that's no longer tracked for live streams so yeah, let me try again. Perhaps this could be as simple as watching for a seek request that returned a position less than what was requested on a live stream, which should indicate you are more or less 'live' again.

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

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 » Thu Jul 19, 2018 2:42 pm

Hardax wrote:
Sun Jul 15, 2018 9:37 am
Playback just stopped. (v17) Log here:

https://pastebin.com/jQeJ907f
Hello Hardax! I took another look at your logs and I do see something. Kodi is reporting a drop-out on the stream ("stream stalled") in the logs immediately after the PVR is doing discovery tasks (devices, recordings, etc). These use HTTP requests, many over the Internet, and I think we are running out of bandwidth. You are running over Wifi, right?

Here's my immediate suggestion. In the PVR addon settings there is an option under General called "Pause discovery while streaming Live TV channels". I suggest turning that one on. This currently only works for Live TV as it states, but I think it should be expanded to include Recorded TV as well, the intent is the same (as are the bandwidth requirements for the stream).

In working on the refreshed stream code, I actually ran into this exact set of events on my Android phone. It would drop out during discovery tasks. I have a solid 5Ghz Wifi connection that tests out to at least 60Mb/s and it still happened. Not executing discovery while streaming may be best served as a default setting rather than an option; the idea here was that while you're watching a stream you could still navigate around Kodi and find something new to watch, so it would be nice if that was all up to date.

There is also a Kodi option you should look at - in the PVR & Live TV settings, under Guide, turn on "Prevent updates during playback". The guide data involves a LOT of HTTP requests and that, like the stream, is driven by a request from Kodi. If the PVR doesn't respond the guide gets muffed up, so that operation won't stop/pause/abort if you are streaming. The only way to really stop it is to tell Kodi not to ask for it. It will pick up where it left off when you stop the stream.

While I'm not sure this would work for all the Linux platforms, for Windows and Android it should be pretty easy for the PVR to know if it's on a Wifi connection or a hard-wired connection. Perhaps some settings can be made more to be on/off/auto, where auto would try to figure out what's best for the environment it's running in.

Hardax
Posts: 48
Joined: Wed Aug 09, 2017 11:01 am

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by Hardax » Thu Jul 19, 2018 5:01 pm

Will definitely give both settings a try and report back.

Strangely I’m on a wired connection with a 100 mb connection and don’t have any other sort of bandwidth issues to speak of. That’s not saying there might not be an intermittent issue with one of my switches etc. but nothing that I’ve noticed.

I’ve been using v18 exclusively all week and again, now that I’ve enabled the recording engine I’ve had no playback stops. One or twice I have had playback pause without any interaction from me. I’m sort of guessing that if I was on v17, this would have been a stop?

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

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 » Thu Jul 19, 2018 7:42 pm

Hardax wrote:
Thu Jul 19, 2018 5:01 pm
Will definitely give both settings a try and report back.

Strangely I’m on a wired connection with a 100 mb connection and don’t have any other sort of bandwidth issues to speak of. That’s not saying there might not be an intermittent issue with one of my switches etc. but nothing that I’ve noticed.

I’ve been using v18 exclusively all week and again, now that I’ve enabled the recording engine I’ve had no playback stops. One or twice I have had playback pause without any interaction from me. I’m sort of guessing that if I was on v17, this would have been a stop?
I don't think it's a network problem at all. The evidence is very strong that it's my discovery tasks. Sorry I thought you were on Wifi. After some additional thought I'm thinking of playing around with something called the "share" interface for cURL (the HTTP library), it allows sharing of things like the DNS lookups. It's hard to know if it's something like that or overall bandwidth. Could even be a QoS thing (that's a stretch). Sadly, none of these problems ever seem to happen on Windows for me, which is the primary development platform. I'm glad it's happening on my Android phone with the exact same symptoms so if I can smooth that out it should have a positive impact for everyone.

The new stream code is also going to be capable of exposing underlying HTTP errors unlike the old one. While it doesn't look like I really need to handle any of them other than better reporting, I've wondered if HTTP 416 (Range not satisfiable) is occurring under certain circumstances -- it could happen if Kodi doesn't obey the length being reported or even if an in-progress recording ends, which switches the length from infinite to fixed.

Anyway, I'm babbling now. Back to work. Hope to have a Krypton-based test version this weekend for the new stream for folks to try before I call it 'good'. I've been down this road before, changing the stream code always seems to nuke at least one platform :)

Hardax
Posts: 48
Joined: Wed Aug 09, 2017 11:01 am

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by Hardax » Sat Jul 21, 2018 9:31 am

Just to report back, Ive gone back to a fresh install of v17 and implemented the 2 settings above and playback stops continue. If anything, they are even more frequent.

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

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 » Sat Jul 21, 2018 9:00 pm

Hardax wrote:
Sat Jul 21, 2018 9:31 am
Just to report back, Ive gone back to a fresh install of v17 and implemented the 2 settings above and playback stops continue. If anything, they are even more frequent.
Could be an actual HTTP error happening. Next version will be able to report that much more effectively. Hang tight!

jhford
Posts: 80
Joined: Mon May 21, 2018 3:56 pm

Deleting recordings

Post by jhford » Mon Jul 23, 2018 3:44 pm

Suggestion. I don't see any way to delete more than one recording at a time. Checkboxes and a Select All link would be great and highly appreciated.

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

Re: Deleting recordings

Post by djp952 » Tue Jul 24, 2018 7:40 pm

jhford wrote:
Mon Jul 23, 2018 3:44 pm
Suggestion. I don't see any way to delete more than one recording at a time. Checkboxes and a Select All link would be great and highly appreciated.
You can actually delete an entire series by right-clicking on the series name and choosing delete. This will delete everything in there. I learned this fairly recently, it was a neat trick to nuke en masse!

Unfortunately, beyond that I don't have any control here. All the PVR client does is respond to a request from Kodi to delete something. Not to arbitrarily pawn you off on this, but this would be a Kodi UI request. You can hit them up at kodi.tv, there is a "FORUM" link at the top.

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

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 » Tue Jul 24, 2018 7:54 pm

Been a little silent, wanted to give you guys an update as to the next version so you know I'm not disappeared again on ya.

I've been going through a lot of things and have made a lot of little changes here and there. Nothing earth-shattering other than the new stream implementation, which is still looking pretty good. Using a first-generation FireStick (weakest hardware I have that can run Kodi) I unfortunately didn't note any real reduction in CPU usage. Disappointing there, but it did seem like it work 'better' overall even though I have no metrics to prove that.

On the world of bugs/defects, I've found four and corrected one so far. The fixed one was that I found a logic error that would cause all the discovery (devices, tuners, etc) tasks to halt if there was an error starting a live TV stream and you had "Pause discovery while streaming Live TV channels" enabled. The scheduler that runs the tasks is stopped, but would not have been restarted if an exception occurred.

There is one in the "can't fix yet" category, and I've documented it as an issue on GitHub since I have no solution yet. Due to what seems to be a bug in SQLite, some of the HTTP discovery queries (devices, tuners, episodes if adding a new timer) are executed multiple times. This doesn't appear to affect any of the big queries (guide data being the main example), but it's a bug nonetheless. What is happening here is that I have a function called http_request() in SQLite that executes an HTTP request. If I run that function as part of a SELECT statement, if the resultant column is checked in a WHERE clause, it's actually executed again. SQLite fixed a bug like this regarding ORDER BY clauses years ago, but haven't seemed to fix it for WHERE clauses yet.

The remaining two bugs I'm researching. I found instances where when seeking a live stream, the MPEG-TS data seems to be unaligned, which trips a trap I put into the packet filter. This technically shouldn't ever happen. Could be a bug in the PVR client (likely) or a bug/bad assumption in regard to the RECORD engine (unlikely). The other one is the frozen picture after a seek operation. I got this to happen pretty easily last night on a 1080i NBC channel, but it's Kodi that's going off in la-la land not the PVR. The two issues could be one and the same under the hood, if the packet filter is misaligned but happens to hit a byte with the value 0x47, it won't know that and may be modifying the stream data rather than modifying the metadata. I will probably need to build Kodi myself to get the debug symbols in place to find out exactly where Kodi is hanging up/looping and work back from there.

Anyhow, that's what's been going on here at chez djp952 after the fam heads off to bed :)

edit: bonus news! Thanks to what appears to be an outage on the backend, I can confirm that HTTP errors are being logged much better now, and the EPG block works! (EPG block stops trying to download guide data if there are multiple errors). Typically expected to be due to an HTTP 403, but getting a 503 right now:

Code: Select all

22:58:02.145 T:2436   ERROR: AddOnLog: HDHomeRun DVR PVR Client: try_getepgforchannel failed due to an exception: SQL logic error (1): http request on url [redacted] failed with http response code 503
22:58:02.146 T:2436  NOTICE: AddOnLog: HDHomeRun DVR PVR Client: GetEPGForChannel: failed to retrieve EPG data for channel -- execute device discovery now
22:58:02.147 T:2436  NOTICE: AddOnLog: HDHomeRun DVR PVR Client: discover_devices_task: initiated local network device discovery
22:58:09.316 T:2436   ERROR: AddOnLog: HDHomeRun DVR PVR Client: discover_devices_task failed due to an exception: SQL logic error (1): http request on url [redacted] failed with http response code 503
22:58:09.317 T:2436  NOTICE: AddOnLog: HDHomeRun DVR PVR Client: discover_devices_task: scheduling next device discovery to initiate in 300 seconds
22:58:16.474 T:2436   ERROR: AddOnLog: HDHomeRun DVR PVR Client: try_getepgforchannel failed due to an exception: SQL logic error (1): http request on url [redacted] failed with http response code 503
22:58:16.474 T:2436   ERROR: AddOnLog: HDHomeRun DVR PVR Client: GetEPGForChannel: Multiple failures were encountered accessing EPG data; EPG functionality is temporarily disabled

Pretty cool. Well, cool to me anyway. Not getting discovery data is more likely annoying to others I assume!

edit 2: Pretty sure I found the elusive 3rd and 4th bugs mentioned above, and it is indeed my fault. It's related to an optimization I made during seek operations that checks to see if the requested data is already cached in the buffer. The determination of the condition is correct, the math of where that data begins in the cache is patently incorrect. I need to analyze this entire thing to avoid/fix any 1-off errors but a quick change seems to have solved both problems here. No more code traps being sprung, and I can't get The Tonight Show (the 1080i NBC program mentioned above) to lock up on a forward seek of 10 seconds after a full backwards seek to the beginning like it was last night. More good news!!
Last edited by djp952 on Tue Jul 24, 2018 9:16 pm, edited 1 time in total.

cscoppa
Posts: 98
Joined: Wed Jul 22, 2015 7:13 pm

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by cscoppa » Tue Jul 24, 2018 8:10 pm

Thanks for posting this (and all of your amazing work) Thought I was going crazy with the way the guide was behaving tonight.

obliojoe
Posts: 14
Joined: Fri Jul 20, 2018 1:57 pm

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by obliojoe » Tue Jul 24, 2018 10:30 pm

I have to start by saying thank you for this project. I have tried so many different things to get a decent DVR / interface going in our house and Kodi + your client is the first one that ticks all the boxes for me (and, more importantly, my wife). I have it running on several devices now. So, thank you, and where can I donate? Edit: just saw you don't accept them - let me know if you change your mind.

The one issue we have consistently is video freezing up when seeking - usually backwards - in any recorded or live TV. This is on Shield TV boxes running your modified Kodi APKs. I've been hesitant to bring it up because I see you are readying a new stream implementation - so I am looking very much forward to that release. I'd be happy to help test anything for you on my devices and help in any way I can.

Oh, and did I mention: thank you! :)

obe

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

Re: Unofficial Kodi PVR Client for HDHomeRun DVR subscribers

Post by djp952 » Wed Jul 25, 2018 9:27 pm

obliojoe wrote:
Tue Jul 24, 2018 10:30 pm
I have to start by saying thank you for this project. I have tried so many different things to get a decent DVR / interface going in our house and Kodi + your client is the first one that ticks all the boxes for me (and, more importantly, my wife). I have it running on several devices now. So, thank you, and where can I donate? Edit: just saw you don't accept them - let me know if you change your mind.

The one issue we have consistently is video freezing up when seeking - usually backwards - in any recorded or live TV. This is on Shield TV boxes running your modified Kodi APKs. I've been hesitant to bring it up because I see you are readying a new stream implementation - so I am looking very much forward to that release. I'd be happy to help test anything for you on my devices and help in any way I can.

Oh, and did I mention: thank you! :)

obe
You are so welcome!!

I may have some good news for you here. I can't be certain that I've 100% nailed it for all circumstances, but I have found and fixed two defects regarding seek operations in the past couple days. They weren't actually related to the 'new' stream implementation, but were exascerabated to the point where I was able to catch them:

- There was a bug in something I added a while back to try and optimize the (extremely) slow Kodi seek operations. Kodi (17/Krypton, at least) thrashes about on the MPEG-TS stream attempting to give you a perfectly accurate seek. This ends up causing a great deal of stream stops and restarts while it figures out where it wants to be. I added a trick that tries to satisfy the seek request quickly if I already have the data Kodi is looking for in the buffer. Unfortunately, there was a math problem there that ended up sending Kodi a position it didn't ask for and also screwed up my MPEG-TS packet filter. I'm not certain why Kodi would lock up, but I ultimately found a perfectly reproducible scenario that led me to the bug. After fixing it, seeks aren't really any faster (sadly) but I can't get it to lock up or misalign the data anymore.

- There appears to be a bug/limitation in Kodi (again 17/Krypton at this point) wherein it doesn't seem to obey it's own documented API. When Kodi is looking for data from a stream the API says to return -1 if bad things happen. I have been doing that to date. What I found here is that returning -1 doesn't stop Kodi from doing anything at all, and it just keeps asking over and over and over again for data it can't have. I changed it to return 0 instead. This appears to have the effect of a stalled/ended stream so Kodi actually stops. While I would prefer to deal with a stream error/exception more elegantly, for the time being this SEEMS to stop Kodi and allow the underlying error condition to be logged properly. I am having more trouble than I expected to actually detect a stalled/errored stream and try to restart it automatically, but I'm hopeful that this change will at a minimum stop everything and send you back to the Kodi UI.

Hang tight -- I'm playing with the new version on the Gen 1 FireStick tonight and it's looking pretty good to me so far. It's hard to quantify if things are "better" so I'm concentrating on slamming it to try and cause anything weird to reveal itself :)

I am still anti-donation, but I truly appreciate the offer. I see this project as leveraging the intellectual property of SiliconDust and Team Kodi for my own personal use (my wife actually likes this too!!!) so it just doesn't feel right to me to accept anything for it. Besides, I have a day job -- that's why I disappeared without a trace for half a year :)

Locked