Transcoding : support multiple encoders and fix skin
authorhschang <chang@dev3>
Wed, 11 Dec 2013 05:06:33 +0000 (14:06 +0900)
committerhschang <chang@dev3>
Thu, 12 Dec 2013 10:11:28 +0000 (19:11 +0900)
lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py

index 77511d1..295eb5d 100755 (executable)
@@ -1,15 +1,25 @@
 from Screens.Screen import Screen
 from Components.ConfigList import ConfigListScreen
-from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection, ConfigInteger
+from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection, ConfigInteger, integer_limits
 from Components.ActionMap import ActionMap
 from Screens.MessageBox import MessageBox
 from Components.Sources.StaticText import StaticText
 from Plugins.Plugin import PluginDescriptor
 from Tools.Directories import fileExists
-from enigma import eTimer
-from os import system as os_system
+from enigma import eTimer, getDesktop
+from os import system as os_system, path as os_path, listdir as os_listdir
 from __init__ import _
 
+class TconfigSelection(ConfigSelection):
+       def __init__(self, encoder, choices, default = None):
+               self.encoder = encoder
+               ConfigSelection.__init__(self, choices, default)
+
+class TconfigInteger(ConfigInteger):
+       def __init__(self, encoder, default, limits = integer_limits):
+               self.encoder = encoder
+               ConfigInteger.__init__(self, default, limits)
+
 def getModel():
        filename = "/proc/stb/info/vumodel"
        if fileExists(filename):
@@ -24,124 +34,165 @@ def getProcValue(procPath):
        return curValue
 
 def setProcValue(procPath, value):
-       print "[TranscodingSetup] set %s to %s" % (procPath, value)
+#      print "[TranscodingSetup] set %s to %s" % (procPath, value)
        fd = open(procPath,'w')
        fd.write(value)
        fd.close()
 
+def getProcPath(encoder, configName):
+       _configName = {
+               "bitrate"               :       "bitrate",
+               "framerate"             :       "framerate",
+               "resolution"    :       "display_format",
+               "aspectratio"   :       "aspectratio",
+               "audiocodec"    :       "audio_codec",
+               "videocodec"    :       "video_codec",
+               "gopframeb"     :       "gop_frameb",
+               "gopframep"     :       "gop_framep",
+               "level"                 :       "level",
+               "profile"               :       "profile",
+               "width"                 :       "width",
+               "height"                :       "height",
+       }.get(configName)
+       return "/proc/stb/encoder/%s/%s" % (encoder, _configName)
+
 def checkSupportAdvanced():
-       if fileExists( g_procPath["aspectratio"] ):
+       if fileExists( getProcPath(0, "aspectratio") ):
                return True
        return False
 
-transcodingsetupinit = None
-
-g_procPath = {
-       "bitrate"               :       "/proc/stb/encoder/0/bitrate",
-       "framerate"             :       "/proc/stb/encoder/0/framerate",
-       "resolution"    :       "/proc/stb/encoder/0/display_format",
-       "aspectratio"   :       "/proc/stb/encoder/0/aspectratio",
-       "audiocodec"    :       "/proc/stb/encoder/0/audio_codec",
-       "videocodec"    :       "/proc/stb/encoder/0/video_codec",
-       "gopframeb"     :       "/proc/stb/encoder/0/gop_frameb",
-       "gopframep"     :       "/proc/stb/encoder/0/gop_framep",
-       "level"                 :       "/proc/stb/encoder/0/level",
-       "profile"               :       "/proc/stb/encoder/0/profile",
-       "width"                 :       "/proc/stb/encoder/0/width",
-       "height"                :       "/proc/stb/encoder/0/height",
-}
-
 config.plugins.transcodingsetup = ConfigSubsection()
 config.plugins.transcodingsetup.transcoding = ConfigSelection(default = "enable", choices = [ ("enable", _("enable")), ("disable", _("disable"))] )
 config.plugins.transcodingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] )
 
-if fileExists( g_procPath["bitrate"] ):
-       if getModel() == "solo2":
-               config.plugins.transcodingsetup.bitrate = ConfigInteger(default = 400000, limits = (50000, 1000000))
-       else:
-               config.plugins.transcodingsetup.bitrate = ConfigInteger(default = 2000000, limits = (100000, 5000000))
-
-if fileExists( g_procPath["framerate"] ):
-       config.plugins.transcodingsetup.framerate = ConfigSelection(default = "30000", choices = [ ("23976", _("23976")), ("24000", _("24000")), ("25000", _("25000")), ("29970", _("29970")), ("30000", _("30000")), ("50000", _("50000")), ("59940", _("59940")), ("60000", _("60000"))] )
+def getAttr(attr, encoder):
+       return getattr(config.plugins.transcodingsetup, encoder == '0' and attr or "%s_%s"%(attr, encoder))
 
