1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

More work on external protocol, this one can already launch external

scripts. "Channel" switching does not work at all.
This commit is contained in:
Antti Seppälä 2007-10-16 20:03:59 +00:00
parent 31b6264a54
commit d69901ffb6

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: protocolext.c,v 1.1 2007/10/15 20:06:38 ajhseppa Exp $ * $Id: protocolext.c,v 1.2 2007/10/16 20:03:59 ajhseppa Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -13,6 +13,7 @@
#include <unistd.h> #include <unistd.h>
#include <vdr/device.h> #include <vdr/device.h>
#include <vdr/plugin.h>
#include "common.h" #include "common.h"
#include "config.h" #include "config.h"
@ -48,12 +49,6 @@ cIptvProtocolExt::~cIptvProtocolExt()
bool cIptvProtocolExt::OpenSocket(const int Port) bool cIptvProtocolExt::OpenSocket(const int Port)
{ {
debug("cIptvProtocolExt::OpenSocket()\n"); debug("cIptvProtocolExt::OpenSocket()\n");
// If socket is there already and it is bound to a different port, it must
// be closed first
if (Port != listenPort) {
debug("cIptvProtocolExt::OpenSocket(): Socket tear-down\n");
CloseSocket();
}
// Bind to the socket if it is not active already // Bind to the socket if it is not active already
if (socketDesc < 0) { if (socketDesc < 0) {
int yes = 1; int yes = 1;
@ -82,7 +77,7 @@ bool cIptvProtocolExt::OpenSocket(const int Port)
// Bind socket // Bind socket
memset(&sockAddr, '\0', sizeof(sockAddr)); memset(&sockAddr, '\0', sizeof(sockAddr));
sockAddr.sin_family = AF_INET; sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons(Port); sockAddr.sin_port = htons(listenPort);
sockAddr.sin_addr.s_addr = htonl(INADDR_ANY); sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
int err = bind(socketDesc, (struct sockaddr *)&sockAddr, sizeof(sockAddr)); int err = bind(socketDesc, (struct sockaddr *)&sockAddr, sizeof(sockAddr));
if (err < 0) { if (err < 0) {
@ -91,8 +86,6 @@ bool cIptvProtocolExt::OpenSocket(const int Port)
CloseSocket(); CloseSocket();
return false; return false;
} }
// Update stream port
streamPort = Port;
} }
return true; return true;
} }
@ -174,14 +167,22 @@ bool cIptvProtocolExt::Open(void)
{ {
debug("cIptvProtocolExt::Open(): streamAddr=%s\n", streamAddr); debug("cIptvProtocolExt::Open(): streamAddr=%s\n", streamAddr);
// Here process execution is forked to prepare for script execution // Reject completely empty stream addresses
// pid_t PID = fork(); if (!strlen(streamAddr))
return false;
// Now run the script with the forked process // Create the listening socket
// if (pid != 0) OpenSocket(streamPort);
// execve(...) if (!isActive) {
char* cmd = NULL;
return true; asprintf(&cmd, "%s/%s start", cPlugin::ConfigDirectory("iptv"),
streamAddr);
int retval = SystemExec(cmd);
free(cmd);
if (!retval)
isActive = true;
}
return isActive;
} }
bool cIptvProtocolExt::Close(void) bool cIptvProtocolExt::Close(void)
@ -189,14 +190,17 @@ bool cIptvProtocolExt::Close(void)
debug("cIptvProtocolExt::Close(): streamAddr=%s\n", streamAddr); debug("cIptvProtocolExt::Close(): streamAddr=%s\n", streamAddr);
// Close the socket // Close the socket
CloseSocket(); CloseSocket();
if (isActive) {
char* cmd = NULL;
asprintf(&cmd, "%s/%s stop",
cPlugin::ConfigDirectory("iptv"), streamAddr);
int retval = SystemExec(cmd);
free(cmd);
if (!retval)
isActive = false;
}
// Now the executed process should be terminated if it still exists return !isActive;
// exit();
// Wait for child termination
// wait();
return true;
} }
bool cIptvProtocolExt::Set(const char* Address, const int Port) bool cIptvProtocolExt::Set(const char* Address, const int Port)
@ -207,6 +211,10 @@ bool cIptvProtocolExt::Set(const char* Address, const int Port)
streamAddr = strcpyrealloc(streamAddr, Address); streamAddr = strcpyrealloc(streamAddr, Address);
streamPort = Port; streamPort = Port;
} }
#if 0 // Are these needed or not?
Close();
Open();
#endif
return true; return true;
} }