=== programs/mythbackend/eitactivescanner.cpp
==================================================================
--- programs/mythbackend/eitactivescanner.cpp	(revision 238)
+++ programs/mythbackend/eitactivescanner.cpp	(revision 239)
@@ -65,58 +65,83 @@
     {
         QDateTime now = QDateTime::currentDateTime();
 
-        if (ismaster && (now > activeScanNextTrig) && !cardList->isEmpty())
+        if (ismaster && (now > nextTriggerTime) && !cardList->isEmpty())
         {
-            cerr << eitCache->GetStatistics() << endl;
-            if (activeScanNextCard == cardIDToSourceID.end())
+            VERBOSE(VB_EIT, eitCache->GetStatistics());
+            if (nextCard == cardsSources.end())
             {
-                activeScanNextCard = cardIDToSourceID.begin();
+                nextCard = cardsSources.begin();
             }
 
-            uint source = *activeScanNextCard;
+            // find source with the highest priority
+            vector<uint>::iterator source = sources.begin();
+            while (source != sources.end())
+            {
+                if ((*nextCard).end() != find((*nextCard).begin(),
+                                            (*nextCard).end(), *source))
+                    break;
+                ++source;
+            }
+            if (source == sources.end())
+            {
+                VERBOSE(VB_EIT, QString("Couldn't find source for card %1.")
+                        .arg(nextCard.key()));
+                continue;
+            }
+            int cardid = nextCard.key();
 
-            int curCardID = activeScanNextCard.key();
-            if (activeScanNextChan[source] == activeScanChannels[source].end())
-                activeScanNextChan[source] = activeScanChannels[source].begin();
 
-            if (!(*(activeScanNextChan[source])).isEmpty() &&
-                (*cardList)[curCardID]->StartEITScan(*(activeScanNextChan[source])))
+            if (!(*(nextChan[*source])).isEmpty() &&
+                (*cardList)[cardid]->StartEITScan(*(nextChan[*source])))
             {
-                VERBOSE(VB_GENERAL, QString("(%1)Now looking for EIT data on "
-                                            "multiplex of channel %2 of source %3")
-                        .arg(curCardID).arg(*(activeScanNextChan[source])).arg(source));
-                activeScanNextChan[source]++;
+                VERBOSE(VB_GENERAL, QString("DVB(%1): Now looking for EIT "
+                                            "data on multiplex of channel %2 "
+                                            "of source %3")
+                        .arg(cardid).arg(*(nextChan[*source])).arg(*source));
+                /* advace to the next channel and test for valid iterator.
+                   needed to simplify selection of the source
+                   with the highest priority. */
+                nextChan[*source]++;
+                if (nextChan[*source] == channels[*source].end())
+                {
+                    nextChan[*source] = channels[*source].begin();
+                    sources.push_back(*source);
+                    sources.erase(source);
+                }
             }
             else
             {
-                VERBOSE(VB_GENERAL, QString("Skipping card %1 in scan for EIT data on "
-                                            "multiplex of channel %2 of source %3")
-                        .arg(curCardID).arg(*(activeScanNextChan[source])).arg(source));
+                VERBOSE(VB_GENERAL, QString("Skipping card %1 in scan for EIT "
+                                            "data on multiplex of channel %2 "
+                                            "of source %3")
+                        .arg(cardid).arg(*(nextChan[*source])).arg(*source));
             }
 
-            activeScanNextTrig = QDateTime::currentDateTime()
-                .addSecs(activeScanTrigTime);
+            nextTriggerTime = QDateTime::currentDateTime().addSecs(triggerTime);
 
-            activeScanNextCard++;
+            nextCard++;
         }
 
+        // prune cache entries that ended more than kPruneCacheTimeOffset ago
         if (now > nextPruneCacheTime)
         {
-            // prune cache entries that ended more than kPruneCacheTimeOffset ago
-            uint prunedEntries = eitCache->PruneOldEntries(now.addSecs(-kPruneCacheTimeOffset).toTime_t());
-            nextPruneCacheTime.addSecs(kPruneCacheTimeOffset);
+            uint prunedEntries = eitCache->PruneOldEntries(now
+                                 .addSecs(-kPruneCacheTimeOffset).toTime_t());
+            nextPruneCacheTime =  QDateTime::currentDateTime()
+                .addSecs(kPruneCacheTimeOffset);
 
-            VERBOSE(VB_GENERAL, QString("Pruned %1 entries from the eit cache")
+            VERBOSE(VB_EIT, eitCache->GetStatistics());
+            VERBOSE(VB_EIT, QString("Pruned %1 entries from the eit cache")
                         .arg(prunedEntries));
         }
             
-        exitThreadCond.wait(200); // sleep up to 200 ms.
+        exitThreadCond.wait(1000); // sleep up to 1 second.
     }
 }
 
 void EITActiveScanner::StartActiveScan()
 {
-    if (!activeScanSources.size())
+    if (!sources.size())
     {
         // get all source ids with useeit == 1
         MSqlQuery query(MSqlQuery::InitCon());
@@ -137,7 +162,7 @@
         }
         
         while (query.next())
-            activeScanSources.push_back(query.value(0).toUInt());
+            sources.push_back(query.value(0).toUInt());
 
         // getting mapping from cardid to sourceid with useeit == 1
         query.prepare(
@@ -154,7 +179,8 @@
         }
         
         while (query.next())
-            cardIDToSourceID[query.value(0).toInt()] = query.value(1).toUInt();
+            cardsSources[query.value(0).toInt()]
+                .push_back(query.value(1).toUInt());
 
 
         // get one channel with sourceid per mplexid
@@ -177,29 +203,34 @@
 
         while (query.next())
         {
-            VERBOSE(VB_EIT,QString("Adding channel %1 for source %2 to scan list")
-            .arg(query.value(0).toString()).arg(query.value(1).toUInt()));
-            activeScanChannels[query.value(0).toUInt()].push_back(query.value(1).toString());
+            VERBOSE(VB_EIT,QString("Adding channel %1 for source %2 "
+                                   "to scan list")
+                    .arg(query.value(0).toString())
+                    .arg(query.value(1).toUInt()));
+            channels[query.value(0).toUInt()]
+                .push_back(query.value(1).toString());
         }
     }
     int number = 0;