-if checkSupportAdvanced() and (hasattr(config.plugins.transcodingsetup, "bitrate") or hasattr(config.plugins.transcodingsetup, "framerate")):
-       config.plugins.transcodingsetup.automode = ConfigSelection(default = "Off", choices = [ ("On", _("On")), ("Off", _("Off")) ] )
+def hasAttr(attr, encoder):
+       return hasattr(config.plugins.transcodingsetup, encoder == '0' and attr or "%s_%s"%(attr, encoder))
 
-if fileExists( g_procPath["resolution"] ):
-       config.plugins.transcodingsetup.resolution = ConfigSelection(default = "480p", choices = [ ("480p", _("480p")), ("576p", _("576p")), ("720p", _("720p")), ("320x240", _("320x240")), ("160x120", _("160x120")) ] )
+def setAttr(attr, encoder, value):
+       setattr(config.plugins.transcodingsetup, encoder == '0' and attr or "%s_%s"%(attr, encoder), value)
 
-if fileExists( g_procPath["aspectratio"] ):
-       config.plugins.transcodingsetup.aspectratio = ConfigSelection(default = "1", choices = [ ("0", _("auto")), ("1", _("4x3")), ("2", _("16x9")) ] )
-
-if fileExists( g_procPath["audiocodec"] ):
-       config.plugins.transcodingsetup.audiocodec = ConfigSelection(default = "aac", choices = [("mpg", _("mpg")), ("mp3", _("mp3")), ("aac", _("aac")), ("aac+", _("aac+")), ("aac+loas", _("aac+loas")), ("aac+adts", _("aac+adts")), ("ac3", _("ac3"))] )
-
-if fileExists( g_procPath["videocodec"] ):
-       config.plugins.transcodingsetup.videocodec = ConfigSelection(default = "h264", choices = [ ("h264", _("h264")), ("mpeg2", _("mpeg2")), ("mpeg4p2", _("mpeg4p2"))] )
-
-if fileExists( g_procPath["gopframeb"] ):
-       config.plugins.transcodingsetup.gopframeb = ConfigInteger(default = 0, limits = (0, 60))
-
-if fileExists( g_procPath["gopframep"] ):
-       config.plugins.transcodingsetup.gopframep = ConfigInteger(default = 29, limits = (0, 60))
-
-if fileExists( g_procPath["level"] ):
-       config.plugins.transcodingsetup.level = ConfigSelection(default = "3.1", choices = [("1.0", _("1.0")), ("2.0", _("2.0")),
-               ("2.1", _("2.1")), ("2.2", _("2.2")), ("3.0", _("3.0")), ("3.1", _("3.1")),
-               ("3.2", _("3.2")), ("4.0", _("4.0")), ("4.1", _("4.1")), ("4.2", _("4.2")),
-               ("5.0", _("5.0")), ("low", _("low")), ("main", _("main")), ("high", _("high"))] )
-
-if fileExists( g_procPath["profile"] ):
-       config.plugins.transcodingsetup.profile = ConfigSelection(default = "baseline", choices = [("baseline", _("baseline")), ("simple", _("simple")), ("main", _("main")), ("high", _("high")), ("advanced simple", _("advanced simple"))] )
+def createTransCodingConfig(encoder):
+       if fileExists( getProcPath(encoder ,"bitrate") ):
+               if getModel() == "solo2":
+                       choice = TconfigInteger(encoder, default = 400000, limits = (50000, 1000000))
+               else:
+                       choice = TconfigInteger(encoder, default = 2000000, limits = (100000, 5000000))
+               setAttr("bitrate", encoder, choice)
+
+       if fileExists( getProcPath(encoder ,"framerate") ):
+               choice = TconfigSelection(encoder, default = "30000", choices = [ ("23976", _("23976")), ("24000", _("24000")), ("25000", _("25000")), ("29970", _("29970")), ("30000", _("30000")), ("50000", _("50000")), ("59940", _("59940")), ("60000", _("60000"))] )
+               setAttr("framerate", encoder, choice)
+
+       if checkSupportAdvanced() and (hasAttr("bitrate", encoder) or hasAttr("framerate", encoder)):
+               choice = TconfigSelection(encoder, default = "Off", choices = [ ("On", _("On")), ("Off", _("Off")) ] )
+               setAttr("automode", encoder, choice)
+
+       if fileExists( getProcPath(encoder, "resolution") ):
+               choice = TconfigSelection(encoder, default = "480p", choices = [ ("480p", _("480p")), ("576p", _("576p")), ("720p", _("720p")), ("320x240", _("320x240")), ("160x120", _("160x120")) ] )
+               setAttr("resolution", encoder, choice)
+
+       if fileExists( getProcPath(encoder, "aspectratio") ):
+               choice = TconfigSelection(encoder, default = "1", choices = [ ("0", _("auto")), ("1", _("4x3")), ("2", _("16x9")) ] )
+               setAttr("aspectratio", encoder, choice)
+
+       if fileExists( getProcPath(encoder, "audiocodec") ):
+               choice = TconfigSelection(encoder, default = "aac", choices = [("mpg", _("mpg")), ("mp3", _("mp3")), ("aac", _("aac")), ("aac+", _("aac+")), ("aac+loas", _("aac+loas")), ("aac+adts", _("aac+adts")), ("ac3", _("ac3"))] )
+               setAttr("audiocodec", encoder, choice)
+
+       if fileExists( getProcPath(encoder, "videocodec") ):
+               choice = TconfigSelection(encoder, default = "h264", choices = [ ("h264", _("h264")), ("mpeg2", _("mpeg2")), ("mpeg4p2", _("mpeg4p2"))] )
+               setAttr("videocodec", encoder, choice)
+
+       if fileExists( getProcPath(encoder, "gopframeb") ):
+               choice = TconfigInteger(encoder, default = 0, limits = (0, 60))
+               setAttr("gopframeb", encoder, choice)
+
+       if fileExists( getProcPath(encoder, "gopframep") ):
+               choice = TconfigInteger(encoder, default = 29, limits = (0, 60))
+               setAttr("gopframep", encoder, choice)
+
+       if fileExists( getProcPath(encoder, "level") ):
+               choice = TconfigSelection(encoder, default = "3.1", choices = [("1.0", _("1.0")), ("2.0", _("2.0")),
+                       ("2.1", _("2.1")), ("2.2", _("2.2")), ("3.0", _("3.0")), ("3.1", _("3.1")),
+                       ("3.2", _("3.2")), ("4.0", _("4.0")), ("4.1", _("4.1")), ("4.2", _("4.2")),
+                       ("5.0", _("5.0")), ("low", _("low")), ("main", _("main")), ("high", _("high"))] )
+               setAttr("level", encoder, choice)
+
+       if fileExists( getProcPath(encoder, "profile") ):
+               choice = TconfigSelection(encoder, default = "baseline", choices = [("baseline", _("baseline")), ("simple", _("simple")), ("main", _("main")), ("high", _("high")), ("advanced simple", _("advancedsimple"))] )
+               setAttr("profile", encoder, choice)
+
+# check encoders
+encoders = []
+encoderPath = "/proc/stb/encoder"
+for encoder in os_listdir(encoderPath):
+       encPath = os_path.join(encoderPath, encoder)
+       if not os_path.isdir(encPath):
+               continue
+       if fileExists(os_path.join(encPath, "bitrate")):
+               encoders.append(encoder)
+               createTransCodingConfig(encoder)
+
+if len(encoders) > 1:
+       encoders.sort()
+       choices = []
+       for encoder in encoders:
+               choices.append((encoder, encoder))
+       config.plugins.transcodingsetup.encoder = ConfigSelection(default = '0', choices = choices )
 
