/SystemPlugins/VideoEnhancement: allow configuration of block_noise_reduction, mosqui...
[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                 def setBlock_noise_reduction(config):
78                         myval = int(config.value)
79                         try:
80                                 print "--> setting block_noise_reduction to: %0.8X" % myval
81                                 open("/proc/stb/vmpeg/0/pep_block_noise_reduction", "w").write("%0.8X" % myval)
82                         except IOError:
83                                 print "couldn't write pep_block_noise_reduction."
84
85                         if VideoEnhancement.firstRun is False:
86                                 self.setConfiguredValues()
87
88                 config.pep.block_noise_reduction = ConfigSlider(default=0, limits=(0,5))
89                 config.pep.block_noise_reduction.addNotifier(setBlock_noise_reduction)
90
91                 def setMosquito_noise_reduction(config):
92                         myval = int(config.value)
93                         try:
94                                 print "--> setting mosquito_noise_reduction to: %0.8X" % myval
95                                 open("/proc/stb/vmpeg/0/pep_mosquito_noise_reduction", "w").write("%0.8X" % myval)
96                         except IOError:
97                                 print "couldn't write pep_mosquito_noise_reduction."
98
99                         if VideoEnhancement.firstRun is False:
100                                 self.setConfiguredValues()
101
102                 config.pep.mosquito_noise_reduction = ConfigSlider(default=0, limits=(0,5))
103                 config.pep.mosquito_noise_reduction.addNotifier(setMosquito_noise_reduction)
104
105                 def setDigital_contour_removal(config):
106                         myval = int(config.value)
107                         try:
108                                 print "--> setting digital_contour_removal to: %0.8X" % myval
109                                 open("/proc/stb/vmpeg/0/pep_digital_contour_removal", "w").write("%0.8X" % myval)
110                         except IOError:
111                                 print "couldn't write pep_digital_contour_removal."
112
113                         if VideoEnhancement.firstRun is False:
114                                 self.setConfiguredValues()
115
116                 config.pep.digital_contour_removal = ConfigSlider(default=0, limits=(0,5))
117                 config.pep.digital_contour_removal.addNotifier(setDigital_contour_removal)
118
119                 if hw_type == 'dm8000':
120                         def setSplitMode(config):
121                                 try:
122                                         print "--> setting splitmode to:",str(config.value)
123                                         open("/proc/stb/vmpeg/0/pep_split", "w").write(str(config.value))
124                                 except IOError:
125                                         print "couldn't write pep_split."
126
127                                 if VideoEnhancement.firstRun is False:
128                                         self.setConfiguredValues()
129
130                         config.pep.split = ConfigSelection(choices={
131                                         "off": _("Off"),
132                                         "left": _("Left"),
133                                         "right": _("Right")},
134                                         default = "off")
135                         config.pep.split.addNotifier(setSplitMode)
136
137                         def setSharpness(config):
138                                 myval = int(config.value*256)
139                                 try:
140                                         print "--> setting sharpness to: %0.8X" % myval
141                                         open("/proc/stb/vmpeg/0/pep_sharpness", "w").write("%0.8X" % myval)
142                                 except IOError:
143                                         print "couldn't write pep_sharpness."
144
145                                 if VideoEnhancement.firstRun is False:
146                                         self.setConfiguredValues()
147
148                         config.pep.sharpness = ConfigSlider(default=0, limits=(0,256))
149                         config.pep.sharpness.addNotifier(setSharpness)
150
151                         def setAutoflesh(config):
152                                 myval = int(config.value)
153                                 try:
154                                         print "--> setting auto_flesh to: %0.8X" % myval
155                                         open("/proc/stb/vmpeg/0/pep_auto_flesh", "w").write("%0.8X" % myval)
156                                 except IOError:
157                                         print "couldn't write pep_auto_flesh."
158
159                                 if VideoEnhancement.firstRun is False:
160                                         self.setConfiguredValues()
161
162                         config.pep.auto_flesh = ConfigSlider(default=0, limits=(0,4))
163                         config.pep.auto_flesh.addNotifier(setAutoflesh)
164
165                         def setGreenboost(config):
166                                 myval = int(config.value)
167                                 try:
168                                         print "--> setting green_boost to: %0.8X" % myval
169                                         open("/proc/stb/vmpeg/0/pep_green_boost", "w").write("%0.8X" % myval)
170                                 except IOError:
171                                         print "couldn't write pep_green_boost."
172
173                                 if VideoEnhancement.firstRun is False:
174                                         self.setConfiguredValues()
175
176                         config.pep.green_boost = ConfigSlider(default=0, limits=(0,4))
177                         config.pep.green_boost.addNotifier(setGreenboost)
178
179                         def setBlueboost(config):
180                                 myval = int(config.value)
181                                 try:
182                                         print "--> setting blue_boost to: %0.8X" % myval
183                                         open("/proc/stb/vmpeg/0/pep_blue_boost", "w").write("%0.8X" % myval)
184                                 except IOError:
185                                         print "couldn't write pep_blue_boost."
186
187                                 if VideoEnhancement.firstRun is False:
188                                         self.setConfiguredValues()
189
190                         config.pep.blue_boost = ConfigSlider(default=0, limits=(0,4))
191                         config.pep.blue_boost.addNotifier(setBlueboost)
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()