From dfbb3515ef4e9c445f0f86f4478e9887dcf259fe Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Sun, 16 Mar 2014 19:58:09 +0200 Subject: [PATCH] Changed code to utilize a proper XML library, refactored the session code, fxed EIT scan functionality, and updated for vdr-2.1.6. --- HISTORY | 7 +++++++ Makefile | 11 +++++++++++ README | 12 ++++++++++-- common.h | 9 +++++++++ device.c | 2 +- discover.c | 48 ++++++++++++++++++++++++++++++++---------------- discover.h | 2 +- param.c | 12 +++++++++--- po/de_DE.po | 4 ++-- po/fi_FI.po | 2 +- satip.c | 4 ++-- tuner.c | 37 +++++++++++++++++++++++-------------- tuner.h | 4 +++- 13 files changed, 111 insertions(+), 43 deletions(-) diff --git a/HISTORY b/HISTORY index 9b8c597..15bf7aa 100644 --- a/HISTORY +++ b/HISTORY @@ -12,3 +12,10 @@ VDR Plugin 'satip' Revision History - Switched to the standard S/T/C source identifiers. - Added a new operation mode setup parameter. - Added new SVDRP commands. + +2014-03-22: Version 0.1.1 + +- Changed code to utilize a proper XML library. +- Refactored the session code. +- Fixed EIT scan functionality. +- Updated for vdr-2.1.6. diff --git a/Makefile b/Makefile index 1d7b7c6..524338c 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,10 @@ #SATIP_DEBUG = 1 +# Use TinyXML instead of PugiXML + +#SATIP_USE_TINYXML = 1 + # Strip debug symbols? Set eg. to /bin/true if not STRIP = strip @@ -64,6 +68,13 @@ INCLUDES += DEFINES += -DPLUGIN_NAME_I18N='"$(PLUGIN)"' +ifdef SATIP_USE_TINYXML +DEFINES += -DUSE_TINYXML +LIBS += -ltinyxml +else +LIBS += -lpugixml +endif + ifdef SATIP_DEBUG DEFINES += -DDEBUG endif diff --git a/README b/README index ff5578a..7a04940 100644 --- a/README +++ b/README @@ -17,6 +17,12 @@ Requirements: - Libcurl - the multiprotocol file transfer library with RTSP support http://curl.haxx.se/libcurl/ +- PugiXML - Light-weight, simple and fast XML parser for C++ + http://pugixml.org/ + or + TinyXML - a simple, small, C++ XML parser + http://www.grinninglizard.com/tinyxml/ + - VDR-2.1.4+ for scrambled channels Description: @@ -92,13 +98,15 @@ Notes: result of invalid channel parameters or lack of free SAT>IP tuners. - SAT>IP specification 1.2 doesn't support DVB-C/DVB-C2 receivers yet, - but DVB-C is supported for Digital Devices Octopus Net devices. + but DVB-C (KABEL>IP) is supported for Digital Devices Octopus Net + devices. - If the plugin doesn't detect your SAT>IP network device, make sure your setup doesn't have firewalled the UDP port 1900. - Stream decryption requires a separate CAM plugin that works without - direct access to any DVB card devices. + direct access to any DVB card devices. The integrated CAM slot in + Octopus Net devices isn't supported. - The 100% compliance against SAT>IP specification 1.2 requires a patched VDR providing channel configuration for pilot, T2 system id, diff --git a/common.h b/common.h index 782b4b4..06a98bb 100644 --- a/common.h +++ b/common.h @@ -78,6 +78,15 @@ } \ } while (0) +#define FREE_POINTER(ptr) \ + do { \ + if (ptr) { \ + typeof(*ptr) *tmp = ptr; \ + ptr = NULL; \ + free(tmp); \ + } \ + } while (0) + #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) uint16_t ts_pid(const uint8_t *bufP); diff --git a/device.c b/device.c index b3748fb..4d48e24 100644 --- a/device.c +++ b/device.c @@ -224,7 +224,7 @@ bool cSatipDevice::ProvidesChannel(const cChannel *channelP, int priorityP, bool bool cSatipDevice::ProvidesEIT(void) const { - return (SatipConfig.GetEITScan() && pTunerM && pTunerM->IsTuned()); + return (SatipConfig.GetEITScan()); } int cSatipDevice::NumProvidedSystems(void) const diff --git a/discover.c b/discover.c index 9a70b8a..167df3a 100644 --- a/discover.c +++ b/discover.c @@ -6,7 +6,11 @@ */ #include - +#ifdef USE_TINYXML + #include +#else + #include +#endif #include "common.h" #include "config.h" #include "socket.h" @@ -43,28 +47,40 @@ void cSatipDiscover::Destroy(void) instanceS->Deactivate(); } -size_t cSatipDiscover::WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP) +size_t cSatipDiscover::WriteCallback(char *ptrP, size_t sizeP, size_t nmembP, void *dataP) { cSatipDiscover *obj = reinterpret_cast(dataP); size_t len = sizeP * nmembP; //debug("cSatipDiscover::%s(%zu)", __FUNCTION__, len); - char *s, *p = (char *)ptrP; - char *r = strtok_r(p, "\r\n", &s); - char *desc = NULL, *model = NULL, *addr = NULL; - while (r) { - //debug("cSatipDiscover::%s(%zu): %s", __FUNCTION__, len, r); - r = skipspace(r); - // OctopusNet - if (startswith(r, "DVBT-2 - if (startswith(r, "GetText() ? descElement->GetText() : "MyBrokenHardware"; + TiXmlElement *modelElement = docHandle.FirstChild("root").FirstChild("device").FirstChild("satip:X_SATIPCAP").ToElement(); + if (modelElement) + model = modelElement->GetText() ? modelElement->GetText() : "DVBS2-1"; +#else + pugi::xml_document doc; + pugi::xml_parse_result result = doc.load_buffer(ptrP, len); + if (result) { + pugi::xml_node descNode = doc.first_element_by_path("root/device/friendlyName"); + if (descNode) + desc = descNode.text().as_string("MyBrokenHardware"); + pugi::xml_node modelNode = doc.first_element_by_path("root/device/satip:X_SATIPCAP"); + if (modelNode) + model = modelNode.text().as_string("DVBS2-1"); + } +#endif SATIP_CURL_EASY_GETINFO(obj->handleM, CURLINFO_PRIMARY_IP, &addr); obj->AddServer(addr, desc, model); } diff --git a/discover.h b/discover.h index 9234f68..f49f085 100644 --- a/discover.h +++ b/discover.h @@ -28,7 +28,7 @@ private: static cSatipDiscover *instanceS; static const char *bcastAddressS; static const char *bcastMessageS; - static size_t WriteCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP); + static size_t WriteCallback(char *ptrP, size_t sizeP, size_t nmembP, void *dataP); cMutex mutexM; CURL *handleM; cSatipSocket *socketM; diff --git a/param.c b/param.c index 3c8c163..6bc9750 100644 --- a/param.c +++ b/param.c @@ -138,9 +138,15 @@ cString GetTransponderUrlParameters(const cChannel *channelP) if (channelP) { char buffer[255]; cDvbTransponderParameters dtp(channelP->Parameters()); - int Pilot = PILOT_AUTO; // should be added into cDvbTransponderParameters - int T2SystemId = 0; // should be added into cDvbTransponderParameters - int SisoMiso = 0; // should be added into cDvbTransponderParameters +#if defined(APIVERSNUM) && APIVERSNUM < 20106 + int Pilot = PILOT_AUTO; + int T2SystemId = 0; + int SisoMiso = 0; +#else + int Pilot = dtp.Pilot(); + int T2SystemId = dtp.T2SystemId(); + int SisoMiso = dtp.SisoMiso(); +#endif float freq = channelP->Frequency(); char type = cSource::ToChar(channelP->Source()); cSource *source = Sources.Get(channelP->Source()); diff --git a/po/de_DE.po b/po/de_DE.po index b6ed04f..caa4be2 100644 --- a/po/de_DE.po +++ b/po/de_DE.po @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: vdr-satip 0.1.0\n" +"Project-Id-Version: vdr-satip 0.1.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-03-15 03:15+0200\n" "PO-Revision-Date: 2014-03-15 03:15+0200\n" @@ -53,7 +53,7 @@ msgid "Description" msgstr "Beschreibung" msgid "Creation date" -msgstr "Erstellungsdatum" +msgstr "Zeitpunkt der Erstellung" msgid "SAT>IP Information" msgstr "SAT>IP Informationen" diff --git a/po/fi_FI.po b/po/fi_FI.po index bfffc60..2e672ff 100644 --- a/po/fi_FI.po +++ b/po/fi_FI.po @@ -5,7 +5,7 @@ # msgid "" msgstr "" -"Project-Id-Version: vdr-satip 0.1.0\n" +"Project-Id-Version: vdr-satip 0.1.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-03-15 03:15+0200\n" "PO-Revision-Date: 2014-03-15 03:15+0200\n" diff --git a/satip.c b/satip.c index 4c7062e..58d2641 100644 --- a/satip.c +++ b/satip.c @@ -21,7 +21,7 @@ #define GITVERSION "" #endif - const char VERSION[] = "0.1.0" GITVERSION; + const char VERSION[] = "0.1.1" GITVERSION; static const char DESCRIPTION[] = trNOOP("SAT>IP Devices"); class cPluginSatip : public cPlugin { @@ -196,7 +196,7 @@ bool cPluginSatip::SetupParse(const char *nameP, const char *valueP) // Parse your own setup parameters and store their values. if (!strcasecmp(nameP, "OperatingMode")) SatipConfig.SetOperatingMode(atoi(valueP)); - if (!strcasecmp(nameP, "EnableEITScan")) + else if (!strcasecmp(nameP, "EnableEITScan")) SatipConfig.SetEITScan(atoi(valueP)); else if (!strcasecmp(nameP, "DisabledFilters")) { int DisabledFilters[SECTION_FILTER_TABLE_SIZE]; diff --git a/tuner.c b/tuner.c index ef53c65..dcbe15f 100644 --- a/tuner.c +++ b/tuner.c @@ -26,6 +26,7 @@ cSatipTuner::cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP) headerListM(NULL), keepAliveM(), pidUpdateCacheM(), + sessionM(), timeoutM(eKeepAliveIntervalMs), openedM(false), tunedM(false), @@ -67,28 +68,29 @@ size_t cSatipTuner::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP, void size_t len = sizeP * nmembP; //debug("cSatipTuner::%s(%zu)", __FUNCTION__, len); - int id = -1, timeout = -1; char *s, *p = (char *)ptrP; char *r = strtok_r(p, "\r\n", &s); - while (r) { + while (obj && r) { //debug("cSatipTuner::%s(%zu): %s", __FUNCTION__, len, r); r = skipspace(r); if (strstr(r, "com.ses.streamID")) { - if (sscanf(r, "com.ses.streamID:%11d", &id) != 1) - id = -1; + int streamid = -1; + if (sscanf(r, "com.ses.streamID:%11d", &streamid) == 1) + obj->SetStreamId(streamid); } else if (strstr(r, "Session:")) { - int session = -1; - if (sscanf(r, "Session:%11d;timeout=%11d", &session, &timeout) != 2) - timeout = -1; + int timeout = -1; + char *session = NULL; + if (sscanf(r, "Session:%m[^;];timeout=%11d", &session, &timeout) == 2) + obj->SetSessionTimeout(skipspace(session), timeout); + else if (sscanf(r, "Session:%m[^;]", &session) == 1) + obj->SetSessionTimeout(skipspace(session), -1); + FREE_POINTER(session); } r = strtok_r(NULL, "\r\n", &s); } - if (id >= 0 && obj) - obj->SetStreamInfo(id, timeout); - return len; } @@ -245,7 +247,7 @@ bool cSatipTuner::Connect(void) // Start playing uri = cString::sprintf("rtsp://%s/stream=%d", *streamAddrM, streamIdM); SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_STREAM_URI, *uri); - SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_SESSION_ID, NULL); + SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_SESSION_ID, *sessionM); SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_RTSP_REQUEST, (long)CURL_RTSPREQ_PLAY); SATIP_CURL_EASY_PERFORM(handleM); if (!ValidateLatestResponse()) @@ -369,11 +371,18 @@ void cSatipTuner::ParseReceptionParameters(const char *paramP) } } -void cSatipTuner::SetStreamInfo(int idP, int timeoutP) +void cSatipTuner::SetStreamId(int streamIdP) { cMutexLock MutexLock(&mutexM); - debug("cSatipTuner::%s(%d, %d)", __FUNCTION__, idP, timeoutP); - streamIdM = idP; + debug("cSatipTuner::%s(%d)", __FUNCTION__, streamIdP); + streamIdM = streamIdP; +} + +void cSatipTuner::SetSessionTimeout(const char *sessionP, int timeoutP) +{ + cMutexLock MutexLock(&mutexM); + debug("cSatipTuner::%s(%s, %d)", __FUNCTION__, sessionP, timeoutP); + sessionM = sessionP; timeoutM = timeoutP > 0 ? timeoutP * 1000L : eKeepAliveIntervalMs; } diff --git a/tuner.h b/tuner.h index 167b477..c156a18 100644 --- a/tuner.h +++ b/tuner.h @@ -50,6 +50,7 @@ private: cTimeMs keepAliveM; cTimeMs signalInfoCacheM; cTimeMs pidUpdateCacheM; + cString sessionM; int timeoutM; bool openedM; bool tunedM; @@ -64,7 +65,8 @@ private: bool Disconnect(void); bool ValidateLatestResponse(void); void ParseReceptionParameters(const char *paramP); - void SetStreamInfo(int idP, int timeoutP); + void SetStreamId(int streamIdP); + void SetSessionTimeout(const char *sessionP, int timeoutP); bool KeepAlive(void); bool UpdateSignalInfoCache(void); bool UpdatePids(void);