Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: improve EPG event update scheme, always check broadcast duration…
… in fuzzy match
  • Loading branch information
perexg committed Oct 30, 2015
1 parent 48f04e3 commit 23576ab
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/dvr/dvr.h
Expand Up @@ -497,6 +497,8 @@ void dvr_rec_migrate(dvr_entry_t *de_old, dvr_entry_t *de_new);

void dvr_event_replaced(epg_broadcast_t *e, epg_broadcast_t *new_e);

void dvr_event_removed(epg_broadcast_t *e);

void dvr_event_updated(epg_broadcast_t *e);

dvr_entry_t *dvr_entry_find_by_id(int id);
Expand Down
40 changes: 29 additions & 11 deletions src/dvr/dvr_db.c
Expand Up @@ -111,6 +111,7 @@ dvr_entry_assign_broadcast(dvr_entry_t *de, epg_broadcast_t *bcast)
de->de_bcast->putref((epg_object_t*)de->de_bcast);
notify_delayed(id, "epg", "dvr_delete");
de->de_bcast = NULL;
de->de_dvb_eid = 0;
}
if (bcast) {
bcast->getref((epg_object_t*)bcast);
Expand Down Expand Up @@ -582,6 +583,12 @@ dvr_entry_fuzzy_match(dvr_entry_t *de, epg_broadcast_t *e, uint16_t eid, int64_t
const char *title1, *title2;
char buf[64];

/* Wrong length (+/-20%) */
t1 = de->de_stop - de->de_start;
t2 = e->stop - e->start;
if (abs(t2 - t1) > (t1 / 5))
return 0;

/* Matching ID */
if (de->de_dvb_eid && eid && de->de_dvb_eid == eid)
return 1;
Expand All @@ -592,12 +599,6 @@ dvr_entry_fuzzy_match(dvr_entry_t *de, epg_broadcast_t *e, uint16_t eid, int64_t
if (!(title2 = lang_str_get(de->de_title, NULL)))
return 0;

/* Wrong length (+/-20%) */
t1 = de->de_stop - de->de_start;
t2 = e->stop - e->start;
if ( abs(t2 - t1) > (t1 / 5) )
return 0;

/* Outside of window */
if ((int64_t)llabs(e->start - de->de_start) > time_window)
return 0;
Expand Down Expand Up @@ -1448,7 +1449,7 @@ dvr_event_replaced(epg_broadcast_t *e, epg_broadcast_t *new_e)
assert(new_e != NULL);

/* Ignore */
if ( e == new_e ) return;
if (e == new_e) return;

/* Existing entry */
if ((de = dvr_entry_find_by_event(e))) {
Expand All @@ -1472,6 +1473,7 @@ dvr_event_replaced(epg_broadcast_t *e, epg_broadcast_t *new_e)

/* Find match */
} else {

RB_FOREACH(e, &e->channel->ch_epg_schedule, sched_link) {
if (dvr_entry_fuzzy_match(de, e, e->dvb_eid,
de->de_config->dvr_update_window)) {
Expand All @@ -1481,17 +1483,34 @@ dvr_event_replaced(epg_broadcast_t *e, epg_broadcast_t *new_e)
epg_broadcast_get_title(e, NULL),
channel_get_name(e->channel),
e->start, e->stop);
dvr_entry_assign_broadcast(de, e);
_dvr_entry_update(de, -1, e, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, DVR_PRIO_NOTSET, 0, 0);
_dvr_entry_update(de, -1, e, NULL, NULL, NULL, NULL, NULL,
0, 0, 0, 0, DVR_PRIO_NOTSET, 0, 0);
return;
}
}
dvr_entry_assign_broadcast(de, NULL);

}
}
}

void dvr_event_updated ( epg_broadcast_t *e )
/**
* Used to notify the DVR that an event has been removed
*/
void
dvr_event_removed(epg_broadcast_t *e)
{
dvr_entry_t *de = dvr_entry_find_by_event(e);
if (de) {
dvr_entry_assign_broadcast(de, NULL);
dvr_entry_save(de);
}
}

/**
* Event was updated in epg
*/
void dvr_event_updated(epg_broadcast_t *e)
{
dvr_entry_t *de;
de = dvr_entry_find_by_event(e);
Expand All @@ -1511,7 +1530,6 @@ void dvr_event_updated ( epg_broadcast_t *e )
epg_broadcast_get_title(e, NULL),
channel_get_name(e->channel),
e->start, e->stop);
dvr_entry_assign_broadcast(de, e);
_dvr_entry_update(de, -1, e, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, DVR_PRIO_NOTSET, 0, 0);
break;
}
Expand Down
8 changes: 6 additions & 2 deletions src/epg.c
Expand Up @@ -1397,12 +1397,16 @@ epg_serieslink_t *epg_serieslink_deserialize
* *************************************************************************/

static void _epg_channel_rem_broadcast
( channel_t *ch, epg_broadcast_t *ebc, epg_broadcast_t *new )
( channel_t *ch, epg_broadcast_t *ebc, epg_broadcast_t *ebc_new )
{
if (new) dvr_event_replaced(ebc, new);
RB_REMOVE(&ch->ch_epg_schedule, ebc, sched_link);
if (ch->ch_epg_now == ebc) ch->ch_epg_now = NULL;
if (ch->ch_epg_next == ebc) ch->ch_epg_next = NULL;
if (ebc_new) {
dvr_event_replaced(ebc, ebc_new);
} else {
dvr_event_removed(ebc);
}
_epg_object_putref(ebc);
}

Expand Down

0 comments on commit 23576ab

Please sign in to comment.