From bf908b613a4d4d3b1d4bf2afd7c34db39d2c063f Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 12 Sep 2010 14:42:40 +0000 Subject: [PATCH] neutrino: port "do not step time for small differences" from tuxbox When receiving new system time data from the DVB stream, and the difference to the current time is less than 120 seconds, do not step the time but call adjtime(3) instead to do a continuous time correction. git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@762 e54a6e83-5905-42d5-8d5c-058d10e6a962 Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/82fd0787ee39bb01609ed12554fb9f12ec98710f Author: Stefan Seyfried Date: 2010-09-12 (Sun, 12 Sep 2010) ------------------ This commit was generated by Migit --- src/driver/rcinput.cpp | 67 +++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/src/driver/rcinput.cpp b/src/driver/rcinput.cpp index 42ffec941..a267662ef 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -827,35 +827,48 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 switch(emsg.eventID) { case CSectionsdClient::EVT_TIMESET: - { - struct timeval ltv; - gettimeofday( <v, NULL ); - int64_t timeOld = (int64_t) ltv.tv_usec + (int64_t)((int64_t) ltv.tv_sec * (int64_t) 1000000); - - //printf("[neutrino] event TIMESET from SECTIONSD %x %x\n", emsg.eventID, *(unsigned*) p); - //g_Sectionsd->registerEvent(CSectionsdClient::EVT_TIMESET, 222, NEUTRINO_UDS_NAME); - stime((time_t*) p); - - gettimeofday( <v, NULL ); - int64_t timeNew = (int64_t) ltv.tv_usec + (int64_t)((int64_t) ltv.tv_sec * (int64_t) 1000000); - - delete[] p;//new [] delete [] - p= new unsigned char[ sizeof(int64_t) ]; - *(int64_t*) p = timeNew - timeOld; - - if ((int64_t)last_keypress > *(int64_t*)p) - last_keypress += *(int64_t *)p; - - // Timer anpassen - for(std::vector::iterator e = timers.begin(); e != timers.end(); ++e) - if (e->correct_time) - e->times_out+= *(int64_t*) p; - - *msg = NeutrinoMessages::EVT_TIMESET; - *data = (neutrino_msg_data_t) p; - dont_delete_p = true; + { + struct timeval ltv; + gettimeofday(<v, NULL); + int64_t timeOld = ltv.tv_usec + ltv.tv_sec * (int64_t)1000000; + time_t dvbtime = *((time_t*)p); + if (dvbtime) { + printf("[neutrino] timeset event. "); + time_t difftime = dvbtime - ltv.tv_sec; + if (abs(difftime) > 120) { + printf("difference is %ld s, stepping...\n", difftime); + if (stime(&dvbtime)) + perror("stime"); + } else if (difftime != 0) { + struct timeval oldd; + ltv.tv_sec = difftime; + ltv.tv_usec = 0; + if (adjtime(<v, &oldd)) + perror("adjtime"); + int64_t t = oldd.tv_sec * 1000000LL + oldd.tv_usec; + printf("difference is %ld s, using adjtime(). oldd: %lld us\n", difftime, t); + } else + printf("difference is 0 s, nothing to do...\n"); } + gettimeofday( <v, NULL ); + int64_t timeNew = ltv.tv_usec + ltv.tv_sec * (int64_t)1000000; + + delete[] p;//new [] delete [] + p = new unsigned char[sizeof(int64_t)]; + *(int64_t*) p = timeNew - timeOld; + + if ((int64_t)last_keypress > *(int64_t*)p) + last_keypress += *(int64_t *)p; + + // Timer anpassen + for(std::vector::iterator e = timers.begin(); e != timers.end(); ++e) + if (e->correct_time) + e->times_out+= *(int64_t*) p; + *msg = NeutrinoMessages::EVT_TIMESET; + *data = (neutrino_msg_data_t) p; + dont_delete_p = true; break; + } case CSectionsdClient::EVT_GOT_CN_EPG: printf("[neutrino] CSectionsdClient::EVT_GOT_CN_EPG\n"); *msg = NeutrinoMessages::EVT_CURRENTNEXT_EPG;