Fixed tuner reconnection issues.

This commit is contained in:
Rolf Ahrenberg 2014-11-16 15:38:23 +02:00
parent 02bf42b006
commit 5c051d919b
8 changed files with 39 additions and 21 deletions

2
rtcp.c
View File

@ -82,7 +82,7 @@ void cSatipRtcp::Action(int fdP)
if (length > 0) { if (length > 0) {
int offset = GetApplicationOffset(&length); int offset = GetApplicationOffset(&length);
if (offset >= 0) if (offset >= 0)
tunerM->ParseReceptionParameters(bufferM + offset, length); tunerM->ProcessApplicationData(bufferM + offset, length);
} }
} }
} }

4
rtcp.h
View File

@ -8,13 +8,11 @@
#ifndef __SATIP_RTCP_H_ #ifndef __SATIP_RTCP_H_
#define __SATIP_RTCP_H_ #define __SATIP_RTCP_H_
#include "common.h"
#include "socket.h" #include "socket.h"
#include "tunerif.h" #include "tunerif.h"
#include "pollerif.h" #include "pollerif.h"
class cSatipRtcp : public cSatipSocket, public cSatipPollerIf class cSatipRtcp : public cSatipSocket, public cSatipPollerIf {
{
private: private:
cSatipTunerIf *tunerM; cSatipTunerIf *tunerM;
unsigned int bufferLenM; unsigned int bufferLenM;

8
rtp.c
View File

@ -8,8 +8,8 @@
#include "common.h" #include "common.h"
#include "rtp.h" #include "rtp.h"
cSatipRtp::cSatipRtp(cSatipDeviceIf &deviceP, unsigned int bufferLenP) cSatipRtp::cSatipRtp(cSatipTunerIf &tunerP, unsigned int bufferLenP)
: deviceM(&deviceP), : tunerM(&tunerP),
bufferLenM(bufferLenP), bufferLenM(bufferLenP),
bufferM(MALLOC(unsigned char, bufferLenM)), bufferM(MALLOC(unsigned char, bufferLenM)),
lastErrorReportM(0), lastErrorReportM(0),
@ -104,11 +104,11 @@ void cSatipRtp::Action(int fdP)
{ {
//debug("cSatipRtp::%s(%d)", __FUNCTION__, fdP); //debug("cSatipRtp::%s(%d)", __FUNCTION__, fdP);
if (bufferM) { if (bufferM) {
int length = Read(bufferM, min(deviceM->CheckData(), bufferLenM)); int length = Read(bufferM, min(tunerM->GetVideoDataSize(), bufferLenM));
if (length > 0) { if (length > 0) {
int headerlen = GetHeaderLenght(length); int headerlen = GetHeaderLenght(length);
if ((headerlen >= 0) && (headerlen < length)) if ((headerlen >= 0) && (headerlen < length))
deviceM->WriteData(bufferM + headerlen, length - headerlen); tunerM->ProcessVideoData(bufferM + headerlen, length - headerlen);
} }
} }
} }

7
rtp.h
View File

@ -9,16 +9,15 @@
#define __SATIP_RTP_H_ #define __SATIP_RTP_H_
#include "socket.h" #include "socket.h"
#include "deviceif.h" #include "tunerif.h"
#include "pollerif.h" #include "pollerif.h"
#include "statistics.h"
class cSatipRtp : public cSatipSocket, public cSatipPollerIf { class cSatipRtp : public cSatipSocket, public cSatipPollerIf {
private: private:
enum { enum {
eReportIntervalS = 300 // in seconds eReportIntervalS = 300 // in seconds
}; };
cSatipDeviceIf *deviceM; cSatipTunerIf *tunerM;
unsigned int bufferLenM; unsigned int bufferLenM;
unsigned char *bufferM; unsigned char *bufferM;
time_t lastErrorReportM; time_t lastErrorReportM;
@ -31,7 +30,7 @@ protected:
virtual void Action(int fdP); virtual void Action(int fdP);
public: public:
cSatipRtp(cSatipDeviceIf &deviceP, unsigned int bufferLenP); cSatipRtp(cSatipTunerIf &tunerP, unsigned int bufferLenP);
virtual ~cSatipRtp(); virtual ~cSatipRtp();
virtual void Close(void); virtual void Close(void);
}; };

2
rtsp.c
View File

@ -89,7 +89,7 @@ size_t cSatipRtsp::WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void *
//debug("cSatipRtsp::%s(%zu)", __FUNCTION__, len); //debug("cSatipRtsp::%s(%zu)", __FUNCTION__, len);
if (obj && obj->tunerM && (len > 0)) if (obj && obj->tunerM && (len > 0))
obj->tunerM->ParseReceptionParameters((u_char*)ptrP, len); obj->tunerM->ProcessApplicationData((u_char*)ptrP, len);
return len; return len;
} }

28
tuner.c
View File

