Merge lp:~bladernr/checkbox/1100594-fix-camera_test-new-gir1.2 into lp:checkbox

Proposed by Jeff Lane 
Status: Merged
Approved by: Brendan Donegan
Approved revision: 2104
Merged at revision: 2101
Proposed branch: lp:~bladernr/checkbox/1100594-fix-camera_test-new-gir1.2
Merge into: lp:checkbox
Diff against target: 279 lines (+79/-47)
3 files modified
debian/changelog (+3/-0)
jobs/camera.txt.in (+0/-1)
scripts/camera_test (+76/-46)
To merge this branch: bzr merge lp:~bladernr/checkbox/1100594-fix-camera_test-new-gir1.2
Reviewer Review Type Date Requested Status
Brendan Donegan (community) Approve
Jeff Lane  Needs Resubmitting
Review via email: mp+162209@code.launchpad.net

Description of the change

fixes camera test by adding bits to determine what version of gst we're using and then set the plugin and video type appropriately for either 0.10 or 1.x. This resolves a problem when fswebcam is not present and we fall back to gst.

Fixed the error handling for the fswebcam call to avoid having nested tracebacks that can be confusing. Now if the call to fswebcam fails, we instead trap the error and run the fallback code outside the exception. If THAT fails, we'll get a less confusing traceback now.

Removed an extraneous line in the requires for one of the camera test jobs (listed gir1.2 twice)

To post a comment you must log in.
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

There seem to be some pep8 errors in your code related to spacing between ',' mainly. I can't remember for certain but I think this may cause Tarmac to reject the submission. Also I'm curious about the comment about fswebcam above - I have fswebcam installed on my system and still get this error. Is there a further problem in the script related to that? Probably best to check it out now.

review: Needs Fixing
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

- package.name == 'gir1.2-gst-plugins-base-0.10' or package.name == 'gir1.2-gst-plugins-base-1.0'

This is a bit wrong in general (not the actual change but stuff really required). Anything that uses gir needs to depend on python3-gi

2099. By Jeff Lane 

"[r=zkrynicki][bug=1103647][author=bladernr] automatic merge by tarmac"

2100. By Brendan Donegan

"[r=zkrynicki][bug=1093718][author=brendan-donegan] automatic merge by tarmac"

2101. By Jeff Lane 

Fixed camera_test to work with both gir1.2-0.10 and gir1.2-1.x

2102. By Jeff Lane 

Removed an exraneous requires line in one of the camera test jobs

2103. By Jeff Lane 

Fixed problems with camera_test in Raring with gir1.2-1.0.6 changes

2104. By Jeff Lane 

Fixed a problem where running camera_test without a test specified resulted in a traceback. A lot of PEP8 fixes

Revision history for this message
Jeff Lane  (bladernr) wrote :

Brendan: fixed my two pep8 errors (spaces) the rest are original to sylvain's code. I've fixed all of those but one because no matter what I tried, I couldn't keep it from generating several more pep8 problems that were seemingly unsolvable. But this one remaining one has been in the test for a long while now so it shouldn't affect things, I hope.

As for fswebcam, it's not specifically the lack of fswebcam, that just brought it to the attention of the guy who reported the bug initially. IIRC, you mentioned the "display" test, which uses gstreamer to create the display window, so I'd expect you would see that bug there.

If this updated script doesn't resolve it on your end, there may be more going on than simply setting the right plugin and video type for gstreamer.

Zygmunt: Yeah, probably so, there are 17 scripts that rely on python3-gi, none of which list it as a requirement. I'm not going to fix those here. That said, however, python3-gi is required for installing checkbox itself, rathter than just a suggests. Then again, so are the gir1.2 packages, so really, neither of those should be required on a test by test basis, you'd think, since they're already required for installing checkbox to begin with.

Anyway, here's a new version with fixes to some problems I didn't catch the first time, and a rash of PEP8 fixes as well.

review: Needs Resubmitting
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

