use cached pts/offsets when available, clean up
[enigma2.git] / lib / dvb / dvb.cpp
index f246936588842d5c957390a86c599931717488e9..11b1285a702d7cbec6dd6b8ed41137bbe0db1d56 100644 (file)
@@ -312,6 +312,7 @@ RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, eUse
                }
                m_cached_channel_state_changed_conn.disconnect();
                m_cached_channel=0;
+               m_releaseCachedChannelTimer.stop();
        }
 
 //     eDebug("allocate channel.. %04x:%04x", channelid.transport_stream_id.get(), channelid.original_network_id.get());
@@ -391,8 +392,7 @@ void eDVBResourceManager::DVBChannelStateChanged(iDVBChannel *chan)
 
 void eDVBResourceManager::releaseCachedChannel()
 {
-       eDebug("release cached channel");
-       m_cached_channel_state_changed_conn.disconnect();
+       eDebug("release cached channel (timer timeout)");
        m_cached_channel=0;
 }
 
@@ -404,6 +404,7 @@ RESULT eDVBResourceManager::allocateRawChannel(eUsePtr<iDVBChannel> &channel, in
        {
                m_cached_channel_state_changed_conn.disconnect();
                m_cached_channel=0;
+               m_releaseCachedChannelTimer.stop();
        }
 
        if (allocateFrontendByIndex(fe, frontend_index))
@@ -421,12 +422,6 @@ RESULT eDVBResourceManager::allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel)
 {
        ePtr<eDVBAllocatedDemux> demux;
 
-       if (m_cached_channel)
-       {
-               m_cached_channel_state_changed_conn.disconnect();
-               m_cached_channel=0;
-       }
-
        eDVBChannel *ch;
        ch = new eDVBChannel(this, 0);
        
@@ -1001,17 +996,8 @@ RESULT eDVBChannel::getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, in
        if (!decoding_demux)
                return -1;
        
-       off_t begin = 0;
-               /* getPTS for offset 0 is cached, so it doesn't harm. */
-       int r = m_tstools.getPTS(begin, pos);
-       if (r)
-       {
-               eDebug("tstools getpts(0) failed!");
-               return r;
-       }
-       
        pts_t now;
-       
+       int r;
                        /* TODO: this is a gross hack. */
        r = decoding_demux->getSTC(now, mode ? 128 : 0);
 
@@ -1021,19 +1007,15 @@ RESULT eDVBChannel::getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, in
                return -1;
        }
        
-//     eDebug("STC: %08llx PTS: %08llx, diff %lld", now, pos, now - pos);
-               /* when we are less than 10 seconds before the start, return 0. */
-               /* (we're just waiting for the timespam to start) */
-       if ((now < pos) && ((pos - now) < 90000 * 10))
+       off_t off = 0; /* TODO: fixme */
+       r = m_tstools.fixupPTS(off, now);
+       if (r)
        {
-               pos = 0;
-               return 0;
+               eDebug("fixup PTS failed");
+               return -1;
        }
        
-       if (now < pos) /* wrap around */
-               pos = now + ((pts_t)1)<<33 - pos;
-       else
-               pos = now - pos;
+       pos = now;
        
        return 0;
 }