From c401be22e1507e5eaef89dd4efc2924f5f901b79 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Tue, 6 Mar 2012 18:28:35 +0400 Subject: [PATCH] driver/rcinput.cpp: try to use monotonic time, ifdef old code with USE_GETTIMEOFDAY; dont set time in neutrino Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/361513c016a5f88bb81665db8407c2311aac3c33 Author: [CST] Focus Date: 2012-03-06 (Tue, 06 Mar 2012) ------------------ This commit was generated by Migit --- src/driver/rcinput.cpp | 91 +++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 28 deletions(-) diff --git a/src/driver/rcinput.cpp b/src/driver/rcinput.cpp index 82cec5d03..c064c5fd0 100644 --- a/src/driver/rcinput.cpp +++ b/src/driver/rcinput.cpp @@ -34,6 +34,7 @@ #endif #include +#include #include #include @@ -41,7 +42,6 @@ #include #include #include -//#define RCDEBUG #include #include #ifdef KEYBOARD_INSTEAD_OF_REMOTE_CONTROL @@ -61,6 +61,11 @@ #include #include +//#define RCDEBUG +//#define USE_GETTIMEOFDAY + +#define ENABLE_REPEAT_CHECK + //const char * const RC_EVENT_DEVICE[NUMBER_OF_EVENT_DEVICES] = {"/dev/input/nevis_ir", "/dev/input/event0"}; const char * const RC_EVENT_DEVICE[NUMBER_OF_EVENT_DEVICES] = {"/dev/input/nevis_ir"}; typedef struct input_event t_input_event; @@ -332,13 +337,15 @@ int CRCInput::messageLoop( bool anyKeyCancels, int timeout ) return res; } - int CRCInput::addTimer(uint64_t Interval, bool oneshot, bool correct_time ) { +#ifdef USE_GETTIMEOFDAY struct timeval tv; - gettimeofday( &tv, NULL ); uint64_t timeNow = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); +#else + uint64_t timeNow = time_monotonic_us(); +#endif timer _newtimer; if (!oneshot) @@ -365,6 +372,7 @@ int CRCInput::addTimer(uint64_t Interval, bool oneshot, bool correct_time ) return _newtimer.id; } +#ifdef USE_GETTIMEOFDAY int CRCInput::addTimer(struct timeval Timeout) { uint64_t timesout = (uint64_t) Timeout.tv_usec + (uint64_t)((uint64_t) Timeout.tv_sec * (uint64_t) 1000000); @@ -375,6 +383,7 @@ int CRCInput::addTimer(const time_t *Timeout) { return addTimer( (uint64_t)*Timeout* (uint64_t) 1000000, true, false ); } +#endif void CRCInput::killTimer(uint32_t &id) { @@ -394,13 +403,14 @@ void CRCInput::killTimer(uint32_t &id) int CRCInput::checkTimers() { - struct timeval tv; int _id = 0; - +#ifdef USE_GETTIMEOFDAY + struct timeval tv; gettimeofday( &tv, NULL ); uint64_t timeNow = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); - - +#else + uint64_t timeNow = time_monotonic_us(); +#endif std::vector::iterator e; for ( e= timers.begin(); e!= timers.end(); ++e ) if ( e->times_out< timeNow+ 2000 ) @@ -440,41 +450,46 @@ int CRCInput::checkTimers() int64_t CRCInput::calcTimeoutEnd(const int timeout_in_seconds) { +#ifdef USE_GETTIMEOFDAY struct timeval tv; - gettimeofday(&tv, NULL); - return (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec + (uint64_t)timeout_in_seconds) * (uint64_t) 1000000; +#else + return time_monotonic_us() + ((uint64_t)timeout_in_seconds * (uint64_t) 1000000); +#endif } int64_t CRCInput::calcTimeoutEnd_MS(const int timeout_in_milliseconds) { +#ifdef USE_GETTIMEOFDAY struct timeval tv; - gettimeofday(&tv, NULL); - uint64_t timeNow = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); - +#else + uint64_t timeNow = time_monotonic_us(); +#endif return ( timeNow + timeout_in_milliseconds * 1000 ); } - void CRCInput::getMsgAbsoluteTimeout(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint64_t *TimeoutEnd, bool bAllowRepeatLR) { +#ifdef USE_GETTIMEOFDAY struct timeval tv; - gettimeofday( &tv, NULL ); uint64_t timeNow = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); - +#else + uint64_t timeNow = time_monotonic_us(); +#endif uint64_t diff; if ( *TimeoutEnd < timeNow+ 100 ) diff = 100; // Minimum Differenz... else diff = ( *TimeoutEnd - timeNow ); + //printf("CRCInput::getMsgAbsoluteTimeout diff %llx TimeoutEnd %llx now %llx\n", diff, *TimeoutEnd, timeNow); getMsg_us( msg, data, diff, bAllowRepeatLR ); - +#ifdef USE_GETTIMEOFDAY if ( *msg == NeutrinoMessages::EVT_TIMESET ) { // recalculate timeout.... @@ -483,6 +498,7 @@ void CRCInput::getMsgAbsoluteTimeout(neutrino_msg_t * msg, neutrino_msg_data_t * //printf("[getMsgAbsoluteTimeout]: EVT_TIMESET - recalculate timeout\n%llx/%llx - %llx/%llx\n", timeNow, *(int64_t*) *data, *TimeoutEnd, ta ); } +#endif } void CRCInput::getMsg(neutrino_msg_t * msg, neutrino_msg_data_t * data, int Timeout, bool bAllowRepeatLR) @@ -495,16 +511,16 @@ void CRCInput::getMsg_ms(neutrino_msg_t * msg, neutrino_msg_data_t * data, int T getMsg_us(msg, data, (uint64_t) Timeout * 1000, bAllowRepeatLR); } -#define ENABLE_REPEAT_CHECK void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint64_t Timeout, bool bAllowRepeatLR) { static uint64_t last_keypress = 0ULL; - uint64_t getKeyBegin; + //uint64_t getKeyBegin; //static __u16 rc_last_key = KEY_MAX; static __u16 rc_last_repeat_key = KEY_MAX; - struct timeval tv, tvselect; + struct timeval tv; + struct timeval tvselect; uint64_t InitialTimeout = Timeout; int64_t targetTimeout; @@ -515,15 +531,22 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 *data = 0; // wiederholung reinmachen - dass wirklich die ganze zeit bis timeout gewartet wird! +#ifdef USE_GETTIMEOFDAY gettimeofday( &tv, NULL ); - getKeyBegin = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); - + uint64_t getKeyBegin = (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); +#else + uint64_t getKeyBegin = time_monotonic_us(); +#endif while(1) { timer_id = 0; if ( timers.size()> 0 ) { +#ifdef USE_GETTIMEOFDAY gettimeofday( &tv, NULL ); uint64_t t_n= (uint64_t) tv.tv_usec + (uint64_t)((uint64_t) tv.tv_sec * (uint64_t) 1000000); +#else + uint64_t t_n = time_monotonic_us(); +#endif if ( timers[0].times_out< t_n ) { timer_id = checkTimers(); @@ -840,6 +863,7 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 { case CSectionsdClient::EVT_TIMESET: { +#if 0 struct timeval ltv; gettimeofday(<v, NULL); int64_t timeOld = ltv.tv_usec + ltv.tv_sec * (int64_t)1000000; @@ -847,7 +871,8 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 if (dvbtime) { printf("[neutrino] timeset event. "); time_t difftime = dvbtime - ltv.tv_sec; - if (abs(difftime) > 120) { + if (abs(difftime) > 120) + { printf("difference is %ld s, stepping...\n", difftime); if (stime(&dvbtime)) perror("stime"); @@ -868,14 +893,18 @@ void CRCInput::getMsg_us(neutrino_msg_t * msg, neutrino_msg_data_t * data, uint6 delete[] p;//new [] delete [] p = new unsigned char[sizeof(int64_t)]; *(int64_t*) p = timeNew - timeOld; - +#endif + printf("[neutrino] CSectionsdClient::EVT_TIMESET: timediff %lld\n", *(int64_t*) p); + /* FIXME what this code really do ? */ if ((int64_t)last_keypress > *(int64_t*)p) - last_keypress += *(int64_t *)p; + last_keypress += *(int64_t *)p; +#ifdef USE_GETTIMEOFDAY // Timer anpassen for(std::vector::iterator e = timers.begin(); e != timers.end(); ++e) if (e->correct_time) e->times_out+= *(int64_t*) p; +#endif *msg = NeutrinoMessages::EVT_TIMESET; *data = (neutrino_msg_data_t) p; dont_delete_p = true; @@ -887,16 +916,18 @@ printf("[neutrino] CSectionsdClient::EVT_GOT_CN_EPG\n"); *data = (neutrino_msg_data_t) p; dont_delete_p = true; break; + case CSectionsdClient::EVT_WRITE_SI_FINISHED: + *msg = NeutrinoMessages::EVT_SI_FINISHED; + *data = 0; + break; +#if 0 case CSectionsdClient::EVT_SERVICES_UPDATE: *msg = NeutrinoMessages::EVT_SERVICES_UPD; *data = 0; break; case CSectionsdClient::EVT_BOUQUETS_UPDATE: break; - case CSectionsdClient::EVT_WRITE_SI_FINISHED: - *msg = NeutrinoMessages::EVT_SI_FINISHED; - *data = 0; - break; +#endif default: printf("[neutrino] event INITID_SECTIONSD - unknown eventID 0x%x\n", emsg.eventID ); } @@ -1260,8 +1291,12 @@ printf("[neutrino] CSectionsdClient::EVT_GOT_CN_EPG\n"); else { //timeout neu kalkulieren +#ifdef USE_GETTIMEOFDAY gettimeofday( &tv, NULL ); int64_t getKeyNow = (int64_t) tv.tv_usec + (int64_t)((int64_t) tv.tv_sec * (int64_t) 1000000); +#else + int64_t getKeyNow = time_monotonic_us(); +#endif int64_t diff = (getKeyNow - getKeyBegin); if( Timeout <= (uint64_t) diff ) {