From af9915b10981420653e97a7ddb5e5527c7b5785c Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Thu, 13 Mar 2014 15:45:41 +0400 Subject: [PATCH] zapit/src/capmt.cpp: stop cam if channel not found Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/b2dc082707f413c7dd92b574e899a474460b138b Author: [CST] Focus Date: 2014-03-13 (Thu, 13 Mar 2014) --- src/zapit/include/zapit/capmt.h | 1 + src/zapit/src/capmt.cpp | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/zapit/include/zapit/capmt.h b/src/zapit/include/zapit/capmt.h index b16180262..30772bc63 100644 --- a/src/zapit/include/zapit/capmt.h +++ b/src/zapit/include/zapit/capmt.h @@ -94,6 +94,7 @@ class CCamManager OpenThreads::Mutex mutex; static CCamManager * manager; bool SetMode(t_channel_id id, enum runmode mode, bool enable, bool force_update = false); + void StopCam(t_channel_id id, CCam *cam); public: CCamManager(); diff --git a/src/zapit/src/capmt.cpp b/src/zapit/src/capmt.cpp index 275b49a44..8f8fc3f95 100644 --- a/src/zapit/src/capmt.cpp +++ b/src/zapit/src/capmt.cpp @@ -181,6 +181,14 @@ CCamManager * CCamManager::getInstance(void) return manager; } +void CCamManager::StopCam(t_channel_id channel_id, CCam *cam) +{ + cam->sendMessage(NULL, 0, false); + cam->sendCaPmt(channel_id, NULL, 0); + channel_map.erase(channel_id); + delete cam; +} + bool CCamManager::SetMode(t_channel_id channel_id, enum runmode mode, bool start, bool force_update) { CCam * cam; @@ -190,12 +198,7 @@ bool CCamManager::SetMode(t_channel_id channel_id, enum runmode mode, bool start CZapitChannel * channel = CServiceManager::getInstance()->FindChannel(channel_id); - if(channel == NULL) { - printf("CCamManager: channel %" PRIx64 " not found\n", channel_id); - return false; - } - //INFO("channel %llx [%s] mode %d %s update %d", channel_id, channel->getName().c_str(), mode, start ? "START" : "STOP", force_update); - mutex.lock(); + OpenThreads::ScopedLock m_lock(mutex); cammap_iterator_t it = channel_map.find(channel_id); if(it != channel_map.end()) { @@ -204,9 +207,14 @@ bool CCamManager::SetMode(t_channel_id channel_id, enum runmode mode, bool start cam = new CCam(); channel_map.insert(std::pair(channel_id, cam)); } else { - mutex.unlock(); return false; } + if(channel == NULL) { + printf("CCamManager: channel %" PRIx64 " not found\n", channel_id); + StopCam(channel_id, cam); + return false; + } + //INFO("channel %llx [%s] mode %d %s update %d", channel_id, channel->getName().c_str(), mode, start ? "START" : "STOP", force_update); /* FIXME until proper demux management */ switch(mode) { @@ -246,10 +254,7 @@ bool CCamManager::SetMode(t_channel_id channel_id, enum runmode mode, bool start if((oldmask != newmask) || force_update) { cam->setCaMask(newmask); cam->setSource(source); - if(newmask == 0) { - cam->sendMessage(NULL, 0, false); - cam->sendCaPmt(channel->getChannelID(), NULL, 0); - } else { + if(newmask != 0) { cam->makeCaPmt(channel, true); cam->setCaPmt(true); } @@ -259,9 +264,9 @@ bool CCamManager::SetMode(t_channel_id channel_id, enum runmode mode, bool start /* FIXME: back to live channel from playback dont parse pmt and call setCaPmt * (see CMD_SB_LOCK / UNLOCK PLAYBACK */ //channel->setRawPmt(NULL);//FIXME - channel_map.erase(channel_id); - delete cam; + StopCam(channel_id, cam); } + CaIdVector caids; cCA::GetInstance()->GetCAIDS(caids); //uint8_t list = CCam::CAPMT_FIRST; @@ -287,7 +292,6 @@ bool CCamManager::SetMode(t_channel_id channel_id, enum runmode mode, bool start cam->sendCaPmt(channel->getChannelID(), buffer, len); //list = CCam::CAPMT_MORE; } - mutex.unlock(); return true; }