Added preliminary RTP protocol support.

This commit is contained in:
Rolf Ahrenberg 2007-09-26 19:49:35 +00:00
parent c03e69a64f
commit 0177f03089
15 changed files with 343 additions and 40 deletions

View File

@ -1,7 +1,7 @@
# #
# Makefile for a Video Disk Recorder plugin # Makefile for a Video Disk Recorder plugin
# #
# $Id: Makefile,v 1.8 2007/09/24 13:03:38 ajhseppa Exp $ # $Id: Makefile,v 1.9 2007/09/26 19:49:35 rahrenbe Exp $
# Debugging on/off # Debugging on/off
#IPTV_DEBUG = 1 #IPTV_DEBUG = 1
@ -57,7 +57,8 @@ endif
### The object files (add further files here): ### The object files (add further files here):
OBJS = $(PLUGIN).o config.o setup.o device.o streamer.o protocoludp.o protocolhttp.o protocolfile.o sectionfilter.o OBJS = $(PLUGIN).o config.o setup.o device.o streamer.o protocoludp.o protocolrtp.o \
protocolhttp.o protocolfile.o sectionfilter.o
### The main target: ### The main target:

3
README
View File

@ -38,11 +38,12 @@ make plugins
Channels.conf examples: Channels.conf examples:
TV1;IPTV:1:IPTV|UDP|127.0.0.1|1234:P:0:512:650:2321:0:1:0:0:0 TV1;IPTV:1:IPTV|UDP|127.0.0.1|1234:P:0:512:650:2321:0:1:0:0:0
TV1;IPTV:1:IPTV|RTP|127.0.0.1|1234:P:0:512:650:2321:0:1:0:0:0
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
| | | | | Source type ("P") | | | | | Source type ("P")
| | | | IP Port Number | | | | IP Port Number
| | | IP Address or File Location | | | IP Address or File Location
| | Protocol ("UDP", "HTTP", "FILE") | | Protocol ("UDP", "RTP", "HTTP", "FILE")
| Plugin ID ("IPTV") | Plugin ID ("IPTV")
Unique enumeration Unique enumeration

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: config.c,v 1.4 2007/09/20 21:45:51 rahrenbe Exp $ * $Id: config.c,v 1.5 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#include "common.h" #include "common.h"
@ -15,6 +15,7 @@ cIptvConfig::cIptvConfig(void)
: tsBufferSize(8), : tsBufferSize(8),
tsBufferPrefillRatio(0), tsBufferPrefillRatio(0),
udpBufferSize(7), udpBufferSize(7),
rtpBufferSize(7),
httpBufferSize(7), httpBufferSize(7),
fileBufferSize(20), fileBufferSize(20),
maxBufferSize(40) // must be bigger than protocol buffer sizes! maxBufferSize(40) // must be bigger than protocol buffer sizes!

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: config.h,v 1.4 2007/09/20 21:45:51 rahrenbe Exp $ * $Id: config.h,v 1.5 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#ifndef __IPTV_CONFIG_H #ifndef __IPTV_CONFIG_H
@ -18,6 +18,7 @@ protected:
unsigned int tsBufferSize; unsigned int tsBufferSize;
unsigned int tsBufferPrefillRatio; unsigned int tsBufferPrefillRatio;
unsigned int udpBufferSize; unsigned int udpBufferSize;
unsigned int rtpBufferSize;
unsigned int httpBufferSize; unsigned int httpBufferSize;
unsigned int fileBufferSize; unsigned int fileBufferSize;
unsigned int maxBufferSize; unsigned int maxBufferSize;
@ -26,12 +27,14 @@ public:
unsigned int GetTsBufferSize(void) { return tsBufferSize; } unsigned int GetTsBufferSize(void) { return tsBufferSize; }
unsigned int GetTsBufferPrefillRatio(void) { return tsBufferPrefillRatio; } unsigned int GetTsBufferPrefillRatio(void) { return tsBufferPrefillRatio; }
unsigned int GetUdpBufferSize(void) { return udpBufferSize; } unsigned int GetUdpBufferSize(void) { return udpBufferSize; }
unsigned int GetRtpBufferSize(void) { return rtpBufferSize; }
unsigned int GetHttpBufferSize(void) { return httpBufferSize; } unsigned int GetHttpBufferSize(void) { return httpBufferSize; }
unsigned int GetFileBufferSize(void) { return fileBufferSize; } unsigned int GetFileBufferSize(void) { return fileBufferSize; }
unsigned int GetMaxBufferSize(void) { return maxBufferSize; } unsigned int GetMaxBufferSize(void) { return maxBufferSize; }
void SetTsBufferSize(unsigned int Size) { tsBufferSize = Size; } void SetTsBufferSize(unsigned int Size) { tsBufferSize = Size; }
void SetTsBufferPrefillRatio(unsigned int Ratio) { tsBufferPrefillRatio = Ratio; } void SetTsBufferPrefillRatio(unsigned int Ratio) { tsBufferPrefillRatio = Ratio; }
void SetUdpBufferSize(unsigned int Size) { udpBufferSize = Size; } void SetUdpBufferSize(unsigned int Size) { udpBufferSize = Size; }
void SetRtpBufferSize(unsigned int Size) { rtpBufferSize = Size; }
void SetHttpBufferSize(unsigned int Size) { httpBufferSize = Size; } void SetHttpBufferSize(unsigned int Size) { httpBufferSize = Size; }
void SetFileBufferSize(unsigned int Size) { fileBufferSize = Size; } void SetFileBufferSize(unsigned int Size) { fileBufferSize = Size; }
}; };

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: device.c,v 1.40 2007/09/24 21:25:53 rahrenbe Exp $ * $Id: device.c,v 1.41 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#include "common.h" #include "common.h"
@ -29,6 +29,7 @@ cIptvDevice::cIptvDevice(unsigned int Index)
tsBuffer->SetTimeouts(100, 100); tsBuffer->SetTimeouts(100, 100);
ResetBuffering(); ResetBuffering();
pUdpProtocol = new cIptvProtocolUdp(); pUdpProtocol = new cIptvProtocolUdp();
pRtpProtocol = new cIptvProtocolRtp();
pHttpProtocol = new cIptvProtocolHttp(); pHttpProtocol = new cIptvProtocolHttp();
pFileProtocol = new cIptvProtocolFile(); pFileProtocol = new cIptvProtocolFile();
pIptvStreamer = new cIptvStreamer(tsBuffer, &mutex); pIptvStreamer = new cIptvStreamer(tsBuffer, &mutex);
@ -86,6 +87,11 @@ cString cIptvDevice::GetChannelSettings(const char *Param, int *IpPort, cIptvPro
*Protocol = pUdpProtocol; *Protocol = pUdpProtocol;
return addr; return addr;
} }
else if (sscanf(Param, "IPTV|RTP|%a[^|]|%u", &loc, IpPort) == 2) {
cString addr(loc, true);
*Protocol = pRtpProtocol;
return addr;
}
else if (sscanf(Param, "IPTV|HTTP|%a[^|]|%u", &loc, IpPort) == 2) { else if (sscanf(Param, "IPTV|HTTP|%a[^|]|%u", &loc, IpPort) == 2) {
cString addr(loc, true); cString addr(loc, true);
*Protocol = pHttpProtocol; *Protocol = pHttpProtocol;

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: device.h,v 1.17 2007/09/24 17:20:58 rahrenbe Exp $ * $Id: device.h,v 1.18 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#ifndef __IPTV_DEVICE_H #ifndef __IPTV_DEVICE_H
@ -11,6 +11,7 @@
#include <vdr/device.h> #include <vdr/device.h>
#include "protocoludp.h" #include "protocoludp.h"
#include "protocolrtp.h"
#include "protocolhttp.h" #include "protocolhttp.h"
#include "protocolfile.h" #include "protocolfile.h"
#include "streamer.h" #include "streamer.h"
@ -35,6 +36,7 @@ private:
cRingBufferLinear *tsBuffer; cRingBufferLinear *tsBuffer;
int tsBufferPrefill; int tsBufferPrefill;
cIptvProtocolUdp *pUdpProtocol; cIptvProtocolUdp *pUdpProtocol;
cIptvProtocolRtp *pRtpProtocol;
cIptvProtocolHttp *pHttpProtocol; cIptvProtocolHttp *pHttpProtocol;
cIptvProtocolFile *pFileProtocol; cIptvProtocolFile *pFileProtocol;
cIptvStreamer *pIptvStreamer; cIptvStreamer *pIptvStreamer;

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: VDR 1.5.7\n" "Project-Id-Version: VDR 1.5.7\n"
"Report-Msgid-Bugs-To: Rolf Ahrenberg\n" "Report-Msgid-Bugs-To: Rolf Ahrenberg\n"
"POT-Creation-Date: 2007-09-19 19:49+0300\n" "POT-Creation-Date: 2007-09-26 20:00+0300\n"
"PO-Revision-Date: 2007-08-12 23:22+0300\n" "PO-Revision-Date: 2007-08-12 23:22+0300\n"
"Last-Translator: Rolf Ahrenberg\n" "Last-Translator: Rolf Ahrenberg\n"
"Language-Team: <vdr@linuxtv.org>\n" "Language-Team: <vdr@linuxtv.org>\n"
@ -19,50 +19,58 @@ msgstr ""
msgid "Experiment the IPTV" msgid "Experiment the IPTV"
msgstr "Koe IPTV:n ihmeellinen maailma" msgstr "Koe IPTV:n ihmeellinen maailma"
#: setup.c:53 #: setup.c:54
msgid "UDP" msgid "UDP"
msgstr "UDP" msgstr "UDP"
#: setup.c:54 #: setup.c:55
msgid "RTP"
msgstr "RTP"
#: setup.c:56
msgid "HTTP" msgid "HTTP"
msgstr "HTTP" msgstr "HTTP"
#: setup.c:55 #: setup.c:57
msgid "FILE" msgid "FILE"
msgstr "FILE" msgstr "FILE"
#: setup.c:170 #: setup.c:180
msgid "Protocol" msgid "Protocol"
msgstr "Protokolla" msgstr "Protokolla"
#: setup.c:178 #: setup.c:188
msgid "Address" msgid "Address"
msgstr "Osoite" msgstr "Osoite"
#: setup.c:179 #: setup.c:189
msgid "Port" msgid "Port"
msgstr "Portti" msgstr "Portti"
#: setup.c:296 #: setup.c:307
msgid "IPTV Channels" msgid "IPTV Channels"
msgstr "IPTV-kanavat" msgstr "IPTV-kanavat"
#: setup.c:432 #: setup.c:444
msgid "TS buffer size [MB]" msgid "TS buffer size [MB]"
msgstr "TS-puskurin koko [MB]" msgstr "TS-puskurin koko [MB]"
#: setup.c:433 #: setup.c:445
msgid "TS buffer prefill ratio [%]" msgid "TS buffer prefill ratio [%]"
msgstr "TS-puskurin esitäyttöaste [%]" msgstr "TS-puskurin esitäyttöaste [%]"
#: setup.c:434 #: setup.c:446
msgid "UDP buffer size [packets]" msgid "UDP buffer size [packets]"
msgstr "UDP-puskurin koko [pakettia]" msgstr "UDP-puskurin koko [pakettia]"
#: setup.c:435 #: setup.c:447
msgid "RTP buffer size [packets]"
msgstr "RTP-puskurin koko [pakettia]"
#: setup.c:448
msgid "HTTP buffer size [packets]" msgid "HTTP buffer size [packets]"
msgstr "HTTP-puskurin koko [pakettia]" msgstr "HTTP-puskurin koko [pakettia]"
#: setup.c:436 #: setup.c:449
msgid "FILE buffer size [packets]" msgid "FILE buffer size [packets]"
msgstr "FILE-puskurin koko [pakettia]" msgstr "FILE-puskurin koko [pakettia]"

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: protocolhttp.c,v 1.4 2007/09/20 21:45:51 rahrenbe Exp $ * $Id: protocolhttp.c,v 1.5 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -20,9 +20,9 @@
#include "protocolhttp.h" #include "protocolhttp.h"
cIptvProtocolHttp::cIptvProtocolHttp() cIptvProtocolHttp::cIptvProtocolHttp()
: streamPort(1234), : streamPort(3000),
socketDesc(-1), socketDesc(-1),
unicastActive(false) isActive(false)
{ {
debug("cIptvProtocolHttp::cIptvProtocolHttp(): %d/%d packets\n", debug("cIptvProtocolHttp::cIptvProtocolHttp(): %d/%d packets\n",
IptvConfig.GetHttpBufferSize(), IptvConfig.GetMaxBufferSize()); IptvConfig.GetHttpBufferSize(), IptvConfig.GetMaxBufferSize());
@ -108,7 +108,7 @@ bool cIptvProtocolHttp::Connect(void)
{ {
debug("cIptvProtocolHttp::Connect()\n"); debug("cIptvProtocolHttp::Connect()\n");
// Check that stream address is valid // Check that stream address is valid
if (!unicastActive && !isempty(streamAddr) && !isempty(streamPath)) { if (!isActive && !isempty(streamAddr) && !isempty(streamPath)) {
// Ensure that socket is valid // Ensure that socket is valid
OpenSocket(streamPort); OpenSocket(streamPort);
@ -195,7 +195,7 @@ bool cIptvProtocolHttp::Connect(void)
// connection should be re-located etc. // connection should be re-located etc.
// Update active flag // Update active flag
unicastActive = true; isActive = true;
} }
return true; return true;
} }
@ -204,11 +204,11 @@ bool cIptvProtocolHttp::Disconnect(void)
{ {
debug("cIptvProtocolHttp::Disconnect()\n"); debug("cIptvProtocolHttp::Disconnect()\n");
// Check that stream address is valid // Check that stream address is valid
if (unicastActive) { if (isActive) {
// Close the socket // Close the socket
CloseSocket(); CloseSocket();
// Update active flag // Update active flag
unicastActive = false; isActive = false;
} }
return true; return true;
} }

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: protocolhttp.h,v 1.3 2007/09/20 21:45:51 rahrenbe Exp $ * $Id: protocolhttp.h,v 1.4 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#ifndef __IPTV_PROTOCOLHTTP_H #ifndef __IPTV_PROTOCOLHTTP_H
@ -20,7 +20,7 @@ private:
int socketDesc; int socketDesc;
unsigned char* readBuffer; unsigned char* readBuffer;
struct sockaddr_in sockAddr; struct sockaddr_in sockAddr;
bool unicastActive; bool isActive;
private: private:
bool OpenSocket(const int Port); bool OpenSocket(const int Port);

225
protocolrtp.c Normal file
View File

@ -0,0 +1,225 @@
/*
* protocolrtp.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: protocolrtp.c,v 1.1 2007/09/26 19:49:35 rahrenbe Exp $
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
#include <vdr/device.h>
#include "common.h"
#include "config.h"
#include "protocolrtp.h"
cIptvProtocolRtp::cIptvProtocolRtp()
: streamPort(1234),
socketDesc(-1),
isActive(false)
{
debug("cIptvProtocolRtp::cIptvProtocolRtp(): %d/%d packets\n",
IptvConfig.GetRtpBufferSize(), IptvConfig.GetMaxBufferSize());
streamAddr = strdup("");
// Allocate receive buffer
readBuffer = MALLOC(unsigned char, (TS_SIZE * IptvConfig.GetMaxBufferSize()));
if (!readBuffer)
error("ERROR: MALLOC() failed in ProtocolRtp()");
}
cIptvProtocolRtp::~cIptvProtocolRtp()
{
debug("cIptvProtocolRtp::~cIptvProtocolRtp()\n");
// Drop the multicast group and close the socket
Close();
// Free allocated memory
free(streamAddr);
free(readBuffer);
}
bool cIptvProtocolRtp::OpenSocket(const int Port)
{
debug("cIptvProtocolRtp::OpenSocket()\n");
// If socket is there already and it is bound to a different port, it must
// be closed first
if (Port != streamPort) {
debug("cIptvProtocolRtp::OpenSocket(): Socket tear-down\n");
CloseSocket();
}
// Bind to the socket if it is not active already
if (socketDesc < 0) {
int yes = 1;
// Create socket
socketDesc = socket(PF_INET, SOCK_DGRAM, 0);
if (socketDesc < 0) {
char tmp[64];
error("ERROR: socket(): %s", strerror_r(errno, tmp, sizeof(tmp)));
return false;
}
// Make it use non-blocking I/O to avoid stuck read calls
if (fcntl(socketDesc, F_SETFL, O_NONBLOCK)) {
char tmp[64];
error("ERROR: fcntl(): %s", strerror_r(errno, tmp, sizeof(tmp)));
CloseSocket();
return false;
}
// Allow multiple sockets to use the same PORT number
if (setsockopt(socketDesc, SOL_SOCKET, SO_REUSEADDR, &yes,
sizeof(yes)) < 0) {
char tmp[64];
error("ERROR: setsockopt(): %s", strerror_r(errno, tmp, sizeof(tmp)));
CloseSocket();
return false;
}
// Bind socket
memset(&sockAddr, '\0', sizeof(sockAddr));
sockAddr.sin_family = AF_INET;
sockAddr.sin_port = htons(Port);
sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
int err = bind(socketDesc, (struct sockaddr *)&sockAddr, sizeof(sockAddr));
if (err < 0) {
char tmp[64];
error("ERROR: bind(): %s", strerror_r(errno, tmp, sizeof(tmp)));
CloseSocket();
return false;
}
// Update stream port
streamPort = Port;
}
return true;
}
void cIptvProtocolRtp::CloseSocket(void)
{
debug("cIptvProtocolRtp::CloseSocket()\n");
// Check if socket exists
if (socketDesc >= 0) {
close(socketDesc);
socketDesc = -1;
}
}
bool cIptvProtocolRtp::JoinMulticast(void)
{
debug("cIptvProtocolRtp::JoinMulticast()\n");
// Check that stream address is valid
if (!isActive && !isempty(streamAddr)) {
// Ensure that socket is valid
OpenSocket(streamPort);
// Join a new multicast group
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr(streamAddr);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
int err = setsockopt(socketDesc, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
sizeof(mreq));
if (err < 0) {
char tmp[64];
error("ERROR: setsockopt(): %s", strerror_r(errno, tmp, sizeof(tmp)));
return false;
}
// Update multicasting flag
isActive = true;
}
return true;
}
bool cIptvProtocolRtp::DropMulticast(void)
{
debug("cIptvProtocolRtp::DropMulticast()\n");
// Check that stream address is valid
if (isActive && !isempty(streamAddr)) {
// Ensure that socket is valid
OpenSocket(streamPort);
// Drop the multicast group
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr(streamAddr);
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
int err = setsockopt(socketDesc, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq,
sizeof(mreq));
if (err < 0) {
char tmp[64];
error("ERROR: setsockopt(): %s", strerror_r(errno, tmp, sizeof(tmp)));
return false;
}
// Update multicasting flag
isActive = false;
}
return true;
}
int cIptvProtocolRtp::Read(unsigned char* *BufferAddr)
{
//debug("cIptvProtocolRtp::Read()\n");
socklen_t addrlen = sizeof(sockAddr);
// Wait for data
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 500000;
// Use select
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(socketDesc, &rfds);
int retval = select(socketDesc + 1, &rfds, NULL, NULL, &tv);
// Check if error
if (retval < 0) {
char tmp[64];
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
return -1;
}
// Check if data available
else if (retval) {
// Read data from socket
int len = recvfrom(socketDesc, readBuffer, (TS_SIZE * IptvConfig.GetRtpBufferSize()),
MSG_DONTWAIT, (struct sockaddr *)&sockAddr, &addrlen);
if (len > 0) {
// http://www.networksorcery.com/enp/rfc/rfc2250.txt
const unsigned int headerlen = 4 * sizeof(uint32_t);
uint8_t *header = readBuffer + sizeof(uint8_t);
// Check if payload type is MPEG2 TS and payload contains multiple of TS packet data
if (((*header & 0x7F) == 33) && (((len - headerlen) % TS_SIZE) == 0)) {
// Set argument point to payload in read buffer
*BufferAddr = readBuffer + headerlen;
return (len - headerlen);
}
}
}
return 0;
}
bool cIptvProtocolRtp::Open(void)
{
debug("cIptvProtocolRtp::Open(): streamAddr=%s\n", streamAddr);
// Join a new multicast group
JoinMulticast();
return true;
}
bool cIptvProtocolRtp::Close(void)
{
debug("cIptvProtocolRtp::Close(): streamAddr=%s\n", streamAddr);
// Drop the multicast group
DropMulticast();
// Close the socket
CloseSocket();
return true;
}
bool cIptvProtocolRtp::Set(const char* Address, const int Port)
{
debug("cIptvProtocolRtp::Set(): %s:%d\n", Address, Port);
if (!isempty(Address)) {
// Drop the multicast group
DropMulticast();
// Update stream address and port
streamAddr = strcpyrealloc(streamAddr, Address);
streamPort = Port;
// Join a new multicast group
JoinMulticast();
}
return true;
}

40
protocolrtp.h Normal file
View File

@ -0,0 +1,40 @@
/*
* protocolrtp.h: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: protocolrtp.h,v 1.1 2007/09/26 19:49:35 rahrenbe Exp $
*/
#ifndef __IPTV_PROTOCOLRTP_H
#define __IPTV_PROTOCOLRTP_H
#include <arpa/inet.h>
#include "protocolif.h"
class cIptvProtocolRtp : public cIptvProtocolIf {
private:
char* streamAddr;
int streamPort;
int socketDesc;
unsigned char* readBuffer;
struct sockaddr_in sockAddr;
bool isActive;
private:
bool OpenSocket(const int Port);
void CloseSocket(void);
bool JoinMulticast(void);
bool DropMulticast(void);
public:
cIptvProtocolRtp();
virtual ~cIptvProtocolRtp();
virtual int Read(unsigned char* *BufferAddr);
virtual bool Set(const char* Address, const int Port);
virtual bool Open(void);
virtual bool Close(void);
};
#endif // __IPTV_PROTOCOLRTP_H

View File

@ -1,9 +1,9 @@
/* /*
* streamer.c: IPTV plugin for the Video Disk Recorder * protocoludp.c: IPTV plugin for the Video Disk Recorder
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: protocoludp.c,v 1.6 2007/09/20 21:45:51 rahrenbe Exp $ * $Id: protocoludp.c,v 1.7 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -21,7 +21,7 @@
cIptvProtocolUdp::cIptvProtocolUdp() cIptvProtocolUdp::cIptvProtocolUdp()
: streamPort(1234), : streamPort(1234),
socketDesc(-1), socketDesc(-1),
mcastActive(false) isActive(false)
{ {
debug("cIptvProtocolUdp::cIptvProtocolUdp(): %d/%d packets\n", debug("cIptvProtocolUdp::cIptvProtocolUdp(): %d/%d packets\n",
IptvConfig.GetUdpBufferSize(), IptvConfig.GetMaxBufferSize()); IptvConfig.GetUdpBufferSize(), IptvConfig.GetMaxBufferSize());
@ -108,7 +108,7 @@ bool cIptvProtocolUdp::JoinMulticast(void)
{ {
debug("cIptvProtocolUdp::JoinMulticast()\n"); debug("cIptvProtocolUdp::JoinMulticast()\n");
// Check that stream address is valid // Check that stream address is valid
if (!mcastActive && !isempty(streamAddr)) { if (!isActive && !isempty(streamAddr)) {
// Ensure that socket is valid // Ensure that socket is valid
OpenSocket(streamPort); OpenSocket(streamPort);
// Join a new multicast group // Join a new multicast group
@ -123,7 +123,7 @@ bool cIptvProtocolUdp::JoinMulticast(void)
return false; return false;
} }
// Update multicasting flag // Update multicasting flag
mcastActive = true; isActive = true;
} }
return true; return true;
} }
@ -132,7 +132,7 @@ bool cIptvProtocolUdp::DropMulticast(void)
{ {
debug("cIptvProtocolUdp::DropMulticast()\n"); debug("cIptvProtocolUdp::DropMulticast()\n");
// Check that stream address is valid // Check that stream address is valid
if (mcastActive && !isempty(streamAddr)) { if (isActive && !isempty(streamAddr)) {
// Ensure that socket is valid // Ensure that socket is valid
OpenSocket(streamPort); OpenSocket(streamPort);
// Drop the multicast group // Drop the multicast group
@ -147,7 +147,7 @@ bool cIptvProtocolUdp::DropMulticast(void)
return false; return false;
} }
// Update multicasting flag // Update multicasting flag
mcastActive = false; isActive = false;
} }
return true; return true;
} }

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: protocoludp.h,v 1.4 2007/09/20 21:45:51 rahrenbe Exp $ * $Id: protocoludp.h,v 1.5 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#ifndef __IPTV_PROTOCOLUDP_H #ifndef __IPTV_PROTOCOLUDP_H
@ -19,7 +19,7 @@ private:
int socketDesc; int socketDesc;
unsigned char* readBuffer; unsigned char* readBuffer;
struct sockaddr_in sockAddr; struct sockaddr_in sockAddr;
bool mcastActive; bool isActive;
private: private:
bool OpenSocket(const int Port); bool OpenSocket(const int Port);

17
setup.c
View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: setup.c,v 1.8 2007/09/20 21:45:51 rahrenbe Exp $ * $Id: setup.c,v 1.9 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#include <string.h> #include <string.h>
@ -26,6 +26,7 @@ class cIptvMenuEditChannel : public cOsdMenu
private: private:
enum { enum {
eProtocolUDP, eProtocolUDP,
eProtocolRTP,
eProtocolHTTP, eProtocolHTTP,
eProtocolFILE, eProtocolFILE,
eProtocolCount eProtocolCount
@ -51,6 +52,7 @@ cIptvMenuEditChannel::cIptvMenuEditChannel(cChannel *Channel, bool New)
:cOsdMenu(trVDR("Edit channel"), 16) :cOsdMenu(trVDR("Edit channel"), 16)
{ {
protocols[eProtocolUDP] = tr("UDP"); protocols[eProtocolUDP] = tr("UDP");
protocols[eProtocolRTP] = tr("RTP");
protocols[eProtocolHTTP] = tr("HTTP"); protocols[eProtocolHTTP] = tr("HTTP");
protocols[eProtocolFILE] = tr("FILE"); protocols[eProtocolFILE] = tr("FILE");
channel = Channel; channel = Channel;
@ -72,6 +74,11 @@ cString cIptvMenuEditChannel::GetIptvSettings(const char *Param, int *Port, int
*Protocol = eProtocolUDP; *Protocol = eProtocolUDP;
return addr; return addr;
} }
else if (sscanf(Param, "IPTV|RTP|%a[^|]|%u", &loc, Port) == 2) {
cString addr(loc, true);
*Protocol = eProtocolRTP;
return addr;
}
else if (sscanf(Param, "IPTV|HTTP|%a[^|]|%u", &loc, Port) == 2) { else if (sscanf(Param, "IPTV|HTTP|%a[^|]|%u", &loc, Port) == 2) {
cString addr(loc, true); cString addr(loc, true);
*Protocol = eProtocolHTTP; *Protocol = eProtocolHTTP;
@ -149,6 +156,9 @@ void cIptvMenuEditChannel::SetChannelData(cChannel *Channel)
case eProtocolHTTP: case eProtocolHTTP:
param = cString::sprintf("IPTV|HTTP|%s|%d", data.location, data.port); param = cString::sprintf("IPTV|HTTP|%s|%d", data.location, data.port);
break; break;
case eProtocolRTP:
param = cString::sprintf("IPTV|RTP|%s|%d", data.location, data.port);
break;
default: default:
case eProtocolUDP: case eProtocolUDP:
param = cString::sprintf("IPTV|UDP|%s|%d", data.location, data.port); param = cString::sprintf("IPTV|UDP|%s|%d", data.location, data.port);
@ -236,6 +246,7 @@ eOSState cIptvMenuEditChannel::ProcessKey(eKeys Key)
data.port = 3000; data.port = 3000;
break; break;
default: default:
case eProtocolRTP:
case eProtocolUDP: case eProtocolUDP:
strn0cpy(data.location, "127.0.0.1", sizeof(data.location)); strn0cpy(data.location, "127.0.0.1", sizeof(data.location));
data.port = 1234; data.port = 1234;
@ -419,6 +430,7 @@ cIptvPluginSetup::cIptvPluginSetup()
tsBufferSize = IptvConfig.GetTsBufferSize(); tsBufferSize = IptvConfig.GetTsBufferSize();
tsBufferPrefill = IptvConfig.GetTsBufferPrefillRatio(); tsBufferPrefill = IptvConfig.GetTsBufferPrefillRatio();
udpBufferSize = IptvConfig.GetUdpBufferSize(); udpBufferSize = IptvConfig.GetUdpBufferSize();
rtpBufferSize = IptvConfig.GetRtpBufferSize();
httpBufferSize = IptvConfig.GetHttpBufferSize(); httpBufferSize = IptvConfig.GetHttpBufferSize();
fileBufferSize = IptvConfig.GetFileBufferSize(); fileBufferSize = IptvConfig.GetFileBufferSize();
Setup(); Setup();
@ -432,6 +444,7 @@ void cIptvPluginSetup::Setup(void)
Add(new cMenuEditIntItem(tr("TS buffer size [MB]"), &tsBufferSize, 2, 16)); Add(new cMenuEditIntItem(tr("TS buffer size [MB]"), &tsBufferSize, 2, 16));
Add(new cMenuEditIntItem(tr("TS buffer prefill ratio [%]"), &tsBufferPrefill, 0, 40)); Add(new cMenuEditIntItem(tr("TS buffer prefill ratio [%]"), &tsBufferPrefill, 0, 40));
Add(new cMenuEditIntItem(tr("UDP buffer size [packets]"), &udpBufferSize, 1, IptvConfig.GetMaxBufferSize())); Add(new cMenuEditIntItem(tr("UDP buffer size [packets]"), &udpBufferSize, 1, IptvConfig.GetMaxBufferSize()));
Add(new cMenuEditIntItem(tr("RTP buffer size [packets]"), &rtpBufferSize, 1, IptvConfig.GetMaxBufferSize()));
Add(new cMenuEditIntItem(tr("HTTP buffer size [packets]"), &httpBufferSize, 1, IptvConfig.GetMaxBufferSize())); Add(new cMenuEditIntItem(tr("HTTP buffer size [packets]"), &httpBufferSize, 1, IptvConfig.GetMaxBufferSize()));
Add(new cMenuEditIntItem(tr("FILE buffer size [packets]"), &fileBufferSize, 1, IptvConfig.GetMaxBufferSize())); Add(new cMenuEditIntItem(tr("FILE buffer size [packets]"), &fileBufferSize, 1, IptvConfig.GetMaxBufferSize()));
SetCurrent(Get(current)); SetCurrent(Get(current));
@ -463,12 +476,14 @@ void cIptvPluginSetup::Store(void)
SetupStore("TsBufferSize", tsBufferSize); SetupStore("TsBufferSize", tsBufferSize);
SetupStore("TsBufferPrefill", tsBufferPrefill); SetupStore("TsBufferPrefill", tsBufferPrefill);
SetupStore("UdpBufferSize", udpBufferSize); SetupStore("UdpBufferSize", udpBufferSize);
SetupStore("RtpBufferSize", rtpBufferSize);
SetupStore("HttpBufferSize", httpBufferSize); SetupStore("HttpBufferSize", httpBufferSize);
SetupStore("FileBufferSize", fileBufferSize); SetupStore("FileBufferSize", fileBufferSize);
// Update global config // Update global config
IptvConfig.SetTsBufferSize(tsBufferSize); IptvConfig.SetTsBufferSize(tsBufferSize);
IptvConfig.SetTsBufferPrefillRatio(tsBufferPrefill); IptvConfig.SetTsBufferPrefillRatio(tsBufferPrefill);
IptvConfig.SetUdpBufferSize(udpBufferSize); IptvConfig.SetUdpBufferSize(udpBufferSize);
IptvConfig.SetUdpBufferSize(rtpBufferSize);
IptvConfig.SetHttpBufferSize(httpBufferSize); IptvConfig.SetHttpBufferSize(httpBufferSize);
IptvConfig.SetFileBufferSize(fileBufferSize); IptvConfig.SetFileBufferSize(fileBufferSize);
} }

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: setup.h,v 1.4 2007/09/18 18:48:11 rahrenbe Exp $ * $Id: setup.h,v 1.5 2007/09/26 19:49:35 rahrenbe Exp $
*/ */
#ifndef __IPTV_SETUP_H #ifndef __IPTV_SETUP_H
@ -17,6 +17,7 @@ private:
int tsBufferSize; int tsBufferSize;
int tsBufferPrefill; int tsBufferPrefill;
int udpBufferSize; int udpBufferSize;
int rtpBufferSize;
int httpBufferSize; int httpBufferSize;
int fileBufferSize; int fileBufferSize;
eOSState EditChannel(void); eOSState EditChannel(void);