speedup resolveFilename a bit
[enigma2.git] / lib / dvb / dvbtime.cpp
index 6c2df6c265c0d5ef98d8359008de102b63cb9b20..4c18faa6329975180c298fc7044caa2fcd02bc2a 100644 (file)
@@ -148,6 +148,11 @@ eDVBLocalTimeHandler::~eDVBLocalTimeHandler()
        instance=0;
        for (std::map<iDVBChannel*, channel_data>::iterator it=m_knownChannels.begin(); it != m_knownChannels.end(); ++it)
                delete it->second.tdt;
+       if (ready())
+       {
+               eDebug("set RTC to previous valid time");
+               setRTC(nowTime());
+       }
 }
 
 void eDVBLocalTimeHandler::readTimeOffsetData( const char* filename )
@@ -216,14 +221,13 @@ void eDVBLocalTimeHandler::updateTime( time_t tp_time, eDVBChannel *chan, int up
                                        now.tm_sec);
                                m_time_difference = rtc_time - linuxTime;
                                eDebug("[eDVBLocalTimerHandler] RTC to Receiver time difference is %ld seconds", nowTime - rtc_time );
-                               if ( abs(m_time_difference) > 59 )
+                               if ( m_time_difference )
                                {
                                        eDebug("[eDVBLocalTimerHandler] set Linux Time to RTC Time");
                                        timeval tnow;
                                        gettimeofday(&tnow,0);
                                        tnow.tv_sec=rtc_time;
                                        settimeofday(&tnow,0);
-                                       eMainloop::addTimeOffset(m_time_difference);
                                        m_time_difference=0;
                                }
                                else if ( !m_time_difference )
@@ -275,8 +279,7 @@ void eDVBLocalTimeHandler::updateTime( time_t tp_time, eDVBChannel *chan, int up
                                        eDebug("[eDVBLocalTimerHandler] use stored correction(<5 min)");
                                        new_diff = ddiff;
                                }
-                               else if ( /*eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7020 &&  TODO !!!*/
-                                               getRTC() )
+                               else if ( getRTC() )
                                {
                                        time_t rtc=getRTC();
                                        m_timeOffsetMap[chan->getChannelID()] = rtc-tp_time;
@@ -326,6 +329,26 @@ void eDVBLocalTimeHandler::updateTime( time_t tp_time, eDVBChannel *chan, int up
                        return;
                }
 
+               if ( !update_count )
+               {
+                       // set rtc to calced transponder time when the first tdt is received on this
+                       // transponder
+                       setRTC(t);
+                       eDebug("[eDVBLocalTimerHandler] update RTC");
+               }
+               else if (getRTC())
+               {
+                       if (abs(getRTC() - t) > 60)
+                       {
+                               eDebug("[eDVBLocalTimerHandler] difference between new linux time and RTC time is > 60 sec... transponder time looks not ok... use rtc time");
+                               t = getRTC();
+                       }
+                       else
+                               eDebug("[eDVBLocalTimerHandler] difference between linux time and RTC time is < 60 sec... so the transponder time looks ok");
+               }
+               else
+                       eDebug("[eDVBLocalTimerHandler] no RTC available :(");
+
                tm now;
                localtime_r(&t, &now);
                eDebug("[eDVBLocalTimerHandler] time update to %02d:%02d:%02d",
@@ -336,25 +359,13 @@ void eDVBLocalTimeHandler::updateTime( time_t tp_time, eDVBChannel *chan, int up
                m_time_difference = t - linuxTime;   // calc our new linux_time -> enigma_time correction
                eDebug("[eDVBLocalTimerHandler] m_time_difference is %d", m_time_difference );
 
-//             if ( eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7020 )  TODO !!
-               if ( !update_count )
-               {
-                       // set rtc to calced transponder time when the first tdt is received on this
-                       // transponder
-                       setRTC(t);
-                       eDebug("[eDVBLocalTimerHandler] update RTC");
-               }
-               else
-                       eDebug("[eDVBLocalTimerHandler] don't update RTC");
-
-               if ( abs(m_time_difference) > 59 )
+               if ( m_time_difference )
                {
                        eDebug("[eDVBLocalTimerHandler] set Linux Time");
                        timeval tnow;
                        gettimeofday(&tnow,0);
                        tnow.tv_sec=t;
                        settimeofday(&tnow,0);
-                       eMainloop::addTimeOffset(m_time_difference);
                        m_time_difference=0;
                }