Add Relevant PIDs Routing. (for support Extra high bitrate in DVB-CI)
[vuplus_dvbapp] / lib / python / Screens / Ci.py
index 0fb0fee..666033b 100644 (file)
@@ -7,6 +7,7 @@ from Components.config import config, ConfigSubsection, ConfigSelection, ConfigS
 from Components.ConfigList import ConfigList
 
 from Components.SystemInfo import SystemInfo
 from Components.ConfigList import ConfigList
 
 from Components.SystemInfo import SystemInfo
+from Tools.Directories import fileExists
 
 from enigma import eTimer, eDVBCI_UI, eDVBCIInterfaces
 
 
 from enigma import eTimer, eDVBCI_UI, eDVBCIInterfaces
 
@@ -18,6 +19,18 @@ def setCIBitrate(configElement):
        else:
                eDVBCI_UI.getInstance().setClockRate(configElement.slotid, eDVBCI_UI.rateHigh)
 
        else:
                eDVBCI_UI.getInstance().setClockRate(configElement.slotid, eDVBCI_UI.rateHigh)
 
+def setRelevantPidsRouting(configElement):
+       fileName = "/proc/stb/tsmux/ci%d_relevant_pids_routing" % (configElement.slotid)
+       if not fileExists(fileName, 'r'):
+               print "[CI] file not found : ", fileName
+       else:
+               data = configElement.value
+               if data in ("yes", "no"):
+                       fd = open(fileName, 'w')
+                       fd.write("%s" % data)
+                       fd.close()
+
+relevantPidsRoutingChoices = None
 def InitCiConfig():
        config.ci = ConfigSubList()
        for slot in range(MAX_NUM_CI):
 def InitCiConfig():
        config.ci = ConfigSubList()
        for slot in range(MAX_NUM_CI):
@@ -28,6 +41,26 @@ def InitCiConfig():
                        config.ci[slot].canHandleHighBitrates.slotid = slot
                        config.ci[slot].canHandleHighBitrates.addNotifier(setCIBitrate)
 
                        config.ci[slot].canHandleHighBitrates.slotid = slot
                        config.ci[slot].canHandleHighBitrates.addNotifier(setCIBitrate)
 
+               if SystemInfo["RelevantPidsRoutingSupport"]:
+                       global relevantPidsRoutingChoices
+                       if not relevantPidsRoutingChoices:
+                               relevantPidsRoutingChoices = [("no", _("No")), ("yes", _("Yes"))]
+                               default = "no"
+                               fileName = "/proc/stb/tsmux/ci%d_relevant_pids_routing_choices"
+                               if fileExists(fileName, 'r'):
+                                       relevantPidsRoutingChoices = []
+                                       fd = open(fileName, 'r')
+                                       data = fd.read()
+                                       data = data.split()
+                                       for x in data:
+                                               relevantPidsRoutingChoices.append((x, _(x)))
+                                       if default not in data:
+                                               default = data[0]
+
+                       config.ci[slot].relevantPidsRouting = ConfigSelection(choices = relevantPidsRoutingChoices, default = default)
+                       config.ci[slot].relevantPidsRouting.slotid = slot
+                       config.ci[slot].relevantPidsRouting.addNotifier(setRelevantPidsRouting)
+
 class MMIDialog(Screen):
        def __init__(self, session, slotid, action, handler = eDVBCI_UI.getInstance(), wait_text = _("wait for ci...") ):
                Screen.__init__(self, session)
 class MMIDialog(Screen):
        def __init__(self, session, slotid, action, handler = eDVBCI_UI.getInstance(), wait_text = _("wait for ci...") ):
                Screen.__init__(self, session)
@@ -244,6 +277,13 @@ class CiMessageHandler:
                except:
                        SystemInfo["CommonInterfaceSupportsHighBitrates"] = False
 
                except:
                        SystemInfo["CommonInterfaceSupportsHighBitrates"] = False
 
