Merge lp:~nico-inattendu/luciole/bug_742343 into lp:luciole/0.8
- bug_742343
- Merge into 0.8
Proposed by
NicoInattendu
Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | NicoInattendu | ||||||||||||
Approved revision: | 82 | ||||||||||||
Merge reported by: | NicoInattendu | ||||||||||||
Merged at revision: | not available | ||||||||||||
Proposed branch: | lp:~nico-inattendu/luciole/bug_742343 | ||||||||||||
Merge into: | lp:luciole/0.8 | ||||||||||||
Diff against target: |
490 lines (+219/-157) 4 files modified
lucioLib/lcl_export/lcl_export_pitivi.py (+2/-1) lucioLib/lcl_gst/lcl_gst_play.py (+3/-2) lucioLib/lucioWebCamDetect/luciole_webcam_detection.py (+109/-154) lucioLib/lucioWebCamDetect/webcam_detection.py (+105/-0) |
||||||||||||
To merge this branch: | bzr merge lp:~nico-inattendu/luciole/bug_742343 | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
NicoInattendu | Pending | ||
Review via email: mp+78899@code.launchpad.net |
Commit message
Description of the change
Bug fixes :
Bug #742343: luciole does not detect webcam on maverick
Bug #782643: export to Pitivi always with same framerate
Bug #871609: Framerate "not integer" provokes play failure
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lucioLib/lcl_export/lcl_export_pitivi.py' | |||
2 | --- lucioLib/lcl_export/lcl_export_pitivi.py 2010-01-03 14:10:07 +0000 | |||
3 | +++ lucioLib/lcl_export/lcl_export_pitivi.py 2011-10-10 23:32:18 +0000 | |||
4 | @@ -157,7 +157,8 @@ | |||
5 | 157 | """ compute duration in pitivi format. | 157 | """ compute duration in pitivi format. |
6 | 158 | Input is the fpi : number of frame per image | 158 | Input is the fpi : number of frame per image |
7 | 159 | """ | 159 | """ |
9 | 160 | duration = (1.0/fpi)*self.__BASE_DURATION_NS | 160 | print "export pitivi calc duration fpi = %s"%fpi |
10 | 161 | duration = (1.0/ (25.0/fpi) )*self.__BASE_DURATION_NS | ||
11 | 161 | # use of str and int : int for a rounded value and str for string in element tree | 162 | # use of str and int : int for a rounded value and str for string in element tree |
12 | 162 | return str(int(duration)) | 163 | return str(int(duration)) |
13 | 163 | 164 | ||
14 | 164 | 165 | ||
15 | === modified file 'lucioLib/lcl_gst/lcl_gst_play.py' | |||
16 | --- lucioLib/lcl_gst/lcl_gst_play.py 2010-02-03 06:11:27 +0000 | |||
17 | +++ lucioLib/lcl_gst/lcl_gst_play.py 2011-10-10 23:32:18 +0000 | |||
18 | @@ -24,6 +24,7 @@ | |||
19 | 24 | import lcl_gst_base as LG | 24 | import lcl_gst_base as LG |
20 | 25 | 25 | ||
21 | 26 | 26 | ||
22 | 27 | import fractions | ||
23 | 27 | 28 | ||
24 | 28 | class lcl_gst_play(LG.lcl_gstreamer) : | 29 | class lcl_gst_play(LG.lcl_gstreamer) : |
25 | 29 | """ implementation of image per image video playing with gstreamer . | 30 | """ implementation of image per image video playing with gstreamer . |
26 | @@ -34,7 +35,7 @@ | |||
27 | 34 | |_______________________________________________________________________________________________________| | 35 | |_______________________________________________________________________________________________________| |
28 | 35 | """ | 36 | """ |
29 | 36 | 37 | ||
31 | 37 | _filter_caps_string = "image/jpeg, framerate=(fraction)%s/1 ,width=360,height=288 " | 38 | _filter_caps_string = "image/jpeg, framerate=(fraction)%s ,width=360,height=288 " |
32 | 38 | 39 | ||
33 | 39 | def _get_nbImages(self): return self._nbImages | 40 | def _get_nbImages(self): return self._nbImages |
34 | 40 | def _set_nbImages(self, value): | 41 | def _set_nbImages(self, value): |
35 | @@ -46,7 +47,7 @@ | |||
36 | 46 | def _get_framerate(self): return self._framerate | 47 | def _get_framerate(self): return self._framerate |
37 | 47 | def _set_framerate(self, value): | 48 | def _set_framerate(self, value): |
38 | 48 | if isinstance(value, str) and self.ImageFilter : | 49 | if isinstance(value, str) and self.ImageFilter : |
40 | 49 | caps_string = self._filter_caps_string % value | 50 | caps_string = self._filter_caps_string % (fractions.Fraction(value)) |
41 | 50 | caps = LG.Caps(caps_string) | 51 | caps = LG.Caps(caps_string) |
42 | 51 | self.ImageFilter.set_property("caps", caps) | 52 | self.ImageFilter.set_property("caps", caps) |
43 | 52 | self._framerate = value | 53 | self._framerate = value |
44 | 53 | 54 | ||
45 | === modified file 'lucioLib/lucioWebCamDetect/luciole_webcam_detection.py' | |||
46 | --- lucioLib/lucioWebCamDetect/luciole_webcam_detection.py 2010-02-03 06:11:27 +0000 | |||
47 | +++ lucioLib/lucioWebCamDetect/luciole_webcam_detection.py 2011-10-10 23:32:18 +0000 | |||
48 | @@ -4,7 +4,7 @@ | |||
49 | 4 | # vim:si:ai:et:sw=4:sts=4:ts=4 | 4 | # vim:si:ai:et:sw=4:sts=4:ts=4 |
50 | 5 | # | 5 | # |
51 | 6 | # | 6 | # |
53 | 7 | # Copyright Nicolas Bertrand (nico@inattendu.org), 2009-2010 | 7 | # Copyright Nicolas Bertrand (nico@inattendu.org), 2009-2011 |
54 | 8 | # | 8 | # |
55 | 9 | # This file is part of Luciole. | 9 | # This file is part of Luciole. |
56 | 10 | # | 10 | # |
57 | @@ -22,59 +22,93 @@ | |||
58 | 22 | # along with Luciole. If not, see <http://www.gnu.org/licenses/>. | 22 | # along with Luciole. If not, see <http://www.gnu.org/licenses/>. |
59 | 23 | # | 23 | # |
60 | 24 | # | 24 | # |
68 | 25 | 25 | """ | |
69 | 26 | import dbus | 26 | luciole_webcam_detection |
70 | 27 | import dbus.glib | 27 | Interface function for webcam detection. |
71 | 28 | import sys | 28 | Retro compatibilty of luciole 0.9 in 0.8 branch. |
72 | 29 | import os | 29 | Main reason : remove usage of hal |
73 | 30 | import fcntl | 30 | """ |
74 | 31 | 31 | import gobject | |
75 | 32 | import gst | 32 | import gst |
76 | 33 | 33 | ||
77 | 34 | import time | ||
78 | 35 | |||
79 | 36 | import gobject | ||
80 | 37 | 34 | ||
81 | 38 | import logging | 35 | import logging |
82 | 39 | module_logger = logging.getLogger('luciole') | 36 | module_logger = logging.getLogger('luciole') |
83 | 40 | 37 | ||
84 | 38 | #from lucioLib.luciole_exceptions import luciole_exceptions as LEXCEP | ||
85 | 41 | 39 | ||
86 | 42 | from .. import luciole_exceptions as LEXCEP | 40 | from .. import luciole_exceptions as LEXCEP |
101 | 43 | 41 | #import luciole_exceptions as LEXCEP | |
102 | 44 | 42 | ||
103 | 45 | # Availables video sources for gstreamer | 43 | |
104 | 46 | GSTREAMER_VIDEO_SOURCES = [ | 44 | from webcam_detection import WebcamDetection |
105 | 47 | "v4l2src", | 45 | |
106 | 48 | "v4lsrc" | 46 | class luciole_webcam_detection(WebcamDetection) : |
93 | 49 | ] | ||
94 | 50 | |||
95 | 51 | |||
96 | 52 | class luciole_webcam_detection(object) : | ||
97 | 53 | """ class in charge of detection of available webcams """ | ||
98 | 54 | |||
99 | 55 | def __get_webcam_devices(self) : return self._webcam_devices | ||
100 | 56 | webcam_devices = property(__get_webcam_devices, None, None, "webcam devices description") | ||
107 | 57 | 47 | ||
108 | 58 | def __init__(self) : | 48 | def __init__(self) : |
128 | 59 | """ class init""" | 49 | WebcamDetection.__init__(self) |
129 | 60 | # init logger | 50 | |
130 | 61 | self.logger = logging.getLogger('luciole') | 51 | def detect_webcam(self): |
131 | 62 | 52 | """ interface function for webcam detection """ | |
132 | 63 | self._webcam_devices = list() | 53 | # udev detetction |
133 | 64 | 54 | _nb_webcams = WebcamDetection.detect_webcams(self) | |
134 | 65 | ############################################################ | 55 | |
135 | 66 | ### PUBLIC METHODS | 56 | if _nb_webcams != 0 : |
136 | 67 | ############################################################ | 57 | # detect properties with gstreamer |
137 | 68 | def detect_webcam(self) : | 58 | self.gst_props = webcam_gstreamer_properties(self.webcam_devices) |
138 | 69 | """ performs webcam detection . | 59 | _nb_webcams = self.gst_props.gst_detection() |
139 | 70 | returns number of webcam detected | 60 | |
140 | 71 | """ | 61 | return _nb_webcams |
141 | 72 | status = self._hal_detection() | 62 | |
142 | 73 | if status != 0 : | 63 | def get_gst_best_input(self, webcam_device_index=0) : |
143 | 74 | # at least webcam was found , perform gstremer detection | 64 | """ interface function to select best input """ |
144 | 75 | status = self._gst_detection() | 65 | return self.gst_props.get_gst_best_input(webcam_device_index) |
145 | 76 | 66 | #_device = self.webcam_devices[webcam_device_index] | |
146 | 77 | return status | 67 | #print "device ", _device |
147 | 68 | #_prop_name ='definition' | ||
148 | 69 | |||
149 | 70 | |||
150 | 71 | #WebcamDetection.get_best_value(self, _prop_name, "") | ||
151 | 72 | |||
152 | 73 | |||
153 | 74 | class webcam_gstreamer_properties(object) : | ||
154 | 75 | |||
155 | 76 | def __init__(self, devices) : | ||
156 | 77 | self._webcam_devices = devices | ||
157 | 78 | # laucnch gst detection | ||
158 | 79 | |||
159 | 80 | |||
160 | 81 | |||
161 | 82 | def gst_detection(self) : | ||
162 | 83 | """ performs webcam type detection with gstreamer : | ||
163 | 84 | _ detects what source yo use ( v4lsrc or v4l2src) | ||
164 | 85 | _ resolution | ||
165 | 86 | _ video mime types | ||
166 | 87 | """ | ||
167 | 88 | nb_device_detected = 0 | ||
168 | 89 | for webcam_device in self._webcam_devices : | ||
169 | 90 | # for each detected device get the data (source type, mimetype, resolution) | ||
170 | 91 | (status, webcam_device_data) = self.__get_gst_webcam_data(webcam_device["device-file"], webcam_device["v4ldriver"]) | ||
171 | 92 | if status[0] == gst.STATE_CHANGE_SUCCESS and webcam_device_data != None : | ||
172 | 93 | # detection is success | ||
173 | 94 | webcam_device["webcam_data"] = webcam_device_data | ||
174 | 95 | nb_device_detected = nb_device_detected +1 | ||
175 | 96 | else : | ||
176 | 97 | # gstreamer test unsuccesfull : test with other driver | ||
177 | 98 | if webcam_device["v4ldriver"] == 'v4lsrc' : | ||
178 | 99 | webcam_device["v4ldriver"] = 'v4l2src' | ||
179 | 100 | else : | ||
180 | 101 | webcam_device["v4ldriver"] ='v4lsrc' | ||
181 | 102 | (status, webcam_device_data) = self.__get_gst_webcam_data(webcam_device["device-file"], webcam_device["v4ldriver"]) | ||
182 | 103 | if status[0] == gst.STATE_CHANGE_SUCCESS and webcam_device_data != None : | ||
183 | 104 | # detection is success | ||
184 | 105 | webcam_device["webcam_data"] = webcam_device_data | ||
185 | 106 | nb_device_detected = nb_device_detected +1 | ||
186 | 107 | else : | ||
187 | 108 | #Nothing detected . Reset webcam device | ||
188 | 109 | webcam_device=dict() | ||
189 | 110 | return nb_device_detected | ||
190 | 111 | |||
191 | 78 | 112 | ||
192 | 79 | def get_gst_best_input(self, webcam_device_index=0) : | 113 | def get_gst_best_input(self, webcam_device_index=0) : |
193 | 80 | """ for selected webcam device returns the gst.Bin with | 114 | """ for selected webcam device returns the gst.Bin with |
194 | @@ -100,10 +134,11 @@ | |||
195 | 100 | if video_formats.has_key(mimetype) : | 134 | if video_formats.has_key(mimetype) : |
196 | 101 | # the resolution format are sorted by resolution | 135 | # the resolution format are sorted by resolution |
197 | 102 | # the higher resolution is first in list | 136 | # the higher resolution is first in list |
202 | 103 | width = video_formats[mimetype][0]['width'] | 137 | |
203 | 104 | height = video_formats[mimetype][0]['height'] | 138 | #width = video_formats[mimetype][0]['width'] |
204 | 105 | framerate = video_formats[mimetype][0]['framerate'] | 139 | #height = video_formats[mimetype][0]['height'] |
205 | 106 | 140 | #framerate = video_formats[mimetype][0]['framerate'] | |
206 | 141 | width, height, framerate = self._get_best_definition(video_formats[mimetype]) | ||
207 | 107 | 142 | ||
208 | 108 | # leave loop when mimetype is found | 143 | # leave loop when mimetype is found |
209 | 109 | break | 144 | break |
210 | @@ -114,113 +149,30 @@ | |||
211 | 114 | webcam_bin_data['height'] = height | 149 | webcam_bin_data['height'] = height |
212 | 115 | webcam_bin_data['framerate_list'] = framerate | 150 | webcam_bin_data['framerate_list'] = framerate |
213 | 116 | webcam_bin_data['framerate_selected'] = framerate[len(framerate)/2] | 151 | webcam_bin_data['framerate_selected'] = framerate[len(framerate)/2] |
216 | 117 | webcam_bin_data['source_input'] = self._webcam_devices[webcam_device_index]['v4l_driver'] | 152 | webcam_bin_data['source_input'] = self._webcam_devices[webcam_device_index]['v4ldriver'] |
217 | 118 | webcam_bin_data['device'] = self._webcam_devices[webcam_device_index]['device'] | 153 | webcam_bin_data['device'] = self._webcam_devices[webcam_device_index]['device-file'] |
218 | 119 | webcam_bin_data['name'] = self._webcam_devices[webcam_device_index]['name'] | 154 | webcam_bin_data['name'] = self._webcam_devices[webcam_device_index]['name'] |
219 | 120 | 155 | ||
220 | 121 | return webcam_bin_data | 156 | return webcam_bin_data |
221 | 122 | 157 | ||
323 | 123 | 158 | ||
324 | 124 | 159 | def _get_best_definition(self, mimetype_data) : | |
325 | 125 | 160 | """ Loop on width height return valu with greatest size ( Widthxheight)""" | |
326 | 126 | 161 | _width = 0 | |
327 | 127 | ############################################################ | 162 | _height = 0 |
328 | 128 | ### PRIVATE METHODS | 163 | _MAX = _width * _height |
329 | 129 | ############################################################ | 164 | _framerate = 0 |
330 | 130 | 165 | for _data in mimetype_data : | |
331 | 131 | def _hal_detection(self) : | 166 | _new_max = _data['width'] * _data['height'] |
332 | 132 | """ performs hal detection """ | 167 | if _new_max > _MAX : |
333 | 133 | 168 | _MAX = _new_max | |
334 | 134 | # get a connection to the system bus | 169 | _width = _data['width'] |
335 | 135 | bus = dbus.SystemBus () | 170 | _height = _data['height'] |
336 | 136 | 171 | _framerate = _data['framerate'] | |
337 | 137 | # get a HAL object and an interface to HAL to make function calls | 172 | return _width, _height, _framerate |
338 | 138 | hal_obj = bus.get_object ('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager') | 173 | |
339 | 139 | hal = dbus.Interface (hal_obj, 'org.freedesktop.Hal.Manager') | 174 | |
340 | 140 | 175 | ||
240 | 141 | # find all devices that have the capability 'video4linux' | ||
241 | 142 | udis = hal.FindDeviceByCapability ('video4linux') | ||
242 | 143 | |||
243 | 144 | # loop on found device | ||
244 | 145 | for udi in udis : | ||
245 | 146 | webcam_device = dict() | ||
246 | 147 | |||
247 | 148 | # get a device object | ||
248 | 149 | dev_obj = bus.get_object ('org.freedesktop.Hal', udi) | ||
249 | 150 | |||
250 | 151 | # get an interface to the device | ||
251 | 152 | dev = dbus.Interface (dev_obj, 'org.freedesktop.Hal.Device') | ||
252 | 153 | |||
253 | 154 | |||
254 | 155 | webcam_device["name"] = dev.GetProperty ('info.product') | ||
255 | 156 | if webcam_device["name"] == None : webcam_device["name"] = "Unknown" | ||
256 | 157 | webcam_device["device"] = dev.GetProperty ('video4linux.device') | ||
257 | 158 | |||
258 | 159 | # detect if need to use v4lsrc or v4l2sec ; property :video4linux.version | ||
259 | 160 | # for robustness if version = 1 , than use v4lsrc else use v4l2src | ||
260 | 161 | version = dev.GetProperty ('video4linux.version') | ||
261 | 162 | # default is v4l2src | ||
262 | 163 | webcam_device['v4l_driver'] = 'v4l2src' | ||
263 | 164 | if version != None and int(version) == 1 : | ||
264 | 165 | webcam_device['v4l_driver'] = 'v4lsrc' | ||
265 | 166 | |||
266 | 167 | |||
267 | 168 | if (not webcam_device["device"] == None) and ( self.__is_device_readable(webcam_device["device"]) ) : | ||
268 | 169 | self._webcam_devices.append(webcam_device) | ||
269 | 170 | |||
270 | 171 | # the function returns the number of device found. | ||
271 | 172 | nb_device_found = 0 | ||
272 | 173 | if not self._webcam_devices == None : | ||
273 | 174 | nb_device_found = len(self._webcam_devices) | ||
274 | 175 | |||
275 | 176 | return nb_device_found | ||
276 | 177 | |||
277 | 178 | def _gst_detection(self) : | ||
278 | 179 | """ performs webcam type detection with gstreamer : | ||
279 | 180 | _ detects what source yo use ( v4lsrc or v4l2src) | ||
280 | 181 | _ resolution | ||
281 | 182 | _ video mime types | ||
282 | 183 | """ | ||
283 | 184 | nb_device_detected = 0 | ||
284 | 185 | for webcam_device in self._webcam_devices : | ||
285 | 186 | # for each detected device get the data (source type, mimetype, resolution) | ||
286 | 187 | (status, webcam_device_data) = self.__get_gst_webcam_data(webcam_device["device"], webcam_device["v4l_driver"]) | ||
287 | 188 | if status[0] == gst.STATE_CHANGE_SUCCESS and webcam_device_data != None : | ||
288 | 189 | # detection is success | ||
289 | 190 | webcam_device["webcam_data"] = webcam_device_data | ||
290 | 191 | nb_device_detected = nb_device_detected +1 | ||
291 | 192 | else : | ||
292 | 193 | # gstreamer test unsuccesfull : test with other driver | ||
293 | 194 | if webcam_device["v4l_driver"] == 'v4lsrc' : | ||
294 | 195 | webcam_device["v4l_driver"] = 'v4l2src' | ||
295 | 196 | else : | ||
296 | 197 | webcam_device["v4l_driver"] ='v4lsrc' | ||
297 | 198 | (status, webcam_device_data) = self.__get_gst_webcam_data(webcam_device["device"], webcam_device["v4l_driver"]) | ||
298 | 199 | if status[0] == gst.STATE_CHANGE_SUCCESS and webcam_device_data != None : | ||
299 | 200 | # detection is success | ||
300 | 201 | webcam_device["webcam_data"] = webcam_device_data | ||
301 | 202 | nb_device_detected = nb_device_detected +1 | ||
302 | 203 | else : | ||
303 | 204 | #Nothing detected . Reset webcam device | ||
304 | 205 | webcam_device=dict() | ||
305 | 206 | return nb_device_detected | ||
306 | 207 | |||
307 | 208 | |||
308 | 209 | ############################################################ | ||
309 | 210 | ### PRIVATE STATIC METHODS | ||
310 | 211 | ############################################################ | ||
311 | 212 | def __is_device_readable(device) : | ||
312 | 213 | """ check if device is readable """ | ||
313 | 214 | is_readable = False | ||
314 | 215 | try : | ||
315 | 216 | fd = open(device,'r') | ||
316 | 217 | except IOError,err: | ||
317 | 218 | is_readable = False | ||
318 | 219 | else : | ||
319 | 220 | is_readable = True | ||
320 | 221 | fd.close() | ||
321 | 222 | return is_readable | ||
322 | 223 | __is_device_readable = staticmethod(__is_device_readable) | ||
341 | 224 | 176 | ||
342 | 225 | def __get_gst_webcam_data(device_name,driver) : | 177 | def __get_gst_webcam_data(device_name,driver) : |
343 | 226 | """ get data from the webcam test compatible sources | 178 | """ get data from the webcam test compatible sources |
344 | @@ -250,7 +202,7 @@ | |||
345 | 250 | # of the source "src" pad | 202 | # of the source "src" pad |
346 | 251 | pad = src.get_pad("src") | 203 | pad = src.get_pad("src") |
347 | 252 | caps = pad.get_caps() | 204 | caps = pad.get_caps() |
349 | 253 | luciole_webcam_detection.gst_get_supported_video_formats(webcam_device,caps) | 205 | webcam_gstreamer_properties.gst_get_supported_video_formats(webcam_device,caps) |
350 | 254 | # stop playing with webcam | 206 | # stop playing with webcam |
351 | 255 | pipeline.set_state(gst.STATE_NULL) | 207 | pipeline.set_state(gst.STATE_NULL) |
352 | 256 | return (ret,webcam_device) | 208 | return (ret,webcam_device) |
353 | @@ -314,7 +266,7 @@ | |||
354 | 314 | (resolution["width"] , resolution["height"] ) = (structure["width"],structure["height"]) | 266 | (resolution["width"] , resolution["height"] ) = (structure["width"],structure["height"]) |
355 | 315 | resolution["framerate"] = None | 267 | resolution["framerate"] = None |
356 | 316 | if structure.has_field("framerate") : | 268 | if structure.has_field("framerate") : |
358 | 317 | resolution["framerate"] = luciole_webcam_detection.gst_get_framerate(structure["framerate"]) | 269 | resolution["framerate"] = webcam_gstreamer_properties.gst_get_framerate(structure["framerate"]) |
359 | 318 | if not resolution in resolution_list : | 270 | if not resolution in resolution_list : |
360 | 319 | resolution_list.append(resolution) | 271 | resolution_list.append(resolution) |
361 | 320 | 272 | ||
362 | @@ -367,6 +319,9 @@ | |||
363 | 367 | return framerate_trans | 319 | return framerate_trans |
364 | 368 | gst_get_framerate = staticmethod(__gst_get_framerate) | 320 | gst_get_framerate = staticmethod(__gst_get_framerate) |
365 | 369 | 321 | ||
366 | 322 | |||
367 | 323 | |||
368 | 324 | |||
369 | 370 | if __name__ == '__main__' : | 325 | if __name__ == '__main__' : |
370 | 371 | # TEST PURPOSE : for webcam detection | 326 | # TEST PURPOSE : for webcam detection |
371 | 372 | CamObj = luciole_webcam_detection() | 327 | CamObj = luciole_webcam_detection() |
372 | @@ -376,7 +331,7 @@ | |||
373 | 376 | #if val >0 : | 331 | #if val >0 : |
374 | 377 | # for device in CamObj.webcam_devices : | 332 | # for device in CamObj.webcam_devices : |
375 | 378 | # for k,j in device.iteritems() : print "%s : %s"%(k,j) | 333 | # for k,j in device.iteritems() : print "%s : %s"%(k,j) |
377 | 379 | # print "----------------------------------------------------------------" | 334 | # print "---------------------------------------------" |
378 | 380 | for i in range(val) : | 335 | for i in range(val) : |
379 | 381 | #for enumerate(index,device) in CamObj.webcam_devices : | 336 | #for enumerate(index,device) in CamObj.webcam_devices : |
380 | 382 | best = CamObj.get_gst_best_input(i) | 337 | best = CamObj.get_gst_best_input(i) |
381 | 383 | 338 | ||
382 | === added file 'lucioLib/lucioWebCamDetect/webcam_detection.py' | |||
383 | --- lucioLib/lucioWebCamDetect/webcam_detection.py 1970-01-01 00:00:00 +0000 | |||
384 | +++ lucioLib/lucioWebCamDetect/webcam_detection.py 2011-10-10 23:32:18 +0000 | |||
385 | @@ -0,0 +1,105 @@ | |||
386 | 1 | #!/usr/bin/env python | ||
387 | 2 | # -*- coding: utf-8 -*- | ||
388 | 3 | # -*- Mode: Python -*- | ||
389 | 4 | # vim:si:ai:et:sw=4:sts=4:ts=4 | ||
390 | 5 | # | ||
391 | 6 | # | ||
392 | 7 | # Copyright Nicolas Bertrand (nico@inattendu.org), 2009-2010 | ||
393 | 8 | # | ||
394 | 9 | # This file is part of Luciole. | ||
395 | 10 | # | ||
396 | 11 | # Luciole is free software: you can redistribute it and/or modify | ||
397 | 12 | # it under the terms of the GNU General Public License as published by | ||
398 | 13 | # the Free Software Foundation, either version 3 of the License, or | ||
399 | 14 | # (at your option) any later version. | ||
400 | 15 | # | ||
401 | 16 | # Luciole is distributed in the hope that it will be useful, | ||
402 | 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
403 | 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
404 | 19 | # GNU General Public License for more details. | ||
405 | 20 | # | ||
406 | 21 | # You should have received a copy of the GNU General Public License | ||
407 | 22 | # along with Luciole. If not, see <http://www.gnu.org/licenses/>. | ||
408 | 23 | # | ||
409 | 24 | # | ||
410 | 25 | """ | ||
411 | 26 | webcam_detection.py : | ||
412 | 27 | Webcam detection module | ||
413 | 28 | """ | ||
414 | 29 | import gudev | ||
415 | 30 | import glib | ||
416 | 31 | |||
417 | 32 | import gst | ||
418 | 33 | |||
419 | 34 | |||
420 | 35 | |||
421 | 36 | class WebcamDetection(object) : | ||
422 | 37 | |||
423 | 38 | def _get_webcam_devices(self) : | ||
424 | 39 | """ getter for webcam_devices""" | ||
425 | 40 | return self._webcam_devices | ||
426 | 41 | webcam_devices = property( _get_webcam_devices, | ||
427 | 42 | None, | ||
428 | 43 | None, | ||
429 | 44 | "webcam devices description") | ||
430 | 45 | |||
431 | 46 | def __init__(self) : | ||
432 | 47 | """ class init""" | ||
433 | 48 | |||
434 | 49 | self._webcam_devices = [] | ||
435 | 50 | |||
436 | 51 | def detect_webcams(self) : | ||
437 | 52 | client = gudev.Client(["block", "usb"]) | ||
438 | 53 | devices = client.query_by_subsystem("video4linux") | ||
439 | 54 | self.device_information(devices) | ||
440 | 55 | |||
441 | 56 | return len(self._webcam_devices) | ||
442 | 57 | |||
443 | 58 | def device_information(self, devices) : | ||
444 | 59 | |||
445 | 60 | for _device in devices : | ||
446 | 61 | _device_desc = {} | ||
447 | 62 | _device_desc['device-file'] = _device.get_device_file() | ||
448 | 63 | |||
449 | 64 | _v4lversion = self._get_prop(_device, 'ID_V4L_VERSION') | ||
450 | 65 | print type(_v4lversion) | ||
451 | 66 | |||
452 | 67 | if int(_v4lversion) in (1, 2) : | ||
453 | 68 | # getting information related to v4l | ||
454 | 69 | if _v4lversion == 1 : | ||
455 | 70 | _device_desc['v4ldriver'] = 'v4lsrc' | ||
456 | 71 | else : | ||
457 | 72 | _device_desc['v4ldriver'] = 'v4l2src' | ||
458 | 73 | |||
459 | 74 | _device_desc['name'] = self._get_prop(_device, 'ID_V4L_PRODUCT') | ||
460 | 75 | if not ':capture:' in self._get_prop(_device, "ID_V4L_CAPABILITIES") : | ||
461 | 76 | self.error('Device %s seems to not have the capture capability', | ||
462 | 77 | _device_desc['device-file']) | ||
463 | 78 | continue | ||
464 | 79 | else : | ||
465 | 80 | self.error( | ||
466 | 81 | "Fix your udev installation to include v4l_id, ignoring %s", | ||
467 | 82 | _device_desc['device-file']) | ||
468 | 83 | continue | ||
469 | 84 | # append selected element | ||
470 | 85 | self._webcam_devices.append(_device_desc) | ||
471 | 86 | |||
472 | 87 | |||
473 | 88 | |||
474 | 89 | def _get_prop(self, device, key_p) : | ||
475 | 90 | _val = "UNKNOW_%s" % key_p | ||
476 | 91 | if device.has_property(key_p) : | ||
477 | 92 | _val = device.get_property(key_p) | ||
478 | 93 | return _val | ||
479 | 94 | |||
480 | 95 | |||
481 | 96 | |||
482 | 97 | if __name__ == '__main__' : | ||
483 | 98 | |||
484 | 99 | CamDetect = WebcamDetection() | ||
485 | 100 | _nb = CamDetect.detect_webcams() | ||
486 | 101 | print "Find %s devices"% _nb | ||
487 | 102 | for _cam in CamDetect.webcam_devices : | ||
488 | 103 | print _cam | ||
489 | 104 | |||
490 | 105 |