+transcodingsetupinit = None
 class TranscodingSetupInit:
        def __init__(self):
                self.pluginsetup = None
                config.plugins.transcodingsetup.port.addNotifier(self.setPort)
 
-               if hasattr(config.plugins.transcodingsetup, "automode"):
-                       if config.plugins.transcodingsetup.automode.value == "On":
-                               config.plugins.transcodingsetup.automode.addNotifier(self.setAutomode)
+               for encoder in encoders:
+                       if hasAttr("automode", encoder):
+                               if getAttr("automode", encoder).value == "On":
+                                       getAttr("automode", encoder).addNotifier(self.setAutomode)
 
-                               if hasattr(config.plugins.transcodingsetup, "bitrate"):
-                                       config.plugins.transcodingsetup.bitrate.addNotifier(self.setBitrate, False)
+                                       if hasAttr("bitrate", encoder):
+                                               getAttr("bitrate", encoder).addNotifier(self.setBitrate, False)
 
-                               if hasattr(config.plugins.transcodingsetup, "framerate"):
-                                       config.plugins.transcodingsetup.framerate.addNotifier(self.setFramerate, False)
+                                       if hasAttr("framerate", encoder):
+                                               getAttr("framerate", encoder).addNotifier(self.setFramerate, False)
 
-                       else: # autoMode Off
-                               config.plugins.transcodingsetup.automode.addNotifier(self.setAutomode, False)
-                               if hasattr(config.plugins.transcodingsetup, "bitrate"):
-                                       config.plugins.transcodingsetup.bitrate.addNotifier(self.setBitrate)
+                               else: # autoMode Off
+                                       getAttr("automode", encoder).addNotifier(self.setAutomode, False)
+                                       if hasAttr("bitrate", encoder):
+                                               getAttr("bitrate", encoder).addNotifier(self.setBitrate)
 