To me it looks fine then. I hope Tarmac doesn't get pissy about the pep8 errors - FYI only files which are modified get checked for errors, so that could be the reason why previous ones were missed, since this file hasn't been touched in a long time.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2013-05-03 10:47:13 +0000
3+++ debian/changelog 2013-05-03 14:34:26 +0000
4@@ -10,6 +10,9 @@
5 than define elements during parsing of /proc/cpuinfo (LP: #1111878)
6 * scripts/lsmod_info: Corrected error handling for the check_output() call to
7 trap the correct error. (LP: #1103647)
8+ * jobs/camera.txt.in: removed an extraneous requres line for gir1.2
9+ scripts/camera_test: added code to determine what version of gst we're
10+ using and set video type and plugin accordingly. (LP: #1100594)
11
12 [ Sylvain Pineau ]
13 * jobs/suspend.txt.in, scripts/gpu_test: Remove the need of running the script
14
15=== modified file 'jobs/camera.txt.in'
16--- jobs/camera.txt.in 2012-11-06 17:11:49 +0000
17+++ jobs/camera.txt.in 2013-05-03 14:34:26 +0000
18@@ -9,7 +9,6 @@
19 name: camera/display
20 depends: camera/detect
21 requires:
22- package.name == 'gir1.2-gst-plugins-base-0.10' or package.name == 'gir1.2-gst-plugins-base-1.0'
23 device.category == 'CAPTURE'
24 command: camera_test display
25 _description:
26
27=== modified file 'scripts/camera_test'
28--- scripts/camera_test 2012-11-01 11:58:46 +0000
29+++ scripts/camera_test 2013-05-03 14:34:26 +0000
30@@ -162,11 +162,13 @@
31 """
32 A simple class that displays a test image via GStreamer.
33 """
34- def __init__(self, args):
35+ def __init__(self, args, gst_plugin=None, gst_video_type=None):
36 self.args = args
37 self._mainloop = GObject.MainLoop()
38 self._width = 640
39 self._height = 480
40+ self._gst_plugin = gst_plugin
41+ self._gst_video_type = gst_video_type
42
43 def detect(self):
44 """
45@@ -186,19 +188,25 @@
46 print(" name : %s" % cp.card.decode('UTF-8'))
47 print(" driver : %s" % cp.driver.decode('UTF-8'))
48 print(" version: %s.%s.%s"
49- % (cp.version >> 16, (cp.version >> 8) & 0xff, cp.version & 0xff))
50+ % (cp.version >> 16,
51+ (cp.version >> 8) & 0xff,
52+ cp.version & 0xff))
53 print(" flags : 0x%x [" % cp.capabilities,
54- ' CAPTURE' if cp.capabilities & V4L2_CAP_VIDEO_CAPTURE else '',
55- ' OVERLAY' if cp.capabilities & V4L2_CAP_VIDEO_OVERLAY else '',
56- ' READWRITE' if cp.capabilities & V4L2_CAP_READWRITE else '',
57- ' STREAMING' if cp.capabilities & V4L2_CAP_STREAMING else '',
58- ' ]', sep="")
59+ ' CAPTURE' if cp.capabilities & V4L2_CAP_VIDEO_CAPTURE
60+ else '',
61+ ' OVERLAY' if cp.capabilities & V4L2_CAP_VIDEO_OVERLAY
62+ else '',
63+ ' READWRITE' if cp.capabilities & V4L2_CAP_READWRITE
64+ else '',
65+ ' STREAMING' if cp.capabilities & V4L2_CAP_STREAMING
66+ else '',
67+ ' ]', sep="")
68
69 resolutions = self._get_supported_resolutions(device)
70 print(' ',
71- self._supported_resolutions_to_string(resolutions).replace(
72- "\n", " "),
73- sep="")
74+ self._supported_resolutions_to_string(resolutions).replace(
75+ "\n", " "),
76+ sep="")
77
78 if cp.capabilities & V4L2_CAP_VIDEO_CAPTURE:
79 cap_status = 0
80@@ -209,10 +217,12 @@
81 Activate camera (switch on led), but don't display any output
82 """
83 pipespec = ("v4l2src device=%(device)s "
84- "! video/x-raw-yuv "
85- "! ffmpegcolorspace "
86+ "! %(type)s "
87+ "! %(plugin)s "
88 "! testsink"
89- % {'device': self.args.device})
90+ % {'device': self.args.device,
91+ 'type': self._gst_video_type,
92+ 'plugin': self._gst_plugin})
93 self._pipeline = Gst.parse_launch(pipespec)
94 self._pipeline.set_state(Gst.State.PLAYING)
95 time.sleep(10)
96@@ -223,12 +233,14 @@
97 Displays the preview window
98 """
99 pipespec = ("v4l2src device=%(device)s "
100- "! video/x-raw-yuv,width=%(width)d,height=%(height)d "
101- "! ffmpegcolorspace "
102+ "! %(type)s,width=%(width)d,height=%(height)d "
103+ "! %(plugin)s "
104 "! autovideosink"
105 % {'device': self.args.device,
106+ 'type': self._gst_video_type,
107 'width': self._width,
108- 'height': self._height})
109+ 'height': self._height,
110+ 'plugin': self._gst_plugin})
111 self._pipeline = Gst.parse_launch(pipespec)
112 self._pipeline.set_state(Gst.State.PLAYING)
113 time.sleep(10)
114@@ -240,11 +252,11 @@
115 """
116 if self.args.filename:
117 self._still_helper(self.args.filename, self._width, self._height,
118- self.args.quiet)
119+ self.args.quiet)
120 else:
121 with NamedTemporaryFile(prefix='camera_test_', suffix='.jpg') as f:
122 self._still_helper(f.name, self._width, self._height,
123- self.args.quiet)
124+ self.args.quiet)
125
126 def _still_helper(self, filename, width, height, quiet, pixelformat=None):
127 """
128@@ -253,25 +265,30 @@
129 user (quiet = True means do not display image).
130 """
131 command = ["fswebcam", "-S 3", "--no-banner",
132- "-d", self.args.device,
133- "-r", "%dx%d"
134- % (width, height), filename]
135+ "-d", self.args.device,
136+ "-r", "%dx%d"
137+ % (width, height), filename]
138+ use_gstreamer = False
139 if pixelformat:
140 command.extend(["-p", pixelformat])
141
142 try:
143 check_call(command, stdout=open(os.devnull, 'w'), stderr=STDOUT)
144 except (CalledProcessError, OSError):
145- pipespec = \
146- ("v4l2src device=%(device)s "
147- "! video/x-raw-yuv,width=%(width)d,height=%(height)d "
148- "! ffmpegcolorspace "
149- "! jpegenc "
150- "! filesink location=%(filename)s"
151- % {'device': self.args.device,
152- 'width': width,
153- 'height': height,
154- 'filename': filename})
155+ use_gstreamer = True
156+
157+ if use_gstreamer:
158+ pipespec = ("v4l2src device=%(device)s "
159+ "! %(type)s,width=%(width)d,height=%(height)d "
160+ "! %(plugin)s "
161+ "! jpegenc "
162+ "! filesink location=%(filename)s"
163+ % {'device': self.args.device,
164+ 'type': self._gst_video_type,
165+ 'width': width,
166+ 'height': height,
167+ 'plugin': self._gst_plugin,
168+ 'filename': filename})
169 self._pipeline = Gst.parse_launch(pipespec)
170 self._pipeline.set_state(Gst.State.PLAYING)
171 time.sleep(3)
172@@ -290,7 +307,7 @@
173 ret = ""
174 for resolution in supported_resolutions:
175 ret += "Format: %s (%s)\n" % (resolution['pixelformat'],
176- resolution['description'])
177+ resolution['description'])
178 ret += "Resolutions: "
179 for res in resolution['resolutions']:
180 ret += "%sx%s," % (res[0], res[1])
181@@ -314,13 +331,13 @@
182 resolution = resolutions[0]
183 if resolution:
184 print("Taking multiple images using the %s format"
185- % resolution['pixelformat'])
186+ % resolution['pixelformat'])
187 for res in resolution['resolutions']:
188 w = res[0]
189 h = res[1]
190 f = NamedTemporaryFile(prefix='camera_test_%s%sx%s' %
191- (resolution['pixelformat'], w, h), suffix='.jpg',
192- delete=False)
193+ (resolution['pixelformat'], w, h),
194+ suffix='.jpg', delete=False)
195 print("Taking a picture at %sx%s" % (w, h))
196 self._still_helper(f.name, w, h, True,
197 pixelformat=resolution['pixelformat'])
198@@ -329,7 +346,7 @@
199 os.remove(f.name)
200 else:
201 print("Failed to validate image %s" % f.name,
202- file=sys.stderr)
203+ file=sys.stderr)
204 os.remove(f.name)
205 return 1
206 return 0
207@@ -354,9 +371,9 @@
208 pixelformat['pixelformat_int'] = fmt.pixelformat
209 pixelformat['pixelformat'] = "%s%s%s%s" % \
210 (chr(fmt.pixelformat & 0xFF),
211- chr((fmt.pixelformat >> 8) & 0xFF),
212- chr((fmt.pixelformat >> 16) & 0xFF),
213- chr((fmt.pixelformat >> 24) & 0xFF))
214+ chr((fmt.pixelformat >> 8) & 0xFF),
215+ chr((fmt.pixelformat >> 16) & 0xFF),
216+ chr((fmt.pixelformat >> 24) & 0xFF))
217 pixelformat['description'] = fmt.description.decode()
218 supported_formats.append(pixelformat)
219 fmt.index = fmt.index + 1
220@@ -404,16 +421,18 @@
221 framesize) == 0:
222 if framesize.type == V4L2_FRMSIZE_TYPE_DISCRETE:
223 resolutions.append([framesize.discrete.width,
224- framesize.discrete.height])
225+ framesize.discrete.height])
226 # for continuous and stepwise, let's just use min and
227 # max they use the same structure and only return
228 # one result
229 elif framesize.type == V4L2_FRMSIZE_TYPE_CONTINUOUS or\
230- framesize.type == V4L2_FRMSIZE_TYPE_STEPWISE:
231+ framesize.type == V4L2_FRMSIZE_TYPE_STEPWISE:
232 resolutions.append([framesize.stepwise.min_width,
233- framesize.stepwise.min_height])
234+ framesize.stepwise.min_height]
235+ )
236 resolutions.append([framesize.stepwise.max_width,
237- framesize.stepwise.max_height])
238+ framesize.stepwise.max_height]
239+ )
240 break
241 framesize.index = framesize.index + 1
242 except IOError as e:
243@@ -455,11 +474,11 @@
244
245 if outw != width:
246 print("Image width does not match, was %s should be %s" %
247- (outw, width), file=sys.stderr)
248+ (outw, width), file=sys.stderr)
249 return False
250 if outh != height:
251 print("Image width does not match, was %s should be %s" %
252- (outh, height), file=sys.stderr)
253+ (outh, height), file=sys.stderr)
254 return False
255
256 return True
257@@ -519,10 +538,21 @@
258 if __name__ == "__main__":
259 args = parse_arguments(sys.argv[1:])
260
261+ if not args.test:
262+ args.test = 'detect'
263+
264 # Import Gst only for the test cases that will need it
265 if args.test in ['display', 'still', 'led', 'resolutions']:
266 from gi.repository import Gst
267+ if Gst.version()[0] > 0:
268+ gst_plugin = 'videoconvert'
269+ gst_video_type = 'video/x-raw'
270+ else:
271+ gst_plugin = 'ffmpegcolorspace'
272+ gst_video_type = 'video/x-raw-yuv'
273 Gst.init(None)
274+ camera = CameraTest(args, gst_plugin, gst_video_type)
275+ else:
276+ camera = CameraTest(args)
277
278- camera = CameraTest(args)
279 sys.exit(getattr(camera, args.test)())

Subscribers

People subscribed via source and target branches