Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
EPG: improve overlap removal (handle grabber priorities)
  • Loading branch information
perexg committed May 4, 2016
1 parent 78122a1 commit d4384a5
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/epg.c
Expand Up @@ -186,16 +186,26 @@ static void _epg_object_set_updated ( void *o )
}
}

static int _epg_object_set_grabber ( void *o, epggrab_module_t *grab )
static int _epg_object_can_remove ( void *_old, void *_new )
{
epggrab_module_t *ograb, *ngrab;
ngrab = ((epg_object_t *)_new)->grabber;
if (ngrab == NULL) return 0;
ograb = ((epg_object_t *)_old)->grabber;
if (ograb == NULL || ograb == ngrab) return 1;
if (ngrab->priority > ograb->priority) return 1;
return 0;

This comment has been minimized.

Copy link
@ksooo

ksooo Aug 25, 2016

Contributor

@perexg: If i read this correct, this will return zero if oldgrabber != null && oldgrabber != newgrabber && newprio <= oldprio. Is it inteded to return zero if newprio == oldprio?

This comment has been minimized.

Copy link
@perexg

perexg Aug 25, 2016

Author Contributor

If you have two grabbers with the same priority, the first grabber wins, otherwise you may end with ping-pong effect - switching grabbers when they receive new/updated data.

}

static int _epg_object_set_grabber ( void *o, epggrab_module_t *ngrab )
{
epg_object_t *eo = o;
if (!grab) return 1; // grab=NULL is override
if (!eo->grabber ||
((eo->grabber != grab) && (grab->priority > eo->grabber->priority))) {
eo->grabber = grab;
return 1;
}
return grab == eo->grabber;
epggrab_module_t *ograb;
if (!ngrab) return 1; // grab=NULL is override
ograb = ((epg_object_t *)o)->grabber;
if (ograb == ngrab) return 1;
if (ograb && ograb->priority >= ngrab->priority) return 0;

This comment has been minimized.

Copy link
@ksooo

ksooo Aug 25, 2016

Contributor

@perexg: doesn't this change behavior? If yes, is it intended?

old:

if (oldgrabber != newgrabber && oldprio == newprio)
  return 0;

new:

if (oldgrabber != newgrabber &&  oldprio == newprio)
  return 1;
((epg_object_t *)o)->grabber = ngrab;
return 1;
}

static void _epg_object_create ( void *o )
Expand Down Expand Up @@ -1662,6 +1672,11 @@ static epg_broadcast_t *_epg_channel_add_broadcast
/* Remove overlapping (before) */
while ((ebc = RB_PREV(ret, sched_link)) != NULL) {
if (ebc->stop <= ret->start) break;
if (!_epg_object_can_remove(ebc, ret)) {
tvhtrace("epg", "grabber for event %u has lower priority than overlap (b), removing", ebc->id);

This comment has been minimized.

Copy link
@ksooo

ksooo Aug 25, 2016

Contributor

@perexg This implies that it is not intended that _epg_object_can_remove returns zero in case newprio == oldprio!?

_epg_channel_rem_broadcast(ch, ret, NULL);
return NULL;
}
tvhtrace("epg", "remove overlap (b) event %u (%s) on %s @ %"PRItime_t " to %"PRItime_t,
ebc->id, epg_broadcast_get_title(ebc, NULL),
channel_get_name(ch), ebc->start, ebc->stop);
Expand All @@ -1671,6 +1686,11 @@ static epg_broadcast_t *_epg_channel_add_broadcast
/* Remove overlapping (after) */
while ((ebc = RB_NEXT(ret, sched_link)) != NULL) {
if (ebc->start >= ret->stop) break;
if (!_epg_object_can_remove(ebc, ret)) {
tvhtrace("epg", "grabber for event %u has lower priority than overlap (a), removing", ebc->id);
_epg_channel_rem_broadcast(ch, ret, NULL);
return NULL;
}
tvhtrace("epg", "remove overlap (a) event %u (%s) on %s @ %"PRItime_t " to %"PRItime_t,
ebc->id, epg_broadcast_get_title(ebc, NULL),
channel_get_name(ch), ebc->start, ebc->stop);
Expand Down

0 comments on commit d4384a5

Please sign in to comment.