Added a user configurable section filter blacklist.

This commit is contained in:
Rolf Ahrenberg 2007-10-06 00:02:50 +00:00
parent d7e2e8d0d3
commit 3e553d5324
9 changed files with 187 additions and 27 deletions

View File

@ -3,11 +3,12 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: common.c,v 1.1 2007/10/05 20:01:24 ajhseppa Exp $
* $Id: common.c,v 1.2 2007/10/06 00:02:50 rahrenbe Exp $
*/
#include <vdr/i18n.h>
#include <vdr/tools.h>
#include "common.h"
uint16_t ts_pid(const uint8_t *buf)
{
@ -28,3 +29,16 @@ uint8_t payload(const uint8_t *tsp)
return 184;
}
const section_filter_table_type section_filter_table[SECTION_FILTER_TABLE_SIZE] =
{
/* description pid tid mask */
{trNOOP("PAT (0x00)"), 0x00, 0x00, 0xFF},
{trNOOP("NIT (0x40)"), 0x10, 0x40, 0xFF},
{trNOOP("SDT (0x42)"), 0x11, 0x42, 0xFF},
{trNOOP("EIT (0x4E/0x4F)"), 0x12, 0x4E, 0xFE},
{trNOOP("EIT (0x5X)"), 0x12, 0x50, 0xF0},
{trNOOP("EIT (0x6X)"), 0x12, 0x60, 0xF0},
{trNOOP("TDT (0x70)"), 0x14, 0x70, 0xFF},
};

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: common.h,v 1.3 2007/10/05 20:01:24 ajhseppa Exp $
* $Id: common.h,v 1.4 2007/10/06 00:02:50 rahrenbe Exp $
*/
#ifndef __IPTV_COMMON_H
@ -22,5 +22,16 @@ uint8_t payload(const uint8_t *tsp);
#define error(x...) esyslog("IPTV: " x);
#endif
#define SECTION_FILTER_TABLE_SIZE 7
typedef struct _section_filter_table_type {
const char *description;
u_short pid;
u_char tid;
u_char mask;
} section_filter_table_type;
extern const section_filter_table_type section_filter_table[SECTION_FILTER_TABLE_SIZE];
#endif // __IPTV_COMMON_H

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: config.c,v 1.11 2007/09/30 21:38:31 rahrenbe Exp $
* $Id: config.c,v 1.12 2007/10/06 00:02:50 rahrenbe Exp $
*/
#include "common.h"
@ -18,4 +18,25 @@ cIptvConfig::cIptvConfig(void)
sectionFiltering(1),
sidScanning(1)
{
for (unsigned int i = 0; i < sizeof(disabledFilters); ++i)
disabledFilters[i] = -1;
}
unsigned int cIptvConfig::GetDisabledFiltersCount(void)
{
unsigned int n = 0;
while ((disabledFilters[n] != -1) && (n < sizeof(disabledFilters)))
n++;
return n;
}
int cIptvConfig::GetDisabledFilters(unsigned int Index)
{
return (Index < sizeof(disabledFilters)) ? disabledFilters[Index] : -1;
}
void cIptvConfig::SetDisabledFilters(unsigned int Index, int Number)
{
if (Index < sizeof(disabledFilters))
disabledFilters[Index] = Number;
}

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: config.h,v 1.9 2007/09/30 21:38:31 rahrenbe Exp $
* $Id: config.h,v 1.10 2007/10/06 00:02:50 rahrenbe Exp $
*/
#ifndef __IPTV_CONFIG_H
@ -20,6 +20,7 @@ protected:
unsigned int tsBufferPrefillRatio;
unsigned int sectionFiltering;
unsigned int sidScanning;
int disabledFilters[SECTION_FILTER_TABLE_SIZE];
public:
cIptvConfig();
@ -28,10 +29,13 @@ public:
unsigned int GetTsBufferPrefillRatio(void) { return tsBufferPrefillRatio; }
unsigned int GetSectionFiltering(void) { return sectionFiltering; }
unsigned int GetSidScanning(void) { return sidScanning; }
unsigned int GetDisabledFiltersCount(void);
int GetDisabledFilters(unsigned int Index);
void SetTsBufferSize(unsigned int Size) { tsBufferSize = Size; }
void SetTsBufferPrefillRatio(unsigned int Ratio) { tsBufferPrefillRatio = Ratio; }
void SetSectionFiltering(unsigned int On) { sectionFiltering = On; }
void SetSidScanning(unsigned int On) { sidScanning = On; }
void SetDisabledFilters(unsigned int Index, int Number);
};
extern cIptvConfig IptvConfig;