-                               if hasattr(config.plugins.transcodingsetup, "framerate"):
-                                       config.plugins.transcodingsetup.framerate.addNotifier(self.setFramerate)
+                                       if hasAttr("framerate", encoder):
+                                               getAttr("framerate", encoder).addNotifier(self.setFramerate)
 
-               if hasattr(config.plugins.transcodingsetup, "resolution"):
-                       config.plugins.transcodingsetup.resolution.addNotifier(self.setResolution)
+                       if hasAttr("resolution", encoder):
+                               getAttr("resolution", encoder).addNotifier(self.setResolution)
 
-               if hasattr(config.plugins.transcodingsetup, "aspectratio"):
-                       config.plugins.transcodingsetup.aspectratio.addNotifier(self.setAspectRatio)
+                       if hasAttr("aspectratio", encoder):
+                               getAttr("aspectratio", encoder).addNotifier(self.setAspectRatio)
 
-               if hasattr(config.plugins.transcodingsetup, "audiocodec"):
-                       config.plugins.transcodingsetup.audiocodec.addNotifier(self.setAudioCodec)
+                       if hasAttr("audiocodec", encoder):
+                               getAttr("audiocodec", encoder).addNotifier(self.setAudioCodec)
 
-               if hasattr(config.plugins.transcodingsetup, "videocodec"):
-                       config.plugins.transcodingsetup.videocodec.addNotifier(self.setVideoCodec)
+                       if hasAttr("videocodec", encoder):
+                               getAttr("videocodec", encoder).addNotifier(self.setVideoCodec)
 
-               if hasattr(config.plugins.transcodingsetup, "gopframeb"):
-                       config.plugins.transcodingsetup.gopframeb.addNotifier(self.setGopFrameB)
+                       if hasAttr("gopframeb", encoder):
+                               getAttr("gopframeb", encoder).addNotifier(self.setGopFrameB)
 
-               if hasattr(config.plugins.transcodingsetup, "gopframep"):
-                       config.plugins.transcodingsetup.gopframep.addNotifier(self.setGopFrameP)
+                       if hasAttr("gopframep", encoder):
+                               getAttr("gopframep", encoder).addNotifier(self.setGopFrameP)
 
-               if hasattr(config.plugins.transcodingsetup, "level"):
-                       config.plugins.transcodingsetup.level.addNotifier(self.setLevel)
+                       if hasAttr("level", encoder):
+                               getAttr("level", encoder).addNotifier(self.setLevel)
 
-               if hasattr(config.plugins.transcodingsetup, "profile"):
-                       config.plugins.transcodingsetup.profile.addNotifier(self.setProfile)
+                       if hasAttr("profile", encoder):
+                               getAttr("profile", encoder).addNotifier(self.setProfile)
 
-       def setConfig(self, procPath, value, configName = ""):
+       def setConfig(self, procPath, value):
                if not fileExists(procPath):
                        return -1
                if isinstance(value, str):
@@ -167,7 +218,7 @@ class TranscodingSetupInit:
                port = configElement.value
                port2 = (port == "8001") and "8002" or "8001"
 
-               print "[TranscodingSetup] set port ",port
+#              print "[TranscodingSetup] set port ",port
                try:
                        newConfigData = ""
                        oldConfigData = file('/etc/inetd.conf').read()
@@ -196,14 +247,13 @@ class TranscodingSetupInit:
                        msg = "Set port OK.\nPC Streaming is replaced with mobile streaming."
                        self.showMessage(msg, MessageBox.TYPE_INFO)
 
-       def setupConfig(self, configElement, configName):
-#              print "[TranscodingSetup] set %s to %s" % ( configName, configElement.value )
+       def setupConfig(self, configElement, procPath):
+#              print "[TranscodingSetup] set %s to %s" % ( procPath, configElement.value )
                configValue = configElement.value
-               procPath = g_procPath[configName]
                if self.setConfig(procPath, configValue):
                        # set config failed, reset to current proc value
                        self.getConfigFromProc(procPath, configElement)
-                       self.showMessage("Set %s failed." % (configName), MessageBox.TYPE_ERROR)
+                       self.showMessage("Set %s failed." % (procPath), MessageBox.TYPE_ERROR)
 
        def getConfigFromProc(self, procPath, configElement):
                curValue = getProcValue(procPath)
@@ -217,55 +267,55 @@ class TranscodingSetupInit:
 #              print "[TranscodingSetup]  setAutomode, configName %s, value %s" % ( configName, configElement.value )
                if configElement.value == "On":
                        autoValue = str(-1)
-                       if ((hasattr(config.plugins.transcodingsetup, "bitrate") and
-                                       self.setConfig(g_procPath["bitrate"], autoValue) ) or
-                                       (hasattr(config.plugins.transcodingsetup, "framerate") and
-                                       self.setConfig(g_procPath["framerate"], autoValue) ) ):
+                       if ((hasAttr("bitrate", configElement.encoder) and
+                                       self.setConfig(getProcPath(configElement.encoder ,"bitrate"), autoValue) ) or
+                                       (hasAttr("framerate", configElement.encoder) and
+                                       self.setConfig(getProcPath(configElement.encoder ,"framerate"), autoValue) ) ):
                                configElement.value = "Off" # set config failed, reset to previous value
                                configElement.save()
                                self.showMessage("Set %s failed." % (configName), MessageBox.TYPE_ERROR)
                else: # Off
-                       if hasattr(config.plugins.transcodingsetup, "bitrate"):
-                               self.setBitrate(config.plugins.transcodingsetup.bitrate)
-                       if hasattr(config.plugins.transcodingsetup, "framerate"):
-                               self.setFramerate(config.plugins.transcodingsetup.framerate)
+                       if hasAttr("bitrate", configElement.encoder):
+                               self.setBitrate(getAttr("bitrate", configElement.encoder))
+                       if hasAttr("framerate", configElement.encoder):
+                               self.setFramerate(getAttr("framerate", configElement.encoder))
 
        def setBitrate(self, configElement):
-               self.setupConfig(configElement, "bitrate")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"bitrate"))
 
        def setFramerate(self, configElement):
-               self.setupConfig(configElement, "framerate")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"framerate"))
 
        def setResolution(self, configElement):
                resolution = configElement.value
                if resolution in [ "320x240", "160x120" ]:
                        (width, height) = tuple(resolution.split('x'))
-                       self.setConfig(g_procPath["resolution"], "custom")
-                       self.setConfig(g_procPath["width"], width)
-                       self.setConfig(g_procPath["height"], height)
+                       self.setConfig(getProcPath(configElement.encoder ,"resolution"), "custom")
+                       self.setConfig(getProcPath(configElement.encoder ,"width"), width)
+                       self.setConfig(getProcPath(configElement.encoder ,"height"), height)
                else:
-                       self.setupConfig(configElement, "resolution")
+                       self.setupConfig(configElement, getProcPath(configElement.encoder ,"resolution"))
 
        def setAspectRatio(self, configElement):
-               self.setupConfig(configElement, "aspectratio")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"aspectratio"))
 
        def setAudioCodec(self, configElement):
-               self.setupConfig(configElement, "audiocodec")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"audiocodec"))
 
        def setVideoCodec(self, configElement):
-               self.setupConfig(configElement, "videocodec")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"videocodec"))
 
        def setGopFrameB(self, configElement):
-               self.setupConfig(configElement, "gopframeb")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"gopframeb"))
 
        def setGopFrameP(self, configElement):
-               self.setupConfig(configElement, "gopframep")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"gopframep"))
 
        def setLevel(self, configElement):
-               self.setupConfig(configElement, "level")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"level"))
 
        def setProfile(self, configElement):
