=== libs/libmythtv/eitcache.h
==================================================================
|
|
|
10 | 10 | |
11 | 11 | // Qt headers |
12 | 12 | #include <qmap.h> |
| 13 | #include <qmutex.h> |
13 | 14 | #include <qstring.h> |
14 | 15 | |
15 | 16 | typedef QMap<uint64_t, uint64_t> key_map_t; |
… |
… |
|
20 | 21 | EITCache(); |
21 | 22 | ~EITCache() {}; |
22 | 23 | |
23 | | bool IsNewEIT(const uint tsid, const uint eventid, |
24 | | const uint serviceid, const uint tableid, |
25 | | const uint version, |
26 | | const unsigned char * const eitdata, |
27 | | const uint eitlength); |
| 24 | bool IsNewEIT(const uint onid, const uint tsid, |
| 25 | const uint serviceid, const uint eventid, |
| 26 | const uint tableid, const uint version, |
| 27 | const uint endtime); |
28 | 28 | |
| 29 | uint PruneOldEntries(uint timestamp); |
| 30 | |
29 | 31 | void ResetStatistics(void); |
30 | 32 | QString GetStatistics(void) const; |
31 | 33 | |
… |
… |
|
33 | 35 | // event key cache |
34 | 36 | key_map_t eventMap; |
35 | 37 | |
| 38 | QMutex eventMapLock; |
| 39 | |
36 | 40 | // statistics |
37 | 41 | uint accessCnt; |
38 | 42 | uint hitCnt; |
=== libs/libmythtv/eithelper.cpp
==================================================================
|
|
|
210 | 210 | for (uint i = 0; i < eit->EventCount(); i++) |
211 | 211 | { |
212 | 212 | // Skip event if we have already processed it before... |
213 | | if (!eitcache->IsNewEIT( |
214 | | eit->TSID(), eit->EventID(i), |
215 | | eit->ServiceID(), eit->TableID(), |
216 | | eit->Version(), |
217 | | eit->Descriptors(i), eit->DescriptorsLength(i))) |
| 213 | if (!eitcache->IsNewEIT(eit->OriginalNetworkID(), eit->TSID(), |
| 214 | eit->ServiceID(), eit->EventID(i), |
| 215 | eit->TableID(), eit->Version(), |
| 216 | eit->StartTimeKey(i)+eit->DurationInSeconds(i))) |
218 | 217 | { |
219 | 218 | continue; |
220 | 219 | } |
=== libs/libmythtv/eitcache.cpp
==================================================================
|
|
|
25 | 25 | |
26 | 26 | QString EITCache::GetStatistics(void) const |
27 | 27 | { |
| 28 | QMutexLocker locker(&eventMapLock); |
28 | 29 | return QString( |
29 | 30 | "EITCache::statistics: Accesses: %1, Hits: %2, " |
30 | | "Table Upgrades %3, New Versions: %4") |
31 | | .arg(accessCnt).arg(hitCnt).arg(tblChgCnt).arg(verChgCnt); |
| 31 | "Table Upgrades %3, New Versions: %4, Entries: %5") |
| 32 | .arg(accessCnt).arg(hitCnt).arg(tblChgCnt).arg(verChgCnt).arg(eventMap.size()); |
32 | 33 | } |
33 | 34 | |
34 | | static uint64_t construct_key(uint tsid, uint eventid, uint serviceid) |
| 35 | static uint64_t construct_key(uint onid, uint tsid, uint serviceid, uint eventid) |
35 | 36 | { |
36 | | return (((uint64_t) tsid << 48) | ((uint64_t) eventid << 32) | |
37 | | ((uint64_t) serviceid << 16)); |
| 37 | return (((uint64_t) onid << 48) | ((uint64_t) tsid << 32) | |
| 38 | ((uint64_t) serviceid << 16) | ((uint64_t) eventid )); |
38 | 39 | } |
39 | 40 | |
40 | | static uint64_t construct_sig(uint tableid, uint version, uint chksum) |
| 41 | static uint64_t construct_sig(uint tableid, uint version, uint endtime) |
41 | 42 | { |
42 | 43 | return (((uint64_t) tableid << 40) | ((uint64_t) version << 32) | |
43 | | ((uint64_t) chksum)); |
| 44 | ((uint64_t) endtime)); |
44 | 45 | } |
45 | 46 | |
46 | 47 | static uint extract_table_id(uint64_t sig) |
… |
… |
|
53 | 54 | return (sig >> 32) & 0x1f; |
54 | 55 | } |
55 | 56 | |
56 | | bool EITCache::IsNewEIT(const uint tsid, const uint eventid, |
57 | | const uint serviceid, const uint tableid, |
58 | | const uint version, |
59 | | const unsigned char * const /*eitdata*/, |
60 | | const uint /*eitlength*/) |
| 57 | static uint extract_endtime(uint64_t sig) |
61 | 58 | { |
| 59 | return sig & 0xffff; |
| 60 | } |
| 61 | |
| 62 | bool EITCache::IsNewEIT(const uint onid, const uint tsid, |
| 63 | const uint serviceid, const uint eventid, |
| 64 | const uint tableid, const uint version, |
| 65 | const uint endtime) |
| 66 | { |
62 | 67 | accessCnt++; |
63 | 68 | |
64 | | uint64_t key = construct_key(tsid, eventid, serviceid); |
| 69 | uint64_t key = construct_key(onid, tsid, serviceid, eventid); |
| 70 | |
| 71 | QMutexLocker locker(&eventMapLock); |
65 | 72 | key_map_t::const_iterator it = eventMap.find(key); |
66 | 73 | |
67 | 74 | if (it != eventMap.end()) |
… |
… |
|
87 | 94 | } |
88 | 95 | } |
89 | 96 | |
90 | | eventMap[key] = construct_sig(tableid, version, 0 /*chksum*/); |
| 97 | eventMap[key] = construct_sig(tableid, version, endtime); |
91 | 98 | |
92 | 99 | return true; |
93 | 100 | } |
94 | 101 | |
| 102 | uint EITCache::PruneOldEntries(uint timestamp) |
| 103 | { |
| 104 | QMutexLocker locker(&eventMapLock); |
| 105 | uint size = eventMap.size(); |
| 106 | key_map_t::iterator it = eventMap.begin(); |
| 107 | while (it != eventMap.end()) |
| 108 | { |
| 109 | if (extract_endtime(*it) < timestamp) |
| 110 | { |
| 111 | key_map_t::iterator tmp = it; |
| 112 | ++tmp; |
| 113 | eventMap.erase(it); |
| 114 | it = tmp; |
| 115 | } |
| 116 | else |
| 117 | ++it; |
| 118 | } |
| 119 | return size - eventMap.size(); |
| 120 | } |
| 121 | |
95 | 122 | /* vim: set expandtab tabstop=4 shiftwidth=4: */ |
=== programs/mythbackend/eitactivescanner.cpp
==================================================================
|
|
|
63 | 63 | |
64 | 64 | while (!exitThread) |
65 | 65 | { |
66 | | if (ismaster && (QDateTime::currentDateTime() > activeScanNextTrig) |
67 | | && !cardList->isEmpty()) |
| 66 | QDateTime now = QDateTime::currentDateTime(); |
| 67 | |
| 68 | if (ismaster && (now > activeScanNextTrig) && !cardList->isEmpty()) |
68 | 69 | { |
69 | 70 | cerr << eitCache->GetStatistics() << endl; |
70 | 71 | if (activeScanNextCard == cardIDToSourceID.end()) |
… |
… |
|
98 | 99 | |
99 | 100 | activeScanNextCard++; |
100 | 101 | } |
101 | | // TODO: prune old eit cache entries every now and then |
| 102 | |
| 103 | if (now > nextPruneCacheTime) |
| 104 | { |
| 105 | // prune cache entries that ended more than kPruneCacheTimeOffset ago |
| 106 | uint prunedEntries = eitCache->PruneOldEntries(now.addSecs(-kPruneCacheTimeOffset).toTime_t()); |
| 107 | nextPruneCacheTime.addSecs(kPruneCacheTimeOffset); |
| 108 | |
| 109 | VERBOSE(VB_GENERAL, QString("Pruned %1 entries from the eit cache") |
| 110 | .arg(prunedEntries)); |
| 111 | } |
102 | 112 | |
103 | 113 | exitThreadCond.wait(200); // sleep up to 200 ms. |
104 | 114 | } |
… |
… |
|
190 | 200 | activeScanNextTrig = QDateTime::currentDateTime(); |
191 | 201 | activeScanTrigTime = max_seconds_per_source / cardList->size(); |
192 | 202 | activeScanNextCard = cardIDToSourceID.begin(); |
| 203 | nextPruneCacheTime = QDateTime::currentDateTime().addSecs(kPruneCacheTimeOffset); |
193 | 204 | } |
194 | 205 | } |
=== programs/mythbackend/eitactivescanner.h
==================================================================
|
|
|
48 | 48 | QMap<int, uint> cardIDToSourceID; |
49 | 49 | QMap<int, uint>::iterator activeScanNextCard; |
50 | 50 | |
51 | | bool ismaster; |
| 51 | bool ismaster; |
| 52 | |
| 53 | QDateTime nextPruneCacheTime; |
| 54 | |
| 55 | static const int kPruneCacheTimeOffset = 21600; // six hours |
52 | 56 | }; |
53 | 57 | |
54 | 58 | #endif //EITACTIVESCANNER_H |