@ -17,13 +17,14 @@ cSatipTuner::cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP)
deviceM(&deviceP), deviceM(&deviceP),
deviceIdM(deviceP.GetId()), deviceIdM(deviceP.GetId()),
rtspM(new cSatipRtsp(*this)), rtspM(new cSatipRtsp(*this)),
rtpM(new cSatipRtp(deviceP, packetLenP)), rtpM(new cSatipRtp(*this, packetLenP)),
rtcpM(new cSatipRtcp(*this, 1500)), rtcpM(new cSatipRtcp(*this, 1500)),
streamAddrM(""), streamAddrM(""),
streamParamM(""), streamParamM(""),
currentServerM(NULL), currentServerM(NULL),
nextServerM(NULL), nextServerM(NULL),
mutexM(), mutexM(),
reConnectM(),
keepAliveM(), keepAliveM(),
statusUpdateM(), statusUpdateM(),
pidUpdateCacheM(), pidUpdateCacheM(),
@ -86,7 +87,7 @@ cSatipTuner::~cSatipTuner()
void cSatipTuner::Action(void) void cSatipTuner::Action(void)
{ {
debug("cSatipTuner::%s(): entering [device %d]", __FUNCTION__, deviceIdM); debug("cSatipTuner::%s(): entering [device %d]", __FUNCTION__, deviceIdM);
cTimeMs reconnection(eConnectTimeoutMs); reConnectM.Set(eConnectTimeoutMs);
// Do the thread loop // Do the thread loop
while (Running()) { while (Running()) {
switch (tunerStatusM) { switch (tunerStatusM) {
@ -100,7 +101,7 @@ void cSatipTuner::Action(void)
break; break;
case tsSet: case tsSet:
//debug("cSatipTuner::%s(): tsSet [device %d]", __FUNCTION__, deviceIdM); //debug("cSatipTuner::%s(): tsSet [device %d]", __FUNCTION__, deviceIdM);
reconnection.Set(eConnectTimeoutMs); reConnectM.Set(eConnectTimeoutMs);
Disconnect(); Disconnect();
if (Connect()) { if (Connect()) {
tunerStatusM = tsTuned; tunerStatusM = tsTuned;
@ -113,7 +114,7 @@ void cSatipTuner::Action(void)
break; break;
case tsTuned: case tsTuned:
//debug("cSatipTuner::%s(): tsTuned [device %d]", __FUNCTION__, deviceIdM); //debug("cSatipTuner::%s(): tsTuned [device %d]", __FUNCTION__, deviceIdM);
reconnection.Set(eConnectTimeoutMs); reConnectM.Set(eConnectTimeoutMs);
// Read reception statistics via DESCRIBE and RTCP // Read reception statistics via DESCRIBE and RTCP
if (hasLockM || ReadReceptionStatus()) { if (hasLockM || ReadReceptionStatus()) {
// Quirk for devices without valid reception data // Quirk for devices without valid reception data
@ -139,7 +140,7 @@ void cSatipTuner::Action(void)
tunerStatusM = tsSet; tunerStatusM = tsSet;
break; break;
} }
if (reconnection.TimedOut()) { if (reConnectM.TimedOut()) {
error("Connection timeout - re-tuning [device %d]", deviceIdM); error("Connection timeout - re-tuning [device %d]", deviceIdM);
tunerStatusM = tsSet; tunerStatusM = tsSet;
break; break;
@ -232,7 +233,22 @@ bool cSatipTuner::Disconnect(void)
return true; 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); //debug("cSatipTuner::%s(%d) [device %d]", __FUNCTION__, lengthP, deviceIdM);
// DVB-S2: // DVB-S2:

View File

@ -70,6 +70,7 @@ private:
cSatipServer *currentServerM; cSatipServer *currentServerM;
cSatipServer *nextServerM; cSatipServer *nextServerM;
cMutex mutexM; cMutex mutexM;
cTimeMs reConnectM;
cTimeMs keepAliveM; cTimeMs keepAliveM;
cTimeMs statusUpdateM; cTimeMs statusUpdateM;
cTimeMs pidUpdateCacheM; cTimeMs pidUpdateCacheM;
@ -110,7 +111,9 @@ public:
// for internal tuner interface // for internal tuner interface
public: 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 SetStreamId(int streamIdP);
virtual void SetSessionTimeout(const char *sessionP, int timeoutP); virtual void SetSessionTimeout(const char *sessionP, int timeoutP);
virtual int GetId(void); virtual int GetId(void);

View File

@ -12,7 +12,9 @@ class cSatipTunerIf {
public: public:
cSatipTunerIf() {} cSatipTunerIf() {}
virtual ~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 SetStreamId(int streamIdP) = 0;
virtual void SetSessionTimeout(const char *sessionP, int timeoutP) = 0; virtual void SetSessionTimeout(const char *sessionP, int timeoutP) = 0;
virtual int GetId(void) = 0; virtual int GetId(void) = 0;