View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: device.c,v 1.50 2007/10/05 19:00:44 ajhseppa Exp $
* $Id: device.c,v 1.51 2007/10/06 00:02:50 rahrenbe Exp $
*/
#include "common.h"
@ -182,15 +182,17 @@ bool cIptvDevice::DeleteFilter(unsigned int Index)
bool cIptvDevice::IsBlackListed(u_short Pid, u_char Tid, u_char Mask)
{
//debug("cIptvDevice::IsBlackListed(%d) Pid=%d Tid=%02X Mask=%02X\n", deviceIndex, Pid, Tid, Mask);
// Black list. Should maybe be configurable via plugin setup menu
switch (Pid) {
case 0x10: // NIT (0x40)
case 0x11: // SDT (0x42)
case 0x14: // TDT (0x70)
// 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[i].pid == Pid) && (section_filter_table[i].tid == Tid) &&
(section_filter_table[i].mask == Mask)) {
//debug("cIptvDevice::IsBlackListed(%d) Found=%s\n", deviceIndex, section_filter_table[i].description);
return true;
default:
break;
}
}
}
return false;
}
@ -199,11 +201,9 @@ int cIptvDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask)
// Check if disabled by user
if (!IptvConfig.GetSectionFiltering())
return -1;
// Black-listing check, refuse certain filters
// Blacklist check, refuse certain filters
if (IsBlackListed(Pid, Tid, Mask))
return -1;
// Search the next free filter slot
for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) {
if (!secfilters[i]) {

27
iptv.c
View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: iptv.c,v 1.9 2007/09/30 21:38:31 rahrenbe Exp $
* $Id: iptv.c,v 1.10 2007/10/06 00:02:50 rahrenbe Exp $
*/
#include <getopt.h>
@ -18,8 +18,8 @@ static const char *DESCRIPTION = trNOOP("Experiment the IPTV");
class cPluginIptv : public cPlugin {
private:
// Add any member variables or functions you may need here.
unsigned int deviceCount;
int ParseFilters(const char *Value, int *Values);
public:
cPluginIptv(void);
virtual ~cPluginIptv();
@ -150,6 +150,23 @@ cMenuSetupPage *cPluginIptv::SetupMenu(void)
return new cIptvPluginSetup();
}
int cPluginIptv::ParseFilters(const char *Value, int *Filters)
{
debug("cPluginIptv::ParseFilters(): Value=%s\n", Value);
char buffer[256];
int n = 0;
while (Value && *Value && (n < SECTION_FILTER_TABLE_SIZE)) {
strn0cpy(buffer, Value, 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++;
}
return n;
}
bool cPluginIptv::SetupParse(const char *Name, const char *Value)
{
debug("cPluginIptv::SetupParse()\n");
@ -162,6 +179,12 @@ bool cPluginIptv::SetupParse(const char *Name, const char *Value)
IptvConfig.SetSectionFiltering(atoi(Value));
else if (!strcasecmp(Name, "SidScanning"))
IptvConfig.SetSidScanning(atoi(Value));
else if (!strcasecmp(Name, "DisabledFilters")) {
int DisabledFilters[SECTION_FILTER_TABLE_SIZE] = { -1 };
int DisabledFiltersCount = ParseFilters(Value, DisabledFilters);
for (int i = 0; i < DisabledFiltersCount; ++i)
IptvConfig.SetDisabledFilters(i, DisabledFilters[i]);
}
else
return false;
return true;

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: VDR 1.5.7\n"
"Report-Msgid-Bugs-To: Rolf Ahrenberg\n"
"POT-Creation-Date: 2007-10-01 21:07+0300\n"
"POT-Creation-Date: 2007-10-06 02:54+0300\n"
"PO-Revision-Date: 2007-08-12 23:22+0300\n"
"Last-Translator: Rolf Ahrenberg\n"
"Language-Team: <vdr@linuxtv.org>\n"
@ -15,6 +15,34 @@ msgstr ""
"Content-Type: text/plain; charset=ISO-8859-15\n"
"Content-Transfer-Encoding: 8bit\n"
#: common.c:36
msgid "PAT (0x00)"
msgstr "PAT (0x00)"
#: common.c:37
msgid "NIT (0x40)"
msgstr "NIT (0x40)"
#: common.c:38
msgid "SDT (0x42)"
msgstr "SDT (0x42)"
#: common.c:39
msgid "EIT (0x4E/0x4F)"
msgstr "EIT (0x4E/0x4F)"
#: common.c:40
msgid "EIT (0x5X)"
msgstr "EIT (0x5X)"
#: common.c:41
msgid "EIT (0x6X)"
msgstr "EIT (0x6X)"
#: common.c:42
msgid "TDT (0x70)"
msgstr "TDT (0x70)"
#: iptv.c:17
msgid "Experiment the IPTV"
msgstr "Koe IPTV:n ihmeellinen maailma"
@ -59,18 +87,27 @@ msgstr "Yksil
msgid "IPTV Channels"
msgstr "IPTV-kanavat"
#: setup.c:486
#: setup.c:494
msgid "TS buffer size [MB]"
msgstr "TS-puskurin koko [MB]"
#: setup.c:487
#: setup.c:495
msgid "TS buffer prefill ratio [%]"
msgstr "TS-puskurin esitäyttöaste [%]"
#: setup.c:488
#: setup.c:496
msgid "Use section filtering"
msgstr "Käytä sektioiden suodatusta"
#: setup.c:490
#: setup.c:498
msgid "Scan Sid automatically"
msgstr "Etsi palvelu-ID automaattisesti"
#: setup.c:499
msgid "Disable filters"
msgstr "Poista suodattimia käytöstä"
#. TRANSLATORS: note the singular!
#: setup.c:502
msgid "Disable filter"
msgstr "Poista suodatin käytöstä"

48
setup.c
View File

@ -3,7 +3,7 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: setup.c,v 1.19 2007/10/01 18:14:57 rahrenbe Exp $
* $Id: setup.c,v 1.20 2007/10/06 00:02:50 rahrenbe Exp $
*/
#include <string.h>
@ -471,10 +471,18 @@ eOSState cIptvMenuChannels::ProcessKey(eKeys Key)
cIptvPluginSetup::cIptvPluginSetup()
{
debug("cIptvPluginSetup::cIptvPluginSetup()\n");
tsBufferSize = IptvConfig.GetTsBufferSize();
tsBufferPrefill = IptvConfig.GetTsBufferPrefillRatio();
sectionFiltering = IptvConfig.GetSectionFiltering();
sidScanning = IptvConfig.GetSidScanning();
numDisabledFilters = IptvConfig.GetDisabledFiltersCount();
if (numDisabledFilters > SECTION_FILTER_TABLE_SIZE)
numDisabledFilters = 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);
}
Setup();
SetHelp(trVDR("Channels"), NULL, NULL, NULL);
}
@ -486,14 +494,21 @@ void cIptvPluginSetup::Setup(void)
Add(new cMenuEditIntItem( tr("TS buffer size [MB]"), &tsBufferSize, 2, 16));
Add(new cMenuEditIntItem( tr("TS buffer prefill ratio [%]"), &tsBufferPrefill, 0, 40));
Add(new cMenuEditBoolItem(tr("Use section filtering"), &sectionFiltering));
if (sectionFiltering)
if (sectionFiltering) {
Add(new cMenuEditBoolItem(tr("Scan Sid automatically"), &sidScanning));
Add(new cMenuEditIntItem( tr("Disable filters"), &numDisabledFilters, 0, SECTION_FILTER_TABLE_SIZE));
for (int i = 0; i < numDisabledFilters; ++i) {
// TRANSLATORS: note the singular!
Add(new cMenuEditStraItem(tr("Disable filter"), &disabledFilterIndexes[i], SECTION_FILTER_TABLE_SIZE, disabledFilterNames));
}
}
SetCurrent(Get(current));
Display();
}
eOSState cIptvPluginSetup::EditChannel(void)
{
debug("cIptvPluginSetup::EditChannel()\n");
if (HasSubMenu())
return osContinue;
return AddSubMenu(new cIptvMenuChannels());
@ -501,6 +516,8 @@ eOSState cIptvPluginSetup::EditChannel(void)
eOSState cIptvPluginSetup::ProcessKey(eKeys Key)
{
int oldsectionFiltering = sectionFiltering;
int oldNumDisabledFilters = numDisabledFilters;
eOSState state = cMenuSetupPage::ProcessKey(Key);
if (state == osUnknown) {
switch (Key) {
@ -508,9 +525,33 @@ eOSState cIptvPluginSetup::ProcessKey(eKeys Key)
default: break;
}
}
if ((Key != kNone) && ((numDisabledFilters != oldNumDisabledFilters) || (sectionFiltering != oldsectionFiltering))) {
while (numDisabledFilters && (numDisabledFilters < oldNumDisabledFilters))
disabledFilterIndexes[--oldNumDisabledFilters] = -1;
Setup();
}
return state;
}
void cIptvPluginSetup::StoreFilters(const char *Name, int *Values)
{
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)
break;
if (q > buffer)
*q++ = ' ';
snprintf(s, sizeof(s), "%d", Values[i]);
strncpy(q, s, strlen(s));
q += strlen(s);
}
*q = 0;
debug("cIptvPluginSetup::StoreFilters(): %s=%s\n", Name, buffer);
SetupStore(Name, buffer);
}
void cIptvPluginSetup::Store(void)
{
// Store values into setup.conf
@ -518,9 +559,12 @@ void cIptvPluginSetup::Store(void)
SetupStore("TsBufferPrefill", tsBufferPrefill);
SetupStore("SectionFiltering", sectionFiltering);
SetupStore("SidScanning", sidScanning);
StoreFilters("DisabledFilters", disabledFilterIndexes);
// Update global config
IptvConfig.SetTsBufferSize(tsBufferSize);
IptvConfig.SetTsBufferPrefillRatio(tsBufferPrefill);
IptvConfig.SetSectionFiltering(sectionFiltering);
IptvConfig.SetSidScanning(sidScanning);
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i)
IptvConfig.SetDisabledFilters(i, disabledFilterIndexes[i]);
}

View File

@ -3,13 +3,14 @@
*
* See the README file for copyright information and how to reach the author.
*
* $Id: setup.h,v 1.9 2007/09/30 21:38:31 rahrenbe Exp $
* $Id: setup.h,v 1.10 2007/10/06 00:02:50 rahrenbe Exp $
*/
#ifndef __IPTV_SETUP_H
#define __IPTV_SETUP_H
#include <vdr/menuitems.h>
#include "common.h"
class cIptvPluginSetup : public cMenuSetupPage
{
@ -18,8 +19,13 @@ private:
int tsBufferPrefill;
int sectionFiltering;
int sidScanning;
int numDisabledFilters;
int disabledFilterIndexes[SECTION_FILTER_TABLE_SIZE];
const char *disabledFilterNames[SECTION_FILTER_TABLE_SIZE];
eOSState EditChannel(void);
virtual void Setup(void);
void StoreFilters(const char *Name, int *Values);
protected:
virtual eOSState ProcessKey(eKeys Key);