1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

Added simple file reader.

This commit is contained in:
Antti Seppälä 2007-09-16 12:18:15 +00:00
parent d1e633c147
commit 2751ba9d7f
5 changed files with 150 additions and 4 deletions

View File

@ -1,7 +1,7 @@
#
# Makefile for a Video Disk Recorder plugin
#
# $Id: Makefile,v 1.5 2007/09/16 09:38:00 ajhseppa Exp $
# $Id: Makefile,v 1.6 2007/09/16 12:18:15 ajhseppa Exp $
# Debugging on/off
#IPTV_DEBUG = 1
@ -57,7 +57,7 @@ endif
### The object files (add further files here):
OBJS = $(PLUGIN).o config.o setup.o device.o streamer.o protocoludp.o protocolhttp.o
OBJS = $(PLUGIN).o config.o setup.o device.o streamer.o protocoludp.o protocolhttp.o protocolfile.o
### The main target:

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: device.c,v 1.17 2007/09/16 09:38:01 ajhseppa Exp $
* $Id: device.c,v 1.18 2007/09/16 12:18:15 ajhseppa Exp $
*/
#include "common.h"
@ -34,6 +34,7 @@ cIptvDevice::cIptvDevice(unsigned int Index)
pUdpProtocol = new cIptvProtocolUdp();
//pRtspProtocol = new cIptvProtocolRtsp();
pHttpProtocol = new cIptvProtocolHttp();
pFileProtocol = new cIptvProtocolFile();
pIptvStreamer = new cIptvStreamer(tsBuffer, &mutex);
StartSectionHandler();
}

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: device.h,v 1.7 2007/09/16 09:38:01 ajhseppa Exp $
* $Id: device.h,v 1.8 2007/09/16 12:18:15 ajhseppa Exp $
*/
#ifndef __IPTV_DEVICE_H
@ -13,6 +13,7 @@
#include "protocoludp.h"
//#include "protocolrtsp.h"
#include "protocolhttp.h"
#include "protocolfile.h"
#include "streamer.h"
class cIptvDevice : public cDevice {
@ -33,6 +34,7 @@ private:
cIptvProtocolUdp *pUdpProtocol;
//cIptvProtocolRtsp *pRtspProtocol;
cIptvProtocolHttp *pHttpProtocol;
cIptvProtocolFile *pFileProtocol;
cIptvStreamer *pIptvStreamer;
cMutex mutex;

105
protocolfile.c Normal file
View File

@ -0,0 +1,105 @@
/*
* protocolfile.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: protocolfile.c,v 1.1 2007/09/16 12:18:15 ajhseppa Exp $
*/
#include <fcntl.h>
#include <unistd.h>
#include <vdr/device.h>
#include "common.h"
#include "protocolfile.h"
cIptvProtocolFile::cIptvProtocolFile()
: fileDesc(-1),
readBufferLen(TS_SIZE * 7),
fileActive(false)
{
debug("cIptvProtocolFile::cIptvProtocolFile()\n");
streamAddr = strdup("");
// Allocate receive buffer
readBuffer = MALLOC(unsigned char, readBufferLen);
if (!readBuffer)
error("ERROR: MALLOC() failed in ProtocolFile()");
}
cIptvProtocolFile::~cIptvProtocolFile()
{
debug("cIptvProtocolFile::~cIptvProtocolFile()\n");
// Drop open handles
Close();
// Free allocated memory
free(streamAddr);
free(readBuffer);
}
bool cIptvProtocolFile::OpenFile(void)
{
debug("cIptvProtocolFile::OpenFile()\n");
// Check that stream address is valid
if (!fileActive && !isempty(streamAddr)) {
fileDesc = open(streamAddr, O_RDONLY | O_NOCTTY | O_NONBLOCK);
if (fileDesc < 0) {
char tmp[64];
error("ERROR: open(): %s", strerror_r(errno, tmp, sizeof(tmp)));
return false;
}
// Update active flag
fileActive = true;
}
return true;
}
void cIptvProtocolFile::CloseFile(void)
{
debug("cIptvProtocolFile::CloseFile()\n");
// Check that stream address is valid
if (fileActive && !isempty(streamAddr)) {
close(fileDesc);
// Update multicasting flag
fileActive = false;
}
}
int cIptvProtocolFile::Read(unsigned char* *BufferAddr)
{
//debug("cIptvProtocolFile::Read()\n");
return read(fileDesc, readBuffer, readBufferLen);
}
bool cIptvProtocolFile::Open(void)
{
debug("cIptvProtocolFile::Open(): streamAddr=%s\n", streamAddr);
// Open the file for input
OpenFile();
return true;
}
bool cIptvProtocolFile::Close(void)
{
debug("cIptvProtocolFile::Close(): streamAddr=%s\n", streamAddr);
// Close the file input
CloseFile();
return true;
}
bool cIptvProtocolFile::Set(const char* Address, const int Port)
{
debug("cIptvProtocolFile::Set(): %s:%d\n", Address, Port);
if (!isempty(Address)) {
// Close the file input
CloseFile();
// Update stream address and port
streamAddr = strcpyrealloc(streamAddr, Address);
streamPort = Port;
// Open the file for input
OpenFile();
}
return true;
}

38
protocolfile.h Normal file
View File

@ -0,0 +1,38 @@
/*
* protocolfile.h: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: protocolfile.h,v 1.1 2007/09/16 12:18:15 ajhseppa Exp $
*/
#ifndef __IPTV_PROTOCOLFILE_H
#define __IPTV_PROTOCOLFILE_H
#include <arpa/inet.h>
#include "protocolif.h"
class cIptvProtocolFile : public cIptvProtocolIf {
private:
char* streamAddr;
int streamPort;
int fileDesc;
unsigned char* readBuffer;
unsigned int readBufferLen;
bool fileActive;
private:
bool OpenFile(void);
void CloseFile(void);
public:
cIptvProtocolFile();
virtual ~cIptvProtocolFile();
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_PROTOCOLFILE_H