19 #define RUNNINGSTATUSTIMEOUT 30 // seconds before the running status is considered unknown
20 #define EPGDATAWRITEDELTA 600 // seconds between writing the epg.data file
33 unsigned int Stream, Type;
70 esyslog(
"ERROR: out of memory");
102 Stream == 2 && (
components[i].type < 5) == (Type < 5)
245 aux = Aux ? strdup(Aux) : NULL;
250 char vpsbuf[64] =
"";
281 switch (Content & 0xF0) {
283 switch (Content & 0x0F) {
285 case 0x00:
return tr(
"Content$Movie/Drama");
286 case 0x01:
return tr(
"Content$Detective/Thriller");
287 case 0x02:
return tr(
"Content$Adventure/Western/War");
288 case 0x03:
return tr(
"Content$Science Fiction/Fantasy/Horror");
289 case 0x04:
return tr(
"Content$Comedy");
290 case 0x05:
return tr(
"Content$Soap/Melodrama/Folkloric");
291 case 0x06:
return tr(
"Content$Romance");
292 case 0x07:
return tr(
"Content$Serious/Classical/Religious/Historical Movie/Drama");
293 case 0x08:
return tr(
"Content$Adult Movie/Drama");
297 switch (Content & 0x0F) {
299 case 0x00:
return tr(
"Content$News/Current Affairs");
300 case 0x01:
return tr(
"Content$News/Weather Report");
301 case 0x02:
return tr(
"Content$News Magazine");
302 case 0x03:
return tr(
"Content$Documentary");
303 case 0x04:
return tr(
"Content$Discussion/Inverview/Debate");
307 switch (Content & 0x0F) {
309 case 0x00:
return tr(
"Content$Show/Game Show");
310 case 0x01:
return tr(
"Content$Game Show/Quiz/Contest");
311 case 0x02:
return tr(
"Content$Variety Show");
312 case 0x03:
return tr(
"Content$Talk Show");
316 switch (Content & 0x0F) {
318 case 0x00:
return tr(
"Content$Sports");
319 case 0x01:
return tr(
"Content$Special Event");
320 case 0x02:
return tr(
"Content$Sport Magazine");
321 case 0x03:
return tr(
"Content$Football/Soccer");
322 case 0x04:
return tr(
"Content$Tennis/Squash");
323 case 0x05:
return tr(
"Content$Team Sports");
324 case 0x06:
return tr(
"Content$Athletics");
325 case 0x07:
return tr(
"Content$Motor Sport");
326 case 0x08:
return tr(
"Content$Water Sport");
327 case 0x09:
return tr(
"Content$Winter Sports");
328 case 0x0A:
return tr(
"Content$Equestrian");
329 case 0x0B:
return tr(
"Content$Martial Sports");
333 switch (Content & 0x0F) {
335 case 0x00:
return tr(
"Content$Children's/Youth Programme");
336 case 0x01:
return tr(
"Content$Pre-school Children's Programme");
337 case 0x02:
return tr(
"Content$Entertainment Programme for 6 to 14");
338 case 0x03:
return tr(
"Content$Entertainment Programme for 10 to 16");
339 case 0x04:
return tr(
"Content$Informational/Educational/School Programme");
340 case 0x05:
return tr(
"Content$Cartoons/Puppets");
344 switch (Content & 0x0F) {
346 case 0x00:
return tr(
"Content$Music/Ballet/Dance");
347 case 0x01:
return tr(
"Content$Rock/Pop");
348 case 0x02:
return tr(
"Content$Serious/Classical Music");
349 case 0x03:
return tr(
"Content$Folk/Tradional Music");
350 case 0x04:
return tr(
"Content$Jazz");
351 case 0x05:
return tr(
"Content$Musical/Opera");
352 case 0x06:
return tr(
"Content$Ballet");
356 switch (Content & 0x0F) {
358 case 0x00:
return tr(
"Content$Arts/Culture");
359 case 0x01:
return tr(
"Content$Performing Arts");
360 case 0x02:
return tr(
"Content$Fine Arts");
361 case 0x03:
return tr(
"Content$Religion");
362 case 0x04:
return tr(
"Content$Popular Culture/Traditional Arts");
363 case 0x05:
return tr(
"Content$Literature");
364 case 0x06:
return tr(
"Content$Film/Cinema");
365 case 0x07:
return tr(
"Content$Experimental Film/Video");
366 case 0x08:
return tr(
"Content$Broadcasting/Press");
367 case 0x09:
return tr(
"Content$New Media");
368 case 0x0A:
return tr(
"Content$Arts/Culture Magazine");
369 case 0x0B:
return tr(
"Content$Fashion");
373 switch (Content & 0x0F) {
375 case 0x00:
return tr(
"Content$Social/Political/Economics");
376 case 0x01:
return tr(
"Content$Magazine/Report/Documentary");
377 case 0x02:
return tr(
"Content$Economics/Social Advisory");
378 case 0x03:
return tr(
"Content$Remarkable People");
382 switch (Content & 0x0F) {
384 case 0x00:
return tr(
"Content$Education/Science/Factual");
385 case 0x01:
return tr(
"Content$Nature/Animals/Environment");
386 case 0x02:
return tr(
"Content$Technology/Natural Sciences");
387 case 0x03:
return tr(
"Content$Medicine/Physiology/Psychology");
388 case 0x04:
return tr(
"Content$Foreign Countries/Expeditions");
389 case 0x05:
return tr(
"Content$Social/Spiritual Sciences");
390 case 0x06:
return tr(
"Content$Further Education");
391 case 0x07:
return tr(
"Content$Languages");
395 switch (Content & 0x0F) {
397 case 0x00:
return tr(
"Content$Leisure/Hobbies");
398 case 0x01:
return tr(
"Content$Tourism/Travel");
399 case 0x02:
return tr(
"Content$Handicraft");
400 case 0x03:
return tr(
"Content$Motoring");
401 case 0x04:
return tr(
"Content$Fitness & Health");
402 case 0x05:
return tr(
"Content$Cooking");
403 case 0x06:
return tr(
"Content$Advertisement/Shopping");
404 case 0x07:
return tr(
"Content$Gardening");
408 switch (Content & 0x0F) {
409 case 0x00:
return tr(
"Content$Original Language");
410 case 0x01:
return tr(
"Content$Black & White");
411 case 0x02:
return tr(
"Content$Unpublished");
412 case 0x03:
return tr(
"Content$Live Broadcast");
447 strftime(buf,
sizeof(buf),
"%d.%m. %R", localtime_r(&
vps, &tm_r));
456 fprintf(f,
"%sT %s\n", Prefix,
title);
458 fprintf(f,
"%sS %s\n", Prefix,
shortText);
465 fprintf(f,
"%sG", Prefix);
475 fprintf(f,
"%sX %s\n", Prefix, *p->
ToString());
479 fprintf(f,
"%sV %ld\n", Prefix,
vps);
482 fprintf(f,
"%s@ %s\n", Prefix,
aux);
486 fprintf(f,
"%se\n", Prefix);
505 int c = strtol(t, &tail, 16);
506 if (0x00 < c && c <= 0xFF) {
521 case 'V':
SetVps(atoi(t));
526 default:
esyslog(
"ERROR: unexpected tag while reading EPG data: %s", s);
538 while ((s = ReadLine.
Read(f)) != NULL) {
542 case 'E':
if (!Event) {
548 int n = sscanf(t,
"%u %ld %d %X %X", &EventID, &StartTime, &Duration, &TableID, &Version);
549 if (n >= 3 && n <= 5) {
555 Event = newEvent =
new cEvent(EventID);
568 case 'e':
if (Event && !Event->
Title())
574 default:
if (Event && !Event->
Parse(s)) {
575 esyslog(
"ERROR: EPG data problem in line %d", Line);
580 esyslog(
"ERROR: unexpected end of file while reading EPG data");
585 #define MAXEPGBUGFIXSTATS 13
586 #define MAXEPGBUGFIXCHANS 100
602 for (; i < p->
n; i++) {
614 static time_t LastReport = 0;
615 time_t now = time(NULL);
616 if (now - LastReport > 3600 || Force) {
619 struct tm *ptm = localtime_r(&now, &tm_r);
620 if (ptm->tm_hour != 5)
625 bool GotHits =
false;
628 const char *delim =
" ";
631 bool PrintedStats =
false;
635 for (
int c = 0; c < p->
n; c++) {
638 dsyslog(
"=====================");
639 dsyslog(
"EPG bugfix statistics");
640 dsyslog(
"=====================");
641 dsyslog(
"IF SOMEBODY WHO IS IN CHARGE OF THE EPG DATA FOR ONE OF THE LISTED");
642 dsyslog(
"CHANNELS READS THIS: PLEASE TAKE A LOOK AT THE FUNCTION cEvent::FixEpgBugs()");
643 dsyslog(
"IN VDR/epg.c TO LEARN WHAT'S WRONG WITH YOUR DATA, AND FIX IT!");
644 dsyslog(
"=====================");
649 q += snprintf(q,
sizeof(buffer) - (q - buffer),
"%-3d %-4d", i, p->
hits);
652 q += snprintf(q,
sizeof(buffer) - (q - buffer),
"%s%s", delim, Channel->Name());
654 if (q - buffer > 80) {
655 q += snprintf(q,
sizeof(buffer) - (q - buffer),
"%s...", delim);
666 dsyslog(
"=====================");
677 if (l == 2 && *p == 0xC2)
679 if (*p == 0x86 || *p == 0x87 || *p == 0x0D) {
680 memmove(s, p + 1, len - l + 1);
713 const char *delim =
"\".";
714 char *e = strstr(p + 1, delim);
717 char *s = strdup(p + 1);
718 char *d = strdup(e + strlen(delim));
783 #define MAX_USEFUL_EPISODE_LENGTH 40
847 case 0x08: p->
description = strdup(
">16:9");
break;
849 case 0x0D: p->
description = strdup(
"HD 4:3");
break;
853 case 0x0F: p->
description = strdup(
"HD 16:9");
break;
855 case 0x10: p->
description = strdup(
"HD >16:9");
break;
874 case 0x05: p->
description = strdup(
"Dolby Digital");
break;
966 time_t now = time(NULL);
968 if (p->StartTime() <= now)
970 else if (p->StartTime() > now + 3600)
984 time_t now = time(NULL);
1006 time_t delta = INT_MAX;
1009 if (dt >= 0 && dt < delta && p->EndTime() >= Time) {
1023 p->SetRunningStatus(RunningStatus, Channel);
1051 p->SetVersion(0xFF);
1070 if (SegmentStart > 0 && SegmentEnd > 0) {
1074 if (p->
EndTime() > SegmentStart) {
1110 fprintf(f,
"%sC %s %s\n", Prefix, *Channel->GetChannelID().ToString(), Channel->Name());
1133 default:
esyslog(
"ERROR: unknown DumpMode %d (%s %d)", DumpMode, __FUNCTION__, __LINE__);
1135 fprintf(f,
"%sc\n", Prefix);
1145 while ((s = ReadLine.
Read(f)) != NULL) {
1149 char *p = strchr(s,
' ');
1154 if (channelID.
Valid()) {
1162 esyslog(
"ERROR: invalid channel ID: %s", s);
1168 esyslog(
"ERROR: unexpected tag in line %d while reading EPG data: %s", Line, s);
1184 virtual void Action(
void);
1192 :
cThread(
"epg data writer", true)
1208 time_t now = time(NULL);
1209 for (
cSchedule *p = Schedules->First(); p; p = Schedules->
Next(p))
1252 time_t now = time(NULL);
1256 else if (!EpgDataWriter.
Active())
1257 EpgDataWriter.
Start();
1265 for (
cSchedule *Schedule = Schedules->First(); Schedule; Schedule = Schedules->
Next(Schedule))
1266 Schedule->ResetVersions();
1284 for (
const cSchedule *p = Schedules->First(); p; p = Schedules->
Next(p))
1285 p->Dump(Channels, f, Prefix, DumpMode, AtTime);
1295 bool OwnFile = f == NULL;
1314 for (
cChannel *Channel = Channels->First(); Channel; Channel = Channels->
Next(Channel))
1315 Schedules->GetSchedule(Channel);
1335 if (p->ChannelID() == ChannelID)
1349 Channel->
schedule = &DummySchedule;
1350 if (Channel->
schedule == &DummySchedule && AddIfMissing) {
1389 if (eh->IgnoreChannel(Channel))
1398 if (eh->HandleEitEvent(Schedule, EitEvent, TableID, Version))
1407 if (eh->HandledExternally(Channel))
1416 if (eh->IsUpdate(EventID, StartTime, TableID, Version))
1425 if (eh->SetEventID(Event, EventID))
1434 if (eh->SetTitle(Event, Title))
1443 if (eh->SetShortText(Event, ShortText))
1452 if (eh->SetDescription(Event, Description))
1461 if (eh->SetContents(Event, Contents))
1470 if (eh->SetParentalRating(Event, ParentalRating))
1479 if (eh->SetStartTime(Event, StartTime))
1488 if (eh->SetDuration(Event, Duration))
1497 if (eh->SetVps(Event, Vps))
1506 if (eh->SetComponents(Event, Components))
1515 if (eh->FixEpgBugs(Event))
1524 if (eh->HandleEvent(Event))
1532 if (eh->SortSchedule(Schedule))
1541 if (eh->DropOutdated(Schedule, SegmentStart, SegmentEnd, TableID, Version))
1544 Schedule->
DropOutdated(SegmentStart, SegmentEnd, TableID, Version);
1550 if (!eh->BeginSegmentTransfer(Channel,
false))
1559 if (eh->EndSegmentTransfer(Modified,
false))
bool Lock(cStateKey &StateKey, bool Write=false, int TimeoutMs=0) const
Tries to get a lock on this list and returns true if successful.
const cEvent * GetPresentEvent(void) const
tChannelID channelIDs[MAXEPGBUGFIXCHANS]
void SetContents(uchar *Contents)
void SetContents(cEvent *Event, uchar *Contents)
tComponent * GetComponent(int Index, uchar Stream, uchar Type)
static tChannelID FromString(const char *s)
bool HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version)
time_t EndTime(void) const
void SetComponent(int Index, const char *s)
void IncNumTimers(void) const
static void ResetVersions(void)
#define MAX_USEFUL_EPISODE_LENGTH
static const cSchedules * GetSchedulesRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of schedules for read access.
void SetDescription(cEvent *Event, const char *Description)
void SetStartTime(time_t StartTime)
cSchedule(tChannelID ChannelID)
void SetDuration(int Duration)
void SetTableID(uchar TableID)
tChannelID ChannelID(void) const
void Add(cListObject *Object, cListObject *After=NULL)
cString ToDescr(void) const
static cMutex numTimersMutex
char language[MAXLANGCODE2]
static const char * ContentToString(uchar Content)
cString GetParentalRatingString(void) const
static cString sprintf(const char *fmt,...) __attribute__((format(printf
void Del(cListObject *Object, unsigned int Id)
void ReportEpgBugFixStats(bool Force)
void DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version)
void SetParentalRating(cEvent *Event, int ParentalRating)
void Dump(const cChannels *Channels, FILE *f, const char *Prefix="", eDumpMode DumpMode=dmAll, time_t AtTime=0) const
void Remove(bool IncState=true)
Removes this key from the lock it was previously used with.
void SetTitle(cEvent *Event, const char *Title)
void SetEventID(cEvent *Event, tEventID EventID)
cHash< cEvent > eventsHashID
uchar Contents(int i=0) const
tComponent * Component(int Index) const
time_t StartTime(void) const
bool HandledExternally(const cChannel *Channel)
static bool Dump(FILE *f=NULL, const char *Prefix="", eDumpMode DumpMode=dmAll, time_t AtTime=0)
T * Get(unsigned int Id) const
void SetShortText(const char *ShortText)
#define LOCK_CHANNELS_WRITE
const cSchedule * schedule
static void SetEpgDataFileName(const char *FileName)
bool BeginSegmentTransfer(const cChannel *Channel)
void ClrRunningStatus(cChannel *Channel=NULL)
void SetComponents(cComponents *Components)
void HandleEvent(cEvent *Event)
cString GetVpsString(void) const
void SetTitle(const char *Title)
void SetStartTime(cEvent *Event, time_t StartTime)
int ParentalRating(void) const
const char * Name(void) const
static void EpgBugFixStat(int Number, tChannelID ChannelID)
uchar TableID(void) const
static cEpgDataWriter EpgDataWriter
static void StripControlCharacters(char *s)
const cChannel * GetByChannelID(tChannelID ChannelID, bool TryWithoutRid=false, bool TryWithoutPolarization=false) const
#define MAXEPGBUGFIXSTATS
cListObject * Next(void) const
static bool Read(FILE *f, cSchedules *Schedules)
#define LOCK_CHANNELS_READ
tChannelID ChannelID(void) const
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
const cEvent * GetEvent(tEventID EventID, time_t StartTime=0) const
void SetDuration(cEvent *Event, int Duration)
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
const cEvent * GetEventAround(time_t Time) const
static bool Read(FILE *f=NULL)
static char * epgDataFileName
void FixEpgBugs(cEvent *Event)
static void Cleanup(bool Force=false)
static int Utf8CharLen(const char *s)
tChannelID GetChannelID(void) const
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
int RunningStatus(void) const
tEventID EventID(void) const
void SortSchedule(cSchedule *Schedule)
void SetAux(const char *Aux)
tEpgBugFixStats EpgBugFixStats[MAXEPGBUGFIXSTATS]
bool FromString(const char *s)
void SetPresentSeen(void)
cEvent * AddEvent(cEvent *Event)
const char * Title(void) const
void SetVps(cEvent *Event, time_t Vps)
bool IgnoreChannel(const cChannel *Channel)
void HashEvent(cEvent *Event)
cString GetEndTimeString(void) const
const cSchedule * GetSchedule(tChannelID ChannelID) const
static cSchedules * GetSchedulesWrite(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of schedules for write access.
void DropOutdated(time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version)
void Del(cListObject *Object, bool DeleteObject=true)
void SetParentalRating(int ParentalRating)
void SetDescription(const char *Description)
bool Active(void)
Checks whether the thread is still alive.
void Dump(FILE *f, const char *Prefix="", bool InfoOnly=false) const
void DecNumTimers(void) const
void SetRunningStatus(int RunningStatus, const cChannel *Channel=NULL)
#define MAXEPGBUGFIXCHANS
static cSchedules schedules
cEpgHandler(void)
Constructs a new EPG handler and adds it to the list of EPG handlers.
uchar contents[MaxEventContents]
void DelEvent(cEvent *Event)
cString GetTimeString(void) const
int NumComponents(void) const
static bool Read(FILE *f, cSchedule *Schedule, int &Line)
#define EPGDATAWRITEDELTA
void SetVersion(uchar Version)
cSchedule * AddSchedule(tChannelID ChannelID)
const cComponents * Components(void) const
void Add(cListObject *Object, unsigned int Id)
static const tChannelID InvalidID
#define LOCK_SCHEDULES_WRITE
#define RUNNINGSTATUSTIMEOUT
bool IsRunning(bool OrAboutToStart=false) const
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
void SetComponents(cEvent *Event, cComponents *Components)
void SetEventID(tEventID EventID)
void DecNumTimers(void) const
static cMutex numTimersMutex
cString GetDateString(void) const
cHash< cEvent > eventsHashStartTime
bool HasTimer(void) const
#define LOCK_SCHEDULES_READ
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater", and a negative value if it is "smaller".
void SetShortText(cEvent *Event, const char *ShortText)
void SetRunningStatus(cEvent *Event, int RunningStatus, const cChannel *Channel=NULL)
bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version)
tChannelID & ClrRid(void)
void SetUseGarbageCollector(void)
bool HasTimer(void) const
void UnhashEvent(cEvent *Event)
void EndSegmentTransfer(bool Modified)
uchar Version(void) const
void IncNumTimers(void) const
const cEvent * GetFollowingEvent(void) const