+               try:
+                       file = open("/proc/stb/tsmux/ci0_relevant_pids_routing", "r")
+                       file.close()
+                       SystemInfo["RelevantPidsRoutingSupport"] = True
+               except:
+                       SystemInfo["RelevantPidsRoutingSupport"] = False
+
        def setSession(self, session):
                self.session = session
 
        def setSession(self, session):
                self.session = session
 
@@ -284,29 +324,39 @@ class CiSelection(Screen):
 
                self.dlg = None
                self.state = { }
 
                self.dlg = None
                self.state = { }
+               self.slots = []
+               self.HighBitrateEntry = {}
+               self.RelevantPidsRoutingEntry = {}
+
+               self.entryData = []
+
                self.list = [ ]
                self.list = [ ]
+               self["entries"] = ConfigList(self.list)
+               self["entries"].list = self.list
+               self["entries"].l.setList(self.list)
+               self["text"] = Label(_("Slot %d")%(1))
+               self.onLayoutFinish.append(self.initialUpdate)
 
 
+       def initialUpdate(self):
                for slot in range(MAX_NUM_CI):
                        state = eDVBCI_UI.getInstance().getState(slot)
                        if state != -1:
                for slot in range(MAX_NUM_CI):
                        state = eDVBCI_UI.getInstance().getState(slot)
                        if state != -1:
-                               self.appendEntries(slot, state)
+                               self.slots.append(slot)
+                               self.state[slot] = state
+                               self.createEntries(slot)
                                CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
 
                                CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
 
-               menuList = ConfigList(self.list)
-               menuList.list = self.list
-               menuList.l.setList(self.list)
-               self["entries"] = menuList
-               self["entries"].onSelectionChanged.append(self.selectionChanged)
-               self["text"] = Label(_("Slot %d")%(1))
+               self.updateEntries()
 
        def selectionChanged(self):
 
        def selectionChanged(self):
-               cur_idx = self["entries"].getCurrentIndex()
-               self["text"].setText(_("Slot %d")%((cur_idx / 5)+1))
+               entryData = self.entryData[self["entries"].getCurrentIndex()]
+               self["text"].setText(_("Slot %d")%(entryData[1] + 1))
 
        def keyConfigEntry(self, key):
 
        def keyConfigEntry(self, key):
+               current = self["entries"].getCurrent()
                try:
                        self["entries"].handleKey(key)
                try:
                        self["entries"].handleKey(key)
-                       self["entries"].getCurrent()[1].save()
+                       current[1].save()
                except:
                        pass
 
                except:
                        pass
 
@@ -316,47 +366,43 @@ class CiSelection(Screen):
        def keyRight(self):
                self.keyConfigEntry(KEY_RIGHT)
 
        def keyRight(self):
                self.keyConfigEntry(KEY_RIGHT)
 
-       def appendEntries(self, slot, state):
-               self.state[slot] = state
-               self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
-               self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
-
-               if self.state[slot] == 0:                       #no module
-                       self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
-               elif self.state[slot] == 1:             #module in init
-                       self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
-               elif self.state[slot] == 2:             #module ready
-                       #get appname
-                       appname = eDVBCI_UI.getInstance().getAppName(slot)
-                       self.list.append( (appname, ConfigNothing(), 2, slot) )
-
-               self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
+       def createEntries(self, slot):
                if SystemInfo["CommonInterfaceSupportsHighBitrates"]:
                if SystemInfo["CommonInterfaceSupportsHighBitrates"]:
