2007-09-14 17:44:25 +02:00
|
|
|
/*
|
2007-09-26 21:49:35 +02:00
|
|
|
* protocoludp.c: IPTV plugin for the Video Disk Recorder
|
2007-09-14 17:44:25 +02:00
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2007-09-15 22:33:15 +02:00
|
|
|
#include <vdr/device.h>
|
|
|
|
|
2007-09-14 17:44:25 +02:00
|
|
|
#include "common.h"
|
2007-09-16 15:38:20 +02:00
|
|
|
#include "config.h"
|
2007-09-14 17:44:25 +02:00
|
|
|
#include "protocoludp.h"
|
2007-10-21 15:31:21 +02:00
|
|
|
#include "socket.h"
|
2007-09-14 17:44:25 +02:00
|
|
|
|
|
|
|
cIptvProtocolUdp::cIptvProtocolUdp()
|
2010-09-15 16:37:20 +02:00
|
|
|
: streamAddr(strdup("")),
|
2012-03-31 19:32:04 +02:00
|
|
|
sourceAddr(strdup("")),
|
|
|
|
streamPort(0)
|
2007-09-14 17:44:25 +02:00
|
|
|
{
|
2007-09-28 18:44:59 +02:00
|
|
|
debug("cIptvProtocolUdp::cIptvProtocolUdp()\n");
|
2007-09-14 17:44:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cIptvProtocolUdp::~cIptvProtocolUdp()
|
|
|
|
{
|
|
|
|
debug("cIptvProtocolUdp::~cIptvProtocolUdp()\n");
|
|
|
|
// Drop the multicast group and close the socket
|
2008-01-05 00:36:37 +01:00
|
|
|
cIptvProtocolUdp::Close();
|
2007-09-14 17:44:25 +02:00
|
|
|
// Free allocated memory
|
|
|
|
free(streamAddr);
|
2010-09-15 16:37:20 +02:00
|
|
|
free(sourceAddr);
|
2007-09-14 17:44:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cIptvProtocolUdp::Open(void)
|
|
|
|
{
|
2012-03-30 18:01:46 +02:00
|
|
|
debug("cIptvProtocolUdp::Open(): sourceAddr=%s streamAddr=%s\n", sourceAddr, streamAddr);
|
2012-03-31 19:32:04 +02:00
|
|
|
OpenSocket(streamPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr));
|
2010-09-15 17:18:46 +02:00
|
|
|
if (!isempty(streamAddr)) {
|
|
|
|
// Join a new multicast group
|
|
|
|
JoinMulticast(inet_addr(streamAddr));
|
|
|
|
}
|
2007-09-14 17:44:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cIptvProtocolUdp::Close(void)
|
|
|
|
{
|
2012-03-30 18:01:46 +02:00
|
|
|
debug("cIptvProtocolUdp::Close(): sourceAddr=%s streamAddr=%s\n", sourceAddr, streamAddr);
|
2010-09-15 17:18:46 +02:00
|
|
|
if (!isempty(streamAddr)) {
|
|
|
|
// Drop the multicast group
|
2012-03-31 19:32:04 +02:00
|
|
|
OpenSocket(streamPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr));
|
2010-09-15 17:18:46 +02:00
|
|
|
DropMulticast(inet_addr(streamAddr));
|
|
|
|
}
|
2007-09-14 17:44:25 +02:00
|
|
|
// Close the socket
|
|
|
|
CloseSocket();
|
2012-03-30 18:01:46 +02:00
|
|
|
// Do NOT reset stream and source addresses
|
|
|
|
//streamAddr = strcpyrealloc(streamAddr, "");
|
|
|
|
//sourceAddr = strcpyrealloc(sourceAddr, "");
|
2007-09-14 17:44:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-02-26 15:04:12 +01:00
|
|
|
int cIptvProtocolUdp::Read(unsigned char* BufferAddr, unsigned int BufferLen)
|
2007-10-21 19:32:43 +02:00
|
|
|
{
|
2009-02-26 15:04:12 +01:00
|
|
|
return cIptvUdpSocket::Read(BufferAddr, BufferLen);
|
2007-10-21 19:32:43 +02:00
|
|
|
}
|
|
|
|
|
2007-10-20 00:18:55 +02:00
|
|
|
bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int Index)
|
2007-09-14 17:44:25 +02:00
|
|
|
{
|
2007-10-20 00:18:55 +02:00
|
|
|
debug("cIptvProtocolUdp::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
|
2007-10-19 23:36:27 +02:00
|
|
|
if (!isempty(Location)) {
|
2010-09-15 16:37:20 +02:00
|
|
|
// Drop the multicast group
|
2010-09-15 17:18:46 +02:00
|
|
|
if (!isempty(streamAddr)) {
|
2012-03-31 19:32:04 +02:00
|
|
|
OpenSocket(streamPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr));
|
2010-09-15 17:18:46 +02:00
|
|
|
DropMulticast(inet_addr(streamAddr));
|
|
|
|
}
|
2010-09-15 16:37:20 +02:00
|
|
|
// Update stream address and port
|
|
|
|
streamAddr = strcpyrealloc(streamAddr, Location);
|
|
|
|
char *p = strstr(streamAddr, ";");
|
|
|
|
if (p) {
|
|
|
|
sourceAddr = strcpyrealloc(sourceAddr, p + 1);
|
|
|
|
*p = 0;
|
|
|
|
}
|
2010-11-29 17:27:39 +01:00
|
|
|
else
|
2010-09-15 16:37:20 +02:00
|
|
|
sourceAddr = strcpyrealloc(sourceAddr, "");
|
2012-03-31 19:32:04 +02:00
|
|
|
streamPort = Parameter;
|
2010-09-15 16:37:20 +02:00
|
|
|
// Join a new multicast group
|
2010-09-15 17:18:46 +02:00
|
|
|
if (!isempty(streamAddr)) {
|
2012-03-31 19:32:04 +02:00
|
|
|
OpenSocket(streamPort, isempty(sourceAddr) ? INADDR_ANY : inet_addr(sourceAddr));
|
2010-09-15 17:18:46 +02:00
|
|
|
JoinMulticast(inet_addr(streamAddr));
|
|
|
|
}
|
2010-09-15 16:37:20 +02:00
|
|
|
}
|
2007-09-14 17:44:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
2007-10-08 00:54:09 +02:00
|
|
|
|
|
|
|
cString cIptvProtocolUdp::GetInformation(void)
|
|
|
|
{
|
|
|
|
//debug("cIptvProtocolUdp::GetInformation()");
|
2012-03-31 19:32:04 +02:00
|
|
|
return cString::sprintf("udp://%s:%d", streamAddr, streamPort);
|
2007-10-08 00:54:09 +02:00
|
|
|
}
|