remove comments from Makefile.am to make automatic parsing easier
[enigma2.git] / lib / python / Components / AVSwitch.py
1 from config import config, ConfigSlider, ConfigSelection, ConfigYesNo, ConfigEnableDisable, ConfigSubsection, ConfigBoolean
2 from enigma import eAVSwitch, getDesktop
3 from SystemInfo import SystemInfo
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                 map = {"cvbs": 0, "rgb": 1, "svideo": 2, "yuv": 3}
18                 eAVSwitch.getInstance().setColorFormat(map[config.av.colorformat.value])
19
20         def setColorFormat(self, value):
21                 eAVSwitch.getInstance().setColorFormat(value)
22
23         def setAspectRatio(self, value):
24                 eAVSwitch.getInstance().setAspectRatio(value)
25                 self.setAspectWSS(value)
26                 self.setAspectSlowBlank(value)
27
28         def setSystem(self, value):
29                 eAVSwitch.getInstance().setVideomode(value)
30
31         def getOutputAspect(self):
32                 valstr = config.av.aspectratio.value
33                 if valstr in ("4_3_letterbox", "4_3_panscan"): # 4:3
34                         return (4,3)
35                 elif valstr == "16_9": # auto ... 4:3 or 16:9
36                         try:
37                                 aspect_str = open("/proc/stb/vmpeg/0/aspect", "r").read()
38                                 if aspect_str == "1": # 4:3
39                                         return (4,3)
40                         except IOError:
41                                 pass
42                 elif valstr in ("16_9_always", "16_9_letterbox"): # 16:9
43                         pass
44                 elif valstr in ("16_10_letterbox", "16_10_panscan"): # 16:10
45                         return (16,10)
46                 return (16,9)
47
48         def getFramebufferScale(self):
49                 aspect = self.getOutputAspect()
50                 fb_size = getDesktop(0).size()
51                 return (aspect[0] * fb_size.height(), aspect[1] * fb_size.width())
52
53         def getAspectRatioSetting(self):
54                 valstr = config.av.aspectratio.value
55                 if valstr == "4_3_letterbox":
56                         val = 0
57                 elif valstr == "4_3_panscan":
58                         val = 1
59                 elif valstr == "16_9":
60                         val = 2
61                 elif valstr == "16_9_always":
62                         val = 3
63                 elif valstr == "16_10_letterbox":
64                         val = 4
65                 elif valstr == "16_10_panscan":
66                         val = 5
67                 elif valstr == "16_9_letterbox":
68                         val = 6
69                 return val
70
71         def setAspectWSS(self, aspect=None):
72                 if aspect is None:
73                         aspect = self.getAspectRatioSetting()
74                 if aspect == 0 or aspect == 1: # letterbox or panscan
75                         if not config.av.wss.value:
76                                 value = 0 # wss off
77                         else:
78                                 value = 3 # 4:3_full_format
79                 elif aspect == 2: # 16:9
80                         if not config.av.wss.value:
81                                 value = 2 # auto(4:3_off)
82                         else:
83                                 value = 1 # auto
84                 elif aspect == 3 or aspect == 6: # always 16:9
85                         value = 4 # 16:9_full_format
86                 elif aspect == 4 or aspect == 5: # 16:10
87                         value = 10 # 14:9_full_format
88                 eAVSwitch.getInstance().setWSS(value)
89
90         def setAspectSlowBlank(self, aspect=None):
91                 if aspect is None:
92                         aspect = self.getAspectRatioSetting()
93                 if aspect == 0 or aspect == 1: # letterbox or panscan
94                         value = 2 # 12 V
95                 elif aspect == 2: # 16:9
96                         value = 4 # auto
97                 elif aspect == 3 or aspect == 4 or aspect == 5 or aspect == 6: # always 16:9
98                         value = 1 # 6V
99                 eAVSwitch.getInstance().setSlowblank(value)
100
101 def InitAVSwitch():
102         config.av = ConfigSubsection()
103         config.av.yuvenabled = ConfigBoolean(default=False)
104         colorformat_choices = {"cvbs": _("CVBS"), "rgb": _("RGB"), "svideo": _("S-Video")}
105         
106         # when YUV is not enabled, don't let the user select it
107         if config.av.yuvenabled.value:
108                 colorformat_choices["yuv"] = _("YPbPr")
109
110         config.av.colorformat = ConfigSelection(choices=colorformat_choices, default="rgb")
111         config.av.aspectratio = ConfigSelection(choices={
112                         "4_3_letterbox": _("4:3 Letterbox"),
113                         "4_3_panscan": _("4:3 PanScan"), 
114                         "16_9": _("16:9"), 
115                         "16_9_always": _("16:9 always"),
116                         "16_10_letterbox": _("16:10 Letterbox"),
117                         "16_10_panscan": _("16:10 PanScan"), 
118                         "16_9_letterbox": _("16:9 Letterbox")}, 
119                         default = "4_3_letterbox")
120
121         config.av.aspect = ConfigSelection(choices={
122                         "4_3": _("4:3"),
123                         "16_9": _("16:9"), 
124                         "16_10": _("16:10"),
125                         "auto": _("Automatic")},
126                         default = "auto")
127         config.av.policy_169 = ConfigSelection(choices={
128                                 # TRANSLATORS: (aspect ratio policy: black bars on top/bottom) in doubt, keep english term.
129                         "letterbox": _("Letterbox"), 
130                                 # TRANSLATORS: (aspect ratio policy: cropped content on left/right) in doubt, keep english term
131                         "panscan": _("Pan&Scan"),  
132                                 # TRANSLATORS: (aspect ratio policy: display as fullscreen, even if this breaks the aspect)
133                         "scale": _("Just Scale")},
134                         default = "letterbox")
135         config.av.policy_43 = ConfigSelection(choices={
136                                 # TRANSLATORS: (aspect ratio policy: black bars on left/right) in doubt, keep english term.
137                         "pillarbox": _("Pillarbox"), 
138                                 # TRANSLATORS: (aspect ratio policy: cropped content on left/right) in doubt, keep english term
139                         "panscan": _("Pan&Scan"),  
140                                 # TRANSLATORS: (aspect ratio policy: display as fullscreen, with stretching the left/right)
141                         "nonlinear": _("Nonlinear"),  
142                                 # TRANSLATORS: (aspect ratio policy: display as fullscreen, even if this breaks the aspect)
143                         "scale": _("Just Scale")},
144                         default = "pillarbox")
145         config.av.tvsystem = ConfigSelection(choices = {"pal": _("PAL"), "ntsc": _("NTSC"), "multinorm": _("multinorm")}, default="pal")
146         config.av.wss = ConfigEnableDisable(default = True)
147         config.av.defaultac3 = ConfigYesNo(default = False)
148         config.av.vcrswitch = ConfigEnableDisable(default = False)
149
150         iAVSwitch = AVSwitch()
151
152         def setColorFormat(configElement):
153                 map = {"cvbs": 0, "rgb": 1, "svideo": 2, "yuv": 3}
154                 iAVSwitch.setColorFormat(map[configElement.value])
155
156         def setAspectRatio(configElement):
157                 map = {"4_3_letterbox": 0, "4_3_panscan": 1, "16_9": 2, "16_9_always": 3, "16_10_letterbox": 4, "16_10_panscan": 5, "16_9_letterbox" : 6}
158                 iAVSwitch.setAspectRatio(map[configElement.value])
159
160         def setSystem(configElement):
161                 map = {"pal": 0, "ntsc": 1, "multinorm" : 2}
162                 iAVSwitch.setSystem(map[configElement.value])
163
164         def setWSS(configElement):
165                 iAVSwitch.setAspectWSS()
166
167         # this will call the "setup-val" initial
168         config.av.colorformat.addNotifier(setColorFormat)
169         config.av.aspectratio.addNotifier(setAspectRatio)
170         config.av.tvsystem.addNotifier(setSystem)
171         config.av.wss.addNotifier(setWSS)
172
173         iAVSwitch.setInput("ENCODER") # init on startup
174         SystemInfo["ScartSwitch"] = eAVSwitch.getInstance().haveScartSwitch()
175
176         try:
177                 can_downmix = open("/proc/stb/audio/ac3_choices", "r").read()[:-1].find("downmix") != -1
178         except:
179                 can_downmix = False
180
181         SystemInfo["CanDownmixAC3"] = can_downmix
182         if can_downmix:
183                 def setAC3Downmix(configElement):
184                         open("/proc/stb/audio/ac3", "w").write(configElement.value and "downmix" or "passthrough")
185                 config.av.downmix_ac3 = ConfigYesNo(default = True)
186                 config.av.downmix_ac3.addNotifier(setAC3Downmix)
187
188         try:
189                 can_osd_alpha = open("/proc/stb/video/alpha", "r") and True or False
190         except:
191                 can_osd_alpha = False
192
193         SystemInfo["CanChangeOsdAlpha"] = can_osd_alpha
194
195         def setAlpha(config):
196                 open("/proc/stb/video/alpha", "w").write(str(config.value))
197
198         if can_osd_alpha:
199                 config.av.osd_alpha = ConfigSlider(default=255, limits=(0,255))
200                 config.av.osd_alpha.addNotifier(setAlpha)