vdr 2.6.1
include/vdr/epg.h
Go to the documentation of this file.
1/*
2 * epg.h: Electronic Program Guide
3 *
4 * See the main source file 'vdr.c' for copyright information and
5 * how to reach the author.
6 *
7 * Original version (as used in VDR before 1.3.0) written by
8 * Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>.
9 *
10 * $Id: epg.h 5.2 2021/04/28 20:44:56 kls Exp $
11 */
12
13#ifndef __EPG_H
14#define __EPG_H
15
16#include "channels.h"
17#include "libsi/section.h"
18#include "thread.h"
19#include "tools.h"
20
21#define MAXEPGBUGFIXLEVEL 3
22
23#define EPG_LINGER_TIME (max(Setup.EPGLinger, 180) * 60) // seconds to keep old EPG data (internal, must be at least Setup.EPGLinger)
24
25enum { MaxEventContents = 4 };
26
30 ecgShow = 0x30,
31 ecgSports = 0x40,
38 ecgSpecial = 0xB0,
39 ecgUserDefined = 0xF0
40 };
41
43
44struct tComponent {
46 uchar type;
48 char *description;
50 bool FromString(const char *s);
51 };
52
53class cComponents {
54private:
55 int numComponents;
57 bool Realloc(int Index);
58public:
61 int NumComponents(void) const { return numComponents; }
62 void SetComponent(int Index, const char *s);
63 void SetComponent(int Index, uchar Stream, uchar Type, const char *Language, const char *Description);
64 tComponent *Component(int Index) const { return (Index < numComponents) ? &components[Index] : NULL; }
65 tComponent *GetComponent(int Index, uchar Stream, uchar Type); // Gets the Index'th component of Stream and Type, skipping other components
66 // In case of an audio stream the 'type' check actually just distinguishes between "normal" and "Dolby Digital"
67 };
68
69class cSchedule;
70
71typedef u_int32_t tEventID;
72
73class cEvent : public cListObject {
74 friend class cSchedule;
75private:
76 static cMutex numTimersMutex; // Protects numTimers, because it might be accessed from parallel read locks
77 // The sequence of these parameters is optimized for minimal memory waste!
78 cSchedule *schedule; // The Schedule this event belongs to
79 mutable u_int16_t numTimers;// The number of timers that use this event
80 tEventID eventID; // Event ID of this event
81 uchar tableID; // Table ID this event came from
82 uchar version; // Version number of section this event came from
83 uchar runningStatus; // 0=undefined, 1=not running, 2=starts in a few seconds, 3=pausing, 4=running
84 uchar parentalRating; // Parental rating of this event
85 char *title; // Title of this event
86 char *shortText; // Short description of this event (typically the episode name in case of a series)
87 char *description; // Description of this event
88 cComponents *components; // The stream components of this event
89 time_t startTime; // Start time of this event
90 int duration; // Duration of this event in seconds
91 uchar contents[MaxEventContents]; // Contents of this event
92 time_t vps; // Video Programming Service timestamp (VPS, aka "Programme Identification Label", PIL)
93 time_t seen; // When this event was last seen in the data stream
94 char *aux; // Auxiliary data, for use with plugins
95public:
98 virtual int Compare(const cListObject &ListObject) const;
99 tChannelID ChannelID(void) const;
100 const cSchedule *Schedule(void) const { return schedule; }
101 tEventID EventID(void) const { return eventID; }
102 uchar TableID(void) const { return tableID; }
103 uchar Version(void) const { return version; }
104 int RunningStatus(void) const { return runningStatus; }
105 const char *Title(void) const { return title; }
106 const char *ShortText(void) const { return shortText; }
107 const char *Description(void) const { return description; }
108 const cComponents *Components(void) const { return components; }
109 uchar Contents(int i = 0) const { return (0 <= i && i < MaxEventContents) ? contents[i] : uchar(0); }
110 int ParentalRating(void) const { return parentalRating; }
111 time_t StartTime(void) const { return startTime; }
112 time_t EndTime(void) const { return startTime + duration; }
113 int Duration(void) const { return duration; }
114 time_t Vps(void) const { return vps; }
115 time_t Seen(void) const { return seen; }
116 bool SeenWithin(int Seconds) const { return time(NULL) - seen < Seconds; }
117 const char *Aux(void) const { return aux; }
118 void IncNumTimers(void) const;
119 void DecNumTimers(void) const;
120 bool HasTimer(void) const { return numTimers > 0; }
121 bool IsRunning(bool OrAboutToStart = false) const;
122 static const char *ContentToString(uchar Content);
131 void SetRunningStatus(int RunningStatus, const cChannel *Channel = NULL);
132 void SetTitle(const char *Title);
133 void SetShortText(const char *ShortText);
134 void SetDescription(const char *Description);
135 void SetComponents(cComponents *Components); // Will take ownership of Components!
140 void SetVps(time_t Vps);
141 void SetSeen(void);
142 void SetAux(const char *Aux);
143 cString ToDescr(void) const;
144 void Dump(FILE *f, const char *Prefix = "", bool InfoOnly = false) const;
145 bool Parse(char *s);
146 static bool Read(FILE *f, cSchedule *Schedule, int &Line);
147 void FixEpgBugs(void);
148 };
149
150class cSchedules;
151
152class cSchedule : public cListObject {
153private:
154 static cMutex numTimersMutex; // Protects numTimers, because it might be accessed from parallel read locks
159 mutable u_int16_t numTimers;// The number of timers that use this schedule
160 bool hasRunning;
161 bool onActualTp;
162 int modified;
163 time_t presentSeen;
164public:
166 tChannelID ChannelID(void) const { return channelID; }
167 bool Modified(int &State) const { bool Result = State != modified; State = modified; return Result; }
169 time_t PresentSeen(void) const { return presentSeen; }
170 bool PresentSeenWithin(int Seconds) const { return time(NULL) - presentSeen < Seconds; }
171 void SetModified(void) { modified++; }
172 void SetPresentSeen(void) { presentSeen = time(NULL); }
173 void SetRunningStatus(cEvent *Event, int RunningStatus, const cChannel *Channel = NULL);
174 void ClrRunningStatus(cChannel *Channel = NULL);
175 void ResetVersions(void);
176 void Sort(void);
177 void DropOutdated(time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version);
178 void Cleanup(time_t Time);
179 void Cleanup(void);
180 void IncNumTimers(void) const;
181 void DecNumTimers(void) const;
182 bool HasTimer(void) const { return numTimers > 0; }
184 void DelEvent(cEvent *Event);
185 void HashEvent(cEvent *Event);
186 void UnhashEvent(cEvent *Event);
187 const cList<cEvent> *Events(void) const { return &events; }
188 const cEvent *GetPresentEvent(void) const;
189 const cEvent *GetFollowingEvent(void) const;
190#define DEPRECATED_SCHEDULE_GET_EVENT 1
191#if DEPRECATED_SCHEDULE_GET_EVENT
192 const cEvent *GetEvent(tEventID EventID, time_t StartTime = 0) const;
193#endif
194 const cEvent *GetEventById(tEventID EventID) const;
195 const cEvent *GetEventByTime(time_t StartTime) const;
196 const cEvent *GetEventAround(time_t Time) const;
197 void Dump(const cChannels *Channels, FILE *f, const char *Prefix = "", eDumpMode DumpMode = dmAll, time_t AtTime = 0) const;
198 static bool Read(FILE *f, cSchedules *Schedules);
199 };
200
201class cSchedules : public cList<cSchedule> {
202 friend class cSchedule;
203private:
204 static cSchedules schedules;
205 static char *epgDataFileName;
206 static time_t lastDump;
207public:
209 static const cSchedules *GetSchedulesRead(cStateKey &StateKey, int TimeoutMs = 0);
212 static cSchedules *GetSchedulesWrite(cStateKey &StateKey, int TimeoutMs = 0);
215 static void SetEpgDataFileName(const char *FileName);
216 static void Cleanup(bool Force = false);
217 static void ResetVersions(void);
218 static bool Dump(FILE *f = NULL, const char *Prefix = "", eDumpMode DumpMode = dmAll, time_t AtTime = 0);
219 static bool Read(FILE *f = NULL);
222 const cSchedule *GetSchedule(const cChannel *Channel, bool AddIfMissing = false) const;
223 };
224
225// Provide lock controlled access to the list:
226
227DEF_LIST_LOCK(Schedules);
228
229// These macros provide a convenient way of locking the global schedules list
230// and making sure the lock is released as soon as the current scope is left
231// (note that these macros wait forever to obtain the lock!):
232
233#define LOCK_SCHEDULES_READ USE_LIST_LOCK_READ(Schedules);
234#define LOCK_SCHEDULES_WRITE USE_LIST_LOCK_WRITE(Schedules);
235
236class cEpgDataReader : public cThread {
237public:
239 virtual void Action(void);
240 };
241
242void ReportEpgBugFixStats(bool Force = false);
243
244class cEpgHandler : public cListObject {
245public:
255 virtual ~cEpgHandler();
256 virtual bool IgnoreChannel(const cChannel *Channel) { return false; }
261 virtual bool HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version) { return false; }
266 virtual bool HandledExternally(const cChannel *Channel) { return false; }
272 virtual bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version) { return false; }
276 virtual bool SetEventID(cEvent *Event, tEventID EventID) { return false; }
277 virtual bool SetTitle(cEvent *Event, const char *Title) { return false; }
278 virtual bool SetShortText(cEvent *Event, const char *ShortText) { return false; }
279 virtual bool SetDescription(cEvent *Event, const char *Description) { return false; }
280 virtual bool SetContents(cEvent *Event, uchar *Contents) { return false; }
281 virtual bool SetParentalRating(cEvent *Event, int ParentalRating) { return false; }
282 virtual bool SetStartTime(cEvent *Event, time_t StartTime) { return false; }
283 virtual bool SetDuration(cEvent *Event, int Duration) { return false; }
284 virtual bool SetVps(cEvent *Event, time_t Vps) { return false; }
285 virtual bool SetComponents(cEvent *Event, cComponents *Components) { return false; }
286 virtual bool FixEpgBugs(cEvent *Event) { return false; }
288 virtual bool HandleEvent(cEvent *Event) { return false; }
291 virtual bool SortSchedule(cSchedule *Schedule) { return false; }
293 virtual bool DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version) { return false; }
296 virtual bool BeginSegmentTransfer(const cChannel *Channel, bool Dummy) { return true; } // TODO remove obsolete Dummy
303 virtual bool EndSegmentTransfer(bool Modified, bool Dummy) { return false; } // TODO remove obsolete Dummy
307 };
308
309class cEpgHandlers : public cList<cEpgHandler> {
310public:
311 bool IgnoreChannel(const cChannel *Channel);
312 bool HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version);
313 bool HandledExternally(const cChannel *Channel);
314 bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version);
315 void SetEventID(cEvent *Event, tEventID EventID);
316 void SetTitle(cEvent *Event, const char *Title);
317 void SetShortText(cEvent *Event, const char *ShortText);
318 void SetDescription(cEvent *Event, const char *Description);
319 void SetContents(cEvent *Event, uchar *Contents);
320 void SetParentalRating(cEvent *Event, int ParentalRating);
321 void SetStartTime(cEvent *Event, time_t StartTime);
322 void SetDuration(cEvent *Event, int Duration);
323 void SetVps(cEvent *Event, time_t Vps);
324 void SetComponents(cEvent *Event, cComponents *Components);
325 void FixEpgBugs(cEvent *Event);
326 void HandleEvent(cEvent *Event);
327 void SortSchedule(cSchedule *Schedule);
328 void DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version);
329 bool BeginSegmentTransfer(const cChannel *Channel);
330 void EndSegmentTransfer(bool Modified);
331 };
332
334
335#endif //__EPG_H
#define MAXLANGCODE2
Definition: channels.h:37
tComponent * GetComponent(int Index, uchar Stream, uchar Type)
tComponent * components
Definition: epg.h:56
tComponent * Component(int Index) const
int numComponents
Definition: epg.h:55
cComponents(void)
bool Realloc(int Index)
~cComponents(void)
int NumComponents(void) const
void SetComponent(int Index, const char *s)
void SetComponent(int Index, uchar Stream, uchar Type, const char *Language, const char *Description)
virtual void Action(void)
A derived cThread class must implement the code it wants to execute as a separate thread in this func...
cEpgDataReader(void)
virtual bool SetTitle(cEvent *Event, const char *Title)
virtual bool SetVps(cEvent *Event, time_t Vps)
virtual bool FixEpgBugs(cEvent *Event)
Fixes some known problems with EPG data.
virtual bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version)
VDR can't perform the update check (version, tid) for externally handled events, therefore the EPG ha...
virtual bool SetParentalRating(cEvent *Event, int ParentalRating)
virtual bool HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version)
Before the raw EitEvent for the given Schedule is processed, the EPG handlers are queried to see if a...
virtual bool BeginSegmentTransfer(const cChannel *Channel, bool Dummy)
virtual bool SetEventID(cEvent *Event, tEventID EventID)
virtual bool SetComponents(cEvent *Event, cComponents *Components)
virtual bool IgnoreChannel(const cChannel *Channel)
Before any EIT data for the given Channel is processed, the EPG handlers are asked whether this Chann...
virtual ~cEpgHandler()
cEpgHandler(void)
Constructs a new EPG handler and adds it to the list of EPG handlers.
virtual bool EndSegmentTransfer(bool Modified, bool Dummy)
< Called directly after IgnoreChannel() before any other handler method is called.
virtual bool HandleEvent(cEvent *Event)
After all modifications of the Event have been done, the EPG handler can take a final look at it.
virtual bool SetContents(cEvent *Event, uchar *Contents)
virtual bool SetDescription(cEvent *Event, const char *Description)
virtual bool SortSchedule(cSchedule *Schedule)
Sorts the Schedule after the complete table has been processed.
virtual bool SetStartTime(cEvent *Event, time_t StartTime)
virtual bool DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version)
Takes a look at all EPG events between SegmentStart and SegmentEnd and drops outdated events.
virtual bool SetDuration(cEvent *Event, int Duration)
virtual bool HandledExternally(const cChannel *Channel)
If any EPG handler returns true in this function, it is assumed that the EPG for the given Channel is...
virtual bool SetShortText(cEvent *Event, const char *ShortText)
void SortSchedule(cSchedule *Schedule)
void EndSegmentTransfer(bool Modified)
bool IgnoreChannel(const cChannel *Channel)
bool HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version)
void SetStartTime(cEvent *Event, time_t StartTime)
void SetTitle(cEvent *Event, const char *Title)
void DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version)
bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version)
void FixEpgBugs(cEvent *Event)
void HandleEvent(cEvent *Event)
void SetComponents(cEvent *Event, cComponents *Components)
void SetVps(cEvent *Event, time_t Vps)
void SetParentalRating(cEvent *Event, int ParentalRating)
bool BeginSegmentTransfer(const cChannel *Channel)
bool HandledExternally(const cChannel *Channel)
void SetContents(cEvent *Event, uchar *Contents)
void SetShortText(cEvent *Event, const char *ShortText)
void SetDuration(cEvent *Event, int Duration)
void SetDescription(cEvent *Event, const char *Description)
void SetEventID(cEvent *Event, tEventID EventID)
Definition: epg.h:73
const char * ShortText(void) const
cString ToDescr(void) const
char * aux
Definition: epg.h:94
time_t Vps(void) const
time_t vps
Definition: epg.h:92
void SetSeen(void)
static cMutex numTimersMutex
Definition: epg.h:76
uchar TableID(void) const
void SetAux(const char *Aux)
time_t EndTime(void) const
uchar parentalRating
Definition: epg.h:84
cString GetDateString(void) const
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater",...
char * title
Definition: epg.h:85
int RunningStatus(void) const
char * shortText
Definition: epg.h:86
const cComponents * Components(void) const
char * description
Definition: epg.h:87
uchar Contents(int i=0) const
const char * Description(void) const
bool IsRunning(bool OrAboutToStart=false) const
cEvent(tEventID EventID)
void SetRunningStatus(int RunningStatus, const cChannel *Channel=NULL)
void IncNumTimers(void) const
int ParentalRating(void) const
static const char * ContentToString(uchar Content)
time_t StartTime(void) const
tChannelID ChannelID(void) const
void SetVps(time_t Vps)
bool SeenWithin(int Seconds) const
bool Parse(char *s)
time_t seen
Definition: epg.h:93
uchar contents[MaxEventContents]
Definition: epg.h:91
const char * Aux(void) const
tEventID eventID
Definition: epg.h:80
void SetShortText(const char *ShortText)
u_int16_t numTimers
Definition: epg.h:79
cString GetTimeString(void) const
const char * Title(void) const
void DecNumTimers(void) const
tEventID EventID(void) const
Definition: epg.h:101
const cSchedule * Schedule(void) const
void SetStartTime(time_t StartTime)
bool HasTimer(void) const
void SetComponents(cComponents *Components)
int duration
Definition: epg.h:90
void SetEventID(tEventID EventID)
cComponents * components
Definition: epg.h:88
cString GetEndTimeString(void) const
int Duration(void) const
cSchedule * schedule
Definition: epg.h:78
cString GetVpsString(void) const
void SetVersion(uchar Version)
uchar tableID
Definition: epg.h:81
static bool Read(FILE *f, cSchedule *Schedule, int &Line)
void Dump(FILE *f, const char *Prefix="", bool InfoOnly=false) const
void SetDuration(int Duration)
void SetContents(uchar *Contents)
uchar Version(void) const
uchar runningStatus
Definition: epg.h:83
void SetTitle(const char *Title)
time_t Seen(void) const
uchar version
Definition: epg.h:82
void SetTableID(uchar TableID)
cString GetParentalRatingString(void) const
void FixEpgBugs(void)
void SetDescription(const char *Description)
time_t startTime
Definition: epg.h:89
void SetParentalRating(int ParentalRating)
Definition: epg.h:152
const cEvent * GetPresentEvent(void) const
bool Modified(int &State) const
bool HasTimer(void) const
void SetRunningStatus(cEvent *Event, int RunningStatus, const cChannel *Channel=NULL)
void UnhashEvent(cEvent *Event)
cHash< cEvent > eventsHashID
Definition: epg.h:157
const cEvent * GetEventAround(time_t Time) const
const cEvent * GetEventByTime(time_t StartTime) const
void DecNumTimers(void) const
const cEvent * GetEvent(tEventID EventID, time_t StartTime=0) const
static bool Read(FILE *f, cSchedules *Schedules)
bool OnActualTp(uchar TableId)
void DropOutdated(time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version)
cSchedule(tChannelID ChannelID)
void SetPresentSeen(void)
cHash< cEvent > eventsHashStartTime
Definition: epg.h:158
bool PresentSeenWithin(int Seconds) const
void ClrRunningStatus(cChannel *Channel=NULL)
void ResetVersions(void)
void Cleanup(void)
tChannelID channelID
Definition: epg.h:155
time_t PresentSeen(void) const
const cEvent * GetEventById(tEventID EventID) const
const cList< cEvent > * Events(void) const
void DelEvent(cEvent *Event)
void HashEvent(cEvent *Event)
void Cleanup(time_t Time)
u_int16_t numTimers
Definition: epg.h:159
tChannelID ChannelID(void) const
Definition: epg.h:166
void SetModified(void)
cList< cEvent > events
Definition: epg.h:156
int modified
Definition: epg.h:162
void Sort(void)
static cMutex numTimersMutex
Definition: epg.h:154
bool onActualTp
Definition: epg.h:161
void IncNumTimers(void) const
time_t presentSeen
Definition: epg.h:163
cEvent * AddEvent(cEvent *Event)
void Dump(const cChannels *Channels, FILE *f, const char *Prefix="", eDumpMode DumpMode=dmAll, time_t AtTime=0) const
bool hasRunning
Definition: epg.h:160
const cEvent * GetFollowingEvent(void) const
static cSchedules schedules
Definition: epg.h:204
cSchedules(void)
static time_t lastDump
Definition: epg.h:206
static cSchedules * GetSchedulesWrite(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of schedules for write access.
const cSchedule * GetSchedule(tChannelID ChannelID) const
static void Cleanup(bool Force=false)
const cSchedule * GetSchedule(const cChannel *Channel, bool AddIfMissing=false) const
static bool Read(FILE *f=NULL)
static void ResetVersions(void)
cSchedule * AddSchedule(tChannelID ChannelID)
static bool Dump(FILE *f=NULL, const char *Prefix="", eDumpMode DumpMode=dmAll, time_t AtTime=0)
static const cSchedules * GetSchedulesRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of schedules for read access.
static void SetEpgDataFileName(const char *FileName)
static char * epgDataFileName
Definition: epg.h:205
u_int32_t tEventID
Definition: epg.h:71
eDumpMode
Definition: epg.h:42
eEventContentGroup
Definition: epg.h:27
cEpgHandlers EpgHandlers
Definition: epg.c:1429
u_int32_t tEventID
DEF_LIST_LOCK(Schedules)
void ReportEpgBugFixStats(bool Force=false)
Definition: epg.c:611
@ dmAtTime
@ dmPresent
@ dmFollowing
@ dmAll
@ MaxEventContents
@ ecgSocialPoliticalEconomics
@ ecgNewsCurrentAffairs
@ ecgEducationalScience
@ ecgMovieDrama
@ ecgArtsCulture
@ ecgShow
@ ecgSports
@ ecgLeisureHobbies
@ ecgMusicBalletDance
@ ecgSpecial
@ ecgUserDefined
@ ecgChildrenYouth
unsigned char uchar
Definition: epg.h:44
char * description
Definition: epg.h:48
bool FromString(const char *s)
uchar stream
Definition: epg.h:45
cString ToString(void)
uchar type
Definition: epg.h:46
char language[MAXLANGCODE2]
Definition: epg.h:47