1 from enigma import eTimer
2 from Components.config import config, ConfigSelection, ConfigSubDict, ConfigYesNo
4 from Tools.CList import CList
6 # The "VideoHardware" is the interface to /proc/stb/video.
7 # It generates hotplug events, and gives you the list of
8 # available and preferred modes, as well as handling the currently
9 # selected mode. No other strict checking is done.
11 rates = { } # high-level, use selectable modes.
13 modes = { } # a list of (high-level) modes for a certain port.
15 rates["PAL"] = { "50Hz": { 50: "pal" },
16 "60Hz": { 60: "pal60" },
17 "multi": { 50: "pal", 60: "pal60" } }
19 rates["NTSC"] = { "60Hz": { 60: "ntsc" } }
21 rates["Multi"] = { "multi": { 50: "pal", 60: "ntsc" } }
23 rates["480i"] = { "60Hz": { 60: "480i" } }
25 rates["576i"] = { "50Hz": { 50: "576i" } }
27 rates["480p"] = { "60Hz": { 60: "480p" } }
29 rates["576p"] = { "50Hz": { 50: "576p" } }
31 rates["720p"] = { "50Hz": { 50: "720p50" },
32 "60Hz": { 60: "720p" },
33 "multi": { 50: "720p50", 60: "720p" } }
35 rates["1080i"] = { "50Hz": { 50: "1080i50" },
36 "60Hz": { 60: "1080i" },
37 "multi": { 50: "1080i50", 60: "1080i" } }
40 "1024x768": { 60: "1024x768" }, # not possible on DM7025
41 "800x600" : { 60: "800x600" }, # also not possible
42 "720x480" : { 60: "720x480" },
43 "720x576" : { 60: "720x576" },
44 "1280x720": { 60: "1280x720" },
45 "1280x720 multi": { 50: "1280x720_50", 60: "1280x720" },
46 "1920x1080": { 60: "1920x1080"},
47 "1920x1080 multi": { 50: "1920x1080", 60: "1920x1080_50" },
48 "1280x1024" : { 60: "1280x1024"},
49 "1366x768" : { 60: "1366x768"},
50 "1366x768 multi" : { 50: "1366x768", 60: "1366x768_50" },
51 "1280x768": { 60: "1280x768" },
52 "640x480" : { 60: "640x480" }
55 modes["Scart"] = ["PAL", "NTSC", "Multi"]
56 modes["YPbPr"] = ["720p", "1080i", "576p", "480p", "576i", "480i"]
57 modes["DVI"] = ["720p", "1080i", "576p", "480p", "576i", "480i"]
58 modes["DVI-PC"] = ["PC"]
60 widescreen_modes = set(["720p", "1080i"])
62 def getOutputAspect(self):
64 port = config.av.videoport.value
65 if port not in config.av.videomode:
66 print "current port not available in getOutputAspect!!! force 16:9"
68 mode = config.av.videomode[port].value
69 force_widescreen = self.isWidescreenMode(port, mode)
70 is_widescreen = force_widescreen or config.av.aspect.value in ["16_9", "16_10"]
71 is_auto = config.av.aspect.value == "auto"
76 aspect = {"16_9": "16:9", "16_10": "16:10"}[config.av.aspect.value]
81 aspect_str = open("/proc/stb/vmpeg/0/aspect", "r").read()
82 if aspect_str == "1": # 4:3
91 self.last_modes_preferred = [ ]
92 self.on_hotplug = CList()
94 self.current_mode = None
95 self.current_port = None
97 self.readAvailableModes()
100 # self.on_hotplug.append(self.createConfig)
102 self.readPreferredModes()
104 # take over old AVSwitch component :)
105 from Components.AVSwitch import AVSwitch
106 # config.av.colorformat.notifiers = [ ]
107 config.av.aspectratio.notifiers = [ ]
108 config.av.tvsystem.notifiers = [ ]
109 config.av.wss.notifiers = [ ]
110 AVSwitch.setInput = self.AVSwitchSetInput
111 AVSwitch.getOutputAspect = self.getOutputAspect
113 config.av.aspect.addNotifier(self.updateAspect)
114 config.av.wss.addNotifier(self.updateAspect)
115 config.av.policy_169.addNotifier(self.updateAspect)
116 config.av.policy_43.addNotifier(self.updateAspect)
118 # until we have the hotplug poll socket
119 # self.timer = eTimer()
120 # self.timer.callback.append(self.readPreferredModes)
121 # self.timer.start(1000)
123 config.av.colorformat.addNotifier(self.updateFastblank)
125 def AVSwitchSetInput(self, mode):
126 self.standby = mode == "SCART"
129 def readAvailableModes(self):
131 modes = open("/proc/stb/video/videomode_choices").read()[:-1]
133 print "couldn't read available videomodes."
134 self.modes_available = [ ]
136 self.modes_available = modes.split(' ')
138 def readPreferredModes(self):
140 modes = open("/proc/stb/video/videomode_preferred").read()[:-1]
141 self.modes_preferred = modes.split(' ')
143 print "reading preferred modes failed, using all modes"
144 self.modes_preferred = self.modes_available
146 if self.modes_preferred != self.last_modes_preferred:
147 self.last_modes_preferred = self.modes_preferred
148 print "hotplug on dvi"
149 self.on_hotplug("DVI") # must be DVI
151 # check if a high-level mode with a given rate is available.
152 def isModeAvailable(self, port, mode, rate):
153 rate = self.rates[mode][rate]
154 for mode in rate.values():
155 # DVI modes must be in "modes_preferred"
157 # if mode not in self.modes_preferred and not config.av.edid_override.value:
158 # print "no, not preferred"
160 if mode not in self.modes_available:
164 def isWidescreenMode(self, port, mode):
165 return mode in self.widescreen_modes
167 def setMode(self, port, mode, rate, force = None):
168 print "setMode - port:", port, "mode:", mode, "rate:", rate
169 # we can ignore "port"
170 self.current_mode = mode
171 self.current_port = port
172 modes = self.rates[mode][rate]
174 mode_50 = modes.get(50)
175 mode_60 = modes.get(60)
176 if mode_50 is None or force == 60:
178 if mode_60 is None or force == 50:
182 open("/proc/stb/video/videomode_50hz", "w").write(mode_50)
183 open("/proc/stb/video/videomode_60hz", "w").write(mode_60)
186 # fallback if no possibility to setup 50/60 hz mode
187 open("/proc/stb/video/videomode", "w").write(mode_50)
189 print "setting videomode failed."
192 open("/etc/videomode", "w").write(mode_50) # use 50Hz mode (if available) for booting
194 print "writing initial videomode to /etc/videomode failed."
196 self.updateAspect(None)
198 def saveMode(self, port, mode, rate):
199 print "saveMode", port, mode, rate
200 config.av.videoport.value = port
201 config.av.videoport.save()
202 config.av.videomode[port].value = mode
203 config.av.videomode[port].save()
204 config.av.videorate[mode].value = rate
205 config.av.videorate[mode].save()
207 def isPortAvailable(self, port):
211 def isPortUsed(self, port):
213 self.readPreferredModes()
214 return len(self.modes_preferred) != 0
218 def getPortList(self):
219 return [port for port in self.modes if self.isPortAvailable(port)]
221 # get a list with all modes, with all rates, for a given port.
222 def getModeList(self, port):
223 print "getModeList for port", port
225 for mode in self.modes[port]:
226 # list all rates which are completely valid
227 rates = [rate for rate in self.rates[mode] if self.isModeAvailable(port, mode, rate)]
229 # if at least one rate is ok, add this mode
231 res.append( (mode, rates) )
234 def createConfig(self, *args):
235 # create list of output ports
236 portlist = self.getPortList()
238 # create list of available modes
239 config.av.videoport = ConfigSelection(choices = [(port, _(port)) for port in portlist])
240 config.av.videomode = ConfigSubDict()
241 config.av.videorate = ConfigSubDict()
243 for port in portlist:
244 modes = self.getModeList(port)
246 config.av.videomode[port] = ConfigSelection(choices = [mode for (mode, rates) in modes])
247 for (mode, rates) in modes:
248 config.av.videorate[mode] = ConfigSelection(choices = rates)
250 def setConfiguredMode(self):
251 port = config.av.videoport.value
252 if port not in config.av.videomode:
253 print "current port not available, not setting videomode"
256 mode = config.av.videomode[port].value
258 if mode not in config.av.videorate:
259 print "current mode not available, not setting videomode"
262 rate = config.av.videorate[mode].value
263 self.setMode(port, mode, rate)
265 def updateAspect(self, cfgelement):
266 # determine aspect = {any,4:3,16:9,16:10}
267 # determine policy = {bestfit,letterbox,panscan,nonlinear}
270 # config.av.videoport.value: current video output device
273 # 4_3: use policy_169
274 # 16_9,16_10: use policy_43
275 # auto always "bestfit"
276 # config.av.policy_169
277 # letterbox use letterbox
278 # panscan use panscan
280 # config.av.policy_43
281 # pillarbox use panscan
282 # panscan use letterbox ("panscan" is just a bad term, it's inverse-panscan)
283 # nonlinear use nonlinear
286 port = config.av.videoport.value
287 if port not in config.av.videomode:
288 print "current port not available, not setting videomode"
290 mode = config.av.videomode[port].value
292 force_widescreen = self.isWidescreenMode(port, mode)
294 is_widescreen = force_widescreen or config.av.aspect.value in ["16_9", "16_10"]
295 is_auto = config.av.aspect.value == "auto"
296 policy2 = "policy" # use main policy
302 aspect = {"16_9": "16:9", "16_10": "16:10"}[config.av.aspect.value]
303 policy = {"pillarbox": "panscan", "panscan": "letterbox", "nonlinear": "nonlinear", "scale": "bestfit"}[config.av.policy_43.value]
304 policy2 = {"letterbox": "letterbox", "panscan": "panscan", "scale": "bestfit"}[config.av.policy_169.value]
310 policy = {"letterbox": "letterbox", "panscan": "panscan", "scale": "bestfit"}[config.av.policy_169.value]
312 if not config.av.wss.value:
313 wss = "auto(4:3_off)"
317 print "-> setting aspect, policy, policy2, wss", aspect, policy, policy2, wss
318 open("/proc/stb/video/aspect", "w").write(aspect)
319 open("/proc/stb/video/policy", "w").write(policy)
320 open("/proc/stb/denc/0/wss", "w").write(wss)
322 open("/proc/stb/video/policy2", "w").write(policy2)
325 self.updateSlowblank()
326 self.updateFastblank()
328 def updateSlowblank(self):
330 from Components.SystemInfo import SystemInfo
331 if SystemInfo["ScartSwitch"]:
341 open("/proc/stb/avs/0/sb", "w").write(sb)
342 open("/proc/stb/avs/0/input", "w").write(input)
344 def updateStandby(self):
345 self.updateSlowblank()
346 self.updateFastblank()
348 def updateFastblank(self, *args):
350 from Components.SystemInfo import SystemInfo
351 if SystemInfo["ScartSwitch"]:
356 if self.current_port == "Scart" and config.av.colorformat.value == "rgb":
360 open("/proc/stb/avs/0/fb", "w").write(fb)
362 config.av.edid_override = ConfigYesNo(default = False)
363 video_hw = VideoHardware()
364 video_hw.setConfiguredMode()