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 .
*
*/
2007-10-06 22:57:53 +02:00
# include <vdr/status.h>
2008-01-19 17:24:40 +01:00
# include <vdr/menu.h>
2007-09-18 20:48:10 +02:00
2007-09-15 17:38:38 +02:00
# include "common.h"
# include "config.h"
2007-10-06 22:57:53 +02:00
# include "device.h"
2007-09-15 17:38:38 +02:00
# include "setup.h"
2007-10-06 22:57:53 +02:00
// --- cIptvMenuInfo ---------------------------------------------------------
class cIptvMenuInfo : public cOsdMenu
{
private :
enum {
2007-10-07 17:13:48 +02:00
INFO_TIMEOUT_MS = 2000
2007-10-06 22:57:53 +02:00
} ;
2013-02-23 14:31:11 +01:00
cString textM ;
cTimeMs timeoutM ;
unsigned int pageM ;
2007-10-07 21:06:33 +02:00
void UpdateInfo ( ) ;
2007-10-06 22:57:53 +02:00
public :
cIptvMenuInfo ( ) ;
virtual ~ cIptvMenuInfo ( ) ;
virtual void Display ( void ) ;
2013-02-23 14:31:11 +01:00
virtual eOSState ProcessKey ( eKeys keyP ) ;
2007-10-06 22:57:53 +02:00
} ;
cIptvMenuInfo : : cIptvMenuInfo ( )
2013-02-23 14:31:11 +01:00
: cOsdMenu ( tr ( " IPTV Information " ) ) , textM ( " " ) , timeoutM ( ) , pageM ( IPTV_DEVICE_INFO_GENERAL )
2007-10-06 22:57:53 +02:00
{
2013-02-23 01:03:27 +01:00
SetMenuCategory ( mcText ) ;
2013-02-23 14:31:11 +01:00
timeoutM . Set ( INFO_TIMEOUT_MS ) ;
2007-10-07 21:06:33 +02:00
UpdateInfo ( ) ;
2007-10-09 18:37:16 +02:00
SetHelp ( tr ( " General " ) , tr ( " Pids " ) , tr ( " Filters " ) , tr ( " Bits/bytes " ) ) ;
2007-10-06 22:57:53 +02:00
}
cIptvMenuInfo : : ~ cIptvMenuInfo ( )
{
}
2007-10-07 21:06:33 +02:00
void cIptvMenuInfo : : UpdateInfo ( )
2007-10-06 22:57:53 +02:00
{
cIptvDevice * device = cIptvDevice : : GetIptvDevice ( cDevice : : ActualDevice ( ) - > CardIndex ( ) ) ;
if ( device )
2013-02-23 14:31:11 +01:00
textM = device - > GetInformation ( pageM ) ;
2007-10-06 22:57:53 +02:00
else
2013-02-23 14:31:11 +01:00
textM = cString ( tr ( " IPTV information not available! " ) ) ;
2007-10-06 22:57:53 +02:00
Display ( ) ;
2013-02-23 14:31:11 +01:00
timeoutM . Set ( INFO_TIMEOUT_MS ) ;
2007-10-06 22:57:53 +02:00
}
void cIptvMenuInfo : : Display ( void )
{
cOsdMenu : : Display ( ) ;
2013-02-23 14:31:11 +01:00
DisplayMenu ( ) - > SetText ( textM , true ) ;
if ( * textM )
cStatus : : MsgOsdTextItem ( textM ) ;
2007-10-06 22:57:53 +02:00
}
2013-02-23 14:31:11 +01:00
eOSState cIptvMenuInfo : : ProcessKey ( eKeys keyP )
2007-10-06 22:57:53 +02:00
{
2013-02-23 14:31:11 +01:00
switch ( int ( keyP ) ) {
2007-10-06 22:57:53 +02:00
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 ) ;
2007-10-06 22:57:53 +02:00
return osContinue ;
default : break ;
}
2013-02-23 14:31:11 +01:00
eOSState state = cOsdMenu : : ProcessKey ( keyP ) ;
2007-10-06 22:57:53 +02:00
if ( state = = osUnknown ) {
2013-02-23 14:31:11 +01:00
switch ( keyP ) {
2007-10-09 01:51:58 +02:00
case kOk : return osBack ;
2013-02-23 14:31:11 +01:00
case kRed : pageM = IPTV_DEVICE_INFO_GENERAL ;
2007-10-09 01:51:58 +02:00
UpdateInfo ( ) ;
break ;
2013-02-23 14:31:11 +01:00
case kGreen : pageM = IPTV_DEVICE_INFO_PIDS ;
2007-10-09 01:51:58 +02:00
UpdateInfo ( ) ;
break ;
2013-02-23 14:31:11 +01:00
case kYellow : pageM = IPTV_DEVICE_INFO_FILTERS ;
2007-10-09 01:51:58 +02:00
UpdateInfo ( ) ;
break ;
2009-03-20 16:43:31 +01:00
case kBlue : IptvConfig . SetUseBytes ( IptvConfig . GetUseBytes ( ) ? 0 : 1 ) ;
2007-10-09 01:51:58 +02:00
UpdateInfo ( ) ;
break ;
2013-02-23 14:31:11 +01:00
default : if ( timeoutM . TimedOut ( ) )
2007-10-09 01:51:58 +02:00
UpdateInfo ( ) ;
state = osContinue ;
break ;
2007-10-06 22:57:53 +02:00
}
}
return state ;
}
2007-09-18 20:48:10 +02:00
// --- 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 ( ) ;
extProtocolBasePortM = IptvConfig . GetExtProtocolBasePort ( ) ;
sectionFilteringM = IptvConfig . GetSectionFiltering ( ) ;
numDisabledFiltersM = IptvConfig . GetDisabledFiltersCount ( ) ;
if ( numDisabledFiltersM > SECTION_FILTER_TABLE_SIZE )
numDisabledFiltersM = SECTION_FILTER_TABLE_SIZE ;
2007-10-06 02:02:50 +02:00
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 ) ;
2007-10-06 02:02:50 +02:00
}
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
2013-02-23 14:31:11 +01:00
Add ( new cMenuEditIntItem ( tr ( " TS buffer size [MB] " ) , & tsBufferSizeM , 1 , 4 ) ) ;
helpM . Append ( tr ( " Define a ringbuffer size for transport streams in megabytes. \n \n Smaller sizes help memory consumption, but are more prone to buffer overflows. " ) ) ;
2008-01-20 00:17:20 +01:00
2013-02-23 14:31:11 +01:00
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 \n This is useful if streaming media over a slow or unreliable connection. " ) ) ;
2008-01-20 00:17:20 +01:00
2013-02-23 14:31:11 +01:00
Add ( new cMenuEditIntItem ( tr ( " EXT protocol base port " ) , & extProtocolBasePortM , 0 , 0xFFF7 ) ) ;
helpM . Append ( tr ( " Define a base port used by EXT protocol. \n \n The 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. " ) ) ;
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 \n Section 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. \n Enabling 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 ) {
Add ( new cMenuEditIntItem ( tr ( " Disable filters " ) , & numDisabledFiltersM , 0 , SECTION_FILTER_TABLE_SIZE ) ) ;
helpM . Append ( tr ( " Define number of section filters to be disabled. \n \n Certain 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 ) {
2007-10-06 02:02:50 +02:00
// 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. " ) ) ;
2007-10-06 02:02:50 +02:00
}
}
2008-01-20 00:17:20 +01:00
2007-09-15 17:38:38 +02:00
SetCurrent ( Get ( current ) ) ;
Display ( ) ;
}
2007-10-06 22:57:53 +02:00
eOSState cIptvPluginSetup : : ShowInfo ( void )
{
2013-02-23 16:12:46 +01:00
debug ( " cIptvPluginSetup::%s() " , __FUNCTION__ ) ;
2007-10-06 22:57:53 +02:00
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
2007-09-18 20:48:10 +02:00
if ( state = = osUnknown ) {
2013-02-23 14:31:11 +01:00
switch ( keyP ) {
2007-10-06 22:57:53 +02:00
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 ;
2007-09-18 20:48:10 +02:00
}
}
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 ;
2007-10-06 02:02:50 +02:00
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 )
2007-10-06 02:02:50 +02:00
{
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 )
2007-10-06 02:02:50 +02:00
break ;
if ( q > buffer )
* q + + = ' ' ;
2013-02-23 14:31:11 +01:00
snprintf ( s , sizeof ( s ) , " %d " , valuesP [ i ] ) ;
2007-10-06 02:02:50 +02:00
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-10-06 02:02:50 +02:00
}
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 ) ;
SetupStore ( " ExtProtocolBasePort " , extProtocolBasePortM ) ;
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 ) ;
IptvConfig . SetExtProtocolBasePort ( extProtocolBasePortM ) ;
IptvConfig . SetSectionFiltering ( sectionFilteringM ) ;
2007-10-06 02:02:50 +02:00
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
}