From 9e6d784aeceb0b7cc111ebcce3923c689e719fc0 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Tue, 14 Jan 2014 18:30:14 +0200 Subject: [PATCH] Shutdown devices already in cPluginManager::Stop(). --- device.c | 17 +++++++++++++++-- device.h | 1 + iptv.c | 1 + pidscanner.c | 1 - pidscanner.h | 8 ++++++++ sectionfilter.c | 14 ++++++++++---- sectionfilter.h | 1 + 7 files changed, 36 insertions(+), 7 deletions(-) diff --git a/device.c b/device.c index 476de8c..f9a69db 100644 --- a/device.c +++ b/device.c @@ -91,6 +91,15 @@ bool cIptvDevice::Initialize(unsigned int deviceCountP) return true; } +void cIptvDevice::Shutdown(void) +{ + debug("cIptvDevice::%s()", __FUNCTION__); + for (int i = 0; i < IPTV_MAX_DEVICES; ++i) { + if (IptvDevicesS[i]) + IptvDevicesS[i]->CloseDvr(); + } +} + unsigned int cIptvDevice::Count(void) { unsigned int count = 0; @@ -106,7 +115,7 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int cardIndexP) { //debug("cIptvDevice::%s(%d)", __FUNCTION__, cardIndexP); for (unsigned int i = 0; i < IPTV_MAX_DEVICES; ++i) { - if ((IptvDevicesS[i] != NULL) && (IptvDevicesS[i]->CardIndex() == cardIndexP)) { + if (IptvDevicesS[i] && (IptvDevicesS[i]->CardIndex() == cardIndexP)) { //debug("cIptvDevice::%s(%d): found!", __FUNCTION__, cardIndexP); return IptvDevicesS[i]; } @@ -320,6 +329,8 @@ bool cIptvDevice::OpenDvr(void) pIptvStreamerM->Open(); if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering()) pSidScannerM->Open(); + if (pidScanEnabledM && pPidScannerM) + pPidScannerM->Open(); isOpenDvrM = true; return true; } @@ -327,6 +338,8 @@ bool cIptvDevice::OpenDvr(void) void cIptvDevice::CloseDvr(void) { debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM); + if (pidScanEnabledM && pPidScannerM) + pPidScannerM->Close(); if (sidScanEnabledM && pSidScannerM) pSidScannerM->Close(); if (pIptvStreamerM) @@ -394,7 +407,7 @@ unsigned int cIptvDevice::CheckData(void) bool cIptvDevice::GetTSPacket(uchar *&Data) { //debug("cIptvDevice::%s(%d)", __FUNCTION__, deviceIndexM); - if (tsBufferM && !IsBuffering()) { + if (isOpenDvrM && tsBufferM && !IsBuffering()) { if (isPacketDeliveredM) { tsBufferM->Del(TS_SIZE); isPacketDeliveredM = false; diff --git a/device.h b/device.h index 5839495..69d8875 100644 --- a/device.h +++ b/device.h @@ -27,6 +27,7 @@ class cIptvDevice : public cDevice, public cIptvPidStatistics, public cIptvBuffe public: static unsigned int deviceCount; static bool Initialize(unsigned int DeviceCount); + static void Shutdown(void); static unsigned int Count(void); static cIptvDevice *GetIptvDevice(int CardIndex); diff --git a/iptv.c b/iptv.c index 3815c4e..594b933 100644 --- a/iptv.c +++ b/iptv.c @@ -118,6 +118,7 @@ void cPluginIptv::Stop(void) { debug("cPluginIptv::%s()", __FUNCTION__); // Stop any background activities the plugin is performing. + cIptvDevice::Shutdown(); curl_global_cleanup(); } diff --git a/pidscanner.c b/pidscanner.c index fcc22c7..777a63a 100644 --- a/pidscanner.c +++ b/pidscanner.c @@ -39,7 +39,6 @@ void cPidScanner::SetChannel(const tChannelID &channelIdP) aPidM = 0xFFFF; numApidsM = 0; processM = true; - timeoutM.Set(PIDSCANNER_TIMEOUT_IN_MS); } void cPidScanner::Process(const uint8_t* bufP) diff --git a/pidscanner.h b/pidscanner.h index 738422c..e9125ec 100644 --- a/pidscanner.h +++ b/pidscanner.h @@ -13,6 +13,12 @@ class cPidScanner { private: + enum { + PIDSCANNER_APID_COUNT = 5, /* minimum count of audio pid samples for pid detection */ + PIDSCANNER_VPID_COUNT = 5, /* minimum count of video pid samples for pid detection */ + PIDSCANNER_PID_DELTA_COUNT = 100, /* minimum count of pid samples for audio/video only pid detection */ + PIDSCANNER_TIMEOUT_IN_MS = 15000 /* 15s timeout for detection */ + }; cTimeMs timeoutM; tChannelID channelIdM; bool processM; @@ -26,6 +32,8 @@ public: ~cPidScanner(); void SetChannel(const tChannelID &channelIdP); void Process(const uint8_t* bufP); + void Open() { debug("cPidScanner::%s()", __FUNCTION__); timeoutM.Set(PIDSCANNER_TIMEOUT_IN_MS); } + void Close() { debug("cPidScanner::%s()", __FUNCTION__); timeoutM.Set(0); } }; #endif // __PIDSCANNER_H diff --git a/sectionfilter.c b/sectionfilter.c index 9bfcd12..02cefbe 100644 --- a/sectionfilter.c +++ b/sectionfilter.c @@ -238,9 +238,7 @@ cIptvSectionFilterHandler::cIptvSectionFilterHandler(int deviceIndexP, unsigned cIptvSectionFilterHandler::~cIptvSectionFilterHandler() { debug("cIptvSectionFilterHandler::%s(%d)", __FUNCTION__, deviceIndexM); - // Stop thread - if (Running()) - Cancel(3); + Stop(); DELETE_POINTER(ringBufferM); @@ -250,6 +248,15 @@ cIptvSectionFilterHandler::~cIptvSectionFilterHandler() Delete(i); } +bool cIptvSectionFilterHandler::Stop(void) +{ + debug("cIptvSectionFilterHandler::%s(%d): entering", __FUNCTION__, deviceIndexM); + // Stop thread + if (Running()) + Cancel(3); + return true; +} + void cIptvSectionFilterHandler::Action(void) { debug("cIptvSectionFilterHandler::%s(%d): entering", __FUNCTION__, deviceIndexM); @@ -383,4 +390,3 @@ void cIptvSectionFilterHandler::Write(uchar *bufferP, int lengthP) ringBufferM->ReportOverflow(lengthP - len); } } - diff --git a/sectionfilter.h b/sectionfilter.h index 935ed5e..c9982e9 100644 --- a/sectionfilter.h +++ b/sectionfilter.h @@ -80,6 +80,7 @@ protected: public: cIptvSectionFilterHandler(int deviceIndexP, unsigned int bufferLenP); virtual ~cIptvSectionFilterHandler(); + bool Stop(void); cString GetInformation(void); int Open(u_short pidP, u_char tidP, u_char maskP); void Close(int handleP);