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

Proposed by NicoInattendu
Status: Merged
Approved by: NicoInattendu
Approved revision: 83
Merge reported by: NicoInattendu
Merged at revision: not available
Proposed branch: lp:~nico-inattendu/luciole/bug_872053
Merge into: lp:luciole/0.8
Prerequisite: lp:~nico-inattendu/luciole/bug_742343
Diff against target: 177 lines (+81/-35)
1 file modified
lucioLib/lcl_gst/lcl_gst_acq.py (+81/-35)
To merge this branch: bzr merge lp:~nico-inattendu/luciole/bug_872053
Reviewer Review Type Date Requested Status
NicoInattendu Pending
Review via email: mp+78898@code.launchpad.net

Description of the change

Bug fixes :
Bug #872053

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_gst/lcl_gst_acq.py'
2--- lucioLib/lcl_gst/lcl_gst_acq.py 2010-02-03 07:31:45 +0000
3+++ lucioLib/lcl_gst/lcl_gst_acq.py 2011-10-10 23:30:28 +0000
4@@ -4,7 +4,7 @@
5 # vim:si:ai:et:sw=4:sts=4:ts=4
6 #
7 #
8-# Copyright Nicolas Bertrand (nico@inattendu.org), 2009-2010
9+# Copyright Nicolas Bertrand (nico@inattendu.org), 2009-2011
10 #
11 # This file is part of Luciole.
12 #
13@@ -42,20 +42,31 @@
14 """ 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 """
15
16 # Do jpeg encoding with a framerate of 5 images per second used to reduce cpu
17- JPEG_CAPS_FILTER = " video/x-raw-yuv, framerate=5/1 "
18+ JPEG_CAPS_FILTER = " video/x-raw-rgb, framerate=1/1, bpp=24, depth=24"
19+ #JPEG_CAPS_FILTER = " video/x-raw-yuv, framerate=5/1"
20
21- def __init__(self) :
22+ def __init__(self, _cb_capture_done) :
23 """
24 Description of pipeline :
25- sink pad | jpegenc --> fakesink |
26+ sink pad | videorate --> csp --> capsfilter --> fakesink |
27+ Jpeg conversion is done on demand, when a capture is requested,
28+ on the caalback. Jpeg conversion is done only when necessary
29+ from a pixbuf.
30+
31 """
32
33 super(PhotoSaveBin,self).__init__()
34+ self._cb_capture_done = _cb_capture_done
35+ self.capture_handler_id = 0
36 ImageBinElems=[]
37
38- Myvideorate = LG.element_factory_make('videorate') # rate transformation
39+ Myvideorate = LG.element_factory_make('videorate','ImageRate') # rate transformation
40 ImageBinElems.append(Myvideorate)
41-
42+
43+ # csp transformation
44+ csp = LG.element_factory_make('ffmpegcolorspace','ImageCsp')
45+ ImageBinElems.append(csp)
46+
47 MyJpegFilter = LG.element_factory_make("capsfilter", "JpegFilter")
48 # create caps string according, width, height and framerate
49 caps = LG.Caps(self.JPEG_CAPS_FILTER)
50@@ -64,18 +75,62 @@
51 MyJpegFilter.set_property("caps", caps)
52 ImageBinElems.append(MyJpegFilter)
53
54- MyJpegenc = LG.element_factory_make("jpegenc","MyJpegenc") # jpeg encoding
55- ImageBinElems.append(MyJpegenc)
56+ #MyJpegenc = LG.element_factory_make("jpegenc","MyJpegenc") # jpeg encoding
57+ #ImageBinElems.append(MyJpegenc)
58
59- photosink = LG.element_factory_make("fakesink","PhotoSink")
60- ImageBinElems.append(photosink)
61+ self.photosink = LG.element_factory_make("fakesink","PhotoSink")
62+ self.photosink.set_property("signal-handoffs", 'true')
63+ ImageBinElems.append(self.photosink)
64
65 for elem in ImageBinElems : self.add(elem)
66
67- LG.element_link_many(Myvideorate,MyJpegFilter,MyJpegenc,photosink)
68+ LG.element_link_many(Myvideorate, csp, MyJpegFilter, self.photosink)
69
70 self.add_pad(LG.GhostPad('sink', Myvideorate.get_pad('sink')))
71
72+ def capture(self, filename =None ) :
73+ """ capture a frame / data with handoff signals """
74+
75+ if self.capture_handler_id != 0 :
76+ self.warning('Skipping capture request. Capture on progress')
77+ return
78+
79+ self.capture_handler_id = \
80+ self.photosink.connect('handoff', self.process_data_cb, filename )
81+ return
82+
83+ def process_data_cb(self, gbin ,data_buffer, pad, filename ) :
84+ _bits_per_pixel = 8
85+
86+ _caps = data_buffer.get_caps()
87+ _structure = _caps[0]
88+ _width = _structure["width"]
89+ _height = _structure["height"]
90+ # generate pixbuf
91+ self.photosink.disconnect(self.capture_handler_id)
92+ self.capture_handler_id = 0
93+
94+ # save to file
95+ _file = open(filename,'w')
96+ _file.write(data_buffer)
97+ _file.close()
98+
99+ _pixbuf = gtk.gdk.pixbuf_new_from_data(
100+ data_buffer.copy_on_write(),
101+ gtk.gdk.COLORSPACE_RGB,
102+ False,
103+ _bits_per_pixel,
104+ _width,
105+ _height,
106+ data_buffer.size / _height)
107+
108+
109+ # save pixbuf to file
110+ if filename != None :
111+ _pixbuf.save(filename, "jpeg", {"quality":"100"})
112+
113+ self.debug('Write Jpeg on %s'%(filename))
114+ self._cb_capture_done()
115
116 class InputImageBin(LG.Bin):
117 """ Load image to mix with stream"""
118@@ -592,8 +647,8 @@
119 queueFile = LG.element_factory_make("queue","queueFile")
120 ElementList.append(queueFile)
121 #fileSink = SaveCapturedImageBin(self.__CaptureImagePath)
122- fileSink = PhotoSaveBin()
123- ElementList.append(fileSink)
124+ self.fileSink = PhotoSaveBin(self._cb_process_frame)
125+ ElementList.append(self.fileSink)
126
127 #
128 # Display queue
129@@ -617,7 +672,7 @@
130 #link input
131 LG.element_link_many(InputBin,MyTee)
132 # link tee File branch
133- LG.element_link_many(MyTee,queueFile,fileSink)
134+ LG.element_link_many(MyTee,queueFile, self.fileSink)
135 #link tee display Branch
136 LG.element_link_many(MyTee,queueDisplay)
137 if (self.__mix == self.MIX) :
138@@ -633,28 +688,19 @@
139
140 def capture(self) :
141 """ capture is requested :
142- - get jpegnec src pad (output pad of jpege enc)
143- - and add a buffer probe with callback when frame is encoded
144+ capture and JpegConversion are done on PhotoSaveBin
145 """
146- # only one src pad with jpegenc
147- pad = self.pipe.get_by_name("MyJpegenc").src_pads().next()
148- # add the probe
149- self.grabprobe = pad.add_buffer_probe(self._cb_process_frame)
150-
151-
152- def _cb_process_frame(self, pad, buffer):
153- """ Callbak to inidicate that buffer is available from probe """
154- # remove the prove
155- pad.remove_buffer_probe(self.grabprobe)
156-
157- # save to file
158- file = open(self.__CaptureImagePath,'w')
159- file.write(buffer)
160- file.close()
161-
162- # callback to indicate that job is done
163- # the execution here is not in the same thread as gui , so call capture_done with idle add
164- if self._cb_capture_done != None : gobject.idle_add(self._cb_capture_done)
165+
166+ return self.fileSink.capture(self.__CaptureImagePath)
167+
168+
169+ def _cb_process_frame(self):
170+ """ Callback to inidicate capture and jpeg conversions are done"""
171+
172+
173+ if self._cb_capture_done != None :
174+ gobject.idle_add(self._cb_capture_done)
175+
176
177 return True
178

Subscribers

People subscribed via source and target branches

to all changes: