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