mirror of
https://github.com/rofafor/vdr-plugin-iptv.git
synced 2023-10-10 13:37:03 +02:00
Moved socket buffer from streamer into protocol.
This commit is contained in:
parent
43eb0db822
commit
bc817a0604
@ -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: protocolif.h,v 1.1 2007/09/14 15:44:25 rahrenbe Exp $
|
* $Id: protocolif.h,v 1.2 2007/09/15 20:33:15 rahrenbe Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __IPTV_PROTOCOLIF_H
|
#ifndef __IPTV_PROTOCOLIF_H
|
||||||
@ -13,7 +13,7 @@ class cIptvProtocolIf {
|
|||||||
public:
|
public:
|
||||||
cIptvProtocolIf() {}
|
cIptvProtocolIf() {}
|
||||||
virtual ~cIptvProtocolIf() {}
|
virtual ~cIptvProtocolIf() {}
|
||||||
virtual int Read(unsigned char *Buffer, int Len) = 0;
|
virtual int Read(unsigned char *Buffer) = 0;
|
||||||
virtual bool Set(const char* Address, const int Port) = 0;
|
virtual bool Set(const char* Address, const int Port) = 0;
|
||||||
virtual bool Open(void) = 0;
|
virtual bool Open(void) = 0;
|
||||||
virtual bool Close(void) = 0;
|
virtual bool Close(void) = 0;
|
||||||
|
@ -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.1 2007/09/14 15:44:25 rahrenbe Exp $
|
* $Id: protocoludp.c,v 1.2 2007/09/15 20:33:15 rahrenbe Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -12,16 +12,23 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <vdr/device.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "protocoludp.h"
|
#include "protocoludp.h"
|
||||||
|
|
||||||
cIptvProtocolUdp::cIptvProtocolUdp()
|
cIptvProtocolUdp::cIptvProtocolUdp()
|
||||||
: streamPort(1234),
|
: streamPort(1234),
|
||||||
socketDesc(-1),
|
socketDesc(-1),
|
||||||
|
readBufferLen(TS_SIZE * 7),
|
||||||
mcastActive(false)
|
mcastActive(false)
|
||||||
{
|
{
|
||||||
debug("cIptvProtocolUdp::cIptvProtocolUdp()\n");
|
debug("cIptvProtocolUdp::cIptvProtocolUdp()\n");
|
||||||
streamAddr = strdup("");
|
streamAddr = strdup("");
|
||||||
|
// Allocate receive buffer
|
||||||
|
readBuffer = MALLOC(unsigned char, readBufferLen);
|
||||||
|
if (!readBuffer)
|
||||||
|
error("ERROR: MALLOC() failed in ProtocolUdp()");
|
||||||
}
|
}
|
||||||
|
|
||||||
cIptvProtocolUdp::~cIptvProtocolUdp()
|
cIptvProtocolUdp::~cIptvProtocolUdp()
|
||||||
@ -31,6 +38,7 @@ cIptvProtocolUdp::~cIptvProtocolUdp()
|
|||||||
Close();
|
Close();
|
||||||
// Free allocated memory
|
// Free allocated memory
|
||||||
free(streamAddr);
|
free(streamAddr);
|
||||||
|
free(readBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cIptvProtocolUdp::OpenSocket(const int Port)
|
bool cIptvProtocolUdp::OpenSocket(const int Port)
|
||||||
@ -143,10 +151,11 @@ bool cIptvProtocolUdp::DropMulticast(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cIptvProtocolUdp::Read(unsigned char *Buffer, int Len)
|
int cIptvProtocolUdp::Read(unsigned char *Buffer)
|
||||||
{
|
{
|
||||||
//debug("cIptvProtocolUdp::Read()\n");
|
//debug("cIptvProtocolUdp::Read()\n");
|
||||||
socklen_t addrlen = sizeof(sockAddr);
|
socklen_t addrlen = sizeof(sockAddr);
|
||||||
|
Buffer = readBuffer;
|
||||||
// Wait for data
|
// Wait for data
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
@ -165,7 +174,7 @@ int cIptvProtocolUdp::Read(unsigned char *Buffer, int Len)
|
|||||||
// 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, Buffer, Len, MSG_DONTWAIT,
|
return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT,
|
||||||
(struct sockaddr *)&sockAddr, &addrlen);
|
(struct sockaddr *)&sockAddr, &addrlen);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -203,4 +212,3 @@ bool cIptvProtocolUdp::Set(const char* Address, const int Port)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.1 2007/09/14 15:44:25 rahrenbe Exp $
|
* $Id: protocoludp.h,v 1.2 2007/09/15 20:33:15 rahrenbe Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __IPTV_PROTOCOLUDP_H
|
#ifndef __IPTV_PROTOCOLUDP_H
|
||||||
@ -17,6 +17,8 @@ private:
|
|||||||
char* streamAddr;
|
char* streamAddr;
|
||||||
int streamPort;
|
int streamPort;
|
||||||
int socketDesc;
|
int socketDesc;
|
||||||
|
unsigned char* readBuffer;
|
||||||
|
unsigned int readBufferLen;
|
||||||
struct sockaddr_in sockAddr;
|
struct sockaddr_in sockAddr;
|
||||||
bool mcastActive;
|
bool mcastActive;
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
cIptvProtocolUdp();
|
cIptvProtocolUdp();
|
||||||
virtual ~cIptvProtocolUdp();
|
virtual ~cIptvProtocolUdp();
|
||||||
virtual int Read(unsigned char *Buffer, int Len);
|
virtual int Read(unsigned char *Buffer);
|
||||||
virtual bool Set(const char* Address, const int Port);
|
virtual bool Set(const char* Address, const int Port);
|
||||||
virtual bool Open(void);
|
virtual bool Open(void);
|
||||||
virtual bool Close(void);
|
virtual bool Close(void);
|
||||||
|
49
streamer.c
49
streamer.c
@ -3,16 +3,9 @@
|
|||||||
*
|
*
|
||||||
* 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: streamer.c,v 1.11 2007/09/14 15:44:25 rahrenbe Exp $
|
* $Id: streamer.c,v 1.12 2007/09/15 20:33:15 rahrenbe Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <vdr/device.h>
|
|
||||||
#include <vdr/thread.h>
|
#include <vdr/thread.h>
|
||||||
#include <vdr/ringbuffer.h>
|
#include <vdr/ringbuffer.h>
|
||||||
|
|
||||||
@ -23,14 +16,9 @@ cIptvStreamer::cIptvStreamer(cRingBufferLinear* RingBuffer, cMutex* Mutex)
|
|||||||
: cThread("IPTV streamer"),
|
: cThread("IPTV streamer"),
|
||||||
ringBuffer(RingBuffer),
|
ringBuffer(RingBuffer),
|
||||||
mutex(Mutex),
|
mutex(Mutex),
|
||||||
readBufferLen(TS_SIZE * 7),
|
|
||||||
protocol(NULL)
|
protocol(NULL)
|
||||||
{
|
{
|
||||||
debug("cIptvStreamer::cIptvStreamer()\n");
|
debug("cIptvStreamer::cIptvStreamer()\n");
|
||||||
// Allocate receive buffer
|
|
||||||
readBuffer = MALLOC(unsigned char, readBufferLen);
|
|
||||||
if (!readBuffer)
|
|
||||||
error("ERROR: MALLOC(readBuffer) failed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cIptvStreamer::~cIptvStreamer()
|
cIptvStreamer::~cIptvStreamer()
|
||||||
@ -38,8 +26,6 @@ cIptvStreamer::~cIptvStreamer()
|
|||||||
debug("cIptvStreamer::~cIptvStreamer()\n");
|
debug("cIptvStreamer::~cIptvStreamer()\n");
|
||||||
// Close the protocol
|
// Close the protocol
|
||||||
Close();
|
Close();
|
||||||
// Free allocated memory
|
|
||||||
free(readBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cIptvStreamer::Action(void)
|
void cIptvStreamer::Action(void)
|
||||||
@ -47,20 +33,21 @@ void cIptvStreamer::Action(void)
|
|||||||
debug("cIptvStreamer::Action(): Entering\n");
|
debug("cIptvStreamer::Action(): Entering\n");
|
||||||
// Do the thread loop
|
// Do the thread loop
|
||||||
while (Running()) {
|
while (Running()) {
|
||||||
if (ringBuffer && mutex && readBuffer && protocol) {
|
if (ringBuffer && mutex && protocol) {
|
||||||
int length = protocol->Read(readBuffer, readBufferLen);
|
unsigned char *buffer = NULL;
|
||||||
|
int length = protocol->Read(buffer);
|
||||||
if (length >= 0) {
|
if (length >= 0) {
|
||||||
mutex->Lock();
|
mutex->Lock();
|
||||||
int p = ringBuffer->Put(readBuffer, length);
|
int p = ringBuffer->Put(buffer, length);
|
||||||
if (p != length && Running())
|
if (p != length && Running())
|
||||||
ringBuffer->ReportOverflow(length - p);
|
ringBuffer->ReportOverflow(length - p);
|
||||||
mutex->Unlock();
|
mutex->Unlock();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cCondWait::SleepMs(3); // reduce cpu load
|
cCondWait::SleepMs(100); // to reduce cpu load
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cCondWait::SleepMs(100); // avoid busy loop
|
cCondWait::SleepMs(100); // and avoid busy loop
|
||||||
}
|
}
|
||||||
debug("cIptvStreamer::Action(): Exiting\n");
|
debug("cIptvStreamer::Action(): Exiting\n");
|
||||||
}
|
}
|
||||||
@ -92,18 +79,18 @@ bool cIptvStreamer::Set(const char* Address, const int Port, cIptvProtocolIf* Pr
|
|||||||
{
|
{
|
||||||
debug("cIptvStreamer::Set(): %s:%d\n", Address, Port);
|
debug("cIptvStreamer::Set(): %s:%d\n", Address, Port);
|
||||||
if (!isempty(Address)) {
|
if (!isempty(Address)) {
|
||||||
// Update protocol; Close the existing one if changed
|
// Update protocol; Close the existing one if changed
|
||||||
if (protocol != Protocol) {
|
if (protocol != Protocol) {
|
||||||
if (protocol)
|
if (protocol)
|
||||||
protocol->Close();
|
protocol->Close();
|
||||||
protocol = Protocol;
|
protocol = Protocol;
|
||||||
if (protocol)
|
if (protocol)
|
||||||
protocol->Open();
|
protocol->Open();
|
||||||
}
|
}
|
||||||
// Set protocol address and port
|
// Set protocol address and port
|
||||||
if (protocol)
|
if (protocol)
|
||||||
protocol->Set(Address, Port);
|
protocol->Set(Address, Port);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user