vdr  2.0.4
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 2.15 2012/09/24 12:53:53 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:
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;
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);
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:
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  };
277 
278 class cEpgHandlers : public cList<cEpgHandler> {
279 public:
280  bool IgnoreChannel(const cChannel *Channel);
281  bool HandleEitEvent(cSchedule *Schedule, const SI::EIT::Event *EitEvent, uchar TableID, uchar Version);
282  bool HandledExternally(const cChannel *Channel);
283  bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version);
284  void SetEventID(cEvent *Event, tEventID EventID);
285  void SetTitle(cEvent *Event, const char *Title);
286  void SetShortText(cEvent *Event, const char *ShortText);
287  void SetDescription(cEvent *Event, const char *Description);
288  void SetContents(cEvent *Event, uchar *Contents);
289  void SetParentalRating(cEvent *Event, int ParentalRating);
290  void SetStartTime(cEvent *Event, time_t StartTime);
291  void SetDuration(cEvent *Event, int Duration);
292  void SetVps(cEvent *Event, time_t Vps);
293  void SetComponents(cEvent *Event, cComponents *Components);
294  void FixEpgBugs(cEvent *Event);
295  void HandleEvent(cEvent *Event);
296  void SortSchedule(cSchedule *Schedule);
297  void DropOutdated(cSchedule *Schedule, time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version);
298  };
299 
301 
302 #endif //__EPG_H
303