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"]:
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")
144 def setEncoderExtra(self):
145 global TranscodingConfigList
146 for x in TranscodingConfigList:
147 if self.setEncoder(x[1], x[3].value):
151 def setEncoder(self, procPath, value):
152 print "<TranscodingSetup> set %s "%procPath, value
153 if not fileExists(procPath):
155 if isinstance(value, str):
156 value = value.strip(' ').strip('\n')
160 fd = open(procPath,'r')
161 old_value = fd.read().strip(' ').strip('\n')
163 if old_value != value:
164 fd = open(procPath,'w')
167 fd = open(procPath,'r')
168 encoder_value = fd.read().strip(' ').strip('\n')
170 if encoder_value != value:
176 class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit):
178 <screen position="center,center" size="400,270" title="Transcoding Setup" >
179 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
180 <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
181 <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" />
182 <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" />
183 <widget name="config" zPosition="2" position="5,70" size="390,70" scrollbarMode="showOnDemand" transparent="1" />
184 <widget source="text" render="Label" position="20,140" size="370,130" font="Regular;18" halign="center" valign="center" />
188 <screen position="center,center" size="400,320" title="Transcoding Setup" >
189 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
190 <ePixmap pixmap="skin_default/buttons/green.png" position="230,10" size="140,40" alphatest="on" />
191 <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" />
192 <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" />
193 <widget name="config" zPosition="2" position="5,70" size="390,120" scrollbarMode="showOnDemand" transparent="1" />
194 <widget source="text" render="Label" position="20,190" size="370,130" font="Regular;18" halign="center" valign="center" />
198 def __init__(self,session):
199 if fileExists("/proc/stb/encoder/0/framerate"):
200 self.skin = TranscodingSetup.skin_ext
201 Screen.__init__(self,session)
202 self.skinName = "TranscodingSetup_ext"
204 Screen.__init__(self,session)
206 if self.getModel() == "duo2":
207 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
208 TEXT += _("\nWhen transcoding, PIP is disabled.")
210 TEXT = _("Transcoding can be started when there is no corresponding channel recordings.")
211 TEXT += _("\nWhen transcoding, both PIP and analog video outputs are disabled.")
212 self.session = session
213 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
216 "cancel": self.keyCancel,
217 "red": self.keyCancel,
218 "green": self.keySave,
221 ConfigListScreen.__init__(self, self.list,session = self.session)
222 self["key_red"] = StaticText(_("Cancel"))
223 self["key_green"] = StaticText(_("Ok"))
224 self["text"] = StaticText(_("%s")%TEXT)
226 self.onLayoutFinish.append(self.checkEncoder)
227 self.invaliedModelTimer = eTimer()
228 self.invaliedModelTimer.callback.append(self.invalidmodel)
231 if fileExists("/proc/stb/info/vumodel"):
232 fd = open("/proc/stb/info/vumodel")
233 vumodel=fd.read().strip()
239 def checkEncoder(self):
240 if not fileExists("/proc/stb/encoder/enable"):
241 self.invaliedModelTimer.start(100,True)
243 def invalidmodel(self):
244 self.session.openWithCallback(self.close, MessageBox, _("This model is not support transcoding."), MessageBox.TYPE_ERROR)
246 def createSetup(self):
247 global TranscodingConfigList
249 self.transcoding = getConfigListEntry(_("Transcoding"), config.plugins.transcodingsetup.transcoding)
250 self.port = getConfigListEntry(_("Port"), config.plugins.transcodingsetup.port)
251 self.list.append( self.transcoding )
252 if config.plugins.transcodingsetup.transcoding.value == "enable":
253 self.list.append( self.port )
254 for x in TranscodingConfigList:
255 self.list.append(getConfigListEntry(_(x[0]), x[3]))
257 self["config"].list = self.list
258 self["config"].l.setList(self.list)
261 transcoding = config.plugins.transcodingsetup.transcoding.value
262 port = config.plugins.transcodingsetup.port.value
263 # print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
264 ret = self.setupTranscoding(transcoding, port)
265 if ret is not None and ret <0 :
268 self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
271 if transcoding == "enable" and port == "8001" :
272 text = "PC Streaming is replaced with mobile streaming."
273 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.\n%s")%(transcoding,text), MessageBox.TYPE_INFO)
275 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.")%transcoding, MessageBox.TYPE_INFO)
278 def resetConfig(self):
279 for x in self["config"].list:
282 def setupTranscoding(self, transcoding = None, port = None):
283 if transcoding == "disable":
284 config.plugins.transcodingsetup.port.value = "8002"
286 return self.setTranscoding(transcoding, port)
289 ConfigListScreen.keyLeft(self)
290 if self["config"].getCurrent() == self.transcoding:
294 ConfigListScreen.keyRight(self)
295 if self["config"].getCurrent() == self.transcoding:
298 def main(session, **kwargs):
299 session.open(TranscodingSetup)
301 def Plugins(**kwargs):
302 return [PluginDescriptor(name=_("TranscodingSetup"), description=_("Transcoding Setup"), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
304 transcodingsetupinit = TranscodingSetupInit()