#include <lib/dvb/sec.h>
#include <lib/dvb/specs.h>
+#include <lib/dvb/fbc.h>
+#include <lib/dvb/fcc.h>
+
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
eDVBAllocatedFrontend::~eDVBAllocatedFrontend()
{
m_fe->dec_use();
+ if (m_fe->m_frontend->is_FBCTuner())
+ {
+ eFBCTunerManager* fbcmng = eFBCTunerManager::getInstance();
+ if (fbcmng)
+ {
+ fbcmng->unset(m_fe);
+ }
+ }
}
DEFINE_REF(eDVBAllocatedDemux);
RESULT eDVBResourceManager::allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm, bool simulate)
{
eSmartPtrList<eDVBRegisteredFrontend> &frontends = simulate ? m_simulate_frontend : m_frontend;
- ePtr<eDVBRegisteredFrontend> best;
+// ePtr<eDVBRegisteredFrontend> best;
+ eDVBRegisteredFrontend *best = NULL;
int bestval = 0;
int foundone = 0;
+ int check_fbc_linked = 0;
+ eDVBRegisteredFrontend *fbc_fe = NULL;
+ eDVBRegisteredFrontend *best_fbc_fe = NULL;
+ eFBCTunerManager* fbcmng = eFBCTunerManager::getInstance();
+
for (eSmartPtrList<eDVBRegisteredFrontend>::iterator i(frontends.begin()); i != frontends.end(); ++i)
{
- int c = i->m_frontend->isCompatibleWith(feparm);
+ int c = 0;
+ fbc_fe = NULL;
+ if (!check_fbc_linked && i->m_frontend->is_FBCTuner() && fbcmng && fbcmng->canLink(*i))
+ {
+ check_fbc_linked = 1;
+ c = fbcmng->isCompatibleWith(feparm, *i, fbc_fe, simulate);
+
+// eDebug("[eDVBResourceManager::allocateFrontend] fbcmng->isCompatibleWith slotid : %p (%d), fbc_fe : %p (%d), score : %d", (eDVBRegisteredFrontend *)*i, i->m_frontend->getSlotID(), fbc_fe, fbc_fe?fbc_fe->m_frontend->getSlotID():-1, c);
+ }
+ else
+ {
+ c = i->m_frontend->isCompatibleWith(feparm);
+ }
if (c) /* if we have at least one frontend which is compatible with the source, flag this. */
foundone = 1;
if (c > bestval)
{
bestval = c;
- best = i;
+// best = i;
+ best = *i;
+ best_fbc_fe = fbc_fe;
}
}
-// else
+ else
+ {
// eDebug("Slot %d, score %d... but BUSY!!!!!!!!!!!", i->m_frontend->getSlotID(), c);
+ }
+
+ eDVBRegisteredFrontend *tmp = *i;
}
if (best)
{
+ if (fbcmng && best_fbc_fe)
+ {
+ fbcmng->addLink(best, best_fbc_fe, simulate);
+ }
+
fe = new eDVBAllocatedFrontend(best);
return 0;
}
if (!simulate) \
eDebug(x); \
} while(0)
-// else \
-// { \
-// eDebugNoNewLine("SIMULATE:"); \
-// eDebug(x); \
-// } \
-
RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel, bool simulate)
{
eSmartPtrList<eDVBRegisteredFrontend> &frontends = simulate ? m_simulate_frontend : m_frontend;
ePtr<eDVBRegisteredFrontend> best;
int bestval = 0;
+ int check_fbc_link = 0;
+ eFBCTunerManager *fbcmng = eFBCTunerManager::getInstance();
for (eSmartPtrList<eDVBRegisteredFrontend>::iterator i(frontends.begin()); i != frontends.end(); ++i)
+ {
if (!i->m_inuse)
{
- int c = i->m_frontend->isCompatibleWith(feparm);
+ int c = 0;
+ if(fbcmng && i->m_frontend->is_FBCTuner() && fbcmng->canLink(*i) && !check_fbc_link)
+ {
+ check_fbc_link = 1;
+ c = fbcmng->isCompatibleWith(feparm, *i, simulate);
+ }
+ else
+ {
+ c = i->m_frontend->isCompatibleWith(feparm);
+ }
if (c > bestval)
bestval = c;
}
+ }
return bestval;
}
int *decremented_cached_channel_fe_usecount=NULL,
*decremented_fe_usecount=NULL;
+ /* check FCC channels */
+ std::vector<int*> fcc_decremented_fe_usecounts;
+ std::map<eDVBChannelID, int> fcc_chids;
+ int apply_to_ignore = 0;
+ if (!eFCCServiceManager::getFCCChannelID(fcc_chids))
+ {
+ for (std::map<eDVBChannelID, int>::iterator i(fcc_chids.begin()); i != fcc_chids.end(); ++i)
+ {
+ //eDebug("[eDVBResourceManager::canAllocateChannel] FCC NS : %08x, TSID : %04x, ONID : %04x", i->first.dvbnamespace.get(), i->first.transport_stream_id.get(), i->first.original_network_id.get());
+ if (ignore == i->first)
+ {
+ apply_to_ignore = i->second;
+ continue;
+ }
+ for (std::list<active_channel>::iterator ii(active_channels.begin()); ii != active_channels.end(); ++ii)
+ {
+ eSmartPtrList<eDVBRegisteredFrontend> &frontends = simulate ? m_simulate_frontend : m_frontend;
+ if (ii->m_channel_id == i->first)
+ {
+ eDVBChannel *channel = (eDVBChannel*) &(*ii->m_channel);
+
+ int check_usecount = channel == &(*m_cached_channel) ? 1 : 0;
+ check_usecount += i->second * 2; // one is used in eDVBServicePMTHandler and another is used in eDVBScan.
+ //eDebug("[eDVBResourceManager::canAllocateChannel] channel->getUseCount() : %d , check_usecount : %d (cached : %d)", channel->getUseCount(), check_usecount, channel == &(*m_cached_channel));
+ if (channel->getUseCount() == check_usecount)
+ {
+ ePtr<iDVBFrontend> fe;
+ if (!ii->m_channel->getFrontend(fe))
+ {
+ for (eSmartPtrList<eDVBRegisteredFrontend>::iterator iii(frontends.begin()); iii != frontends.end(); ++iii)
+ {
+ if ( &(*fe) == &(*iii->m_frontend) )
+ {
+ //eDebug("[eDVBResourceManager::canAllocateChannel] fcc : decrease fcc fe use_count! feid : %d (%d -> %d)", iii->m_frontend->getSlotID(), iii->m_inuse, iii->m_inuse-1);
+ --iii->m_inuse;
+ int *tmp_decremented_fe_usecount = &iii->m_inuse;
+ fcc_decremented_fe_usecounts.push_back(tmp_decremented_fe_usecount);
+ if (channel == &(*m_cached_channel))
+ decremented_cached_channel_fe_usecount = tmp_decremented_fe_usecount;
+ break;
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+
for (std::list<active_channel>::iterator i(active_channels.begin()); i != active_channels.end(); ++i)
{
eSmartPtrList<eDVBRegisteredFrontend> &frontends = simulate ? m_simulate_frontend : m_frontend;
// another on eUsePtr<iDVBChannel> is used in the eDVBScan instance used in eDVBServicePMTHandler (for SDT scan)
// so we must check here if usecount is 3 (when the channel is equal to the cached channel)
// or 2 when the cached channel is not equal to the compared channel
- if (channel == &(*m_cached_channel) ? channel->getUseCount() == 3 : channel->getUseCount() == 2) // channel only used once..
+ int check_usecount = channel == &(*m_cached_channel) ? 1 : 0;
+ check_usecount += (apply_to_ignore+1) * 2; // one is used in eDVBServicePMTHandler and another is used in eDVBScan.
+ //eDebug("[eDVBResourceManager::canAllocateChannel] channel->getUseCount() : %d , check_usecount : %d (cached : %d)", channel->getUseCount(), check_usecount, channel == &(*m_cached_channel));
+ if (channel->getUseCount() == check_usecount) // channel only used once..(except fcc)
{
ePtr<iDVBFrontend> fe;
if (!i->m_channel->getFrontend(fe))
{
if ( &(*fe) == &(*ii->m_frontend) )
{
+ //eDebug("[eDVBResourceManager::canAllocateChannel] ignore : decrease fcc fe use_count! feid : %d (%d -> %d)", ii->m_frontend->getSlotID(), ii->m_inuse, ii->m_inuse-1);
--ii->m_inuse;
decremented_fe_usecount = &ii->m_inuse;
if (channel == &(*m_cached_channel))
++(*decremented_fe_usecount);
if (decremented_cached_channel_fe_usecount)
++(*decremented_cached_channel_fe_usecount);
+ if (fcc_decremented_fe_usecounts.size())
+ {
+ for (std::vector<int*>::iterator i(fcc_decremented_fe_usecounts.begin()); i != fcc_decremented_fe_usecounts.end(); ++i)
+ {
+ //eDebug("[eDVBResourceManager::canAllocateChannel] fcc : increase fcc fe use_count!");
+ ++(**i);
+ }
+ }
return ret;
}