vdr-plugin-iptv/protocoludp.c

95 lines
2.3 KiB
C
Raw Permalink Normal View History

2007-09-14 17:44:25 +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>
#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"
#include "socket.h"
2007-09-14 17:44:25 +02:00
cIptvProtocolUdp::cIptvProtocolUdp()
: streamAddr(strdup("")),
2012-03-31 19:32:04 +02:00
streamPort(0)
2007-09-14 17:44:25 +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);
}
bool cIptvProtocolUdp::Open(void)
{
debug("cIptvProtocolUdp::Open(): streamAddr=%s\n", streamAddr);
OpenSocket(streamPort, inet_addr(streamAddr));
if (!isempty(streamAddr)) {
// Join a new multicast group
JoinMulticast();
}
2007-09-14 17:44:25 +02:00
return true;
}
bool cIptvProtocolUdp::Close(void)
{
debug("cIptvProtocolUdp::Close(): streamAddr=%s\n", streamAddr);
if (!isempty(streamAddr)) {
// Drop the multicast group
OpenSocket(streamPort, inet_addr(streamAddr));
DropMulticast();
}
2007-09-14 17:44:25 +02:00
// Close the socket
CloseSocket();
// Do NOT reset stream and source addresses
//streamAddr = strcpyrealloc(streamAddr, "");
2012-03-31 19:43:10 +02:00
//streamPort = 0;
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)
{
2009-02-26 15:04:12 +01:00
return cIptvUdpSocket::Read(BufferAddr, BufferLen);
}
bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int Index)
2007-09-14 17:44:25 +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)) {
// Drop the multicast group
if (!isempty(streamAddr)) {
OpenSocket(streamPort, inet_addr(streamAddr));
DropMulticast();
}
// Update stream address and port
streamAddr = strcpyrealloc(streamAddr, Location);
2012-03-31 19:32:04 +02:00
streamPort = Parameter;
// Join a new multicast group
if (!isempty(streamAddr)) {
OpenSocket(streamPort, inet_addr(streamAddr));
JoinMulticast();
}
}
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
}