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

113 lines
3.0 KiB
C
Raw 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()
2013-02-23 14:31:11 +01:00
: isIGMPv3M(false),
sourceAddrM(strdup("")),
streamAddrM(strdup("")),
streamPortM(0)
2007-09-14 17:44:25 +02:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvProtocolUdp::%s()", __FUNCTION__);
2007-09-14 17:44:25 +02:00
}
cIptvProtocolUdp::~cIptvProtocolUdp()
{
2013-02-23 16:12:46 +01:00
debug("cIptvProtocolUdp::%s()", __FUNCTION__);
2007-09-14 17:44:25 +02:00
// 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
2013-02-23 14:31:11 +01:00
free(streamAddrM);
free(sourceAddrM);
2007-09-14 17:44:25 +02:00
}
bool cIptvProtocolUdp::Open(void)
{
2013-02-23 16:12:46 +01:00
debug("cIptvProtocolUdp::%s(%s)", __FUNCTION__, streamAddrM);
2013-02-23 14:31:11 +01:00
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
if (!isempty(streamAddrM)) {
// Join a new multicast group
JoinMulticast();
}
2007-09-14 17:44:25 +02:00
return true;
}
bool cIptvProtocolUdp::Close(void)
{
2013-02-23 16:12:46 +01:00
debug("cIptvProtocolUdp::%s(%s)", __FUNCTION__, streamAddrM);
2013-02-23 14:31:11 +01:00
if (!isempty(streamAddrM)) {
// Drop the multicast group
2013-02-23 14:31:11 +01:00
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
DropMulticast();
}
2007-09-14 17:44:25 +02:00
// Close the socket
CloseSocket();
// Do NOT reset stream and source addresses
2013-02-23 14:31:11 +01:00
//sourceAddrM = strcpyrealloc(sourceAddrM, "");
//streamAddrM = strcpyrealloc(streamAddrM, "");
//streamPortM = 0;
2007-09-14 17:44:25 +02:00
return true;
}
2013-02-23 14:31:11 +01:00
int cIptvProtocolUdp::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
{
2013-02-23 14:31:11 +01:00
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
2013-02-23 14:31:11 +01:00
bool cIptvProtocolUdp::Set(const char* locationP, const int parameterP, const int indexP)
2007-09-14 17:44:25 +02:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvProtocolUdp::%s(%s, %d, %d)", __FUNCTION__, locationP, parameterP, indexP);
2013-02-23 14:31:11 +01:00
if (!isempty(locationP)) {
// Drop the multicast group
2013-02-23 14:31:11 +01:00
if (!isempty(streamAddrM)) {
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
DropMulticast();
}
// Update stream address and port
2013-02-23 14:31:11 +01:00
streamAddrM = strcpyrealloc(streamAddrM, locationP);
// <group address> or <source address>@<group address>
2013-02-23 14:31:11 +01:00
char *p = strstr(streamAddrM, "@");
if (p) {
*p = 0;
2013-02-23 14:31:11 +01:00
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
streamAddrM = strcpyrealloc(streamAddrM, p + 1);
isIGMPv3M = true;
}
else {
2013-02-23 14:31:11 +01:00
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
isIGMPv3M = false;
}
2013-02-23 14:31:11 +01:00
streamPortM = parameterP;
// Join a new multicast group
2013-02-23 14:31:11 +01:00
if (!isempty(streamAddrM)) {
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
JoinMulticast();
}
}
2007-09-14 17:44:25 +02:00
return true;
}
2007-10-08 00:54:09 +02:00
cString cIptvProtocolUdp::GetInformation(void)
{
2013-02-23 16:12:46 +01:00
//debug("cIptvProtocolUdp::%s()", __FUNCTION__);
2013-02-23 14:31:11 +01:00
if (isIGMPv3M)
return cString::sprintf("udp://%s@%s:%d", sourceAddrM, streamAddrM, streamPortM);
return cString::sprintf("udp://%s:%d", streamAddrM, streamPortM);
2007-10-08 00:54:09 +02:00
}