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)
51 if fileExists("/proc/stb/info/vumodel"):
52 fd = open("/proc/stb/info/vumodel")
53 vumodel=fd.read().strip()
59 def createConfig(self):
60 config.plugins.transcodingsetup = ConfigSubsection()
61 config.plugins.transcodingsetup.transcoding = ConfigSelection(default = "disable", choices = [ ("enable", _("enable")), ("disable", _("disable"))] )
62 config.plugins.transcodingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] )
63 global TranscodingConfigList
64 for x in TranscodingConfigList:
66 if self.getModel() == "solo2":
67 default_bitrate = 400000
71 default_bitrate = 2000000
74 config.plugins.transcodingsetup.bitrate = ConfigInteger(default = default_bitrate, limits = (br_min, br_max))
75 x.append(config.plugins.transcodingsetup.bitrate)
76 elif x[0] == "Framerate":
77 config.plugins.transcodingsetup.framerate = ConfigSelection(default = "30000", choices = [ ("23976", _("23976")), ("24000", _("24000")), ("25000", _("25000")), ("29970", _("29970")), ("30000", _("30000")), ("50000", _("50000")), ("59940", _("59940")), ("60000", _("60000"))])
78 x.append(config.plugins.transcodingsetup.framerate)
80 def setTranscoding(self, transcoding, port):
81 if transcoding not in ["enable","disable"] or port not in ["8001","8002"]:
82 # print "Input error."
84 if not fileExists("/proc/stb/encoder/enable"):
86 elif not fileExists("/etc/inetd.conf"):
88 res = self.setEncoderExtra()
91 if self.setEncoderEnable(transcoding) < 0:
93 res = self.setPort(port)
95 self.setEncoderEnable(self.transcoding_old)
101 def setEncoderEnable(self,mode = "disable"):
102 # print "<TranscodingSetup> set encoder %s" % mode
103 mode = mode.strip(' ').strip('\n')
105 fd = open("/proc/stb/encoder/enable",'r')
106 self.transcoding_old = fd.read()
108 fd = open("/proc/stb/encoder/enable",'w')
111 fd = open("/proc/stb/encoder/enable",'r')
112 encoder_enable = fd.read().strip(' ').strip('\n')
114 if encoder_enable == mode:
117 # print "<TranscodingSetup> can not setting."
120 # print "setEncoderEnable exception error"
123 def setPort(self, port = "8001"):
124 # print "<TranscodingSetup> set port %s" % port
126 fp = file('/etc/inetd.conf', 'r')
127 datas = fp.readlines()
130 # print "file open error, inetd.conf!"
140 if line.find("transtreamproxy") != -1:
141 p=line.replace('\t',' ').find(' ')
143 elif line.find("streamproxy") != -1:
144 p=line.replace('\t',' ').find(' ')
145 line = s_port+line[p:]
148 if newdatas.find("transtreamproxy") == -1:
149 newdatas+=port+'\t'+'stream'+'\t'+'tcp'+'\t'+'nowait'+'\t'+'root'+'\t'+'/usr/bin/transtreamproxy'+'\t'+'transtreamproxy\n'
150 fd = file("/etc/inetd.conf",'w')
157 def inetdRestart(self):
158 if fileExists("/etc/init.d/inetd"):
159 os_system("/etc/init.d/inetd restart")
160 elif fileExists("/etc/init.d/inetd.busybox"):
161 os_system("/etc/init.d/inetd.busybox restart")
163 def setEncoderExtra(self):
164 global TranscodingConfigList
165 for x in TranscodingConfigList:
166 if self.setEncoder(x[1], x[3].value):
170 def setEncoder(self, procPath, value):
171 # print "<TranscodingSetup> set %s "%procPath, value
172 if not fileExists(procPath):
174 if isinstance(value, str):
175 value = value.strip(' ').strip('\n')
179 fd = open(procPath,'r')
180 old_value = fd.read().strip(' ').strip('\n')
182 if old_value != value:
183 print "<TranscodingSetup> set %s "%procPath, value
184 fd = open(procPath,'w')
187 fd = open(procPath,'r')
188 encoder_value = fd.read().strip(' ').strip('\n')
190 if encoder_value != value:
196 class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit):
198 <screen position="center,center" size="400,270" title="Transcoding Setup" >
199 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
200 <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
201 <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" />
202 <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" />
203 <widget name="config" zPosition="2" position="5,70" size="390,70" scrollbarMode="showOnDemand" transparent="1" />
204 <widget source="text" render="Label" position="20,140" size="370,130" font="Regular;18" halign="center" valign="center" />
208 <screen position="center,center" size="400,320" title="Transcoding Setup" >
209 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
210 <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
211 <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" />
212 <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" />
213 <widget name="config" zPosition="2" position="5,70" size="390,120" scrollbarMode="showOnDemand" transparent="1" />
214 <widget source="text" render="Label" position="20,190" size="370,130" font="Regular;18" halign="center" valign="center" />
218 def __init__(self,session):
219 if fileExists("/proc/stb/encoder/0/framerate"):
220 self.skin = TranscodingSetup.skin_ext
221 Screen.__init__(self,session)
222 self.skinName = "TranscodingSetup_ext"
224 Screen.__init__(self,session)
226 if self.getModel() == "duo2":
227 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
228 TEXT += _("\nWhen transcoding, PIP is disabled.")
230 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
231 TEXT += _("\nWhen transcoding, both PIP and analog video outputs are disabled.")
232 self.session = session
233 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
236 "cancel": self.keyCancel,
237 "red": self.keyCancel,
238 "green": self.keySave,
241 ConfigListScreen.__init__(self, self.list,session = self.session)
242 self["key_red"] = StaticText(_("Cancel"))
243 self["key_green"] = StaticText(_("Ok"))
244 self["text"] = StaticText(_("%s")%TEXT)
246 self.onLayoutFinish.append(self.checkEncoder)
247 self.invaliedModelTimer = eTimer()
248 self.invaliedModelTimer.callback.append(self.invalidmodel)
251 if fileExists("/proc/stb/info/vumodel"):
252 fd = open("/proc/stb/info/vumodel")
253 vumodel=fd.read().strip()
259 def checkEncoder(self):
260 if not fileExists("/proc/stb/encoder/enable"):
261 self.invaliedModelTimer.start(100,True)
263 def invalidmodel(self):
264 self.session.openWithCallback(self.close, MessageBox, _("This model is not support transcoding."), MessageBox.TYPE_ERROR)
266 def createSetup(self):
267 global TranscodingConfigList
269 self.transcoding = getConfigListEntry(_("Transcoding"), config.plugins.transcodingsetup.transcoding)
270 self.port = getConfigListEntry(_("Port"), config.plugins.transcodingsetup.port)
271 self.list.append( self.transcoding )
272 if config.plugins.transcodingsetup.transcoding.value == "enable":
273 self.list.append( self.port )
274 for x in TranscodingConfigList:
275 self.list.append(getConfigListEntry(_(x[0]), x[3]))
277 self["config"].list = self.list
278 self["config"].l.setList(self.list)
281 transcoding = config.plugins.transcodingsetup.transcoding.value
282 port = config.plugins.transcodingsetup.port.value
283 # print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
284 ret = self.setupTranscoding(transcoding, port)
285 if ret is not None and ret <0 :
288 self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
291 if transcoding == "enable" and port == "8001" :
292 text = "PC Streaming is replaced with mobile streaming."
293 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.\n%s")%(transcoding,text), MessageBox.TYPE_INFO)
295 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.")%transcoding, MessageBox.TYPE_INFO)
298 def resetConfig(self):
299 for x in self["config"].list:
302 def setupTranscoding(self, transcoding = None, port = None):
303 if transcoding == "disable":
304 config.plugins.transcodingsetup.port.value = "8002"
306 return self.setTranscoding(transcoding, port)
309 ConfigListScreen.keyLeft(self)
310 if self["config"].getCurrent() == self.transcoding:
314 ConfigListScreen.keyRight(self)
315 if self["config"].getCurrent() == self.transcoding:
318 def main(session, **kwargs):
319 session.open(TranscodingSetup)
321 def Plugins(**kwargs):
322 return [PluginDescriptor(name=_("TranscodingSetup"), description=_("Transcoding Setup"), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
324 transcodingsetupinit = TranscodingSetupInit()