revert DVI workaround... because hdmi is broken when one time a dvi mode was
[enigma2.git] / lib / python / Plugins / SystemPlugins / Videomode / VideoHardware.py
index f3e3c07a6bd171d73e95ee61628528d50670d6df..43543bb1bd4d5bd1ea82ba293c39da3f579aa924 100644 (file)
@@ -46,16 +46,22 @@ class VideoHardware:
                "1366x768" : { 60: "1366x768"},
                "1366x768 multi" : { 50: "1366x768", 60: "1366x768_50"},
                "1280x768": { 60: "1280x768"},
-               "640x480" : { 60: "640x480"} 
+               "640x480" : { 60: "640x480"}
        }
 
        modes["Scart"] = ["PAL", "NTSC", "Multi"]
        modes["YPbPr"] = ["720p", "1080i"]
        modes["DVI"] = ["720p", "1080i", "PC"]
+       modes["DVI-PC"] = ["PC"]
+
+       widescreen_modes = set(["720p", "1080i"])
 
        def __init__(self):
                self.last_modes_preferred =  [ ]
                self.on_hotplug = CList()
+               self.standby = False
+               self.current_mode = None
+               self.current_port = None
 
                self.readAvailableModes()
 
@@ -64,11 +70,30 @@ class VideoHardware:
 
                self.readPreferredModes()
 
+               # take over old AVSwitch component :)
+               from Components.AVSwitch import AVSwitch
+#              config.av.colorformat.notifiers = [ ] 
+               config.av.aspectratio.notifiers = [ ]
+               config.av.tvsystem.notifiers = [ ]
+               config.av.wss.notifiers = [ ]
+               AVSwitch.setInput = self.AVSwitchSetInput
+
+               config.av.aspect.addNotifier(self.updateAspect)
+               config.av.wss.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.callback.append(self.readPreferredModes)
 #              self.timer.start(1000)
 
+               config.av.colorformat.addNotifier(self.updateFastblank) 
+
+       def AVSwitchSetInput(self, mode):
+               self.standby = mode == "SCART"
+               self.updateStandby()
+
        def readAvailableModes(self):
                try:
                        modes = open("/proc/stb/video/videomode_choices").read()[:-1]
@@ -104,10 +129,14 @@ 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"
                self.current_mode = mode
+               self.current_port = port
                modes = self.rates[mode][rate]
 
                mode_50 = modes.get(50)
@@ -118,8 +147,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,15 +161,15 @@ class VideoHardware:
                except IOError:
                        print "writing initial videomode to /etc/videomode failed."
 
-               # workaround: this should not be set here.
-               if port != "Scart":
-                       open("/proc/stb/video/aspect", "w").write("any")
-                       open("/proc/stb/video/policy", "w").write("panscan")
+               self.updateAspect(None)
 
        def saveMode(self, port, mode, rate):
                config.av.videoport.value = port
+               config.av.videoport.save()
                config.av.videomode[port].value = mode
+               config.av.videomode[port].save()
                config.av.videorate[mode].value = rate
+               config.av.videorate[mode].save()
 
        def isPortAvailable(self, port):
                # fixme
@@ -199,7 +228,97 @@ 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]
+
+               if not config.av.wss.value:
+                       wss = "auto(4:3_off)"
+               else:
+                       wss = "auto"
+
+               print "-> setting aspect, policy, wss", aspect, policy, wss
+               open("/proc/stb/video/aspect", "w").write(aspect)
+               open("/proc/stb/video/policy", "w").write(policy)
+               open("/proc/stb/denc/0/wss", "w").write(wss)
+               self.updateSlowblank()
+               self.updateFastblank()
+
+       def updateSlowblank(self):
+               if self.standby:
+                       from Components.SystemInfo import SystemInfo
+                       if SystemInfo["ScartSwitch"]:
+                               input = "scart"
+                               sb = "vcr"
+                       else:
+                               input = "off"
+                               sb = "0"
+               else:
+                       input = "encoder"
+                       sb = "auto"
+
+               open("/proc/stb/avs/0/sb", "w").write(sb)
+               open("/proc/stb/avs/0/input", "w").write(input)
+
+       def updateStandby(self):
+               self.updateSlowblank()
+               self.updateFastblank()
+
+       def updateFastblank(self, *args):
+               if self.standby:
+                       from Components.SystemInfo import SystemInfo
+                       if SystemInfo["ScartSwitch"]:
+                               fb = "vcr"
+                       else:
+                               fb = "low"
+               else:
+                       if self.current_port == "Scart" and config.av.colorformat.value == "rgb":
+                               fb = "high"
+                       else:
+                               fb = "low"
+               open("/proc/stb/avs/0/fb", "w").write(fb)
 
 config.av.edid_override = ConfigYesNo(default = False)
 video_hw = VideoHardware()