driver/scanepg.cpp: try to make zap for epg scan non-blocking

This commit is contained in:
[CST] Focus
2013-08-12 13:35:32 +04:00
parent 640056c938
commit 46980f524d
2 changed files with 59 additions and 30 deletions

View File

@@ -42,6 +42,7 @@ extern CBouquetList * bouquetList;
CEpgScan::CEpgScan() CEpgScan::CEpgScan()
{ {
current_bnum = -1; current_bnum = -1;
next_chid = 0;
} }
CEpgScan::~CEpgScan() CEpgScan::~CEpgScan()
@@ -60,6 +61,7 @@ void CEpgScan::Clear()
{ {
scanmap.clear(); scanmap.clear();
current_bnum = -1; current_bnum = -1;
next_chid = 0;
} }
void CEpgScan::handleMsg(const neutrino_msg_t msg, neutrino_msg_data_t data) void CEpgScan::handleMsg(const neutrino_msg_t msg, neutrino_msg_data_t data)
@@ -98,39 +100,64 @@ void CEpgScan::handleMsg(const neutrino_msg_t msg, neutrino_msg_data_t data)
if (scanmap.empty()) if (scanmap.empty())
return; return;
t_channel_id live_channel_id = CZapit::getInstance()->GetCurrentChannelID(); Next();
}
CFrontend *live_fe = CZapit::getInstance()->GetLiveFrontend(); else if (msg == NeutrinoMessages::EVT_BACK_ZAP_COMPLETE) {
CFEManager::getInstance()->lockFrontend(live_fe); t_channel_id chid = *(t_channel_id *)data;
#ifdef ENABLE_PIP INFO("EVT_BACK_ZAP_COMPLETE [" PRINTF_CHANNEL_ID_TYPE "]", chid);
CFrontend *pip_fe = CZapit::getInstance()->GetPipFrontend(); if (next_chid) {
if (pip_fe && pip_fe != live_fe) newchan = CServiceManager::getInstance()->FindChannel(next_chid);
CFEManager::getInstance()->lockFrontend(pip_fe); if (newchan) {
#endif if(chid) {
for (eit_scanmap_iterator_t it = scanmap.begin(); it != scanmap.end(); /* ++it*/) { INFO("try to scan [%s]", newchan->getName().c_str());
newchan = CServiceManager::getInstance()->FindChannel(it->second);
if ((newchan == NULL) || SAME_TRANSPONDER(live_channel_id, newchan->getChannelID())) {
scanmap.erase(it++);
continue;
}
if (CFEManager::getInstance()->canTune(newchan)) {
INFO("try to scan [%s]", newchan->getName().c_str());
bool ret = g_Zapit->zapTo_record(newchan->getChannelID()) > 0;
if (ret) {
g_Sectionsd->setServiceChanged(newchan->getChannelID(), false, newchan->getRecordDemux()); g_Sectionsd->setServiceChanged(newchan->getChannelID(), false, newchan->getRecordDemux());
break;
} else { } else {
scanmap.erase(it++); INFO("tune failed [%s]", newchan->getName().c_str());
continue; scanmap.erase(newchan->getTransponderId());
Next();
} }
} else }
INFO("skip [%s], cannot tune", newchan->getName().c_str());
++it;
} }
CFEManager::getInstance()->unlockFrontend(live_fe);
#ifdef ENABLE_PIP
if (pip_fe && pip_fe != live_fe)
CFEManager::getInstance()->unlockFrontend(pip_fe);
#endif
} }
} }
void CEpgScan::Next()
{
next_chid = 0;
if (CNeutrinoApp::getInstance()->getMode() != NeutrinoMessages::mode_standby)
return;
t_channel_id live_channel_id = CZapit::getInstance()->GetCurrentChannelID();
CFrontend *live_fe = CZapit::getInstance()->GetLiveFrontend();
/* executed in neutrino thread - possible race with locks in zapit zap NOWAIT :
send zaTo_NOWAIT -> EIT_COMPLETE from sectionsd -> zap and this at the same time
*/
CFEManager::getInstance()->lockFrontend(live_fe);
#ifdef ENABLE_PIP
CFrontend *pip_fe = CZapit::getInstance()->GetPipFrontend();
if (pip_fe && pip_fe != live_fe)
CFEManager::getInstance()->lockFrontend(pip_fe);
#endif
for (eit_scanmap_iterator_t it = scanmap.begin(); it != scanmap.end(); /* ++it*/) {
CZapitChannel * newchan = CServiceManager::getInstance()->FindChannel(it->second);
if ((newchan == NULL) || SAME_TRANSPONDER(live_channel_id, newchan->getChannelID())) {
scanmap.erase(it++);
continue;
}
if (CFEManager::getInstance()->canTune(newchan)) {
INFO("try to tune [%s]", newchan->getName().c_str());
next_chid = newchan->getChannelID();
break;
} else
INFO("skip [%s], cannot tune", newchan->getName().c_str());
++it;
}
CFEManager::getInstance()->unlockFrontend(live_fe);
#ifdef ENABLE_PIP
if (pip_fe && pip_fe != live_fe)
CFEManager::getInstance()->unlockFrontend(pip_fe);
#endif
if (next_chid)
g_Zapit->zapTo_epg(next_chid);
}

View File

@@ -31,7 +31,9 @@ class CEpgScan
private: private:
int current_bnum; int current_bnum;
eit_scanmap_t scanmap; eit_scanmap_t scanmap;
t_channel_id next_chid;
std::set<transponder_id_t> scanned; std::set<transponder_id_t> scanned;
void Next();
CEpgScan(); CEpgScan();
public: public: