From 72a9f21006b8a3233d5eec69f82268dd1aa68533 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Sat, 2 Mar 2013 01:26:04 +0200 Subject: [PATCH] Changed a pointer to a reference in order to stabilize the CURL protocol and always remember to close the sid scanner. --- device.c | 2 +- protocolcurl.c | 26 +++++++++++++------------- protocolcurl.h | 2 +- sidscanner.h | 4 ++-- streamer.c | 5 +++-- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/device.c b/device.c index 0054428..bd59212 100644 --- a/device.c +++ b/device.c @@ -392,7 +392,7 @@ bool cIptvDevice::OpenDvr(void) void cIptvDevice::CloseDvr(void) { debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM); - if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering()) + if (sidScanEnabledM && pSidScannerM ) pSidScannerM->Close(); if (pIptvStreamerM) pIptvStreamerM->Close(); diff --git a/protocolcurl.c b/protocolcurl.c index 16178f6..e4f39dc 100644 --- a/protocolcurl.c +++ b/protocolcurl.c @@ -26,8 +26,8 @@ cIptvProtocolCurl::cIptvProtocolCurl() handleM(NULL), multiM(NULL), headerListM(NULL), - ringBufferM(new cRingBufferLinear(MEGABYTE(IptvConfig.GetTsBufferSize()), 7 * TS_SIZE, - false, *cString::sprintf("IPTV CURL"))), + ringBufferM(new cRingBufferLinear(MEGABYTE(IptvConfig.GetTsBufferSize()), + 7 * TS_SIZE, false, "IPTV CURL")), rtspControlM(), modeM(eModeUnknown), connectedM(false), @@ -65,7 +65,7 @@ size_t cIptvProtocolCurl::WriteRtspCallback(void *ptrP, size_t sizeP, size_t nme size_t len = sizeP * nmembP; unsigned char *p = (unsigned char *)ptrP; //debug("cIptvProtocolCurl::%s(%zu)", __FUNCTION__, len); - + // Validate packet header ('$') and channel (0) if (obj && (p[0] == 0x24 ) && (p[1] == 0)) { int length = (p[2] << 8) | p[3]; @@ -121,7 +121,7 @@ size_t cIptvProtocolCurl::DescribeCallback(void *ptrP, size_t sizeP, size_t nmem free(s); } r = strtok(NULL, "\r\n"); - } + } if (!isempty(*control) && obj) obj->SetRtspControl(*control); @@ -190,12 +190,12 @@ void cIptvProtocolCurl::ClearData() ringBufferM->Clear(); } -unsigned char *cIptvProtocolCurl::GetData(unsigned int *lenP) +unsigned char *cIptvProtocolCurl::GetData(int &lenP) { cMutexLock MutexLock(&mutexM); //debug("cIptvProtocolCurl::%s()", __FUNCTION__); unsigned char *p = NULL; - *lenP = 0; + lenP = 0; if (ringBufferM) { int count = 0; p = ringBufferM->Get(count); @@ -210,13 +210,13 @@ unsigned char *cIptvProtocolCurl::GetData(unsigned int *lenP) } error("IPTV skipped %d bytes to sync on TS packet\n", count); ringBufferM->Del(count); - *lenP = 0; + lenP = 0; return NULL; } } #endif count -= (count % TS_SIZE); - *lenP = count; + lenP = count; } return p; @@ -473,11 +473,11 @@ int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP) } // ... and try to empty it - unsigned char *p = GetData(&bufferLenP); - if (p && (bufferLenP > 0)) { - memcpy(bufferAddrP, p, bufferLenP); - DelData(bufferLenP); - len = bufferLenP; + unsigned char *p = GetData(len); + if (p && (len > 0)) { + len = min(len, (int)bufferLenP); + memcpy(bufferAddrP, p, len); + DelData(len); //debug("cIptvProtocolCurl::%s(): get %d bytes", __FUNCTION__, len); } } diff --git a/protocolcurl.h b/protocolcurl.h index 9d6b691..ef6a464 100644 --- a/protocolcurl.h +++ b/protocolcurl.h @@ -54,7 +54,7 @@ private: bool PutData(unsigned char *dataP, int lenP); void DelData(int lenP); void ClearData(void); - unsigned char *GetData(unsigned int *lenP); + unsigned char *GetData(int &lenP); public: cIptvProtocolCurl(); diff --git a/sidscanner.h b/sidscanner.h index b0358d2..5649232 100644 --- a/sidscanner.h +++ b/sidscanner.h @@ -26,8 +26,8 @@ public: cSidScanner(void); ~cSidScanner(); void SetChannel(const tChannelID &channelIdP); - void Open() { isActiveM = true; } - void Close() { isActiveM = false; } + void Open() { debug("cSidScanner::%s()", __FUNCTION__); isActiveM = true; } + void Close() { debug("cSidScanner::%s()", __FUNCTION__); isActiveM = false; } }; #endif // __SIDSCANNER_H diff --git a/streamer.c b/streamer.c index 0e2241b..0c13c5e 100644 --- a/streamer.c +++ b/streamer.c @@ -46,8 +46,9 @@ void cIptvStreamer::Action(void) // Do the thread loop while (packetBufferM && Running()) { int length = -1; - if (protocolM) - length = protocolM->Read(packetBufferM, min((unsigned int)ringBufferM->Free(), packetBufferLenM)); + unsigned int size = min((unsigned int)ringBufferM->Free(), packetBufferLenM); + if (protocolM && (size > 0)) + length = protocolM->Read(packetBufferM, size); if (length > 0) { AddStreamerStatistic(length); if (ringBufferM) {