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.transcordingsetup = ConfigSubsection()
14 config.plugins.transcordingsetup.transcording = ConfigSelection(default = "disabled", choices = [ ("enabled", _("enabled")), ("disabled", _("disabled"))] )
15 config.plugins.transcordingsetup.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 TranscordingSetupInit:
28 self.transcording_value = config.plugins.transcordingsetup.transcording.value
29 if self.transcording_value == "disabled":
30 self.port_value = "8002"
32 self.port_value = config.plugins.transcordingsetup.port.value
33 self.transcording_old = config.plugins.transcordingsetup.transcording.value
34 ret = self.setTranscording(self.transcording_value, self.port_value)
35 if ret is not None and ret < 0:
36 print "[TranscordingSetup] setup failed!(%s, %s)"%(self.transcording_value, self.port_value)
38 def setTranscording(self, transcording, port):
39 if not self.getModel():
40 print "This plugin is only supported for solo2/duo2."
42 if transcording not in ["enabled","disabled"] or port not in ["8001","8002"]:
43 print "Input arg error.."
45 if not fileExists("/proc/stb/encoder/enable"):
47 elif not fileExists("/etc/inetd.conf"):
49 if self.setEncoder(transcording) < 0:
51 res = self.setPort(port)
53 self.setEncoder(self.transcording_old)
59 def setEncoder(self,mode = "disabled"):
60 print "<TranscordingSetup> set encoder : %s" % mode
61 mode = mode.strip(' ').strip('\n')
63 fd = open("/proc/stb/encoder/enable",'r')
64 self.transcording_old = fd.read()
66 fd = open("/proc/stb/encoder/enable",'w')
70 fd = open("/proc/stb/encoder/enable",'r')
71 encoder_enable = fd.read().strip(' ').strip('\n')
73 print "<--",encoder_enable
74 if encoder_enable == mode:
77 print "can not setting.."
80 print "setEncoder exception error"
83 def setPort(self, port = "8001"):
84 print "<TranscordingSetup> set port : %s" % port
86 fp = file('/etc/inetd.conf', 'r')
87 datas = fp.readlines()
90 print "file open error, inetd.conf!"
100 if line.find("transtreamproxy") != -1:
101 p=line.replace('\t',' ').find(' ')
103 elif line.find("streamproxy") != -1:
104 p=line.replace('\t',' ').find(' ')
105 line = s_port+line[p:]
108 if newdatas.find("transtreamproxy") == -1:
109 newdatas+=port+'\t'+'stream'+'\t'+'tcp'+'\t'+'nowait'+'\t'+'root'+'\t'+'/usr/bin/transtreamproxy'+'\t'+'transtreamproxy\n'
110 fd = file("/etc/inetd.conf",'w')
117 def inetdRestart(self):
118 if fileExists("/etc/init.d/inetd"):
119 os_system("/etc/init.d/inetd restart")
122 if fileExists("/proc/stb/info/vumodel"):
123 vumodel = open("/proc/stb/info/vumodel")
124 info=vumodel.read().strip()
126 if info in ["solo2", "duo2"]:
133 class TranscordingSetup(Screen,ConfigListScreen, TranscordingSetupInit):
135 <screen position="center,center" size="560,270" title="Transcording Setup" >
136 <ePixmap pixmap="skin_default/buttons/red.png" position="110,10" size="140,40" alphatest="on" />
137 <ePixmap pixmap="skin_default/buttons/green.png" position="310,10" size="140,40" alphatest="on" />
138 <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" />
139 <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" />
140 <widget name="config" zPosition="2" position="5,70" size="550,70" scrollbarMode="showOnDemand" transparent="1" />
141 <widget source="text" render="Label" position="20,140" size="520,130" font="Regular;18" halign="center" valign="center" />
145 def __init__(self,session):
146 Screen.__init__(self,session)
147 self.session = session
148 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
151 "cancel": self.keyCancel,
152 "red": self.keyCancel,
153 "green": self.keySave,
156 ConfigListScreen.__init__(self, self.list,session = self.session)
157 TEXT = "Tanscoding can be started when there is no corresponding channel recordings."
158 TEXT += "\nWhen transcoding, both PIP and analog video outputs are disabled."
159 self["key_red"] = StaticText(_("Cancel"))
160 self["key_green"] = StaticText(_("Ok"))
161 self["text"] = StaticText(_("%s")%TEXT)
163 self.onLayoutFinish.append(self.checkModel)
164 self.checkModelTimer = eTimer()
165 self.checkModelTimer.callback.append(self.invalidmodel)
167 def checkModel(self):
168 if not self.getModel():
169 self.checkModelTimer.start(1000,True)
171 def invalidmodel(self):
172 self.session.openWithCallback(self.close, MessageBox, _("This Plugin is available on SOLO2/DUO2"), MessageBox.TYPE_ERROR)
174 def createSetup(self):
176 self.transcording = getConfigListEntry(_("Transcording"), config.plugins.transcordingsetup.transcording)
177 self.port = getConfigListEntry(_("Port"), config.plugins.transcordingsetup.port)
178 self.list.append( self.transcording )
179 if config.plugins.transcordingsetup.transcording.value == "enabled":
180 self.list.append( self.port )
181 self["config"].list = self.list
182 self["config"].l.setList(self.list)
185 transcording = config.plugins.transcordingsetup.transcording.value
186 port = config.plugins.transcordingsetup.port.value
187 print "<ZappingModeSelection> Transcording %s(port : %s)"%(transcording, port)
188 ret = self.setupTranscording(transcording, port)
189 if ret is not None and ret <0 :
192 self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcording, error_msg[ret]), MessageBox.TYPE_ERROR)
195 if transcording == "enabled" and port == "8001" :
196 text = "PC Streaming is replaced with mobile streaming."
197 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.\n%s")%(transcording,text), MessageBox.TYPE_INFO)
199 self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.")%transcording, MessageBox.TYPE_INFO)
202 def resetConfig(self):
203 for x in self["config"].list:
206 def setupTranscording(self, transcording = None, port = None):
207 if transcording == "disabled":
208 config.plugins.transcordingsetup.port.value = "8002"
210 return self.setTranscording(transcording, port)
213 ConfigListScreen.keyLeft(self)
214 if self["config"].getCurrent() == self.transcording:
218 ConfigListScreen.keyRight(self)
219 if self["config"].getCurrent() == self.transcording:
222 def main(session, **kwargs):
223 session.open(TranscordingSetup)
225 def Plugins(**kwargs):
226 return [PluginDescriptor(name=_("TranscordingSetup"), description="Transcording Setup", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
228 transcordingsetupinit = TranscordingSetupInit()