1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection, ConfigInteger
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 _
14 -1 : "File not exist - /proc/stb/encoder/enable.",
15 -2 : "File not exist - /etc/inetd.conf.",
16 -3 : "File open error - /proc/stb/encoder/enable.",
17 -4 : "File open error - /etc/inetd.conf.",
18 -5 : "Set encoder error.",
19 -6 : "Set port error.",
20 -7 : "Setting value is incorrect.",
21 -8 : "Set encoder bitrate error.",
22 -9 : "Set encoder framerate error.",
24 TranscodingConfigList = []
26 class TranscodingSetupInit:
28 self.createConfigList()
30 self.transcoding_value = config.plugins.transcodingsetup.transcoding.value
31 if self.transcoding_value == "disable":
32 self.port_value = "8002"
34 self.port_value = config.plugins.transcodingsetup.port.value
35 self.transcoding_old = config.plugins.transcodingsetup.transcoding.value
36 res = self.setTranscoding(self.transcoding_value, self.port_value)
37 if res is not None and res < 0:
38 print "[TranscodingSetup] set failed!(%s, %s, %d)"%(self.transcoding_value, self.port_value, res)
40 def createConfigList(self):
41 global TranscodingConfigList
43 ["Bitrate", "/proc/stb/encoder/0/bitrate", -8],
44 ["Framerate", "/proc/stb/encoder/0/framerate", -9]
48 TranscodingConfigList.append(x)
50 def createConfig(self):
51 config.plugins.transcodingsetup = ConfigSubsection()
52 config.plugins.transcodingsetup.transcoding = ConfigSelection(default = "disable", choices = [ ("enable", _("enable")), ("disable", _("disable"))] )
53 config.plugins.transcodingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] )
54 global TranscodingConfigList
55 for x in TranscodingConfigList:
57 config.plugins.transcodingsetup.bitrate = ConfigInteger(default = 2000000, limits = (100000, 5000000))
58 x.append(config.plugins.transcodingsetup.bitrate)
59 elif x[0] == "Framerate":
60 config.plugins.transcodingsetup.framerate = ConfigSelection(default = "30000", choices = [ ("23976", _("23976")), ("24000", _("24000")), ("29970", _("29970")), ("30000", _("30000")), ("59940", _("59940")), ("60000", _("60000"))])
61 x.append(config.plugins.transcodingsetup.framerate)
63 def setTranscoding(self, transcoding, port):
64 if transcoding not in ["enable","disable"] or port not in ["8001","8002"]:
65 # print "Input error."
67 if not fileExists("/proc/stb/encoder/enable"):
69 elif not fileExists("/etc/inetd.conf"):
71 res = self.setEncoderExtra()
74 if self.setEncoderEnable(transcoding) < 0:
76 res = self.setPort(port)
78 self.setEncoderEnable(self.transcoding_old)
84 def setEncoderEnable(self,mode = "disable"):
85 # print "<TranscodingSetup> set encoder %s" % mode
86 mode = mode.strip(' ').strip('\n')
88 fd = open("/proc/stb/encoder/enable",'r')
89 self.transcoding_old = fd.read()
91 fd = open("/proc/stb/encoder/enable",'w')
94 fd = open("/proc/stb/encoder/enable",'r')
95 encoder_enable = fd.read().strip(' ').strip('\n')
97 if encoder_enable == mode:
100 # print "<TranscodingSetup> can not setting."
103 # print "setEncoderEnable exception error"
106 def setPort(self, port = "8001"):
107 # print "<TranscodingSetup> set port %s" % port
109 fp = file('/etc/inetd.conf', 'r')
110 datas = fp.readlines()
113 # print "file open error, inetd.conf!"
123 if line.find("transtreamproxy") != -1:
124 p=line.replace('\t',' ').find(' ')
126 elif line.find("streamproxy") != -1:
127 p=line.replace('\t',' ').find(' ')
128 line = s_port+line[p:]
131 if newdatas.find("transtreamproxy") == -1:
132 newdatas+=port+'\t'+'stream'+'\t'+'tcp'+'\t'+'nowait'+'\t'+'root'+'\t'+'/usr/bin/transtreamproxy'+'\t'+'transtreamproxy\n'
133 fd = file("/etc/inetd.conf",'w')
140 def inetdRestart(self):
141 if fileExists("/etc/init.d/inetd"):
142 os_system("/etc/init.d/inetd restart")
143 elif fileExists("/etc/init.d/inetd.busybox"):
144 os_system("/etc/init.d/inetd.busybox restart")
146 def setEncoderExtra(self):
147 global TranscodingConfigList
148 for x in TranscodingConfigList:
149 if self.setEncoder(x[1], x[3].value):
153 def setEncoder(self, procPath, value):
154 # print "<TranscodingSetup> set %s "%procPath, value
155 if not fileExists(procPath):
157 if isinstance(value, str):
158 value = value.strip(' ').strip('\n')
162 fd = open(procPath,'r')
163 old_value = fd.read().strip(' ').strip('\n')
165 if old_value != value:
166 fd = open(procPath,'w')
169 fd = open(procPath,'r')
170 encoder_value = fd.read().strip(' ').strip('\n')
172 if encoder_value != value:
178 class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit):
180 <screen position="center,center" size="400,270" title="Transcoding Setup" >
181 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
182 <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
183 <widget source="key_red" render="Label" position="30,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
184 <widget source="key_green" render="Label" position="230,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
185 <widget name="config" zPosition="2" position="5,70" size="390,70" scrollbarMode="showOnDemand" transparent="1" />
186 <widget source="text" render="Label" position="20,140" size="370,130" font="Regular;18" halign="center" valign="center" />
190 <screen position="center,center" size="400,320" title="Transcoding Setup" >
191 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
192 <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
193 <widget source="key_red" render="Label" position="30,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
194 <widget source="key_green" render="Label" position="230,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
195 <widget name="config" zPosition="2" position="5,70" size="390,120" scrollbarMode="showOnDemand" transparent="1" />
196 <widget source="text" render="Label" position="20,190" size="370,130" font="Regular;18" halign="center" valign="center" />
200 def __init__(self,session):
201 if fileExists("/proc/stb/encoder/0/framerate"):
202 self.skin = TranscodingSetup.skin_ext
203 Screen.__init__(self,session)
204 self.skinName = "TranscodingSetup_ext"
206 Screen.__init__(self,session)
208 if self.getModel() == "duo2":
209 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
210 TEXT += _("\nWhen transcoding, PIP is disabled.")
212 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
213 TEXT += _("\nWhen transcoding, both PIP and analog video outputs are disabled.")
214 self.session = session
215 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
218 "cancel": self.keyCancel,
219 "red": self.keyCancel,
220 "green": self.keySave,
223 ConfigListScreen.__init__(self, self.list,session = self.session)
224 self["key_red"] = StaticText(_("Cancel"))
225 self["key_green"] = StaticText(_("Ok"))
226 self["text"] = StaticText(_("%s")%TEXT)
228 self.onLayoutFinish.append(self.checkEncoder)
229 self.invaliedModelTimer = eTimer()
230 self.invaliedModelTimer.callback.append(self.invalidmodel)
233 if fileExists("/proc/stb/info/vumodel"):
234 fd = open("/proc/stb/info/vumodel")
235 vumodel=fd.read().strip()
241 def checkEncoder(self):
242 if not fileExists("/proc/stb/encoder/enable"):
243 self.invaliedModelTimer.start(100,True)
245 def invalidmodel(self):
246 self.session.openWithCallback(self.close, MessageBox, _("This model is not support transcoding."), MessageBox.TYPE_ERROR)
248 def createSetup(self):
249 global TranscodingConfigList
251 self.transcoding = getConfigListEntry(_("Transcoding"), config.plugins.transcodingsetup.transcoding)
252 self.port = getConfigListEntry(_("Port"), config.plugins.transcodingsetup.port)
253 self.list.append( self.transcoding )
254 if config.plugins.transcodingsetup.transcoding.value == "enable":
255 self.list.append( self.port )
256 for x in TranscodingConfigList:
257 self.list.append(getConfigListEntry(_(x[0]), x[3]))
259 self["config"].list = self.list
260 self["config"].l.setList(self.list)
263 transcoding = config.plugins.transcodingsetup.transcoding.value
264 port = config.plugins.transcodingsetup.port.value
265 # print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
266 ret = self.setupTranscoding(transcoding, port)
267 if ret is not None and ret <0 :
270 self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
273 if transcoding == "enable" and port == "8001" :
274 text = "PC Streaming is replaced with mobile streaming."
275 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.\n%s")%(transcoding,text), MessageBox.TYPE_INFO)
277 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.")%transcoding, MessageBox.TYPE_INFO)
280 def resetConfig(self):
281 for x in self["config"].list:
284 def setupTranscoding(self, transcoding = None, port = None):
285 if transcoding == "disable":
286 config.plugins.transcodingsetup.port.value = "8002"
288 return self.setTranscoding(transcoding, port)
291 ConfigListScreen.keyLeft(self)
292 if self["config"].getCurrent() == self.transcoding:
296 ConfigListScreen.keyRight(self)
297 if self["config"].getCurrent() == self.transcoding:
300 def main(session, **kwargs):
301 session.open(TranscodingSetup)
303 def Plugins(**kwargs):
304 return [PluginDescriptor(name=_("TranscodingSetup"), description=_("Transcoding Setup"), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
306 transcodingsetupinit = TranscodingSetupInit()