eDVBAllocatedFrontend::eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe): m_fe(fe)
{
- m_fe->m_inuse++;
+ m_fe->inc_use();
}
eDVBAllocatedFrontend::~eDVBAllocatedFrontend()
{
- --m_fe->m_inuse;
+ m_fe->dec_use();
}
DEFINE_REF(eDVBAllocatedDemux);
if (!adapter->getFrontend(frontend, i))
{
- frontend->setTone(iDVBFrontend::toneOff);
- frontend->setVoltage(iDVBFrontend::voltageOff);
frontend->setSEC(m_sec);
m_frontend.push_back(new eDVBRegisteredFrontend(frontend, adapter));
}
RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel)
{
/* first, check if a channel is already existing. */
-
+
+ if (m_cached_channel)
+ {
+ eDVBChannel *cache_chan = (eDVBChannel*)&(*m_cached_channel);
+ if(channelid==cache_chan->getChannelID())
+ {
+ eDebug("use cached_channel");
+ channel=m_cached_channel;
+ return 0;
+ }
+ m_cached_channel=0;
+ }
+
// eDebug("allocate channel.. %04x:%04x", channelid.transport_stream_id.get(), channelid.original_network_id.get());
for (std::list<active_channel>::iterator i(m_active_channels.begin()); i != m_active_channels.end(); ++i)
{
channel = 0;
return errChidNotFound;
}
- channel = ch;
+ m_cached_channel = channel = ch;
return 0;
}
{
ePtr<eDVBAllocatedFrontend> fe;
+ if (m_cached_channel)
+ m_cached_channel=0;
+
if (allocateFrontendByIndex(fe, frontend_index))
return errNoFrontend;
RESULT eDVBResourceManager::allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel)
{
ePtr<eDVBAllocatedDemux> demux;
-
+
+ if (m_cached_channel)
+ m_cached_channel=0;
+
eDVBChannel *ch;
ch = new eDVBChannel(this, 0);
return 0;
}
-bool eDVBResourceManager::canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm, int used_tuner_mask)
+bool eDVBResourceManager::canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm)
{
- eDebug("canAllocateFrontend mask %08x", used_tuner_mask);
ePtr<eDVBRegisteredFrontend> best;
int bestval = 0;
for (eSmartPtrList<eDVBRegisteredFrontend>::iterator i(m_frontend.begin()); i != m_frontend.end(); ++i)
- if ( !(used_tuner_mask & (1<<i->m_frontend->getID())) )
+ if (!i->m_inuse)
{
int c = i->m_frontend->isCompatibleWith(feparm);
if (c > bestval)
return bestval>0;
}
-bool eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid)
+bool eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID& ignore)
{
- return true;
-#if 0
- int used_tuner_mask=0;
+ bool ret=true;
+ if (m_cached_channel)
+ {
+ eDVBChannel *cache_chan = (eDVBChannel*)&(*m_cached_channel);
+ if(channelid==cache_chan->getChannelID())
+ return ret;
+ }
/* first, check if a channel is already existing. */
// eDebug("allocate channel.. %04x:%04x", channelid.transport_stream_id.get(), channelid.original_network_id.get());
- int cnt=0;
- for (std::list<active_channel>::iterator i(m_active_channels.begin()); i != m_active_channels.end(); ++i, ++cnt)
+ for (std::list<active_channel>::iterator i(m_active_channels.begin()); i != m_active_channels.end(); ++i)
{
// eDebug("available channel.. %04x:%04x", i->m_channel_id.transport_stream_id.get(), i->m_channel_id.original_network_id.get());
if (i->m_channel_id == channelid)
{
// eDebug("found shared channel..");
- return true;
+ return ret;
+ }
+ }
+
+ int *decremented_cached_channel_fe_usecount=NULL,
+ *decremented_fe_usecount=NULL;
+
+ for (std::list<active_channel>::iterator i(m_active_channels.begin()); i != m_active_channels.end(); ++i)
+ {
+// eDebug("available channel.. %04x:%04x", i->m_channel_id.transport_stream_id.get(), i->m_channel_id.original_network_id.get());
+ if (i->m_channel_id == ignore)
+ {
+ eDVBChannel *channel = (eDVBChannel*) &(*i->m_channel);
+ if (channel == &(*m_cached_channel) ? channel->getUseCount() == 2 : channel->getUseCount() == 1) // channel only used once..
+ {
+ ePtr<iDVBFrontend> fe;
+ if (!i->m_channel->getFrontend(fe))
+ {
+ for (eSmartPtrList<eDVBRegisteredFrontend>::iterator ii(m_frontend.begin()); ii != m_frontend.end(); ++ii)
+ {
+ if ( &(*fe) == &(*ii->m_frontend) )
+ {
+ --ii->m_inuse;
+ decremented_fe_usecount = &ii->m_inuse;
+ if (channel == &(*m_cached_channel))
+ decremented_cached_channel_fe_usecount = decremented_fe_usecount;
+ break;
+ }
+ }
+ }
+ }
+ break;
}
+ }
- eDebug("activeChannel %d, NonDecoderDemux %p, DecoderDemux %p",
- cnt, i->m_channel->getNonDecoderDemux(), i->m_channel->getDecoderDemux() );
- if ( i->m_channel->getNonDecoderDemux() )
+ if (!decremented_cached_channel_fe_usecount)
+ {
+ if (m_cached_channel)
{
- ePtr<iDVBFrontend> fe;
- if (!i->m_channel->getFrontend(fe))
+ eDVBChannel *channel = (eDVBChannel*) &(*m_cached_channel);
+ if (channel->getUseCount() == 1)
{
- if (fe)
+ ePtr<iDVBFrontend> fe;
+ if (!channel->getFrontend(fe))
{
for (eSmartPtrList<eDVBRegisteredFrontend>::iterator ii(m_frontend.begin()); ii != m_frontend.end(); ++ii)
{
if ( &(*fe) == &(*ii->m_frontend) )
{
- used_tuner_mask |= (1 << ii->m_frontend->getID());
+ --ii->m_inuse;
+ decremented_cached_channel_fe_usecount = &ii->m_inuse;
break;
}
}
}
- else
- eDebug("fe kaputt");
}
}
}
+ else
+ decremented_cached_channel_fe_usecount=NULL;
+
+ ePtr<iDVBFrontendParameters> feparm;
if (!m_list)
{
eDebug("no channel list set!");
- return false;
+ ret = false;
+ goto error;
}
- ePtr<iDVBFrontendParameters> feparm;
if (m_list->getChannelFrontendData(channelid, feparm))
{
eDebug("channel not found!");
- return false;
+ ret = false;
+ goto error;
}
- return canAllocateFrontend(feparm, used_tuner_mask);
-#endif
+ ret = canAllocateFrontend(feparm);
+
+error:
+ if (decremented_fe_usecount)
+ ++(*decremented_fe_usecount);
+ if (decremented_cached_channel_fe_usecount)
+ ++(*decremented_cached_channel_fe_usecount);
+
+ return ret;
}
DEFINE_REF(eDVBChannel);
return -ENODEV;
}
- m_pvr_fd_src = open(file, O_RDONLY);
+ m_pvr_fd_src = open(file, O_RDONLY|O_LARGEFILE);
if (m_pvr_fd_src < 0)
{
eDebug("can't open PVR m_pvr_fd_src file %s (%m)", file);
return m_tstools.calcLen(len);
}
-RESULT eDVBChannel::getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos)
+RESULT eDVBChannel::getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode)
{
if (!decoding_demux)
return -1;
pts_t now;
- r = decoding_demux->getSTC(now);
+ /* TODO: this is a gross hack. */
+ r = decoding_demux->getSTC(now, mode ? 128 : 0);
if (r)
{
if (relative)
{
pts_t now;
- if (getCurrentPosition(decoding_demux, now))
+ if (getCurrentPosition(decoding_demux, now, 0))
{
eDebug("seekTo: getCurrentPosition failed!");
return -1;