Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pvr] finally make it possible to use multiple PVR clients #7020

Closed
wants to merge 4 commits into from

Conversation

Jalle19
Copy link
Member

@Jalle19 Jalle19 commented Apr 27, 2015

I've grown tired of telling users that it's not possible to use more than one addon at a time due to a bug, so this is my attempt at fixing it. We really need a solution for this for Isengard so I'd appreciate it if we can keep the bikeshedding to a minimum and focus on getting something that works done, even though the solution might not be the prettiest.

The problem:

  • the addons are started by CPVRClients on a background thread. Meanwhile, CPVRManager used a simple sleep loop while waiting for at least one addon to load before continuing. If the second (or third) addon didn't load during the same 50 millisecond sleep duration, the startup would continue with just one addon.

The solution:

  • use a boolean in CPVRClients to indicate whether all clients have been loaded or not. From CPVRManager we call a method which blocks until this boolean's condition variable is signaled.

Ping @opdenkamp @ksooo @xhaggi @FernetMenta

I'm not convinced this is the ultimate solution, but at least it works and it doesn't introduce arbitrary sleep durations.

@Jalle19 Jalle19 added Type: Fix non-breaking change which fixes an issue Type: Improvement non-breaking change which improves existing functionality Component: PVR v15 Isengard labels Apr 27, 2015
@xhaggi
Copy link
Member

xhaggi commented Apr 27, 2015

does not runtime test it, but looks good.

@ksooo
Copy link
Member

ksooo commented Apr 27, 2015

Looking good, wrt pragmatic approach to improve things for Isengard. Though I did not runtime test.

@Jalle19
Copy link
Member Author

Jalle19 commented Apr 27, 2015

It's easy to runtime test, just enable pvr.demo and start Kodi a few times, checking that both your normal PVR client and the demo client gets loaded.

@xhaggi
Copy link
Member

xhaggi commented Apr 27, 2015

IMO shove it in, even better than it was before.

@Jalle19
Copy link
Member Author

Jalle19 commented Apr 27, 2015

I'd still like to hear @opdenkamp's thoughts

@MartijnKaijser
Copy link
Member

I don't see this as a fix

@Jalle19
Copy link
Member Author

Jalle19 commented Apr 28, 2015

@MartijnKaijser why not? We have always supported multiple clients, it just hasn't ever really worked that well so we have always adviced people to not do it.

@xhaggi
Copy link
Member

xhaggi commented Apr 28, 2015

totally agree with @Jalle19, it's a feature since the beginning but it didn't work in some cases. This will fix it and therefore it's a fix ;)

@xhaggi xhaggi added this to the Isengard 15.0-beta1 milestone Apr 28, 2015
@xhaggi
Copy link
Member

xhaggi commented Apr 28, 2015

@Jalle19 i would say let's shove it in for Beta1 so we have a wide range of testings till our final release.

jenkins build this please.

@Jalle19
Copy link
Member Author

Jalle19 commented Apr 28, 2015

I agree, any breakage should be easily spotted.

@ksooo
Copy link
Member

ksooo commented Apr 28, 2015

👍 for inclusion in beta
👍 for being a fix

@xhaggi
Copy link
Member

xhaggi commented Apr 29, 2015

any objections, if not i'll merge it in later today.

@FernetMenta
Copy link
Contributor

i am traveling and would like to have a closer look at this.

@opdenkamp
Copy link
Member

and I've been out of the loop for a couple of days because I was ill and
haven't looked at it yet either.

On 29-04-15 13:41, Rainer Hochecker wrote:

i am traveling and would like to have a closer look at this.


Reply to this email directly or view it on GitHub
#7020 (comment).

// indicate that addons have now been initialised
{
CSingleLock lock(m_critSection);
m_bAddonsInitialised = true;

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@Jalle19
Copy link
Member Author

Jalle19 commented Apr 30, 2015

@FernetMenta I changed it to use an event instead and removed the superfluous boolean. Tested by injecting sleeps here and there and it seems to work just fine.

return bReturn;
}

void CPVRClients::WaitForInitialisation()
{
m_loadedEvent.Wait();

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@opdenkamp
Copy link
Member

it's not.

On 30-04-15 12:32, freddysmith1 wrote:

Any sort of fix is better then no fix at all


Reply to this email directly or view it on GitHub
#7020 (comment).

@Jalle19
Copy link
Member Author

Jalle19 commented Apr 30, 2015

why is this so urgent that it needs a half fix that may or may not be fixed properly at some point? you're removing the "one add-on loaded" code now, which was there on purpose, which used to work a couple of releases back and which was broken while refactoring a while ago

It has been broken for over two years and I don't see anyone else fixing it.

unless there's a very good reason to not fix this properly now (shouldn't be that much work)

Do you have any suggestions on how this should be done properly? Either way I've updated the PR to wait a maximum of 5 seconds instead of forever.

@xbmc xbmc locked and limited conversation to collaborators Apr 30, 2015
@Jalle19
Copy link
Member Author

Jalle19 commented May 4, 2015

What's the verdict on this?

@@ -47,6 +47,8 @@ using namespace EPG;
/** sleep time in milliseconds when no auto-configured add-ons were found */
#define PVR_CLIENT_AVAHI_SLEEP_TIME_MS (250)

const int CPVRClients::CLIENT_LOAD_TIMEOUT = 5000;

This comment was marked as spam.

@opdenkamp
Copy link
Member

we should not wait for all clients to be connected, as explained earlier. that's why the code was structured like this.

it should just return from the method when 1 add-on connected, and the updater thread for the clients should keep trying to connect to the other add-ons (if any) while they're not all connected.

@Jalle19
Copy link
Member Author

Jalle19 commented May 4, 2015

There's much work to be done to implement it the way you're suggesting:

a) m_channelGroups->Load() is only called once (when the manager starts), if all clients are not loaded by then their "content" will not be loaded regardless of whether the client gets loaded eventually.

b) once the channel group container has started to load it will search the database and find all channels from the client that didn't start on time and delete them. This can take a lot of time. Same thing happens with the EPG data.

c) even if we'd change the code so that the channel group container etc. is reloaded when a new client is connected there'd be a ton of pointless database operations in between.

I don't see why we can't go with the current solution for now, the absolutely worst case scenario is that the "Loading channels from clients" dialog is shown for five seconds during startup, alternatively during shutdown if the user quits Kodi as soon as possible after launching it.

edit: typo

@Jalle19
Copy link
Member Author

Jalle19 commented May 4, 2015

@FernetMenta I updated the event handling, is this how you meant?

@opdenkamp
Copy link
Member

The main advantage of having multiple pvr clients imo is to be able to switch between backends easily. All the rest can be consolidated into 1 backend. The code originally did handle this correctly a couple of years ago, but it broke with all the refactoring. Rather than doing it like this, and removing the parts of the code that were structured to handle it properly in the process, the points you mentioned should be fixed. It's one of the main reasons for having the updater threads in pvr...

@Jalle19
Copy link
Member Author

Jalle19 commented May 23, 2015

@opdenkamp since you're pretty much the only one who is familiar with how it should work (I didn't use PVR many years ago), any chance you might look into it at some point?

@Jalle19
Copy link
Member Author

Jalle19 commented Jul 1, 2015

@opdenkamp while thinking about this again, I realized that the way you want it to work will make the startup code incredibly complicated. Think of this scenario:

  1. The user normally has two addons enabled so he has channels and guide data from both addons.
  2. Start Kodi, and only one addon gets started "in time".
  3. All the channels and guide data from the "stale" addon is removed. This actually takes quite some time, especially the guide data.
  4. Suddenly the second addon wakes up and starts to add data, all the while the data is still being deleted. This sounds like a recipe for a disaster.

{
CLog::Log(LOGINFO, "PVRManager - %s - %d of %d enabled clients connected in time, continue to start",
__FUNCTION__, numConnectedClients, numEnabledClients);
}

This comment was marked as spam.

@Jalle19
Copy link
Member Author

Jalle19 commented Jan 25, 2016

Got some fresh complaints about us never fixing this bug (http://trac.kodi.tv/ticket/14498), any chance we could just show this if I fix the outstanding comments (not the architectural ones)?

@Jalle19
Copy link
Member Author

Jalle19 commented Jan 25, 2016

Added some fixups, squashed the last [squash] commit.

jenkins build this please

@Jalle19
Copy link
Member Author

Jalle19 commented Aug 25, 2016

Supposed to be obsolete

@Jalle19 Jalle19 closed this Aug 25, 2016
@zag2me
Copy link
Contributor

zag2me commented Aug 25, 2016

Is this possible to do yet? I'm using DVBS-2 and now have IPTV also, I'm happy to write a guide if it does work....

@ksooo
Copy link
Member

ksooo commented Aug 25, 2016

Is this possible to do yet? I'm using DVBS-2 and now have IPTV also, I'm happy to write a guide if it does work....

Not supported, works only by luck if at all.

To realize your use case, I'd route iptv through tvheadend.

@Jalle19
Copy link
Member Author

Jalle19 commented Aug 25, 2016

Just enable more than one PVR client

@ksooo
Copy link
Member

ksooo commented Aug 25, 2016

Just enable more than one PVR client

... which does not work reliably as we know. No?

@Jalle19
Copy link
Member Author

Jalle19 commented Aug 25, 2016

I thought it was fixed now that the manager is started asynchronously?

@ksooo
Copy link
Member

ksooo commented Aug 25, 2016

@FernetMenta ^^^ ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: PVR Type: Fix non-breaking change which fixes an issue Type: Improvement non-breaking change which improves existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants