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
=== modified file 'lucioLib/lcl_export/lcl_export_pitivi.py'
--- lucioLib/lcl_export/lcl_export_pitivi.py 2010-01-03 14:10:07 +0000
+++ lucioLib/lcl_export/lcl_export_pitivi.py 2011-10-10 23:32:18 +0000
@@ -157,7 +157,8 @@
157 """ compute duration in pitivi format. 157 """ compute duration in pitivi format.
158 Input is the fpi : number of frame per image158 Input is the fpi : number of frame per image
159 """159 """
160 duration = (1.0/fpi)*self.__BASE_DURATION_NS160 print "export pitivi calc duration fpi = %s"%fpi
161 duration = (1.0/ (25.0/fpi) )*self.__BASE_DURATION_NS
161 # use of str and int : int for a rounded value and str for string in element tree162 # use of str and int : int for a rounded value and str for string in element tree
162 return str(int(duration))163 return str(int(duration))
163164
164165
=== modified file 'lucioLib/lcl_gst/lcl_gst_play.py'
--- lucioLib/lcl_gst/lcl_gst_play.py 2010-02-03 06:11:27 +0000
+++ lucioLib/lcl_gst/lcl_gst_play.py 2011-10-10 23:32:18 +0000
@@ -24,6 +24,7 @@
24import lcl_gst_base as LG24import lcl_gst_base as LG
2525
2626
27import fractions
2728
28class lcl_gst_play(LG.lcl_gstreamer) :29class lcl_gst_play(LG.lcl_gstreamer) :
29 """ implementation of image per image video playing with gstreamer .30 """ implementation of image per image video playing with gstreamer .
@@ -34,7 +35,7 @@
34 |_______________________________________________________________________________________________________|35 |_______________________________________________________________________________________________________|
35 """36 """
3637
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 "
38 39
39 def _get_nbImages(self): return self._nbImages40 def _get_nbImages(self): return self._nbImages
40 def _set_nbImages(self, value):41 def _set_nbImages(self, value):
@@ -46,7 +47,7 @@
46 def _get_framerate(self): return self._framerate47 def _get_framerate(self): return self._framerate
47 def _set_framerate(self, value):48 def _set_framerate(self, value):
48 if isinstance(value, str) and self.ImageFilter :49 if isinstance(value, str) and self.ImageFilter :
49 caps_string = self._filter_caps_string % value50 caps_string = self._filter_caps_string % (fractions.Fraction(value))
50 caps = LG.Caps(caps_string)51 caps = LG.Caps(caps_string)
51 self.ImageFilter.set_property("caps", caps)52 self.ImageFilter.set_property("caps", caps)
52 self._framerate = value 53 self._framerate = value
5354
=== modified file 'lucioLib/lucioWebCamDetect/luciole_webcam_detection.py'
--- lucioLib/lucioWebCamDetect/luciole_webcam_detection.py 2010-02-03 06:11:27 +0000
+++ lucioLib/lucioWebCamDetect/luciole_webcam_detection.py 2011-10-10 23:32:18 +0000
@@ -4,7 +4,7 @@
4# vim:si:ai:et:sw=4:sts=4:ts=44# vim:si:ai:et:sw=4:sts=4:ts=4
5#5#
6#6#
7# Copyright Nicolas Bertrand (nico@inattendu.org), 2009-20107# Copyright Nicolas Bertrand (nico@inattendu.org), 2009-2011
8#8#
9# This file is part of Luciole.9# This file is part of Luciole.
10#10#
@@ -22,59 +22,93 @@
22# along with Luciole. If not, see <http://www.gnu.org/licenses/>.22# along with Luciole. If not, see <http://www.gnu.org/licenses/>.
23#23#
24#24#
2525"""
26import dbus26luciole_webcam_detection
27import dbus.glib27Interface function for webcam detection.
28import sys28Retro compatibilty of luciole 0.9 in 0.8 branch.
29import os29Main reason : remove usage of hal
30import fcntl30"""
3131import gobject
32import gst32import gst
3333
34import time
35
36import gobject
3734
38import logging 35import logging
39module_logger = logging.getLogger('luciole')36module_logger = logging.getLogger('luciole')
4037
38#from lucioLib.luciole_exceptions import luciole_exceptions as LEXCEP
4139
42from .. import luciole_exceptions as LEXCEP40from .. import luciole_exceptions as LEXCEP
4341#import luciole_exceptions as LEXCEP
4442
45# Availables video sources for gstreamer43
46GSTREAMER_VIDEO_SOURCES = [44from webcam_detection import WebcamDetection
47 "v4l2src",45
48 "v4lsrc"46class luciole_webcam_detection(WebcamDetection) :
49 ]
50
51
52class luciole_webcam_detection(object) :
53 """ class in charge of detection of available webcams """
54
55 def __get_webcam_devices(self) : return self._webcam_devices
56 webcam_devices = property(__get_webcam_devices, None, None, "webcam devices description")
5747
58 def __init__(self) :48 def __init__(self) :
59 """ class init"""49 WebcamDetection.__init__(self)
60 # init logger50
61 self.logger = logging.getLogger('luciole')51 def detect_webcam(self):
62 52 """ interface function for webcam detection """
63 self._webcam_devices = list()53 # udev detetction
64 54 _nb_webcams = WebcamDetection.detect_webcams(self)
65 ############################################################55
66 ### PUBLIC METHODS56 if _nb_webcams != 0 :
67 ############################################################57 # detect properties with gstreamer
68 def detect_webcam(self) :58 self.gst_props = webcam_gstreamer_properties(self.webcam_devices)
69 """ performs webcam detection . 59 _nb_webcams = self.gst_props.gst_detection()
70 returns number of webcam detected 60
71 """61 return _nb_webcams
72 status = self._hal_detection()62
73 if status != 0 :63 def get_gst_best_input(self, webcam_device_index=0) :
74 # at least webcam was found , perform gstremer detection 64 """ interface function to select best input """
75 status = self._gst_detection()65 return self.gst_props.get_gst_best_input(webcam_device_index)
76 66 #_device = self.webcam_devices[webcam_device_index]
77 return status67 #print "device ", _device
68 #_prop_name ='definition'
69
70
71 #WebcamDetection.get_best_value(self, _prop_name, "")
72
73
74class webcam_gstreamer_properties(object) :
75
76 def __init__(self, devices) :
77 self._webcam_devices = devices
78 # laucnch gst detection
79
80
81
82 def gst_detection(self) :
83 """ performs webcam type detection with gstreamer :
84 _ detects what source yo use ( v4lsrc or v4l2src)
85 _ resolution
86 _ video mime types
87 """
88 nb_device_detected = 0
89 for webcam_device in self._webcam_devices :
90 # for each detected device get the data (source type, mimetype, resolution)
91 (status, webcam_device_data) = self.__get_gst_webcam_data(webcam_device["device-file"], webcam_device["v4ldriver"])
92 if status[0] == gst.STATE_CHANGE_SUCCESS and webcam_device_data != None :
93 # detection is success
94 webcam_device["webcam_data"] = webcam_device_data
95 nb_device_detected = nb_device_detected +1
96 else :
97 # gstreamer test unsuccesfull : test with other driver
98 if webcam_device["v4ldriver"] == 'v4lsrc' :
99 webcam_device["v4ldriver"] = 'v4l2src'
100 else :
101 webcam_device["v4ldriver"] ='v4lsrc'
102 (status, webcam_device_data) = self.__get_gst_webcam_data(webcam_device["device-file"], webcam_device["v4ldriver"])
103 if status[0] == gst.STATE_CHANGE_SUCCESS and webcam_device_data != None :
104 # detection is success
105 webcam_device["webcam_data"] = webcam_device_data
106 nb_device_detected = nb_device_detected +1
107 else :
108 #Nothing detected . Reset webcam device
109 webcam_device=dict()
110 return nb_device_detected
111
78112
79 def get_gst_best_input(self, webcam_device_index=0) :113 def get_gst_best_input(self, webcam_device_index=0) :
80 """ for selected webcam device returns the gst.Bin with 114 """ for selected webcam device returns the gst.Bin with
@@ -100,10 +134,11 @@
100 if video_formats.has_key(mimetype) :134 if video_formats.has_key(mimetype) :
101 # the resolution format are sorted by resolution 135 # the resolution format are sorted by resolution
102 # the higher resolution is first in list136 # the higher resolution is first in list
103 width = video_formats[mimetype][0]['width']137
104 height = video_formats[mimetype][0]['height']138 #width = video_formats[mimetype][0]['width']
105 framerate = video_formats[mimetype][0]['framerate']139 #height = video_formats[mimetype][0]['height']
106140 #framerate = video_formats[mimetype][0]['framerate']
141 width, height, framerate = self._get_best_definition(video_formats[mimetype])
107 142
108 # leave loop when mimetype is found143 # leave loop when mimetype is found
109 break144 break
@@ -114,113 +149,30 @@
114 webcam_bin_data['height'] = height149 webcam_bin_data['height'] = height
115 webcam_bin_data['framerate_list'] = framerate150 webcam_bin_data['framerate_list'] = framerate
116 webcam_bin_data['framerate_selected'] = framerate[len(framerate)/2]151 webcam_bin_data['framerate_selected'] = framerate[len(framerate)/2]
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']
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']
119 webcam_bin_data['name'] = self._webcam_devices[webcam_device_index]['name']154 webcam_bin_data['name'] = self._webcam_devices[webcam_device_index]['name']
120155
121 return webcam_bin_data156 return webcam_bin_data
122157
123 158
124 159 def _get_best_definition(self, mimetype_data) :
125 160 """ Loop on width height return valu with greatest size ( Widthxheight)"""
126161 _width = 0
127 ############################################################162 _height = 0
128 ### PRIVATE METHODS163 _MAX = _width * _height
129 ############################################################164 _framerate = 0
130165 for _data in mimetype_data :
131 def _hal_detection(self) :166 _new_max = _data['width'] * _data['height']
132 """ performs hal detection """167 if _new_max > _MAX :
133 168 _MAX = _new_max
134 # get a connection to the system bus169 _width = _data['width']
135 bus = dbus.SystemBus ()170 _height = _data['height']
136171 _framerate = _data['framerate']
137 # get a HAL object and an interface to HAL to make function calls172 return _width, _height, _framerate
138 hal_obj = bus.get_object ('org.freedesktop.Hal', '/org/freedesktop/Hal/Manager')173
139 hal = dbus.Interface (hal_obj, 'org.freedesktop.Hal.Manager')174
140175
141 # find all devices that have the capability 'video4linux'
142 udis = hal.FindDeviceByCapability ('video4linux')
143
144 # loop on found device
145 for udi in udis :
146 webcam_device = dict()
147
148 # get a device object
149 dev_obj = bus.get_object ('org.freedesktop.Hal', udi)
150
151 # get an interface to the device
152 dev = dbus.Interface (dev_obj, 'org.freedesktop.Hal.Device')
153
154
155 webcam_device["name"] = dev.GetProperty ('info.product')
156 if webcam_device["name"] == None : webcam_device["name"] = "Unknown"
157 webcam_device["device"] = dev.GetProperty ('video4linux.device')
158
159 # detect if need to use v4lsrc or v4l2sec ; property :video4linux.version
160 # for robustness if version = 1 , than use v4lsrc else use v4l2src
161 version = dev.GetProperty ('video4linux.version')
162 # default is v4l2src
163 webcam_device['v4l_driver'] = 'v4l2src'
164 if version != None and int(version) == 1 :
165 webcam_device['v4l_driver'] = 'v4lsrc'
166
167
168 if (not webcam_device["device"] == None) and ( self.__is_device_readable(webcam_device["device"]) ) :
169 self._webcam_devices.append(webcam_device)
170
171 # the function returns the number of device found.
172 nb_device_found = 0
173 if not self._webcam_devices == None :
174 nb_device_found = len(self._webcam_devices)
175
176 return nb_device_found
177
178 def _gst_detection(self) :
179 """ performs webcam type detection with gstreamer :
180 _ detects what source yo use ( v4lsrc or v4l2src)
181 _ resolution
182 _ video mime types
183 """
184 nb_device_detected = 0
185 for webcam_device in self._webcam_devices :
186 # for each detected device get the data (source type, mimetype, resolution)
187 (status, webcam_device_data) = self.__get_gst_webcam_data(webcam_device["device"], webcam_device["v4l_driver"])
188 if status[0] == gst.STATE_CHANGE_SUCCESS and webcam_device_data != None :
189 # detection is success
190 webcam_device["webcam_data"] = webcam_device_data
191 nb_device_detected = nb_device_detected +1
192 else :
193 # gstreamer test unsuccesfull : test with other driver
194 if webcam_device["v4l_driver"] == 'v4lsrc' :
195 webcam_device["v4l_driver"] = 'v4l2src'
196 else :
197 webcam_device["v4l_driver"] ='v4lsrc'
198 (status, webcam_device_data) = self.__get_gst_webcam_data(webcam_device["device"], webcam_device["v4l_driver"])
199 if status[0] == gst.STATE_CHANGE_SUCCESS and webcam_device_data != None :
200 # detection is success
201 webcam_device["webcam_data"] = webcam_device_data
202 nb_device_detected = nb_device_detected +1
203 else :
204 #Nothing detected . Reset webcam device
205 webcam_device=dict()
206 return nb_device_detected
207
208
209 ############################################################
210 ### PRIVATE STATIC METHODS
211 ############################################################
212 def __is_device_readable(device) :
213 """ check if device is readable """
214 is_readable = False
215 try :
216 fd = open(device,'r')
217 except IOError,err:
218 is_readable = False
219 else :
220 is_readable = True
221 fd.close()
222 return is_readable
223 __is_device_readable = staticmethod(__is_device_readable)
224176
225 def __get_gst_webcam_data(device_name,driver) :177 def __get_gst_webcam_data(device_name,driver) :
226 """ get data from the webcam test compatible sources178 """ get data from the webcam test compatible sources
@@ -250,7 +202,7 @@
250 # of the source "src" pad 202 # of the source "src" pad
251 pad = src.get_pad("src")203 pad = src.get_pad("src")
252 caps = pad.get_caps()204 caps = pad.get_caps()
253 luciole_webcam_detection.gst_get_supported_video_formats(webcam_device,caps)205 webcam_gstreamer_properties.gst_get_supported_video_formats(webcam_device,caps)
254 # stop playing with webcam206 # stop playing with webcam
255 pipeline.set_state(gst.STATE_NULL)207 pipeline.set_state(gst.STATE_NULL)
256 return (ret,webcam_device)208 return (ret,webcam_device)
@@ -314,7 +266,7 @@
314 (resolution["width"] , resolution["height"] ) = (structure["width"],structure["height"]) 266 (resolution["width"] , resolution["height"] ) = (structure["width"],structure["height"])
315 resolution["framerate"] = None267 resolution["framerate"] = None
316 if structure.has_field("framerate") :268 if structure.has_field("framerate") :
317 resolution["framerate"] = luciole_webcam_detection.gst_get_framerate(structure["framerate"])269 resolution["framerate"] = webcam_gstreamer_properties.gst_get_framerate(structure["framerate"])
318 if not resolution in resolution_list :270 if not resolution in resolution_list :
319 resolution_list.append(resolution)271 resolution_list.append(resolution)
320 272
@@ -367,6 +319,9 @@
367 return framerate_trans319 return framerate_trans
368 gst_get_framerate = staticmethod(__gst_get_framerate)320 gst_get_framerate = staticmethod(__gst_get_framerate)
369321
322
323
324
370if __name__ == '__main__' :325if __name__ == '__main__' :
371 # TEST PURPOSE : for webcam detection326 # TEST PURPOSE : for webcam detection
372 CamObj = luciole_webcam_detection()327 CamObj = luciole_webcam_detection()
@@ -376,7 +331,7 @@
376 #if val >0 :331 #if val >0 :
377 # for device in CamObj.webcam_devices : 332 # for device in CamObj.webcam_devices :
378 # for k,j in device.iteritems() : print "%s : %s"%(k,j)333 # for k,j in device.iteritems() : print "%s : %s"%(k,j)
379 # print "----------------------------------------------------------------"334 # print "---------------------------------------------"
380 for i in range(val) :335 for i in range(val) :
381 #for enumerate(index,device) in CamObj.webcam_devices :336 #for enumerate(index,device) in CamObj.webcam_devices :
382 best = CamObj.get_gst_best_input(i)337 best = CamObj.get_gst_best_input(i)
383338
=== added file 'lucioLib/lucioWebCamDetect/webcam_detection.py'
--- lucioLib/lucioWebCamDetect/webcam_detection.py 1970-01-01 00:00:00 +0000
+++ lucioLib/lucioWebCamDetect/webcam_detection.py 2011-10-10 23:32:18 +0000
@@ -0,0 +1,105 @@
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# -*- Mode: Python -*-
4# vim:si:ai:et:sw=4:sts=4:ts=4
5#
6#
7# Copyright Nicolas Bertrand (nico@inattendu.org), 2009-2010
8#
9# This file is part of Luciole.
10#
11# Luciole is free software: you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation, either version 3 of the License, or
14# (at your option) any later version.
15#
16# Luciole is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with Luciole. If not, see <http://www.gnu.org/licenses/>.
23#
24#
25"""
26 webcam_detection.py :
27 Webcam detection module
28"""
29import gudev
30import glib
31
32import gst
33
34
35
36class WebcamDetection(object) :
37
38 def _get_webcam_devices(self) :
39 """ getter for webcam_devices"""
40 return self._webcam_devices
41 webcam_devices = property( _get_webcam_devices,
42 None,
43 None,
44 "webcam devices description")
45
46 def __init__(self) :
47 """ class init"""
48
49 self._webcam_devices = []
50
51 def detect_webcams(self) :
52 client = gudev.Client(["block", "usb"])
53 devices = client.query_by_subsystem("video4linux")
54 self.device_information(devices)
55
56 return len(self._webcam_devices)
57
58 def device_information(self, devices) :
59
60 for _device in devices :
61 _device_desc = {}
62 _device_desc['device-file'] = _device.get_device_file()
63
64 _v4lversion = self._get_prop(_device, 'ID_V4L_VERSION')
65 print type(_v4lversion)
66
67 if int(_v4lversion) in (1, 2) :
68 # getting information related to v4l
69 if _v4lversion == 1 :
70 _device_desc['v4ldriver'] = 'v4lsrc'
71 else :
72 _device_desc['v4ldriver'] = 'v4l2src'
73
74 _device_desc['name'] = self._get_prop(_device, 'ID_V4L_PRODUCT')
75 if not ':capture:' in self._get_prop(_device, "ID_V4L_CAPABILITIES") :
76 self.error('Device %s seems to not have the capture capability',
77 _device_desc['device-file'])
78 continue
79 else :
80 self.error(
81 "Fix your udev installation to include v4l_id, ignoring %s",
82 _device_desc['device-file'])
83 continue
84 # append selected element
85 self._webcam_devices.append(_device_desc)
86
87
88
89 def _get_prop(self, device, key_p) :
90 _val = "UNKNOW_%s" % key_p
91 if device.has_property(key_p) :
92 _val = device.get_property(key_p)
93 return _val
94
95
96
97if __name__ == '__main__' :
98
99 CamDetect = WebcamDetection()
100 _nb = CamDetect.detect_webcams()
101 print "Find %s devices"% _nb
102 for _cam in CamDetect.webcam_devices :
103 print _cam
104
105

Subscribers

People subscribed via source and target branches

to all changes: