=== programs/mythbackend/eitactivescanner.cpp
==================================================================
|
|
|
|
| 65 | 65 | { |
| 66 | 66 | QDateTime now = QDateTime::currentDateTime(); |
| 67 | 67 | |
| 68 | | if (ismaster && (now > activeScanNextTrig) && !cardList->isEmpty()) |
| | 68 | if (ismaster && (now > nextTriggerTime) && !cardList->isEmpty()) |
| 69 | 69 | { |
| 70 | | cerr << eitCache->GetStatistics() << endl; |
| 71 | | if (activeScanNextCard == cardIDToSourceID.end()) |
| | 70 | VERBOSE(VB_EIT, eitCache->GetStatistics()); |
| | 71 | if (nextCard == cardsSources.end()) |
| 72 | 72 | { |
| 73 | | activeScanNextCard = cardIDToSourceID.begin(); |
| | 73 | nextCard = cardsSources.begin(); |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | | uint source = *activeScanNextCard; |
| | 76 | // find source with the highest priority |
| | 77 | vector<uint>::iterator source = sources.begin(); |
| | 78 | while (source != sources.end()) |
| | 79 | { |
| | 80 | if ((*nextCard).end() != find((*nextCard).begin(), |
| | 81 | (*nextCard).end(), *source)) |
| | 82 | break; |
| | 83 | ++source; |
| | 84 | } |
| | 85 | if (source == sources.end()) |
| | 86 | { |
| | 87 | VERBOSE(VB_EIT, QString("Couldn't find source for card %1.") |
| | 88 | .arg(nextCard.key())); |
| | 89 | continue; |
| | 90 | } |
| | 91 | int cardid = nextCard.key(); |
| 77 | 92 | |
| 78 | | int curCardID = activeScanNextCard.key(); |
| 79 | | if (activeScanNextChan[source] == activeScanChannels[source].end()) |
| 80 | | activeScanNextChan[source] = activeScanChannels[source].begin(); |
| 81 | 93 | |
| 82 | | if (!(*(activeScanNextChan[source])).isEmpty() && |
| 83 | | (*cardList)[curCardID]->StartEITScan(*(activeScanNextChan[source]))) |
| | 94 | if (!(*(nextChan[*source])).isEmpty() && |
| | 95 | (*cardList)[cardid]->StartEITScan(*(nextChan[*source]))) |
| 84 | 96 | { |
| 85 | | VERBOSE(VB_GENERAL, QString("(%1)Now looking for EIT data on " |
| 86 | | "multiplex of channel %2 of source %3") |
| 87 | | .arg(curCardID).arg(*(activeScanNextChan[source])).arg(source)); |
| 88 | | activeScanNextChan[source]++; |
| | 97 | VERBOSE(VB_GENERAL, QString("DVB(%1): Now looking for EIT " |
| | 98 | "data on multiplex of channel %2 " |
| | 99 | "of source %3") |
| | 100 | .arg(cardid).arg(*(nextChan[*source])).arg(*source)); |
| | 101 | /* advace to the next channel and test for valid iterator. |
| | 102 | needed to simplify selection of the source |
| | 103 | with the highest priority. */ |
| | 104 | nextChan[*source]++; |
| | 105 | if (nextChan[*source] == channels[*source].end()) |
| | 106 | { |
| | 107 | nextChan[*source] = channels[*source].begin(); |
| | 108 | sources.push_back(*source); |
| | 109 | sources.erase(source); |
| | 110 | } |
| 89 | 111 | } |
| 90 | 112 | else |
| 91 | 113 | { |
| 92 | | VERBOSE(VB_GENERAL, QString("Skipping card %1 in scan for EIT data on " |
| 93 | | "multiplex of channel %2 of source %3") |
| 94 | | .arg(curCardID).arg(*(activeScanNextChan[source])).arg(source)); |
| | 114 | VERBOSE(VB_GENERAL, QString("Skipping card %1 in scan for EIT " |
| | 115 | "data on multiplex of channel %2 " |
| | 116 | "of source %3") |
| | 117 | .arg(cardid).arg(*(nextChan[*source])).arg(*source)); |
| 95 | 118 | } |
| 96 | 119 | |
| 97 | | activeScanNextTrig = QDateTime::currentDateTime() |
| 98 | | .addSecs(activeScanTrigTime); |
| | 120 | nextTriggerTime = QDateTime::currentDateTime().addSecs(triggerTime); |
| 99 | 121 | |
| 100 | | activeScanNextCard++; |
| | 122 | nextCard++; |
| 101 | 123 | } |
| 102 | 124 | |
| | 125 | // prune cache entries that ended more than kPruneCacheTimeOffset ago |
| 103 | 126 | if (now > nextPruneCacheTime) |
| 104 | 127 | { |
| 105 | | // prune cache entries that ended more than kPruneCacheTimeOffset ago |
| 106 | | uint prunedEntries = eitCache->PruneOldEntries(now.addSecs(-kPruneCacheTimeOffset).toTime_t()); |
| 107 | | nextPruneCacheTime.addSecs(kPruneCacheTimeOffset); |
| | 128 | uint prunedEntries = eitCache->PruneOldEntries(now |
| | 129 | .addSecs(-kPruneCacheTimeOffset).toTime_t()); |
| | 130 | nextPruneCacheTime = QDateTime::currentDateTime() |
| | 131 | .addSecs(kPruneCacheTimeOffset); |
| 108 | 132 | |
| 109 | | VERBOSE(VB_GENERAL, QString("Pruned %1 entries from the eit cache") |
| | 133 | VERBOSE(VB_EIT, eitCache->GetStatistics()); |
| | 134 | VERBOSE(VB_EIT, QString("Pruned %1 entries from the eit cache") |
| 110 | 135 | .arg(prunedEntries)); |
| 111 | 136 | } |
| 112 | 137 | |
| 113 | | exitThreadCond.wait(200); // sleep up to 200 ms. |
| | 138 | exitThreadCond.wait(1000); // sleep up to 1 second. |
| 114 | 139 | } |
| 115 | 140 | } |
| 116 | 141 | |
| 117 | 142 | void EITActiveScanner::StartActiveScan() |
| 118 | 143 | { |
| 119 | | if (!activeScanSources.size()) |
| | 144 | if (!sources.size()) |
| 120 | 145 | { |
| 121 | 146 | // get all source ids with useeit == 1 |
| 122 | 147 | MSqlQuery query(MSqlQuery::InitCon()); |
| … |
… |
|
| 137 | 162 | } |
| 138 | 163 | |
| 139 | 164 | while (query.next()) |
| 140 | | activeScanSources.push_back(query.value(0).toUInt()); |
| | 165 | sources.push_back(query.value(0).toUInt()); |
| 141 | 166 | |
| 142 | 167 | // getting mapping from cardid to sourceid with useeit == 1 |
| 143 | 168 | query.prepare( |
| … |
… |
|
| 154 | 179 | } |
| 155 | 180 | |
| 156 | 181 | while (query.next()) |
| 157 | | cardIDToSourceID[query.value(0).toInt()] = query.value(1).toUInt(); |
| | 182 | cardsSources[query.value(0).toInt()] |
| | 183 | .push_back(query.value(1).toUInt()); |
| 158 | 184 | |
| 159 | 185 | |
| 160 | 186 | // get one channel with sourceid per mplexid |
| … |
… |
|
| 177 | 203 | |
| 178 | 204 | while (query.next()) |
| 179 | 205 | { |
| 180 | | VERBOSE(VB_EIT,QString("Adding channel %1 for source %2 to scan list") |
| 181 | | .arg(query.value(0).toString()).arg(query.value(1).toUInt())); |
| 182 | | activeScanChannels[query.value(0).toUInt()].push_back(query.value(1).toString()); |
| | 206 | VERBOSE(VB_EIT,QString("Adding channel %1 for source %2 " |
| | 207 | "to scan list") |
| | 208 | .arg(query.value(0).toString()) |
| | 209 | .arg(query.value(1).toUInt())); |
| | 210 | channels[query.value(0).toUInt()] |
| | 211 | .push_back(query.value(1).toString()); |
| 183 | 212 | } |
| 184 | 213 | } |
| 185 | 214 | int number = 0; |
| 186 | | for (vector<uint>::iterator it = activeScanSources.begin(); it != activeScanSources.end(); ++it) |
| | 215 | for (vector<uint>::iterator it = sources.begin(); it != sources.end(); ++it) |
| 187 | 216 | { |
| 188 | | activeScanNextChan[*it] = activeScanChannels[*it].begin(); |
| 189 | | number += activeScanChannels[*it].size(); |
| | 217 | nextChan[*it] = channels[*it].begin(); |
| | 218 | number += channels[*it].size(); |
| 190 | 219 | } |
| 191 | 220 | |
| 192 | 221 | VERBOSE(VB_EIT, |
| 193 | 222 | QString("StartActiveScan called with %1 multiplexes on %2 sources") |
| 194 | | .arg(number).arg(activeScanSources.size())); |
| | 223 | .arg(number).arg(sources.size())); |
| 195 | 224 | |
| 196 | | if (activeScanSources.size()) |
| | 225 | if (sources.size()) |
| 197 | 226 | { |
| 198 | | uint max_seconds_per_source = gContext->GetNumSetting("EITTransportTimeout", 5) * 60; |
| | 227 | uint scantime = gContext->GetNumSetting("EITTransportTimeout", 5) * 60; |
| | 228 | uint idle_start = gContext->GetNumSetting("EITCrawIdleStart", 60); |
| 199 | 229 | |
| 200 | | activeScanNextTrig = QDateTime::currentDateTime(); |
| 201 | | activeScanTrigTime = max_seconds_per_source / cardList->size(); |
| 202 | | activeScanNextCard = cardIDToSourceID.begin(); |
| 203 | | nextPruneCacheTime = QDateTime::currentDateTime().addSecs(kPruneCacheTimeOffset); |
| | 230 | nextTriggerTime = QDateTime::currentDateTime().addSecs(idle_start+5); |
| | 231 | triggerTime = scantime / cardList->size(); |
| | 232 | nextCard = cardsSources.begin(); |
| | 233 | nextPruneCacheTime = QDateTime::currentDateTime() |
| | 234 | .addSecs(kPruneCacheTimeOffset); |
| 204 | 235 | } |
| 205 | 236 | } |
=== programs/mythbackend/eitactivescanner.h
==================================================================
|
|
|
|
| 37 | 37 | |
| 38 | 38 | EITCache *eitCache; |
| 39 | 39 | |
| 40 | | QDateTime activeScanNextTrig; |
| 41 | | uint activeScanTrigTime; |
| | 40 | QDateTime nextTriggerTime; |
| | 41 | uint triggerTime; |
| 42 | 42 | |
| 43 | | vector<uint> activeScanSources; |
| 44 | | QMap<uint, QStringList> activeScanChannels; |
| 45 | | QMap<uint, QStringList::iterator> activeScanNextChan; |
| | 43 | vector<uint> sources; |
| | 44 | QMap<uint, QStringList> channels; |
| | 45 | QMap<uint, QStringList::iterator> nextChan; |
| 46 | 46 | |
| 47 | | QMap<int, EncoderLink *> *cardList; |
| 48 | | QMap<int, uint> cardIDToSourceID; |
| 49 | | QMap<int, uint>::iterator activeScanNextCard; |
| | 47 | QMap<int, EncoderLink *> *cardList; |
| 50 | 48 | |
| | 49 | QMap<int, vector<uint> > cardsSources; |
| | 50 | QMap<int, vector<uint> >::iterator nextCard; |
| | 51 | |
| 51 | 52 | bool ismaster; |
| 52 | 53 | |
| 53 | 54 | QDateTime nextPruneCacheTime; |