Improved matching timers to EPG events

This commit is contained in:
Klaus Schmidinger 2005-03-13 11:42:59 +01:00
parent 25b8a40eef
commit 57e34f6240
3 changed files with 50 additions and 26 deletions

View File

@ -3444,7 +3444,7 @@ Video Disk Recorder Revision History
- Fixed handling repeated kAudio keys.
- Improved displaying the the current audio track in the ST:TNG channel display.
2005-03-12: Version 1.3.23
2005-03-13: Version 1.3.23
- The setup option "DVB/Video display format" is now only available if "Video format"
is set to "4:3" (suggested by Mikko Salo).
@ -3453,3 +3453,5 @@ Video Disk Recorder Revision History
- Updated the Finnish OSD texts (thanks to Rolf Ahrenberg).
- Updated the Swedish OSD texts (thanks to Tomas Prybil).
- Fixed a few French OSD texts that were in the wrong place.
- Improved matching timers to EPG events, especially in case there are several events
with the same VPS time.

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: timers.c 1.22 2005/02/06 09:45:52 kls Exp $
* $Id: timers.c 1.23 2005/03/13 11:42:59 kls Exp $
*/
#include "timers.h"
@ -353,24 +353,26 @@ bool cTimer::Matches(time_t t, bool Directly) const
return false;
}
int cTimer::Matches(const cEvent *Event)
#define FULLMATCH 1000
int cTimer::Matches(const cEvent *Event, int *Overlap)
{
if (channel->GetChannelID() == Event->ChannelID()) {
if (HasFlags(tfActive) && channel->GetChannelID() == Event->ChannelID()) {
bool UseVps = HasFlags(tfVps) && Event->Vps();
time_t t1 = UseVps ? Event->Vps() : Event->StartTime();
time_t t2 = t1 + Event->Duration();
bool m1 = Matches(t1, true);
bool m2 = UseVps ? m1 : Matches(t2, true);
Matches(UseVps ? Event->Vps() : Event->StartTime(), true);
int overlap;
if (UseVps)
overlap = (startTime == Event->Vps()) ? FULLMATCH + (Event->IsRunning() ? 200 : 100) : 0;
else if (startTime <= Event->StartTime() && Event->EndTime() <= stopTime)
overlap = FULLMATCH;
else if (stopTime <= Event->StartTime() || Event->EndTime() <= startTime)
overlap = 0;
else
overlap = (min(stopTime, Event->EndTime()) - max(startTime, Event->StartTime())) * FULLMATCH / max(Event->Duration(), 1);
startTime = stopTime = 0;
if (m1 && m2) {
if (UseVps && Event->IsRunning(true))
return tmFull;
if (time(NULL) > Event->EndTime())
return tmNone;
return tmFull;
}
if ((m1 || m2) && time(NULL) <= Event->EndTime())
return tmPartial;
if (Overlap)
*Overlap = overlap;
return overlap >= 1000 ? tmFull : overlap > 0 ? tmPartial : tmNone;
}
return tmNone;
}
@ -536,6 +538,8 @@ bool cTimers::Modified(void)
return Result;
}
#define EPGLIMIT (12 * 3600) // time in seconds around now, within which EPG events will be taken into consideration
void cTimers::SetEvents(void)
{
if (time(NULL) - lastSetEvents < 5)
@ -549,17 +553,35 @@ void cTimers::SetEvents(void)
if (Schedule) {
if (!lastSetEvents || Schedule->Modified() >= lastSetEvents) {
const cEvent *Event = NULL;
int Match = tmNone;
int Overlap = 0;
int Distance = INT_MIN;
time_t now = time(NULL);
for (const cEvent *e = Schedule->Events()->First(); e; e = Schedule->Events()->Next(e)) {
if (cRemote::HasKeys())
return; // react immediately on user input
int m = ti->Matches(e);
if (m > Match) {
Match = m;
if (e->EndTime() < now - EPGLIMIT)
continue; // skip old events
if (e->StartTime() > now + EPGLIMIT)
break; // no need to process events too far in the future
int overlap = 0;
ti->Matches(e, &overlap);
if (overlap && overlap >= Overlap) {
int distance = 0;
if (now < e->StartTime())
distance = e->StartTime() - now;
else if (now > e->EndTime())
distance = e->EndTime() - now;
if (Event && overlap == Overlap) {
if (Overlap > FULLMATCH) { // this means VPS
if (abs(Distance) < abs(distance))
break; // we've already found the closest VPS event
}
else if (e->Duration() <= Event->Duration())
continue; // if overlap is the same, we take the longer event
}
Overlap = overlap;
Distance = distance;
Event = e;
if (Match == tmFull)
break;
//XXX what if there's another event with the same VPS time???
}
}
ti->SetEvent(Event);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: timers.h 1.13 2004/12/26 12:21:29 kls Exp $
* $Id: timers.h 1.14 2005/03/12 16:27:36 kls Exp $
*/
#ifndef __TIMERS_H
@ -71,7 +71,7 @@ public:
static time_t SetTime(time_t t, int SecondsFromMidnight);
char *SetFile(const char *File);
bool Matches(time_t t = 0, bool Directly = false) const;
int Matches(const cEvent *Event);
int Matches(const cEvent *Event, int *Overlap = NULL);
time_t StartTime(void) const;
time_t StopTime(void) const;
void SetEvent(const cEvent *Event);