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()
93 self.current_mode = None
94 self.current_port = None
96 self.readAvailableModes()
99 # self.on_hotplug.append(self.createConfig)
101 self.readPreferredModes()
103 # take over old AVSwitch component :)
104 from Components.AVSwitch import AVSwitch
105 # config.av.colorformat.notifiers = [ ]
106 config.av.aspectratio.notifiers = [ ]
107 config.av.tvsystem.notifiers = [ ]
108 config.av.wss.notifiers = [ ]
109 AVSwitch.getOutputAspect = self.getOutputAspect
111 config.av.aspect.addNotifier(self.updateAspect)
112 config.av.wss.addNotifier(self.updateAspect)
113 config.av.policy_169.addNotifier(self.updateAspect)
114 config.av.policy_43.addNotifier(self.updateAspect)
116 # until we have the hotplug poll socket
117 # self.timer = eTimer()
118 # self.timer.callback.append(self.readPreferredModes)
119 # self.timer.start(1000)
121 def readAvailableModes(self):
123 modes = open("/proc/stb/video/videomode_choices").read()[:-1]
125 print "couldn't read available videomodes."
126 self.modes_available = [ ]
128 self.modes_available = modes.split(' ')
130 def readPreferredModes(self):
132 modes = open("/proc/stb/video/videomode_preferred").read()[:-1]
133 self.modes_preferred = modes.split(' ')
135 print "reading preferred modes failed, using all modes"
136 self.modes_preferred = self.modes_available
138 if self.modes_preferred != self.last_modes_preferred:
139 self.last_modes_preferred = self.modes_preferred
140 print "hotplug on dvi"
141 self.on_hotplug("DVI") # must be DVI
143 # check if a high-level mode with a given rate is available.
144 def isModeAvailable(self, port, mode, rate):
145 rate = self.rates[mode][rate]
146 for mode in rate.values():
147 # DVI modes must be in "modes_preferred"
149 # if mode not in self.modes_preferred and not config.av.edid_override.value:
150 # print "no, not preferred"
152 if mode not in self.modes_available:
156 def isWidescreenMode(self, port, mode):
157 return mode in self.widescreen_modes
159 def setMode(self, port, mode, rate, force = None):
160 print "setMode - port:", port, "mode:", mode, "rate:", rate
161 # we can ignore "port"
162 self.current_mode = mode
163 self.current_port = port
164 modes = self.rates[mode][rate]
166 mode_50 = modes.get(50)
167 mode_60 = modes.get(60)
168 if mode_50 is None or force == 60:
170 if mode_60 is None or force == 50:
174 open("/proc/stb/video/videomode_50hz", "w").write(mode_50)
175 open("/proc/stb/video/videomode_60hz", "w").write(mode_60)
178 # fallback if no possibility to setup 50/60 hz mode
179 open("/proc/stb/video/videomode", "w").write(mode_50)
181 print "setting videomode failed."
184 open("/etc/videomode", "w").write(mode_50) # use 50Hz mode (if available) for booting
186 print "writing initial videomode to /etc/videomode failed."
188 self.updateAspect(None)
190 def saveMode(self, port, mode, rate):
191 print "saveMode", port, mode, rate
192 config.av.videoport.value = port
193 config.av.videoport.save()
194 config.av.videomode[port].value = mode
195 config.av.videomode[port].save()
196 config.av.videorate[mode].value = rate
197 config.av.videorate[mode].save()
199 def isPortAvailable(self, port):
203 def isPortUsed(self, port):
205 self.readPreferredModes()
206 return len(self.modes_preferred) != 0
210 def getPortList(self):
211 return [port for port in self.modes if self.isPortAvailable(port)]
213 # get a list with all modes, with all rates, for a given port.
214 def getModeList(self, port):
215 print "getModeList for port", port
217 for mode in self.modes[port]:
218 # list all rates which are completely valid
219 rates = [rate for rate in self.rates[mode] if self.isModeAvailable(port, mode, rate)]
221 # if at least one rate is ok, add this mode
223 res.append( (mode, rates) )
226 def createConfig(self, *args):
227 # create list of output ports
228 portlist = self.getPortList()
230 # create list of available modes
231 config.av.videoport = ConfigSelection(choices = [(port, _(port)) for port in portlist])
232 config.av.videomode = ConfigSubDict()
233 config.av.videorate = ConfigSubDict()
235 for port in portlist:
236 modes = self.getModeList(port)
238 config.av.videomode[port] = ConfigSelection(choices = [mode for (mode, rates) in modes])
239 for (mode, rates) in modes:
240 config.av.videorate[mode] = ConfigSelection(choices = rates)
242 def setConfiguredMode(self):
243 port = config.av.videoport.value
244 if port not in config.av.videomode:
245 print "current port not available, not setting videomode"
248 mode = config.av.videomode[port].value
250 if mode not in config.av.videorate:
251 print "current mode not available, not setting videomode"
254 rate = config.av.videorate[mode].value
255 self.setMode(port, mode, rate)
257 def updateAspect(self, cfgelement):
258 # determine aspect = {any,4:3,16:9,16:10}
259 # determine policy = {bestfit,letterbox,panscan,nonlinear}
262 # config.av.videoport.value: current video output device
265 # 4_3: use policy_169
266 # 16_9,16_10: use policy_43
267 # auto always "bestfit"
268 # config.av.policy_169
269 # letterbox use letterbox
270 # panscan use panscan
272 # config.av.policy_43
273 # pillarbox use panscan
274 # panscan use letterbox ("panscan" is just a bad term, it's inverse-panscan)
275 # nonlinear use nonlinear
278 port = config.av.videoport.value
279 if port not in config.av.videomode:
280 print "current port not available, not setting videomode"
282 mode = config.av.videomode[port].value
284 force_widescreen = self.isWidescreenMode(port, mode)
286 is_widescreen = force_widescreen or config.av.aspect.value in ["16_9", "16_10"]
287 is_auto = config.av.aspect.value == "auto"
288 policy2 = "policy" # use main policy
294 aspect = {"16_9": "16:9", "16_10": "16:10"}[config.av.aspect.value]
295 policy = {"pillarbox": "panscan", "panscan": "letterbox", "nonlinear": "nonlinear", "scale": "bestfit"}[config.av.policy_43.value]
296 policy2 = {"letterbox": "letterbox", "panscan": "panscan", "scale": "bestfit"}[config.av.policy_169.value]
302 policy = {"letterbox": "letterbox", "panscan": "panscan", "scale": "bestfit"}[config.av.policy_169.value]
304 if not config.av.wss.value:
305 wss = "auto(4:3_off)"
309 print "-> setting aspect, policy, policy2, wss", aspect, policy, policy2, wss
310 open("/proc/stb/video/aspect", "w").write(aspect)
311 open("/proc/stb/video/policy", "w").write(policy)
312 open("/proc/stb/denc/0/wss", "w").write(wss)
314 open("/proc/stb/video/policy2", "w").write(policy2)
318 config.av.edid_override = ConfigYesNo(default = False)
319 video_hw = VideoHardware()
320 video_hw.setConfiguredMode()