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()
98 if self.modes.has_key("DVI-PC") and not self.getModeList("DVI-PC"):
99 print "remove DVI-PC because of not existing modes"
100 del self.modes["DVI-PC"]
103 # self.on_hotplug.append(self.createConfig)
105 self.readPreferredModes()
107 # take over old AVSwitch component :)
108 from Components.AVSwitch import AVSwitch
109 # config.av.colorformat.notifiers = [ ]
110 config.av.aspectratio.notifiers = [ ]
111 config.av.tvsystem.notifiers = [ ]
112 config.av.wss.notifiers = [ ]
113 AVSwitch.getOutputAspect = self.getOutputAspect
115 config.av.aspect.addNotifier(self.updateAspect)
116 config.av.wss.addNotifier(self.updateAspect)
117 config.av.policy_169.addNotifier(self.updateAspect)
118 config.av.policy_43.addNotifier(self.updateAspect)
120 # until we have the hotplug poll socket
121 # self.timer = eTimer()
122 # self.timer.callback.append(self.readPreferredModes)
123 # self.timer.start(1000)
125 def readAvailableModes(self):
127 modes = open("/proc/stb/video/videomode_choices").read()[:-1]
129 print "couldn't read available videomodes."
130 self.modes_available = [ ]
132 self.modes_available = modes.split(' ')
134 def readPreferredModes(self):
136 modes = open("/proc/stb/video/videomode_preferred").read()[:-1]
137 self.modes_preferred = modes.split(' ')
139 print "reading preferred modes failed, using all modes"
140 self.modes_preferred = self.modes_available
142 if self.modes_preferred != self.last_modes_preferred:
143 self.last_modes_preferred = self.modes_preferred
144 print "hotplug on dvi"
145 self.on_hotplug("DVI") # must be DVI
147 # check if a high-level mode with a given rate is available.
148 def isModeAvailable(self, port, mode, rate):
149 rate = self.rates[mode][rate]
150 for mode in rate.values():
151 # DVI modes must be in "modes_preferred"
153 # if mode not in self.modes_preferred and not config.av.edid_override.value:
154 # print "no, not preferred"
156 if mode not in self.modes_available:
160 def isWidescreenMode(self, port, mode):
161 return mode in self.widescreen_modes
163 def setMode(self, port, mode, rate, force = None):
164 print "setMode - port:", port, "mode:", mode, "rate:", rate
165 # we can ignore "port"
166 self.current_mode = mode
167 self.current_port = port
168 modes = self.rates[mode][rate]
170 mode_50 = modes.get(50)
171 mode_60 = modes.get(60)
172 if mode_50 is None or force == 60:
174 if mode_60 is None or force == 50:
178 open("/proc/stb/video/videomode_50hz", "w").write(mode_50)
179 open("/proc/stb/video/videomode_60hz", "w").write(mode_60)
182 # fallback if no possibility to setup 50/60 hz mode
183 open("/proc/stb/video/videomode", "w").write(mode_50)
185 print "setting videomode failed."
188 open("/etc/videomode", "w").write(mode_50) # use 50Hz mode (if available) for booting
190 print "writing initial videomode to /etc/videomode failed."
192 self.updateAspect(None)
194 def saveMode(self, port, mode, rate):
195 print "saveMode", port, mode, rate
196 config.av.videoport.value = port
197 config.av.videoport.save()
198 config.av.videomode[port].value = mode
199 config.av.videomode[port].save()
200 config.av.videorate[mode].value = rate
201 config.av.videorate[mode].save()
203 def isPortAvailable(self, port):
207 def isPortUsed(self, port):
209 self.readPreferredModes()
210 return len(self.modes_preferred) != 0
214 def getPortList(self):
215 return [port for port in self.modes if self.isPortAvailable(port)]
217 # get a list with all modes, with all rates, for a given port.
218 def getModeList(self, port):
219 print "getModeList for port", port
221 for mode in self.modes[port]:
222 # list all rates which are completely valid
223 rates = [rate for rate in self.rates[mode] if self.isModeAvailable(port, mode, rate)]
225 # if at least one rate is ok, add this mode
227 res.append( (mode, rates) )
230 def createConfig(self, *args):
231 # create list of output ports
232 portlist = self.getPortList()
234 # create list of available modes
235 config.av.videoport = ConfigSelection(choices = [(port, _(port)) for port in portlist])
236 config.av.videomode = ConfigSubDict()
237 config.av.videorate = ConfigSubDict()
239 for port in portlist:
240 modes = self.getModeList(port)
242 config.av.videomode[port] = ConfigSelection(choices = [mode for (mode, rates) in modes])
243 for (mode, rates) in modes:
244 config.av.videorate[mode] = ConfigSelection(choices = rates)
246 def setConfiguredMode(self):
247 port = config.av.videoport.value
248 if port not in config.av.videomode:
249 print "current port not available, not setting videomode"
252 mode = config.av.videomode[port].value
254 if mode not in config.av.videorate:
255 print "current mode not available, not setting videomode"
258 rate = config.av.videorate[mode].value
259 self.setMode(port, mode, rate)
261 def updateAspect(self, cfgelement):
262 # determine aspect = {any,4:3,16:9,16:10}
263 # determine policy = {bestfit,letterbox,panscan,nonlinear}
266 # config.av.videoport.value: current video output device
269 # 4_3: use policy_169
270 # 16_9,16_10: use policy_43
271 # auto always "bestfit"
272 # config.av.policy_169
273 # letterbox use letterbox
274 # panscan use panscan
276 # config.av.policy_43
277 # pillarbox use panscan
278 # panscan use letterbox ("panscan" is just a bad term, it's inverse-panscan)
279 # nonlinear use nonlinear
282 port = config.av.videoport.value
283 if port not in config.av.videomode:
284 print "current port not available, not setting videomode"
286 mode = config.av.videomode[port].value
288 force_widescreen = self.isWidescreenMode(port, mode)
290 is_widescreen = force_widescreen or config.av.aspect.value in ("16_9", "16_10")
291 is_auto = config.av.aspect.value == "auto"
292 policy2 = "policy" # use main policy
298 aspect = {"16_9": "16:9", "16_10": "16:10"}[config.av.aspect.value]
299 policy = {"pillarbox": "panscan", "panscan": "letterbox", "nonlinear": "nonlinear", "scale": "bestfit"}[config.av.policy_43.value]
300 policy2 = {"letterbox": "letterbox", "panscan": "panscan", "scale": "bestfit"}[config.av.policy_169.value]
306 policy = {"letterbox": "letterbox", "panscan": "panscan", "scale": "bestfit"}[config.av.policy_169.value]
308 if not config.av.wss.value:
309 wss = "auto(4:3_off)"
313 print "-> setting aspect, policy, policy2, wss", aspect, policy, policy2, wss
314 open("/proc/stb/video/aspect", "w").write(aspect)
315 open("/proc/stb/video/policy", "w").write(policy)
316 open("/proc/stb/denc/0/wss", "w").write(wss)
318 open("/proc/stb/video/policy2", "w").write(policy2)
322 config.av.edid_override = ConfigYesNo(default = False)
323 video_hw = VideoHardware()
324 video_hw.setConfiguredMode()