fix (or hack) scart switching because the value in /proc/stb/avs/0/fb reads low,...
[enigma2.git] / lib / dvb / dvb.cpp
index 0a5bb45e3b189fb65b6fa2904b7473f6ca5976ff..6289937997c0e19d75396e8942036ca6e5aa8d31 100644 (file)
@@ -440,6 +440,14 @@ bool eDVBResourceManager::canAllocateFrontend(ePtr<iDVBFrontendParameters> &fepa
 
 bool eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID& ignore)
 {
+       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());
        for (std::list<active_channel>::iterator i(m_active_channels.begin()); i != m_active_channels.end(); ++i)
@@ -448,11 +456,12 @@ bool eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, con
                if (i->m_channel_id == channelid)
                {
 //                     eDebug("found shared channel..");
-                       return true;
+                       return ret;
                }
        }
 
-       int *decremented_fe_usecount=NULL;
+       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)
        {
@@ -471,6 +480,8 @@ bool eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, con
                                                {
                                                        --ii->m_inuse;
                                                        decremented_fe_usecount = &ii->m_inuse;
+                                                       if (channel == &(*m_cached_channel))
+                                                               decremented_cached_channel_fe_usecount = decremented_fe_usecount;
                                                        break;
                                                }
                                        }
@@ -480,23 +491,52 @@ bool eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, con
                }
        }
 
+       if (!decremented_cached_channel_fe_usecount)
+       {
+               eDVBChannel *channel = (eDVBChannel*) &(*m_cached_channel);
+               if (channel->getUseCount() == 1)
+               {
+                       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) )
+                                       {
+                                               --ii->m_inuse;
+                                               decremented_cached_channel_fe_usecount = &ii->m_inuse;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+       }
+       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;
        }
 
-       bool ret = canAllocateFrontend(feparm);
+       ret = canAllocateFrontend(feparm);
 
+error:
        if (decremented_fe_usecount)
                ++(*decremented_fe_usecount);
+       if (decremented_cached_channel_fe_usecount)
+               ++(*decremented_cached_channel_fe_usecount);
 
        return ret;
 }
@@ -680,7 +720,7 @@ RESULT eDVBChannel::playFile(const char *file)
                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);
@@ -702,7 +742,7 @@ RESULT eDVBChannel::getLength(pts_t &len)
        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;
@@ -718,7 +758,8 @@ RESULT eDVBChannel::getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos)
        
        pts_t now;
        
-       r = decoding_demux->getSTC(now);
+                       /* TODO: this is a gross hack. */
+       r = decoding_demux->getSTC(now, mode ? 128 : 0);
 
        if (r)
        {
@@ -753,7 +794,7 @@ RESULT eDVBChannel::seekTo(iDVBDemux *decoding_demux, int relative, pts_t &pts)
        if (relative)
        {
                pts_t now;
-               if (getCurrentPosition(decoding_demux, now))
+               if (getCurrentPosition(decoding_demux, now, 0))
                {
                        eDebug("seekTo: getCurrentPosition failed!");
                        return -1;