Added mechanism to resize protocol read buffers on the fly.

This commit is contained in:
Rolf Ahrenberg 2007-09-20 21:45:51 +00:00
parent e85dc10fea
commit d4133a8888
9 changed files with 32 additions and 35 deletions

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.3 2007/09/16 13:38:20 rahrenbe Exp $ * $Id: config.c,v 1.4 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#include "common.h" #include "common.h"
@ -16,6 +16,7 @@ cIptvConfig::cIptvConfig(void)
tsBufferPrefillRatio(0), tsBufferPrefillRatio(0),
udpBufferSize(7), udpBufferSize(7),
httpBufferSize(7), httpBufferSize(7),
fileBufferSize(7) fileBufferSize(20),
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.3 2007/09/16 13:38:20 rahrenbe Exp $ * $Id: config.h,v 1.4 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#ifndef __IPTV_CONFIG_H #ifndef __IPTV_CONFIG_H
@ -20,6 +20,7 @@ protected:
unsigned int udpBufferSize; unsigned int udpBufferSize;
unsigned int httpBufferSize; unsigned int httpBufferSize;
unsigned int fileBufferSize; unsigned int fileBufferSize;
unsigned int maxBufferSize;
public: public:
cIptvConfig(); cIptvConfig();
unsigned int GetTsBufferSize(void) { return tsBufferSize; } unsigned int GetTsBufferSize(void) { return tsBufferSize; }
@ -27,6 +28,7 @@ public:
unsigned int GetUdpBufferSize(void) { return udpBufferSize; } unsigned int GetUdpBufferSize(void) { return udpBufferSize; }
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; }
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; }

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: protocolfile.c,v 1.6 2007/09/20 21:15:08 rahrenbe Exp $ * $Id: protocolfile.c,v 1.7 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#include <fcntl.h> #include <fcntl.h>
@ -16,14 +16,13 @@
#include "protocolfile.h" #include "protocolfile.h"
cIptvProtocolFile::cIptvProtocolFile() cIptvProtocolFile::cIptvProtocolFile()
: readBufferLen(TS_SIZE * IptvConfig.GetFileBufferSize()), : fileActive(false)
fileActive(false)
{ {
debug("cIptvProtocolFile::cIptvProtocolFile(): readBufferLen=%d (%d)\n", debug("cIptvProtocolFile::cIptvProtocolFile(): %d/%d packets\n",
readBufferLen, (readBufferLen / TS_SIZE)); IptvConfig.GetFileBufferSize(), IptvConfig.GetMaxBufferSize());
streamAddr = strdup(""); streamAddr = strdup("");
// Allocate receive buffer // Allocate receive buffer
readBuffer = MALLOC(unsigned char, readBufferLen); readBuffer = MALLOC(unsigned char, (TS_SIZE * IptvConfig.GetMaxBufferSize()));
if (!readBuffer) if (!readBuffer)
error("ERROR: MALLOC() failed in ProtocolFile()"); error("ERROR: MALLOC() failed in ProtocolFile()");
} }
@ -84,7 +83,7 @@ int cIptvProtocolFile::Read(unsigned char* *BufferAddr)
// during the sleep and buffers are disposed. Check here that the plugin is // during the sleep and buffers are disposed. Check here that the plugin is
// still active before accessing the buffers // still active before accessing the buffers
if (fileActive) if (fileActive)
return fread(readBuffer, sizeof(unsigned char), readBufferLen, fileStream); return fread(readBuffer, sizeof(unsigned char), (TS_SIZE * IptvConfig.GetFileBufferSize()), fileStream);
return -1; return -1;
} }

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: protocolfile.h,v 1.2 2007/09/16 14:47:01 ajhseppa Exp $ * $Id: protocolfile.h,v 1.3 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#ifndef __IPTV_PROTOCOLFILE_H #ifndef __IPTV_PROTOCOLFILE_H
@ -18,7 +18,6 @@ private:
int streamPort; int streamPort;
FILE* fileStream; FILE* fileStream;
unsigned char* readBuffer; unsigned char* readBuffer;
unsigned int readBufferLen;
bool fileActive; bool fileActive;
private: private:

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.3 2007/09/19 17:14:03 rahrenbe Exp $ * $Id: protocolhttp.c,v 1.4 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -22,15 +22,14 @@
cIptvProtocolHttp::cIptvProtocolHttp() cIptvProtocolHttp::cIptvProtocolHttp()
: streamPort(1234), : streamPort(1234),
socketDesc(-1), socketDesc(-1),
readBufferLen(TS_SIZE * IptvConfig.GetHttpBufferSize()),
unicastActive(false) unicastActive(false)
{ {
debug("cIptvProtocolHttp::cIptvProtocolHttp(): readBufferLen=%d (%d)\n", debug("cIptvProtocolHttp::cIptvProtocolHttp(): %d/%d packets\n",
readBufferLen, (readBufferLen / TS_SIZE)); IptvConfig.GetHttpBufferSize(), IptvConfig.GetMaxBufferSize());
streamAddr = strdup(""); streamAddr = strdup("");
streamPath = strdup("/"); streamPath = strdup("/");
// Allocate receive buffer // Allocate receive buffer
readBuffer = MALLOC(unsigned char, readBufferLen); readBuffer = MALLOC(unsigned char, (TS_SIZE * IptvConfig.GetMaxBufferSize()));
if (!readBuffer) if (!readBuffer)
error("ERROR: MALLOC() failed in ProtocolHttp()"); error("ERROR: MALLOC() failed in ProtocolHttp()");
} }
@ -238,8 +237,8 @@ int cIptvProtocolHttp::Read(unsigned char* *BufferAddr)
// Check if data available // Check if data available
else if (retval) { else if (retval) {
// Read data from socket // Read data from socket
return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT, return recvfrom(socketDesc, readBuffer, (TS_SIZE * IptvConfig.GetHttpBufferSize()),
(struct sockaddr *)&sockAddr, &addrlen); MSG_DONTWAIT, (struct sockaddr *)&sockAddr, &addrlen);
} }
return 0; return 0;
} }

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.2 2007/09/19 17:14:03 rahrenbe Exp $ * $Id: protocolhttp.h,v 1.3 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#ifndef __IPTV_PROTOCOLHTTP_H #ifndef __IPTV_PROTOCOLHTTP_H
@ -19,7 +19,6 @@ private:
int streamPort; int streamPort;
int socketDesc; int socketDesc;
unsigned char* readBuffer; unsigned char* readBuffer;
unsigned int readBufferLen;
struct sockaddr_in sockAddr; struct sockaddr_in sockAddr;
bool unicastActive; bool unicastActive;

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.c,v 1.5 2007/09/16 13:38:20 rahrenbe Exp $ * $Id: protocoludp.c,v 1.6 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#include <sys/types.h> #include <sys/types.h>
@ -21,14 +21,13 @@
cIptvProtocolUdp::cIptvProtocolUdp() cIptvProtocolUdp::cIptvProtocolUdp()
: streamPort(1234), : streamPort(1234),
socketDesc(-1), socketDesc(-1),
readBufferLen(TS_SIZE * IptvConfig.GetUdpBufferSize()),
mcastActive(false) mcastActive(false)
{ {
debug("cIptvProtocolUdp::cIptvProtocolUdp(): readBufferLen=%d (%d)\n", debug("cIptvProtocolUdp::cIptvProtocolUdp(): %d/%d packets\n",
readBufferLen, (readBufferLen / TS_SIZE)); IptvConfig.GetUdpBufferSize(), IptvConfig.GetMaxBufferSize());
streamAddr = strdup(""); streamAddr = strdup("");
// Allocate receive buffer // Allocate receive buffer
readBuffer = MALLOC(unsigned char, readBufferLen); readBuffer = MALLOC(unsigned char, (TS_SIZE * IptvConfig.GetMaxBufferSize()));
if (!readBuffer) if (!readBuffer)
error("ERROR: MALLOC() failed in ProtocolUdp()"); error("ERROR: MALLOC() failed in ProtocolUdp()");
} }
@ -177,8 +176,8 @@ int cIptvProtocolUdp::Read(unsigned char* *BufferAddr)
// Check if data available // Check if data available
else if (retval) { else if (retval) {
// Read data from socket // Read data from socket
return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT, return recvfrom(socketDesc, readBuffer, (TS_SIZE * IptvConfig.GetUdpBufferSize()),
(struct sockaddr *)&sockAddr, &addrlen); MSG_DONTWAIT, (struct sockaddr *)&sockAddr, &addrlen);
} }
return 0; return 0;
} }

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.3 2007/09/15 21:27:00 rahrenbe Exp $ * $Id: protocoludp.h,v 1.4 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#ifndef __IPTV_PROTOCOLUDP_H #ifndef __IPTV_PROTOCOLUDP_H
@ -18,7 +18,6 @@ private:
int streamPort; int streamPort;
int socketDesc; int socketDesc;
unsigned char* readBuffer; unsigned char* readBuffer;
unsigned int readBufferLen;
struct sockaddr_in sockAddr; struct sockaddr_in sockAddr;
bool mcastActive; bool mcastActive;

10
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.7 2007/09/19 17:14:03 rahrenbe Exp $ * $Id: setup.c,v 1.8 2007/09/20 21:45:51 rahrenbe Exp $
*/ */
#include <string.h> #include <string.h>
@ -429,11 +429,11 @@ void cIptvPluginSetup::Setup(void)
{ {
int current = Current(); int current = Current();
Clear(); Clear();
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, 14)); Add(new cMenuEditIntItem(tr("UDP buffer size [packets]"), &udpBufferSize, 1, IptvConfig.GetMaxBufferSize()));
Add(new cMenuEditIntItem(tr("HTTP buffer size [packets]"), &httpBufferSize, 1, 14)); Add(new cMenuEditIntItem(tr("HTTP buffer size [packets]"), &httpBufferSize, 1, IptvConfig.GetMaxBufferSize()));
Add(new cMenuEditIntItem(tr("FILE buffer size [packets]"), &fileBufferSize, 1, 14)); Add(new cMenuEditIntItem(tr("FILE buffer size [packets]"), &fileBufferSize, 1, IptvConfig.GetMaxBufferSize()));
SetCurrent(Get(current)); SetCurrent(Get(current));
Display(); Display();
} }