204
resolutions = self._supported_resolutions_to_string(
205
self._get_supported_resolutions(device))
206
resolutions = resolutions.replace(
207
"Resolutions:", " Resolutions:")
208
resolutions = resolutions.replace("Format:", " Format:")
205
resolutions = self._get_supported_resolutions(device)
207
self._supported_resolutions_to_string(resolutions).replace(
211
211
if cp.capabilities & V4L2_CAP_VIDEO_CAPTURE:
213
213
return dev_status | cap_status
215
def _on_destroy(self, *args):
218
def _take_photo(self, *args):
219
Cheese.Camera.take_photo(self.camera, self.filename)
223
217
Activate camera (switch on led), but don't display any output
225
Clutter.threads_add_timeout(0, 3000, self._on_destroy, None, None)
226
video_texture = Clutter.Actor()
228
camera = Cheese.Camera.new(
229
video_texture, self.args.device, self._width, self._height)
230
except TypeError: # libcheese < 3.18 still use Clutter.Texture
231
video_texture = Clutter.Texture()
232
camera = Cheese.Camera.new(
233
video_texture, self.args.device, self._width, self._height)
234
Cheese.Camera.setup(camera, None)
235
Cheese.Camera.play(camera)
219
pipespec = ("v4l2src device=%(device)s "
223
% {'device': self.args.device,
224
'type': self._gst_video_type,
225
'plugin': self._gst_plugin})
226
self._pipeline = Gst.parse_launch(pipespec)
227
self._pipeline.set_state(Gst.State.PLAYING)
229
self._pipeline.set_state(Gst.State.NULL)
238
231
def display(self):
240
233
Displays the preview window
242
stage = Clutter.Stage()
243
stage.set_title('Camera test')
244
stage.set_size(self._width, self._height)
245
stage.connect('destroy', self._on_destroy)
246
Clutter.threads_add_timeout(0, 10000, self._on_destroy, None, None)
247
video_texture = Clutter.Actor()
249
camera = Cheese.Camera.new(
250
video_texture, self.args.device, self._width, self._height)
251
except TypeError: # libcheese < 3.18 still use Clutter.Texture
252
video_texture = Clutter.Texture()
253
camera = Cheese.Camera.new(
254
video_texture, self.args.device, self._width, self._height)
255
stage.add_actor(video_texture)
256
Cheese.Camera.setup(camera, None)
257
Cheese.Camera.play(camera)
235
pipespec = ("v4l2src device=%(device)s "
236
"! %(type)s,width=%(width)d,height=%(height)d "
239
% {'device': self.args.device,
240
'type': self._gst_video_type,
241
'width': self._width,
242
'height': self._height,
243
'plugin': self._gst_plugin})
244
self._pipeline = Gst.parse_launch(pipespec)
245
self._pipeline.set_state(Gst.State.PLAYING)
247
self._pipeline.set_state(Gst.State.NULL)
280
268
"-d", self.args.device,
282
270
% (width, height), filename]
271
use_gstreamer = False
285
if 'MJPG' == pixelformat: # special tweak for fswebcam
286
pixelformat = 'MJPEG'
287
273
command.extend(["-p", pixelformat])
290
276
check_call(command, stdout=open(os.devnull, 'w'), stderr=STDOUT)
291
277
except (CalledProcessError, OSError):
295
stage = Clutter.Stage()
296
stage.connect('destroy', self._on_destroy)
297
video_texture = Clutter.Actor()
299
self.camera = Cheese.Camera.new(
300
video_texture, self.args.device, self._width, self._height)
301
except TypeError: # libcheese < 3.18 still use Clutter.Texture
302
video_texture = Clutter.Texture()
303
self.camera = Cheese.Camera.new(
304
video_texture, self.args.device, self._width, self._height)
305
Cheese.Camera.setup(self.camera, None)
306
Cheese.Camera.play(self.camera)
307
self.filename = filename
308
Clutter.threads_add_timeout(0, 3000, self._take_photo , None, None)
309
Clutter.threads_add_timeout(0, 4000, self._on_destroy, None, None)
311
Cheese.Camera.stop(self.camera)
281
pipespec = ("v4l2src device=%(device)s "
282
"! %(type)s,width=%(width)d,height=%(height)d "
285
"! filesink location=%(filename)s"
286
% {'device': self.args.device,
287
'type': self._gst_video_type,
290
'plugin': self._gst_plugin,
291
'filename': filename})
292
self._pipeline = Gst.parse_launch(pipespec)
293
self._pipeline.set_state(Gst.State.PLAYING)
295
self._pipeline.set_state(Gst.State.NULL)
314
stage = Clutter.Stage()
315
stage.set_title('Camera still picture test')
316
stage.set_size(width, height)
317
stage.connect('destroy', self._on_destroy)
318
Clutter.threads_add_timeout(0, 10000, self._on_destroy, None, None)
319
still_texture = Clutter.Texture.new_from_file(filename)
320
stage.add_actor(still_texture)
299
check_call(["timeout", "-k", "11", "10", "eog", filename])
300
except CalledProcessError:
324
303
def _supported_resolutions_to_string(self, supported_resolutions):
516
495
description='Available camera tests')
518
parser.add_argument('--debug', dest='log_level',
519
action="store_const", const=logging.DEBUG,
520
default=logging.INFO, help="Show debugging messages")
522
497
def add_device_parameter(parser):
523
498
group = parser.add_mutually_exclusive_group()
524
499
group.add_argument("-d", "--device", default="/dev/video0",
564
540
if not args.test:
565
541
args.test = 'detect'
567
logging.basicConfig(level=args.log_level)
569
543
# Import Gst only for the test cases that will need it
570
544
if args.test in ['display', 'still', 'led', 'resolutions']:
572
# Workaround to avoid "cluttervideosink missing"
573
# See https://bugzilla.gnome.org/show_bug.cgi?id=721277
574
with contextlib.suppress(FileNotFoundError):
575
gst_registry = '~/.cache/gstreamer-1.0/registry.x86_64.bin'
576
os.remove(os.path.expanduser(gst_registry))
578
gi.require_version('Gst', '1.0')
579
545
from gi.repository import Gst
580
gi.require_version('Cheese', '3.0')
581
from gi.repository import Cheese
582
gi.require_version('Clutter', '1.0')
583
from gi.repository import Clutter
546
if Gst.version()[0] > 0:
547
gst_plugin = 'videoconvert'
548
gst_video_type = 'video/x-raw'
550
gst_plugin = 'ffmpegcolorspace'
551
gst_video_type = 'video/x-raw-yuv'
586
camera = CameraTest(args)
553
camera = CameraTest(args, gst_plugin, gst_video_type)
555
camera = CameraTest(args)
587
557
sys.exit(getattr(camera, args.test)())