-    for (vector<uint>::iterator it = activeScanSources.begin(); it != activeScanSources.end(); ++it)
+    for (vector<uint>::iterator it = sources.begin(); it != sources.end(); ++it)
     {
-        activeScanNextChan[*it] = activeScanChannels[*it].begin();
-        number += activeScanChannels[*it].size();
+        nextChan[*it] = channels[*it].begin();
+        number += channels[*it].size();
     }
 
     VERBOSE(VB_EIT,
             QString("StartActiveScan called with %1 multiplexes on %2 sources")
-            .arg(number).arg(activeScanSources.size()));
+            .arg(number).arg(sources.size()));
 
-    if (activeScanSources.size())
+    if (sources.size())
     {
-        uint max_seconds_per_source = gContext->GetNumSetting("EITTransportTimeout", 5) * 60;
+        uint scantime = gContext->GetNumSetting("EITTransportTimeout", 5) * 60;
+        uint idle_start = gContext->GetNumSetting("EITCrawIdleStart", 60);
 
-        activeScanNextTrig = QDateTime::currentDateTime();
-        activeScanTrigTime = max_seconds_per_source / cardList->size();
-        activeScanNextCard = cardIDToSourceID.begin();
-        nextPruneCacheTime = QDateTime::currentDateTime().addSecs(kPruneCacheTimeOffset);
+        nextTriggerTime    = QDateTime::currentDateTime().addSecs(idle_start+5);
+        triggerTime        = scantime / cardList->size();
+        nextCard           = cardsSources.begin();
+        nextPruneCacheTime = QDateTime::currentDateTime()
+            .addSecs(kPruneCacheTimeOffset);
     }
 }
=== programs/mythbackend/eitactivescanner.h
==================================================================
--- programs/mythbackend/eitactivescanner.h	(revision 238)
+++ programs/mythbackend/eitactivescanner.h	(revision 239)
@@ -37,17 +37,18 @@
 
     EITCache         *eitCache;
 
-    QDateTime        activeScanNextTrig;
-    uint             activeScanTrigTime;
+    QDateTime        nextTriggerTime;
+    uint             triggerTime;
 
-    vector<uint>                      activeScanSources;
-    QMap<uint, QStringList>           activeScanChannels;
-    QMap<uint, QStringList::iterator> activeScanNextChan;
+    vector<uint>                        sources;
+    QMap<uint, QStringList>             channels;
+    QMap<uint, QStringList::iterator>   nextChan;
 
-    QMap<int, EncoderLink *>   *cardList;
-    QMap<int, uint>            cardIDToSourceID;
-    QMap<int, uint>::iterator  activeScanNextCard;
+    QMap<int, EncoderLink *>            *cardList;
 
+    QMap<int, vector<uint> >            cardsSources;
+    QMap<int, vector<uint> >::iterator  nextCard;
+
     bool                ismaster;
 
     QDateTime           nextPruneCacheTime;
