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
69 default_bitrate = 2000000
70 config.plugins.transcodingsetup.bitrate = ConfigInteger(default = default_bitrate, limits = (100000, 5000000))
71 x.append(config.plugins.transcodingsetup.bitrate)
72 elif x[0] == "Framerate":
73 config.plugins.transcodingsetup.framerate = ConfigSelection(default = "30000", choices = [ ("23976", _("23976")), ("24000", _("24000")), ("29970", _("29970")), ("30000", _("30000")), ("59940", _("59940")), ("60000", _("60000"))])
74 x.append(config.plugins.transcodingsetup.framerate)
76 def setTranscoding(self, transcoding, port):
77 if transcoding not in ["enable","disable"] or port not in ["8001","8002"]:
78 # print "Input error."
80 if not fileExists("/proc/stb/encoder/enable"):
82 elif not fileExists("/etc/inetd.conf"):
84 res = self.setEncoderExtra()
87 if self.setEncoderEnable(transcoding) < 0:
89 res = self.setPort(port)
91 self.setEncoderEnable(self.transcoding_old)
97 def setEncoderEnable(self,mode = "disable"):
98 # print "<TranscodingSetup> set encoder %s" % mode
99 mode = mode.strip(' ').strip('\n')
101 fd = open("/proc/stb/encoder/enable",'r')
102 self.transcoding_old = fd.read()
104 fd = open("/proc/stb/encoder/enable",'w')
107 fd = open("/proc/stb/encoder/enable",'r')
108 encoder_enable = fd.read().strip(' ').strip('\n')
110 if encoder_enable == mode:
113 # print "<TranscodingSetup> can not setting."
116 # print "setEncoderEnable exception error"
119 def setPort(self, port = "8001"):
120 # print "<TranscodingSetup> set port %s" % port
122 fp = file('/etc/inetd.conf', 'r')
123 datas = fp.readlines()
126 # print "file open error, inetd.conf!"
136 if line.find("transtreamproxy") != -1:
137 p=line.replace('\t',' ').find(' ')
139 elif line.find("streamproxy") != -1:
140 p=line.replace('\t',' ').find(' ')
141 line = s_port+line[p:]
144 if newdatas.find("transtreamproxy") == -1:
145 newdatas+=port+'\t'+'stream'+'\t'+'tcp'+'\t'+'nowait'+'\t'+'root'+'\t'+'/usr/bin/transtreamproxy'+'\t'+'transtreamproxy\n'
146 fd = file("/etc/inetd.conf",'w')
153 def inetdRestart(self):
154 if fileExists("/etc/init.d/inetd"):
155 os_system("/etc/init.d/inetd restart")
156 elif fileExists("/etc/init.d/inetd.busybox"):
157 os_system("/etc/init.d/inetd.busybox restart")
159 def setEncoderExtra(self):
160 global TranscodingConfigList
161 for x in TranscodingConfigList:
162 if self.setEncoder(x[1], x[3].value):
166 def setEncoder(self, procPath, value):
167 # print "<TranscodingSetup> set %s "%procPath, value
168 if not fileExists(procPath):
170 if isinstance(value, str):
171 value = value.strip(' ').strip('\n')
175 fd = open(procPath,'r')
176 old_value = fd.read().strip(' ').strip('\n')
178 if old_value != value:
179 print "<TranscodingSetup> set %s "%procPath, value
180 fd = open(procPath,'w')
183 fd = open(procPath,'r')
184 encoder_value = fd.read().strip(' ').strip('\n')
186 if encoder_value != value:
192 class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit):
194 <screen position="center,center" size="400,270" title="Transcoding Setup" >
195 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
196 <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
197 <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" />
198 <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" />
199 <widget name="config" zPosition="2" position="5,70" size="390,70" scrollbarMode="showOnDemand" transparent="1" />
200 <widget source="text" render="Label" position="20,140" size="370,130" font="Regular;18" halign="center" valign="center" />
204 <screen position="center,center" size="400,320" title="Transcoding Setup" >
205 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
206 <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
207 <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" />
208 <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" />
209 <widget name="config" zPosition="2" position="5,70" size="390,120" scrollbarMode="showOnDemand" transparent="1" />
210 <widget source="text" render="Label" position="20,190" size="370,130" font="Regular;18" halign="center" valign="center" />
214 def __init__(self,session):
215 if fileExists("/proc/stb/encoder/0/framerate"):
216 self.skin = TranscodingSetup.skin_ext
217 Screen.__init__(self,session)
218 self.skinName = "TranscodingSetup_ext"
220 Screen.__init__(self,session)
222 if self.getModel() == "duo2":
223 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
224 TEXT += _("\nWhen transcoding, PIP is disabled.")
226 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
227 TEXT += _("\nWhen transcoding, both PIP and analog video outputs are disabled.")
228 self.session = session
229 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
232 "cancel": self.keyCancel,
233 "red": self.keyCancel,
234 "green": self.keySave,
237 ConfigListScreen.__init__(self, self.list,session = self.session)
238 self["key_red"] = StaticText(_("Cancel"))
239 self["key_green"] = StaticText(_("Ok"))
240 self["text"] = StaticText(_("%s")%TEXT)
242 self.onLayoutFinish.append(self.checkEncoder)
243 self.invaliedModelTimer = eTimer()
244 self.invaliedModelTimer.callback.append(self.invalidmodel)
247 if fileExists("/proc/stb/info/vumodel"):
248 fd = open("/proc/stb/info/vumodel")
249 vumodel=fd.read().strip()
255 def checkEncoder(self):
256 if not fileExists("/proc/stb/encoder/enable"):
257 self.invaliedModelTimer.start(100,True)
259 def invalidmodel(self):
260 self.session.openWithCallback(self.close, MessageBox, _("This model is not support transcoding."), MessageBox.TYPE_ERROR)
262 def createSetup(self):
263 global TranscodingConfigList
265 self.transcoding = getConfigListEntry(_("Transcoding"), config.plugins.transcodingsetup.transcoding)
266 self.port = getConfigListEntry(_("Port"), config.plugins.transcodingsetup.port)
267 self.list.append( self.transcoding )
268 if config.plugins.transcodingsetup.transcoding.value == "enable":
269 self.list.append( self.port )
270 for x in TranscodingConfigList:
271 self.list.append(getConfigListEntry(_(x[0]), x[3]))
273 self["config"].list = self.list
274 self["config"].l.setList(self.list)
277 transcoding = config.plugins.transcodingsetup.transcoding.value
278 port = config.plugins.transcodingsetup.port.value
279 # print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
280 ret = self.setupTranscoding(transcoding, port)
281 if ret is not None and ret <0 :
284 self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
287 if transcoding == "enable" and port == "8001" :
288 text = "PC Streaming is replaced with mobile streaming."
289 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.\n%s")%(transcoding,text), MessageBox.TYPE_INFO)
291 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.")%transcoding, MessageBox.TYPE_INFO)
294 def resetConfig(self):
295 for x in self["config"].list:
298 def setupTranscoding(self, transcoding = None, port = None):
299 if transcoding == "disable":
300 config.plugins.transcodingsetup.port.value = "8002"
302 return self.setTranscoding(transcoding, port)
305 ConfigListScreen.keyLeft(self)
306 if self["config"].getCurrent() == self.transcoding:
310 ConfigListScreen.keyRight(self)
311 if self["config"].getCurrent() == self.transcoding:
314 def main(session, **kwargs):
315 session.open(TranscodingSetup)
317 def Plugins(**kwargs):
318 return [PluginDescriptor(name=_("TranscodingSetup"), description=_("Transcoding Setup"), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
320 transcodingsetupinit = TranscodingSetupInit()