mirror of
https://github.com/rofafor/vdr-plugin-iptv.git
synced 2023-10-10 13:37:03 +02:00
Improved file reader, still doesn't work though
This commit is contained in:
parent
df279b5503
commit
61f0b5b6d0
@ -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.2 2007/09/16 13:38:20 rahrenbe Exp $
|
* $Id: protocolfile.c,v 1.3 2007/09/16 14:47:01 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -16,8 +16,7 @@
|
|||||||
#include "protocolfile.h"
|
#include "protocolfile.h"
|
||||||
|
|
||||||
cIptvProtocolFile::cIptvProtocolFile()
|
cIptvProtocolFile::cIptvProtocolFile()
|
||||||
: fileDesc(-1),
|
: readBufferLen(TS_SIZE * IptvConfig.GetFileBufferSize()),
|
||||||
readBufferLen(TS_SIZE * IptvConfig.GetFileBufferSize()),
|
|
||||||
fileActive(false)
|
fileActive(false)
|
||||||
{
|
{
|
||||||
debug("cIptvProtocolFile::cIptvProtocolFile(): readBufferLen=%d (%d)\n",
|
debug("cIptvProtocolFile::cIptvProtocolFile(): readBufferLen=%d (%d)\n",
|
||||||
@ -45,10 +44,10 @@ bool cIptvProtocolFile::OpenFile(void)
|
|||||||
// Check that stream address is valid
|
// Check that stream address is valid
|
||||||
if (!fileActive && !isempty(streamAddr)) {
|
if (!fileActive && !isempty(streamAddr)) {
|
||||||
|
|
||||||
fileDesc = open(streamAddr, O_RDONLY | O_NOCTTY | O_NONBLOCK);
|
fileStream = fopen(streamAddr, "rb");
|
||||||
if (fileDesc < 0) {
|
if (ferror(fileStream) || !fileStream) {
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
error("ERROR: open(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
error("ERROR: fopen(): %s", strerror_r(errno, tmp, sizeof(tmp)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Update active flag
|
// Update active flag
|
||||||
@ -62,7 +61,7 @@ void cIptvProtocolFile::CloseFile(void)
|
|||||||
debug("cIptvProtocolFile::CloseFile()\n");
|
debug("cIptvProtocolFile::CloseFile()\n");
|
||||||
// Check that stream address is valid
|
// Check that stream address is valid
|
||||||
if (fileActive && !isempty(streamAddr)) {
|
if (fileActive && !isempty(streamAddr)) {
|
||||||
close(fileDesc);
|
fclose(fileStream);
|
||||||
// Update multicasting flag
|
// Update multicasting flag
|
||||||
fileActive = false;
|
fileActive = false;
|
||||||
}
|
}
|
||||||
@ -71,8 +70,16 @@ void cIptvProtocolFile::CloseFile(void)
|
|||||||
int cIptvProtocolFile::Read(unsigned char* *BufferAddr)
|
int cIptvProtocolFile::Read(unsigned char* *BufferAddr)
|
||||||
{
|
{
|
||||||
//debug("cIptvProtocolFile::Read()\n");
|
//debug("cIptvProtocolFile::Read()\n");
|
||||||
|
*BufferAddr = readBuffer;
|
||||||
return read(fileDesc, readBuffer, readBufferLen);
|
if(ferror(fileStream)) {
|
||||||
|
debug("Read error\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(feof(fileStream)) {
|
||||||
|
rewind(fileStream);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return fread(readBuffer, sizeof(unsigned char), readBufferLen, fileStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cIptvProtocolFile::Open(void)
|
bool cIptvProtocolFile::Open(void)
|
||||||
|
@ -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.1 2007/09/16 12:18:15 ajhseppa Exp $
|
* $Id: protocolfile.h,v 1.2 2007/09/16 14:47:01 ajhseppa Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __IPTV_PROTOCOLFILE_H
|
#ifndef __IPTV_PROTOCOLFILE_H
|
||||||
@ -16,7 +16,7 @@ class cIptvProtocolFile : public cIptvProtocolIf {
|
|||||||
private:
|
private:
|
||||||
char* streamAddr;
|
char* streamAddr;
|
||||||
int streamPort;
|
int streamPort;
|
||||||
int fileDesc;
|
FILE* fileStream;
|
||||||
unsigned char* readBuffer;
|
unsigned char* readBuffer;
|
||||||
unsigned int readBufferLen;
|
unsigned int readBufferLen;
|
||||||
bool fileActive;
|
bool fileActive;
|
||||||
|
Loading…
Reference in New Issue
Block a user