|
SASC-NG
DVBSoftCAM
|
00001 /* 00002 * epg.h: Electronic Program Guide 00003 * 00004 * See the main source file 'vdr.c' for copyright information and 00005 * how to reach the author. 00006 * 00007 * Original version (as used in VDR before 1.3.0) written by 00008 * Robert Schneider <Robert.Schneider@web.de> and Rolf Hakenes <hakenes@hippomi.de>. 00009 * 00010 * $Id: epg.h 1.35 2006/10/07 13:47:19 kls Exp $ 00011 */ 00012 00013 #ifndef __EPG_H 00014 #define __EPG_H 00015 00016 #include "channels.h" 00017 #include "thread.h" 00018 #include "tools.h" 00019 00020 #define MAXEPGBUGFIXLEVEL 3 00021 00022 enum eDumpMode { dmAll, dmPresent, dmFollowing, dmAtTime }; 00023 00024 struct tComponent { 00025 uchar stream; 00026 uchar type; 00027 char language[MAXLANGCODE2]; 00028 char *description; 00029 cString ToString(void); 00030 bool FromString(const char *s); 00031 }; 00032 00033 class cComponents { 00034 private: 00035 int numComponents; 00036 tComponent *components; 00037 void Realloc(int Index); 00038 public: 00039 cComponents(void); 00040 ~cComponents(void); 00041 int NumComponents(void) const { return numComponents; } 00042 void SetComponent(int Index, const char *s); 00043 void SetComponent(int Index, uchar Stream, uchar Type, const char *Language, const char *Description); 00044 tComponent *Component(int Index) const { return (Index < numComponents) ? &components[Index] : NULL; } 00045 tComponent *GetComponent(int Index, uchar Stream, uchar Type); // Gets the Index'th component of Stream and Type, skipping other components 00046 // In case of an audio stream the 'type' check actually just distinguishes between "normal" and "Dolby Digital" 00047 }; 00048 00049 class cSchedule; 00050 00051 typedef u_int32_t tEventID; 00052 00053 class cEvent : public cListObject { 00054 friend class cSchedule; 00055 private: 00056 cSchedule *schedule; // The Schedule this event belongs to 00057 tEventID eventID; // Event ID of this event 00058 uchar tableID; // Table ID this event came from 00059 uchar version; // Version number of section this event came from 00060 int runningStatus; // 0=undefined, 1=not running, 2=starts in a few seconds, 3=pausing, 4=running 00061 char *title; // Title of this event 00062 char *shortText; // Short description of this event (typically the episode name in case of a series) 00063 char *description; // Description of this event 00064 cComponents *components; // The stream components of this event 00065 time_t startTime; // Start time of this event 00066 int duration; // Duration of this event in seconds 00067 time_t vps; // Video Programming Service timestamp (VPS, aka "Programme Identification Label", PIL) 00068 time_t seen; // When this event was last seen in the data stream 00069 public: 00070 cEvent(tEventID EventID); 00071 ~cEvent(); 00072 virtual int Compare(const cListObject &ListObject) const; 00073 tChannelID ChannelID(void) const; 00074 const cSchedule *Schedule(void) const { return schedule; } 00075 tEventID EventID(void) const { return eventID; } 00076 uchar TableID(void) const { return tableID; } 00077 uchar Version(void) const { return version; } 00078 int RunningStatus(void) const { return runningStatus; } 00079 const char *Title(void) const { return title; } 00080 const char *ShortText(void) const { return shortText; } 00081 const char *Description(void) const { return description; } 00082 const cComponents *Components(void) const { return components; } 00083 time_t StartTime(void) const { return startTime; } 00084 time_t EndTime(void) const { return startTime + duration; } 00085 int Duration(void) const { return duration; } 00086 time_t Vps(void) const { return vps; } 00087 time_t Seen(void) const { return seen; } 00088 bool SeenWithin(int Seconds) const { return time(NULL) - seen < Seconds; } 00089 bool HasTimer(void) const; 00090 bool IsRunning(bool OrAboutToStart = false) const; 00091 cString GetDateString(void) const; 00092 cString GetTimeString(void) const; 00093 cString GetEndTimeString(void) const; 00094 cString GetVpsString(void) const; 00095 void SetEventID(tEventID EventID); 00096 void SetTableID(uchar TableID); 00097 void SetVersion(uchar Version); 00098 void SetRunningStatus(int RunningStatus, cChannel *Channel = NULL); 00099 void SetTitle(const char *Title); 00100 void SetShortText(const char *ShortText); 00101 void SetDescription(const char *Description); 00102 void SetComponents(cComponents *Components); // Will take ownership of Components! 00103 void SetStartTime(time_t StartTime); 00104 void SetDuration(int Duration); 00105 void SetVps(time_t Vps); 00106 void SetSeen(void); 00107 cString ToDescr(void) const; 00108 void Dump(FILE *f, const char *Prefix = "", bool InfoOnly = false) const; 00109 bool Parse(char *s); 00110 static bool Read(FILE *f, cSchedule *Schedule); 00111 void FixEpgBugs(void); 00112 }; 00113 00114 class cSchedules; 00115 00116 class cSchedule : public cListObject { 00117 private: 00118 tChannelID channelID; 00119 cList<cEvent> events; 00120 cHash<cEvent> eventsHashID; 00121 cHash<cEvent> eventsHashStartTime; 00122 bool hasRunning; 00123 time_t modified; 00124 time_t presentSeen; 00125 public: 00126 cSchedule(tChannelID ChannelID); 00127 tChannelID ChannelID(void) const { return channelID; } 00128 time_t Modified(void) const { return modified; } 00129 time_t PresentSeen(void) const { return presentSeen; } 00130 bool PresentSeenWithin(int Seconds) const { return time(NULL) - presentSeen < Seconds; } 00131 void SetModified(void) { modified = time(NULL); } 00132 void SetPresentSeen(void) { presentSeen = time(NULL); } 00133 void SetRunningStatus(cEvent *Event, int RunningStatus, cChannel *Channel = NULL); 00134 void ClrRunningStatus(cChannel *Channel = NULL); 00135 void ResetVersions(void); 00136 void Sort(void); 00137 void DropOutdated(time_t SegmentStart, time_t SegmentEnd, uchar TableID, uchar Version); 00138 void Cleanup(time_t Time); 00139 void Cleanup(void); 00140 cEvent *AddEvent(cEvent *Event); 00141 void DelEvent(cEvent *Event); 00142 void HashEvent(cEvent *Event); 00143 void UnhashEvent(cEvent *Event); 00144 const cList<cEvent> *Events(void) const { return &events; } 00145 const cEvent *GetPresentEvent(void) const; 00146 const cEvent *GetFollowingEvent(void) const; 00147 const cEvent *GetEvent(tEventID EventID, time_t StartTime = 0) const; 00148 const cEvent *GetEventAround(time_t Time) const; 00149 void Dump(FILE *f, const char *Prefix = "", eDumpMode DumpMode = dmAll, time_t AtTime = 0) const; 00150 static bool Read(FILE *f, cSchedules *Schedules); 00151 }; 00152 00153 class cSchedulesLock { 00154 private: 00155 bool locked; 00156 public: 00157 cSchedulesLock(bool WriteLock = false, int TimeoutMs = 0); 00158 ~cSchedulesLock(); 00159 bool Locked(void) { return locked; } 00160 }; 00161 00162 class cSchedules : public cList<cSchedule> { 00163 friend class cSchedule; 00164 friend class cSchedulesLock; 00165 private: 00166 cRwLock rwlock; 00167 static cSchedules schedules; 00168 static const char *epgDataFileName; 00169 static time_t lastCleanup; 00170 static time_t lastDump; 00171 static time_t modified; 00172 public: 00173 static void SetEpgDataFileName(const char *FileName); 00174 static const cSchedules *Schedules(cSchedulesLock &SchedulesLock); 00178 static time_t Modified(void) { return modified; } 00179 static void SetModified(cSchedule *Schedule); 00180 static void Cleanup(bool Force = false); 00181 static void ResetVersions(void); 00182 static bool ClearAll(void); 00183 static bool Dump(FILE *f, const char *Prefix = "", eDumpMode DumpMode = dmAll, time_t AtTime = 0); 00184 static bool Read(FILE *f = NULL); 00185 cSchedule *AddSchedule(tChannelID ChannelID); 00186 const cSchedule *GetSchedule(tChannelID ChannelID) const; 00187 const cSchedule *GetSchedule(const cChannel *Channel, bool AddIfMissing = false) const; 00188 }; 00189 00190 void ReportEpgBugFixStats(bool Reset = false); 00191 00192 #endif //__EPG_H