1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection
4 from Components.ActionMap import ActionMap
5 from Screens.MessageBox import MessageBox
6 from Components.Sources.StaticText import StaticText
7 from Plugins.Plugin import PluginDescriptor
8 from Tools.Directories import fileExists
9 from enigma import eTimer
10 from os import system as os_system
11 from __init__ import _
13 config.plugins.transcodingsetup = ConfigSubsection()
14 config.plugins.transcodingsetup.transcoding = ConfigSelection(default = "disabled", choices = [ ("enabled", _("enabled")), ("disabled", _("disabled"))] )
15 config.plugins.transcodingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] )
18 -1 : "File not exist - /proc/stb/encoder/enable.",
19 -2 : "File not exist - /etc/inetd.conf.",
20 -3 : "File open error - /proc/stb/encoder/enable.",
21 -4 : "File open error - /etc/inetd.conf.",
22 -5 : "Set encoder error.",
23 -6 : "Set port error.",
24 -7 : "Setting value is incorrect."
26 class TranscodingSetupInit:
28 self.transcoding_value = config.plugins.transcodingsetup.transcoding.value
29 if self.transcoding_value == "disabled":
30 self.port_value = "8002"
32 self.port_value = config.plugins.transcodingsetup.port.value
33 self.transcoding_old = config.plugins.transcodingsetup.transcoding.value
34 ret = self.setTranscoding(self.transcoding_value, self.port_value)
35 if ret is not None and ret < 0:
36 print "[TranscodingSetup] set failed!(%s, %s)"%(self.transcoding_value, self.port_value)
38 def setTranscoding(self, transcoding, port):
39 if not self.getModel():
40 print "This plugin is only supported for solo2/duo2."
42 if transcoding not in ["enabled","disabled"] or port not in ["8001","8002"]:
45 if not fileExists("/proc/stb/encoder/enable"):
47 elif not fileExists("/etc/inetd.conf"):
49 if self.setEncoder(transcoding) < 0:
51 res = self.setPort(port)
53 self.setEncoder(self.transcoding_old)
59 def setEncoder(self,mode = "disabled"):
60 print "<TranscodingSetup> set encoder : %s" % mode
61 mode = mode.strip(' ').strip('\n')
63 fd = open("/proc/stb/encoder/enable",'r')
64 self.transcoding_old = fd.read()
66 fd = open("/proc/stb/encoder/enable",'w')
69 fd = open("/proc/stb/encoder/enable",'r')
70 encoder_enable = fd.read().strip(' ').strip('\n')
72 if encoder_enable == mode:
75 # print "<TranscodingSetup> can not setting."
78 # print "setEncoder exception error"
81 def setPort(self, port = "8001"):
82 print "<TranscodingSetup> set port : %s" % port
84 fp = file('/etc/inetd.conf', 'r')
85 datas = fp.readlines()
88 # print "file open error, inetd.conf!"
98 if line.find("transtreamproxy") != -1:
99 p=line.replace('\t',' ').find(' ')
101 elif line.find("streamproxy") != -1:
102 p=line.replace('\t',' ').find(' ')
103 line = s_port+line[p:]
106 if newdatas.find("transtreamproxy") == -1:
107 newdatas+=port+'\t'+'stream'+'\t'+'tcp'+'\t'+'nowait'+'\t'+'root'+'\t'+'/usr/bin/transtreamproxy'+'\t'+'transtreamproxy\n'
108 fd = file("/etc/inetd.conf",'w')
115 def inetdRestart(self):
116 if fileExists("/etc/init.d/inetd"):
117 os_system("/etc/init.d/inetd restart")
120 if fileExists("/proc/stb/info/vumodel"):
121 vumodel = open("/proc/stb/info/vumodel")
122 info=vumodel.read().strip()
124 if info in ["solo2", "duo2"]:
131 class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit):
133 <screen position="center,center" size="560,270" title="Transcoding Setup" >
134 <ePixmap pixmap="skin_default/buttons/red.png" position="110,10" size="140,40" alphatest="on" />
135 <ePixmap pixmap="skin_default/buttons/green.png" position="310,10" size="140,40" alphatest="on" />
136 <widget source="key_red" render="Label" position="110,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
137 <widget source="key_green" render="Label" position="310,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
138 <widget name="config" zPosition="2" position="5,70" size="550,70" scrollbarMode="showOnDemand" transparent="1" />
139 <widget source="text" render="Label" position="20,140" size="520,130" font="Regular;18" halign="center" valign="center" />
143 def __init__(self,session):
144 Screen.__init__(self,session)
145 self.session = session
146 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
149 "cancel": self.keyCancel,
150 "red": self.keyCancel,
151 "green": self.keySave,
154 ConfigListScreen.__init__(self, self.list,session = self.session)
155 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
156 TEXT += _("\nWhen transcoding, both PIP and analog video outputs are disabled.")
157 self["key_red"] = StaticText(_("Cancel"))
158 self["key_green"] = StaticText(_("Ok"))
159 self["text"] = StaticText(_("%s")%TEXT)
161 self.onLayoutFinish.append(self.checkModel)
162 self.checkModelTimer = eTimer()
163 self.checkModelTimer.callback.append(self.invalidmodel)
165 def checkModel(self):
166 if not self.getModel():
167 self.checkModelTimer.start(1000,True)
169 def invalidmodel(self):
170 self.session.openWithCallback(self.close, MessageBox, _("This plugin is available on SOLO2/DUO2"), MessageBox.TYPE_ERROR)
172 def createSetup(self):
174 self.transcoding = getConfigListEntry(_("Transcoding"), config.plugins.transcodingsetup.transcoding)
175 self.port = getConfigListEntry(_("Port"), config.plugins.transcodingsetup.port)
176 self.list.append( self.transcoding )
177 if config.plugins.transcodingsetup.transcoding.value == "enabled":
178 self.list.append( self.port )
179 self["config"].list = self.list
180 self["config"].l.setList(self.list)
183 transcoding = config.plugins.transcodingsetup.transcoding.value
184 port = config.plugins.transcodingsetup.port.value
185 print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
186 ret = self.setupTranscoding(transcoding, port)
187 if ret is not None and ret <0 :
190 self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
193 if transcoding == "enabled" and port == "8001" :
194 text = "PC Streaming is replaced with mobile streaming."
195 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.\n%s")%(transcoding,text), MessageBox.TYPE_INFO)
197 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.")%transcoding, MessageBox.TYPE_INFO)
200 def resetConfig(self):
201 for x in self["config"].list:
204 def setupTranscoding(self, transcoding = None, port = None):
205 if transcoding == "disabled":
206 config.plugins.transcodingsetup.port.value = "8002"
208 return self.setTranscoding(transcoding, port)
211 ConfigListScreen.keyLeft(self)
212 if self["config"].getCurrent() == self.transcoding:
216 ConfigListScreen.keyRight(self)
217 if self["config"].getCurrent() == self.transcoding:
220 def main(session, **kwargs):
221 session.open(TranscodingSetup)
223 def Plugins(**kwargs):
224 return [PluginDescriptor(name=_("TranscodingSetup"), description=_("Transcoding Setup"), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
226 transcodingsetupinit = TranscodingSetupInit()