From: hschang Date: Wed, 3 Jul 2013 05:54:07 +0000 (+0900) Subject: TranscodingSetup : add bitrate/framerate support. X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=commitdiff_plain;h=bf3bf39c3d2517264fd2f92ed35d105e656f38c8 TranscodingSetup : add bitrate/framerate support. --- diff --git a/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py b/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py index 7bb47a4..ec832bb 100755 --- a/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py +++ b/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py @@ -1,6 +1,6 @@ from Screens.Screen import Screen from Components.ConfigList import ConfigListScreen -from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection +from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection, ConfigInteger from Components.ActionMap import ActionMap from Screens.MessageBox import MessageBox from Components.Sources.StaticText import StaticText @@ -10,10 +10,6 @@ from enigma import eTimer from os import system as os_system from __init__ import _ -config.plugins.transcodingsetup = ConfigSubsection() -config.plugins.transcodingsetup.transcoding = ConfigSelection(default = "disabled", choices = [ ("enabled", _("enabled")), ("disabled", _("disabled"))] ) -config.plugins.transcodingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] ) - error_msg ={ -1 : "File not exist - /proc/stb/encoder/enable.", -2 : "File not exist - /etc/inetd.conf.", @@ -21,43 +17,72 @@ error_msg ={ -4 : "File open error - /etc/inetd.conf.", -5 : "Set encoder error.", -6 : "Set port error.", - -7 : "Setting value is incorrect." + -7 : "Setting value is incorrect.", + -8 : "Set encoder bitrate error.", + -9 : "Set encoder framerate error.", } +TranscodingConfigList = [] + class TranscodingSetupInit: def __init__(self): + self.createConfigList() + self.createConfig() self.transcoding_value = config.plugins.transcodingsetup.transcoding.value - if self.transcoding_value == "disabled": + if self.transcoding_value == "disable": self.port_value = "8002" else: self.port_value = config.plugins.transcodingsetup.port.value self.transcoding_old = config.plugins.transcodingsetup.transcoding.value - ret = self.setTranscoding(self.transcoding_value, self.port_value) - if ret is not None and ret < 0: - print "[TranscodingSetup] set failed!(%s, %s)"%(self.transcoding_value, self.port_value) + res = self.setTranscoding(self.transcoding_value, self.port_value) + if res is not None and res < 0: + print "[TranscodingSetup] set failed!(%s, %s, %d)"%(self.transcoding_value, self.port_value, res) + + def createConfigList(self): + global TranscodingConfigList + configList = [ + ["Bitrate", "/proc/stb/encoder/0/bitrate", -8], + ["Framerate", "/proc/stb/encoder/0/framerate", -9] + ] + for x in configList: + if fileExists(x[1]): + TranscodingConfigList.append(x) + + def createConfig(self): + config.plugins.transcodingsetup = ConfigSubsection() + config.plugins.transcodingsetup.transcoding = ConfigSelection(default = "disable", choices = [ ("enable", _("enable")), ("disable", _("disable"))] ) + config.plugins.transcodingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] ) + global TranscodingConfigList + for x in TranscodingConfigList: + if x[0] == "Bitrate": + config.plugins.transcodingsetup.bitrate = ConfigInteger(default = 2000000, limits = (100000, 5000000)) + x.append(config.plugins.transcodingsetup.bitrate) + elif x[0] == "Framerate": + config.plugins.transcodingsetup.framerate = ConfigSelection(default = "30000", choices = [ ("23976", _("23976")), ("24000", _("24000")), ("29970", _("29970")), ("30000", _("30000")), ("59940", _("59940")), ("60000", _("60000"))]) + x.append(config.plugins.transcodingsetup.framerate) def setTranscoding(self, transcoding, port): - if not self.getModel(): - print "This plugin is only supported for solo2/duo2." - return -8 - if transcoding not in ["enabled","disabled"] or port not in ["8001","8002"]: + if transcoding not in ["enable","disable"] or port not in ["8001","8002"]: print "Input error." return -7 if not fileExists("/proc/stb/encoder/enable"): return -1 elif not fileExists("/etc/inetd.conf"): return -2 - if self.setEncoder(transcoding) < 0: + res = self.setEncoderExtra() + if res < 0: + return res + if self.setEncoderEnable(transcoding) < 0: return -5 res = self.setPort(port) if res < 0: - self.setEncoder(self.transcoding_old) + self.setEncoderEnable(self.transcoding_old) return res else: self.inetdRestart() return res - def setEncoder(self,mode = "disabled"): - print " set encoder : %s" % mode + def setEncoderEnable(self,mode = "disable"): + print " set encoder %s" % mode mode = mode.strip(' ').strip('\n') try: fd = open("/proc/stb/encoder/enable",'r') @@ -75,11 +100,11 @@ class TranscodingSetupInit: # print " can not setting." return -1 except: -# print "setEncoder exception error" +# print "setEncoderEnable exception error" return -1 def setPort(self, port = "8001"): - print " set port : %s" % port + print " set port %s" % port try: fp = file('/etc/inetd.conf', 'r') datas = fp.readlines() @@ -116,17 +141,37 @@ class TranscodingSetupInit: if fileExists("/etc/init.d/inetd"): os_system("/etc/init.d/inetd restart") - def getModel(self): - if fileExists("/proc/stb/info/vumodel"): - vumodel = open("/proc/stb/info/vumodel") - info=vumodel.read().strip() - vumodel.close() - if info in ["solo2", "duo2"]: - return True - else: - return False + def setEncoderExtra(self): + global TranscodingConfigList + for x in TranscodingConfigList: + if self.setEncoder(x[1], x[3].value): + return x[2] + return 0 + + def setEncoder(self, procPath, value): + print " set %s "%procPath, value + if not fileExists(procPath): + return -1 + if isinstance(value, str): + value = value.strip(' ').strip('\n') else: - return False + value = str(value) + try: + fd = open(procPath,'r') + old_value = fd.read().strip(' ').strip('\n') + fd.close() + if old_value != value: + fd = open(procPath,'w') + fd.write(value) + fd.close() + fd = open(procPath,'r') + encoder_value = fd.read().strip(' ').strip('\n') + fd.close() + if encoder_value != value: + return -1 + return 0 + except: + return -1 class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit): skin = """ @@ -139,9 +184,31 @@ class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit): """ + skin_ext = """ + + + + + + + + + """ def __init__(self,session): - Screen.__init__(self,session) + if fileExists("/proc/stb/encoder/0/framerate"): + self.skin = TranscodingSetup.skin_ext + Screen.__init__(self,session) + self.skinName = "TranscodingSetup_ext" + else: + Screen.__init__(self,session) + + if self.getModel() == "duo2": + TEXT = _("Transcoding can be started when there is no corresponding channel recordings.") + TEXT += _("\nWhen transcoding, PIP is disabled.") + else: + TEXT = _("Transcoding can be started when there is no corresponding channel recordings.") + TEXT += _("\nWhen transcoding, both PIP and analog video outputs are disabled.") self.session = session self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ], { @@ -152,37 +219,48 @@ class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit): }, -2) self.list = [] ConfigListScreen.__init__(self, self.list,session = self.session) - TEXT = _("Transcoding can be started when there is no corresponding channel recordings.") - TEXT += _("\nWhen transcoding, both PIP and analog video outputs are disabled.") self["key_red"] = StaticText(_("Cancel")) self["key_green"] = StaticText(_("Ok")) self["text"] = StaticText(_("%s")%TEXT) self.createSetup() - self.onLayoutFinish.append(self.checkModel) - self.checkModelTimer = eTimer() - self.checkModelTimer.callback.append(self.invalidmodel) + self.onLayoutFinish.append(self.checkEncoder) + self.invaliedModelTimer = eTimer() + self.invaliedModelTimer.callback.append(self.invalidmodel) + + def getModel(self): + if fileExists("/proc/stb/info/vumodel"): + fd = open("/proc/stb/info/vumodel") + vumodel=fd.read().strip() + fd.close() + return vumodel + else: + return "" - def checkModel(self): - if not self.getModel(): - self.checkModelTimer.start(1000,True) + def checkEncoder(self): + if not fileExists("/proc/stb/encoder/enable"): + self.invaliedModelTimer.start(100,True) def invalidmodel(self): - self.session.openWithCallback(self.close, MessageBox, _("This plugin is available on SOLO2/DUO2"), MessageBox.TYPE_ERROR) + self.session.openWithCallback(self.close, MessageBox, _("This model is not support transcoding."), MessageBox.TYPE_ERROR) def createSetup(self): + global TranscodingConfigList self.list = [] self.transcoding = getConfigListEntry(_("Transcoding"), config.plugins.transcodingsetup.transcoding) self.port = getConfigListEntry(_("Port"), config.plugins.transcodingsetup.port) self.list.append( self.transcoding ) - if config.plugins.transcodingsetup.transcoding.value == "enabled": + if config.plugins.transcodingsetup.transcoding.value == "enable": self.list.append( self.port ) + for x in TranscodingConfigList: + self.list.append(getConfigListEntry(_(x[0]), x[3])) + self["config"].list = self.list self["config"].l.setList(self.list) def keySave(self): transcoding = config.plugins.transcodingsetup.transcoding.value port = config.plugins.transcodingsetup.port.value - print " Transcoding %s(port : %s)"%(transcoding, port) +# print " Transcoding %s(port : %s)"%(transcoding, port) ret = self.setupTranscoding(transcoding, port) if ret is not None and ret <0 : self.resetConfig() @@ -190,7 +268,7 @@ class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit): self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR) else: self.saveAll() - if transcoding == "enabled" and port == "8001" : + if transcoding == "enable" and port == "8001" : text = "PC Streaming is replaced with mobile streaming." self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.\n%s")%(transcoding,text), MessageBox.TYPE_INFO) else: @@ -202,7 +280,7 @@ class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit): x[1].cancel() def setupTranscoding(self, transcoding = None, port = None): - if transcoding == "disabled": + if transcoding == "disable": config.plugins.transcodingsetup.port.value = "8002" port = "8002" return self.setTranscoding(transcoding, port)