Enigma2: add VideoEnhancement plugin to SystemPlugins to configure advanced video...
[enigma2.git] / lib / python / Plugins / SystemPlugins / VideoEnhancement / VideoEnhancement.py
1 from enigma import eTimer
2 from Components.config import config, ConfigSubsection, ConfigSlider, ConfigSelection,ConfigYesNo
3 from Tools.CList import CList
4 from Tools.HardwareInfo import HardwareInfo
5 import os
6 # The "VideoEnhancement" is the interface to /proc/stb/vmpeg/0.
7
8 class VideoEnhancement:
9
10         firstRun = None
11
12         def __init__(self):
13                 self.last_modes_preferred =  [ ]
14                 self.on_hotplug = CList()
15                 self.createConfig()
16
17         def createConfig(self, *args):
18                 hw_type = HardwareInfo().get_device_name()
19                 config.pep = ConfigSubsection()
20
21                 def setContrast(config):
22                         myval = int(config.value*256)
23                         try:
24                                 print "--> setting contrast to: %0.8X" % myval
25                                 open("/proc/stb/vmpeg/0/pep_contrast", "w").write("%0.8X" % myval)
26                         except IOError:
27                                 print "couldn't write pep_contrast."
28
29                         if VideoEnhancement.firstRun is False:
30                                 self.setConfiguredValues()
31
32                 config.pep.contrast = ConfigSlider(default=128, limits=(0,256))
33                 config.pep.contrast.addNotifier(setContrast)
34
35                 def setSaturation(config):
36                         myval = int(config.value*256)
37                         try:
38                                 print "--> setting saturation to: %0.8X" % myval
39                                 open("/proc/stb/vmpeg/0/pep_saturation", "w").write("%0.8X" % myval)
40                         except IOError:
41                                 print "couldn't write pep_saturaion."
42
43                         if VideoEnhancement.firstRun is False:
44                                 self.setConfiguredValues()
45
46                 config.pep.saturation = ConfigSlider(default=128, limits=(0,256))
47                 config.pep.saturation.addNotifier(setSaturation)
48
49                 def setHue(config):
50                         myval = int(config.value*256)
51                         try:
52                                 print "--> setting hue to: %0.8X" % myval
53                                 open("/proc/stb/vmpeg/0/pep_hue", "w").write("%0.8X" % myval)
54                         except IOError:
55                                 print "couldn't write pep_hue."
56
57                         if VideoEnhancement.firstRun is False:
58                                 self.setConfiguredValues()
59
60                 config.pep.hue = ConfigSlider(default=128, limits=(0,256))
61                 config.pep.hue.addNotifier(setHue)
62
63                 def setBrightness(config):
64                         myval = int(config.value*256)
65                         try:
66                                 print "--> setting brightness to: %0.8X" % myval
67                                 open("/proc/stb/vmpeg/0/pep_brightness", "w").write("%0.8X" % myval)
68                         except IOError:
69                                 print "couldn't write pep_brightness."
70
71                         if VideoEnhancement.firstRun is False:
72                                 self.setConfiguredValues()
73
74                 config.pep.brightness = ConfigSlider(default=128, limits=(0,256))
75                 config.pep.brightness.addNotifier(setBrightness)
76
77                 if hw_type == 'dm8000':
78                         def setSplitMode(config):
79                                 try:
80                                         print "--> setting splitmode to:",str(config.value)
81                                         open("/proc/stb/vmpeg/0/pep_split", "w").write(str(config.value))
82                                 except IOError:
83                                         print "couldn't write pep_split."
84
85                                 if VideoEnhancement.firstRun is False:
86                                         self.setConfiguredValues()
87
88                         config.pep.split = ConfigSelection(choices={
89                                         "off": _("Off"),
90                                         "left": _("Left"),
91                                         "right": _("Right")},
92                                         default = "off")
93                         config.pep.split.addNotifier(setSplitMode)
94
95                         def setSharpness(config):
96                                 myval = int(config.value*256)
97                                 try:
98                                         print "--> setting sharpness to: %0.8X" % myval
99                                         open("/proc/stb/vmpeg/0/pep_sharpness", "w").write("%0.8X" % myval)
100                                 except IOError:
101                                         print "couldn't write pep_sharpness."
102
103                                 if VideoEnhancement.firstRun is False:
104                                         self.setConfiguredValues()
105
106                         config.pep.sharpness = ConfigSlider(default=0, limits=(0,256))
107                         config.pep.sharpness.addNotifier(setSharpness)
108
109                         def setAutoflesh(config):
110                                 myval = int(config.value)
111                                 try:
112                                         print "--> setting auto_flesh to: %0.8X" % myval
113                                         open("/proc/stb/vmpeg/0/pep_auto_flesh", "w").write("%0.8X" % myval)
114                                 except IOError:
115                                         print "couldn't write pep_auto_flesh."
116
117                                 if VideoEnhancement.firstRun is False:
118                                         self.setConfiguredValues()
119
120                         config.pep.auto_flesh = ConfigSlider(default=0, limits=(0,4))
121                         config.pep.auto_flesh.addNotifier(setAutoflesh)
122
123                         def setGreenboost(config):
124                                 myval = int(config.value)
125                                 try:
126                                         print "--> setting green_boost to: %0.8X" % myval
127                                         open("/proc/stb/vmpeg/0/pep_green_boost", "w").write("%0.8X" % myval)
128                                 except IOError:
129                                         print "couldn't write pep_green_boost."
130
131                                 if VideoEnhancement.firstRun is False:
132                                         self.setConfiguredValues()
133
134                         config.pep.green_boost = ConfigSlider(default=0, limits=(0,4))
135                         config.pep.green_boost.addNotifier(setGreenboost)
136
137                         def setBlueboost(config):
138                                 myval = int(config.value)
139                                 try:
140                                         print "--> setting blue_boost to: %0.8X" % myval
141                                         open("/proc/stb/vmpeg/0/pep_blue_boost", "w").write("%0.8X" % myval)
142                                 except IOError:
143                                         print "couldn't write pep_blue_boost."
144
145                                 if VideoEnhancement.firstRun is False:
146                                         self.setConfiguredValues()
147
148                         config.pep.blue_boost = ConfigSlider(default=0, limits=(0,4))
149                         config.pep.blue_boost.addNotifier(setBlueboost)
150
151                         def setBlock_noise_reduction(config):
152                                 myval = int(config.value)
153                                 try:
154                                         print "--> setting block_noise_reduction to: %0.8X" % myval
155                                         open("/proc/stb/vmpeg/0/pep_block_noise_reduction", "w").write("%0.8X" % myval)
156                                 except IOError:
157                                         print "couldn't write pep_block_noise_reduction."
158
159                                 if VideoEnhancement.firstRun is False:
160                                         self.setConfiguredValues()
161
162                         config.pep.block_noise_reduction = ConfigSlider(default=0, limits=(0,5))
163                         config.pep.block_noise_reduction.addNotifier(setBlock_noise_reduction)
164
165                         def setMosquito_noise_reduction(config):
166                                 myval = int(config.value)
167                                 try:
168                                         print "--> setting mosquito_noise_reduction to: %0.8X" % myval
169                                         open("/proc/stb/vmpeg/0/pep_mosquito_noise_reduction", "w").write("%0.8X" % myval)
170                                 except IOError:
171                                         print "couldn't write pep_mosquito_noise_reduction."
172
173                                 if VideoEnhancement.firstRun is False:
174                                         self.setConfiguredValues()
175
176                         config.pep.mosquito_noise_reduction = ConfigSlider(default=0, limits=(0,5))
177                         config.pep.mosquito_noise_reduction.addNotifier(setMosquito_noise_reduction)
178
179                         def setDigital_contour_removal(config):
180                                 myval = int(config.value)
181                                 try:
182                                         print "--> setting digital_contour_removal to: %0.8X" % myval
183                                         open("/proc/stb/vmpeg/0/pep_digital_contour_removal", "w").write("%0.8X" % myval)
184                                 except IOError:
185                                         print "couldn't write pep_digital_contour_removal."
186
187                                 if VideoEnhancement.firstRun is False:
188                                         self.setConfiguredValues()
189
190                         config.pep.digital_contour_removal = ConfigSlider(default=0, limits=(0,5))
191                         config.pep.digital_contour_removal.addNotifier(setDigital_contour_removal)
192
193                         def setDynamic_contrast(config):
194                                 myval = int(config.value)
195                                 try:
196                                         print "--> setting dynamic_contrast to: %0.8X" % myval
197                                         open("/proc/stb/vmpeg/0/pep_dynamic_contrast", "w").write("%0.8X" % myval)
198                                 except IOError:
199                                         print "couldn't write pep_dynamic_contrast."
200
201                                 if VideoEnhancement.firstRun is False:
202                                         self.setConfiguredValues()
203
204                         config.pep.dynamic_contrast = ConfigSlider(default=0, limits=(0,256))
205                         config.pep.dynamic_contrast.addNotifier(setDynamic_contrast)
206
207                 VideoEnhancement.firstRun = True
208
209         def setConfiguredValues(self):
210                 try:
211                         print "--> applying pep values"
212                         open("/proc/stb/vmpeg/0/pep_apply", "w").write("1")
213                         VideoEnhancement.firstRun = False
214                 except IOError:
215                         print "couldn't apply pep values."
216
217
218 if config.usage.setup_level.index >= 2: # expert+
219         hw_type = HardwareInfo().get_device_name()
220         if hw_type == 'dm8000' or hw_type == 'dm800':
221                 video_enhancement = VideoEnhancement()
222                 if video_enhancement.firstRun == True:
223                         video_enhancement.setConfiguredValues()