fix typo
[enigma2.git] / lib / python / Plugins / SystemPlugins / Videomode / VideoHardware.py
index a6d886c6e09b28797cfa557590917cb74ed78eac..ade2035d29d4c555d180a92e475485a034074159 100644 (file)
@@ -53,6 +53,8 @@ class VideoHardware:
        modes["YPbPr"] = ["720p", "1080i"]
        modes["DVI"] = ["720p", "1080i", "PC"]
 
+       widescreen_modes = set(["720p", "1080i"])
+
        def __init__(self):
                self.last_modes_preferred =  [ ]
                self.on_hotplug = CList()
@@ -64,9 +66,13 @@ class VideoHardware:
 
                self.readPreferredModes()
 
+               config.av.aspect.addNotifier(self.updateAspect)
+               config.av.policy_169.addNotifier(self.updateAspect)
+               config.av.policy_43.addNotifier(self.updateAspect)
+
                # until we have the hotplug poll socket
 #              self.timer = eTimer()
-#              self.timer.timeout.get().append(self.readPreferredModes)
+#              self.timer.callback.append(self.readPreferredModes)
 #              self.timer.start(1000)
 
        def readAvailableModes(self):
@@ -104,6 +110,9 @@ class VideoHardware:
                                return False
                return True
 
+       def isWidescreenMode(self, port, mode):
+               return mode in self.widescreen_modes
+
        def setMode(self, port, mode, rate, force = None):
                print "setMode - port:", port, "mode:", mode, "rate:", rate
                # we can ignore "port"
@@ -118,8 +127,8 @@ class VideoHardware:
                        mode_60 = mode_50
 
                try:
-                       open("/proc/stb/video/videomode_60hz", "w").write(mode_50)
-                       open("/proc/stb/video/videomode_50hz", "w").write(mode_60)
+                       open("/proc/stb/video/videomode_50hz", "w").write(mode_50)
+                       open("/proc/stb/video/videomode_60hz", "w").write(mode_60)
                except IOError:
                        try:
                                # fallback if no possibility to setup 50/60 hz mode
@@ -132,6 +141,13 @@ class VideoHardware:
                except IOError:
                        print "writing initial videomode to /etc/videomode failed."
 
+               self.updateAspect(None)
+
+       def saveMode(self, port, mode, rate):
+               config.av.videoport.value = port
+               config.av.videomode[port].value = mode
+               config.av.videorate[mode].value = rate
+
        def isPortAvailable(self, port):
                # fixme
                return True
@@ -148,6 +164,7 @@ class VideoHardware:
 
        # get a list with all modes, with all rates, for a given port.
        def getModeList(self, port):
+               print "getModeList for port", port
                res = [ ]
                for mode in self.modes[port]:
                        # list all rates which are completely valid
@@ -188,6 +205,56 @@ class VideoHardware:
 
                rate = config.av.videorate[mode].value
                self.setMode(port, mode, rate)
+               
+
+       def updateAspect(self, cfgelement):
+               # determine aspect = {any,4:3,16:9,16:10}
+               # determine policy = {bestfit,letterbox,panscan,nonlinear}
+
+               # based on;
+               #   config.av.videoport.value: current video output device
+               #     Scart: 
+               #   config.av.aspect:
+               #     4_3:            use policy_169
+               #     16_9,16_10:     use policy_43
+               #     auto            always "bestfit"
+               #   config.av.policy_169
+               #     letterbox       use letterbox
+               #     panscan         use panscan
+               #     scale           use bestfit
+               #   config.av.policy_43
+               #     pillarbox       use panscan
+               #     panscan         use letterbox  ("panscan" is just a bad term, it's inverse-panscan)
+               #     nonlinear       use nonlinear
+               #     scale           use bestfit
+
+               port = config.av.videoport.value
+               if port not in config.av.videomode:
+                       print "current port not available, not setting videomode"
+                       return
+               mode = config.av.videomode[port].value
+
+               force_widescreen = self.isWidescreenMode(port, mode)
+
+               is_widescreen = force_widescreen or config.av.aspect.value in ["16_9", "16_10"]
+               is_auto = config.av.aspect.value == "auto"
+
+               if is_widescreen:
+                       if force_widescreen:
+                               aspect = "16:9"
+                       else:
+                               aspect = {"16_9": "16:9", "16_10": "16:10"}[config.av.aspect.value]
+                       policy = {"pillarbox": "panscan", "panscan": "letterbox", "nonlinear": "nonlinear", "scale": "bestfit"}[config.av.policy_43.value]
+               elif is_auto:
+                       aspect = "any"
+                       policy = "bestfit"
+               else:
+                       aspect = "4:3"
+                       policy = {"letterbox": "letterbox", "panscan": "panscan", "scale": "bestfit"}[config.av.policy_169.value]
+
+               print "-> setting aspect, policy", aspect, policy
+               open("/proc/stb/video/aspect", "w").write(aspect)
+               open("/proc/stb/video/policy", "w").write(policy)
 
 config.av.edid_override = ConfigYesNo(default = False)
 video_hw = VideoHardware()