zapit/src/capmt.cpp: stop cam if channel not found

Origin commit data
------------------
Commit: b2dc082707
Author: [CST] Focus <focus.cst@gmail.com>
Date: 2014-03-13 (Thu, 13 Mar 2014)
This commit is contained in:
[CST] Focus
2014-03-13 15:45:41 +04:00
parent 8eb6ec4a1c
commit af9915b109
2 changed files with 19 additions and 14 deletions

View File

@@ -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();

View File

@@ -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<OpenThreads::Mutex> 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<t_channel_id, CCam*>(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;
}