/
epgcache.h
278 lines (245 loc) · 8.02 KB
/
epgcache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#ifndef __epgcache_h_
#define __epgcache_h_
#define ENABLE_PRIVATE_EPG 1
#define ENABLE_MHW_EPG 1
#define ENABLE_FREESAT 1
#define ENABLE_NETMED 1
#define ENABLE_VIRGIN 1
#define ENABLE_ATSC 1
#define ENABLE_OPENTV 1
#ifndef SWIG
#include <vector>
#include <tr1/unordered_map>
#include <lib/dvb/idvb.h>
#include <lib/dvb/dvbtime.h>
#include <lib/base/ebase.h>
#include <lib/base/thread.h>
#include <lib/base/message.h>
#include <lib/service/event.h>
#include <lib/python/python.h>
struct eventData;
class eServiceReferenceDVB;
class eEPGChannelData;
class eEPGTransponderDataReader;
struct uniqueEPGKey
{
int sid, onid, tsid;
uniqueEPGKey( const eServiceReference &ref )
:sid( ref.type != eServiceReference::idInvalid ? ((eServiceReferenceDVB&)ref).getServiceID().get() : -1 )
,onid( ref.type != eServiceReference::idInvalid ? ((eServiceReferenceDVB&)ref).getOriginalNetworkID().get() : -1 )
,tsid( ref.type != eServiceReference::idInvalid ? ((eServiceReferenceDVB&)ref).getTransportStreamID().get() : -1 )
{
}
uniqueEPGKey()
:sid(-1), onid(-1), tsid(-1)
{
}
uniqueEPGKey( int sid, int onid, int tsid )
:sid(sid), onid(onid), tsid(tsid)
{
}
bool operator <(const uniqueEPGKey &a) const
{
if (sid < a.sid)
return true;
if (sid != a.sid)
return false;
if (onid < a.onid)
return true;
if (onid != a.onid)
return false;
return (tsid < a.tsid);
}
operator bool() const
{
return !(sid == -1 && onid == -1 && tsid == -1);
}
bool operator==(const uniqueEPGKey &a) const
{
return (tsid == a.tsid) && (onid == a.onid) && (sid == a.sid);
}
struct equal
{
bool operator()(const uniqueEPGKey &a, const uniqueEPGKey &b) const
{
return (a.tsid == b.tsid) && (a.onid == b.onid) && (a.sid == b.sid);
}
};
};
//eventMap is sorted by event_id
typedef std::map<uint16_t, eventData*> eventMap;
//timeMap is sorted by beginTime
typedef std::map<time_t, eventData*> timeMap;
struct hash_uniqueEPGKey
{
inline size_t operator()( const uniqueEPGKey &x) const
{
return (x.onid << 16) | x.tsid;
}
};
struct EventCacheItem {
eventMap byEvent;
timeMap byTime;
int sources;
EventCacheItem(): sources(0) {}
};
typedef std::tr1::unordered_map<uniqueEPGKey, EventCacheItem, hash_uniqueEPGKey, uniqueEPGKey::equal> eventCache;
#ifdef ENABLE_PRIVATE_EPG
typedef std::tr1::unordered_map<time_t, std::pair<time_t, uint16_t> > contentTimeMap;
typedef std::tr1::unordered_map<int, contentTimeMap > contentMap;
typedef std::tr1::unordered_map<uniqueEPGKey, contentMap, hash_uniqueEPGKey, uniqueEPGKey::equal > contentMaps;
#endif
struct eit_parental_rating {
u_char country_code[3];
u_char rating;
};
#endif
class eEPGCache: public eMainloop, private eThread, public sigc::trackable
{
#ifndef SWIG
DECLARE_REF(eEPGCache)
public:
struct Message
{
enum
{
flush,
quit,
timeChanged
};
int type;
uniqueEPGKey service;
union {
int err;
};
Message()
:type(0) {}
Message(int type)
:type(type) {}
Message(int type, const eServiceReference& service, int err=0)
:type(type), service(service), err(err) {}
};
eFixedMessagePump<Message> messages;
private:
friend struct eventData;
friend class eEPGChannelData;
friend class eEPGTransponderDataReader;
static eEPGCache *instance;
unsigned int historySeconds;
eventCache eventDB;
std::string m_filename;
bool m_running;
unsigned int m_enabledEpgSources;
ePtr<eTimer> cleanTimer;
bool load_epg;
PSignal0<void> epgCacheStarted;
std::vector<uniqueEPGKey> eit_blacklist;
std::vector<uniqueEPGKey> eit_whitelist;
#ifdef ENABLE_PRIVATE_EPG
contentMaps content_time_tables;
#endif
void thread(); // thread function
#ifdef ENABLE_PRIVATE_EPG
void privateSectionRead(const uniqueEPGKey &, const uint8_t *);
#endif
void sectionRead(const uint8_t *data, int source, eEPGChannelData *channel);
void gotMessage(const Message &message);
void cleanLoop();
void submitEventData(const std::vector<int>& sids, const std::vector<eDVBChannelID>& chids, long start, long duration, const char* title, const char* short_summary, const char* long_description, char event_type, int event_id, int source);
void submitEventData(const std::vector<int>& sids, const std::vector<eDVBChannelID>& chids, long start, long duration, const char* title, const char* short_summary, const char* long_description, std::vector<uint8_t> event_types, std::vector<eit_parental_rating> parental_ratings, int event_id, int source);
void clearCompleteEPGCache();
eServiceReferenceDVB *m_timeQueryRef;
time_t m_timeQueryBegin;
int m_timeQueryMinutes;
int m_timeQueryCount; // counts the returned events; getNextTimeEntry returns always the m_timeQueryCount'th event
#else
eEPGCache();
~eEPGCache();
#endif // SWIG
public:
static eEPGCache *getInstance() { return instance; }
void crossepgImportEPGv21(std::string dbroot);
void save();
void load();
void timeUpdated();
void flushEPG(const uniqueEPGKey & s=uniqueEPGKey(), bool lock = true);
void reloadEITConfig(int listType);
#ifndef SWIG
eEPGCache();
~eEPGCache();
#endif
// must be called once!
void setCacheFile(const char *filename);
// at moment just for one service..
RESULT startTimeQuery(const eServiceReference &service, time_t begin=-1, int minutes=-1);
#ifndef SWIG
private:
// For internal use only. Acquire the cache lock before calling.
RESULT lookupEventId(const eServiceReference &service, int event_id, const eventData *&);
RESULT lookupEventTime(const eServiceReference &service, time_t, const eventData *&, int direction=0);
public:
/* Only used by servicedvbrecord.cpp to write the EIT file */
RESULT saveEventToFile(const char* filename, const eServiceReference &service, int eit_event_id, time_t begTime, time_t endTime);
// Events are parsed epg events.. it's safe to use them after cache unlock
// after use the Event pointer must be released using "delete".
RESULT lookupEventId(const eServiceReference &service, int event_id, Event* &);
RESULT lookupEventTime(const eServiceReference &service, time_t, Event* &, int direction=0);
RESULT getNextTimeEntry(Event *&);
#endif
enum {
SIMILAR_BROADCASTINGS_SEARCH,
EXAKT_TITLE_SEARCH,
PARTIAL_TITLE_SEARCH,
START_TITLE_SEARCH,
END_TITLE_SEARCH,
PARTIAL_DESCRIPTION_SEARCH,
CRID_SEARCH
};
enum {
CASE_CHECK,
NO_CASE_CHECK
};
PyObject *lookupEvent(SWIG_PYOBJECT(ePyObject) list, SWIG_PYOBJECT(ePyObject) convertFunc=(PyObject*)0);
PyObject *search(SWIG_PYOBJECT(ePyObject));
// eServiceEvent are parsed epg events.. it's safe to use them after cache unlock
// for use from python ( members: m_start_time, m_duration, m_short_description, m_extended_description )
SWIG_VOID(RESULT) lookupEventId(const eServiceReference &service, int event_id, ePtr<eServiceEvent> &SWIG_OUTPUT);
SWIG_VOID(RESULT) lookupEventTime(const eServiceReference &service, time_t, ePtr<eServiceEvent> &SWIG_OUTPUT, int direction=0);
SWIG_VOID(RESULT) getNextTimeEntry(ePtr<eServiceEvent> &SWIG_OUTPUT);
enum {ALL=0, WHITELIST=1, BLACKLIST=2};
enum {PRIVATE=0, NOWNEXT=1, SCHEDULE=2, SCHEDULE_OTHER=4
#ifdef ENABLE_MHW_EPG
,MHW=8
#endif
#ifdef ENABLE_FREESAT
,FREESAT_NOWNEXT=16
,FREESAT_SCHEDULE=32
,FREESAT_SCHEDULE_OTHER=64
#endif
,VIASAT=256
#ifdef ENABLE_NETMED
,NETMED_SCHEDULE=512
,NETMED_SCHEDULE_OTHER=1024
#endif
#ifdef ENABLE_VIRGIN
,VIRGIN_NOWNEXT=2048
,VIRGIN_SCHEDULE=4096
#endif
#ifdef ENABLE_ATSC
,ATSC_EIT=8192
#endif
#ifdef ENABLE_OPENTV
,OPENTV=16384
#endif
,EPG_IMPORT=0x80000000
};
void setEpgHistorySeconds(time_t seconds);
void setEpgSources(unsigned int mask);
unsigned int getEpgSources();
bool getIsBlacklisted(const uniqueEPGKey epgKey);
bool getIsWhitelisted(const uniqueEPGKey epgKey);
void submitEventData(const std::vector<eServiceReferenceDVB>& serviceRefs, long start, long duration, const char* title, const char* short_summary, const char* long_description, std::vector<uint8_t> event_types, std::vector<eit_parental_rating> parental_ratings, uint16_t eventId=0);
void importEvents(SWIG_PYOBJECT(ePyObject) serviceReferences, SWIG_PYOBJECT(ePyObject) list);
void importEvent(SWIG_PYOBJECT(ePyObject) serviceReference, SWIG_PYOBJECT(ePyObject) list);
};
#endif