1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

Added RTP packet error detection.

This commit is contained in:
Rolf Ahrenberg 2014-04-05 19:11:30 +03:00
parent dc9f9f2b86
commit 53c2026a60
2 changed files with 30 additions and 1 deletions

View File

@ -21,6 +21,9 @@
cIptvSocket::cIptvSocket() cIptvSocket::cIptvSocket()
: socketPortM(0), : socketPortM(0),
socketDescM(-1), socketDescM(-1),
lastErrorReportM(0),
packetErrorsM(0),
sequenceNumberM(-1),
isActiveM(false) isActiveM(false)
{ {
debug("cIptvSocket::%s()", __FUNCTION__); debug("cIptvSocket::%s()", __FUNCTION__);
@ -87,6 +90,11 @@ void cIptvSocket::CloseSocket(void)
socketPortM = 0; socketPortM = 0;
memset(&sockAddrM, 0, sizeof(sockAddrM)); memset(&sockAddrM, 0, sizeof(sockAddrM));
} }
if (packetErrorsM) {
info("detected %d RTP packet errors", packetErrorsM);
packetErrorsM = 0;
lastErrorReportM = time(NULL);
}
} }
bool cIptvSocket::CheckAddress(const char *addrP, in_addr_t *inAddrP) bool cIptvSocket::CheckAddress(const char *addrP, in_addr_t *inAddrP)
@ -274,6 +282,21 @@ int cIptvUdpSocket::Read(unsigned char *bufferAddrP, unsigned int bufferLenP)
unsigned int cc = bufferAddrP[0] & 0x0F; unsigned int cc = bufferAddrP[0] & 0x0F;
// Payload type: MPEG2 TS = 33 // Payload type: MPEG2 TS = 33
//unsigned int pt = bufferAddrP[1] & 0x7F; //unsigned int pt = bufferAddrP[1] & 0x7F;
// Sequence number
int seq = ((bufferAddrP[2] & 0xFF) << 8) | (bufferAddrP[3] & 0xFF);
if ((((sequenceNumberM + 1) % 0xFFFF) == 0) && (seq == 0xFFFF))
sequenceNumberM = -1;
else if ((sequenceNumberM >= 0) && (((sequenceNumberM + 1) % 0xFFFF) != seq)) {
packetErrorsM++;
if (time(NULL) - lastErrorReportM > eReportIntervalS) {
info("detected %d RTP packet errors", packetErrorsM);
packetErrorsM = 0;
lastErrorReportM = time(NULL);
}
sequenceNumberM = seq;
}
else
sequenceNumberM = seq;
// Header lenght // Header lenght
unsigned int headerlen = (3 + cc) * (unsigned int)sizeof(uint32_t); unsigned int headerlen = (3 + cc) * (unsigned int)sizeof(uint32_t);
// Check if extension // Check if extension
@ -401,7 +424,7 @@ bool cIptvTcpSocket::Write(const char *bufferAddrP, unsigned int bufferLenP)
//debug("cIptvTcpSocket::%s()", __FUNCTION__); //debug("cIptvTcpSocket::%s()", __FUNCTION__);
// Error out if socket not initialized // Error out if socket not initialized
if (socketDescM <= 0) { if (socketDescM <= 0) {
error("Invalid socket in cIptvTcpSocket::%s()", __FUNCTION__); error("cIptvTcpSocket::%s(): Invalid socket", __FUNCTION__);
return false; return false;
} }
ERROR_IF_RET(send(socketDescM, bufferAddrP, bufferLenP, 0) < 0, "send()", return false); ERROR_IF_RET(send(socketDescM, bufferAddrP, bufferLenP, 0) < 0, "send()", return false);

View File

@ -18,8 +18,14 @@ private:
int socketPortM; int socketPortM;
protected: protected:
enum {
eReportIntervalS = 300 // in seconds
};
int socketDescM; int socketDescM;
struct sockaddr_in sockAddrM; struct sockaddr_in sockAddrM;
time_t lastErrorReportM;
int packetErrorsM;
int sequenceNumberM;
bool isActiveM; bool isActiveM;
protected: protected: