[pvr] make all livetv views available to the user earlier (as soon as channels are fetched from the backend and before epg is loaded from the db) by changing the pvr/epg manager startup logic #1994

merged 2 commits into from Sep 7, 2013


None yet

4 participants


This is quite a big one, but tested to greatly reduce the time needed for the LiveTV views to be available to the user upon startup.

Right now, the logic is a little weird, as PVR manager thread is supposed to first load channel groups, etc, and then ask the EpgContainer to start before it enters its main loop.

The thing is that as soon as all channels are loaded from the db and updated, CreateChannelEpgs is executed (this is done after every internal channel group is loaded), which in turn calls LoadFromDB for the EPG data before it does its work.
Therefore, EPG data is loaded from the database before the epg thread is even asked to start, which causes a huge delay (especially on installations with many channels and slow hardware) before PVR is actually usable (in my secondary RPi setup, this takes more than 5 minutes(!)).

I changed the logic, so that PVR manager loads/updates the channels, but CreateChannelEpgs is only called as a trigger/callback when the main loop has started and therefore EPG data has been loaded from the database. The EPG loading itself has been changed to lock only when needed and not during the whole process.

This means that upon startup, all LiveTV views (and channel viewing, etc) are available as soon as the channels are loaded, even before epg is loaded from the database.
As a side-effect, it also cures the "ugly" overdrawing of the channel and epg loading popups.

In my opinion, it is crucial not to have the user wait for minutes before he/she can start watching TV.

Team Kodi member

i'll review this after frodo is out


Hmm, was hoping that it would make it to Frodo, since the current behavior is slow/ugly.
Have you tried initializing PVR in an installation with 1700 channels and a slow machine? (eg.Ion, or even worse rpi) :-)
Btw, when is Frodo coming out?

PS. At least check PR #1982, it will be a real shame if that one doesn't make it to Frodo, too

Team Kodi member

soon. only critical fixes or minor changes until frodo is out.

Team Kodi member

this PR causes some issues in my test build. If I try to access one of the liveTV windows but PVR addon is not yet completely loaded (IIRC channels are not yet fully imported) I sometimes only get a black screen and the only possibility to "close" it is by pressing "h" or "home" to get to the home screen.

@opdenkamp opdenkamp was assigned Jan 30, 2013
Team Kodi member

Any comments on this PR?

please rebase


Just rebased.
FYI I have been running this for the past 3 months or so without any issues...

Team Kodi member

@nemphys could you rebase another time please
@da-anda if you still encounter the black screen after this, please create a ticket and attach a debug log


Rebased, still using it without problems
EDIT: DO NOT MERGE YET, just compiled the rebased branch and it does not work as expected; must look into it further


OK, found the culprit: it was commit bdf8842 (by @opdenkamp ), which I had reverted just after it was merged in January (and forgotten about it since).
This commit breaks the functionality of my commit. Reverting it brings it back to normal; tell me what you want me to do.

Team Kodi member

right indeed, these two conflict, forgot about that one. please add the revert for that one to this pr, and we'll shove it in



@opdenkamp opdenkamp commented on the diff Jun 10, 2013
@@ -174,6 +195,8 @@ void CEpgContainer::OnSettingChanged(const CSetting *setting)
void CEpgContainer::LoadFromDB(void)
+ CSingleLock lock(m_critSection);
opdenkamp Jun 10, 2013 Team Kodi member

sorry, missed this one before. locking in here isn't very useful like this.
best just create a copy of m_epgs and iterate over that without holding a lock. only thing that can happen here really is that tables are being created, and those will be picked up later

nemphys Jun 12, 2013

If you check the code, ::LoadFromDB is called from ::Start, which (before my changes) held a lock during the call anyway.
The way I did it, the lock is only held when necessary, as the lock is released before calling ::LoadFromDB and created again after it is finished.

Team Kodi member

@nemphys can you update and rebase this PR?

nemphys added some commits Apr 1, 2013
@nemphys nemphys [pvr] make all livetv views available to the user earlier (as soon as…
… channels are fetched from the backend and before epg is loaded from the db) by changing the pvr/epg manager startup logic
@nemphys nemphys Revert "[epg] fixed - epg load/update was interrupted when the pvr ma…
…nager imports channels, leading to delays and channel ids gone missing in certain situations"

This reverts commit bdf8842.




@opdenkamp opdenkamp merged commit b0f94c7 into xbmc:master Sep 7, 2013
@CharlieMarshall CharlieMarshall added a commit to CharlieMarshall/xbmc that referenced this pull request Sep 15, 2013
@CharlieMarshall CharlieMarshall Revert "Merge pull request #1994 from nemphys/pvr-epg-startup"
This reverts commit b0f94c7, reversing
changes made to dcd897b.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment