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