mirror of
https://github.com/rofafor/vdr-plugin-satip.git
synced 2023-10-10 13:37:42 +02:00
Tuner Bugfix, Blocking socket Preparation
(Replay of Subversion #54 and #55)
This commit is contained in:
parent
fbf43d4d49
commit
c2ef6d593e
3
config.c
3
config.c
@ -13,7 +13,8 @@ cSatipConfig SatipConfig;
|
|||||||
cSatipConfig::cSatipConfig(void)
|
cSatipConfig::cSatipConfig(void)
|
||||||
: operatingModeM(eOperatingModeLow),
|
: operatingModeM(eOperatingModeLow),
|
||||||
eitScanM(1),
|
eitScanM(1),
|
||||||
useBytesM(1)
|
useBytesM(1),
|
||||||
|
usePollingM(true)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < ARRAY_SIZE(disabledSourcesM); ++i)
|
for (unsigned int i = 0; i < ARRAY_SIZE(disabledSourcesM); ++i)
|
||||||
disabledSourcesM[i] = cSource::stNone;
|
disabledSourcesM[i] = cSource::stNone;
|
||||||
|
2
config.h
2
config.h
@ -20,6 +20,7 @@ private:
|
|||||||
int disabledSourcesM[MAX_DISABLED_SOURCES_COUNT];
|
int disabledSourcesM[MAX_DISABLED_SOURCES_COUNT];
|
||||||
int disabledFiltersM[SECTION_FILTER_TABLE_SIZE];
|
int disabledFiltersM[SECTION_FILTER_TABLE_SIZE];
|
||||||
char configDirectoryM[PATH_MAX];
|
char configDirectoryM[PATH_MAX];
|
||||||
|
bool usePollingM;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum {
|
enum {
|
||||||
@ -50,6 +51,7 @@ public:
|
|||||||
void SetConfigDirectory(const char *directoryP);
|
void SetConfigDirectory(const char *directoryP);
|
||||||
void SetDisabledSources(unsigned int indexP, int sourceP);
|
void SetDisabledSources(unsigned int indexP, int sourceP);
|
||||||
void SetDisabledFilters(unsigned int indexP, int numberP);
|
void SetDisabledFilters(unsigned int indexP, int numberP);
|
||||||
|
bool IsPolling() {return usePollingM;}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern cSatipConfig SatipConfig;
|
extern cSatipConfig SatipConfig;
|
||||||
|
13
data.c
13
data.c
@ -20,7 +20,7 @@ enum LOGLEVEL {
|
|||||||
logAll = 0xFFFF
|
logAll = 0xFFFF
|
||||||
};
|
};
|
||||||
|
|
||||||
int logLevel = logFunc | logFuncPerf | logData;
|
int logLevel = logFunc /*| logFuncPerf | logData*/;
|
||||||
|
|
||||||
#define log(lvl) \
|
#define log(lvl) \
|
||||||
if (logLevel & lvl) \
|
if (logLevel & lvl) \
|
||||||
@ -79,7 +79,9 @@ int cSatipTunerDataThread::LastReceivedMs()
|
|||||||
{
|
{
|
||||||
int rc = timeDataReceivedM.Elapsed();
|
int rc = timeDataReceivedM.Elapsed();
|
||||||
|
|
||||||
log2(logFunc, "returning %d", rc);
|
log2(logFuncPerf, "returning %d", rc);
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cSatipTunerDataThread::ResetLastReceivedMs()
|
void cSatipTunerDataThread::ResetLastReceivedMs()
|
||||||
@ -107,6 +109,7 @@ void cSatipTunerDataThread::Flush(void)
|
|||||||
void cSatipTunerDataThread::Action(void)
|
void cSatipTunerDataThread::Action(void)
|
||||||
{
|
{
|
||||||
log(logFunc);
|
log(logFunc);
|
||||||
|
bool polling = SatipConfig.IsPolling();
|
||||||
|
|
||||||
// Increase priority
|
// Increase priority
|
||||||
SetPriority(-1);
|
SetPriority(-1);
|
||||||
@ -121,6 +124,9 @@ void cSatipTunerDataThread::Action(void)
|
|||||||
// Read data
|
// Read data
|
||||||
if (rtpSocketM && rtpSocketM->IsOpen()) {
|
if (rtpSocketM && rtpSocketM->IsOpen()) {
|
||||||
length = rtpSocketM->ReadVideo(packetBufferM, size);
|
length = rtpSocketM->ReadVideo(packetBufferM, size);
|
||||||
|
if (!polling || length > 0)
|
||||||
|
timeDataReceivedM.Set();
|
||||||
|
|
||||||
log2(logData, "received %d bytes", length);
|
log2(logData, "received %d bytes", length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,13 +138,12 @@ void cSatipTunerDataThread::Action(void)
|
|||||||
if (statisticsM)
|
if (statisticsM)
|
||||||
statisticsM->AddTunerStatistic(length);
|
statisticsM->AddTunerStatistic(length);
|
||||||
|
|
||||||
timeDataReceivedM.Set();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mutexM.Unlock();
|
mutexM.Unlock();
|
||||||
|
|
||||||
// to avoid busy loop and reduce cpu load
|
// to avoid busy loop and reduce cpu load
|
||||||
if (length <= 0)
|
if (polling && length <= 0)
|
||||||
sleepM.Wait(10);
|
sleepM.Wait(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
15
socket.c
15
socket.c
@ -23,7 +23,8 @@ cSatipSocket::cSatipSocket()
|
|||||||
socketDescM(-1),
|
socketDescM(-1),
|
||||||
lastErrorReportM(0),
|
lastErrorReportM(0),
|
||||||
packetErrorsM(0),
|
packetErrorsM(0),
|
||||||
sequenceNumberM(-1)
|
sequenceNumberM(-1),
|
||||||
|
waitM(false)
|
||||||
{
|
{
|
||||||
debug("cSatipSocket::%s()", __FUNCTION__);
|
debug("cSatipSocket::%s()", __FUNCTION__);
|
||||||
memset(&sockAddrM, 0, sizeof(sockAddrM));
|
memset(&sockAddrM, 0, sizeof(sockAddrM));
|
||||||
@ -36,17 +37,22 @@ cSatipSocket::~cSatipSocket()
|
|||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cSatipSocket::Open(const int portP)
|
bool cSatipSocket::Open(const int portP, bool waitP)
|
||||||
{
|
{
|
||||||
// Bind to the socket if it is not active already
|
// Bind to the socket if it is not active already
|
||||||
if (socketDescM < 0) {
|
if (socketDescM < 0) {
|
||||||
|
waitM = waitP;
|
||||||
|
|
||||||
socklen_t len = sizeof(sockAddrM);
|
socklen_t len = sizeof(sockAddrM);
|
||||||
// Create socket
|
// Create socket
|
||||||
socketDescM = socket(PF_INET, SOCK_DGRAM, 0);
|
socketDescM = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
ERROR_IF_RET(socketDescM < 0, "socket()", return false);
|
ERROR_IF_RET(socketDescM < 0, "socket()", return false);
|
||||||
|
|
||||||
|
if (!waitP)
|
||||||
// Make it use non-blocking I/O to avoid stuck read calls
|
// Make it use non-blocking I/O to avoid stuck read calls
|
||||||
ERROR_IF_FUNC(fcntl(socketDescM, F_SETFL, O_NONBLOCK), "fcntl(O_NONBLOCK)",
|
ERROR_IF_FUNC(fcntl(socketDescM, F_SETFL, O_NONBLOCK), "fcntl(O_NONBLOCK)",
|
||||||
Close(), return false);
|
Close(), return false);
|
||||||
|
|
||||||
// Allow multiple sockets to use the same PORT number
|
// Allow multiple sockets to use the same PORT number
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
ERROR_IF_FUNC(setsockopt(socketDescM, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0,
|
ERROR_IF_FUNC(setsockopt(socketDescM, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0,
|
||||||
@ -63,7 +69,8 @@ bool cSatipSocket::Open(const int portP)
|
|||||||
"getsockname()", Close(), return false);
|
"getsockname()", Close(), return false);
|
||||||
socketPortM = ntohs(sockAddrM.sin_port);
|
socketPortM = ntohs(sockAddrM.sin_port);
|
||||||
}
|
}
|
||||||
debug("cSatipSocket::%s(%d): socketPort=%d", __FUNCTION__, portP, socketPortM);
|
debug("cSatipSocket::%s(%d,%d): socketPort=%d",
|
||||||
|
__FUNCTION__, portP, socketPortM, waitP);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +140,7 @@ int cSatipSocket::Read(unsigned char *bufferAddrP, unsigned int bufferLenP)
|
|||||||
msgh.msg_flags = 0;
|
msgh.msg_flags = 0;
|
||||||
|
|
||||||
if (socketDescM && bufferAddrP && (bufferLenP > 0))
|
if (socketDescM && bufferAddrP && (bufferLenP > 0))
|
||||||
len = (int)recvmsg(socketDescM, &msgh, MSG_DONTWAIT);
|
len = (int)recvmsg(socketDescM, &msgh, waitM ? 0 : MSG_DONTWAIT);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
return len;
|
return len;
|
||||||
} while (len > 0);
|
} while (len > 0);
|
||||||
|
3
socket.h
3
socket.h
@ -21,11 +21,12 @@ private:
|
|||||||
time_t lastErrorReportM;
|
time_t lastErrorReportM;
|
||||||
int packetErrorsM;
|
int packetErrorsM;
|
||||||
int sequenceNumberM;
|
int sequenceNumberM;
|
||||||
|
bool waitM;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cSatipSocket();
|
cSatipSocket();
|
||||||
~cSatipSocket();
|
~cSatipSocket();
|
||||||
bool Open(const int portP = 0);
|
bool Open(const int portP = 0, bool waitP = false);
|
||||||
void Close(void);
|
void Close(void);
|
||||||
int Port(void) { return socketPortM; }
|
int Port(void) { return socketPortM; }
|
||||||
bool IsOpen(void) { return (socketDescM >= 0); }
|
bool IsOpen(void) { return (socketDescM >= 0); }
|
||||||
|
19
tuner.c
19
tuner.c
@ -43,9 +43,12 @@ cSatipTuner::cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP)
|
|||||||
|
|
||||||
RtspInitialize();
|
RtspInitialize();
|
||||||
|
|
||||||
|
bool waitSocket = false;
|
||||||
|
|
||||||
// Open sockets
|
// Open sockets
|
||||||
for (int i = 100; i > 0; --i) {
|
for (int i = 100; i > 0; --i) {
|
||||||
if (rtpSocketM->Open() && rtcpSocketM->Open(rtpSocketM->Port() + 1))
|
if (rtpSocketM->Open(0, waitSocket) &&
|
||||||
|
rtcpSocketM->Open(rtpSocketM->Port() + 1), waitSocket)
|
||||||
break;
|
break;
|
||||||
rtpSocketM->Close();
|
rtpSocketM->Close();
|
||||||
rtcpSocketM->Close();
|
rtcpSocketM->Close();
|
||||||
@ -94,7 +97,7 @@ void cSatipTuner::Action(void)
|
|||||||
// Do the thread loop
|
// Do the thread loop
|
||||||
while (Running()) {
|
while (Running()) {
|
||||||
if (reconnectM) {
|
if (reconnectM) {
|
||||||
info("SAT>IP Device %d timed out. Reconnecting.", deviceM->GetId());
|
info("SAT>IP Device %d reconnecting.", deviceM->GetId());
|
||||||
cMutexLock MutexLock(&mutexM);
|
cMutexLock MutexLock(&mutexM);
|
||||||
if (tunedM)
|
if (tunedM)
|
||||||
Disconnect();
|
Disconnect();
|
||||||
@ -130,20 +133,22 @@ void cSatipTuner::Action(void)
|
|||||||
signalQualityM = eDefaultSignalQuality;
|
signalQualityM = eDefaultSignalQuality;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rtcpTimeout.TimedOut())
|
if (rtcpTimeout.TimedOut()) {
|
||||||
|
error("No RTP Data received for %d ms [device %d], Reconnect initiated",
|
||||||
|
(int)rtcpTimeout.Elapsed(), deviceM->GetId());
|
||||||
|
rtcpTimeout.Set(eReConnectTimeoutMs);
|
||||||
reconnectM = true;
|
reconnectM = true;
|
||||||
|
}
|
||||||
|
|
||||||
int passedMs = dataThreadM.LastReceivedMs();
|
int passedMs = dataThreadM.LastReceivedMs();
|
||||||
if (passedMs >= eReConnectTimeoutMs) {
|
if (passedMs >= eReConnectTimeoutMs) {
|
||||||
error("No Data received for %d ms [device %d], Reconnect initiated",
|
error("No RTP Data received for %d ms [device %d], Reconnect initiated",
|
||||||
(int)passedMs, deviceM->GetId());
|
(int)passedMs, deviceM->GetId());
|
||||||
dataThreadM.ResetLastReceivedMs();
|
dataThreadM.ResetLastReceivedMs();
|
||||||
reconnectM = true;
|
reconnectM = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
sleepM.Wait(10); // to avoid busy loop and reduce cpu load
|
sleepM.Wait(50); // to avoid busy loop and reduce cpu load
|
||||||
}
|
}
|
||||||
debug("cSatipTuner::%s(): exiting [device %d]", __FUNCTION__, deviceIdM);
|
debug("cSatipTuner::%s(): exiting [device %d]", __FUNCTION__, deviceIdM);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user