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
} ;
2007-10-07 00:15:02 +02:00
cString text ;
2007-10-06 22:57:53 +02:00
cTimeMs timeout ;
2007-10-09 01:51:58 +02:00
unsigned int page ;
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 ) ;
virtual eOSState ProcessKey ( eKeys Key ) ;
} ;
cIptvMenuInfo : : cIptvMenuInfo ( )
2007-10-27 01:13:24 +02:00
: cOsdMenu ( tr ( " IPTV Information " ) ) , text ( " " ) , timeout ( ) , page ( IPTV_DEVICE_INFO_GENERAL )
2007-10-06 22:57:53 +02:00
{
2007-10-27 01:13:24 +02:00
timeout . 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 )
2007-10-09 01:51:58 +02:00
text = device - > GetInformation ( page ) ;
2007-10-06 22:57:53 +02:00
else
2007-10-07 00:15:02 +02:00
text = cString ( tr ( " IPTV information not available! " ) ) ;
2007-10-06 22:57:53 +02:00
Display ( ) ;
2007-10-07 17:13:48 +02:00
timeout . Set ( INFO_TIMEOUT_MS ) ;
2007-10-06 22:57:53 +02:00
}
void cIptvMenuInfo : : Display ( void )
{
cOsdMenu : : Display ( ) ;
DisplayMenu ( ) - > SetText ( text , true ) ;
2008-02-18 12:54:01 +01:00
if ( * text )
2007-10-06 22:57:53 +02:00
cStatus : : MsgOsdTextItem ( text ) ;
}
eOSState cIptvMenuInfo : : ProcessKey ( eKeys Key )
{
2011-12-04 18:40:46 +01:00
switch ( int ( Key ) ) {
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 :
DisplayMenu ( ) - > Scroll ( NORMALKEY ( Key ) = = kUp | | NORMALKEY ( Key ) = = kLeft , NORMALKEY ( Key ) = = kLeft | | NORMALKEY ( Key ) = = kRight ) ;
cStatus : : MsgOsdTextItem ( NULL , NORMALKEY ( Key ) = = kUp | | NORMALKEY ( Key ) = = kLeft ) ;
return osContinue ;
default : break ;
}
eOSState state = cOsdMenu : : ProcessKey ( Key ) ;
if ( state = = osUnknown ) {
switch ( Key ) {
2007-10-09 01:51:58 +02:00
case kOk : return osBack ;
case kRed : page = IPTV_DEVICE_INFO_GENERAL ;
UpdateInfo ( ) ;
break ;
case kGreen : page = IPTV_DEVICE_INFO_PIDS ;
UpdateInfo ( ) ;
break ;
case kYellow : page = IPTV_DEVICE_INFO_FILTERS ;
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 ;
default : if ( timeout . TimedOut ( ) )
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
{
2007-10-06 02:02:50 +02:00
debug ( " cIptvPluginSetup::cIptvPluginSetup() \n " ) ;
2007-09-16 15:38:20 +02:00
tsBufferSize = IptvConfig . GetTsBufferSize ( ) ;
tsBufferPrefill = IptvConfig . GetTsBufferPrefillRatio ( ) ;
2007-10-20 19:26:46 +02:00
extProtocolBasePort = IptvConfig . GetExtProtocolBasePort ( ) ;
2007-09-30 23:38:31 +02:00
sectionFiltering = IptvConfig . GetSectionFiltering ( ) ;
2007-10-06 02:02:50 +02:00
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 ) ;
}
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 ( ) ;
2008-01-19 17:24:40 +01:00
help . Clear ( ) ;
2008-01-20 00:17:20 +01:00
Add ( new cMenuEditIntItem ( tr ( " TS buffer size [MB] " ) , & tsBufferSize , 1 , 4 ) ) ;
2008-01-20 15:13:28 +01:00
help . 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
2007-10-07 22:08:44 +02:00
Add ( new cMenuEditIntItem ( tr ( " TS buffer prefill ratio [%] " ) , & tsBufferPrefill , 0 , 40 ) ) ;
2008-01-20 15:13:28 +01:00
help . 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
2008-01-20 15:13:28 +01:00
Add ( new cMenuEditIntItem ( tr ( " EXT protocol base port " ) , & extProtocolBasePort , 0 , 0xFFF7 ) ) ;
2008-01-20 14:17:36 +01:00
help . 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
2008-01-20 15:13:28 +01:00
Add ( new cMenuEditBoolItem ( tr ( " Use section filtering " ) , & sectionFiltering ) ) ;
help . 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
2007-10-06 02:02:50 +02:00
if ( sectionFiltering ) {
2008-01-20 15:13:28 +01:00
Add ( new cMenuEditIntItem ( tr ( " Disable filters " ) , & numDisabledFilters , 0 , SECTION_FILTER_TABLE_SIZE ) ) ;
2008-01-20 14:17:36 +01:00
help . 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
2007-10-06 02:02:50 +02:00
for ( int i = 0 ; i < numDisabledFilters ; + + i ) {
// TRANSLATORS: note the singular!
2008-01-20 15:13:28 +01:00
Add ( new cMenuEditStraItem ( tr ( " Disable filter " ) , & disabledFilterIndexes [ i ] , SECTION_FILTER_TABLE_SIZE , disabledFilterNames ) ) ;
2008-01-20 00:17:20 +01:00
help . 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 )
{
debug ( " cIptvPluginSetup::ShowInfo() \n " ) ;
if ( HasSubMenu ( ) )
return osContinue ;
return AddSubMenu ( new cIptvMenuInfo ( ) ) ;
}
2007-09-15 17:38:38 +02:00
eOSState cIptvPluginSetup : : ProcessKey ( eKeys Key )
{
2007-10-06 02:02:50 +02:00
int oldsectionFiltering = sectionFiltering ;
int oldNumDisabledFilters = numDisabledFilters ;
2007-09-15 17:38:38 +02:00
eOSState state = cMenuSetupPage : : ProcessKey ( Key ) ;
2008-01-20 00:17:20 +01:00
2007-09-18 20:48:10 +02:00
if ( state = = osUnknown ) {
switch ( Key ) {
2007-10-06 22:57:53 +02:00
case kBlue : return ShowInfo ( ) ;
2008-01-19 17:24:40 +01:00
case kInfo : if ( Current ( ) < help . Size ( ) )
return AddSubMenu ( new cMenuText ( cString : : sprintf ( " %s - %s '%s' " , tr ( " Help " ) , trVDR ( " Plugin " ) , PLUGIN_NAME_I18N ) , help [ 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
2007-10-06 02:02:50 +02:00
if ( ( Key ! = kNone ) & & ( ( numDisabledFilters ! = oldNumDisabledFilters ) | | ( sectionFiltering ! = oldsectionFiltering ) ) ) {
2007-10-10 22:54:58 +02:00
while ( ( numDisabledFilters < oldNumDisabledFilters ) & & ( oldNumDisabledFilters > 0 ) )
2007-10-06 02:02:50 +02:00
disabledFilterIndexes [ - - oldNumDisabledFilters ] = - 1 ;
Setup ( ) ;
}
2008-01-20 00:17:20 +01:00
2007-09-15 17:38:38 +02:00
return state ;
}
2007-10-06 02:02:50 +02:00
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 ) ;
}
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
SetupStore ( " TsBufferSize " , tsBufferSize ) ;
SetupStore ( " TsBufferPrefill " , tsBufferPrefill ) ;
2007-10-20 19:26:46 +02:00
SetupStore ( " ExtProtocolBasePort " , extProtocolBasePort ) ;
2007-09-30 23:38:31 +02:00
SetupStore ( " SectionFiltering " , sectionFiltering ) ;
2007-10-06 02:02:50 +02:00
StoreFilters ( " DisabledFilters " , disabledFilterIndexes ) ;
2007-09-16 15:38:20 +02:00
// Update global config
IptvConfig . SetTsBufferSize ( tsBufferSize ) ;
IptvConfig . SetTsBufferPrefillRatio ( tsBufferPrefill ) ;
2007-10-20 19:26:46 +02:00
IptvConfig . SetExtProtocolBasePort ( extProtocolBasePort ) ;
2007-09-30 23:38:31 +02:00
IptvConfig . SetSectionFiltering ( sectionFiltering ) ;
2007-10-06 02:02:50 +02:00
for ( int i = 0 ; i < SECTION_FILTER_TABLE_SIZE ; + + i )
IptvConfig . SetDisabledFilters ( i , disabledFilterIndexes [ i ] ) ;
2007-09-15 17:38:38 +02:00
}