-               self.setupConfig(configElement, "profile")
+               self.setupConfig(configElement, getProcPath(configElement.encoder ,"profile"))
 
        def inetdRestart(self):
                if fileExists("/etc/init.d/inetd"):
@@ -278,8 +328,18 @@ class TranscodingSetupInit:
                        self.pluginsetup.showMessage(msg, msgType)
 
 class TranscodingSetup(Screen, ConfigListScreen):
-       skin_expert =  """
-               <screen position="center,center" size="600,450">
+       size = getDesktop(0).size()
+       if checkSupportAdvanced():
+               if size.width() > 750:
+                       size_h = 450
+               else:
+                       size_h = 370
+       else:
+               size_h = 280
+
+       pos_h = ( size_h , size_h - 150 , (size_h - 150) + 70, (size_h - 150) + 70 + 60 )
+       skin_advanced =  """
+               <screen position="center,center" size="600,%d">
                        <ePixmap pixmap="skin_default/buttons/red.png" position="5,0" size="140,40" alphatest="on" />
                        <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" size="140,40" alphatest="on" />
                        <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,0" size="140,40" alphatest="on" />
@@ -288,25 +348,25 @@ class TranscodingSetup(Screen, ConfigListScreen):
                        <widget source="key_green" render="Label" position="155,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
                        <widget source="key_yellow" render="Label" position="305,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
                        <widget source="key_blue" render="Label" position="455,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
-                       <widget name="config" zPosition="2" position="25,70" size="560,300" scrollbarMode="showOnDemand" transparent="1" />
-                       <widget source="description" render="Label" position="20,370" size="540,60" font="Regular;20" halign="center" valign="center" />
-                       <widget source="text" render="Label" position="20,430" size="540,20" font="Regular;22" halign="center" valign="center" />
+                       <widget name="config" zPosition="2" position="25,70" size="560,%d" scrollbarMode="showOnDemand" transparent="1" />
+                       <widget source="description" render="Label" position="20,%d" size="540,60" font="Regular;20" halign="center" valign="center" />
+                       <widget source="text" render="Label" position="20,%d" size="540,20" font="Regular;22" halign="center" valign="center" />
                </screen>
-               """
+               """ % pos_h
 
        skin_normal =  """
-               <screen position="center,center" size="540,290">
-                       <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
-                       <ePixmap pixmap="skin_default/buttons/green.png" position="200,10" size="140,40" alphatest="on" />
-                       <ePixmap pixmap="skin_default/buttons/yellow.png" position="370,10" size="140,40" alphatest="on" />
-                       <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" />
-                       <widget source="key_green" render="Label" position="200,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
-                       <widget source="key_yellow" render="Label" position="370,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
-                       <widget name="config" zPosition="2" position="20,70" size="500,120" scrollbarMode="showOnDemand" transparent="1" />
-                       <widget source="description" render="Label" position="30,190" size="480,60" font="Regular;20" halign="center" valign="center" />
-                       <widget source="text" render="Label" position="30,250" size="480,30" font="Regular;22" halign="center" valign="center" />
+               <screen position="center,center" size="600,%d">
+                       <ePixmap pixmap="skin_default/buttons/red.png" position="40,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/green.png" position="230,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/yellow.png" position="420,0" size="140,40" alphatest="on" />
+                       <widget source="key_red" render="Label" position="40,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
+                       <widget source="key_green" render="Label" position="230,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
+                       <widget source="key_yellow" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
+                       <widget name="config" zPosition="2" position="25,70" size="560,%d" scrollbarMode="showOnDemand" transparent="1" />
+                       <widget source="description" render="Label" position="20,%d" size="540,60" font="Regular;20" halign="center" valign="center" />
+                       <widget source="text" render="Label" position="20,%d" size="540,20" font="Regular;22" halign="center" valign="center" />
                </screen>
-               """
+               """ % pos_h
 
        def __init__(self,session):
                Screen.__init__(self,session)
@@ -314,9 +374,10 @@ class TranscodingSetup(Screen, ConfigListScreen):
                self.setTitle(_("Transcoding Setup"))
 
                if checkSupportAdvanced():
-                       self.skin = TranscodingSetup.skin_expert
+                       self.skin = TranscodingSetup.skin_advanced
                else:
                        self.skin = TranscodingSetup.skin_normal
+
                if getModel() == "solo2":
                        TEXT = _("Transcoding and PIP are mutually exclusive.")
                else:
@@ -341,6 +402,7 @@ class TranscodingSetup(Screen, ConfigListScreen):
                self.list = []
                ConfigListScreen.__init__(self, self.list,session = self.session)
                self.setupMode = "Normal" # Normal / Advanced
+               self.encoder = None
                self.automode = None
                self.createSetup()
                self.onLayoutFinish.append(self.checkEncoder)
@@ -364,42 +426,52 @@ class TranscodingSetup(Screen, ConfigListScreen):
                self.list = []
                self.list.append(getConfigListEntry(_("Port"), config.plugins.transcodingsetup.port))
 
-               if self.automode is None and checkSupportAdvanced() and hasattr(config.plugins.transcodingsetup, "automode"):
-                       self.automode = getConfigListEntry(_("Auto set Framerate / Bitrate"), config.plugins.transcodingsetup.automode)
+               encoder = None
+               if len(encoders) == 1:
+                       encoder = encoders[0]
+               elif len(encoders) > 1:
+                       self.encoder = getConfigListEntry(_("Encoder"), config.plugins.transcodingsetup.encoder)
+                       self.list.append( self.encoder )
+                       encoder = config.plugins.transcodingsetup.encoder.value                 
+
+               if encoder is not None:
+                       self.automode = None
+                       if checkSupportAdvanced() and hasAttr('automode', encoder):
+                               self.automode = getConfigListEntry(_("Auto set Framerate / Bitrate"), getAttr('automode', encoder))
 
-               if self.automode is not None:
-                       self.list.append( self.automode )
+                       if self.automode is not None:
+                               self.list.append( self.automode )
 
-               if not ( hasattr(config.plugins.transcodingsetup, "automode") and config.plugins.transcodingsetup.automode.value == "On" ):
-                       if hasattr(config.plugins.transcodingsetup, "bitrate"):
-                               self.list.append(getConfigListEntry(_("Bitrate"), config.plugins.transcodingsetup.bitrate))
-                       if hasattr(config.plugins.transcodingsetup, "framerate"):
-                               self.list.append(getConfigListEntry(_("Framerate"), config.plugins.transcodingsetup.framerate))
+                       if not ( hasAttr('automode', encoder) and getAttr('automode', encoder).value == "On" ):
+                               if hasAttr('bitrate', encoder):
+                                       self.list.append(getConfigListEntry(_("Bitrate"), getAttr('bitrate', encoder)))
+                               if hasAttr('framerate', encoder):
+                                       self.list.append(getConfigListEntry(_("Framerate"), getAttr('framerate', encoder)))
 
-               if hasattr(config.plugins.transcodingsetup, "resolution"):
-                               self.list.append(getConfigListEntry(_("Resolution"), config.plugins.transcodingsetup.resolution))
+                       if hasAttr('resolution', encoder):
+                                       self.list.append(getConfigListEntry(_("Resolution"), getAttr('resolution', encoder)))
 
-               if checkSupportAdvanced() and self.setupMode != "Normal":
-                       if hasattr(config.plugins.transcodingsetup, "aspectratio"):
-                               self.list.append(getConfigListEntry(_("Aspect Ratio"), config.plugins.transcodingsetup.aspectratio))
+                       if checkSupportAdvanced() and self.setupMode != "Normal":
+                               if hasAttr('aspectratio', encoder):
+                                       self.list.append(getConfigListEntry(_("Aspect Ratio"), getAttr('aspectratio', encoder)))
 
-                       if hasattr(config.plugins.transcodingsetup, "audiocodec"):
-                               self.list.append(getConfigListEntry(_("Audio codec"), config.plugins.transcodingsetup.audiocodec))
+                               if hasAttr('audiocodec', encoder):
+                                       self.list.append(getConfigListEntry(_("Audio codec"), getAttr('audiocodec', encoder)))
 
-                       if hasattr(config.plugins.transcodingsetup, "videocodec"):
-                               self.list.append(getConfigListEntry(_("Video codec"), config.plugins.transcodingsetup.videocodec))
+                               if hasAttr('videocodec', encoder):
+                                       self.list.append(getConfigListEntry(_("Video codec"), getAttr('videocodec', encoder)))
 
-                       if hasattr(config.plugins.transcodingsetup, "gopframeb"):
-                               self.list.append(getConfigListEntry(_("GOP Frame B"), config.plugins.transcodingsetup.gopframeb))
+                               if hasAttr('gopframe', encoder):
+                                       self.list.append(getConfigListEntry(_("GOP Frame B"), getAttr('gopframeb', encoder)))
 
-                       if hasattr(config.plugins.transcodingsetup, "gopframep"):
-                               self.list.append(getConfigListEntry(_("GOP Frame P"), config.plugins.transcodingsetup.gopframep))
+                               if hasAttr('gopframep', encoder):
+                                       self.list.append(getConfigListEntry(_("GOP Frame P"), getAttr('gopframep', encoder)))
 
-                       if hasattr(config.plugins.transcodingsetup, "level"):
-                               self.list.append(getConfigListEntry(_("Level"), config.plugins.transcodingsetup.level))
+                               if hasAttr('level', encoder):
+                                       self.list.append(getConfigListEntry(_("Level"), getAttr('level', encoder)))
 
-                       if hasattr(config.plugins.transcodingsetup, "profile"):
-                               self.list.append(getConfigListEntry(_("Profile"), config.plugins.transcodingsetup.profile))
+                               if hasAttr('profile', encoder):
+                                       self.list.append(getConfigListEntry(_("Profile"), getAttr('profile', encoder)))
 
                self["config"].list = self.list
                self["config"].l.setList(self.list)
@@ -411,22 +483,27 @@ class TranscodingSetup(Screen, ConfigListScreen):
                current = self["config"].getCurrent()[1]
                className = self["config"].getCurrent()[1].__class__.__name__
                text = ""
-               if className == "ConfigSelection":
+               if className == "ConfigSelection" or className == "TconfigSelection":
                        text = configName
                        for choice in current.choices.choices:
                                if text == configName:  
                                        text += choice[1]
                                else:
                                        text += ', ' + choice[1]
-               elif className == "ConfigInteger":
+               elif className == "ConfigInteger" or className == "TconfigInteger":
                        limits = current.limits[0]
                        text = configName
-                       text += "Max : %d, Min : %d" % (limits[0], limits[1])
-               self["description"].setText( _(text) )
+                       text += "%s : %d, %s : %d" % (_("Max"), limits[0], _("Min"), limits[1])
+               self["description"].setText(text)
 
        def showMessage(self, msg, msgType = MessageBox.TYPE_ERROR):
                self.session.open(MessageBox, _(msg), msgType)
 
+       def saveAll(self):
+               configs = config.plugins.transcodingsetup.dict()
+               for (configName, configElement) in configs.items():
+                       configElement.save()
+
        def keySave(self):
                self.saveAll()
                self.close()
@@ -434,13 +511,13 @@ class TranscodingSetup(Screen, ConfigListScreen):
        def KeyDefault(self):
                configs = config.plugins.transcodingsetup.dict()
                for (configName, configElement) in configs.items():
-                       if configName == "automode":
+                       if configName.startswith("automode"):
                                continue
                        configElement.value = configElement.default
 
-               if "automode" in configs.keys():
-                       configElement = configs["automode"]
-                       configElement.value = configElement.default
+               for (configName, configElement) in configs.items():
+                       if configName.startswith("automode"):
+                               configElement.value = configElement.default
 
                self.createSetup()
 
@@ -461,12 +538,12 @@ class TranscodingSetup(Screen, ConfigListScreen):
 
        def keyLeft(self):
                ConfigListScreen.keyLeft(self)
-               if self.automode is not None and (self["config"].getCurrent() == self.automode) :
+               if self.encoder is not None and (self["config"].getCurrent() == self.encoder) or self.automode is not None and (self["config"].getCurrent() == self.automode):
                        self.createSetup()
 
        def keyRight(self):
                ConfigListScreen.keyRight(self)
-               if self.automode is not None and (self["config"].getCurrent() == self.automode) :
+               if self.encoder is not None and (self["config"].getCurrent() == self.encoder) or self.automode is not None and (self["config"].getCurrent() == self.automode):
                        self.createSetup()
 
        def cancelConfirm(self, result):
@@ -474,14 +551,15 @@ class TranscodingSetup(Screen, ConfigListScreen):
                        return
 
                configs = config.plugins.transcodingsetup.dict()
-               for (key, configElement) in configs.items():
-                       if key == "automode":
+
+               for (configName, configElement) in configs.items():
+                       if configName.startswith("automode"):
                                continue
                        configElement.cancel()
 
-               if "automode" in configs.keys():
-                       configElement = configs["automode"]
-                       configElement.cancel()
+               for (configName, configElement) in configs.items():
+                       if configName.startswith("automode"):
+                               configElement.cancel()
 
                self.close()