Separate filter Close to a private method.

This commit is contained in:
Antti Seppälä 2007-09-22 08:17:35 +00:00
parent 067ba7c505
commit bdacb388c3
2 changed files with 41 additions and 31 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: device.c,v 1.30 2007/09/21 21:50:52 rahrenbe Exp $ * $Id: device.c,v 1.31 2007/09/22 08:17:35 ajhseppa Exp $
*/ */
#include "common.h" #include "common.h"
@ -44,6 +44,7 @@ cIptvDevice::cIptvDevice(unsigned int Index)
unlink(filters[i].pipeName); unlink(filters[i].pipeName);
memset(filters[i].pipeName, '\0', sizeof(filters[i].pipeName)); memset(filters[i].pipeName, '\0', sizeof(filters[i].pipeName));
filters[i].fifoDesc = -1; filters[i].fifoDesc = -1;
filters[i].readDesc = -1;
filters[i].active = false; filters[i].active = false;
} }
StartSectionHandler(); StartSectionHandler();
@ -56,16 +57,8 @@ cIptvDevice::~cIptvDevice()
delete pUdpProtocol; delete pUdpProtocol;
delete tsBuffer; delete tsBuffer;
// Iterate over all filters and clear their settings // Iterate over all filters and clear their settings
for (int i = 0; i < eMaxFilterCount; ++i) { for (int i = 0; i < eMaxFilterCount; ++i)
if (filters[i].active) { DeleteFilter(i);
close(filters[i].fifoDesc);
unlink(filters[i].pipeName);
memset(filters[i].pipeName, '\0', sizeof(filters[i].pipeName));
filters[i].fifoDesc = -1;
filters[i].active = false;
clear_trans_filt(&filter, i);
}
}
} }
bool cIptvDevice::Initialize(unsigned int DeviceCount) bool cIptvDevice::Initialize(unsigned int DeviceCount)
@ -172,12 +165,29 @@ bool cIptvDevice::SetPid(cPidHandle *Handle, int Type, bool On)
return true; return true;
} }
bool cIptvDevice::DeleteFilter(unsigned int Index)
{
debug("cIptvDevice::DeleteFilter(%d) Index=%d\n", deviceIndex, Index);
if ((Index < eMaxFilterCount) && filters[Index].active) {
close(filters[Index].fifoDesc);
close(filters[Index].readDesc);
unlink(filters[Index].pipeName);
memset(filters[Index].pipeName, '\0', sizeof(filters[Index].pipeName));
filters[Index].fifoDesc = -1;
filters[Index].readDesc = -1;
filters[Index].active = false;
clear_trans_filt(&filter, Index);
return true;
}
return false;
}
int cIptvDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask) int cIptvDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask)
{ {
// Search the next free filter slot // Search the next free filter slot
for (unsigned int i = 0; i < eMaxFilterCount; ++i) { for (unsigned int i = 0; i < eMaxFilterCount; ++i) {
if (!filters[i].active) { if (!filters[i].active) {
debug("cIptvDevice::OpenFilter(%d): Pid=%d Tid=%02X Mask=%02X Count=%d\n", deviceIndex, Pid, Tid, Mask, i); debug("cIptvDevice::OpenFilter(%d): Pid=%d Tid=%02X Mask=%02X Index=%d\n", deviceIndex, Pid, Tid, Mask, i);
uint8_t mask[eMaxFilterMaskLen] = { 0 }; uint8_t mask[eMaxFilterMaskLen] = { 0 };
uint8_t filt[eMaxFilterMaskLen] = { 0 }; uint8_t filt[eMaxFilterMaskLen] = { 0 };
mask[0] = Mask; mask[0] = Mask;
@ -198,18 +208,26 @@ int cIptvDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask)
break; break;
} }
// Create descriptors // Create descriptors
int fifoDescriptor = open(filters[i].pipeName, O_RDWR | O_NONBLOCK); filters[i].fifoDesc = open(filters[i].pipeName, O_RDWR | O_NONBLOCK);
int returnDescriptor = open(filters[i].pipeName, O_RDONLY | O_NONBLOCK); filters[i].readDesc = open(filters[i].pipeName, O_RDONLY | O_NONBLOCK);
// Store the write pipe and set active flag
filters[i].fifoDesc = fifoDescriptor;
filters[i].active = true; filters[i].active = true;
return returnDescriptor; return filters[i].readDesc;
} }
} }
// No free filter slot found // No free filter slot found
return -1; return -1;
} }
bool cIptvDevice::CloseFilter(int Handle)
{
debug("cIptvDevice::CloseFilter(%d): %d\n", deviceIndex, Handle);
for (unsigned int i = 0; i < eMaxFilterCount; ++i) {
if (Handle == filters[i].readDesc)
return DeleteFilter(i);
}
return false;
}
bool cIptvDevice::OpenDvr(void) bool cIptvDevice::OpenDvr(void)
{ {
debug("cIptvDevice::OpenDvr(%d)\n", deviceIndex); debug("cIptvDevice::OpenDvr(%d)\n", deviceIndex);
@ -230,12 +248,7 @@ void cIptvDevice::CloseDvr(void)
// Iterate over all filters and clear their settings // Iterate over all filters and clear their settings
for (int i = 0; i < eMaxFilterCount; ++i) { for (int i = 0; i < eMaxFilterCount; ++i) {
if (filters[i].active) { if (filters[i].active) {
close(filters[i].fifoDesc); DeleteFilter(i);
unlink(filters[i].pipeName);
memset(filters[i].pipeName, '\0', sizeof(filters[i].pipeName));
filters[i].fifoDesc = -1;
filters[i].active = false;
clear_trans_filt(&filter, i);
} }
} }
isOpenDvr = false; isOpenDvr = false;
@ -308,13 +321,7 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
if (retval < 0) { if (retval < 0) {
char tmp[64]; char tmp[64];
error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp))); error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp)));
// VDR has probably closed the filter file descriptor, so clear the filter DeleteFilter(i);
close(filters[i].fifoDesc);
unlink(filters[i].pipeName);
memset(filters[i].pipeName, '\0', sizeof(filters[i].pipeName));
filters[i].fifoDesc = -1;
filters[i].active = false;
clear_trans_filt(&filter, i);
} }
// There is no data in the fifo, more can be written // There is no data in the fifo, more can be written
else if (!retval) { else if (!retval) {

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.14 2007/09/21 21:50:52 rahrenbe Exp $ * $Id: device.h,v 1.15 2007/09/22 08:17:35 ajhseppa Exp $
*/ */
#ifndef __IPTV_DEVICE_H #ifndef __IPTV_DEVICE_H
@ -21,6 +21,7 @@
struct filterInfo { struct filterInfo {
bool active; bool active;
int fifoDesc; int fifoDesc;
int readDesc;
char pipeName[128]; char pipeName[128];
int lastProvided; int lastProvided;
}; };
@ -63,6 +64,7 @@ private:
bool ProvidesIptv(const char *Param) const; bool ProvidesIptv(const char *Param) const;
void ResetBuffering(void); void ResetBuffering(void);
bool IsBuffering(void); bool IsBuffering(void);
bool DeleteFilter(unsigned int Index);
// for channel selection // for channel selection
public: public:
@ -82,6 +84,7 @@ protected:
// for section filtering // for section filtering
public: public:
virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask); virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask);
virtual bool CloseFilter(int Handle);
// for transponder lock // for transponder lock
public: public: