From 5c051d919b1a9e4a4616c773b9c49867d134be70 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Sun, 16 Nov 2014 15:38:23 +0200 Subject: [PATCH] Fixed tuner reconnection issues. --- rtcp.c | 2 +- rtcp.h | 4 +--- rtp.c | 8 ++++---- rtp.h | 7 +++---- rtsp.c | 2 +- tuner.c | 28 ++++++++++++++++++++++------ tuner.h | 5 ++++- tunerif.h | 4 +++- 8 files changed, 39 insertions(+), 21 deletions(-) diff --git a/rtcp.c b/rtcp.c index 2efa4e6..2d9a785 100644 --- a/rtcp.c +++ b/rtcp.c @@ -82,7 +82,7 @@ void cSatipRtcp::Action(int fdP) if (length > 0) { int offset = GetApplicationOffset(&length); if (offset >= 0) - tunerM->ParseReceptionParameters(bufferM + offset, length); + tunerM->ProcessApplicationData(bufferM + offset, length); } } } diff --git a/rtcp.h b/rtcp.h index 1372244..0f095b3 100644 --- a/rtcp.h +++ b/rtcp.h @@ -8,13 +8,11 @@ #ifndef __SATIP_RTCP_H_ #define __SATIP_RTCP_H_ -#include "common.h" #include "socket.h" #include "tunerif.h" #include "pollerif.h" -class cSatipRtcp : public cSatipSocket, public cSatipPollerIf -{ +class cSatipRtcp : public cSatipSocket, public cSatipPollerIf { private: cSatipTunerIf *tunerM; unsigned int bufferLenM; diff --git a/rtp.c b/rtp.c index 44c9ad9..ad9c243 100644 --- a/rtp.c +++ b/rtp.c @@ -8,8 +8,8 @@ #include "common.h" #include "rtp.h" -cSatipRtp::cSatipRtp(cSatipDeviceIf &deviceP, unsigned int bufferLenP) -: deviceM(&deviceP), +cSatipRtp::cSatipRtp(cSatipTunerIf &tunerP, unsigned int bufferLenP) +: tunerM(&tunerP), bufferLenM(bufferLenP), bufferM(MALLOC(unsigned char, bufferLenM)), lastErrorReportM(0), @@ -104,11 +104,11 @@ void cSatipRtp::Action(int fdP) { //debug("cSatipRtp::%s(%d)", __FUNCTION__, fdP); if (bufferM) { - int length = Read(bufferM, min(deviceM->CheckData(), bufferLenM)); + int length = Read(bufferM, min(tunerM->GetVideoDataSize(), bufferLenM)); if (length > 0) { int headerlen = GetHeaderLenght(length); if ((headerlen >= 0) && (headerlen < length)) - deviceM->WriteData(bufferM + headerlen, length - headerlen); + tunerM->ProcessVideoData(bufferM + headerlen, length - headerlen); } } } diff --git a/rtp.h b/rtp.h index b15c0a9..94b5541 100644 --- a/rtp.h +++ b/rtp.h @@ -9,16 +9,15 @@ #define __SATIP_RTP_H_ #include "socket.h" -#include "deviceif.h" +#include "tunerif.h" #include "pollerif.h" -#include "statistics.h" class cSatipRtp : public cSatipSocket, public cSatipPollerIf { private: enum { eReportIntervalS = 300 // in seconds }; - cSatipDeviceIf *deviceM; + cSatipTunerIf *tunerM; unsigned int bufferLenM; unsigned char *bufferM; time_t lastErrorReportM; @@ -31,7 +30,7 @@ protected: virtual void Action(int fdP); public: - cSatipRtp(cSatipDeviceIf &deviceP, unsigned int bufferLenP); + cSatipRtp(cSatipTunerIf &tunerP, unsigned int bufferLenP); virtual ~cSatipRtp(); virtual void Close(void); }; diff --git a/rtsp.c b/rtsp.c index cbcef6c..73390af 100644 --- a/rtsp.c +++ b/rtsp.c @@ -89,7 +89,7 @@ size_t cSatipRtsp::WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void * //debug("cSatipRtsp::%s(%zu)", __FUNCTION__, len); if (obj && obj->tunerM && (len > 0)) - obj->tunerM->ParseReceptionParameters((u_char*)ptrP, len); + obj->tunerM->ProcessApplicationData((u_char*)ptrP, len); return len; } diff --git a/tuner.c b/tuner.c index 67719d8..c9c92ce 100644 --- a/tuner.c +++ b/tuner.c @@ -17,13 +17,14 @@ cSatipTuner::cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP) deviceM(&deviceP), deviceIdM(deviceP.GetId()), rtspM(new cSatipRtsp(*this)), - rtpM(new cSatipRtp(deviceP, packetLenP)), + rtpM(new cSatipRtp(*this, packetLenP)), rtcpM(new cSatipRtcp(*this, 1500)), streamAddrM(""), streamParamM(""), currentServerM(NULL), nextServerM(NULL), mutexM(), + reConnectM(), keepAliveM(), statusUpdateM(), pidUpdateCacheM(), @@ -86,7 +87,7 @@ cSatipTuner::~cSatipTuner() void cSatipTuner::Action(void) { debug("cSatipTuner::%s(): entering [device %d]", __FUNCTION__, deviceIdM); - cTimeMs reconnection(eConnectTimeoutMs); + reConnectM.Set(eConnectTimeoutMs); // Do the thread loop while (Running()) { switch (tunerStatusM) { @@ -100,7 +101,7 @@ void cSatipTuner::Action(void) break; case tsSet: //debug("cSatipTuner::%s(): tsSet [device %d]", __FUNCTION__, deviceIdM); - reconnection.Set(eConnectTimeoutMs); + reConnectM.Set(eConnectTimeoutMs); Disconnect(); if (Connect()) { tunerStatusM = tsTuned; @@ -113,7 +114,7 @@ void cSatipTuner::Action(void) break; case tsTuned: //debug("cSatipTuner::%s(): tsTuned [device %d]", __FUNCTION__, deviceIdM); - reconnection.Set(eConnectTimeoutMs); + reConnectM.Set(eConnectTimeoutMs); // Read reception statistics via DESCRIBE and RTCP if (hasLockM || ReadReceptionStatus()) { // Quirk for devices without valid reception data @@ -139,7 +140,7 @@ void cSatipTuner::Action(void) tunerStatusM = tsSet; break; } - if (reconnection.TimedOut()) { + if (reConnectM.TimedOut()) { error("Connection timeout - re-tuning [device %d]", deviceIdM); tunerStatusM = tsSet; break; @@ -232,7 +233,22 @@ bool cSatipTuner::Disconnect(void) return true; } -void cSatipTuner::ParseReceptionParameters(u_char *bufferP, int lengthP) +unsigned int cSatipTuner::GetVideoDataSize(void) +{ + //debug("cSatipTuner::%s() [device %d]", __FUNCTION__, deviceIdM); + return deviceM->CheckData(); +} + +void cSatipTuner::ProcessVideoData(u_char *bufferP, int lengthP) +{ + //debug("cSatipTuner::%s(%d) [device %d]", __FUNCTION__, lengthP, deviceIdM); + if (lengthP > 0) + deviceM->WriteData(bufferP, lengthP); + cMutexLock MutexLock(&mutexM); + reConnectM.Set(eConnectTimeoutMs); +} + +void cSatipTuner::ProcessApplicationData(u_char *bufferP, int lengthP) { //debug("cSatipTuner::%s(%d) [device %d]", __FUNCTION__, lengthP, deviceIdM); // DVB-S2: diff --git a/tuner.h b/tuner.h index f4c391a..57ad887 100644 --- a/tuner.h +++ b/tuner.h @@ -70,6 +70,7 @@ private: cSatipServer *currentServerM; cSatipServer *nextServerM; cMutex mutexM; + cTimeMs reConnectM; cTimeMs keepAliveM; cTimeMs statusUpdateM; cTimeMs pidUpdateCacheM; @@ -110,7 +111,9 @@ public: // for internal tuner interface public: - virtual void ParseReceptionParameters(u_char *bufferP, int lengthP); + virtual unsigned int GetVideoDataSize(void); + virtual void ProcessVideoData(u_char *bufferP, int lengthP); + virtual void ProcessApplicationData(u_char *bufferP, int lengthP); virtual void SetStreamId(int streamIdP); virtual void SetSessionTimeout(const char *sessionP, int timeoutP); virtual int GetId(void); diff --git a/tunerif.h b/tunerif.h index 6a716fb..512856d 100644 --- a/tunerif.h +++ b/tunerif.h @@ -12,7 +12,9 @@ class cSatipTunerIf { public: cSatipTunerIf() {} virtual ~cSatipTunerIf() {} - virtual void ParseReceptionParameters(u_char *bufferP, int lenghtP) = 0; + virtual unsigned int GetVideoDataSize(void) = 0; + virtual void ProcessVideoData(u_char *bufferP, int lenghtP) = 0; + virtual void ProcessApplicationData(u_char *bufferP, int lenghtP) = 0; virtual void SetStreamId(int streamIdP) = 0; virtual void SetSessionTimeout(const char *sessionP, int timeoutP) = 0; virtual int GetId(void) = 0;