Cleaned up the code.

This commit is contained in:
Rolf Ahrenberg 2013-02-23 15:31:11 +02:00
parent 94461d6c08
commit e75080b1a8
30 changed files with 957 additions and 1009 deletions

View File

@ -10,38 +10,38 @@
cIptvConfig IptvConfig;
cIptvConfig::cIptvConfig(void)
: tsBufferSize(2),
tsBufferPrefillRatio(0),
extProtocolBasePort(4321),
useBytes(1),
sectionFiltering(1)
: tsBufferSizeM(2),
tsBufferPrefillRatioM(0),
extProtocolBasePortM(4321),
useBytesM(1),
sectionFilteringM(1)
{
for (unsigned int i = 0; i < ARRAY_SIZE(disabledFilters); ++i)
disabledFilters[i] = -1;
memset(configDirectory, '\0', sizeof(configDirectory));
for (unsigned int i = 0; i < ARRAY_SIZE(disabledFiltersM); ++i)
disabledFiltersM[i] = -1;
memset(configDirectoryM, '\0', sizeof(configDirectoryM));
}
unsigned int cIptvConfig::GetDisabledFiltersCount(void) const
{
unsigned int n = 0;
while ((n < ARRAY_SIZE(disabledFilters) && (disabledFilters[n] != -1)))
while ((n < ARRAY_SIZE(disabledFiltersM) && (disabledFiltersM[n] != -1)))
n++;
return n;
}
int cIptvConfig::GetDisabledFilters(unsigned int Index) const
int cIptvConfig::GetDisabledFilters(unsigned int indexP) const
{
return (Index < ARRAY_SIZE(disabledFilters)) ? disabledFilters[Index] : -1;
return (indexP < ARRAY_SIZE(disabledFiltersM)) ? disabledFiltersM[indexP] : -1;
}
void cIptvConfig::SetDisabledFilters(unsigned int Index, int Number)
void cIptvConfig::SetDisabledFilters(unsigned int indexP, int numberP)
{
if (Index < ARRAY_SIZE(disabledFilters))
disabledFilters[Index] = Number;
if (indexP < ARRAY_SIZE(disabledFiltersM))
disabledFiltersM[indexP] = numberP;
}
void cIptvConfig::SetConfigDirectory(const char *directoryP)
{
debug("cIptvConfig::SetConfigDirectory(%s)\n", directoryP);
ERROR_IF(!realpath(directoryP, configDirectory), "Cannot canonicalize configuration directory");
ERROR_IF(!realpath(directoryP, configDirectoryM), "Cannot canonicalize configuration directory");
}

View File

@ -14,30 +14,30 @@
class cIptvConfig
{
private:
unsigned int tsBufferSize;
unsigned int tsBufferPrefillRatio;
unsigned int extProtocolBasePort;
unsigned int useBytes;
unsigned int sectionFiltering;
int disabledFilters[SECTION_FILTER_TABLE_SIZE];
char configDirectory[PATH_MAX];
unsigned int tsBufferSizeM;
unsigned int tsBufferPrefillRatioM;
unsigned int extProtocolBasePortM;
unsigned int useBytesM;
unsigned int sectionFilteringM;
int disabledFiltersM[SECTION_FILTER_TABLE_SIZE];
char configDirectoryM[PATH_MAX];
public:
cIptvConfig();
unsigned int GetTsBufferSize(void) const { return tsBufferSize; }
unsigned int GetTsBufferPrefillRatio(void) const { return tsBufferPrefillRatio; }
unsigned int GetExtProtocolBasePort(void) const { return extProtocolBasePort; }
unsigned int GetUseBytes(void) const { return useBytes; }
unsigned int GetSectionFiltering(void) const { return sectionFiltering; }
const char *GetConfigDirectory(void) const { return configDirectory; }
unsigned int GetTsBufferSize(void) const { return tsBufferSizeM; }
unsigned int GetTsBufferPrefillRatio(void) const { return tsBufferPrefillRatioM; }
unsigned int GetExtProtocolBasePort(void) const { return extProtocolBasePortM; }
unsigned int GetUseBytes(void) const { return useBytesM; }
unsigned int GetSectionFiltering(void) const { return sectionFilteringM; }
const char *GetConfigDirectory(void) const { return configDirectoryM; }
unsigned int GetDisabledFiltersCount(void) const;
int GetDisabledFilters(unsigned int Index) const;
void SetTsBufferSize(unsigned int Size) { tsBufferSize = Size; }
void SetTsBufferPrefillRatio(unsigned int Ratio) { tsBufferPrefillRatio = Ratio; }
void SetExtProtocolBasePort(unsigned int PortNumber) { extProtocolBasePort = PortNumber; }
void SetUseBytes(unsigned int On) { useBytes = On; }
void SetSectionFiltering(unsigned int On) { sectionFiltering = On; }
void SetDisabledFilters(unsigned int Index, int Number);
int GetDisabledFilters(unsigned int indexP) const;
void SetTsBufferSize(unsigned int sizeP) { tsBufferSizeM = sizeP; }
void SetTsBufferPrefillRatio(unsigned int ratioP) { tsBufferPrefillRatioM = ratioP; }
void SetExtProtocolBasePort(unsigned int portNumberP) { extProtocolBasePortM = portNumberP; }
void SetUseBytes(unsigned int onOffP) { useBytesM = onOffP; }
void SetSectionFiltering(unsigned int onOffP) { sectionFilteringM = onOffP; }
void SetDisabledFilters(unsigned int indexP, int numberP);
void SetConfigDirectory(const char *directoryP);
};

364
device.c
View File

