allow YUV if manually enabled
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / AVSwitch.py
1 from config import *
2 import os
3 from enigma import *
4
5 class AVSwitch:
6         INPUT = { "ENCODER": (0, 4), "SCART": (1, 3), "AUX": (2, 4) }
7
8         def setInput(self, input):
9                 eAVSwitch.getInstance().setInput(self.INPUT[input][0])
10                 if self.INPUT[input][1] == 4:
11                         aspect = self.getAspectRatioSetting()
12                         self.setAspectWSS(aspect)
13                         self.setAspectSlowBlank(aspect)
14                 else:
15                         eAVSwitch.getInstance().setSlowblank(self.INPUT[input][1])
16                 # FIXME why do we have to reset the colorformat? bug in avs-driver?
17                 eAVSwitch.getInstance().setColorFormat(config.av.colorformat.value)
18
19         def setColorFormat(self, value):
20                 eAVSwitch.getInstance().setColorFormat(value)
21
22         def setAspectRatio(self, value):
23                 eAVSwitch.getInstance().setAspectRatio(value)
24                 self.setAspectWSS(value)
25                 self.setAspectSlowBlank(value)
26
27         def setSystem(self, value):
28                 eAVSwitch.getInstance().setVideomode(value)
29
30         def getAspectRatioSetting(self):
31                 valstr = currentConfigSelectionElement(config.av.aspectratio)
32                 if valstr == "4_3_letterbox":
33                         val = 0
34                 elif valstr == "4_3_panscan":
35                         val = 1
36                 elif valstr == "16_9":
37                         val = 2
38                 elif valstr == "16_9_always":
39                         val = 3
40                 return val
41
42         def setAspectWSS(self, aspect=None):
43                 if aspect is None:
44                         aspect = self.getAspectRatioSetting()
45                 if aspect == 0 or aspect == 1: # letterbox or panscan
46                         value = 3 # 4:3_full_format
47                 elif aspect == 2: # 16:9
48                         if currentConfigSelectionElement(config.av.wss) == "off":
49                                 value = 2 # auto(4:3_off)
50                         else:
51                                 value = 1 # auto
52                 elif aspect == 3: # always 16:9
53                         value = 4 # 16:9_full_format
54                 eAVSwitch.getInstance().setWSS(value)
55
56         def setAspectSlowBlank(self, aspect=None):
57                 if aspect is None:
58                         aspect = self.getAspectRatioSetting()
59                 if aspect == 0 or aspect == 1: # letterbox or panscan
60                         value = 2 # 12 V
61                 elif aspect == 2: # 16:9
62                         value = 4 # auto
63                 elif aspect == 3: # always 16:9
64                         value = 1 # 6V
65                 eAVSwitch.getInstance().setSlowblank(value)
66
67 def InitAVSwitch():
68         config.av = ConfigSubsection();
69         config.av.yuvenabled = configElementBoolean("config.av.yuvenabled", 0)
70         colorformat_choices = ( ("cvbs", _("CVBS")), ("rgb", _("RGB")), ("svideo", _("S-Video")), ("yuv", _("YPbPr")) )
71         
72         # when YUV is not enabled, don't let the user select it
73         if not config.av.yuvenabled.value:
74                 colorformat_choices = colorformat_choices[:3]
75
76         config.av.colorformat = configElement("config.av.colorformat", configSelection, 1, colorformat_choices)
77         config.av.aspectratio = configElement("config.av.aspectratio", configSelection, 0, (("4_3_letterbox", _("4:3 Letterbox")), ("4_3_panscan", _("4:3 PanScan")), ("16_9", _("16:9")), ("16_9_always", _("16:9 always"))) )
78         #config.av.tvsystem = configElement("config.av.tvsystem", configSelection, 0, ("PAL", "PAL + PAL60", "Multi", "NTSC") )
79         config.av.tvsystem = configElement("config.av.tvsystem", configSelection, 0, (("pal", _("PAL")), ("ntsc", _("NTSC"))) )
80         config.av.wss = configElement("config.av.wss", configSelection, 0, (("off", _("Off")), ("on", _("On"))) )
81         config.av.defaultac3 = configElement("config.av.defaultac3", configSelection, 1, (("enable", _("Enable")), ("disable", _("Disable"))))
82         config.av.vcrswitch = configElement("config.av.vcrswitch", configSelection, 1, (("enable", _("Enable")), ("disable", _("Disable"))))
83
84         iAVSwitch = AVSwitch()
85
86         def setColorFormat(configElement):
87                 iAVSwitch.setColorFormat(configElement.value)
88
89         def setAspectRatio(configElement):
90                 iAVSwitch.setAspectRatio(configElement.value)
91
92         def setSystem(configElement):
93                 iAVSwitch.setSystem(configElement.value)
94
95         def setWSS(configElement):
96                 iAVSwitch.setAspectWSS()
97
98         # this will call the "setup-val" initial
99         config.av.colorformat.addNotifier(setColorFormat)
100         config.av.aspectratio.addNotifier(setAspectRatio)
101         config.av.tvsystem.addNotifier(setSystem)
102         config.av.wss.addNotifier(setWSS)
103
104         iAVSwitch.setInput("ENCODER") # init on startup