예제 #1
0
    def test_webcam(self):
        if not POSIX or OSX:
            get_util_logger().info("webcam test skipped: %s not supported yet",
                                   sys.platform)
            return
        from xpra.platform.xposix.webcam import get_virtual_video_devices, check_virtual_dir
        if not check_virtual_dir():
            get_util_logger().info(
                "webcam test skipped: no virtual video device directory")
            return
        devices = get_virtual_video_devices()
        if not devices:
            get_util_logger().info(
                "webcam test skipped: no virtual video devices found")
            return
        from xpra.server.source.webcam_mixin import WebcamMixin
        server = AdHocStruct()
        wm = WebcamMixin()
        server.webcam_enabled = True
        server.webcam_device = None
        server.webcam_encodings = ["png", "jpeg"]
        wm.init_from(None, server)
        wm.init_state()
        wm.hello_sent = True
        packets = []

        def send(*args):
            packets.append(args)

        #wm.send = send
        wm.send_async = send
        try:
            assert wm.get_info()
            device_id = 0
            w, h = 640, 480
            assert wm.start_virtual_webcam(device_id, w, h)
            assert wm.get_info().get("webcam", {}).get("active-devices",
                                                       0) == 1
            assert len(packets) == 1  #ack sent
            frame_no = 0
            encoding = "png"
            buf = BytesIOClass()
            from PIL import Image
            image = Image.new('RGB', size=(w, h), color=(155, 0, 0))
            image.save(buf, 'jpeg')
            data = buf.getvalue()
            buf.close()
            wm.process_webcam_frame(device_id, frame_no, encoding, w, h, data)
            assert len(packets) == 2  #ack sent
            wm.stop_virtual_webcam(device_id)
        finally:
            wm.cleanup()
예제 #2
0
 def init_virtual_video_devices(self):
     log("init_virtual_video_devices")
     if not POSIX or OSX:
         return 0
     try:
         from xpra.codecs.v4l2.pusher import Pusher
         assert Pusher
     except ImportError as e:
         log.error("Error: failed to import the virtual video module:")
         log.error(" %s", e)
         return 0
     try:
         from xpra.platform.xposix.webcam import get_virtual_video_devices, check_virtual_dir
     except ImportError as e:
         log.warn("Warning: cannot load webcam components")
         log.warn(" %s", e)
         log.warn(" webcam forwarding disabled")
         return 0
     check_virtual_dir()
     devices = get_virtual_video_devices()
     log.info("found %i virtual video device%s for webcam forwarding", len(devices), engs(devices))
     return len(devices)
예제 #3
0
    def test_webcam(self):
        if not POSIX or OSX:
            return
        from xpra.platform.xposix.webcam import get_virtual_video_devices, check_virtual_dir
        if not check_virtual_dir():
            return
        devices = get_virtual_video_devices()
        if not devices:
            return
        from xpra.server.source.webcam_mixin import WebcamMixin
        wm = WebcamMixin(True, None, ["png", "jpeg"])
        wm.init_state()
        wm.hello_sent = True
        packets = []

        def send(*args):
            packets.append(args)

        #wm.send = send
        wm.send_async = send
        try:
            assert wm.get_info()
            device_id = 0
            w, h = 640, 480
            assert wm.start_virtual_webcam(device_id, w, h)
            assert wm.get_info().get("webcam", {}).get("active-devices",
                                                       0) == 1
            assert len(packets) == 1  #ack sent
            frame_no = 0
            encoding = "png"
            buf = BytesIOClass()
            from PIL import Image
            image = Image.new('RGB', size=(w, h), color=(155, 0, 0))
            image.save(buf, 'jpeg')
            data = buf.getvalue()
            buf.close()
            wm.process_webcam_frame(device_id, frame_no, encoding, w, h, data)
            assert len(packets) == 2  #ack sent
            wm.stop_virtual_webcam(device_id)
        finally:
            wm.cleanup()
예제 #4
0
    def test_webcam(self):
        if not POSIX or OSX:
            get_util_logger().info("webcam test skipped: %s not supported yet",
                                   sys.platform)
            return
        from xpra.platform.xposix.webcam import get_virtual_video_devices, check_virtual_dir
        if not check_virtual_dir():
            get_util_logger().info(
                "webcam test skipped: no virtual video device directory")
            return
        devices = get_virtual_video_devices()
        if not devices:
            get_util_logger().info(
                "webcam test skipped: no virtual video devices found")
            return
        from xpra.server.source.webcam_mixin import WebcamMixin
        self._test_mixin_class(WebcamMixin)
        server = AdHocStruct()
        wm = WebcamMixin()
        server.webcam_enabled = True
        server.webcam_device = None
        server.webcam_encodings = ["png", "jpeg"]
        wm.init_from(None, server)
        wm.init_state()
        wm.hello_sent = True
        packets = []

        def send(*args):
            packets.append(args)

        #wm.send = send
        wm.send_async = send
        try:
            assert wm.get_info()
            device_id = 0
            w, h = 640, 480
            assert wm.start_virtual_webcam(device_id, w, h)
            assert wm.get_info().get("webcam", {}).get("active-devices",
                                                       0) == 1
            assert len(packets) == 1  #ack sent
            assert packets[0][0] == "webcam-ack"
            frame_no = 0
            from PIL import Image
            image = Image.new('RGB', size=(w, h), color=(155, 0, 0))
            buf = BytesIO()
            image.save(buf, "png")
            data = buf.getvalue()
            buf.close()
            assert wm.process_webcam_frame(device_id, frame_no, "png", w, h,
                                           data)
            assert len(packets) == 2  #ack sent
            assert packets[1][0] == "webcam-ack"
            #now send a jpeg as png,
            #which should fail and stop:
            buf = BytesIO()
            image.save(buf, "jpeg")
            data = buf.getvalue()
            buf.close()
            #suspend error logging to avoid the scary message:
            from xpra.server.source.webcam_mixin import log as webcam_log
            elog = webcam_log.error
            try:
                webcam_log.error = webcam_log.debug
                assert not wm.process_webcam_frame(device_id, frame_no, "png",
                                                   w, h, data)
            finally:
                #restore it:
                webcam_log.error = elog
            assert len(packets) == 3
            assert packets[2][0] == "webcam-stop"
        finally:
            wm.cleanup()