From fbf43d4d497be406a4d1e687e8cae05f54cf1dfc Mon Sep 17 00:00:00 2001 From: nafets227 Date: Sun, 9 Nov 2014 22:24:22 +0100 Subject: [PATCH] Simplified RTP timeout handling (Replay of Subversion #53) --- data.c | 38 ++++++++++++-------------------------- data.h | 11 ++++++----- tuner.c | 11 +++++++++-- tuner.h | 2 -- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/data.c b/data.c index abb21b9..221395c 100644 --- a/data.c +++ b/data.c @@ -40,10 +40,7 @@ cSatipTunerDataThread::cSatipTunerDataThread(cSatipDeviceIf &deviceP, cSatipTune packetBufferLenM(packetLenP), packetBufferM(NULL), rtpSocketM(NULL), - timeoutM(-1), - timeoutHandlerM(0), - timeoutFuncM(NULL), - timeoutParamM(NULL), + timeDataReceivedM(), sleepM(), mutexM() { @@ -78,23 +75,18 @@ void cSatipTunerDataThread::Start(cSatipSocket *rtpSocketP) cThread::Start(); } -void cSatipTunerDataThread::SetTimeout(int timeoutP, fCallback callbackP, void *paramP) +int cSatipTunerDataThread::LastReceivedMs() { - log2(logFunc, "(%d, ...)", timeoutP); - cMutexLock MutexLock(&mutexM); + int rc = timeDataReceivedM.Elapsed(); - if (timeoutP > 0) { - timeoutM = timeoutP; - timeoutFuncM = callbackP; - timeoutParamM = paramP; - timeoutHandlerM.Set(timeoutM); - } - else { - timeoutM = -1; - timeoutFuncM = NULL; - timeoutParamM = NULL; - timeoutHandlerM.Set(0); - } + log2(logFunc, "returning %d", rc); +} + +void cSatipTunerDataThread::ResetLastReceivedMs() +{ + log(logFunc); + + timeDataReceivedM.Set(); } void cSatipTunerDataThread::Cancel(int WaitSeconds) @@ -140,13 +132,7 @@ void cSatipTunerDataThread::Action(void) if (statisticsM) statisticsM->AddTunerStatistic(length); - timeoutHandlerM.Set(timeoutM); - } - - if (timeoutM > 0 && timeoutFuncM && timeoutHandlerM.TimedOut()) { - error("No Data received for %d ms [device %d], timeout handling started", timeoutM, deviceM->GetId()); - (*timeoutFuncM)(timeoutParamM); - timeoutHandlerM.Set(timeoutM); + timeDataReceivedM.Set(); } mutexM.Unlock(); diff --git a/data.h b/data.h index 816cb60..14261ea 100644 --- a/data.h +++ b/data.h @@ -29,7 +29,11 @@ public: cSatipTunerDataThread(cSatipDeviceIf &deviceP, cSatipTunerStatistics &statisticsP, unsigned int packetLenP); ~cSatipTunerDataThread(void); void Start(cSatipSocket *rtpSocketP); - void SetTimeout(int timeoutP, fCallback callbackP, void *parmP); + + + // returns number of milliseconds since last time we received Data + int LastReceivedMs(); + void ResetLastReceivedMs(); void Cancel(int WaitSeconds = 0); void Flush(); @@ -44,10 +48,7 @@ private: unsigned int packetBufferLenM; unsigned char *packetBufferM; cSatipSocket *rtpSocketM; - int timeoutM; - cTimeMs timeoutHandlerM; - fCallback timeoutFuncM; - void *timeoutParamM; + cTimeMs timeDataReceivedM; cCondWait sleepM; cMutex mutexM; }; diff --git a/tuner.c b/tuner.c index 71483da..14ee9b5 100644 --- a/tuner.c +++ b/tuner.c @@ -133,6 +133,15 @@ void cSatipTuner::Action(void) if (rtcpTimeout.TimedOut()) reconnectM = true; + int passedMs = dataThreadM.LastReceivedMs(); + if (passedMs >= eReConnectTimeoutMs) { + error("No Data received for %d ms [device %d], Reconnect initiated", + (int)passedMs, deviceM->GetId()); + dataThreadM.ResetLastReceivedMs(); + reconnectM = true; + } + + } sleepM.Wait(10); // to avoid busy loop and reduce cpu load } @@ -376,11 +385,9 @@ bool cSatipTuner::UpdatePids(bool forceP) *GeneratePidParameter(forceP)); // Disable RTP Timeout while sending PLAY Command - dataThreadM.SetTimeout(-1, &DataTimeoutCallback, this); if (RtspPlay(*uri)) { addPidsM.Clear(); delPidsM.Clear(); - dataThreadM.SetTimeout(eReConnectTimeoutMs, &DataTimeoutCallback, this); return true; } Disconnect(); diff --git a/tuner.h b/tuner.h index 2d39f53..1c4900e 100644 --- a/tuner.h +++ b/tuner.h @@ -57,8 +57,6 @@ private: eMinKeepAliveIntervalMs = 30000 // in milliseconds }; - static void DataTimeoutCallback(void *objP); - cSatipTunerDataThread dataThreadM; cCondWait sleepM; cSatipDeviceIf* deviceM;