@ -11,92 +11,89 @@
#define IPTV_MAX_DEVICES MAXDEVICES
static cIptvDevice * IptvDevices[IPTV_MAX_DEVICES] = { NULL };
static cIptvDevice * IptvDevicesS[IPTV_MAX_DEVICES] = { NULL };
unsigned int cIptvDevice::deviceCount = 0;
cIptvDevice::cIptvDevice(unsigned int Index)
: deviceIndex(Index),
dvrFd(-1),
isPacketDelivered(false),
isOpenDvr(false),
isBuffering(true),
sidScanEnabled(false),
pidScanEnabled(false),
channelId(tChannelID::InvalidID)
cIptvDevice::cIptvDevice(unsigned int indexP)
: deviceIndexM(indexP),
dvrFdM(-1),
isPacketDeliveredM(false),
isOpenDvrM(false),
sidScanEnabledM(false),
pidScanEnabledM(false),
channelIdM(tChannelID::InvalidID)
{
unsigned int bufsize = (unsigned int)MEGABYTE(IptvConfig.GetTsBufferSize());
bufsize -= (bufsize % TS_SIZE);
isyslog("creating IPTV device %d (CardIndex=%d)", deviceIndex, CardIndex());
tsBuffer = new cRingBufferLinear(bufsize + 1, TS_SIZE, false,
*cString::sprintf("IPTV %d", deviceIndex));
tsBuffer->SetTimeouts(10, 10);
isyslog("creating IPTV device %d (CardIndex=%d)", deviceIndexM, CardIndex());
tsBufferM = new cRingBufferLinear(bufsize + 1, TS_SIZE, false,
*cString::sprintf("IPTV %d", deviceIndexM));
tsBufferM->SetTimeouts(10, 10);
ResetBuffering();
pUdpProtocol = new cIptvProtocolUdp();
pCurlProtocol = new cIptvProtocolCurl();
pHttpProtocol = new cIptvProtocolHttp();
pFileProtocol = new cIptvProtocolFile();
pExtProtocol = new cIptvProtocolExt();
pIptvStreamer = new cIptvStreamer(tsBuffer, (100 * TS_SIZE));
pPidScanner = new cPidScanner();
pUdpProtocolM = new cIptvProtocolUdp();
pCurlProtocolM = new cIptvProtocolCurl();
pHttpProtocolM = new cIptvProtocolHttp();
pFileProtocolM = new cIptvProtocolFile();
pExtProtocolM = new cIptvProtocolExt();
pIptvStreamerM = new cIptvStreamer(tsBufferM, (100 * TS_SIZE));
pPidScannerM = new cPidScanner();
// Initialize filter pointers
memset(secfilters, '\0', sizeof(secfilters));
memset(secFiltersM, 0, sizeof(secFiltersM));
// Start section handler for iptv device
StartSectionHandler();
// Sid scanner must be created after the section handler
pSidScanner = new cSidScanner();
if (pSidScanner)
AttachFilter(pSidScanner);
pSidScannerM = new cSidScanner();
if (pSidScannerM)
AttachFilter(pSidScannerM);
// Check if dvr fifo exists
struct stat sb;
cString filename = cString::sprintf(IPTV_DVR_FILENAME, deviceIndex);
cString filename = cString::sprintf(IPTV_DVR_FILENAME, deviceIndexM);
stat(filename, &sb);
if (S_ISFIFO(sb.st_mode)) {
dvrFd = open(filename, O_RDWR | O_NONBLOCK);
if (dvrFd >= 0)
dsyslog("IPTV device %d redirecting input stream to '%s'", deviceIndex, *filename);
dvrFdM = open(filename, O_RDWR | O_NONBLOCK);
if (dvrFdM >= 0)
dsyslog("IPTV device %d redirecting input stream to '%s'", deviceIndexM, *filename);
}
}
cIptvDevice::~cIptvDevice()
{
debug("cIptvDevice::~cIptvDevice(%d)\n", deviceIndex);
debug("cIptvDevice::~cIptvDevice(%d)\n", deviceIndexM);
// Stop section handler of iptv device
StopSectionHandler();
DELETE_POINTER(pIptvStreamer);
DELETE_POINTER(pUdpProtocol);
DELETE_POINTER(pCurlProtocol);
DELETE_POINTER(pHttpProtocol);
DELETE_POINTER(pFileProtocol);
DELETE_POINTER(pExtProtocol);
DELETE_POINTER(tsBuffer);
DELETE_POINTER(pPidScanner);
DELETE_POINTER(pIptvStreamerM);
DELETE_POINTER(pUdpProtocolM);
DELETE_POINTER(pCurlProtocolM);
DELETE_POINTER(pHttpProtocolM);
DELETE_POINTER(pFileProtocolM);
DELETE_POINTER(pExtProtocolM);
DELETE_POINTER(tsBufferM);
DELETE_POINTER(pPidScannerM);
// Detach and destroy sid filter
if (pSidScanner) {
Detach(pSidScanner);
DELETE_POINTER(pSidScanner);
if (pSidScannerM) {
Detach(pSidScannerM);
DELETE_POINTER(pSidScannerM);
}
// Destroy all filters
for (int i = 0; i < eMaxSecFilterCount; ++i)
DeleteFilter(i);
// Close dvr fifo
if (dvrFd >= 0) {
int fd = dvrFd;
dvrFd = -1;
if (dvrFdM >= 0) {
int fd = dvrFdM;
dvrFdM = -1;
close(fd);
}
}
bool cIptvDevice::Initialize(unsigned int DeviceCount)
bool cIptvDevice::Initialize(unsigned int deviceCountP)
{
debug("cIptvDevice::Initialize(): DeviceCount=%d\n", DeviceCount);
debug("cIptvDevice::Initialize(): DeviceCount=%d\n", deviceCountP);
new cIptvSourceParam(IPTV_SOURCE_CHARACTER, "IPTV");
if (DeviceCount > IPTV_MAX_DEVICES)
DeviceCount = IPTV_MAX_DEVICES;
for (unsigned int i = 0; i < DeviceCount; ++i)
IptvDevices[i] = new cIptvDevice(i);
for (unsigned int i = DeviceCount; i < IPTV_MAX_DEVICES; ++i)
IptvDevices[i] = NULL;
if (deviceCountP > IPTV_MAX_DEVICES)
deviceCountP = IPTV_MAX_DEVICES;
for (unsigned int i = 0; i < deviceCountP; ++i)
IptvDevicesS[i] = new cIptvDevice(i);
for (unsigned int i = deviceCountP; i < IPTV_MAX_DEVICES; ++i)
IptvDevicesS[i] = NULL;
return true;
}
@ -105,19 +102,19 @@ unsigned int cIptvDevice::Count(void)
unsigned int count = 0;
debug("cIptvDevice::Count()\n");
for (unsigned int i = 0; i < IPTV_MAX_DEVICES; ++i) {
if (IptvDevices[i] != NULL)
if (IptvDevicesS[i] != NULL)
count++;
}
return count;
}
cIptvDevice *cIptvDevice::GetIptvDevice(int CardIndex)
cIptvDevice *cIptvDevice::GetIptvDevice(int cardIndexP)
{
//debug("cIptvDevice::GetIptvDevice(%d)\n", CardIndex);
//debug("cIptvDevice::GetIptvDevice(%d)\n", cardIndexP);
for (unsigned int i = 0; i < IPTV_MAX_DEVICES; ++i) {
if ((IptvDevices[i] != NULL) && (IptvDevices[i]->CardIndex() == CardIndex)) {
//debug("cIptvDevice::GetIptvDevice(%d): FOUND!\n", CardIndex);
return IptvDevices[i];
if ((IptvDevicesS[i] != NULL) && (IptvDevicesS[i]->CardIndex() == cardIndexP)) {
//debug("cIptvDevice::GetIptvDevice(%d): FOUND!\n", cardIndexP);
return IptvDevicesS[i];
}
}
return NULL;
@ -125,32 +122,32 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int CardIndex)
cString cIptvDevice::GetGeneralInformation(void)
{
//debug("cIptvDevice::GetGeneralInformation(%d)\n", deviceIndex);
//debug("cIptvDevice::GetGeneralInformation(%d)\n", deviceIndexM);
return cString::sprintf("IPTV device: %d\nCardIndex: %d\nStream: %s\nStream bitrate: %s\n%sChannel: %s",
deviceIndex, CardIndex(),
pIptvStreamer ? *pIptvStreamer->GetInformation() : "",
pIptvStreamer ? *pIptvStreamer->GetStreamerStatistic() : "",
deviceIndexM, CardIndex(),
pIptvStreamerM ? *pIptvStreamerM->GetInformation() : "",
pIptvStreamerM ? *pIptvStreamerM->GetStreamerStatistic() : "",
*GetBufferStatistic(),
*Channels.GetByNumber(cDevice::CurrentChannel())->ToText());
}
cString cIptvDevice::GetPidsInformation(void)
{
//debug("cIptvDevice::GetPidsInformation(%d)\n", deviceIndex);
//debug("cIptvDevice::GetPidsInformation(%d)\n", deviceIndexM);
return GetPidStatistic();
}
cString cIptvDevice::GetFiltersInformation(void)
{
//debug("cIptvDevice::GetFiltersInformation(%d)\n", deviceIndex);
//debug("cIptvDevice::GetFiltersInformation(%d)\n", deviceIndexM);
unsigned int count = 0;
cString s("Active section filters:\n");
// loop through active section filters
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (secfilters[i]) {
if (secFiltersM[i]) {
s = cString::sprintf("%sFilter %d: %s Pid=0x%02X (%s)\n", *s, i,
*secfilters[i]->GetSectionStatistic(), secfilters[i]->GetPid(),
id_pid(secfilters[i]->GetPid()));
*secFiltersM[i]->GetSectionStatistic(), secFiltersM[i]->GetPid(),
id_pid(secFiltersM[i]->GetPid()));
if (++count > IPTV_STATS_ACTIVE_FILTERS_COUNT)
break;
}
@ -158,11 +155,11 @@ cString cIptvDevice::GetFiltersInformation(void)
return s;
}
cString cIptvDevice::GetInformation(unsigned int Page)
cString cIptvDevice::GetInformation(unsigned int pageP)
{
// generate information string
cString s;
switch (Page) {
switch (pageP) {
case IPTV_DEVICE_INFO_GENERAL:
s = GetGeneralInformation();
break;
@ -173,10 +170,10 @@ cString cIptvDevice::GetInformation(unsigned int Page)
s = GetFiltersInformation();
break;
case IPTV_DEVICE_INFO_PROTOCOL:
s = pIptvStreamer ? *pIptvStreamer->GetInformation() : "";
s = pIptvStreamerM ? *pIptvStreamerM->GetInformation() : "";
break;
case IPTV_DEVICE_INFO_BITRATE:
s = pIptvStreamer ? *pIptvStreamer->GetStreamerStatistic() : "";
s = pIptvStreamerM ? *pIptvStreamerM->GetStreamerStatistic() : "";
break;
default:
s = cString::sprintf("%s%s%s",
@ -190,59 +187,59 @@ cString cIptvDevice::GetInformation(unsigned int Page)
cString cIptvDevice::DeviceType(void) const
{
debug("cIptvDevice::DeviceType(%d)\n", deviceIndex);
debug("cIptvDevice::DeviceType(%d)\n", deviceIndexM);
return "IPTV";
}
cString cIptvDevice::DeviceName(void) const
{
debug("cIptvDevice::DeviceName(%d)\n", deviceIndex);
return cString::sprintf("IPTV %d", deviceIndex);
debug("cIptvDevice::DeviceName(%d)\n", deviceIndexM);
return cString::sprintf("IPTV %d", deviceIndexM);
}
int cIptvDevice::SignalStrength(void) const
{
debug("cIptvDevice::SignalStrength(%d)\n", deviceIndex);
debug("cIptvDevice::SignalStrength(%d)\n", deviceIndexM);
return (100);
}
int cIptvDevice::SignalQuality(void) const
{
debug("cIptvDevice::SignalQuality(%d)\n", deviceIndex);
debug("cIptvDevice::SignalQuality(%d)\n", deviceIndexM);
return (100);
}
bool cIptvDevice::ProvidesSource(int Source) const
bool cIptvDevice::ProvidesSource(int sourceP) const
{
debug("cIptvDevice::ProvidesSource(%d)\n", deviceIndex);
return (cSource::IsType(Source, IPTV_SOURCE_CHARACTER));
debug("cIptvDevice::ProvidesSource(%d)\n", deviceIndexM);
return (cSource::IsType(sourceP, IPTV_SOURCE_CHARACTER));
}
bool cIptvDevice::ProvidesTransponder(const cChannel *Channel) const
bool cIptvDevice::ProvidesTransponder(const cChannel *channelP) const
{
debug("cIptvDevice::ProvidesTransponder(%d)\n", deviceIndex);
return (ProvidesSource(Channel->Source()));
debug("cIptvDevice::ProvidesTransponder(%d)\n", deviceIndexM);
return (ProvidesSource(channelP->Source()));
}
bool cIptvDevice::ProvidesChannel(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers) const
bool cIptvDevice::ProvidesChannel(const cChannel *channelP, int priorityP, bool *needsDetachReceiversP) const
{
bool result = false;
bool hasPriority = Priority == IDLEPRIORITY || Priority > this->Priority();
bool hasPriority = (priorityP == IDLEPRIORITY) || (priorityP > this->Priority());
bool needsDetachReceivers = false;
debug("cIptvDevice::ProvidesChannel(%d)\n", deviceIndex);
debug("cIptvDevice::ProvidesChannel(%d)\n", deviceIndexM);
if (Channel && ProvidesTransponder(Channel)) {
if (channelP && ProvidesTransponder(channelP)) {
result = hasPriority;
if (Receiving()) {
if (Channel->GetChannelID() == channelId)
if (channelP->GetChannelID() == channelIdM)
result = true;
else
needsDetachReceivers = Receiving();
}
}
if (NeedsDetachReceivers)
*NeedsDetachReceivers = needsDetachReceivers;
if (needsDetachReceiversP)
*needsDetachReceiversP = needsDetachReceivers;
return result;
}
@ -256,101 +253,101 @@ int cIptvDevice::NumProvidedSystems(void) const
return 1;
}
bool cIptvDevice::SetChannelDevice(const cChannel *Channel, bool LiveView)
bool cIptvDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP)
{
cIptvProtocolIf *protocol;
cIptvTransponderParameters itp(Channel->Parameters());
cIptvTransponderParameters itp(channelP->Parameters());
debug("cIptvDevice::SetChannelDevice(%d)\n", deviceIndex);
debug("cIptvDevice::SetChannelDevice(%d)\n", deviceIndexM);
if (isempty(itp.Address())) {
error("Unrecognized IPTV address: %s", Channel->Parameters());
error("Unrecognized IPTV address: %s", channelP->Parameters());
return false;
}
switch (itp.Protocol()) {
case cIptvTransponderParameters::eProtocolUDP:
protocol = pUdpProtocol;
protocol = pUdpProtocolM;
break;
case cIptvTransponderParameters::eProtocolCURL:
protocol = pCurlProtocol;
protocol = pCurlProtocolM;
break;
case cIptvTransponderParameters::eProtocolHTTP:
protocol = pHttpProtocol;
protocol = pHttpProtocolM;
break;
case cIptvTransponderParameters::eProtocolFILE:
protocol = pFileProtocol;
protocol = pFileProtocolM;
break;
case cIptvTransponderParameters::eProtocolEXT:
protocol = pExtProtocol;
protocol = pExtProtocolM;
break;
default:
error("Unrecognized IPTV protocol: %s", Channel->Parameters());
error("Unrecognized IPTV protocol: %s", channelP->Parameters());
return false;
break;
}
sidScanEnabled = itp.SidScan() ? true : false;
pidScanEnabled = itp.PidScan() ? true : false;
if (pIptvStreamer->Set(itp.Address(), itp.Parameter(), deviceIndex, protocol)) {
channelId = Channel->GetChannelID();
if (sidScanEnabled && pSidScanner && IptvConfig.GetSectionFiltering())
pSidScanner->SetChannel(channelId);
if (pidScanEnabled && pPidScanner)
pPidScanner->SetChannel(channelId);
sidScanEnabledM = itp.SidScan() ? true : false;
pidScanEnabledM = itp.PidScan() ? true : false;
if (pIptvStreamerM->Set(itp.Address(), itp.Parameter(), deviceIndexM, protocol)) {
channelIdM = channelP->GetChannelID();
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
pSidScannerM->SetChannel(channelIdM);
if (pidScanEnabledM && pPidScannerM)
pPidScannerM->SetChannel(channelIdM);
}
return true;
}
bool cIptvDevice::SetPid(cPidHandle *Handle, int Type, bool On)
bool cIptvDevice::SetPid(cPidHandle *handleP, int typeP, bool onP)
{
debug("cIptvDevice::SetPid(%d) Pid=%d Type=%d On=%d\n", deviceIndex, Handle->pid, Type, On);
debug("cIptvDevice::SetPid(%d) Pid=%d Type=%d On=%d\n", deviceIndexM, handleP->pid, typeP, onP);
return true;
}
bool cIptvDevice::DeleteFilter(unsigned int Index)
bool cIptvDevice::DeleteFilter(unsigned int indexP)
{
if ((Index < eMaxSecFilterCount) && secfilters[Index]) {
//debug("cIptvDevice::DeleteFilter(%d) Index=%d\n", deviceIndex, Index);
cIptvSectionFilter *tmp = secfilters[Index];
secfilters[Index] = NULL;
if ((indexP < eMaxSecFilterCount) && secFiltersM[indexP]) {
//debug("cIptvDevice::DeleteFilter(%d) Index=%d\n", deviceIndexM, indexP);
cIptvSectionFilter *tmp = secFiltersM[indexP];
secFiltersM[indexP] = NULL;
delete tmp;
return true;
}
return false;
}
bool cIptvDevice::IsBlackListed(u_short Pid, u_char Tid, u_char Mask) const
bool cIptvDevice::IsBlackListed(u_short pidP, u_char tidP, u_char maskP) const
{
//debug("cIptvDevice::IsBlackListed(%d) Pid=%d Tid=%02X Mask=%02X\n", deviceIndex, Pid, Tid, Mask);
//debug("cIptvDevice::IsBlackListed(%d) Pid=%d Tid=%02X Mask=%02X\n", deviceIndexM, pidP, tidP, maskP);
// loop through section filter table
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i) {
int index = IptvConfig.GetDisabledFilters(i);
// check if matches
if ((index >= 0) && (index < SECTION_FILTER_TABLE_SIZE) &&
(section_filter_table[index].pid == Pid) && (section_filter_table[index].tid == Tid) &&
(section_filter_table[index].mask == Mask)) {
//debug("cIptvDevice::IsBlackListed(%d) Found=%s\n", deviceIndex, section_filter_table[index].description);
(section_filter_table[index].pid == pidP) && (section_filter_table[index].tid == tidP) &&
(section_filter_table[index].mask == maskP)) {
//debug("cIptvDevice::IsBlackListed(%d) Found=%s\n", deviceIndexM, section_filter_table[index].description);
return true;
}
}
return false;
}
int cIptvDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask)
int cIptvDevice::OpenFilter(u_short pidP, u_char tidP, u_char maskP)
{
// Check if disabled by user
if (!IptvConfig.GetSectionFiltering())
return -1;
// Blacklist check, refuse certain filters
if (IsBlackListed(Pid, Tid, Mask))
if (IsBlackListed(pidP, tidP, maskP))
return -1;
// Lock
cMutexLock MutexLock(&mutex);
cMutexLock MutexLock(&mutexM);
// Search the next free filter slot
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (!secfilters[i]) {
//debug("cIptvDevice::OpenFilter(%d): Pid=%d Tid=%02X Mask=%02X Index=%d\n", deviceIndex, Pid, Tid, Mask, i);
secfilters[i] = new cIptvSectionFilter(deviceIndex, Pid, Tid, Mask);
if (secfilters[i])
if (!secFiltersM[i]) {
//debug("cIptvDevice::OpenFilter(%d): Pid=%d Tid=%02X Mask=%02X Index=%d\n", deviceIndexM, pidP, tidP, maskP, i);
secFiltersM[i] = new cIptvSectionFilter(deviceIndexM, pidP, tidP, maskP);
if (secFiltersM[i])
return i;
break;
}
@ -359,99 +356,96 @@ int cIptvDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask)
return -1;
}
int cIptvDevice::ReadFilter(int Handle, void *Buffer, size_t Length)
int cIptvDevice::ReadFilter(int handleP, void *bufferP, size_t lengthP)
{
// Lock
cMutexLock MutexLock(&mutex);
cMutexLock MutexLock(&mutexM);
// ... and load
if (secfilters[Handle]) {
return secfilters[Handle]->Read(Buffer, Length);
//debug("cIptvDevice::ReadFilter(%d): %d %d\n", deviceIndex, Handle, Length);
if (secFiltersM[handleP]) {
return secFiltersM[handleP]->Read(bufferP, lengthP);
//debug("cIptvDevice::ReadFilter(%d): %d %d\n", deviceIndexM, handleP, lengthP);
}
return 0;
}
void cIptvDevice::CloseFilter(int Handle)
void cIptvDevice::CloseFilter(int handleP)
{
// Lock
cMutexLock MutexLock(&mutex);
cMutexLock MutexLock(&mutexM);
// ... and load
if (secfilters[Handle]) {
//debug("cIptvDevice::CloseFilter(%d): %d\n", deviceIndex, Handle);
DeleteFilter(Handle);
if (secFiltersM[handleP]) {
//debug("cIptvDevice::CloseFilter(%d): %d\n", deviceIndexM, handleP);
DeleteFilter(handleP);
}
}
bool cIptvDevice::OpenDvr(void)
{
debug("cIptvDevice::OpenDvr(%d)\n", deviceIndex);
isPacketDelivered = false;
tsBuffer->Clear();
debug("cIptvDevice::OpenDvr(%d)\n", deviceIndexM);
isPacketDeliveredM = false;
tsBufferM->Clear();
ResetBuffering();
if (pIptvStreamer)
pIptvStreamer->Open();
if (sidScanEnabled && pSidScanner && IptvConfig.GetSectionFiltering())
pSidScanner->Open();
isOpenDvr = true;
if (pIptvStreamerM)
pIptvStreamerM->Open();
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
pSidScannerM->Open();
isOpenDvrM = true;
return true;
}
void cIptvDevice::CloseDvr(void)
{
debug("cIptvDevice::CloseDvr(%d)\n", deviceIndex);
if (sidScanEnabled && pSidScanner && IptvConfig.GetSectionFiltering())
pSidScanner->Close();
if (pIptvStreamer)
pIptvStreamer->Close();
isOpenDvr = false;
debug("cIptvDevice::CloseDvr(%d)\n", deviceIndexM);
if (sidScanEnabledM && pSidScannerM && IptvConfig.GetSectionFiltering())
pSidScannerM->Close();
if (pIptvStreamerM)
pIptvStreamerM->Close();
isOpenDvrM = false;
}
bool cIptvDevice::HasLock(int TimeoutMs) const
bool cIptvDevice::HasLock(int timeoutMsP) const
{
//debug("cIptvDevice::HasLock(%d): %d\n", deviceIndex, TimeoutMs);
return (!isBuffering);
//debug("cIptvDevice::HasLock(%d): %d\n", deviceIndexM, timeoutMsP);
return (!IsBuffering());
}
bool cIptvDevice::HasInternalCam(void)
{
//debug("cIptvDevice::HasInternalCam(%d)\n", deviceIndex);
//debug("cIptvDevice::HasInternalCam(%d)\n", deviceIndexM);
return true;
}
void cIptvDevice::ResetBuffering(void)
{
debug("cIptvDevice::ResetBuffering(%d)\n", deviceIndex);
isBuffering = true;
debug("cIptvDevice::ResetBuffering(%d)\n", deviceIndexM);
// pad prefill to multiple of TS_SIZE
tsBufferPrefill = (unsigned int)MEGABYTE(IptvConfig.GetTsBufferSize()) *
tsBufferPrefillM = (unsigned int)MEGABYTE(IptvConfig.GetTsBufferSize()) *
IptvConfig.GetTsBufferPrefillRatio() / 100;
tsBufferPrefill -= (tsBufferPrefill % TS_SIZE);
tsBufferPrefillM -= (tsBufferPrefillM % TS_SIZE);
}
void cIptvDevice::CheckBuffering(void)
bool cIptvDevice::IsBuffering(void) const
{
//debug("cIptvDevice::CheckBuffering(%d): %d\n", deviceIndex);
if (tsBufferPrefill && tsBuffer && tsBuffer->Available() < tsBufferPrefill)
isBuffering = true;
else {
isBuffering = false;
tsBufferPrefill = 0;
}
//debug("cIptvDevice::IsBuffering(%d): %d\n", deviceIndexM);
if (tsBufferPrefillM && tsBufferM && tsBufferM->Available() < tsBufferPrefillM)
return true;
else
tsBufferPrefillM = 0;
return false;
}
bool cIptvDevice::GetTSPacket(uchar *&Data)
{
//debug("cIptvDevice::GetTSPacket(%d)\n", deviceIndex);
CheckBuffering();
if (tsBuffer && !isBuffering) {
if (isPacketDelivered) {
tsBuffer->Del(TS_SIZE);
isPacketDelivered = false;
//debug("cIptvDevice::GetTSPacket(%d)\n", deviceIndexM);
if (tsBufferM && !IsBuffering()) {
if (isPacketDeliveredM) {
tsBufferM->Del(TS_SIZE);
isPacketDeliveredM = false;
// Update buffer statistics
AddBufferStatistic(TS_SIZE, tsBuffer->Available());
AddBufferStatistic(TS_SIZE, tsBufferM->Available());
}
int Count = 0;
uchar *p = tsBuffer->Get(Count);
uchar *p = tsBufferM->Get(Count);
if (p && Count >= TS_SIZE) {
if (*p != TS_SYNC_BYTE) {
for (int i = 1; i < Count; i++) {
@ -460,26 +454,26 @@ bool cIptvDevice::GetTSPacket(uchar *&Data)
break;
}
}
tsBuffer->Del(Count);
tsBufferM->Del(Count);
error("Skipped %d bytes to sync on TS packet\n", Count);
return false;
}
isPacketDelivered = true;
isPacketDeliveredM = true;
Data = p;
// Update pid statistics
AddPidStatistic(ts_pid(p), payload(p));
// Send data also to dvr fifo
if (dvrFd >= 0)
Count = (int)write(dvrFd, p, TS_SIZE);
if (dvrFdM >= 0)
Count = (int)write(dvrFdM, p, TS_SIZE);
// Analyze incomplete streams with built-in pid analyzer
if (pidScanEnabled && pPidScanner)
pPidScanner->Process(p);
if (pidScanEnabledM && pPidScannerM)
pPidScannerM->Process(p);
// Lock
cMutexLock MutexLock(&mutex);
cMutexLock MutexLock(&mutexM);
// Run the data through all filters
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (secfilters[i])
secfilters[i]->Process(p);
if (secFiltersM[i])
secFiltersM[i]->Process(p);
}
return true;
}

View File

@ -34,32 +34,31 @@ private:
enum {
eMaxSecFilterCount = 32
};
unsigned int deviceIndex;
int dvrFd;
bool isPacketDelivered;
bool isOpenDvr;
bool isBuffering;
bool sidScanEnabled;
bool pidScanEnabled;
cRingBufferLinear *tsBuffer;
int tsBufferPrefill;
tChannelID channelId;
cIptvProtocolUdp *pUdpProtocol;
cIptvProtocolCurl *pCurlProtocol;
cIptvProtocolHttp *pHttpProtocol;
cIptvProtocolFile *pFileProtocol;
cIptvProtocolExt *pExtProtocol;
cIptvStreamer *pIptvStreamer;
cPidScanner *pPidScanner;
cSidScanner *pSidScanner;
cMutex mutex;
cIptvSectionFilter *secfilters[eMaxSecFilterCount];
unsigned int deviceIndexM;
int dvrFdM;
bool isPacketDeliveredM;
bool isOpenDvrM;
bool sidScanEnabledM;
bool pidScanEnabledM;
cRingBufferLinear *tsBufferM;
mutable int tsBufferPrefillM;
tChannelID channelIdM;
cIptvProtocolUdp *pUdpProtocolM;
cIptvProtocolCurl *pCurlProtocolM;
cIptvProtocolHttp *pHttpProtocolM;
cIptvProtocolFile *pFileProtocolM;
cIptvProtocolExt *pExtProtocolM;
cIptvStreamer *pIptvStreamerM;
cPidScanner *pPidScannerM;
cSidScanner *pSidScannerM;
cMutex mutexM;
cIptvSectionFilter *secFiltersM[eMaxSecFilterCount];
// constructor & destructor
public:
cIptvDevice(unsigned int DeviceIndex);
cIptvDevice(unsigned int deviceIndexP);
virtual ~cIptvDevice();
cString GetInformation(unsigned int Page = IPTV_DEVICE_INFO_ALL);
cString GetInformation(unsigned int pageP = IPTV_DEVICE_INFO_ALL);
// copy and assignment constructors
private:
@ -74,9 +73,9 @@ private:
// for channel parsing & buffering
private:
void ResetBuffering(void);
void CheckBuffering(void);
bool DeleteFilter(unsigned int Index);
bool IsBlackListed(u_short Pid, u_char Tid, u_char Mask) const;
bool IsBuffering(void) const;
bool DeleteFilter(unsigned int indexP);
bool IsBlackListed(u_short pidP, u_char tidP, u_char maskP) const;
// for channel info
public:
@ -87,30 +86,30 @@ public:
// for channel selection
public:
virtual bool ProvidesSource(int Source) const;
virtual bool ProvidesTransponder(const cChannel *Channel) const;
virtual bool ProvidesChannel(const cChannel *Channel, int Priority = -1, bool *NeedsDetachReceivers = NULL) const;
virtual bool ProvidesSource(int sourceP) const;
virtual bool ProvidesTransponder(const cChannel *channelP) const;
virtual bool ProvidesChannel(const cChannel *channelP, int priorityP = -1, bool *needsDetachReceiversP = NULL) const;
virtual bool ProvidesEIT(void) const;
virtual int NumProvidedSystems(void) const;
protected:
virtual bool SetChannelDevice(const cChannel *Channel, bool LiveView);
virtual bool SetChannelDevice(const cChannel *channelP, bool liveViewP);
// for recording
protected:
virtual bool SetPid(cPidHandle *Handle, int Type, bool On);
virtual bool SetPid(cPidHandle *handleP, int typeP, bool onP);
virtual bool OpenDvr(void);
virtual void CloseDvr(void);
virtual bool GetTSPacket(uchar *&Data);
virtual bool GetTSPacket(uchar *&dataP);
// for section filtering
public:
virtual int OpenFilter(u_short Pid, u_char Tid, u_char Mask);
virtual int ReadFilter(int Handle, void *Buffer, size_t Length);
virtual void CloseFilter(int Handle);
virtual int OpenFilter(u_short pidP, u_char tidP, u_char maskP);
virtual int ReadFilter(int handleP, void *bufferP, size_t lengthP);
virtual void CloseFilter(int handleP);
// for transponder lock
public:
virtual bool HasLock(int) const;
virtual bool HasLock(int timeoutMsP) const;
// for common interface
public:

68
iptv.c
View File

@ -26,8 +26,8 @@ static const char DESCRIPTION[] = trNOOP("Experience the IPTV");
class cPluginIptv : public cPlugin {
private:
unsigned int deviceCount;
int ParseFilters(const char *Value, int *Values);
unsigned int deviceCountM;
int ParseFilters(const char *valueP, int *filtersP);
public:
cPluginIptv(void);
virtual ~cPluginIptv();
@ -52,7 +52,7 @@ public:
};
cPluginIptv::cPluginIptv(void)
: deviceCount(1)
: deviceCountM(1)
{
//debug("cPluginIptv::cPluginIptv()\n");
// Initialize any member variables here.
@ -86,7 +86,7 @@ bool cPluginIptv::ProcessArgs(int argc, char *argv[])
while ((c = getopt_long(argc, argv, "d:", long_options, NULL)) != -1) {
switch (c) {
case 'd':
deviceCount = atoi(optarg);
deviceCountM = atoi(optarg);
break;
default:
return false;
@ -100,7 +100,7 @@ bool cPluginIptv::Initialize(void)
debug("cPluginIptv::Initialize()\n");
// Initialize any background activities the plugin shall perform.
IptvConfig.SetConfigDirectory(cPlugin::ResourceDirectory(PLUGIN_NAME_I18N));
return cIptvDevice::Initialize(deviceCount);
return cIptvDevice::Initialize(deviceCountM);
}
bool cPluginIptv::Start(void)
@ -162,40 +162,40 @@ cMenuSetupPage *cPluginIptv::SetupMenu(void)
return new cIptvPluginSetup();
}
int cPluginIptv::ParseFilters(const char *Value, int *Filters)
int cPluginIptv::ParseFilters(const char *valueP, int *filtersP)
{
debug("cPluginIptv::ParseFilters(): Value=%s\n", Value);
debug("cPluginIptv::ParseFilters(%s)\n", valueP);
char buffer[256];
int n = 0;
while (Value && *Value && (n < SECTION_FILTER_TABLE_SIZE)) {
strn0cpy(buffer, Value, sizeof(buffer));
while (valueP && *valueP && (n < SECTION_FILTER_TABLE_SIZE)) {
strn0cpy(buffer, valueP, sizeof(buffer));
int i = atoi(buffer);
//debug("cPluginIptv::ParseFilters(): Filters[%d]=%d\n", n, i);
if (i >= 0)
Filters[n++] = i;
if ((Value = strchr(Value, ' ')) != NULL)
Value++;
filtersP[n++] = i;
if ((valueP = strchr(valueP, ' ')) != NULL)
valueP++;
}
return n;
}
bool cPluginIptv::SetupParse(const char *Name, const char *Value)
bool cPluginIptv::SetupParse(const char *nameP, const char *valueP)
{
debug("cPluginIptv::SetupParse()\n");
// Parse your own setup parameters and store their values.
if (!strcasecmp(Name, "TsBufferSize"))
IptvConfig.SetTsBufferSize(atoi(Value));
else if (!strcasecmp(Name, "TsBufferPrefill"))
IptvConfig.SetTsBufferPrefillRatio(atoi(Value));
else if (!strcasecmp(Name, "ExtProtocolBasePort"))
IptvConfig.SetExtProtocolBasePort(atoi(Value));
else if (!strcasecmp(Name, "SectionFiltering"))
IptvConfig.SetSectionFiltering(atoi(Value));
else if (!strcasecmp(Name, "DisabledFilters")) {
if (!strcasecmp(nameP, "TsBufferSize"))
IptvConfig.SetTsBufferSize(atoi(valueP));
else if (!strcasecmp(nameP, "TsBufferPrefill"))
IptvConfig.SetTsBufferPrefillRatio(atoi(valueP));
else if (!strcasecmp(nameP, "ExtProtocolBasePort"))
IptvConfig.SetExtProtocolBasePort(atoi(valueP));
else if (!strcasecmp(nameP, "SectionFiltering"))
IptvConfig.SetSectionFiltering(atoi(valueP));
else if (!strcasecmp(nameP, "DisabledFilters")) {
int DisabledFilters[SECTION_FILTER_TABLE_SIZE];
for (unsigned int i = 0; i < ARRAY_SIZE(DisabledFilters); ++i)
DisabledFilters[i] = -1;
unsigned int DisabledFiltersCount = ParseFilters(Value, DisabledFilters);
unsigned int DisabledFiltersCount = ParseFilters(valueP, DisabledFilters);
for (unsigned int i = 0; i < DisabledFiltersCount; ++i)
IptvConfig.SetDisabledFilters(i, DisabledFilters[i]);
}
@ -204,12 +204,12 @@ bool cPluginIptv::SetupParse(const char *Name, const char *Value)
return true;
}
bool cPluginIptv::Service(const char *Id, void *Data)
bool cPluginIptv::Service(const char *idP, void *dataP)
{
debug("cPluginIptv::Service()\n");
if (strcmp(Id,"IptvService-v1.0") == 0) {
if (Data) {
IptvService_v1_0 *data = reinterpret_cast<IptvService_v1_0*>(Data);
if (strcmp(idP,"IptvService-v1.0") == 0) {
if (dataP) {
IptvService_v1_0 *data = reinterpret_cast<IptvService_v1_0*>(dataP);
cIptvDevice *dev = cIptvDevice::GetIptvDevice(data->cardIndex);
if (!dev)
return false;
@ -236,26 +236,26 @@ const char **cPluginIptv::SVDRPHelpPages(void)
return HelpPages;
}
cString cPluginIptv::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
cString cPluginIptv::SVDRPCommand(const char *commandP, const char *optionP, int &replyCodeP)
{
debug("cPluginIptv::SVDRPCommand(): Command=%s Option=%s\n", Command, Option);
if (strcasecmp(Command, "INFO") == 0) {
debug("cPluginIptv::SVDRPCommand('%s', %s')\n", commandP, optionP);
if (strcasecmp(commandP, "INFO") == 0) {
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device) {
int page = IPTV_DEVICE_INFO_ALL;
if (Option) {
page = atoi(Option);
if (optionP) {
page = atoi(optionP);
if ((page < IPTV_DEVICE_INFO_ALL) || (page > IPTV_DEVICE_INFO_FILTERS))
page = IPTV_DEVICE_INFO_ALL;
}
return device->GetInformation(page);
}
else {
ReplyCode = 550; // Requested action not taken
replyCodeP = 550; // Requested action not taken
return cString("IPTV information not available!");
}
}
else if (strcasecmp(Command, "MODE") == 0) {
else if (strcasecmp(commandP, "MODE") == 0) {
unsigned int mode = !IptvConfig.GetUseBytes();
IptvConfig.SetUseBytes(mode);
return cString::sprintf("IPTV information mode is: %s\n", mode ? "bytes" : "bits");

View File

@ -14,13 +14,13 @@
#define PIDSCANNER_PID_DELTA_COUNT 100 /* minimum count of pid samples for audio/video only pid detection */
cPidScanner::cPidScanner(void)
: timeout(0),
channelId(tChannelID::InvalidID),
process(true),
Vpid(0xFFFF),
Apid(0xFFFF),
numVpids(0),
numApids(0)
: timeoutM(0),
channelIdM(tChannelID::InvalidID),
processM(true),
vPidM(0xFFFF),
aPidM(0xFFFF),
numVpidsM(0),
numApidsM(0)
{
debug("cPidScanner::cPidScanner()\n");
}
@ -30,90 +30,90 @@ cPidScanner::~cPidScanner()
debug("cPidScanner::~cPidScanner()\n");
}
void cPidScanner::SetChannel(const tChannelID &ChannelId)
void cPidScanner::SetChannel(const tChannelID &channelIdP)
{
debug("cPidScanner::SetChannel(): %s\n", *ChannelId.ToString());
channelId = ChannelId;
Vpid = 0xFFFF;
numVpids = 0;
Apid = 0xFFFF;
numApids = 0;
process = true;
timeout.Set(PIDSCANNER_TIMEOUT_IN_MS);
debug("cPidScanner::SetChannel(): %s\n", *channelIdP.ToString());
channelIdM = channelIdP;
vPidM = 0xFFFF;
numVpidsM = 0;
aPidM = 0xFFFF;
numApidsM = 0;
processM = true;
timeoutM.Set(PIDSCANNER_TIMEOUT_IN_MS);
}
void cPidScanner::Process(const uint8_t* buf)
void cPidScanner::Process(const uint8_t* bufP)
{
//debug("cPidScanner::Process()\n");
if (!process)
if (!processM)
return;
// Stop scanning after defined timeout
if (timeout.TimedOut()) {
if (timeoutM.TimedOut()) {
debug("cPidScanner::Process: Timed out determining pids\n");
process = false;
processM = false;
}
// Verify TS packet
if (buf[0] != 0x47) {
error("Not TS packet: 0x%X\n", buf[0]);
if (bufP[0] != 0x47) {
error("Not TS packet: 0x%X\n", bufP[0]);
return;
}
// Found TS packet
int pid = ts_pid(buf);
int xpid = (buf[1] << 8 | buf[2]);
int pid = ts_pid(bufP);
int xpid = (bufP[1] << 8 | bufP[2]);
// Check if payload available
uint8_t count = payload(buf);
uint8_t count = payload(bufP);
if (count == 0)
return;
if (xpid & 0x4000) {
// Stream start (Payload Unit Start Indicator)
uchar *d = (uint8_t*)buf;
uchar *d = (uint8_t*)bufP;
d += 4;
// pointer to payload
if (buf[3] & 0x20)
if (bufP[3] & 0x20)
d += d[0] + 1;
// Skip adaption field
if (buf[3] & 0x10) {
if (bufP[3] & 0x10) {
// Payload present
if ((d[0] == 0) && (d[1] == 0) && (d[2] == 1)) {
// PES packet start
int sid = d[3];
// Stream ID
if ((sid >= 0xC0) && (sid <= 0xDF)) {
if (pid < Apid) {
debug("cPidScanner::Process: Found lower Apid: 0x%X instead of 0x%X\n", pid, Apid);
Apid = pid;
numApids = 1;
if (pid < aPidM) {
debug("cPidScanner::Process: Found lower Apid: 0x%X instead of 0x%X\n", pid, aPidM);
aPidM = pid;
numApidsM = 1;
}
else if (pid == Apid) {
++numApids;
debug("cPidScanner::Process: Incrementing Apids, now at %d\n", numApids);
else if (pid == aPidM) {
++numApidsM;
debug("cPidScanner::Process: Incrementing Apids, now at %d\n", numApidsM);
}
}
else if ((sid >= 0xE0) && (sid <= 0xEF)) {
if (pid < Vpid) {
debug("cPidScanner::Process: Found lower Vpid: 0x%X instead of 0x%X\n", pid, Vpid);
Vpid = pid;
numVpids = 1;
if (pid < vPidM) {
debug("cPidScanner::Process: Found lower Vpid: 0x%X instead of 0x%X\n", pid, vPidM);
vPidM = pid;
numVpidsM = 1;
}
else if (pid == Vpid) {
++numVpids;
debug("cPidScanner::Process: Incrementing Vpids, now at %d\n", numVpids);
else if (pid == vPidM) {
++numVpidsM;
debug("cPidScanner::Process: Incrementing Vpids, now at %d\n", numVpidsM);
}
}
}
if (((numVpids >= PIDSCANNER_VPID_COUNT) && (numApids >= PIDSCANNER_APID_COUNT)) ||
(abs(numApids - numVpids) >= PIDSCANNER_PID_DELTA_COUNT)) {
if (((numVpidsM >= PIDSCANNER_VPID_COUNT) && (numApidsM >= PIDSCANNER_APID_COUNT)) ||
(abs(numApidsM - numVpidsM) >= PIDSCANNER_PID_DELTA_COUNT)) {
// Lock channels for pid updates
if (!Channels.Lock(true, 10)) {
timeout.Set(PIDSCANNER_TIMEOUT_IN_MS);
timeoutM.Set(PIDSCANNER_TIMEOUT_IN_MS);
return;
}
cChannel *IptvChannel = Channels.GetByChannelID(channelId);
cChannel *IptvChannel = Channels.GetByChannelID(channelIdM);
if (IptvChannel) {
int Apids[MAXAPIDS + 1] = { 0 }; // these lists are zero-terminated
int Atypes[MAXAPIDS + 1] = { 0 };
@ -127,18 +127,18 @@ void cPidScanner::Process(const uint8_t* buf)
int Ppid = IptvChannel->Ppid();
int Tpid = IptvChannel->Tpid();
bool foundApid = false;
if (numVpids < PIDSCANNER_VPID_COUNT)
Vpid = 0; // No detected video pid
else if (numApids < PIDSCANNER_APID_COUNT)
Apid = 0; // No detected audio pid
if (numVpidsM < PIDSCANNER_VPID_COUNT)
vPidM = 0; // No detected video pid
else if (numApidsM < PIDSCANNER_APID_COUNT)
aPidM = 0; // No detected audio pid
for (unsigned int i = 0; i < MAXAPIDS; ++i) {
Apids[i] = IptvChannel->Apid(i);
Atypes[i] = IptvChannel->Atype(i);
if (Apids[i] && (Apids[i] == Apid))
if (Apids[i] && (Apids[i] == aPidM))
foundApid = true;
}
if (!foundApid) {
Apids[0] = Apid;
Apids[0] = aPidM;
Atypes[0] = 4;
}
for (unsigned int i = 0; i < MAXDPIDS; ++i) {
@ -147,11 +147,11 @@ void cPidScanner::Process(const uint8_t* buf)
}
for (unsigned int i = 0; i < MAXSPIDS; ++i)
Spids[i] = IptvChannel->Spid(i);
debug("cPidScanner::Process(): Vpid=0x%04X, Apid=0x%04X\n", Vpid, Apid);
IptvChannel->SetPids(Vpid, Ppid, Vtype, Apids, Atypes, ALangs, Dpids, Dtypes, DLangs, Spids, SLangs, Tpid);
debug("cPidScanner::Process(): Vpid=0x%04X, Apid=0x%04X\n", vPidM, aPidM);
IptvChannel->SetPids(vPidM, Ppid, Vtype, Apids, Atypes, ALangs, Dpids, Dtypes, DLangs, Spids, SLangs, Tpid);
}
Channels.Unlock();
process = false;
processM = false;
}
}
}

View File

@ -13,19 +13,19 @@
class cPidScanner {
private:
cTimeMs timeout;
tChannelID channelId;
bool process;
int Vpid;
int Apid;
int numVpids;
int numApids;
cTimeMs timeoutM;
tChannelID channelIdM;
bool processM;
int vPidM;
int aPidM;
int numVpidsM;
int numApidsM;
public:
cPidScanner(void);
~cPidScanner();
void SetChannel(const tChannelID &ChannelId);
void Process(const uint8_t* buf);
void SetChannel(const tChannelID &channelIdP);
void Process(const uint8_t* bufP);
};
#endif // __PIDSCANNER_H

View File

@ -404,7 +404,7 @@ bool cIptvProtocolCurl::Close(void)
return true;
}
int cIptvProtocolCurl::Read(unsigned char* BufferAddr, unsigned int BufferLen)
int cIptvProtocolCurl::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
{
//debug("cIptvProtocolCurl::Read()\n");
int len = 0;
@ -462,11 +462,11 @@ int cIptvProtocolCurl::Read(unsigned char* BufferAddr, unsigned int BufferLen)
}
// ... and try to empty it
unsigned char *p = GetData(&BufferLen);
if (p && (BufferLen > 0)) {
memcpy(BufferAddr, p, BufferLen);
DelData(BufferLen);
len = BufferLen;
unsigned char *p = GetData(&bufferLenP);
if (p && (bufferLenP > 0)) {
memcpy(bufferAddrP, p, bufferLenP);
DelData(bufferLenP);
len = bufferLenP;
//debug("cIptvProtocolCurl::Read(): get %d bytes\n", len);
}
}
@ -474,14 +474,14 @@ int cIptvProtocolCurl::Read(unsigned char* BufferAddr, unsigned int BufferLen)
return len;
}
bool cIptvProtocolCurl::Set(const char* Location, const int Parameter, const int Index)
bool cIptvProtocolCurl::Set(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolCurl::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
if (!isempty(Location)) {
debug("cIptvProtocolCurl::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
if (!isempty(locationP)) {
// Disconnect
Disconnect();
// Update stream URL: colons (%3A) and pipes (%7C) shall be decoded
char *s = strdup(Location);
char *s = strdup(locationP);
strreplace(s, "%3A", ":");
strreplace(s, "%7C", "|");
streamUrlM = s;
@ -497,7 +497,7 @@ bool cIptvProtocolCurl::Set(const char* Location, const int Parameter, const int
else
modeM = eModeUnknown;
// Update stream parameter
streamParamM = Parameter;
streamParamM = parameterP;
//debug("%s [%d]\n", *streamUrlM, streamParamM);
// Reconnect
Connect();

View File

@ -60,8 +60,8 @@ private:
public:
cIptvProtocolCurl();
virtual ~cIptvProtocolCurl();
int Read(unsigned char* BufferAddr, unsigned int BufferLen);
bool Set(const char* Location, const int Parameter, const int Index);
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@ -24,10 +24,10 @@
#endif
cIptvProtocolExt::cIptvProtocolExt()
: pid(-1),
scriptFile(""),
scriptParameter(0),
streamPort(0)
: pidM(-1),
scriptFileM(""),
scriptParameterM(0),
streamPortM(0)
{
debug("cIptvProtocolExt::cIptvProtocolExt()\n");
}
@ -43,22 +43,22 @@ void cIptvProtocolExt::ExecuteScript(void)
{
debug("cIptvProtocolExt::ExecuteScript()\n");
// Check if already executing
if (isActive || isempty(scriptFile))
if (isActive || isempty(scriptFileM))
return;
if (pid > 0) {
if (pidM > 0) {
error("Cannot execute script!");
return;
}
// Let's fork
ERROR_IF_RET((pid = fork()) == -1, "fork()", return);
ERROR_IF_RET((pidM = fork()) == -1, "fork()", return);
// Check if child process
if (pid == 0) {
if (pidM == 0) {
// Close all dup'ed filedescriptors
int MaxPossibleFileDescriptors = getdtablesize();
for (int i = STDERR_FILENO + 1; i < MaxPossibleFileDescriptors; i++)
close(i);
// Execute the external script
cString cmd = cString::sprintf("%s %d %d", *scriptFile, scriptParameter, streamPort);
cString cmd = cString::sprintf("%s %d %d", *scriptFileM, scriptParameterM, streamPortM);
debug("cIptvProtocolExt::ExecuteScript(child): %s\n", *cmd);
// Create a new session for a process group
ERROR_IF_RET(setsid() == -1, "setsid()", _exit(-1));
@ -69,38 +69,38 @@ void cIptvProtocolExt::ExecuteScript(void)
_exit(0);
}
else {
debug("cIptvProtocolExt::ExecuteScript(): pid=%d\n", pid);
debug("cIptvProtocolExt::ExecuteScript(): pid=%d\n", pidM);
}
}
void cIptvProtocolExt::TerminateScript(void)
{
debug("cIptvProtocolExt::TerminateScript(): pid=%d\n", pid);
if (!isActive || isempty(scriptFile))
debug("cIptvProtocolExt::TerminateScript(): pid=%d\n", pidM);
if (!isActive || isempty(scriptFileM))
return;
if (pid > 0) {
if (pidM > 0) {
const unsigned int timeoutms = 100;
unsigned int waitms = 0;
bool waitOver = false;
// Signal and wait for termination
int retval = killpg(pid, SIGINT);
int retval = killpg(pidM, SIGINT);
ERROR_IF_RET(retval < 0, "kill()", waitOver = true);
while (!waitOver) {
retval = 0;
waitms += timeoutms;
if ((waitms % 2000) == 0) {
error("Script '%s' won't terminate - killing it!", *scriptFile);
killpg(pid, SIGKILL);
error("Script '%s' won't terminate - killing it!", *scriptFileM);
killpg(pidM, SIGKILL);
}
// Clear wait status to make sure child exit status is accessible
// and wait for child termination
#ifdef __FreeBSD__
int waitStatus = 0;
retval = waitpid(pid, &waitStatus, WNOHANG);
retval = waitpid(pidM, &waitStatus, WNOHANG);
#else // __FreeBSD__
siginfo_t waitStatus;
memset(&waitStatus, '\0', sizeof(waitStatus));
retval = waitid(P_PID, pid, &waitStatus, (WNOHANG | WEXITED));
retval = waitid(P_PID, pidM, &waitStatus, (WNOHANG | WEXITED));
#endif // __FreeBSD__
ERROR_IF_RET(retval < 0, "waitid()", waitOver = true);
// These are the acceptable conditions under which child exit is
@ -108,17 +108,17 @@ void cIptvProtocolExt::TerminateScript(void)
#ifdef __FreeBSD__
if (retval > 0 && (WIFEXITED(waitStatus) || WIFSIGNALED(waitStatus))) {
#else // __FreeBSD__
if (!retval && waitStatus.si_pid && (waitStatus.si_pid == pid) &&
if (!retval && waitStatus.si_pid && (waitStatus.si_pid == pidM) &&
((waitStatus.si_code == CLD_EXITED) || (waitStatus.si_code == CLD_KILLED))) {
#endif // __FreeBSD__
debug("Child (%d) exited as expected\n", pid);
debug("Child (%d) exited as expected\n", pidM);
waitOver = true;
}
// Unsuccessful wait, avoid busy looping
if (!waitOver)
cCondWait::SleepMs(timeoutms);
}
pid = -1;
pidM = -1;
}
}
@ -126,10 +126,10 @@ bool cIptvProtocolExt::Open(void)
{
debug("cIptvProtocolExt::Open()\n");
// Reject empty script files
if (!strlen(*scriptFile))
if (!strlen(*scriptFileM))
return false;
// Create the listening socket
OpenSocket(streamPort);
OpenSocket(streamPortM);
// Execute the external script
ExecuteScript();
isActive = true;
@ -147,25 +147,25 @@ bool cIptvProtocolExt::Close(void)
return true;
}
int cIptvProtocolExt::Read(unsigned char* BufferAddr, unsigned int BufferLen)
int cIptvProtocolExt::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
{
return cIptvUdpSocket::Read(BufferAddr, BufferLen);
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
bool cIptvProtocolExt::Set(const char* Location, const int Parameter, const int Index)
bool cIptvProtocolExt::Set(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolExt::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
if (!isempty(Location)) {
debug("cIptvProtocolExt::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
if (!isempty(locationP)) {
struct stat stbuf;
// Update script file and parameter
scriptFile = cString::sprintf("%s/%s", IptvConfig.GetConfigDirectory(), Location);
if ((stat(*scriptFile, &stbuf) != 0) || (strstr(*scriptFile, "..") != 0)) {
error("Non-existent or relative path script '%s'", *scriptFile);
scriptFileM = cString::sprintf("%s/%s", IptvConfig.GetConfigDirectory(), locationP);
if ((stat(*scriptFileM, &stbuf) != 0) || (strstr(*scriptFileM, "..") != 0)) {
error("Non-existent or relative path script '%s'", *scriptFileM);
return false;
}
scriptParameter = Parameter;
scriptParameterM = parameterP;
// Update listen port
streamPort = IptvConfig.GetExtProtocolBasePort() + Index;
streamPortM = IptvConfig.GetExtProtocolBasePort() + indexP;
}
return true;
}
@ -173,5 +173,5 @@ bool cIptvProtocolExt::Set(const char* Location, const int Parameter, const int
cString cIptvProtocolExt::GetInformation(void)
{
//debug("cIptvProtocolExt::GetInformation()");
return cString::sprintf("ext://%s:%d", *scriptFile, scriptParameter);
return cString::sprintf("ext://%s:%d", *scriptFileM, scriptParameterM);
}

View File

@ -14,10 +14,10 @@
class cIptvProtocolExt : public cIptvUdpSocket, public cIptvProtocolIf {
private:
int pid;
cString scriptFile;
int scriptParameter;
int streamPort;
int pidM;
cString scriptFileM;
int scriptParameterM;
int streamPortM;
private:
void TerminateScript(void);
@ -26,8 +26,8 @@ private:
public:
cIptvProtocolExt();
virtual ~cIptvProtocolExt();
int Read(unsigned char* BufferAddr, unsigned int BufferLen);
bool Set(const char* Location, const int Parameter, const int Index);
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@ -15,12 +15,12 @@
#include "protocolfile.h"
cIptvProtocolFile::cIptvProtocolFile()
: fileDelay(0),
fileStream(NULL),
isActive(false)
: fileLocationM(strdup("")),
fileDelayM(0),
fileStreamM(NULL),
isActiveM(false)
{
debug("cIptvProtocolFile::cIptvProtocolFile()\n");
fileLocation = strdup("");
}
cIptvProtocolFile::~cIptvProtocolFile()
@ -29,18 +29,18 @@ cIptvProtocolFile::~cIptvProtocolFile()
// Drop open handles
cIptvProtocolFile::Close();
// Free allocated memory
free(fileLocation);
free(fileLocationM);
}
bool cIptvProtocolFile::OpenFile(void)
{
debug("cIptvProtocolFile::OpenFile()\n");
// Check that stream address is valid
if (!isActive && !isempty(fileLocation)) {
fileStream = fopen(fileLocation, "rb");
ERROR_IF_RET(!fileStream || ferror(fileStream), "fopen()", return false);
if (!isActiveM && !isempty(fileLocationM)) {
fileStreamM = fopen(fileLocationM, "rb");
ERROR_IF_RET(!fileStreamM || ferror(fileStreamM), "fopen()", return false);
// Update active flag
isActive = true;
isActiveM = true;
}
return true;
}
@ -49,33 +49,33 @@ void cIptvProtocolFile::CloseFile(void)
{
debug("cIptvProtocolFile::CloseFile()\n");
// Check that file stream is valid
if (isActive && !isempty(fileLocation)) {
fclose(fileStream);
if (isActiveM && !isempty(fileLocationM)) {
fclose(fileStreamM);
// Update active flag
isActive = false;
isActiveM = false;
}
}
int cIptvProtocolFile::Read(unsigned char* BufferAddr, unsigned int BufferLen)
int cIptvProtocolFile::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
{
//debug("cIptvProtocolFile::Read()\n");
// Check errors
if (ferror(fileStream)) {
if (ferror(fileStreamM)) {
debug("Read error\n");
return -1;
}
// Rewind if EOF
if (feof(fileStream))
rewind(fileStream);
if (feof(fileStreamM))
rewind(fileStreamM);
// Sleep before reading the file stream to prevent aggressive busy looping
// and prevent transfer ringbuffer overflows
if (fileDelay)
cCondWait::SleepMs(fileDelay);
if (fileDelayM)
cCondWait::SleepMs(fileDelayM);
// This check is to prevent a race condition where file may be switched off
// during the sleep and buffers are disposed. Check here that the plugin is
// still active before accessing the buffers
if (isActive)
return (int)fread(BufferAddr, sizeof(unsigned char), BufferLen, fileStream);
if (isActiveM)
return (int)fread(bufferAddrP, sizeof(unsigned char), bufferLenP, fileStreamM);
return -1;
}
@ -95,15 +95,15 @@ bool cIptvProtocolFile::Close(void)
return true;
}
bool cIptvProtocolFile::Set(const char* Location, const int Parameter, const int Index)
bool cIptvProtocolFile::Set(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolFile::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
if (!isempty(Location)) {
debug("cIptvProtocolFile::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
if (!isempty(locationP)) {
// Close the file stream
CloseFile();
// Update stream address and port
fileLocation = strcpyrealloc(fileLocation, Location);
fileDelay = Parameter;
fileLocationM = strcpyrealloc(fileLocationM, locationP);
fileDelayM = parameterP;
// Open the file for input
OpenFile();
}
@ -113,5 +113,5 @@ bool cIptvProtocolFile::Set(const char* Location, const int Parameter, const int
cString cIptvProtocolFile::GetInformation(void)
{
//debug("cIptvProtocolFile::GetInformation()");
return cString::sprintf("file://%s:%d", fileLocation, fileDelay);
return cString::sprintf("file://%s:%d", fileLocationM, fileDelayM);
}

View File

@ -13,10 +13,10 @@
class cIptvProtocolFile : public cIptvProtocolIf {
private:
char* fileLocation;
int fileDelay;
FILE* fileStream;
bool isActive;
char* fileLocationM;
int fileDelayM;
FILE* fileStreamM;
bool isActiveM;
private:
bool OpenFile(void);
@ -25,8 +25,8 @@ private:
public:
cIptvProtocolFile();
virtual ~cIptvProtocolFile();
int Read(unsigned char* BufferAddr, unsigned int BufferLen);
bool Set(const char* Location, const int Parameter, const int Index);
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@ -19,9 +19,9 @@
#include "protocolhttp.h"
cIptvProtocolHttp::cIptvProtocolHttp()
: streamAddr(strdup("")),
streamPath(strdup("/")),
streamPort(0)
: streamAddrM(strdup("")),
streamPathM(strdup("/")),
streamPortM(0)
{
debug("cIptvProtocolHttp::cIptvProtocolHttp()\n");
}
@ -32,17 +32,17 @@ cIptvProtocolHttp::~cIptvProtocolHttp()
// Close the socket
cIptvProtocolHttp::Close();
// Free allocated memory
free(streamPath);
free(streamAddr);
free(streamPathM);
free(streamAddrM);
}
bool cIptvProtocolHttp::Connect(void)
{
debug("cIptvProtocolHttp::Connect()\n");
// Check that stream address is valid
if (!isActive && !isempty(streamAddr) && !isempty(streamPath)) {
if (!isActive && !isempty(streamAddrM) && !isempty(streamPathM)) {
// Ensure that socket is valid and connect
OpenSocket(streamPort, streamAddr);
OpenSocket(streamPortM, streamAddrM);
if (!ConnectSocket()) {
CloseSocket();
return false;
@ -53,7 +53,8 @@ bool cIptvProtocolHttp::Connect(void)
"User-Agent: vdr-%s/%s\r\n"
"Range: bytes=0-\r\n"
"Connection: Close\r\n"
"\r\n", streamPath, streamAddr, PLUGIN_NAME_I18N, VERSION);
"\r\n", streamPathM, streamAddrM,
PLUGIN_NAME_I18N, VERSION);
debug("Sending http request: %s\n", *buffer);
if (!Write(*buffer, (unsigned int)strlen(*buffer))) {
CloseSocket();
@ -82,16 +83,16 @@ bool cIptvProtocolHttp::Disconnect(void)
return true;
}
bool cIptvProtocolHttp::GetHeaderLine(char* dest, unsigned int destLen,
unsigned int &recvLen)
bool cIptvProtocolHttp::GetHeaderLine(char* destP, unsigned int destLenP,
unsigned int &recvLenP)
{
debug("cIptvProtocolHttp::GetHeaderLine()\n");
bool linefeed = false;
bool newline = false;
char *bufptr = dest;
recvLen = 0;
char *bufptr = destP;
recvLenP = 0;
if (!dest)
if (!destP)
return false;
while (!newline || !linefeed) {
@ -106,13 +107,13 @@ bool cIptvProtocolHttp::GetHeaderLine(char* dest, unsigned int destLen,
// Saw just data or \r without \n
else {
linefeed = false;
++recvLen;
++recvLenP;
}
++bufptr;
// Check that buffer won't be exceeded
if (recvLen >= destLen) {
if (recvLenP >= destLenP) {
error("Header wouldn't fit into buffer\n");
recvLen = 0;
recvLenP = 0;
return false;
}
}
@ -170,28 +171,28 @@ bool cIptvProtocolHttp::Close(void)
return true;
}
int cIptvProtocolHttp::Read(unsigned char* BufferAddr, unsigned int BufferLen)
int cIptvProtocolHttp::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
{
return cIptvTcpSocket::Read(BufferAddr, BufferLen);
return cIptvTcpSocket::Read(bufferAddrP, bufferLenP);
}
bool cIptvProtocolHttp::Set(const char* Location, const int Parameter, const int Index)
bool cIptvProtocolHttp::Set(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolHttp::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
if (!isempty(Location)) {
debug("cIptvProtocolHttp::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
if (!isempty(locationP)) {
// Disconnect the current socket
Disconnect();
// Update stream address, path and port
streamAddr = strcpyrealloc(streamAddr, Location);
char *path = strstr(streamAddr, "/");
streamAddrM = strcpyrealloc(streamAddrM, locationP);
char *path = strstr(streamAddrM, "/");
if (path) {
streamPath = strcpyrealloc(streamPath, path);
streamPathM = strcpyrealloc(streamPathM, path);
*path = 0;
}
else
streamPath = strcpyrealloc(streamPath, "/");
streamPort = Parameter;
//debug("http://%s:%d%s\n", streamAddr, streamPort, streamPath);
streamPathM = strcpyrealloc(streamPathM, "/");
streamPortM = parameterP;
//debug("http://%s:%d%s\n", streamAddrM, streamPortM, streamPathM);
// Re-connect the socket
Connect();
}
@ -201,5 +202,5 @@ bool cIptvProtocolHttp::Set(const char* Location, const int Parameter, const int
cString cIptvProtocolHttp::GetInformation(void)
{
//debug("cIptvProtocolHttp::GetInformation()");
return cString::sprintf("http://%s:%d%s", streamAddr, streamPort, streamPath);
return cString::sprintf("http://%s:%d%s", streamAddrM, streamPortM, streamPathM);
}

View File

@ -14,21 +14,21 @@
class cIptvProtocolHttp : public cIptvTcpSocket, public cIptvProtocolIf {
private:
char* streamAddr;
char* streamPath;
int streamPort;
char* streamAddrM;
char* streamPathM;
int streamPortM;
private:
bool Connect(void);
bool Disconnect(void);
bool GetHeaderLine(char* dest, unsigned int destLen, unsigned int &recvLen);
bool GetHeaderLine(char* destP, unsigned int destLenP, unsigned int &recvLenP);
bool ProcessHeaders(void);
public:
cIptvProtocolHttp();
virtual ~cIptvProtocolHttp();
int Read(unsigned char* BufferAddr, unsigned int BufferLen);
bool Set(const char* Location, const int Parameter, const int Index);
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@ -12,8 +12,8 @@ class cIptvProtocolIf {
public:
cIptvProtocolIf() {}
virtual ~cIptvProtocolIf() {}
virtual int Read(unsigned char* BufferAddr, unsigned int BufferLen) = 0;
virtual bool Set(const char* Location, const int Parameter, const int Index) = 0;
virtual int Read(unsigned char* bufferAddrP, unsigned int bufferLenP) = 0;
virtual bool Set(const char* locationP, const int parameterP, const int indexP) = 0;
virtual bool Open(void) = 0;
virtual bool Close(void) = 0;
virtual cString GetInformation(void) = 0;

View File

@ -19,10 +19,10 @@
#include "socket.h"
cIptvProtocolUdp::cIptvProtocolUdp()
: isIGMPv3(false),
sourceAddr(strdup("")),
streamAddr(strdup("")),
streamPort(0)
: isIGMPv3M(false),
sourceAddrM(strdup("")),
streamAddrM(strdup("")),
streamPortM(0)
{
debug("cIptvProtocolUdp::cIptvProtocolUdp()\n");
}
@ -33,15 +33,15 @@ cIptvProtocolUdp::~cIptvProtocolUdp()
// Drop the multicast group and close the socket
cIptvProtocolUdp::Close();
// Free allocated memory
free(streamAddr);
free(sourceAddr);
free(streamAddrM);
free(sourceAddrM);
}
bool cIptvProtocolUdp::Open(void)
{
debug("cIptvProtocolUdp::Open(): streamAddr=%s\n", streamAddr);
OpenSocket(streamPort, streamAddr, sourceAddr, isIGMPv3);
if (!isempty(streamAddr)) {
debug("cIptvProtocolUdp::Open(): '%s'\n", streamAddrM);
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
if (!isempty(streamAddrM)) {
// Join a new multicast group
JoinMulticast();
}
@ -50,53 +50,53 @@ bool cIptvProtocolUdp::Open(void)
bool cIptvProtocolUdp::Close(void)
{
debug("cIptvProtocolUdp::Close(): streamAddr=%s\n", streamAddr);
if (!isempty(streamAddr)) {
debug("cIptvProtocolUdp::Close(): '%s'\n", streamAddrM);
if (!isempty(streamAddrM)) {
// Drop the multicast group
OpenSocket(streamPort, streamAddr, sourceAddr, isIGMPv3);
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
DropMulticast();
}
// Close the socket
CloseSocket();
// Do NOT reset stream and source addresses
//sourceAddr = strcpyrealloc(sourceAddr, "");
//streamAddr = strcpyrealloc(streamAddr, "");
//streamPort = 0;
//sourceAddrM = strcpyrealloc(sourceAddrM, "");
//streamAddrM = strcpyrealloc(streamAddrM, "");
//streamPortM = 0;
return true;
}
int cIptvProtocolUdp::Read(unsigned char* BufferAddr, unsigned int BufferLen)
int cIptvProtocolUdp::Read(unsigned char* bufferAddrP, unsigned int bufferLenP)
{
return cIptvUdpSocket::Read(BufferAddr, BufferLen);
return cIptvUdpSocket::Read(bufferAddrP, bufferLenP);
}
bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int Index)
bool cIptvProtocolUdp::Set(const char* locationP, const int parameterP, const int indexP)
{
debug("cIptvProtocolUdp::Set(): Location=%s Parameter=%d Index=%d\n", Location, Parameter, Index);
if (!isempty(Location)) {
debug("cIptvProtocolUdp::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
if (!isempty(locationP)) {
// Drop the multicast group
if (!isempty(streamAddr)) {
OpenSocket(streamPort, streamAddr, sourceAddr, isIGMPv3);
if (!isempty(streamAddrM)) {
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
DropMulticast();
}
// Update stream address and port
streamAddr = strcpyrealloc(streamAddr, Location);
streamAddrM = strcpyrealloc(streamAddrM, locationP);
// <group address> or <source address>@<group address>
char *p = strstr(streamAddr, "@");
char *p = strstr(streamAddrM, "@");
if (p) {
*p = 0;
sourceAddr = strcpyrealloc(sourceAddr, streamAddr);
streamAddr = strcpyrealloc(streamAddr, p + 1);
isIGMPv3 = true;
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
streamAddrM = strcpyrealloc(streamAddrM, p + 1);
isIGMPv3M = true;
}
else {
sourceAddr = strcpyrealloc(sourceAddr, streamAddr);
isIGMPv3 = false;
sourceAddrM = strcpyrealloc(sourceAddrM, streamAddrM);
isIGMPv3M = false;
}
streamPort = Parameter;
streamPortM = parameterP;
// Join a new multicast group
if (!isempty(streamAddr)) {
OpenSocket(streamPort, streamAddr, sourceAddr, isIGMPv3);
if (!isempty(streamAddrM)) {
OpenSocket(streamPortM, streamAddrM, sourceAddrM, isIGMPv3M);
JoinMulticast();
}
}
@ -106,7 +106,7 @@ bool cIptvProtocolUdp::Set(const char* Location, const int Parameter, const int
cString cIptvProtocolUdp::GetInformation(void)
{
//debug("cIptvProtocolUdp::GetInformation()");
if (isIGMPv3)
return cString::sprintf("udp://%s@%s:%d", sourceAddr, streamAddr, streamPort);
return cString::sprintf("udp://%s:%d", streamAddr, streamPort);
if (isIGMPv3M)
return cString::sprintf("udp://%s@%s:%d", sourceAddrM, streamAddrM, streamPortM);
return cString::sprintf("udp://%s:%d", streamAddrM, streamPortM);
}

View File

@ -14,16 +14,16 @@
class cIptvProtocolUdp : public cIptvUdpSocket, public cIptvProtocolIf {
private:
bool isIGMPv3;
char* sourceAddr;
char* streamAddr;
int streamPort;
bool isIGMPv3M;
char* sourceAddrM;
char* streamAddrM;
int streamPortM;
public:
cIptvProtocolUdp();
virtual ~cIptvProtocolUdp();
int Read(unsigned char* BufferAddr, unsigned int BufferLen);
bool Set(const char* Location, const int Parameter, const int Index);
int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
bool Set(const char* locationP, const int parameterP, const int indexP);
bool Open(void);
bool Close(void);
cString GetInformation(void);

View File

@ -8,101 +8,101 @@
#include "config.h"
#include "sectionfilter.h"
cIptvSectionFilter::cIptvSectionFilter(int DeviceIndex, uint16_t Pid, uint8_t Tid, uint8_t Mask)
: pusi_seen(0),
feedcc(0),
doneq(0),
secbuf(NULL),
secbufp(0),
seclen(0),
tsfeedp(0),
pid(Pid),
devid(DeviceIndex)
cIptvSectionFilter::cIptvSectionFilter(int deviceIndexP, uint16_t pidP, uint8_t tidP, uint8_t maskP)
: pusiSeenM(0),
feedCcM(0),
doneqM(0),
secBufM(NULL),
secBufpM(0),
secLenM(0),
tsFeedpM(0),
pidM(pidP),
devIdM(deviceIndexP)
{
//debug("cIptvSectionFilter::cIptvSectionFilter(%d, %d)\n", devid, pid);
//debug("cIptvSectionFilter::cIptvSectionFilter(%d, %d)\n", devIdM, pidM);
int i;
memset(secbuf_base, '\0', sizeof(secbuf_base));
memset(filter_value, '\0', sizeof(filter_value));
memset(filter_mask, '\0', sizeof(filter_mask));
memset(filter_mode, '\0', sizeof(filter_mode));
memset(maskandmode, '\0', sizeof(maskandmode));
memset(maskandnotmode, '\0', sizeof(maskandnotmode));
memset(secBufBaseM, 0, sizeof(secBufBaseM));
memset(filterValueM, 0, sizeof(filterValueM));
memset(filterMaskM, 0, sizeof(filterMaskM));
memset(filterModeM, 0, sizeof(filterModeM));
memset(maskAndModeM, 0, sizeof(maskAndModeM));
memset(maskAndNotModeM, 0, sizeof(maskAndNotModeM));
filter_value[0] = Tid;
filter_mask[0] = Mask;
filterValueM[0] = tidP;
filterMaskM[0] = maskP;
// Invert the filter
for (i = 0; i < DMX_MAX_FILTER_SIZE; ++i)
filter_value[i] ^= 0xff;
filterValueM[i] ^= 0xFF;
uint8_t mask, mode, local_doneq = 0;
uint8_t mask, mode, doneq = 0;
for (i = 0; i < DMX_MAX_FILTER_SIZE; ++i) {
mode = filter_mode[i];
mask = filter_mask[i];
maskandmode[i] = (uint8_t)(mask & mode);
maskandnotmode[i] = (uint8_t)(mask & ~mode);
local_doneq |= maskandnotmode[i];
mode = filterModeM[i];
mask = filterMaskM[i];
maskAndModeM[i] = (uint8_t)(mask & mode);
maskAndNotModeM[i] = (uint8_t)(mask & ~mode);
doneq |= maskAndNotModeM[i];
}
doneq = local_doneq ? 1 : 0;
doneqM = doneq ? 1 : 0;
// Create filtering buffer
ringbuffer = new cRingBufferLinear(KILOBYTE(128), 0, false, *cString::sprintf("IPTV SECTION %d/%d", devid, pid));
if (ringbuffer)
ringbuffer->SetTimeouts(10, 10);
ringbufferM = new cRingBufferLinear(KILOBYTE(128), 0, false, *cString::sprintf("IPTV SECTION %d/%d", devIdM, pidM));
if (ringbufferM)
ringbufferM->SetTimeouts(10, 10);
else
error("Failed to allocate buffer for section filter (device=%d pid=%d): ", devid, pid);
error("Failed to allocate buffer for section filter (device=%d pid=%d): ", devIdM, pidM);
}
cIptvSectionFilter::~cIptvSectionFilter()
{
//debug("cIptvSectionFilter::~cIptvSectionfilter(%d, %d)\n", devid, pid);
DELETE_POINTER(ringbuffer);
secbuf = NULL;
//debug("cIptvSectionFilter::~cIptvSectionfilter(%d, %d)\n", devIdM, pidM);
DELETE_POINTER(ringbufferM);
secBufM = NULL;
}
int cIptvSectionFilter::Read(void *Data, size_t Length)
{
int count = 0;
uchar *p = ringbuffer->Get(count);
uchar *p = ringbufferM->Get(count);
if (p && count > 0) {
memcpy(Data, p, count);
ringbuffer->Del(count);
ringbufferM->Del(count);
}
return count;
}
inline uint16_t cIptvSectionFilter::GetLength(const uint8_t *Data)
inline uint16_t cIptvSectionFilter::GetLength(const uint8_t *dataP)
{
return (uint16_t)(3 + ((Data[1] & 0x0f) << 8) + Data[2]);
return (uint16_t)(3 + ((dataP[1] & 0x0f) << 8) + dataP[2]);
}
void cIptvSectionFilter::New(void)
{
tsfeedp = secbufp = seclen = 0;
secbuf = secbuf_base;
tsFeedpM = secBufpM = secLenM = 0;
secBufM = secBufBaseM;
}
int cIptvSectionFilter::Filter(void)
{
if (secbuf) {
if (secBufM) {
int i;
uint8_t neq = 0;
for (i = 0; i < DMX_MAX_FILTER_SIZE; ++i) {
uint8_t local_xor = (uint8_t)(filter_value[i] ^ secbuf[i]);
if (maskandmode[i] & local_xor)
uint8_t calcxor = (uint8_t)(filterValueM[i] ^ secBufM[i]);
if (maskAndModeM[i] & calcxor)
return 0;
neq |= (maskandnotmode[i] & local_xor);
neq |= (maskAndNotModeM[i] & calcxor);
}
if (doneq && !neq)
if (doneqM && !neq)
return 0;
if (ringbuffer) {
int len = ringbuffer->Put(secbuf, seclen);
if (len != seclen)
ringbuffer->ReportOverflow(seclen - len);
if (ringbufferM) {
int len = ringbufferM->Put(secBufM, secLenM);
if (len != secLenM)
ringbufferM->ReportOverflow(secLenM - len);
// Update statistics
AddSectionStatistic(len, 1);
}
@ -114,56 +114,56 @@ inline int cIptvSectionFilter::Feed(void)
{
if (Filter() < 0)
return -1;
seclen = 0;
secLenM = 0;
return 0;
}
int cIptvSectionFilter::CopyDump(const uint8_t *buf, uint8_t len)
int cIptvSectionFilter::CopyDump(const uint8_t *bufP, uint8_t lenP)
{
uint16_t limit, seclen_local, n;
uint16_t limit, seclen, n;
if (tsfeedp >= DMX_MAX_SECFEED_SIZE)
if (tsFeedpM >= DMX_MAX_SECFEED_SIZE)
return 0;
if (tsfeedp + len > DMX_MAX_SECFEED_SIZE)
len = (uint8_t)(DMX_MAX_SECFEED_SIZE - tsfeedp);
if (tsFeedpM + lenP > DMX_MAX_SECFEED_SIZE)
lenP = (uint8_t)(DMX_MAX_SECFEED_SIZE - tsFeedpM);
if (len <= 0)
if (lenP <= 0)
return 0;
memcpy(secbuf_base + tsfeedp, buf, len);
tsfeedp = uint16_t(tsfeedp + len);
memcpy(secBufBaseM + tsFeedpM, bufP, lenP);
tsFeedpM = uint16_t(tsFeedpM + lenP);
limit = tsfeedp;
limit = tsFeedpM;
if (limit > DMX_MAX_SECFEED_SIZE)
return -1; // internal error should never happen
// Always set secbuf
secbuf = secbuf_base + secbufp;
secBufM = secBufBaseM + secBufpM;
for (n = 0; secbufp + 2 < limit; ++n) {
seclen_local = GetLength(secbuf);
if ((seclen_local <= 0) || (seclen_local > DMX_MAX_SECTION_SIZE) || ((seclen_local + secbufp) > limit))
for (n = 0; secBufpM + 2 < limit; ++n) {
seclen = GetLength(secBufM);
if ((seclen <= 0) || (seclen > DMX_MAX_SECTION_SIZE) || ((seclen + secBufpM) > limit))
return 0;
seclen = seclen_local;
if (pusi_seen)
secLenM = seclen;
if (pusiSeenM)
Feed();
secbufp = uint16_t(secbufp + seclen_local);
secbuf += seclen_local;
secBufpM = uint16_t(secBufpM + seclen);
secBufM += seclen;
}
return 0;
}
void cIptvSectionFilter::Process(const uint8_t* Data)
void cIptvSectionFilter::Process(const uint8_t* dataP)
{
if (Data[0] != TS_SYNC_BYTE)
if (dataP[0] != TS_SYNC_BYTE)
return;
// Stop if not the PID this filter is looking for
if (ts_pid(Data) != pid)
if (ts_pid(dataP) != pidM)
return;
uint8_t count = payload(Data);
uint8_t count = payload(dataP);
// Check if no payload or out of range
if (count == 0)
@ -172,41 +172,41 @@ void cIptvSectionFilter::Process(const uint8_t* Data)
// Payload start
uint8_t p = (uint8_t)(TS_SIZE - count);
uint8_t cc = (uint8_t)(Data[3] & 0x0f);
int ccok = ((feedcc + 1) & 0x0f) == cc;
feedcc = cc;
uint8_t cc = (uint8_t)(dataP[3] & 0x0f);
int ccok = ((feedCcM + 1) & 0x0f) == cc;
feedCcM = cc;
int dc_i = 0;
if (Data[3] & 0x20) {
if (dataP[3] & 0x20) {
// Adaption field present, check for discontinuity_indicator
if ((Data[4] > 0) && (Data[5] & 0x80))
if ((dataP[4] > 0) && (dataP[5] & 0x80))
dc_i = 1;
}
if (!ccok || dc_i) {
// Discontinuity detected. Reset pusi_seen = 0 to
// Discontinuity detected. Reset pusiSeenM = 0 to
// stop feeding of suspicious data until next PUSI=1 arrives
pusi_seen = 0;
pusiSeenM = 0;
New();
}
if (Data[1] & 0x40) {
if (dataP[1] & 0x40) {
// PUSI=1 (is set), section boundary is here
if (count > 1 && Data[p] < count) {
const uint8_t *before = &Data[p + 1];
uint8_t before_len = Data[p];
if (count > 1 && dataP[p] < count) {
const uint8_t *before = &dataP[p + 1];
uint8_t before_len = dataP[p];
const uint8_t *after = &before[before_len];
uint8_t after_len = (uint8_t)(count - 1 - before_len);
CopyDump(before, before_len);
// Before start of new section, set pusi_seen = 1
pusi_seen = 1;
// Before start of new section, set pusiSeenM = 1
pusiSeenM = 1;
New();
CopyDump(after, after_len);
}
}
else {
// PUSI=0 (is not set), no section boundary
CopyDump(&Data[p], count);
CopyDump(&dataP[p], count);
}
}

View File

@ -24,41 +24,41 @@ private:
DMX_MAX_SECFEED_SIZE = (DMX_MAX_SECTION_SIZE + TS_SIZE)
};
int pusi_seen;
int feedcc;
int doneq;
int pusiSeenM;
int feedCcM;
int doneqM;
uint8_t *secbuf;
uint8_t secbuf_base[DMX_MAX_SECFEED_SIZE];
uint16_t secbufp;
uint16_t seclen;
uint16_t tsfeedp;
uint16_t pid;
uint8_t *secBufM;
uint8_t secBufBaseM[DMX_MAX_SECFEED_SIZE];
uint16_t secBufpM;
uint16_t secLenM;
uint16_t tsFeedpM;
uint16_t pidM;
int devid;
int devIdM;
uint8_t filter_value[DMX_MAX_FILTER_SIZE];
uint8_t filter_mask[DMX_MAX_FILTER_SIZE];
uint8_t filter_mode[DMX_MAX_FILTER_SIZE];
uint8_t filterValueM[DMX_MAX_FILTER_SIZE];
uint8_t filterMaskM[DMX_MAX_FILTER_SIZE];
uint8_t filterModeM[DMX_MAX_FILTER_SIZE];
uint8_t maskandmode[DMX_MAX_FILTER_SIZE];
uint8_t maskandnotmode[DMX_MAX_FILTER_SIZE];
uint8_t maskAndModeM[DMX_MAX_FILTER_SIZE];
uint8_t maskAndNotModeM[DMX_MAX_FILTER_SIZE];
cRingBufferLinear *ringbuffer;
cRingBufferLinear *ringbufferM;
inline uint16_t GetLength(const uint8_t *Data);
inline uint16_t GetLength(const uint8_t *dataP);
void New(void);
int Filter(void);
inline int Feed(void);
int CopyDump(const uint8_t *buf, uint8_t len);
int CopyDump(const uint8_t *bufP, uint8_t lenP);
public:
// constructor & destructor
cIptvSectionFilter(int DeviceIndex, uint16_t Pid, uint8_t Tid, uint8_t Mask);
cIptvSectionFilter(int deviceIndexP, uint16_t pidP, uint8_t tidP, uint8_t maskP);
virtual ~cIptvSectionFilter();
void Process(const uint8_t* Data);
int Read(void *Buffer, size_t Length);
uint16_t GetPid(void) const { return pid; }
void Process(const uint8_t* dataP);
int Read(void *bufferP, size_t lengthP);
uint16_t GetPid(void) const { return pidM; }
};
#endif // __IPTV_SECTIONFILTER_H

142
setup.c
View File

@ -21,23 +21,23 @@ private:
enum {
INFO_TIMEOUT_MS = 2000
};
cString text;
cTimeMs timeout;
unsigned int page;
cString textM;
cTimeMs timeoutM;
unsigned int pageM;
void UpdateInfo();
public:
cIptvMenuInfo();
virtual ~cIptvMenuInfo();
virtual void Display(void);
virtual eOSState ProcessKey(eKeys Key);
virtual eOSState ProcessKey(eKeys keyP);
};
cIptvMenuInfo::cIptvMenuInfo()
:cOsdMenu(tr("IPTV Information")), text(""), timeout(), page(IPTV_DEVICE_INFO_GENERAL)
:cOsdMenu(tr("IPTV Information")), textM(""), timeoutM(), pageM(IPTV_DEVICE_INFO_GENERAL)
{
SetMenuCategory(mcText);
timeout.Set(INFO_TIMEOUT_MS);
timeoutM.Set(INFO_TIMEOUT_MS);
UpdateInfo();
SetHelp(tr("General"), tr("Pids"), tr("Filters"), tr("Bits/bytes"));
}
@ -50,24 +50,24 @@ void cIptvMenuInfo::UpdateInfo()
{
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device)
text = device->GetInformation(page);
textM = device->GetInformation(pageM);
else
text = cString(tr("IPTV information not available!"));
textM = cString(tr("IPTV information not available!"));
Display();
timeout.Set(INFO_TIMEOUT_MS);
timeoutM.Set(INFO_TIMEOUT_MS);
}
void cIptvMenuInfo::Display(void)
{
cOsdMenu::Display();
DisplayMenu()->SetText(text, true);
if (*text)
cStatus::MsgOsdTextItem(text);
DisplayMenu()->SetText(textM, true);
if (*textM)
cStatus::MsgOsdTextItem(textM);
}
eOSState cIptvMenuInfo::ProcessKey(eKeys Key)
eOSState cIptvMenuInfo::ProcessKey(eKeys keyP)
{
switch (int(Key)) {
switch (int(keyP)) {
case kUp|k_Repeat:
case kUp:
case kDown|k_Repeat:
@ -76,30 +76,30 @@ eOSState cIptvMenuInfo::ProcessKey(eKeys Key)
case kLeft:
case kRight|k_Repeat:
case kRight:
DisplayMenu()->Scroll(NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft, NORMALKEY(Key) == kLeft || NORMALKEY(Key) == kRight);
cStatus::MsgOsdTextItem(NULL, NORMALKEY(Key) == kUp || NORMALKEY(Key) == kLeft);
DisplayMenu()->Scroll(NORMALKEY(keyP) == kUp || NORMALKEY(keyP) == kLeft, NORMALKEY(keyP) == kLeft || NORMALKEY(keyP) == kRight);
cStatus::MsgOsdTextItem(NULL, NORMALKEY(keyP) == kUp || NORMALKEY(keyP) == kLeft);
return osContinue;
default: break;
}
eOSState state = cOsdMenu::ProcessKey(Key);
eOSState state = cOsdMenu::ProcessKey(keyP);
if (state == osUnknown) {
switch (Key) {
switch (keyP) {
case kOk: return osBack;
case kRed: page = IPTV_DEVICE_INFO_GENERAL;
case kRed: pageM = IPTV_DEVICE_INFO_GENERAL;
UpdateInfo();
break;
case kGreen: page = IPTV_DEVICE_INFO_PIDS;
case kGreen: pageM = IPTV_DEVICE_INFO_PIDS;
UpdateInfo();
break;
case kYellow: page = IPTV_DEVICE_INFO_FILTERS;
case kYellow: pageM = IPTV_DEVICE_INFO_FILTERS;
UpdateInfo();
break;
case kBlue: IptvConfig.SetUseBytes(IptvConfig.GetUseBytes() ? 0 : 1);
UpdateInfo();
break;
default: if (timeout.TimedOut())
default: if (timeoutM.TimedOut())
UpdateInfo();
state = osContinue;
break;
@ -113,16 +113,16 @@ eOSState cIptvMenuInfo::ProcessKey(eKeys Key)
cIptvPluginSetup::cIptvPluginSetup()
{
debug("cIptvPluginSetup::cIptvPluginSetup()\n");
tsBufferSize = IptvConfig.GetTsBufferSize();
tsBufferPrefill = IptvConfig.GetTsBufferPrefillRatio();
extProtocolBasePort = IptvConfig.GetExtProtocolBasePort();
sectionFiltering = IptvConfig.GetSectionFiltering();
numDisabledFilters = IptvConfig.GetDisabledFiltersCount();
if (numDisabledFilters > SECTION_FILTER_TABLE_SIZE)
numDisabledFilters = SECTION_FILTER_TABLE_SIZE;
tsBufferSizeM = IptvConfig.GetTsBufferSize();
tsBufferPrefillM = IptvConfig.GetTsBufferPrefillRatio();
extProtocolBasePortM = IptvConfig.GetExtProtocolBasePort();
sectionFilteringM = IptvConfig.GetSectionFiltering();
numDisabledFiltersM = IptvConfig.GetDisabledFiltersCount();
if (numDisabledFiltersM > SECTION_FILTER_TABLE_SIZE)
numDisabledFiltersM = SECTION_FILTER_TABLE_SIZE;
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i) {
disabledFilterIndexes[i] = IptvConfig.GetDisabledFilters(i);
disabledFilterNames[i] = tr(section_filter_table[i].description);
disabledFilterIndexesM[i] = IptvConfig.GetDisabledFilters(i);
disabledFilterNamesM[i] = tr(section_filter_table[i].description);
}
Setup();
SetHelp(NULL, NULL, NULL, trVDR("Button$Info"));
@ -133,28 +133,28 @@ void cIptvPluginSetup::Setup(void)
int current = Current();
Clear();
help.Clear();
helpM.Clear();
Add(new cMenuEditIntItem( tr("TS buffer size [MB]"), &tsBufferSize, 1, 4));
help.Append(tr("Define a ringbuffer size for transport streams in megabytes.\n\nSmaller sizes help memory consumption, but are more prone to buffer overflows."));
Add(new cMenuEditIntItem( tr("TS buffer size [MB]"), &tsBufferSizeM, 1, 4));
helpM.Append(tr("Define a ringbuffer size for transport streams in megabytes.\n\nSmaller sizes help memory consumption, but are more prone to buffer overflows."));
Add(new cMenuEditIntItem( tr("TS buffer prefill ratio [%]"), &tsBufferPrefill, 0, 40));
help.Append(tr("Define a prefill ratio of the ringbuffer for transport streams before data is transferred to VDR.\n\nThis is useful if streaming media over a slow or unreliable connection."));
Add(new cMenuEditIntItem( tr("TS buffer prefill ratio [%]"), &tsBufferPrefillM, 0, 40));
helpM.Append(tr("Define a prefill ratio of the ringbuffer for transport streams before data is transferred to VDR.\n\nThis is useful if streaming media over a slow or unreliable connection."));
Add(new cMenuEditIntItem( tr("EXT protocol base port"), &extProtocolBasePort, 0, 0xFFF7));
help.Append(tr("Define a base port used by EXT protocol.\n\nThe port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."));
Add(new cMenuEditIntItem( tr("EXT protocol base port"), &extProtocolBasePortM, 0, 0xFFF7));
helpM.Append(tr("Define a base port used by EXT protocol.\n\nThe port range is defined by the number of IPTV devices. This setting sets the port which is listened for connections from external applications when using the EXT protocol."));
Add(new cMenuEditBoolItem(tr("Use section filtering"), &sectionFiltering));
help.Append(tr("Define whether the section filtering shall be used.\n\nSection filtering means that IPTV plugin tries to parse and provide VDR with secondary data about the currently active stream. VDR can then use this data for providing various functionalities such as automatic pid change detection and EPG etc.\nEnabling this feature does not affect streams that do not contain section data."));
Add(new cMenuEditBoolItem(tr("Use section filtering"), &sectionFilteringM));
helpM.Append(tr("Define whether the section filtering shall be used.\n\nSection filtering means that IPTV plugin tries to parse and provide VDR with secondary data about the currently active stream. VDR can then use this data for providing various functionalities such as automatic pid change detection and EPG etc.\nEnabling this feature does not affect streams that do not contain section data."));
if (sectionFiltering) {
Add(new cMenuEditIntItem( tr("Disable filters"), &numDisabledFilters, 0, SECTION_FILTER_TABLE_SIZE));
help.Append(tr("Define number of section filters to be disabled.\n\nCertain section filters might cause some unwanted behaviour to VDR such as time being falsely synchronized. By black-listing the filters here useful section data can be left intact for VDR to process."));
if (sectionFilteringM) {
Add(new cMenuEditIntItem( tr("Disable filters"), &numDisabledFiltersM, 0, SECTION_FILTER_TABLE_SIZE));
helpM.Append(tr("Define number of section filters to be disabled.\n\nCertain section filters might cause some unwanted behaviour to VDR such as time being falsely synchronized. By black-listing the filters here useful section data can be left intact for VDR to process."));
for (int i = 0; i < numDisabledFilters; ++i) {
for (int i = 0; i < numDisabledFiltersM; ++i) {
// TRANSLATORS: note the singular!
Add(new cMenuEditStraItem(tr("Disable filter"), &disabledFilterIndexes[i], SECTION_FILTER_TABLE_SIZE, disabledFilterNames));
help.Append(tr("Define an ill-behaving filter to be blacklisted."));
Add(new cMenuEditStraItem(tr("Disable filter"), &disabledFilterIndexesM[i], SECTION_FILTER_TABLE_SIZE, disabledFilterNamesM));
helpM.Append(tr("Define an ill-behaving filter to be blacklisted."));
}
}
@ -170,62 +170,62 @@ eOSState cIptvPluginSetup::ShowInfo(void)
return AddSubMenu(new cIptvMenuInfo());
}
eOSState cIptvPluginSetup::ProcessKey(eKeys Key)
eOSState cIptvPluginSetup::ProcessKey(eKeys keyP)
{
int oldsectionFiltering = sectionFiltering;
int oldNumDisabledFilters = numDisabledFilters;
eOSState state = cMenuSetupPage::ProcessKey(Key);
int oldsectionFiltering = sectionFilteringM;
int oldNumDisabledFilters = numDisabledFiltersM;
eOSState state = cMenuSetupPage::ProcessKey(keyP);
if (state == osUnknown) {
switch (Key) {
switch (keyP) {
case kBlue: return ShowInfo();
case kInfo: if (Current() < help.Size())
return AddSubMenu(new cMenuText(cString::sprintf("%s - %s '%s'", tr("Help"), trVDR("Plugin"), PLUGIN_NAME_I18N), help[Current()]));
case kInfo: if (Current() < helpM.Size())
return AddSubMenu(new cMenuText(cString::sprintf("%s - %s '%s'", tr("Help"), trVDR("Plugin"), PLUGIN_NAME_I18N), helpM[Current()]));
default: state = osContinue; break;
}
}
if ((Key != kNone) && ((numDisabledFilters != oldNumDisabledFilters) || (sectionFiltering != oldsectionFiltering))) {
while ((numDisabledFilters < oldNumDisabledFilters) && (oldNumDisabledFilters > 0))
disabledFilterIndexes[--oldNumDisabledFilters] = -1;
if ((keyP != kNone) && ((numDisabledFiltersM != oldNumDisabledFilters) || (sectionFilteringM != oldsectionFiltering))) {
while ((numDisabledFiltersM < oldNumDisabledFilters) && (oldNumDisabledFilters > 0))
disabledFilterIndexesM[--oldNumDisabledFilters] = -1;
Setup();
}
return state;
}
void cIptvPluginSetup::StoreFilters(const char *Name, int *Values)
void cIptvPluginSetup::StoreFilters(const char *nameP, int *valuesP)
{
char buffer[SECTION_FILTER_TABLE_SIZE * 4];
char *q = buffer;
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i) {
char s[3];
if (Values[i] < 0)
if (valuesP[i] < 0)
break;
if (q > buffer)
*q++ = ' ';
snprintf(s, sizeof(s), "%d", Values[i]);
snprintf(s, sizeof(s), "%d", valuesP[i]);
strncpy(q, s, strlen(s));
q += strlen(s);
}
*q = 0;
debug("cIptvPluginSetup::StoreFilters(): %s=%s\n", Name, buffer);
SetupStore(Name, buffer);
debug("cIptvPluginSetup::StoreFilters(): %s=%s\n", nameP, buffer);
SetupStore(nameP, buffer);
}
void cIptvPluginSetup::Store(void)
{
// Store values into setup.conf
SetupStore("TsBufferSize", tsBufferSize);
SetupStore("TsBufferPrefill", tsBufferPrefill);
SetupStore("ExtProtocolBasePort", extProtocolBasePort);
SetupStore("SectionFiltering", sectionFiltering);
StoreFilters("DisabledFilters", disabledFilterIndexes);
SetupStore("TsBufferSize", tsBufferSizeM);
SetupStore("TsBufferPrefill", tsBufferPrefillM);
SetupStore("ExtProtocolBasePort", extProtocolBasePortM);
SetupStore("SectionFiltering", sectionFilteringM);
StoreFilters("DisabledFilters", disabledFilterIndexesM);
// Update global config
IptvConfig.SetTsBufferSize(tsBufferSize);
IptvConfig.SetTsBufferPrefillRatio(tsBufferPrefill);
IptvConfig.SetExtProtocolBasePort(extProtocolBasePort);
IptvConfig.SetSectionFiltering(sectionFiltering);
IptvConfig.SetTsBufferSize(tsBufferSizeM);
IptvConfig.SetTsBufferPrefillRatio(tsBufferPrefillM);
IptvConfig.SetExtProtocolBasePort(extProtocolBasePortM);
IptvConfig.SetSectionFiltering(sectionFilteringM);
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i)
IptvConfig.SetDisabledFilters(i, disabledFilterIndexes[i]);
IptvConfig.SetDisabledFilters(i, disabledFilterIndexesM[i]);
}

66
setup.h
View File

@ -12,70 +12,24 @@
#include <vdr/sourceparams.h>
#include "common.h"
class cIptvTransponderParameters
{
friend class cIptvSourceParam;
private:
int sidscan;
int pidscan;
int protocol;
char address[NAME_MAX];
int parameter;
public:
cIptvTransponderParameters(const char *Parameters = NULL);
int SidScan(void) const { return sidscan; }
int PidScan(void) const { return pidscan; }
int Protocol(void) const { return protocol; }
const char *Address(void) const { return address; }
int Parameter(void) const { return parameter; }
void SetSidScan(int SidScan) { sidscan = SidScan; }
void SetPidScan(int PidScan) { pidscan = PidScan; }
void SetProtocol(int Protocol) { protocol = Protocol; }
void SetAddress(const char *Address) { strncpy(address, Address, sizeof(address)); }
void SetParameter(int Parameter) { parameter = Parameter; }
cString ToString(char Type) const;
bool Parse(const char *s);
};
class cIptvSourceParam : public cSourceParam
{
private:
enum {
eProtocolUDP,
eProtocolHTTP,
eProtocolFILE,
eProtocolEXT,
eProtocolCount
};
int param;
cChannel data;
cIptvTransponderParameters itp;
const char *protocols[eProtocolCount];
public:
cIptvSourceParam(char Source, const char *Description);
virtual void SetData(cChannel *Channel);
virtual void GetData(cChannel *Channel);
virtual cOsdItem *GetOsdItem(void);
};
class cIptvPluginSetup : public cMenuSetupPage
{
private:
int tsBufferSize;
int tsBufferPrefill;
int extProtocolBasePort;
int sectionFiltering;
int numDisabledFilters;
int disabledFilterIndexes[SECTION_FILTER_TABLE_SIZE];
const char *disabledFilterNames[SECTION_FILTER_TABLE_SIZE];
cVector<const char*> help;
int tsBufferSizeM;
int tsBufferPrefillM;
int extProtocolBasePortM;
int sectionFilteringM;
int numDisabledFiltersM;
int disabledFilterIndexesM[SECTION_FILTER_TABLE_SIZE];
const char *disabledFilterNamesM[SECTION_FILTER_TABLE_SIZE];
cVector<const char*> helpM;
eOSState ShowInfo(void);
void Setup(void);
void StoreFilters(const char *Name, int *Values);
void StoreFilters(const char *nameP, int *valuesP);
protected:
virtual eOSState ProcessKey(eKeys Key);
virtual eOSState ProcessKey(eKeys keyP);
virtual void Store(void);
public:

View File

@ -11,10 +11,10 @@
#include "sidscanner.h"
cSidScanner::cSidScanner(void)
: channelId(tChannelID::InvalidID),
sidFound(false),
nidFound(false),
tidFound(false)
: channelIdM(tChannelID::InvalidID),
sidFoundM(false),
nidFoundM(false),
tidFoundM(false)
{
debug("cSidScanner::cSidScanner()\n");
Set(0x00, 0x00); // PAT
@ -26,75 +26,75 @@ cSidScanner::~cSidScanner()
debug("cSidScanner::~cSidScanner()\n");
}
void cSidScanner::SetStatus(bool On)
void cSidScanner::SetStatus(bool onP)
{
debug("cSidScanner::SetStatus(): %d\n", On);
cFilter::SetStatus(On);
debug("cSidScanner::SetStatus(%d)\n", onP);
cFilter::SetStatus(onP);
}
void cSidScanner::SetChannel(const tChannelID &ChannelId)
void cSidScanner::SetChannel(const tChannelID &channelIdP)
{
debug("cSidScanner::SetChannel(): %s\n", *ChannelId.ToString());
channelId = ChannelId;
sidFound = false;
nidFound = false;
tidFound = false;
debug("cSidScanner::SetChannel('%s')\n", *channelIdP.ToString());
channelIdM = channelIdP;
sidFoundM = false;
nidFoundM = false;
tidFoundM = false;
}
void cSidScanner::Process(u_short Pid, u_char Tid, const u_char *Data, int Length)
void cSidScanner::Process(u_short pidP, u_char tidP, const u_char *dataP, int lengthP)
{
int newSid = -1, newNid = -1, newTid = -1;
//debug("cSidScanner::Process()\n");
if (channelId.Valid()) {
if ((Pid == 0x00) && (Tid == 0x00)) {
debug("cSidScanner::Process(): Pid=%d Tid=%02X\n", Pid, Tid);
SI::PAT pat(Data, false);
if (channelIdM.Valid()) {
if ((pidP == 0x00) && (tidP == 0x00)) {
debug("cSidScanner::Process(): Pid=%d Tid=%02X\n", pidP, tidP);
SI::PAT pat(dataP, false);
if (!pat.CheckCRCAndParse())
return;
SI::PAT::Association assoc;
for (SI::Loop::Iterator it; pat.associationLoop.getNext(assoc, it); ) {
if (!assoc.isNITPid()) {
if (assoc.getServiceId() != channelId.Sid()) {
if (assoc.getServiceId() != channelIdM.Sid()) {
debug("cSidScanner::Process(): Sid=%d\n", assoc.getServiceId());
newSid = assoc.getServiceId();
}
sidFound = true;
sidFoundM = true;
break;
}
}
}
else if ((Pid == 0x10) && (Tid == 0x40)) {
debug("cSidScanner::Process(): Pid=%d Tid=%02X\n", Pid, Tid);
SI::NIT nit(Data, false);
else if ((pidP == 0x10) && (tidP == 0x40)) {
debug("cSidScanner::Process(): Pid=%d Tid=%02X\n", pidP, tidP);
SI::NIT nit(dataP, false);
if (!nit.CheckCRCAndParse())
return;
SI::NIT::TransportStream ts;
for (SI::Loop::Iterator it; nit.transportStreamLoop.getNext(ts, it); ) {
if (ts.getTransportStreamId() != channelId.Tid()) {
if (ts.getTransportStreamId() != channelIdM.Tid()) {
debug("cSidScanner::Process(): TSid=%d\n", ts.getTransportStreamId());
newTid = ts.getTransportStreamId();
}
tidFound = true;
tidFoundM = true;
break; // default to the first one
}
if (nit.getNetworkId() != channelId.Nid()) {
if (nit.getNetworkId() != channelIdM.Nid()) {
debug("cSidScanner::Process(): Nid=%d\n", ts.getTransportStreamId());
newNid = nit.getNetworkId();
}
nidFound = true;
nidFoundM = true;
}
}
if ((newSid >= 0) || (newNid >= 0) || (newTid >= 0)) {
if (!Channels.Lock(true, 10))
return;
cChannel *IptvChannel = Channels.GetByChannelID(channelId);
cChannel *IptvChannel = Channels.GetByChannelID(channelIdM);
if (IptvChannel)
IptvChannel->SetId((newNid < 0) ? IptvChannel->Nid() : newNid, (newTid < 0) ? IptvChannel->Tid() : newTid,
(newSid < 0) ? IptvChannel->Sid() : newSid, IptvChannel->Rid());
Channels.Unlock();
}
if (sidFound && nidFound && tidFound) {
if (sidFoundM && nidFoundM && tidFoundM) {
SetChannel(tChannelID::InvalidID);
SetStatus(false);
}

View File

@ -13,19 +13,19 @@
class cSidScanner : public cFilter {
private:
tChannelID channelId;
bool sidFound;
bool nidFound;
bool tidFound;
tChannelID channelIdM;
bool sidFoundM;
bool nidFoundM;
bool tidFoundM;
protected:
virtual void Process(u_short Pid, u_char Tid, const u_char *Data, int Length);
virtual void SetStatus(bool On);
virtual void Process(u_short pidP, u_char tidP, const u_char *dataP, int lengthP);
virtual void SetStatus(bool onP);
public:
cSidScanner(void);
~cSidScanner();
void SetChannel(const tChannelID &ChannelId);
void SetChannel(const tChannelID &channelIdP);
void Open() { SetStatus(true); }
void Close() { SetStatus(false); }
};

122
source.c
View File

@ -10,25 +10,25 @@
// --- cIptvTransponderParameters --------------------------------------------
cIptvTransponderParameters::cIptvTransponderParameters(const char *Parameters)
: sidscan(0),
pidscan(0),
protocol(eProtocolUDP),
parameter(0)
cIptvTransponderParameters::cIptvTransponderParameters(const char *parametersP)
: sidScanM(0),
pidScanM(0),
protocolM(eProtocolUDP),
parameterM(0)
{
debug("cIptvTransponderParameters::cIptvTransponderParameters(): Parameters=%s\n", Parameters);
debug("cIptvTransponderParameters::cIptvTransponderParameters('%s')\n", parametersP);
memset(&address, 0, sizeof(address));
Parse(Parameters);
memset(&addressM, 0, sizeof(addressM));
Parse(parametersP);
}
cString cIptvTransponderParameters::ToString(char Type) const
cString cIptvTransponderParameters::ToString(char typeP) const
{
debug("cIptvTransponderParameters::ToString() Type=%c\n", Type);
debug("cIptvTransponderParameters::ToString(%c)\n", typeP);
const char *protocolstr;
switch (protocol) {
switch (protocolM) {
case eProtocolEXT:
protocolstr = "EXT";
break;
@ -46,17 +46,17 @@ cString cIptvTransponderParameters::ToString(char Type) const
protocolstr = "UDP";
break;
}
return cString::sprintf("S=%d|P=%d|F=%s|U=%s|A=%d", sidscan, pidscan, protocolstr, address, parameter);
return cString::sprintf("S=%d|P=%d|F=%s|U=%s|A=%d", sidScanM, pidScanM, protocolstr, addressM, parameterM);
}
bool cIptvTransponderParameters::Parse(const char *s)
bool cIptvTransponderParameters::Parse(const char *strP)
{
debug("cIptvTransponderParameters::Parse(): s=%s\n", s);
debug("cIptvTransponderParameters::Parse('%s'\n", strP);
bool result = false;
if (s && *s) {
if (strP && *strP) {
const char *delim = "|";
char *str = strdup(s);
char *str = strdup(strP);
char *saveptr = NULL;
char *token = NULL;
bool found_s = false;
@ -72,41 +72,41 @@ bool cIptvTransponderParameters::Parse(const char *s)
++data;
switch (*token) {
case 'S':
sidscan = (int)strtol(data, (char **)NULL, 10);
sidScanM = (int)strtol(data, (char **)NULL, 10);
found_s = true;
break;
case 'P':
pidscan = (int)strtol(data, (char **)NULL, 10);
pidScanM = (int)strtol(data, (char **)NULL, 10);
found_p = true;
break;
case 'F':
if (strstr(data, "UDP")) {
protocol = eProtocolUDP;
protocolM = eProtocolUDP;
found_f = true;
}
else if (strstr(data, "CURL")) {
protocol = eProtocolCURL;
protocolM = eProtocolCURL;
found_f = true;
}
else if (strstr(data, "HTTP")) {
protocol = eProtocolHTTP;
protocolM = eProtocolHTTP;
found_f = true;
}
else if (strstr(data, "FILE")) {
protocol = eProtocolFILE;
protocolM = eProtocolFILE;
found_f = true;
}
else if (strstr(data, "EXT")) {
protocol = eProtocolEXT;
protocolM = eProtocolEXT;
found_f = true;
}
break;
case 'U':
strn0cpy(address, data, sizeof(address));
strn0cpy(addressM, data, sizeof(addressM));
found_u = true;
break;
case 'A':
parameter = (int)strtol(data, (char **)NULL, 10);
parameterM = (int)strtol(data, (char **)NULL, 10);
found_a = true;
break;
default:
@ -129,55 +129,55 @@ bool cIptvTransponderParameters::Parse(const char *s)
// --- cIptvSourceParam ------------------------------------------------------
cIptvSourceParam::cIptvSourceParam(char Source, const char *Description)
: cSourceParam(Source, Description),
param(0),
nid(0),
tid(0),
rid(0),
data(),
itp()
cIptvSourceParam::cIptvSourceParam(char sourceP, const char *descriptionP)
: cSourceParam(sourceP, descriptionP),
paramM(0),
nidM(0),
tidM(0),
ridM(0),
dataM(),
itpM()
{
debug("cIptvSourceParam::cIptvSourceParam(): Source=%c Description=%s\n", Source, Description);
debug("cIptvSourceParam::cIptvSourceParam(%c, '%s')\n", sourceP, descriptionP);
protocols[cIptvTransponderParameters::eProtocolUDP] = tr("UDP");
protocols[cIptvTransponderParameters::eProtocolCURL] = tr("CURL");
protocols[cIptvTransponderParameters::eProtocolHTTP] = tr("HTTP");
protocols[cIptvTransponderParameters::eProtocolFILE] = tr("FILE");
protocols[cIptvTransponderParameters::eProtocolEXT] = tr("EXT");
protocolsM[cIptvTransponderParameters::eProtocolUDP] = tr("UDP");
protocolsM[cIptvTransponderParameters::eProtocolCURL] = tr("CURL");
protocolsM[cIptvTransponderParameters::eProtocolHTTP] = tr("HTTP");
protocolsM[cIptvTransponderParameters::eProtocolFILE] = tr("FILE");
protocolsM[cIptvTransponderParameters::eProtocolEXT] = tr("EXT");
}
void cIptvSourceParam::SetData(cChannel *Channel)
void cIptvSourceParam::SetData(cChannel *channelP)
{
debug("cIptvSourceParam::SetData(): Channel=%s)\n", Channel->Parameters());
data = *Channel;
nid = data.Nid();
tid = data.Tid();
rid = data.Rid();
itp.Parse(data.Parameters());
param = 0;
debug("cIptvSourceParam::SetData('%s')\n", channelP->Parameters());
dataM = *channelP;
nidM = dataM.Nid();
tidM = dataM.Tid();
ridM = dataM.Rid();
itpM.Parse(dataM.Parameters());
paramM = 0;
}
void cIptvSourceParam::GetData(cChannel *Channel)
void cIptvSourceParam::GetData(cChannel *channelP)
{
debug("cIptvSourceParam::GetData(): Channel=%s\n", Channel->Parameters());
data.SetTransponderData(Channel->Source(), Channel->Frequency(), data.Srate(), itp.ToString(Source()), true);
data.SetId(nid, tid, Channel->Sid(), rid);
*Channel = data;
debug("cIptvSourceParam::GetData('%s')\n", channelP->Parameters());
dataM.SetTransponderData(channelP->Source(), channelP->Frequency(), dataM.Srate(), itpM.ToString(Source()), true);
dataM.SetId(nidM, tidM, channelP->Sid(), ridM);
*channelP = dataM;
}
cOsdItem *cIptvSourceParam::GetOsdItem(void)
{
debug("cIptvSourceParam::GetOsdItem()\n");
switch (param++) {
case 0: return new cMenuEditIntItem( tr("Nid"), &nid, 0);
case 1: return new cMenuEditIntItem( tr("Tid"), &tid, 0);
case 2: return new cMenuEditIntItem( tr("Rid"), &rid, 0);
case 3: return new cMenuEditBoolItem(tr("Scan section ids"), &itp.sidscan);
case 4: return new cMenuEditBoolItem(tr("Scan pids"), &itp.pidscan);
case 5: return new cMenuEditStraItem(tr("Protocol"), &itp.protocol, ELEMENTS(protocols), protocols);
case 6: return new cMenuEditStrItem( tr("Address"), itp.address, sizeof(itp.address));
case 7: return new cMenuEditIntItem( tr("Parameter"), &itp.parameter, 0, 0xFFFF);
switch (paramM++) {
case 0: return new cMenuEditIntItem( tr("Nid"), &nidM, 0);
case 1: return new cMenuEditIntItem( tr("Tid"), &tidM, 0);
case 2: return new cMenuEditIntItem( tr("Rid"), &ridM, 0);
case 3: return new cMenuEditBoolItem(tr("Scan section ids"), &itpM.sidScanM);
case 4: return new cMenuEditBoolItem(tr("Scan pids"), &itpM.pidScanM);
case 5: return new cMenuEditStraItem(tr("Protocol"), &itpM.protocolM, ELEMENTS(protocolsM), protocolsM);
case 6: return new cMenuEditStrItem( tr("Address"), itpM.addressM, sizeof(itpM.addressM));
case 7: return new cMenuEditIntItem( tr("Parameter"), &itpM.parameterM, 0, 0xFFFF);
default: return NULL;
}
return NULL;

View File

@ -17,11 +17,11 @@ class cIptvTransponderParameters
friend class cIptvSourceParam;
private:
int sidscan;
int pidscan;
int protocol;
char address[NAME_MAX];
int parameter;
int sidScanM;
int pidScanM;
int protocolM;
char addressM[NAME_MAX];
int parameterM;
public:
enum {
@ -32,36 +32,36 @@ public:
eProtocolEXT,
eProtocolCount
};
cIptvTransponderParameters(const char *Parameters = NULL);
int SidScan(void) const { return sidscan; }
int PidScan(void) const { return pidscan; }
int Protocol(void) const { return protocol; }
const char *Address(void) const { return address; }
int Parameter(void) const { return parameter; }
void SetSidScan(int SidScan) { sidscan = SidScan; }
void SetPidScan(int PidScan) { pidscan = PidScan; }
void SetProtocol(int Protocol) { protocol = Protocol; }
void SetAddress(const char *Address) { strncpy(address, Address, sizeof(address)); }
void SetParameter(int Parameter) { parameter = Parameter; }
cString ToString(char Type) const;
bool Parse(const char *s);
cIptvTransponderParameters(const char *parametersP = NULL);
int SidScan(void) const { return sidScanM; }
int PidScan(void) const { return pidScanM; }
int Protocol(void) const { return protocolM; }
const char *Address(void) const { return addressM; }
int Parameter(void) const { return parameterM; }
void SetSidScan(int sidScanP) { sidScanM = sidScanP; }
void SetPidScan(int pidScanP) { pidScanM = pidScanP; }
void SetProtocol(int protocolP) { protocolM = protocolP; }
void SetAddress(const char *addressP) { strncpy(addressM, addressP, sizeof(addressM)); }
void SetParameter(int parameterP) { parameterM = parameterP; }
cString ToString(char typeP) const;
bool Parse(const char *strP);
};
class cIptvSourceParam : public cSourceParam
{
private:
int param;
int nid;
int tid;
int rid;
cChannel data;
cIptvTransponderParameters itp;
const char *protocols[cIptvTransponderParameters::eProtocolCount];
int paramM;
int nidM;
int tidM;
int ridM;
cChannel dataM;
cIptvTransponderParameters itpM;
const char *protocolsM[cIptvTransponderParameters::eProtocolCount];
public:
cIptvSourceParam(char Source, const char *Description);
virtual void SetData(cChannel *Channel);
virtual void GetData(cChannel *Channel);
cIptvSourceParam(char sourceP, const char *descriptionP);
virtual void SetData(cChannel *channelP);
virtual void GetData(cChannel *channelP);
virtual cOsdItem *GetOsdItem(void);
};

View File

@ -13,10 +13,10 @@
// Section statistic class
cIptvSectionStatistics::cIptvSectionStatistics()
: filteredData(0),
numberOfCalls(0),
timer(),
mutex()
: filteredDataM(0),
numberOfCallsM(0),
timerM(),
mutexM()
{
//debug("cIptvSectionStatistics::cIptvSectionStatistics()\n");
}
@ -29,36 +29,36 @@ cIptvSectionStatistics::~cIptvSectionStatistics()
cString cIptvSectionStatistics::GetSectionStatistic()
{
//debug("cIptvSectionStatistics::GetStatistic()\n");
cMutexLock MutexLock(&mutex);
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
timer.Set();
long bitrate = elapsed ? (long)(1000.0L * filteredData / KILOBYTE(1) / elapsed) : 0L;
cMutexLock MutexLock(&mutexM);
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
timerM.Set();
long bitrate = elapsed ? (long)(1000.0L * filteredDataM / KILOBYTE(1) / elapsed) : 0L;
if (!IptvConfig.GetUseBytes())
bitrate *= 8;
// no trailing linefeed here!
cString s = cString::sprintf("%4ld (%4ld k%s/s)", numberOfCalls, bitrate,
cString s = cString::sprintf("%4ld (%4ld k%s/s)", numberOfCallsM, bitrate,
IptvConfig.GetUseBytes() ? "B" : "bit");
filteredData = numberOfCalls = 0;
filteredDataM = numberOfCallsM = 0;
return s;
}
void cIptvSectionStatistics::AddSectionStatistic(long Bytes, long Calls)
void cIptvSectionStatistics::AddSectionStatistic(long bytesP, long callsP)
{
//debug("cIptvSectionStatistics::AddStatistic(Bytes=%ld, Calls=%ld)\n", Bytes, Calls);
cMutexLock MutexLock(&mutex);
filteredData += Bytes;
numberOfCalls += Calls;
//debug("cIptvSectionStatistics::AddStatistic(%ld, %ld)\n", bytesP, callsP);
cMutexLock MutexLock(&mutexM);
filteredDataM += bytesP;
numberOfCallsM += callsP;
}
// --- cIptvPidStatistics ----------------------------------------------------
// Device statistic class
cIptvPidStatistics::cIptvPidStatistics()
: timer(),
mutex()
: timerM(),
mutexM()
{
debug("cIptvPidStatistics::cIptvPidStatistics()\n");
memset(mostActivePids, '\0', sizeof(mostActivePids));
memset(mostActivePidsM, '\0', sizeof(mostActivePidsM));
}
cIptvPidStatistics::~cIptvPidStatistics()
@ -69,29 +69,29 @@ cIptvPidStatistics::~cIptvPidStatistics()
cString cIptvPidStatistics::GetPidStatistic()
{
//debug("cIptvPidStatistics::GetStatistic()\n");
cMutexLock MutexLock(&mutex);
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
timer.Set();
cMutexLock MutexLock(&mutexM);
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
timerM.Set();
cString s("Active pids:\n");
for (unsigned int i = 0; i < IPTV_STATS_ACTIVE_PIDS_COUNT; ++i) {
if (mostActivePids[i].pid) {
long bitrate = elapsed ? (long)(1000.0L * mostActivePids[i].DataAmount / KILOBYTE(1) / elapsed) : 0L;
if (mostActivePidsM[i].pid) {
long bitrate = elapsed ? (long)(1000.0L * mostActivePidsM[i].DataAmount / KILOBYTE(1) / elapsed) : 0L;
if (!IptvConfig.GetUseBytes())
bitrate *= 8;
s = cString::sprintf("%sPid %d: %4d (%4ld k%s/s)\n", *s, i,
mostActivePids[i].pid, bitrate,
mostActivePidsM[i].pid, bitrate,
IptvConfig.GetUseBytes() ? "B" : "bit");
}
}
memset(mostActivePids, '\0', sizeof(mostActivePids));
memset(mostActivePidsM, '\0', sizeof(mostActivePidsM));
return s;
}
int cIptvPidStatistics::SortPids(const void* data1, const void* data2)
int cIptvPidStatistics::SortPids(const void* data1P, const void* data2P)
{
//debug("cIptvPidStatistics::SortPids()\n");
const pidStruct *comp1 = reinterpret_cast<const pidStruct*>(data1);
const pidStruct *comp2 = reinterpret_cast<const pidStruct*>(data2);
const pidStruct *comp1 = reinterpret_cast<const pidStruct*>(data1P);
const pidStruct *comp2 = reinterpret_cast<const pidStruct*>(data2P);
if (comp1->DataAmount > comp2->DataAmount)
return -1;
if (comp1->DataAmount < comp2->DataAmount)
@ -99,27 +99,27 @@ int cIptvPidStatistics::SortPids(const void* data1, const void* data2)
return 0;
}
void cIptvPidStatistics::AddPidStatistic(u_short Pid, long Payload)
void cIptvPidStatistics::AddPidStatistic(u_short pidP, long payloadP)
{
//debug("cIptvPidStatistics::AddStatistic(pid=%ld, payload=%ld)\n", Pid, Payload);
cMutexLock MutexLock(&mutex);
const int numberOfElements = sizeof(mostActivePids) / sizeof(pidStruct);
//debug("cIptvPidStatistics::AddStatistic(%ld, %ld)\n", pidP, payloadP);
cMutexLock MutexLock(&mutexM);
const int numberOfElements = sizeof(mostActivePidsM) / sizeof(pidStruct);
// If our statistic already is in the array, update it and quit
for (int i = 0; i < numberOfElements; ++i) {
if (mostActivePids[i].pid == Pid) {
mostActivePids[i].DataAmount += Payload;
if (mostActivePidsM[i].pid == pidP) {
mostActivePidsM[i].DataAmount += payloadP;
// Now re-sort the array and quit
qsort(mostActivePids, numberOfElements, sizeof(pidStruct), SortPids);
qsort(mostActivePidsM, numberOfElements, sizeof(pidStruct), SortPids);
return;
}
}
// Apparently our pid isn't in the array. Replace the last element with this
// one if new payload is greater
if (mostActivePids[numberOfElements - 1].DataAmount < Payload) {
mostActivePids[numberOfElements - 1].pid = Pid;
mostActivePids[numberOfElements - 1].DataAmount = Payload;
if (mostActivePidsM[numberOfElements - 1].DataAmount < payloadP) {
mostActivePidsM[numberOfElements - 1].pid = pidP;
mostActivePidsM[numberOfElements - 1].DataAmount = payloadP;
// Re-sort
qsort(mostActivePids, numberOfElements, sizeof(pidStruct), SortPids);
qsort(mostActivePidsM, numberOfElements, sizeof(pidStruct), SortPids);
}
}
@ -127,9 +127,9 @@ void cIptvPidStatistics::AddPidStatistic(u_short Pid, long Payload)
// Streamer statistic class
cIptvStreamerStatistics::cIptvStreamerStatistics()
: dataBytes(0),
timer(),
mutex()
: dataBytesM(0),
timerM(),
mutexM()
{
debug("cIptvStreamerStatistics::cIptvStreamerStatistics()\n");
}
@ -142,32 +142,32 @@ cIptvStreamerStatistics::~cIptvStreamerStatistics()
cString cIptvStreamerStatistics::GetStreamerStatistic()
{
//debug("cIptvStreamerStatistics::GetStatistic()\n");
cMutexLock MutexLock(&mutex);
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
timer.Set();
long bitrate = elapsed ? (long)(1000.0L * dataBytes / KILOBYTE(1) / elapsed) : 0L;
cMutexLock MutexLock(&mutexM);
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
timerM.Set();
long bitrate = elapsed ? (long)(1000.0L * dataBytesM / KILOBYTE(1) / elapsed) : 0L;
if (!IptvConfig.GetUseBytes())
bitrate *= 8;
cString s = cString::sprintf("%ld k%s/s", bitrate, IptvConfig.GetUseBytes() ? "B" : "bit");
dataBytes = 0;
dataBytesM = 0;
return s;
}
void cIptvStreamerStatistics::AddStreamerStatistic(long Bytes)
void cIptvStreamerStatistics::AddStreamerStatistic(long bytesP)
{
//debug("cIptvStreamerStatistics::AddStatistic(Bytes=%ld)\n", Bytes);
cMutexLock MutexLock(&mutex);
dataBytes += Bytes;
//debug("cIptvStreamerStatistics::AddStatistic(%ld)\n", bytesP);
cMutexLock MutexLock(&mutexM);
dataBytesM += bytesP;
}
// Buffer statistic class
cIptvBufferStatistics::cIptvBufferStatistics()
: dataBytes(0),
freeSpace(0),
usedSpace(0),
timer(),
mutex()
: dataBytesM(0),
freeSpaceM(0),
usedSpaceM(0),
timerM(),
mutexM()
{
debug("cIptvBufferStatistics::cIptvBufferStatistics()\n");
}
@ -180,14 +180,14 @@ cIptvBufferStatistics::~cIptvBufferStatistics()
cString cIptvBufferStatistics::GetBufferStatistic()
{
//debug("cIptvBufferStatistics::GetStatistic()\n");
cMutexLock MutexLock(&mutex);
uint64_t elapsed = timer.Elapsed(); /* in milliseconds */
timer.Set();
long bitrate = elapsed ? (long)(1000.0L * dataBytes / KILOBYTE(1) / elapsed) : 0L;
cMutexLock MutexLock(&mutexM);
uint64_t elapsed = timerM.Elapsed(); /* in milliseconds */
timerM.Set();
long bitrate = elapsed ? (long)(1000.0L * dataBytesM / KILOBYTE(1) / elapsed) : 0L;
long totalSpace = MEGABYTE(IptvConfig.GetTsBufferSize());
float percentage = (float)((float)usedSpace / (float)totalSpace * 100.0);
float percentage = (float)((float)usedSpaceM / (float)totalSpace * 100.0);
long totalKilos = totalSpace / KILOBYTE(1);
long usedKilos = usedSpace / KILOBYTE(1);
long usedKilos = usedSpaceM / KILOBYTE(1);
if (!IptvConfig.GetUseBytes()) {
bitrate *= 8;
totalKilos *= 8;
@ -196,16 +196,16 @@ cString cIptvBufferStatistics::GetBufferStatistic()
cString s = cString::sprintf("Buffer bitrate: %ld k%s/s\nBuffer usage: %ld/%ld k%s (%2.1f%%)\n", bitrate,
IptvConfig.GetUseBytes() ? "B" : "bit", usedKilos, totalKilos,
IptvConfig.GetUseBytes() ? "B" : "bit", percentage);
dataBytes = 0;
usedSpace = 0;
dataBytesM = 0;
usedSpaceM = 0;
return s;
}
void cIptvBufferStatistics::AddBufferStatistic(long Bytes, long Used)
void cIptvBufferStatistics::AddBufferStatistic(long bytesP, long usedP)
{
//debug("cIptvBufferStatistics::AddStatistic(Bytes=%ld, Used=%ld)\n", Bytes, Used);
cMutexLock MutexLock(&mutex);
dataBytes += Bytes;
if (Used > usedSpace)
usedSpace = Used;
//debug("cIptvBufferStatistics::AddStatistic(%ld, %ld)\n", bytesP, usedP);
cMutexLock MutexLock(&mutexM);
dataBytesM += bytesP;
if (usedP > usedSpaceM)
usedSpaceM = usedP;
}

View File

@ -18,13 +18,13 @@ public:
cString GetSectionStatistic();
protected:
void AddSectionStatistic(long Bytes, long Calls);
void AddSectionStatistic(long bytesP, long callsP);
private:
long filteredData;
long numberOfCalls;
cTimeMs timer;
cMutex mutex;
long filteredDataM;
long numberOfCallsM;
cTimeMs timerM;
cMutex mutexM;
};
// Pid statistics
@ -35,19 +35,19 @@ public:
cString GetPidStatistic();
protected:
void AddPidStatistic(u_short Pid, long Payload);
void AddPidStatistic(u_short pidP, long payloadP);
private:
struct pidStruct {
u_short pid;
long DataAmount;
};
pidStruct mostActivePids[IPTV_STATS_ACTIVE_PIDS_COUNT];
cTimeMs timer;
cMutex mutex;
pidStruct mostActivePidsM[IPTV_STATS_ACTIVE_PIDS_COUNT];
cTimeMs timerM;
cMutex mutexM;
private:
static int SortPids(const void* data1, const void* data2);
static int SortPids(const void* data1P, const void* data2P);
};
// Streamer statistics
@ -58,12 +58,12 @@ public:
cString GetStreamerStatistic();
protected:
void AddStreamerStatistic(long Bytes);
void AddStreamerStatistic(long bytesP);
private:
long dataBytes;
cTimeMs timer;
cMutex mutex;
long dataBytesM;
cTimeMs timerM;
cMutex mutexM;
};
// Buffer statistics
@ -74,14 +74,14 @@ public:
cString GetBufferStatistic();
protected:
void AddBufferStatistic(long Bytes, long Used);
void AddBufferStatistic(long bytesP, long usedP);
private:
long dataBytes;
long freeSpace;
long usedSpace;
cTimeMs timer;
cMutex mutex;
long dataBytesM;
long freeSpaceM;
long usedSpaceM;
cTimeMs timerM;
cMutex mutexM;
};
#endif // __IPTV_STATISTICS_H

View File

@ -11,17 +11,17 @@
#include "common.h"
#include "streamer.h"
cIptvStreamer::cIptvStreamer(cRingBufferLinear* RingBuffer, unsigned int PacketLen)
cIptvStreamer::cIptvStreamer(cRingBufferLinear* ringBufferP, unsigned int packetLenP)
: cThread("IPTV streamer"),
ringBuffer(RingBuffer),
packetBufferLen(PacketLen),
protocol(NULL)
ringBufferM(ringBufferP),
packetBufferLenM(packetLenP),
protocolM(NULL)
{
debug("cIptvStreamer::cIptvStreamer(%d)\n", packetBufferLen);
debug("cIptvStreamer::cIptvStreamer(%d)\n", packetBufferLenM);
// Allocate packet buffer
packetBuffer = MALLOC(unsigned char, packetBufferLen);
if (packetBuffer)
memset(packetBuffer, 0, packetBufferLen);
packetBufferM = MALLOC(unsigned char, packetBufferLenM);
if (packetBufferM)
memset(packetBufferM, 0, packetBufferLenM);
else
error("MALLOC() failed for packet buffer");
}
@ -31,10 +31,10 @@ cIptvStreamer::~cIptvStreamer()
debug("cIptvStreamer::~cIptvStreamer()\n");
// Close the protocol
Close();
protocol = NULL;
ringBuffer = NULL;
protocolM = NULL;
ringBufferM = NULL;
// Free allocated memory
free(packetBuffer);
free(packetBufferM);
}
void cIptvStreamer::Action(void)
@ -43,20 +43,20 @@ void cIptvStreamer::Action(void)
// Increase priority
//SetPriority(-1);
// Do the thread loop
while (packetBuffer && Running()) {
while (packetBufferM && Running()) {
int length = -1;
if (protocol)
length = protocol->Read(packetBuffer, min((unsigned int)ringBuffer->Free(), packetBufferLen));
if (protocolM)
length = protocolM->Read(packetBufferM, min((unsigned int)ringBufferM->Free(), packetBufferLenM));
if (length > 0) {
AddStreamerStatistic(length);
if (ringBuffer) {
int p = ringBuffer->Put(packetBuffer, length);
if (ringBufferM) {
int p = ringBufferM->Put(packetBufferM, length);
if (p != length)
ringBuffer->ReportOverflow(length - p);
ringBufferM->ReportOverflow(length - p);
}
}
else
sleep.Wait(10); // to avoid busy loop and reduce cpu load
sleepM.Wait(10); // to avoid busy loop and reduce cpu load
}
debug("cIptvStreamer::Action(): Exiting\n");
}
@ -65,7 +65,7 @@ bool cIptvStreamer::Open(void)
{
debug("cIptvStreamer::Open()\n");
// Open the protocol
if (protocol && !protocol->Open())
if (protocolM && !protocolM->Open())
return false;
// Start thread
Start();
@ -76,31 +76,31 @@ bool cIptvStreamer::Close(void)
{
debug("cIptvStreamer::Close()\n");
// Stop thread
sleep.Signal();
sleepM.Signal();
if (Running())
Cancel(3);
// Close the protocol
if (protocol)
protocol->Close();
if (protocolM)
protocolM->Close();
return true;
}
bool cIptvStreamer::Set(const char* Location, const int Parameter, const int Index, cIptvProtocolIf* Protocol)
bool cIptvStreamer::Set(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP)
{
debug("cIptvStreamer::Set(): %s:%d\n", Location, Parameter);
if (!isempty(Location)) {
debug("cIptvStreamer::Set('%s', %d, %d)\n", locationP, parameterP, indexP);
if (!isempty(locationP)) {
// Update protocol and set location and parameter; Close the existing one if changed
if (protocol != Protocol) {
if (protocol)
protocol->Close();
protocol = Protocol;
if (protocol) {
protocol->Set(Location, Parameter, Index);
protocol->Open();
if (protocolM != protocolP) {
if (protocolM)
protocolM->Close();
protocolM = protocolP;
if (protocolM) {
protocolM->Set(locationP, parameterP, indexP);
protocolM->Open();
}
}
else if (protocol)
protocol->Set(Location, Parameter, Index);
else if (protocolM)
protocolM->Set(locationP, parameterP, indexP);
}
return true;
}
@ -108,8 +108,8 @@ bool cIptvStreamer::Set(const char* Location, const int Parameter, const int Ind
cString cIptvStreamer::GetInformation(void)
{
//debug("cIptvStreamer::GetInformation()");
cString info;
if (protocol)
info = protocol->GetInformation();
return info;
cString s;
if (protocolM)
s = protocolM->GetInformation();
return s;
}

View File

@ -18,19 +18,19 @@
class cIptvStreamer : public cThread, public cIptvStreamerStatistics {
private:
cRingBufferLinear* ringBuffer;
cCondWait sleep;
unsigned char* packetBuffer;
unsigned int packetBufferLen;
cIptvProtocolIf* protocol;
cRingBufferLinear* ringBufferM;
cCondWait sleepM;
unsigned char* packetBufferM;
unsigned int packetBufferLenM;
cIptvProtocolIf* protocolM;
protected:
virtual void Action(void);
public:
cIptvStreamer(cRingBufferLinear* RingBuffer, unsigned int PacketLen);
cIptvStreamer(cRingBufferLinear* ringBufferP, unsigned int packetLenP);
virtual ~cIptvStreamer();
bool Set(const char* Location, const int Parameter, const int Index, cIptvProtocolIf* Protocol);
bool Set(const char* locationP, const int parameterP, const int indexP, cIptvProtocolIf* protocolP);
bool Open(void);
bool Close(void);
cString GetInformation(void);