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

233 lines
8.0 KiB
C
Raw Normal View History

2007-09-15 17:38:38 +02:00
/*
* setup.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <vdr/status.h>
#include <vdr/menu.h>
2007-09-15 17:38:38 +02:00
#include "common.h"
#include "config.h"
#include "device.h"
2007-09-15 17:38:38 +02:00
#include "setup.h"
// --- cIptvMenuInfo ---------------------------------------------------------
class cIptvMenuInfo : public cOsdMenu
{
private:
enum {
INFO_TIMEOUT_MS = 2000
};
2013-02-23 14:31:11 +01:00
cString textM;
cTimeMs timeoutM;
unsigned int pageM;
void UpdateInfo();
public:
cIptvMenuInfo();
virtual ~cIptvMenuInfo();
virtual void Display(void);
2013-02-23 14:31:11 +01:00
virtual eOSState ProcessKey(eKeys keyP);
};
cIptvMenuInfo::cIptvMenuInfo()
2013-02-23 14:31:11 +01:00
:cOsdMenu(tr("IPTV Information")), textM(""), timeoutM(), pageM(IPTV_DEVICE_INFO_GENERAL)
{
SetMenuCategory(mcText);
2013-02-23 14:31:11 +01:00
timeoutM.Set(INFO_TIMEOUT_MS);
UpdateInfo();
2007-10-09 18:37:16 +02:00
SetHelp(tr("General"), tr("Pids"), tr("Filters"), tr("Bits/bytes"));
}
cIptvMenuInfo::~cIptvMenuInfo()
{
}
void cIptvMenuInfo::UpdateInfo()
{
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device)
2013-02-23 14:31:11 +01:00
textM = device->GetInformation(pageM);
else
2013-02-23 14:31:11 +01:00
textM = cString(tr("IPTV information not available!"));
Display();
2013-02-23 14:31:11 +01:00
timeoutM.Set(INFO_TIMEOUT_MS);
}
void cIptvMenuInfo::Display(void)
{
cOsdMenu::Display();
2013-02-23 14:31:11 +01:00
DisplayMenu()->SetText(textM, true);
if (*textM)
cStatus::MsgOsdTextItem(textM);
}
2013-02-23 14:31:11 +01:00
eOSState cIptvMenuInfo::ProcessKey(eKeys keyP)
{
2013-02-23 14:31:11 +01:00
switch (int(keyP)) {
case kUp|k_Repeat:
case kUp:
case kDown|k_Repeat:
case kDown:
case kLeft|k_Repeat:
case kLeft:
case kRight|k_Repeat:
case kRight:
2013-02-23 14:31:11 +01:00
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;
}
2013-02-23 14:31:11 +01:00
eOSState state = cOsdMenu::ProcessKey(keyP);
if (state == osUnknown) {
2013-02-23 14:31:11 +01:00
switch (keyP) {
case kOk: return osBack;
2013-02-23 14:31:11 +01:00
case kRed: pageM = IPTV_DEVICE_INFO_GENERAL;
UpdateInfo();
break;
2013-02-23 14:31:11 +01:00
case kGreen: pageM = IPTV_DEVICE_INFO_PIDS;
UpdateInfo();
break;
2013-02-23 14:31:11 +01:00
case kYellow: pageM = IPTV_DEVICE_INFO_FILTERS;
UpdateInfo();
break;
2009-03-20 16:43:31 +01:00
case kBlue: IptvConfig.SetUseBytes(IptvConfig.GetUseBytes() ? 0 : 1);
UpdateInfo();
break;
2013-02-23 14:31:11 +01:00
default: if (timeoutM.TimedOut())
UpdateInfo();
state = osContinue;
break;
}
}
return state;
}
// --- cIptvPluginSetup ------------------------------------------------------
cIptvPluginSetup::cIptvPluginSetup()
2007-09-15 17:38:38 +02:00
{
2013-02-23 16:12:46 +01:00
debug("cIptvPluginSetup::%s()", __FUNCTION__);
2013-02-23 14:31:11 +01:00
tsBufferSizeM = IptvConfig.GetTsBufferSize();
tsBufferPrefillM = IptvConfig.GetTsBufferPrefillRatio();
2014-02-19 20:38:11 +01:00
protocolBasePortM = IptvConfig.GetProtocolBasePort();
2013-02-23 14:31:11 +01:00
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) {
2013-02-23 14:31:11 +01:00
disabledFilterIndexesM[i] = IptvConfig.GetDisabledFilters(i);
disabledFilterNamesM[i] = tr(section_filter_table[i].description);
}
2013-03-13 22:33:37 +01:00
SetMenuCategory(mcSetupPlugins);
2007-09-15 17:38:38 +02:00
Setup();
2010-03-04 16:34:21 +01:00
SetHelp(NULL, NULL, NULL, trVDR("Button$Info"));
2007-09-15 17:38:38 +02:00
}
void cIptvPluginSetup::Setup(void)
{
int current = Current();
2008-01-20 00:17:20 +01:00
2007-09-15 17:38:38 +02:00
Clear();
2013-02-23 14:31:11 +01:00
helpM.Clear();
2008-01-20 00:17:20 +01:00
2014-02-19 20:38:11 +01:00
Add(new cMenuEditIntItem(tr("TS buffer size [MB]"), &tsBufferSizeM, 1, 4));
2013-02-23 14:31:11 +01:00
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."));
2008-01-20 00:17:20 +01:00
2014-02-19 20:38:11 +01:00
Add(new cMenuEditIntItem(tr("TS buffer prefill ratio [%]"), &tsBufferPrefillM, 0, 40));
2013-02-23 14:31:11 +01:00
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."));
2008-01-20 00:17:20 +01:00
2014-02-19 20:38:11 +01:00
Add(new cMenuEditIntItem(tr("Protocol base port"), &protocolBasePortM, 0, 0xFFFF - MAXDEVICES * 2));
helpM.Append(tr("Define a base port used by CURL/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 CURL/EXT protocol."));
2008-01-20 00:17:20 +01:00
2013-02-23 14:31:11 +01:00
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."));
2008-01-20 00:17:20 +01:00
2013-02-23 14:31:11 +01:00
if (sectionFilteringM) {
2014-02-19 20:38:11 +01:00
Add(new cMenuEditIntItem(tr("Disable filters"), &numDisabledFiltersM, 0, SECTION_FILTER_TABLE_SIZE));
2013-02-23 14:31:11 +01:00
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."));
2008-01-20 00:17:20 +01:00
2013-02-23 14:31:11 +01:00
for (int i = 0; i < numDisabledFiltersM; ++i) {
// TRANSLATORS: note the singular!
2013-02-23 14:31:11 +01:00
Add(new cMenuEditStraItem(tr("Disable filter"), &disabledFilterIndexesM[i], SECTION_FILTER_TABLE_SIZE, disabledFilterNamesM));
helpM.Append(tr("Define an ill-behaving filter to be blacklisted."));
}
}
2008-01-20 00:17:20 +01:00
2007-09-15 17:38:38 +02:00
SetCurrent(Get(current));
Display();
}
eOSState cIptvPluginSetup::ShowInfo(void)
{
2013-02-23 16:12:46 +01:00
debug("cIptvPluginSetup::%s()", __FUNCTION__);
if (HasSubMenu())
return osContinue;
return AddSubMenu(new cIptvMenuInfo());
}
2013-02-23 14:31:11 +01:00
eOSState cIptvPluginSetup::ProcessKey(eKeys keyP)
2007-09-15 17:38:38 +02:00
{
2013-02-23 14:31:11 +01:00
int oldsectionFiltering = sectionFilteringM;
int oldNumDisabledFilters = numDisabledFiltersM;
eOSState state = cMenuSetupPage::ProcessKey(keyP);
2008-01-20 00:17:20 +01:00
if (state == osUnknown) {
2013-02-23 14:31:11 +01:00
switch (keyP) {
case kBlue: return ShowInfo();
2013-02-23 14:31:11 +01:00
case kInfo: if (Current() < helpM.Size())
return AddSubMenu(new cMenuText(cString::sprintf("%s - %s '%s'", tr("Help"), trVDR("Plugin"), PLUGIN_NAME_I18N), helpM[Current()]));
2009-03-20 23:56:37 +01:00
default: state = osContinue; break;
}
}
2008-01-20 00:17:20 +01:00
2013-02-23 14:31:11 +01:00
if ((keyP != kNone) && ((numDisabledFiltersM != oldNumDisabledFilters) || (sectionFilteringM != oldsectionFiltering))) {
while ((numDisabledFiltersM < oldNumDisabledFilters) && (oldNumDisabledFilters > 0))
disabledFilterIndexesM[--oldNumDisabledFilters] = -1;
Setup();
}
2008-01-20 00:17:20 +01:00
2007-09-15 17:38:38 +02:00
return state;
}
2013-02-23 14:31:11 +01:00
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];
2013-02-23 14:31:11 +01:00
if (valuesP[i] < 0)
break;
if (q > buffer)
*q++ = ' ';
2013-02-23 14:31:11 +01:00
snprintf(s, sizeof(s), "%d", valuesP[i]);
strncpy(q, s, strlen(s));
q += strlen(s);
}
*q = 0;
2013-02-23 16:12:46 +01:00
debug("cIptvPluginSetup::%s(%s, %s)", __FUNCTION__, nameP, buffer);
2013-02-23 14:31:11 +01:00
SetupStore(nameP, buffer);
}
2007-09-15 17:38:38 +02:00
void cIptvPluginSetup::Store(void)
{
2007-09-16 15:38:20 +02:00
// Store values into setup.conf
2013-02-23 14:31:11 +01:00
SetupStore("TsBufferSize", tsBufferSizeM);
SetupStore("TsBufferPrefill", tsBufferPrefillM);
2014-02-19 20:38:11 +01:00
SetupStore("ExtProtocolBasePort", protocolBasePortM);
2013-02-23 14:31:11 +01:00
SetupStore("SectionFiltering", sectionFilteringM);
StoreFilters("DisabledFilters", disabledFilterIndexesM);
2007-09-16 15:38:20 +02:00
// Update global config
2013-02-23 14:31:11 +01:00
IptvConfig.SetTsBufferSize(tsBufferSizeM);
IptvConfig.SetTsBufferPrefillRatio(tsBufferPrefillM);
2014-02-19 20:38:11 +01:00
IptvConfig.SetProtocolBasePort(protocolBasePortM);
2013-02-23 14:31:11 +01:00
IptvConfig.SetSectionFiltering(sectionFilteringM);
for (int i = 0; i < SECTION_FILTER_TABLE_SIZE; ++i)
2013-02-23 14:31:11 +01:00
IptvConfig.SetDisabledFilters(i, disabledFilterIndexesM[i]);
2007-09-15 17:38:38 +02:00
}