Merge lp:~nico-inattendu/luciole/bug_742343 into lp:luciole/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
Reviewer Review Type Date Requested Status
NicoInattendu Pending
Review via email: mp+78899@code.launchpad.net

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

Subscribers

People subscribed via source and target branches

to all changes: