vdr  2.2.0
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 3.1 2013/08/23 10:50:05 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 enum { MaxEventContents = 4 };
24 
26  ecgMovieDrama = 0x10,
28  ecgShow = 0x30,
29  ecgSports = 0x40,
36  ecgSpecial = 0xB0,
38  };
39 
41 
42 struct tComponent {
46  char *description;
47  cString ToString(void);
48  bool FromString(const char *s);
49  };
50 
51 class cComponents {
52 private:
55  bool Realloc(int Index);
56 public:
57  cComponents(void);
58  ~cComponents(void);
59  int NumComponents(void) const { return numComponents; }
60  void SetComponent(int Index, const char *s);
61  void SetComponent(int Index, uchar Stream, uchar Type, const char *Language, const char *Description);
62  tComponent *Component(int Index) const { return (Index < numComponents) ? &components[Index] : NULL; }
63  tComponent *GetComponent(int Index, uchar Stream, uchar Type); // Gets the Index'th component of Stream and Type, skipping other components
64  // In case of an audio stream the 'type' check actually just distinguishes between "normal" and "Dolby Digital"
65  };
66 
67 class cSchedule;
68 
69 typedef u_int32_t tEventID;
70 
71 class cEvent : public cListObject {
72  friend class cSchedule;
73 private:
74  // The sequence of these parameters is optimized for minimal memory waste!
75  cSchedule *schedule; // The Schedule this event belongs to
76  tEventID eventID; // Event ID of this event
77  uchar tableID; // Table ID this event came from
78  uchar version; // Version number of section this event came from
79  uchar runningStatus; // 0=undefined, 1=not running, 2=starts in a few seconds, 3=pausing, 4=running
80  uchar parentalRating; // Parental rating of this event
81  char *title; // Title of this event
82  char *shortText; // Short description of this event (typically the episode name in case of a series)
83  char *description; // Description of this event
84  cComponents *components; // The stream components of this event
85  uchar contents[MaxEventContents]; // Contents of this event
86  time_t startTime; // Start time of this event
87  int duration; // Duration of this event in seconds
88  time_t vps; // Video Programming Service timestamp (VPS, aka "Programme Identification Label", PIL)
89  time_t seen; // When this event was last seen in the data stream
90 public:
91  cEvent(tEventID EventID);
92  ~cEvent();
93  virtual int Compare(const cListObject &ListObject) const;
94  tChannelID ChannelID(void) const;
95  const cSchedule *Schedule(void) const { return schedule; }
96  tEventID EventID(void) const { return eventID; }
97  uchar TableID(void) const { return tableID; }
98  uchar Version(void) const { return version; }
99  int RunningStatus(void) const { return runningStatus; }
100  const char *Title(void) const { return title; }
101  const char *ShortText(void) const { return shortText; }
102  const char *Description(void) const { return description; }
103  const cComponents *Components(void) const { return components; }
104  uchar Contents(int i = 0) const { return (0 <= i && i < MaxEventContents) ? contents[i] : uchar(0); }
105  int ParentalRating(void) const { return parentalRating; }
106  time_t StartTime(void) const { return startTime; }
107  time_t EndTime(void) const { return startTime + duration; }
108  int Duration(void) const { return duration; }
109  time_t Vps(void) const { return vps; }
110  time_t Seen(void) const { return seen; }
111  bool SeenWithin(int Seconds) const { return time(NULL) - seen < Seconds; }
112  bool HasTimer(void) const;
113  bool IsRunning(bool OrAboutToStart = false) const;
114  static const char *ContentToString(uchar Content);
115  cString GetParentalRatingString(void) const;
116  cString GetDateString(void) const;
117  cString GetTimeString(void) const;
118  cString GetEndTimeString(void) const;
119  cString GetVpsString(void) const;
120  void SetEventID(tEventID EventID);
121  void SetTableID(uchar TableID);
122  void SetVersion(uchar Version);
123  void SetRunningStatus(int RunningStatus, cChannel *Channel = NULL);
124  void SetTitle(const char *Title);
125  void SetShortText(const char *ShortText);
126  void SetDescription(const char *Description);
127  void SetComponents(cComponents *Components); // Will take ownership of Components!
128  void SetContents(uchar *Contents);
129  void SetParentalRating(int ParentalRating);
130  void SetStartTime(time_t StartTime);
131  void SetDuration(int Duration);
132  void SetVps(time_t Vps);
133  void SetSeen(void);
134  cString ToDescr(void) const;
135  void Dump(FILE *f, const char *Prefix = "", bool InfoOnly = false) const;
136  bool Parse(char *s);
137  static bool Read(FILE *f, cSchedule *Schedule);
138  void FixEpgBugs(void);
139  };
140 
141 class cSchedules;
142 
143 class cSchedule : public cListObject {
144 private:
150  time_t modified;
151  time_t presentSeen;
152 public:
153  cSchedule(tChannelID ChannelID);
154  tChannelID ChannelID(void) const { return channelID; }
155  time_t Modified(void) const { return modified; }
156  time_t PresentSeen(void) const { return presentSeen; }
157  bool PresentSeenWithin(int Seconds) const { return time(NULL) - presentSeen < Seconds; }
158  void SetModified(void) { modified = time(NULL); }
159  void SetPresentSeen(void) { presentSeen = time(NULL); }
160  void SetRunningStatus(cEvent *Event, int RunningStatus, cChannel *Channel = NULL);
161  void ClrRunningStatus(cChannel *Channel = NULL);
162  void ResetVersions(void);
163  void Sort(void);
164  void DropOutdated(time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version);
165  void Cleanup(time_t Time);
166  void Cleanup(void);
167  cEvent *AddEvent(cEvent *Event);
168  void DelEvent(cEvent *Event);
169  void HashEvent(cEvent *Event);
170  void UnhashEvent(cEvent *Event);
171  const cList<cEvent> *Events(void) const { return &events; }
172  const cEvent *GetPresentEvent(void) const;
173  const cEvent *GetFollowingEvent(void) const;
174  const cEvent *GetEvent(tEventID EventID, time_t StartTime = 0) const;
175  const cEvent *GetEventAround(time_t Time) const;
176  void Dump(FILE *f, const char *Prefix = "", eDumpMode DumpMode = dmAll, time_t AtTime = 0) const;
177  static bool Read(FILE *f, cSchedules *Schedules);
178  };
179 
181 private:
182  bool locked;
183 public:
184  cSchedulesLock(bool WriteLock = false, int TimeoutMs = 0);
185  ~cSchedulesLock();
186  bool Locked(void) { return locked; }
187  };
188 
189 class cSchedules : public cList<cSchedule> {
190  friend class cSchedule;
191  friend class cSchedulesLock;
192 private:
195  static char *epgDataFileName;
196  static time_t lastDump;
197  static time_t modified;
198 public:
199  static void SetEpgDataFileName(const char *FileName);
200  static const cSchedules *Schedules(cSchedulesLock &SchedulesLock);
204  static time_t Modified(void) { return modified; }
205  static void SetModified(cSchedule *Schedule);
206  static void Cleanup(bool Force = false);
207  static void ResetVersions(void);
208  static bool ClearAll(void);
209  static bool Dump(FILE *f = NULL, const char *Prefix = "", eDumpMode DumpMode = dmAll, time_t AtTime = 0);
210  static bool Read(FILE *f = NULL);
211  cSchedule *AddSchedule(tChannelID ChannelID);
212  const cSchedule *GetSchedule(tChannelID ChannelID) const;
213  const cSchedule *GetSchedule(const cChannel *Channel, bool AddIfMissing = false) const;
214  };
215 
216 class cEpgDataReader : public cThread {
217 public:
218  cEpgDataReader(void);
219  virtual void Action(void);
220  };
221 
222 void ReportEpgBugFixStats(bool Force = false);
223 
224 class cEpgHandler : public cListObject {
225 public:
226  cEpgHandler(void);
235  virtual ~cEpgHandler();
236  virtual bool IgnoreChannel(const cChannel *Channel) { return false; }
241  virtual bool HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version) { return false; }
246  virtual bool HandledExternally(const cChannel *Channel) { return false; }
252  virtual bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version) { return false; }
256  virtual bool SetEventID(cEvent *Event, tEventID EventID) { return false; }
257  virtual bool SetTitle(cEvent *Event, const char *Title) { return false; }
258  virtual bool SetShortText(cEvent *Event, const char *ShortText) { return false; }
259  virtual bool SetDescription(cEvent *Event, const char *Description) { return false; }
260  virtual bool SetContents(cEvent *Event, uchar *Contents) { return false; }
261  virtual bool SetParentalRating(cEvent *Event, int ParentalRating) { return false; }
262  virtual bool SetStartTime(cEvent *Event, time_t StartTime) { return false; }
263  virtual bool SetDuration(cEvent *Event, int Duration) { return false; }
264  virtual bool SetVps(cEvent *Event, time_t Vps) { return false; }
265  virtual bool SetComponents(cEvent *Event, cComponents *Components) { return false; }
266  virtual bool FixEpgBugs(cEvent *Event) { return false; }
268  virtual bool HandleEvent(cEvent *Event) { return false; }
271  virtual bool SortSchedule(cSchedule *Schedule) { return false; }
273  virtual bool DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version) { return false; }
276  virtual bool BeginSegmentTransfer(const cChannel *Channel, bool OnlyRunningStatus) { return false; }
279  virtual bool EndSegmentTransfer(bool Modified, bool OnlyRunningStatus) { return false; }
282  };
283 
284 class cEpgHandlers : public cList<cEpgHandler> {
285 public:
286  bool IgnoreChannel(const cChannel *Channel);
287  bool HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version);
288  bool HandledExternally(const cChannel *Channel);
289  bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version);
290  void SetEventID(cEvent *Event, tEventID EventID);
291  void SetTitle(cEvent *Event, const char *Title);
292  void SetShortText(cEvent *Event, const char *ShortText);
293  void SetDescription(cEvent *Event, const char *Description);
294  void SetContents(cEvent *Event, uchar *Contents);
295  void SetParentalRating(cEvent *Event, int ParentalRating);
296  void SetStartTime(cEvent *Event, time_t StartTime);
297  void SetDuration(cEvent *Event, int Duration);
298  void SetVps(cEvent *Event, time_t Vps);
299  void SetComponents(cEvent *Event, cComponents *Components);
300  void FixEpgBugs(cEvent *Event);
301  void HandleEvent(cEvent *Event);
302  void SortSchedule(cSchedule *Schedule);
303  void DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version);
304  void BeginSegmentTransfer(const cChannel *Channel, bool OnlyRunningStatus);
305  void EndSegmentTransfer(bool Modified, bool OnlyRunningStatus);
306  };
307 
309 
310 #endif //__EPG_H
unsigned char uchar
Definition: tools.h:30
Definition: epg.h:71
virtual bool SortSchedule(cSchedule *Schedule)
Sorts the Schedule after the complete table has been processed.
Definition: epg.h:271
time_t presentSeen
Definition: epg.h:151
static time_t modified
Definition: epg.h:197
time_t EndTime(void) const
Definition: epg.h:107
u_int32_t tEventID
Definition: epg.h:67
Definition: epg.h:40
virtual bool SetContents(cEvent *Event, uchar *Contents)
Definition: epg.h:260
RunningStatus
Definition: si.h:197
time_t Vps(void) const
Definition: epg.h:109
tChannelID ChannelID(void) const
Definition: epg.h:154
virtual bool SetTitle(cEvent *Event, const char *Title)
Definition: epg.h:257
uchar tableID
Definition: epg.h:77
char language[MAXLANGCODE2]
Definition: epg.h:45
virtual bool SetDuration(cEvent *Event, int Duration)
Definition: epg.h:263
virtual bool SetParentalRating(cEvent *Event, int ParentalRating)
Definition: epg.h:261
const cSchedule * Schedule(void) const
Definition: epg.h:95
tChannelID channelID
Definition: epg.h:145
char * title
Definition: epg.h:81
bool hasRunning
Definition: epg.h:149
virtual bool HandleEvent(cEvent *Event)
After all modifications of the Event have been done, the EPG handler can take a final look at it...
Definition: epg.h:268
int Duration(void) const
Definition: epg.h:108
time_t PresentSeen(void) const
Definition: epg.h:156
cHash< cEvent > eventsHashID
Definition: epg.h:147
uchar Contents(int i=0) const
Definition: epg.h:104
tComponent * Component(int Index) const
Definition: epg.h:62
time_t StartTime(void) const
Definition: epg.h:106
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...
Definition: epg.h:241
time_t Seen(void) const
Definition: epg.h:110
Definition: epg.h:36
static time_t lastDump
Definition: epg.h:196
bool PresentSeenWithin(int Seconds) const
Definition: epg.h:157
Definition: epg.h:28
virtual bool SetDescription(cEvent *Event, const char *Description)
Definition: epg.h:259
time_t startTime
Definition: epg.h:86
Definition: epg.h:40
virtual bool SetComponents(cEvent *Event, cComponents *Components)
Definition: epg.h:265
virtual bool EndSegmentTransfer(bool Modified, bool OnlyRunningStatus)
Called after the segment data has been processed.
Definition: epg.h:279
cSchedule * schedule
Definition: epg.h:75
int ParentalRating(void) const
Definition: epg.h:105
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".
Definition: tools.h:460
uchar TableID(void) const
Definition: epg.h:97
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...
Definition: epg.h:273
static time_t Modified(void)
Definition: epg.h:204
static bool Read(FILE *f, cSchedules *Schedules)
Definition: epg.c:1100
int duration
Definition: epg.h:87
uchar type
Definition: epg.h:44
Definition: epg.h:40
const cList< cEvent > * Events(void) const
Definition: epg.h:171
static char * epgDataFileName
Definition: epg.h:195
cComponents * components
Definition: epg.h:84
virtual bool SetStartTime(cEvent *Event, time_t StartTime)
Definition: epg.h:262
int RunningStatus(void) const
Definition: epg.h:99
time_t Modified(void) const
Definition: epg.h:155
tEventID EventID(void) const
Definition: epg.h:96
cString ToString(void)
Definition: epg.c:25
void SetRunningStatus(cEvent *Event, int RunningStatus, cChannel *Channel=NULL)
Definition: epg.c:975
char * description
Definition: epg.h:46
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...
Definition: epg.h:246
bool FromString(const char *s)
Definition: epg.c:32
void SetPresentSeen(void)
Definition: epg.h:159
#define MAXLANGCODE2
Definition: channels.h:42
const char * Title(void) const
Definition: epg.h:100
char * shortText
Definition: epg.h:82
uchar version
Definition: epg.h:78
Definition: epg.h:42
cRwLock rwlock
Definition: epg.h:193
uchar parentalRating
Definition: epg.h:80
Definition: thread.h:53
Definition: epg.h:143
tComponent * components
Definition: epg.h:54
void ReportEpgBugFixStats(bool Force=false)
Definition: epg.c:585
static cSchedules schedules
Definition: epg.h:194
time_t seen
Definition: epg.h:89
virtual bool SetShortText(cEvent *Event, const char *ShortText)
Definition: epg.h:258
int NumComponents(void) const
Definition: epg.h:59
Definition: thread.h:77
eDumpMode
Definition: epg.h:40
const char * Description(void) const
Definition: epg.h:102
virtual bool IgnoreChannel(const cChannel *Channel)
Before any EIT data for the given Channel is processed, the EPG handlers are asked whether this Chann...
Definition: epg.h:236
virtual bool SetVps(cEvent *Event, time_t Vps)
Definition: epg.h:264
uchar runningStatus
Definition: epg.h:79
void SetModified(void)
Definition: epg.h:158
const cComponents * Components(void) const
Definition: epg.h:103
uchar stream
Definition: epg.h:43
bool SeenWithin(int Seconds) const
Definition: epg.h:111
virtual bool FixEpgBugs(cEvent *Event)
Fixes some known problems with EPG data.
Definition: epg.h:266
tEventID eventID
Definition: epg.h:76
cEpgHandlers EpgHandlers
Definition: epg.c:1381
virtual bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version)
VDR can&#39;t perform the update check (version, tid) for externally handled events, therefore the EPG ha...
Definition: epg.h:252
virtual bool BeginSegmentTransfer(const cChannel *Channel, bool OnlyRunningStatus)
Called directly after IgnoreChannel() before any other handler method is called.
Definition: epg.h:276
cHash< cEvent > eventsHashStartTime
Definition: epg.h:148
bool Locked(void)
Definition: epg.h:186
const char * ShortText(void) const
Definition: epg.h:101
eEventContentGroup
Definition: epg.h:25
void Dump(FILE *f, const char *Prefix="", eDumpMode DumpMode=dmAll, time_t AtTime=0) const
Definition: epg.c:1067
Definition: epg.h:29
bool locked
Definition: epg.h:182
char * description
Definition: epg.h:83
uchar Version(void) const
Definition: epg.h:98
time_t modified
Definition: epg.h:150
time_t vps
Definition: epg.h:88
Definition: tools.h:168
int numComponents
Definition: epg.h:53
cList< cEvent > events
Definition: epg.h:146
virtual bool SetEventID(cEvent *Event, tEventID EventID)
Definition: epg.h:256