-                       self.list.append(getConfigListEntry(_("High bitrate support"), config.ci[slot].canHandleHighBitrates))
-
-       def updateState(self, slot):
-               state = eDVBCI_UI.getInstance().getState(slot)
-               self.state[slot] = state
-
-               slotidx=0
-               while len(self.list[slotidx]) < 3 or self.list[slotidx][3] != slot:
-                       slotidx += 1
-
-               slotidx += 1 # do not change Reset
-               slotidx += 1 # do not change Init
-
-               if state == 0:                  #no module
-                       self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
-               elif state == 1:                #module in init
-                       self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
-               elif state == 2:                #module ready
-                       #get appname
-                       appname = eDVBCI_UI.getInstance().getAppName(slot)
-                       self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
-
-               lst = self["entries"]
-               lst.list = self.list
-               lst.l.setList(self.list)
+                       self.HighBitrateEntry[slot] = getConfigListEntry(_("High bitrate support"), config.ci[slot].canHandleHighBitrates)
+               if SystemInfo["RelevantPidsRoutingSupport"]:
+                       self.RelevantPidsRoutingEntry[slot] = getConfigListEntry(_("Relevant PIDs Routing"), config.ci[slot].relevantPidsRouting)
+
+       def addToList(self, data, action, slotid):
+               self.list.append(data)
+               self.entryData.append((action, slotid))
+
+       def updateEntries(self):
+               self.list = []
+               self.entryData = []
+               for slot in self.slots:
+                       self.addToList((_("Reset"), ConfigNothing()), 0, slot)
+                       self.addToList((_("Init"), ConfigNothing()), 1, slot)
+
+                       if self.state[slot] == 0:                       #no module
+                               self.addToList((_("no module found"), ConfigNothing()), 2, slot)
+                       elif self.state[slot] == 1:             #module in init
+                               self.addToList((_("init module"), ConfigNothing()), 2, slot)
+                       elif self.state[slot] == 2:             #module ready
+                               #get appname
+                               appname = eDVBCI_UI.getInstance().getAppName(slot)
+                               self.addToList((appname, ConfigNothing()), 2, slot)
+
+                       self.addToList(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices), -1, slot)
+
+                       if SystemInfo["CommonInterfaceSupportsHighBitrates"]:
+                               self.addToList(self.HighBitrateEntry[slot], -1, slot)
+                       if SystemInfo["RelevantPidsRoutingSupport"]:
+                               self.addToList(self.RelevantPidsRoutingEntry[slot], -1, slot)
+
+               self["entries"].list = self.list
+               self["entries"].l.setList(self.list)
+               if self.selectionChanged not in self["entries"].onSelectionChanged:
+                       self["entries"].onSelectionChanged.append(self.selectionChanged)
 
        def ciStateChanged(self, slot):
                if self.dlg:
 
        def ciStateChanged(self, slot):
                if self.dlg:
@@ -366,21 +412,23 @@ class CiSelection(Screen):
                        if self.state[slot] != state:
                                #print "something happens"
                                self.state[slot] = state
                        if self.state[slot] != state:
                                #print "something happens"
                                self.state[slot] = state
-                               self.updateState(slot)
+                               self.updateEntries()
 
        def dlgClosed(self, slot):
                self.dlg = None
 
        def okbuttonClick(self):
                cur = self["entries"].getCurrent()
 
        def dlgClosed(self, slot):
                self.dlg = None
 
        def okbuttonClick(self):
                cur = self["entries"].getCurrent()
-               if cur and len(cur) > 2:
-                       action = cur[2]
-                       slot = cur[3]
+               if cur:
+                       idx = self["entries"].getCurrentIndex()
+                       entryData = self.entryData[idx]
+                       action = entryData[0]
+                       slot = entryData[1]
                        if action == 0:         #reset
                                eDVBCI_UI.getInstance().setReset(slot)
                        elif action == 1:               #init
                                eDVBCI_UI.getInstance().setInit(slot)
                        if action == 0:         #reset
                                eDVBCI_UI.getInstance().setReset(slot)
                        elif action == 1:               #init
                                eDVBCI_UI.getInstance().setInit(slot)
-                       elif self.state[slot] == 2:
+                       elif action == 2 and self.state[slot] == 2:
                                self.dlg = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, action)
 
        def cancel(self):
                                self.dlg = self.session.openWithCallback(self.dlgClosed, MMIDialog, slot, action)
 
        def cancel(self):