diff options
-rwxr-xr-x | smarttvfactory.c | 11 | ||||
-rwxr-xr-x | smarttvfactory.h | 2 | ||||
-rw-r--r-- | smarttvweb.c | 20 | ||||
-rwxr-xr-x | stvw_cfg.c | 166 | ||||
-rwxr-xr-x | stvw_cfg.h | 43 |
5 files changed, 227 insertions, 15 deletions
diff --git a/smarttvfactory.c b/smarttvfactory.c index 3d18fd5..cac8330 100755 --- a/smarttvfactory.c +++ b/smarttvfactory.c @@ -1078,17 +1078,20 @@ void SmartTvServer::initCmdCmds() { } -void SmartTvServer::initServer(string dir) { +void SmartTvServer::initServer(string dir, cSmartTvConfig* cfg) { /* This function initialtes the listening socket for the server * and sets isInited to true */ + esyslog("SmartTvWeb: initServer dir= %s", dir.c_str()); mConfigDir = dir; int ret; struct sockaddr_in sock; int yes = 1; #ifndef STANDALONE - mConfig = new cSmartTvConfig(dir); + // mConfig = new cSmartTvConfig(dir); + mConfig = cfg; + mConfig->Initialize(dir); serverPort = mConfig->getServerPort(); mLog.init(mConfig->getLogFile()); @@ -1104,8 +1107,8 @@ void SmartTvServer::initServer(string dir) { #else mConfig = new cSmartTvConfig("."); mLog.init(mConfig->getLogFile()); - cout << "SmartTvWeb: Logfile created" << endl; - cout << "SmartTvWeb: Listening on port= " << PORT << endl; + esyslog ("SmartTvWeb: Logfile created"); + esyslog ("SmartTvWeb: Listening on port= %d", PORT); #endif diff --git a/smarttvfactory.h b/smarttvfactory.h index a2a53f1..1762967 100755 --- a/smarttvfactory.h +++ b/smarttvfactory.h @@ -153,7 +153,7 @@ class SmartTvServer : public cStatus { SmartTvServer(); virtual ~SmartTvServer(); - void initServer(string c_dir); + void initServer(string c_dir, cSmartTvConfig* cfg); void loop(); void cleanUp(); int runAsThread(); diff --git a/smarttvweb.c b/smarttvweb.c index 60827e4..1412533 100644 --- a/smarttvweb.c +++ b/smarttvweb.c @@ -59,6 +59,7 @@ public: virtual bool ProcessArgs(int argc, char *argv[]); virtual bool Initialize(void); virtual bool Start(void); + virtual void Stop(void); virtual bool SetupParse(const char *Name, const char *Value); virtual const char **SVDRPHelpPages(void); @@ -71,6 +72,7 @@ public: private: SmartTvServer mServer; string mConfigDir; + cSmartTvConfig * mConfig; }; cPluginSmartTvWeb::cPluginSmartTvWeb(void) { @@ -78,6 +80,13 @@ cPluginSmartTvWeb::cPluginSmartTvWeb(void) { // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT! mConfigDir = ""; + mConfig = new cSmartTvConfig(); + + esyslog("SmartTvWeb: Constructor ConfigName= %s", cPlugin::ConfigDirectory(Name())); +} + +void cPluginSmartTvWeb::Stop(void) { + // mConfig->Store(this); } bool cPluginSmartTvWeb::Start(void) { @@ -92,7 +101,7 @@ bool cPluginSmartTvWeb::Start(void) { mConfigDir = string(dir_name); } - mServer.initServer(mConfigDir); + mServer.initServer(mConfigDir, mConfig); int success = mServer.runAsThread(); esyslog("SmartTvWeb: started %s", (success == 1) ? "sucessfully" : "failed!!!!"); @@ -123,10 +132,12 @@ bool cPluginSmartTvWeb::Initialize(void) { return true; } -bool cPluginSmartTvWeb::SetupParse(const char *Name, const char *Value) -{ +bool cPluginSmartTvWeb::SetupParse(const char *Name, const char *Value) { // Parse your own setup parameters and store their values. - return false; + esyslog("SmartTvWeb: SetupParse K= %s V= %s", Name, Value); + return mConfig->SetupParse(Name, Value); + + // return false; } const char **cPluginSmartTvWeb::SVDRPHelpPages(void) { @@ -168,6 +179,7 @@ cString cPluginSmartTvWeb::Active(void) { return NULL; } + #endif VDRPLUGINCREATOR(cPluginSmartTvWeb); // Don't touch this! @@ -31,7 +31,7 @@ #include <cstdio> #include <cstdlib> -cSmartTvConfig::cSmartTvConfig(string d): mConfigDir(d), mLog(NULL), mCfgFile(NULL), +cSmartTvConfig::cSmartTvConfig(): mConfigDir(""), mLog(NULL), mCfgFile(NULL), mUseVdrSetupConf(false), mLogFile(), mMediaFolder(), mSegmentDuration(), mHasMinBufferTime(), mHasBitrateCorrection(), mLiveChannels(), mGroupSep(IGNORE), mServerAddress(""), mServerPort(8000), mCmds(false), mUseStreamDev4Live(true), mBuiltInLiveStartMode (4), mBuiltInLivePktBuf4Hd(150), mBuiltInLivePktBuf4Sd(75), mBuiltInLiveBufDur(0.6), @@ -49,7 +49,91 @@ cSmartTvConfig::cSmartTvConfig(string d): mConfigDir(d), mLog(NULL), mCfgFile(NU mHasMinBufferTime = 40; mHasBitrateCorrection = 1.1; mLiveChannels = 30; +} + +cSmartTvConfig::~cSmartTvConfig() { +} + + +void cSmartTvConfig::Store(cPlugin *mPlugin) { + mPlugin->SetupStore("LiveChannels", mLiveChannels); + mPlugin->SetupStore("LogFile", mLogFile.c_str()); + mPlugin->SetupStore("MediaFolder", mMediaFolder.c_str()); + mPlugin->SetupStore("SegmentDuration", mSegmentDuration); + mPlugin->SetupStore("HasMinBufferTime", mHasMinBufferTime); + mPlugin->SetupStore("HasBitrateCorrection", mHasBitrateCorrection); + switch (mGroupSep) { + case EMPTYIGNORE: + mPlugin->SetupStore("GroupSeparators", "EmptyIgnore"); + break; + case EMPTYFOLDERDOWN: + mPlugin->SetupStore("GroupSeparators", "EmptyFolderDown"); + break; + } + mPlugin->SetupStore("ServerAddress", mServerAddress.c_str()); + mPlugin->SetupStore("ServerPort", mServerPort); + mPlugin->SetupStore("Commands", (mCmds ? 1 : 0)); + mPlugin->SetupStore("UseStreamDev4Live", (mUseStreamDev4Live ? 1 : 0)); + mPlugin->SetupStore("BuiltInLiveBufDur", (mBuiltInLiveBufDur ? 1 : 0)); + if (mAddCorsHeader) + mPlugin->SetupStore("CorsHeader", mCorsHeaderPyld.c_str()); + else + mPlugin->SetupStore("CorsHeader"); +} + +bool cSmartTvConfig::SetupParse(const char *name, const char *value) { + + if ( strcmp( name, "LiveChannels" ) == 0 ) + mLiveChannels = atoi( value ); + else if ( strcmp( name, "LogFile" ) == 0 ) + mLogFile = string(value); + else if ( strcmp(name, "MediaFolder") == 0) + mMediaFolder = string (value); + else if (strcmp(name, "SegmentDuration") == 0) + mSegmentDuration = atoi(value); + else if (strcmp(name, "HasMinBufferTime") == 0) + mHasMinBufferTime = atoi(value); + else if (strcmp(name, "HasBitrateCorrection") == 0) + mHasBitrateCorrection = atof(value); + else if (strcmp(name, "GroupSeparators") == 0) { + if (strcmp (value, "EmptyIgnore") == 0) { + mGroupSep = EMPTYIGNORE; + } + else if ( strcmp(value, "EmptyFolderDown") == 0) { + mGroupSep = EMPTYFOLDERDOWN; + } + } + else if (strcmp(name, "ServerAddress") == 0) + mServerAddress = value; + else if (strcmp(name, "ServerPort") == 0) { + mServerPort = atoi(value); + } + else if (strcmp(name, "Commands") == 0) { + if (strcmp(value, "enable") == 0) + mCmds = true; + } + else if (strcmp(name, "UseStreamDev4Live") == 0) { + if (strcmp(value, "false") == 0) + mUseStreamDev4Live = false; + } + else if (strcmp(name, "BuiltInLiveBufDur") == 0) { + mBuiltInLiveBufDur = atoi(value) /1000.0; + if (mBuiltInLiveBufDur <= 0.0) + mBuiltInLiveBufDur = 0.5; + } + else if (strcmp(name, "CorsHeader") == 0) { + mAddCorsHeader = true; + mCorsHeaderPyld = value; + } + else + return false; + mUseVdrSetupConf = true; + return true; +} + +void cSmartTvConfig::Initialize(string dir) { + mConfigDir = dir; readConfig(); struct stat statbuf; @@ -61,9 +145,6 @@ cSmartTvConfig::cSmartTvConfig(string d): mConfigDir(d), mLog(NULL), mCfgFile(NU } } -cSmartTvConfig::~cSmartTvConfig() { -} - void cSmartTvConfig::printConfig() { mLog = Log::getInstance(); @@ -87,18 +168,35 @@ void cSmartTvConfig::printConfig() { } + +//void cSmartTvConfig::readPluginConfig() { + /* + mPlugin = cPluginManager::GetPlugin("smarttvweb"); + + if (!mPlugin) + return; + + mPlugin->SetupStore("LiveChannels", mLiveChannels); + */ +//} + void cSmartTvConfig::readConfig() { string line; char attr[200]; char value[200]; + if (mUseVdrSetupConf) { + esyslog("SmartTvWeb: Using config from VDR setup"); + return; + } + ifstream myfile ((mConfigDir +"/smarttvweb.conf").c_str()); if (!myfile.is_open()) { #ifndef STANDALONE esyslog ("ERROR in SmartTvWeb: Cannot open config file. Expecting %s", (mConfigDir +"/smarttvweb.conf").c_str() ); #else - cout << "ERROR: Cannot open config file. Expecting "<< (mConfigDir +"/smarttvweb.conf") << endl; + cout << "ERROR in SmartTvWeb: Cannot open config file. Expecting "<< (mConfigDir +"/smarttvweb.conf") << endl; #endif return; } @@ -255,3 +353,61 @@ cResumes* cSmartTvConfig::readConfig(string f) { return NULL; } */ + +cWidgetConfigBase::cWidgetConfigBase() { + mUseDefaultBuffer = false; + mTotalBufferSize = 3500000; + mInitialBufferSize = 1000000; + mPendingBufferSize = 500000; + mSkipDuration = 30; + mUsePdlForRecordings = true; + mFormat = "hls"; + mLiveChannels = 20; + mDirectAccessTimeout = 2000; + mSortType = 0; + mPlayKeyBehavior = 0; + mShowInfoMsgs = true; + mWidgetdebug = false; +} + +string cWidgetConfigBase::BoolLine(string name, bool val) { + string res = "<" + name + ">" ; + res += (val ? "true" : "false"); + res += "</" + name + ">\r\n"; + return res; +} + +string cWidgetConfigBase::IntLine(string name, int val) { + snprintf(f, sizeof(f), "%d", val); + string res = "<" + name + ">"; + res += f; + res += "</" + name + ">\r\n"; + return res; +} + +string cWidgetConfigBase::GetWidgetConf() { + + string res = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"; + res += "<config>\r\n"; + + res += BoolLine("useDefaultBuffer", mUseDefaultBuffer); + res += IntLine("totalBufferSize", mTotalBufferSize); + res += IntLine("initialBufferSize", mInitialBufferSize); + res += IntLine("pendingBufferSize", mPendingBufferSize); + res += IntLine("skipDuration", mSkipDuration); + + res += BoolLine("usePdlForRecordings", mUsePdlForRecordings); + + // snprintf(f, sizeof(f), "%s", mFormat); + res += "<format>" + mFormat + "</format>\r\n"; + + res += IntLine("liveChannels", mLiveChannels); + res += IntLine ("directAccessTimeout", mDirectAccessTimeout); + res += IntLine("sortType", mSortType); + res += IntLine ("playKeyBehavior", mPlayKeyBehavior); + res += BoolLine("showInfoMsgs", mShowInfoMsgs); + res += BoolLine("widgetdebug", mWidgetdebug); + + res += "</config>"; + return res; +} @@ -39,12 +39,43 @@ enum eGroupSep { EMPTYFOLDERDOWN }; +class cWidgetConfigBase { + private: + bool mUseDefaultBuffer; + int mTotalBufferSize; + int mInitialBufferSize; + int mPendingBufferSize; + int mSkipDuration; + bool mUsePdlForRecordings; + string mFormat; + int mLiveChannels; + int mDirectAccessTimeout; + int mSortType; + int mPlayKeyBehavior; + bool mShowInfoMsgs; + bool mWidgetdebug; + + char f[400]; + + string BoolLine(string name, bool val); + string IntLine(string name, int val); + + public: + cWidgetConfigBase(); + + string GetWidgetConf(); + +}; + +class cPlugin; + class cSmartTvConfig { private: string mConfigDir; Log* mLog; FILE *mCfgFile; + bool mUseVdrSetupConf; string mLogFile; string mMediaFolder; bool mHaveMediaFolder; @@ -66,11 +97,18 @@ class cSmartTvConfig { bool mAddCorsHeader; string mCorsHeaderPyld; + // cPlugin* mPlugin; + cWidgetConfigBase mWidgetConfigBase; public: - cSmartTvConfig(string dir); + cSmartTvConfig(); ~cSmartTvConfig(); + bool SetupParse(const char *Name, const char *Value); + void Store(cPlugin *mPlugin); + + void Initialize(string dir); void readConfig(); + // void readPluginConfig(); void printConfig(); string getLogFile() { return mLogFile; }; @@ -92,6 +130,9 @@ class cSmartTvConfig { bool addCorsHeader() { return mAddCorsHeader; }; string getCorsHeader() {return mCorsHeaderPyld; }; + + string GetWidgetConf() { return mWidgetConfigBase.GetWidgetConf(); }; }; + #endif |