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

120 lines
3.1 KiB
C
Raw Normal View History

2007-09-14 15:44:25 +00:00
/*
* protocoludp.c: IPTV plugin for the Video Disk Recorder
2007-09-14 15:44:25 +00: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 15:44:25 +00:00
#include "common.h"
2007-09-16 13:38:20 +00:00
#include "config.h"
2015-03-08 14:33:18 +02:00
#include "log.h"
#include "socket.h"
2015-03-08 14:33:18 +02:00
#include "protocoludp.h"
2007-09-14 15:44:25 +00:00
cIptvProtocolUdp::cIptvProtocolUdp()
2013-02-23 15:31:11 +02:00
: isIGMPv3M(false),
sourceAddrM(strdup("")),
streamAddrM(strdup("")),
streamPortM(0)
2007-09-14 15:44:25 +00:00
{
2015-03-08 14:33:18 +02:00
debug1("%s", __PRETTY_FUNCTION__);
2007-09-14 15:44:25 +00:00
}
cIptvProtocolUdp::~cIptvProtocolUdp()
{
2015-03-08 14:33:18 +02:00
debug1("%s", __PRETTY_FUNCTION__);
2007-09-14 15:44:25 +00:00
// Drop the multicast group and close the socket
2008-01-04 23:36:37 +00:00
cIptvProtocolUdp::Close();
2007-09-14 15:44:25 +00:00
// Free allocated memory
2013-02-23 15:31:11 +02:00
free(streamAddrM);
free(sourceAddrM);
2007-09-14 15:44:25 +00:00
}
bool cIptvProtocolUdp::Open(void)
{
2015-03-08 14:33:18 +02:00
debug1("%s streamAddr='%s'", __PRETTY_FUNCTION__, streamAddrM);
2013-02-23 15:31:11 +02:00
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
if (!isempty(streamAddrM)) {
// Join a new multicast group
JoinMulticast();
}
2007-09-14 15:44:25 +00:00
return true;
}
bool cIptvProtocolUdp::Close(void)
{
2015-03-08 14:33:18 +02:00
debug1("%s streamAddr='%s'", __PRETTY_FUNCTION__, streamAddrM);
2013-02-23 15:31:11 +02:00
if (!isempty(streamAddrM)) {
// Drop the multicast group
2013-02-23 15:31:11 +02:00
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
DropMulticast();
}
2007-09-14 15:44:25 +00:00
// Close the socket
CloseSocket();
// Do NOT reset stream and source addresses
2013-02-23 15:31:11 +02:00
//sourceAddrM = strcpyrealloc(sourceAddrM, "");
//streamAddrM = strcpyrealloc(streamAddrM, "");
//streamPortM = 0;
2007-09-14 15:44:25 +00:00
return true;
}
2013-02-23 15:31:11 +02:00
int cIptvProtocolUdp::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
{
2013-02-23 15:31:11 +02:00
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
2014-02-09 19:22:02 +02:00
bool cIptvProtocolUdp::SetSource(const char* locationP, const int parameterP, const int indexP)
2007-09-14 15:44:25 +00:00
{
2015-03-08 14:33:18 +02:00
debug1("%s (%s, %d, %d)", __PRETTY_FUNCTION__, locationP, parameterP, indexP);
2013-02-23 15:31:11 +02:00
if (!isempty(locationP)) {
// Drop the multicast group
2013-02-23 15:31:11 +02:00
if (!isempty(streamAddrM)) {
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
DropMulticast();
}
// Update stream address and port
2013-02-23 15:31:11 +02:00
streamAddrM = strcpyrealloc(streamAddrM, locationP);
// <group address> or <source address>@<group address>
2013-02-23 15:31:11 +02:00
char *p = strstr(streamAddrM, "@");
if (p) {
*p = 0;
2013-02-23 15:31:11 +02:00
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
streamAddrM = strcpyrealloc(streamAddrM, p + 1);
isIGMPv3M = true;
}
else {
2013-02-23 15:31:11 +02:00
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
isIGMPv3M = false;
}
2013-02-23 15:31:11 +02:00
streamPortM = parameterP;
// Join a new multicast group
2013-02-23 15:31:11 +02:00
if (!isempty(streamAddrM)) {
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
JoinMulticast();
}
}
2007-09-14 15:44:25 +00:00
return true;
}
2007-10-07 22:54:09 +00:00
2014-02-09 19:22:02 +02:00
bool cIptvProtocolUdp::SetPid(int pidP, int typeP, bool onP)
{
2015-03-08 14:33:18 +02:00
debug16("%s (%d, %d, %d)", __PRETTY_FUNCTION__, pidP, typeP, onP);
2014-02-09 19:22:02 +02:00
return true;
}
2007-10-07 22:54:09 +00:00
cString cIptvProtocolUdp::GetInformation(void)
{
2015-03-08 14:33:18 +02:00
debug16("%s", __PRETTY_FUNCTION__);
2013-02-23 15:31:11 +02:00
if (isIGMPv3M)
return cString::sprintf("udp://%s@%s:%d", sourceAddrM, streamAddrM, streamPortM);
return cString::sprintf("udp://%s:%d", streamAddrM, streamPortM);
2007-10-07 22:54:09 +00:00
}