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()
|
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)) {
|
2010-09-15 17:18:46 +02:00
|
|
|
// Join a new multicast group
|
2012-04-01 23:35:32 +02:00
|
|
|
JoinMulticast();
|
2010-09-15 17:18:46 +02:00
|
|
|
}
|
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)) {
|
2010-09-15 17:18:46 +02:00
|
|
|
// Drop the multicast group
|
2013-02-23 14:31:11 +01:00
|
|
|
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
|
2012-04-01 23:35:32 +02:00
|
|
|
DropMulticast();
|
2010-09-15 17:18:46 +02:00
|
|
|
}
|
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
|
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)
|
2007-10-21 19:32:43 +02:00
|
|
|
{
|
2013-02-23 14:31:11 +01:00
|
|
|
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
|
2007-10-21 19:32:43 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 18:22:02 +01:00
|
|
|
bool cIptvProtocolUdp::SetSource(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)) {
|
2010-09-15 16:37:20 +02:00
|
|
|
// Drop the multicast group
|
2013-02-23 14:31:11 +01:00
|
|
|
if (!isempty(streamAddrM)) {
|
|
|
|
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
|
2012-04-01 23:35:32 +02:00
|
|
|
DropMulticast();
|
2010-09-15 17:18:46 +02:00
|
|
|
}
|
2010-09-15 16:37:20 +02:00
|
|
|
// Update stream address and port
|
2013-02-23 14:31:11 +01:00
|
|
|
streamAddrM = strcpyrealloc(streamAddrM, locationP);
|
2012-09-30 17:42:40 +02:00
|
|
|
// <group address> or <source address>@<group address>
|
2013-02-23 14:31:11 +01:00
|
|
|
char *p = strstr(streamAddrM, "@");
|
2012-09-30 17:42:40 +02:00
|
|
|
if (p) {
|
|
|
|
*p = 0;
|
2013-02-23 14:31:11 +01:00
|
|
|
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
|
|
|
|
streamAddrM = strcpyrealloc(streamAddrM, p + 1);
|
|
|
|
isIGMPv3M = true;
|
2012-09-30 17:42:40 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-02-23 14:31:11 +01:00
|
|
|
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
|
|
|
|
isIGMPv3M = false;
|
2012-09-30 17:42:40 +02:00
|
|
|
}
|
2013-02-23 14:31:11 +01:00
|
|
|
streamPortM = parameterP;
|
2010-09-15 16:37:20 +02:00
|
|
|
// Join a new multicast group
|
2013-02-23 14:31:11 +01:00
|
|
|
if (!isempty(streamAddrM)) {
|
|
|
|
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
|
2012-04-01 23:35:32 +02:00
|
|
|
JoinMulticast();
|
2010-09-15 17:18:46 +02:00
|
|
|
}
|
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
|
|
|
|
2014-02-09 18:22:02 +01:00
|
|
|
bool cIptvProtocolUdp::SetPid(int pidP, int typeP, bool onP)
|
|
|
|
{
|
|
|
|
//debug("cIptvProtocolUdp::%s(%d, %d, %d)", __FUNCTION__, pidP, typeP, onP);
|
|
|
|
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
|
|
|
}
|