Merge lp:~nico-inattendu/luciole/bug_excessive_cpu into lp:luciole/0.8

Proposed by NicoInattendu
Status: Merged
Approved by: NicoInattendu
Approved revision: not available
Merge reported by: NicoInattendu
Merged at revision: not available
Proposed branch: lp:~nico-inattendu/luciole/bug_excessive_cpu
Merge into: lp:luciole/0.8
Diff against target: 804 lines (+364/-74)
8 files modified
lucioLib/gui/dialog_project_properties.py (+166/-24)
lucioLib/lcl_gst/lcl_gst_acq.py (+41/-11)
lucioLib/lcl_gst/lcl_gst_base.py (+10/-6)
lucioLib/lcl_gst/lcl_gst_play.py (+0/-1)
lucioLib/lucioWebCamDetect/luciole_webcam_detection.py (+70/-16)
lucioLib/luciole_controller.py (+11/-6)
lucioLib/luciole_project.py (+64/-10)
luciole.py (+2/-0)
To merge this branch: bzr merge lp:~nico-inattendu/luciole/bug_excessive_cpu
Reviewer Review Type Date Requested Status
NicoInattendu Approve
Review via email: mp+18246@code.launchpad.net

Commit message

Merge with corrections fo excessive CPU bug #500649

To post a comment you must log in.
Revision history for this message
NicoInattendu (nico-inattendu) wrote :

Merge with 0.8

Translation update needed after

Revision history for this message
NicoInattendu (nico-inattendu) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lucioLib/gui/dialog_project_properties.py'
--- lucioLib/gui/dialog_project_properties.py 2009-04-28 13:36:55 +0000
+++ lucioLib/gui/dialog_project_properties.py 2010-01-29 07:10:30 +0000
@@ -1,9 +1,9 @@
1#!/usr/bin/env python1#!/usr/bin/env python
2# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-
3# -*- Mode: Python -*-3# -*- Mode: Python -*-
4# vi:si:ai:et:sw=4:sts=4:ts=44# vim:si:ai:et:sw=4:sts=4:ts=4
5#5#
6# Copyright Nicolas Bertrand (nico@inattendu.org), 20096# Copyright Nicolas Bertrand (nico@inattendu.org), 2009, 2010
7#7#
8# This file is part of Luciole.8# This file is part of Luciole.
9#9#
@@ -22,16 +22,22 @@
22#22#
23#23#
24"""24"""
25 dialog_project_properties.py : Dialog who display the project properties25 dialog_project_properties.py : Dialog who display the luciole project properties
26"""26"""
27#i18n
27from gettext import gettext as _28from gettext import gettext as _
29
28import gtk30import gtk
29import pango31import pango
3032
31from .. import luciole_constants as LCONST33from .. import luciole_constants as LCONST
32import webcam_detection_widget as LWDW34import webcam_detection_widget as LWDW
3335
34(LABEL,ENTRY)=range(2)36
37#type of widgets for displaying webcam data
38(LABEL,ENTRY,SCALE)=range(3)
39
40
3541
36class Project_properties(object):42class Project_properties(object):
37 43
@@ -83,14 +89,19 @@
83 'desc' : _('Video height :'),89 'desc' : _('Video height :'),
84 'type' : LABEL90 'type' : LABEL
85 },91 },
92 'framerate_list': {
93 'desc' : _('Webcam framerate \n (number of images per second)'),
94 'type' : SCALE
95 },
96
97
86 }98 }
8799
88100
89 _title = _('Project properties')101 _title = _('Project properties')
90 102
91 def __init__(self,main_window, project, cb_project_change) :103 def __init__(self,main_window, project, cb_project_change) :
92 """ create a Dialog with project properties and disqpay it"""104 """ create a Dialog with project properties and display it"""
93
94 self._dialog = gtk.Dialog ( _(self._title),105 self._dialog = gtk.Dialog ( _(self._title),
95 main_window,106 main_window,
96 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,107 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
@@ -101,6 +112,9 @@
101 self._project = project112 self._project = project
102 self._cb_project_change = cb_project_change113 self._cb_project_change = cb_project_change
103 114
115 # keep framerate list and framerate selected those value can change
116 self._framerate_selected = self._project['webcam_data']['framerate_selected']
117 self._framerate_list = self._project['webcam_data']['framerate_list']
104 # connect destroy signal118 # connect destroy signal
105 #self._dialog.connect("destroy", self._cb_on_exit)119 #self._dialog.connect("destroy", self._cb_on_exit)
106 self._dialog.connect("delete-event", self._cb_on_exit)120 self._dialog.connect("delete-event", self._cb_on_exit)
@@ -131,10 +145,19 @@
131 # assumption only enry on webcam data145 # assumption only enry on webcam data
132 webcam_dict = self._project['webcam_data']146 webcam_dict = self._project['webcam_data']
133 for (key_entry, widget_entry) in self.webcam_widgets.iteritems() :147 for (key_entry, widget_entry) in self.webcam_widgets.iteritems() :
134 if widget_entry.get_text() != webcam_dict[key_entry] :148 # specific treatment when the wigdet is associated to framerate_list
135 # entry value changed149 # store framerate_list and framerate_selected
136 # emit callback to inidcate project change150 if key_entry == 'framerate_list' :
137 self._cb_project_change('webcam_data', key_entry, widget_entry.get_text())151 # callback for updated framerate
152 self._cb_project_change('webcam_data', 'framerate_selected',self._framerate_selected)
153 # check if framerate list has changed if yes callback for framerate list
154 if webcam_dict[key_entry] != self._framerate_list :
155 self._cb_project_change('webcam_data', 'framerate_list',self._framerate_list)
156 else :
157 if widget_entry.get_text() != webcam_dict[key_entry] :
158 # entry value changed
159 # emit callback to inidcate project change
160 self._cb_project_change('webcam_data', key_entry, widget_entry.get_text())
138 161
139 def _cb_on_exit(self,widget,event) :162 def _cb_on_exit(self,widget,event) :
140 self._dialog.destroy()163 self._dialog.destroy()
@@ -196,15 +219,19 @@
196 widget = None219 widget = None
197 if self._WEBCAM_PREFS[key]['type'] == ENTRY :220 if self._WEBCAM_PREFS[key]['type'] == ENTRY :
198 widget = gtk.Entry()221 widget = gtk.Entry()
199 widget.set_alignment(xalign=0.0) # left justification of label222 widget.set_alignment(xalign = 0.0) # left justification
200 else: 223 widget.set_text("%s"%self._project['webcam_data'][key])
224 elif self._WEBCAM_PREFS[key]['type'] == LABEL :
201 widget = gtk.Label()225 widget = gtk.Label()
202 widget.set_alignment(xalign=0.0,yalign=0.5) # left justification of label226 widget.set_alignment(xalign = 0.0, yalign = 0.5) # left justification
203 227 widget.set_text("%s"%self._project['webcam_data'][key])
228 elif self._WEBCAM_PREFS[key]['type'] == SCALE :
229 widget = Framerate_scale(self._project['webcam_data'][key],
230 self._project['webcam_data']['framerate_selected'],
231 self._cb_framerate_selected)
232
204 self.webcam_widgets[key] = widget # save the widget233 self.webcam_widgets[key] = widget # save the widget
205 234
206 widget.set_text("%s"%self._project['webcam_data'][key])
207
208 widget.show()235 widget.show()
209 table.attach(widget, 1, 2, row, row+1,xpadding = 10 )236 table.attach(widget, 1, 2, row, row+1,xpadding = 10 )
210237
@@ -235,7 +262,9 @@
235 self.make_table_webcam_row(table,2,'height')262 self.make_table_webcam_row(table,2,'height')
236 self.make_table_webcam_row(table,3,'source_input')263 self.make_table_webcam_row(table,3,'source_input')
237 self.make_table_webcam_row(table,4,'device')264 self.make_table_webcam_row(table,4,'device')
238 265 self.make_table_webcam_row(table,5,'framerate_list')
266 # No lines for framerate_selected tag : handled framerate_list tag
267
239 Hbox.pack_start( child = table,268 Hbox.pack_start( child = table,
240 expand = True,269 expand = True,
241 fill = True,270 fill = True,
@@ -294,15 +323,25 @@
294323
295324
296 def _cb_webcam_detection(self,project_data) :325 def _cb_webcam_detection(self,project_data) :
297 """ calback when webcam detection is done update webcam data """326 """ callback when webcam detection is done update webcam data """
298 if project_data.has_key('webcam_data') and project_data['webcam_data'] != {} :327 if project_data.has_key('webcam_data') and project_data['webcam_data'] != {} :
299 for (w_key, w_widget) in self.webcam_widgets.iteritems() :328 for (w_key, w_widget) in self.webcam_widgets.iteritems() :
300 if project_data['webcam_data'].has_key(w_key) : 329 # Sepcific operation for framerate_list widget
301 w_text ="%s"%project_data['webcam_data'][w_key]330 if w_key == 'framerate_list' :
302 w_widget.set_text(w_text)331 w_widget.refresh(project_data['webcam_data']['framerate_list'],
332 project_data['webcam_data']['framerate_selected'] )
333 self._framerate_list = project_data['webcam_data']['framerate_list']
334 # for other webcam widgets : only text to update
303 else :335 else :
304 w_widget.set_text('')336 if project_data['webcam_data'].has_key(w_key) :
305337 w_text ="%s"%project_data['webcam_data'][w_key]
338 w_widget.set_text(w_text)
339 else :
340 w_widget.set_text('')
341
342 def _cb_framerate_selected(self,framerate) :
343 """ callback to update selected framerate used by Framerate_scale widget """
344 self._framerate_selected = framerate
306345
307class Webcam_detection_dialog(gtk.MessageDialog) :346class Webcam_detection_dialog(gtk.MessageDialog) :
308 """ Opens Dialog for webcam Detection """347 """ Opens Dialog for webcam Detection """
@@ -352,4 +391,107 @@
352 return True391 return True
353392
354393
355394class Framerate_scale(gtk.HScale) :
395 """
396 Widget use to display an horizontal scale :
397 represenation of webcam framerates in number of images per seconds
398 """
399
400 def __init__(self,framerate_range,initial_range,cb_framerate_changed) :
401 """
402 Constructor
403 params :
404 - framerate_range : The framerate range - a list of framerate tuple
405 - initial_range : The initial range to dipslay - a tuple
406 - cb_framerate_changed : the callback function to indicate framerate change
407 """
408
409 #
410 # store params
411 #
412 self._framerate_range = framerate_range
413 self._initial_range = initial_range
414 self._cb_framerate_changed = cb_framerate_changed
415
416
417 #
418 # configure widget
419 #
420
421 # compute the initial position on Scale bar
422 initial_f_value = float(self._framerate_range.index(self._initial_range))
423
424 #
425 # compute an adjustment in range [0 .. nb_framerate], icrement is 1
426 # Use floats as ints actually
427 # Display framerates instead of float values
428 #
429 adj = gtk.Adjustment(value =initial_f_value,
430 lower = 0.0,
431 upper = float(len( self._framerate_range)),
432 step_incr = 1.0,
433 page_incr = 1.0)
434
435
436 super(Framerate_scale,self).__init__(adjustment = adj)
437
438 # configure signals
439 self.connect("format-value", self.on_format_value)
440 self.connect("value-changed", self.on_value_changed)
441
442 # configure widget display properties
443 self.set_update_policy(gtk.UPDATE_DISCONTINUOUS)
444 self.set_value_pos(gtk.POS_BOTTOM)
445 self.show_all()
446
447 def on_format_value(self,widget,value) :
448 """
449 Signal 'format-value' : Used to display value in scale in image/seconds format.
450 Computed according the adjustment value, the intger round of value is the index
451 of framerate_range
452 """
453 int_val = int(value)
454 if int_val >= len(self._framerate_range) :
455 int_val = len(self._framerate_range) -1
456 val_to_display = self._framerate_range[int_val]
457 # compute and return the number of images per second
458 return int(val_to_display[0]/val_to_display[1])
459
460 def on_value_changed(self,widget) :
461 """
462 Emited when a value is changed and selected by user
463 the signal function get the float value, round it,
464 get the equivalent framerate.
465 """
466 # TODO : how to update webcam date
467
468 # get rounded value
469 int_val = int(widget.get_value())
470 if int_val >= len(self._framerate_range) :
471 int_val = len(self._framerate_range) -1
472 # update project data : do callback call
473 self._cb_framerate_changed( self._framerate_range[int_val])
474
475
476 def refresh(self, framerate_list, framerate_selected) :
477 """
478 Update Scale bar and ajustment according new framerate range
479 """
480
481 self._framerate_range = framerate_list
482 self._initial_range = framerate_selected
483
484 #
485 # recompute adjustment
486 #
487 initial_f_value = float(self._framerate_range.index(self._initial_range))
488
489 adj = gtk.Adjustment(value =initial_f_value,
490 lower = 0.0,
491 upper = float(len( self._framerate_range)),
492 step_incr = 1.0,
493 page_incr = 1.0)
494
495 self.set_adjustment(adj)
496
497
356498
=== modified file 'lucioLib/lcl_gst/lcl_gst_acq.py'
--- lucioLib/lcl_gst/lcl_gst_acq.py 2009-12-14 06:15:44 +0000
+++ lucioLib/lcl_gst/lcl_gst_acq.py 2010-01-29 07:10:30 +0000
@@ -40,12 +40,28 @@
4040
41class PhotoSaveBin(LG.Bin) :41class PhotoSaveBin(LG.Bin) :
42 """ Bin Pad to save in jpeg format image from stream. Stream alyays encoded but the result will be saved to file only when a capture is done """42 """ Bin Pad to save in jpeg format image from stream. Stream alyays encoded but the result will be saved to file only when a capture is done """
43
44 # Do jpeg encoding with a framerate of 5 images per second used to reduce cpu
45 JPEG_CAPS_FILTER = " video/x-raw-yuv, framerate=5/1 "
46
43 def __init__(self) :47 def __init__(self) :
44 """ Pilpeline desc : jpegenc + fakseink """48 """ Pilpeline desc : jpegenc + fakseink """
4549
50 super(PhotoSaveBin,self).__init__()
46 self.__gobject_init__()51 self.__gobject_init__()
47 ImageBinElems=[]52 ImageBinElems=[]
48 53
54 Myvideorate = LG.element_factory_make('videorate') # rate transformation
55 ImageBinElems.append(Myvideorate)
56
57 MyJpegFilter = LG.element_factory_make("capsfilter", "JpegFilter")
58 # create caps string according, width, height and framerate
59 caps = LG.Caps(self.JPEG_CAPS_FILTER)
60
61 self.logger.info(" Webcam cap : %s"%caps.to_string())
62 MyJpegFilter.set_property("caps", caps)
63 ImageBinElems.append(MyJpegFilter)
64
49 MyJpegenc = LG.element_factory_make("jpegenc","MyJpegenc") # jpeg encoding65 MyJpegenc = LG.element_factory_make("jpegenc","MyJpegenc") # jpeg encoding
50 ImageBinElems.append(MyJpegenc) 66 ImageBinElems.append(MyJpegenc)
51 67
@@ -54,9 +70,9 @@
54 70
55 for elem in ImageBinElems : self.add(elem)71 for elem in ImageBinElems : self.add(elem)
56 72
57 LG.element_link_many(MyJpegenc,photosink)73 LG.element_link_many(Myvideorate,MyJpegFilter,MyJpegenc,photosink)
58 74
59 self.add_pad(LG.GhostPad('sink', MyJpegenc.get_pad('sink')))75 self.add_pad(LG.GhostPad('sink', Myvideorate.get_pad('sink')))
6076
6177
62class InputImageBin(LG.Bin):78class InputImageBin(LG.Bin):
@@ -79,7 +95,7 @@
79 self.MyAlpha.set_property("alpha",self.__alphaValueImage) 95 self.MyAlpha.set_property("alpha",self.__alphaValueImage)
80 alphaValueImage = property(get_alphaValueImage, set_alphaValueImage, None, " Framerate for displaying input image ")96 alphaValueImage = property(get_alphaValueImage, set_alphaValueImage, None, " Framerate for displaying input image ")
8197
82 def __init__(self,image,alphaValue,framerate=25) :98 def __init__(self,image,alphaValue,framerate=1) :
83 self.__gobject_init__()99 self.__gobject_init__()
84 self.__image2Mix = image100 self.__image2Mix = image
85 self.__framerate = framerate101 self.__framerate = framerate
@@ -90,11 +106,12 @@
90 self.InputImage= LG.element_factory_make('multifilesrc')106 self.InputImage= LG.element_factory_make('multifilesrc')
91 self.InputImage.set_property('location',self.__image2Mix)107 self.InputImage.set_property('location',self.__image2Mix)
92 ImageBinElems.append(self.InputImage)108 ImageBinElems.append(self.InputImage)
93 109
110
94 # filter to set frame rate111 # filter to set frame rate
95 self.ImageFilter = LG.element_factory_make("capsfilter")112 self.ImageFilter = LG.element_factory_make("capsfilter")
96 self._filter_caps_string = "image/jpeg, framerate=(fraction)%s/1 ,width=%s,height=%s "113 self._filter_caps_string = "image/jpeg, framerate=(fraction)%s/1 ,width=%s,height=%s "
97114
98 caps_string = self._filter_caps_string%(self.__framerate,MCONST.VIDEO_PAL_RES[0],MCONST.VIDEO_PAL_RES[1])115 caps_string = self._filter_caps_string%(self.__framerate,MCONST.VIDEO_PAL_RES[0],MCONST.VIDEO_PAL_RES[1])
99 caps = LG.Caps(caps_string)116 caps = LG.Caps(caps_string)
100 self.ImageFilter.set_property("caps", caps)117 self.ImageFilter.set_property("caps", caps)
@@ -282,16 +299,22 @@
282299
283class WebcamInputBin(LG.Bin) :300class WebcamInputBin(LG.Bin) :
284 """ LG.Bin for Web cam input"""301 """ LG.Bin for Web cam input"""
285 def __init__(self,width=640,height=480,source_input='v4l2src',device='/dev/video0') :302 def __init__(self,width=640, height=480, framerate=(2,25), source_input='v4l2src', device='/dev/video0') :
286 """build Dv cam input bin303 """build web cam input bin
287 Description of pipeline : 304 Description of pipeline :
288 __________________________________________________________305 __________________________________________________________
289 | | 306 | |
290 -->-- | v4lsrc --> capsfilter --> ffmpegcolorspace --> ScaleBin | ghostPad -->--307 -->-- | v4lsrc --> capsfilter --> ffmpegcolorspace --> ScaleBin | ghostPad -->--
291 |__________________________________________________________|_ 308 |__________________________________________________________|_
292 309 params :
310 width : The webcam width. Integer value
311 height : The webcam width. Integer value
312 framerate : The webcam framerate. A tuple for fraction representation (denom,num)
313 source_input : The type of driver input. A string
314 device : Path to webcam device. A string
315
293 """316 """
294317 super(WebcamInputBin,self).__init__()
295 self.__gobject_init__()318 self.__gobject_init__()
296 ImageBinElems=[]319 ImageBinElems=[]
297 320
@@ -300,8 +323,9 @@
300 ImageBinElems.append(MyVideoSrc)323 ImageBinElems.append(MyVideoSrc)
301 324
302 MyVideoSrcFilter = LG.element_factory_make("capsfilter", "MyVideoSrc")325 MyVideoSrcFilter = LG.element_factory_make("capsfilter", "MyVideoSrc")
303326 # create caps string according, width, height and framerate
304 caps = LG.Caps("video/x-raw-yuv, width=%s,height=%s"%(width,height) )327 caps = LG.Caps("video/x-raw-yuv, width=%s,height=%s , framerate=%s/%s "%(width,height,framerate[0],framerate[1]) )
328 self.logger.info(" Webcam cap : %s"%caps.to_string())
305 MyVideoSrcFilter.set_property("caps", caps)329 MyVideoSrcFilter.set_property("caps", caps)
306 ImageBinElems.append(MyVideoSrcFilter)330 ImageBinElems.append(MyVideoSrcFilter)
307 331
@@ -492,6 +516,8 @@
492 self.__webcam_data['height'] = 480516 self.__webcam_data['height'] = 480
493 self.__webcam_data['device'] = "/dev/video0"517 self.__webcam_data['device'] = "/dev/video0"
494 self.__webcam_data['source_input'] = "v4l2src"518 self.__webcam_data['source_input'] = "v4l2src"
519 self.__webcam_data['framerate_list'] = [ (25,2) ]
520 self.__webcam_data['framerate_selected'] = (25,2)
495521
496 def reset_pipe(self): 522 def reset_pipe(self):
497 """ Gstreamer pipe configuration :523 """ Gstreamer pipe configuration :
@@ -500,10 +526,14 @@
500 """526 """
501 ElementList = []527 ElementList = []
502 self.pipe = LG.Pipeline(self.pipe_name)528 self.pipe = LG.Pipeline(self.pipe_name)
529 print self.__webcam_data
530 print " type framerate list :" , type(self.__webcam_data['framerate_list'])
531
503 if (self.__inputType == MCONST.WEBCAM) :532 if (self.__inputType == MCONST.WEBCAM) :
504 InputBin = WebcamInputBin(533 InputBin = WebcamInputBin(
505 width = self.__webcam_data['width'],534 width = self.__webcam_data['width'],
506 height = self.__webcam_data['height'],535 height = self.__webcam_data['height'],
536 framerate = self.__webcam_data['framerate_selected'],
507 source_input = self.__webcam_data['source_input'],537 source_input = self.__webcam_data['source_input'],
508 device = self.__webcam_data['device']538 device = self.__webcam_data['device']
509 )539 )
510540
=== modified file 'lucioLib/lcl_gst/lcl_gst_base.py'
--- lucioLib/lcl_gst/lcl_gst_base.py 2009-12-14 06:15:44 +0000
+++ lucioLib/lcl_gst/lcl_gst_base.py 2010-01-29 07:10:30 +0000
@@ -60,11 +60,19 @@
60#60#
6161
62class Pipeline(gst.Pipeline) :62class Pipeline(gst.Pipeline) :
63 """ Interaface class for pipeline """63 """ Interface class for gst pipeline """
6464
65 def __init__(self, *args,**kwargs) :65 def __init__(self, *args,**kwargs) :
66 super(Pipeline, self).__init__(*args,**kwargs)66 super(Pipeline, self).__init__(*args,**kwargs)
6767
68class Bin(gst.Bin) :
69 """ Interface class for gst Bin """
70
71 def __init__(self, *args,**kwargs) :
72 super(Bin, self).__init__(*args,**kwargs)
73 self.logger = logging.getLogger('luciole')
74
75
68class VideoWidget(object):76class VideoWidget(object):
69 """ class usage to be understood """ 77 """ class usage to be understood """
70 def __init__(self,DrawingArea):78 def __init__(self,DrawingArea):
@@ -91,11 +99,7 @@
9199
92 def __init__(self,video_widget = None, pipe_name=None, cb_on_error = None, cb_on_eos = None ):100 def __init__(self,video_widget = None, pipe_name=None, cb_on_error = None, cb_on_eos = None ):
93 # init logger101 # init logger
94
95 self.logger = logging.getLogger('luciole')102 self.logger = logging.getLogger('luciole')
96 if self.logger.level == logging.DEBUG :
97 gst.debug_set_active(True)
98 gst.debug_set_default_threshold(gst.LEVEL_DEBUG)
99 103
100 #104 #
101 # link display window widget with gstreamer 105 # link display window widget with gstreamer
@@ -109,7 +113,7 @@
109 self._cb_on_eos = cb_on_eos113 self._cb_on_eos = cb_on_eos
110 114
111 self.pipe = Pipeline(pipe_name)115 self.pipe = Pipeline(pipe_name)
112 print self.pipe116 self.logger.info(self.pipe)
113 117
114 def connect_bus(self) :118 def connect_bus(self) :
115 """ Connect to bus """119 """ Connect to bus """
116120
=== modified file 'lucioLib/lcl_gst/lcl_gst_play.py'
--- lucioLib/lcl_gst/lcl_gst_play.py 2009-12-14 06:15:44 +0000
+++ lucioLib/lcl_gst/lcl_gst_play.py 2010-01-29 07:10:30 +0000
@@ -83,7 +83,6 @@
83 # filter83 # filter
84 self.ImageFilter = LG.element_factory_make("capsfilter")84 self.ImageFilter = LG.element_factory_make("capsfilter")
85 caps_string = self._filter_caps_string % self._framerate85 caps_string = self._filter_caps_string % self._framerate
86 print caps_string
87 caps = LG.gst.Caps(caps_string)86 caps = LG.gst.Caps(caps_string)
88 self.ImageFilter.set_property("caps", caps)87 self.ImageFilter.set_property("caps", caps)
89 ElementList.append(self.ImageFilter)88 ElementList.append(self.ImageFilter)
9089
=== modified file 'lucioLib/lucioWebCamDetect/luciole_webcam_detection.py'
--- lucioLib/lucioWebCamDetect/luciole_webcam_detection.py 2009-05-09 16:11:31 +0000
+++ lucioLib/lucioWebCamDetect/luciole_webcam_detection.py 2010-01-29 07:10:30 +0000
@@ -35,6 +35,12 @@
3535
36import gobject36import gobject
3737
38import logging
39module_logger = logging.getLogger('luciole')
40
41
42from .. import luciole_exceptions as LEXCEP
43
3844
39# Availables video sources for gstreamer45# Availables video sources for gstreamer
40GSTREAMER_VIDEO_SOURCES = [46GSTREAMER_VIDEO_SOURCES = [
@@ -51,6 +57,9 @@
5157
52 def __init__(self) :58 def __init__(self) :
53 """ class init"""59 """ class init"""
60 # init logger
61 self.logger = logging.getLogger('luciole')
62
54 self._webcam_devices = list()63 self._webcam_devices = list()
55 64
56 ############################################################65 ############################################################
@@ -86,13 +95,15 @@
86 video_formats = self._webcam_devices[webcam_device_index]['webcam_data']['video_formats'] 95 video_formats = self._webcam_devices[webcam_device_index]['webcam_data']['video_formats']
87 mimetypes = ('video/x-raw-yuv','video/x-raw-rgb','image/jpeg')96 mimetypes = ('video/x-raw-yuv','video/x-raw-rgb','image/jpeg')
88 (width,height)=(None,None)97 (width,height)=(None,None)
89
90 for mimetype in mimetypes :98 for mimetype in mimetypes :
99
91 if video_formats.has_key(mimetype) :100 if video_formats.has_key(mimetype) :
92 # the resolution format are sorted by resolution 101 # the resolution format are sorted by resolution
93 # the higher resolution is first in list102 # the higher resolution is first in list
94 width = video_formats[mimetype][0]['width']103 width = video_formats[mimetype][0]['width']
95 height = video_formats[mimetype][0]['height']104 height = video_formats[mimetype][0]['height']
105 framerate = video_formats[mimetype][0]['framerate']
106
96 107
97 # leave loop when mimetype is found108 # leave loop when mimetype is found
98 break109 break
@@ -101,9 +112,11 @@
101 # a format was detected : prepare pipeline info112 # a format was detected : prepare pipeline info
102 webcam_bin_data['width'] = width 113 webcam_bin_data['width'] = width
103 webcam_bin_data['height'] = height114 webcam_bin_data['height'] = height
115 webcam_bin_data['framerate_list'] = framerate
116 webcam_bin_data['framerate_selected'] = framerate[len(framerate)/2]
104 webcam_bin_data['source_input'] = self._webcam_devices[webcam_device_index]['v4l_driver']117 webcam_bin_data['source_input'] = self._webcam_devices[webcam_device_index]['v4l_driver']
105 webcam_bin_data['device'] = self._webcam_devices[webcam_device_index]['device'] 118 webcam_bin_data['device'] = self._webcam_devices[webcam_device_index]['device']
106 webcam_bin_data['name'] = self._webcam_devices[webcam_device_index]['name'] 119 webcam_bin_data['name'] = self._webcam_devices[webcam_device_index]['name']
107120
108 return webcam_bin_data121 return webcam_bin_data
109122
@@ -262,7 +275,6 @@
262 for i in range(num_structures) :275 for i in range(num_structures) :
263 # loop on each strutcures276 # loop on each strutcures
264 structure = caps[i]277 structure = caps[i]
265
266 if ( structure.has_name("video/x-raw-yuv") 278 if ( structure.has_name("video/x-raw-yuv")
267 or structure.has_name("video/x-raw-rgb") 279 or structure.has_name("video/x-raw-rgb")
268 or structure.has_name("image/jpeg")280 or structure.has_name("image/jpeg")
@@ -271,12 +283,12 @@
271 if not webcam_device["video_formats"].has_key(structure.get_name()):283 if not webcam_device["video_formats"].has_key(structure.get_name()):
272 webcam_device["video_formats"][structure.get_name()] = list()284 webcam_device["video_formats"][structure.get_name()] = list()
273 resolution_list = webcam_device["video_formats"][structure.get_name()]285 resolution_list = webcam_device["video_formats"][structure.get_name()]
274 #print " resolution_list at the begin : %s"%webcam_device["video_formats"]286 #print " resolution_list at the begin : \n %s"%webcam_device["video_formats"]
275 287
276 # take in acount only structure wih fields width and height288 # take in acount only structure wih fields width and height
277 if (structure.has_field("width") and structure.has_field("height")) :289 if (structure.has_field("width") and structure.has_field("height")) :
278 #print " %s : %s x %s"%(structure.get_name(),structure["width"],structure["height"] )290 #print " %s : %s x %s"%(structure.get_name(),structure["width"],structure["height"] )
279 291 resolution=dict()
280 # check if result is in GST_TYPE_INT_RANGE format292 # check if result is in GST_TYPE_INT_RANGE format
281 if (isinstance(structure["width"], gst.IntRange)):293 if (isinstance(structure["width"], gst.IntRange)):
282 # when type is range --> some resolution points are created in the range294 # when type is range --> some resolution points are created in the range
@@ -286,21 +298,31 @@
286 while ( ( width_cur <= structure["width"].high ) and298 while ( ( width_cur <= structure["width"].high ) and
287 ( height_cur <= structure["height"].high ) 299 ( height_cur <= structure["height"].high )
288 ):300 ):
289 resolution=dict()301
290 ( resolution["width"] , resolution["height"] ) = (width_cur,height_cur) 302 ( resolution["width"] , resolution["height"] ) = (width_cur,height_cur)
303 #store framerate
304 resolution["framerate"] = None
305 if structure.has_field("framerate") :
306 resolution["framerate"] = structure["framerate"]
307 # Append resolution dict to list
291 if not resolution in resolution_list :308 if not resolution in resolution_list :
292 resolution_list.append(resolution)309 resolution_list.append(resolution)
293 (width_cur,height_cur) = (width_cur*2,height_cur*2)310 (width_cur,height_cur) = (width_cur*2,height_cur*2)
294 311
295 # check if result is in G_TYPE_INT format312 # check if result is in G_TYPE_INT format
296 elif structure.has_field_typed("width",gobject.TYPE_INT) :313 elif structure.has_field_typed("width",gobject.TYPE_INT) :
297 resolution=dict()
298 (resolution["width"] , resolution["height"] ) = (structure["width"],structure["height"]) 314 (resolution["width"] , resolution["height"] ) = (structure["width"],structure["height"])
315 resolution["framerate"] = None
316 if structure.has_field("framerate") :
317 resolution["framerate"] = luciole_webcam_detection.gst_get_framerate(structure["framerate"])
299 if not resolution in resolution_list :318 if not resolution in resolution_list :
300 resolution_list.append(resolution)319 resolution_list.append(resolution)
301 320
302 else :321 else :
303 print " type %s"% structure.get_field_type("width")322 # raise error
323 excep_message = "unkown video type %s"% structure.get_field_type("width")
324 raise LEXCEP.LucioException,excep_message
325
304 for mimetype,res_list in webcam_device["video_formats"].iteritems():326 for mimetype,res_list in webcam_device["video_formats"].iteritems():
305 # loop on video on formats to stort it327 # loop on video on formats to stort it
306 # data are sorted by width , in reverse order; i.e max res is the first in the list328 # data are sorted by width , in reverse order; i.e max res is the first in the list
@@ -314,7 +336,36 @@
314 # print "----- %s : %s"%(mimetype,res_list)336 # print "----- %s : %s"%(mimetype,res_list)
315 gst_get_supported_video_formats = staticmethod(__gst_get_supported_video_formats)337 gst_get_supported_video_formats = staticmethod(__gst_get_supported_video_formats)
316338
317339 def __gst_get_framerate(framerate_obj):
340 """ create a list of gst.Fraction framerates """
341 framerate = list()
342 if type(framerate_obj) == list :
343 framerate = framerate_obj
344 elif isinstance(framerate_obj, gst.FractionRange) :
345 # convert also to list of framerate
346 NB_FRAMERATE = 4
347 MAX_FRAMERATE = gst.Fraction(25,1)
348
349 # limit max framerate
350 if framerate_obj.high < MAX_FRAMERATE :
351 framerate_obj.high = MAX_FRAMERATE
352
353 new_framerate = framerate_obj.high
354 for i in range(NB_FRAMERATE) :
355 framerate.append(new_framerate)
356 new_framerate = new_framerate/2
357 # at end of loop append the lowest framerate if not 0
358 if framerate_obj.low != gst.Fraction(0,1) :
359 framerate.append(framerate_obj.low)
360 else :
361 # raise error
362 excep_message = " unable to detect framerate : unknown type : %s for "%(type(framerate_obj),framerate_obj)
363 raise LEXCEP.LucioException,excep_message
364 # transform framerate in not gst format
365 if framerate != None :
366 framerate_trans = [ (fraction.num,fraction.denom) for fraction in framerate]
367 return framerate_trans
368 gst_get_framerate = staticmethod(__gst_get_framerate)
318369
319if __name__ == '__main__' :370if __name__ == '__main__' :
320 # TEST PURPOSE : for webcam detection371 # TEST PURPOSE : for webcam detection
@@ -322,11 +373,14 @@
322 val = CamObj.detect_webcam()373 val = CamObj.detect_webcam()
323 print " found %s webCam device "%val374 print " found %s webCam device "%val
324375
325 if val >0 :376 #if val >0 :
326 for device in CamObj.webcam_devices : 377 # for device in CamObj.webcam_devices :
327 for k,j in device.iteritems() : print "%s : %s"%(k,j)378 # for k,j in device.iteritems() : print "%s : %s"%(k,j)
328 print "----------------------------------------------------------------"379 # print "----------------------------------------------------------------"
329380 for i in range(val) :
330381 #for enumerate(index,device) in CamObj.webcam_devices :
331382 best = CamObj.get_gst_best_input(i)
383 print "Best webcam resolution found "
384 print best
385 print "\n \n"
332386
333387
=== modified file 'lucioLib/luciole_controller.py'
--- lucioLib/luciole_controller.py 2009-12-14 06:15:44 +0000
+++ lucioLib/luciole_controller.py 2010-01-29 07:10:30 +0000
@@ -123,10 +123,6 @@
123 project_dico_data = LP.project_dico() 123 project_dico_data = LP.project_dico()
124 for k,v in project_data.iteritems() :124 for k,v in project_data.iteritems() :
125 project_dico_data[k] = project_data[k]125 project_dico_data[k] = project_data[k]
126 #convert webcam_data as str values to be coherent with load of webcam data from a file
127 if k == 'webcam_data' :
128 for w_k in project_dico_data[k].keys() :
129 project_dico_data[k][w_k] = "%s"%project_dico_data[k][w_k]
130 self.project = project_dico_data126 self.project = project_dico_data
131127
132 # 2. create project ( folder structure ,etc ...)128 # 2. create project ( folder structure ,etc ...)
@@ -146,8 +142,17 @@
146 # if a project is loaded close it142 # if a project is loaded close it
147 print """ DEBUG : Close project Before """ 143 print """ DEBUG : Close project Before """
148 self.close()144 self.close()
149145 try :
150 self.project = self.project_ctrller.open(project_path)146 (is_valid,self.project) = self.project_ctrller.open(project_path)
147 except L_EXCEP.LucioException,err :
148 print err
149
150 # webcam data are not valid
151 if is_valid == False :
152 msg = _(" Webcam data not valid in project. Please restart webcam detection")
153 LTK.Dialog.ErrorMessage(self.gui.window, msg)
154
155
151156
152 # 3. load project in application157 # 3. load project in application
153 self.__load_project_in_app()158 self.__load_project_in_app()
154159
=== modified file 'lucioLib/luciole_project.py'
--- lucioLib/luciole_project.py 2009-04-24 13:42:04 +0000
+++ lucioLib/luciole_project.py 2010-01-29 07:10:30 +0000
@@ -4,7 +4,7 @@
4# vi:si:ai:et:sw=4:sts=4:ts=44# vi:si:ai:et:sw=4:sts=4:ts=4
5#5#
6#6#
7# Copyright Nicolas Bertrand (nico@inattendu.org), 20097# Copyright Nicolas Bertrand (nico@inattendu.org), 2009,2010
8#8#
9# This file is part of Luciole.9# This file is part of Luciole.
10#10#
@@ -30,18 +30,49 @@
30import xml.etree.ElementTree as ET #python 2.530import xml.etree.ElementTree as ET #python 2.5
31from xml.parsers.expat import ParserCreate, ExpatError31from xml.parsers.expat import ParserCreate, ExpatError
3232
33
33import luciole_constants as LCONST34import luciole_constants as LCONST
34import luciole_tools as LT35import luciole_tools as LT
35import luciole_exceptions as L_EXCEP36import luciole_exceptions as L_EXCEP
3637
37class project_dico(dict):38class project_dico(dict):
39 """
40 Luciole project dicitionary : contains all porject data as dictionary
41 """
42
43 #
44 # CONSTANTS
45 #
46
47 # mandatory tags for webcam description
48 WEBCAM_DATA_TAGS = [ 'name',
49 'device',
50 'source_input',
51 'height',
52 'width',
53 'framerate_list',
54 'framerate_selected',
55 ]
56
57 # default values for webcam
58 WEBCAM_TAGS_DEFAULT_VALUES = {
59 'framerate_list' : [(5,1) ],
60 'framerate_selected' : (5,1) ,
61 }
62
63
38 def __init__(self):64 def __init__(self):
65 """ constructor : init a dict """
39 super(project_dico,self).__init__()66 super(project_dico,self).__init__()
4067
41class project_controller(object) :68class project_controller(object) :
69 """
70 Class for handling luciole projects : creation, open, save
71 """
72
42 73
43 def __init__(self):74 def __init__(self):
44 pass75 """ Constructor"""
45 # by default no project loaded76 # by default no project loaded
46 self.__project_loaded = False77 self.__project_loaded = False
47 78
@@ -170,21 +201,44 @@
170 # loop on webcam data and save on data dictionary201 # loop on webcam data and save on data dictionary
171 webcam_data={}202 webcam_data={}
172 for my_item in et_webcam_data.getchildren() :203 for my_item in et_webcam_data.getchildren() :
173 webcam_data[my_item.tag] = my_item.attrib.get("key")204 # for framerate_selected and framerate_list tage : evaluate to convert in tuple and list
174 # create acquisition object205 # for others keep it as str
175 p_project['webcam_data'] =webcam_data 206 if my_item.tag == 'framerate_selected' or my_item.tag == 'framerate_list' :
207 webcam_data[my_item.tag] = eval(my_item.attrib.get("key"))
208 else :
209 webcam_data[my_item.tag] = my_item.attrib.get("key")
210
211 # check webcam data validity
212 is_valid = True
213 missing_tags = []
214 for data in p_project.WEBCAM_DATA_TAGS :
215 if not webcam_data.has_key(data) :
216 is_valid = False
217 missing_tags.append(data)
218
219 if is_valid == False :
220 # not a valid project
221 for missing_tag in missing_tags :
222 if p_project.WEBCAM_TAGS_DEFAULT_VALUES.has_key(missing_tag) :
223 webcam_data[missing_tag] = p_project.WEBCAM_TAGS_DEFAULT_VALUES[missing_tag]
224 print missing_tag
225 else :
226 err = 'Invalid Project webcam data , tag %s is missing '%missing_tag
227 raise L_EXCEP.LucioException, err
228
229 p_project['webcam_data'] = webcam_data
176 else :230 else :
177 # nbd@grape : raise Error231 # raise Error
178 print " Invalide webcam data found "232 err = "Invalid webcam data found "
179 return None233 raise L_EXCEP.LucioException, err
180 234
181 p_project['rush_images'] = self.__scanImages("rushData") 235 p_project['rush_images'] = self.__scanImages("rushData")
182 p_project['capture_images'] = self.__scanImages("captureData") 236 p_project['capture_images'] = self.__scanImages("captureData")
183 p_project['chrono_images'] = self.__scanImages("chronoData") 237 p_project['chrono_images'] = self.__scanImages("chronoData")
184 238
185 p_project = self.__check_rush_images(p_project)239 p_project = self.__check_rush_images(p_project)
186 240
187 return p_project241 return (is_valid,p_project)
188242
189243
190 def __scanImages(self,p_type) :244 def __scanImages(self,p_type) :
191245
=== modified file 'luciole.py'
--- luciole.py 2009-12-10 05:12:06 +0000
+++ luciole.py 2010-01-29 07:10:30 +0000
@@ -47,6 +47,8 @@
47 logger = logging.getLogger("luciole")47 logger = logging.getLogger("luciole")
48 if is_verbose == True :48 if is_verbose == True :
49 logger.setLevel(logging.DEBUG)49 logger.setLevel(logging.DEBUG)
50 else :
51 logger.setLevel(logging.INFO)
50 52
51 # create console handler with a higher log level53 # create console handler with a higher log level
52 ch = logging.StreamHandler()54 ch = logging.StreamHandler()

Subscribers

People subscribed via source and target branches

to all changes: