From b3b06e569faac1c0dba0d52e674fa46a1bc287ba Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Sat, 31 Mar 2012 20:32:04 +0300 Subject: [PATCH] Fixed some channel switching bugs. --- HISTORY | 4 ++-- protocolext.c | 9 +++++---- protocolext.h | 1 + protocolhttp.c | 11 ++++++----- protocolhttp.h | 1 + protocoludp.c | 15 ++++++++------- protocoludp.h | 1 + 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/HISTORY b/HISTORY index 8ea9e8e..65cfbb5 100644 --- a/HISTORY +++ b/HISTORY @@ -159,7 +159,7 @@ VDR Plugin 'iptv' Revision History - Added support for LDFLAGS. - Added cppcheck target into Makefile. -2012-03-25: Version 0.5.1 +2012-04-01: Version 0.5.1 - Updated for vdr-1.7.27. -- Fixed channel switching in UDP protocol. +- Fixed some channel switching bugs. diff --git a/protocolext.c b/protocolext.c index c42449c..a5a3086 100644 --- a/protocolext.c +++ b/protocolext.c @@ -22,7 +22,8 @@ cIptvProtocolExt::cIptvProtocolExt() : pid(-1), scriptFile(""), - scriptParameter(0) + scriptParameter(0), + streamPort(0) { debug("cIptvProtocolExt::cIptvProtocolExt()\n"); } @@ -53,7 +54,7 @@ void cIptvProtocolExt::ExecuteScript(void) for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++) close(i); // Execute the external script - cString cmd = cString::sprintf("%s %d %d", *scriptFile, scriptParameter, socketPort); + cString cmd = cString::sprintf("%s %d %d", *scriptFile, scriptParameter, streamPort); debug("cIptvProtocolExt::ExecuteScript(child): %s\n", *cmd); if (execl("/bin/bash", "sh", "-c", *cmd, (char *)NULL) == -1) { error("Script execution failed: %s", *cmd); @@ -113,7 +114,7 @@ bool cIptvProtocolExt::Open(void) if (!strlen(*scriptFile)) return false; // Create the listening socket - OpenSocket(socketPort); + OpenSocket(streamPort); // Execute the external script ExecuteScript(); isActive = true; @@ -149,7 +150,7 @@ bool cIptvProtocolExt::Set(const char* Location, const int Parameter, const int } scriptParameter = Parameter; // Update listen port - socketPort = IptvConfig.GetExtProtocolBasePort() + Index; + streamPort = IptvConfig.GetExtProtocolBasePort() + Index; } return true; } diff --git a/protocolext.h b/protocolext.h index e8bebdc..8d40204 100644 --- a/protocolext.h +++ b/protocolext.h @@ -17,6 +17,7 @@ private: int pid; cString scriptFile; int scriptParameter; + int streamPort; private: void TerminateScript(void); diff --git a/protocolhttp.c b/protocolhttp.c index 62abbd6..42c525e 100644 --- a/protocolhttp.c +++ b/protocolhttp.c @@ -20,7 +20,8 @@ cIptvProtocolHttp::cIptvProtocolHttp() : streamAddr(strdup("")), - streamPath(strdup("/")) + streamPath(strdup("/")), + streamPort(0) { debug("cIptvProtocolHttp::cIptvProtocolHttp()\n"); } @@ -41,7 +42,7 @@ bool cIptvProtocolHttp::Connect(void) // Check that stream address is valid if (!isActive && !isempty(streamAddr) && !isempty(streamPath)) { // Ensure that socket is valid and connect - OpenSocket(socketPort, streamAddr); + OpenSocket(streamPort, streamAddr); if (!ConnectSocket()) { CloseSocket(); return false; @@ -185,8 +186,8 @@ bool cIptvProtocolHttp::Set(const char* Location, const int Parameter, const int } else streamPath = strcpyrealloc(streamPath, "/"); - socketPort = Parameter; - //debug("http://%s:%d%s\n", streamAddr, socketPort, streamPath); + streamPort = Parameter; + //debug("http://%s:%d%s\n", streamAddr, streamPort, streamPath); // Re-connect the socket Connect(); } @@ -196,5 +197,5 @@ bool cIptvProtocolHttp::Set(const char* Location, const int Parameter, const int cString cIptvProtocolHttp::GetInformation(void) { //debug("cIptvProtocolHttp::GetInformation()"); - return cString::sprintf("http://%s:%d%s", streamAddr, socketPort, streamPath); + return cString::sprintf("http://%s:%d%s", streamAddr, streamPort, streamPath); } diff --git a/protocolhttp.h b/protocolhttp.h index 392bb0b..8338335 100644 --- a/protocolhttp.h +++ b/protocolhttp.h @@ -16,6 +16,7 @@ class cIptvProtocolHttp : public cIptvTcpSocket, public cIptvProtocolIf { private: char* streamAddr; char* streamPath; + int streamPort; private: bool Connect(void); diff --git a/protocoludp.c b/protocoludp.c index d7dfe13..3332fb2 100644 --- a/protocoludp.c +++ b/protocoludp.c @@ -20,7 +20,8 @@ cIptvProtocolUdp::cIptvProtocolUdp() : streamAddr(strdup("")), - sourceAddr(strdup("")) + sourceAddr(strdup("")), + streamPort(0) { debug("cIptvProtocolUdp::cIptvProtocolUdp()\n"); } @@ -38,7 +39,7 @@ cIptvProtocolUdp::~cIptvProtocolUdp() bool cIptvProtocolUdp::Open(void) { debug("cIptvProtocolUdp::Open(): sourceAddr=%s streamAddr=%s\n", sourceAddr, streamAddr); - OpenSocket(socketPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr)); + OpenSocket(streamPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr)); if (!isempty(streamAddr)) { // Join a new multicast group JoinMulticast(inet_addr(streamAddr)); @@ -51,7 +52,7 @@ bool cIptvProtocolUdp::Close(void) debug("cIptvProtocolUdp::Close(): sourceAddr=%s streamAddr=%s\n", sourceAddr, streamAddr); if (!isempty(streamAddr)) { // Drop the multicast group - OpenSocket(socketPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr)); + OpenSocket(streamPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr)); DropMulticast(inet_addr(streamAddr)); } // Close the socket @@ -73,7 +74,7 @@ bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int if (!isempty(Location)) { // Drop the multicast group if (!isempty(streamAddr)) { - OpenSocket(socketPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr)); + OpenSocket(streamPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr)); DropMulticast(inet_addr(streamAddr)); } // Update stream address and port @@ -85,10 +86,10 @@ bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int } else sourceAddr = strcpyrealloc(sourceAddr, ""); - socketPort = Parameter; + streamPort = Parameter; // Join a new multicast group if (!isempty(streamAddr)) { - OpenSocket(socketPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr)); + OpenSocket(streamPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr)); JoinMulticast(inet_addr(streamAddr)); } } @@ -98,5 +99,5 @@ bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int cString cIptvProtocolUdp::GetInformation(void) { //debug("cIptvProtocolUdp::GetInformation()"); - return cString::sprintf("udp://%s:%d", streamAddr, socketPort); + return cString::sprintf("udp://%s:%d", streamAddr, streamPort); } diff --git a/protocoludp.h b/protocoludp.h index 3cfe0af..5831bab 100644 --- a/protocoludp.h +++ b/protocoludp.h @@ -16,6 +16,7 @@ class cIptvProtocolUdp : public cIptvUdpSocket, public cIptvProtocolIf { private: char* streamAddr; char* sourceAddr; + int streamPort; public: cIptvProtocolUdp();