Esempio n. 1
0
        private void Camera_NewFrameEvent(object sender, NewCameraFrameEventArgs e)
        {
            CameraConnection camera = sender as CameraConnection;

            if (camera == null)
            {
                return;
            }

            var status = boundCameras[camera.Name];

            lock (status.ReadWriteLock)
            {
                var oldImage = status.LatestImage;

                status.LatestImage = new Bitmap(e.Frame);

                if (oldImage != null)
                {
                    oldImage.Dispose();
                }

                status.ImageTimestamp = DateTime.Now;
            }
        }
Esempio n. 2
0
        public async Task PowerOffAsync()
        {
            var cts = new CancellationTokenSource(4000);

            using var connection = new CameraConnection(IPAddress.Parse("192.168.1.201"), 1259,
                                                        logger: GetLogger <CameraConnection>());
            await connection.SendAsync(ViscaCommands.PowerOff, cts.Token);
        }
 public void Setup()
 {
     _barcodeReader = Substitute.For <IBarcodeReader>();
     _timer         = Substitute.For <ITimer <Timer> >();
     _video         = Substitute.For <IVideoSource>();
     _output        = Substitute.For <IOutput>();
     _uut           = new CameraConnection(_timer, _barcodeReader, _video, _output);
 }
Esempio n. 4
0
        public SnapshotHandler(CameraConnection camera)
        {
            this.camera = camera;

            if (camera.Settings.Properties.EnableSnapshots)
            {
                // bind events
                this.camera.NewFrameEvent += Camera_NewFrameEvent;
            }
        }
Esempio n. 5
0
        public async Task TestInvalidConnectionDefaultTimeoutAsync()
        {
            using var connection = new CameraConnection(IPAddress.Parse("192.168.1.201"), 1259,
                                                        logger: GetLogger <CameraConnection>());
            var timestamp = Stopwatch.GetTimestamp();
            await Assert.ThrowsAsync <TaskCanceledException>(() => connection.SendAsync(ViscaCommands.Home));

            var delaySecs = (double)(Stopwatch.GetTimestamp() - timestamp) / Stopwatch.Frequency;

            Context.WriteLine($"Task cancelled after {delaySecs:F3}s");
            Assert.False(connection.IsConnected);
        }
Esempio n. 6
0
        public CameraConnection AddCamera(CamViewerController controller)
        {
            var form = controller.CreateView <IAddCameraForm>();
            CameraConnection connection = null;

            if (form.Process())
            {
                connection = form.Connection;
                controller.Model.Settings.Connections.Add(connection);
                controller.SaveSettings();
            }

            return(connection);
        }
Esempio n. 7
0
        public async Task Invalid_connection_explicit_timeout_Async()
        {
            const int msTimeout = 100;

            using var connection = new CameraConnection(IPAddress.Parse("127.0.0.1"), 65000,
                                                        logger: GetLogger <CameraConnection>());
            var timestamp = Stopwatch.GetTimestamp();
            var cts       = new CancellationTokenSource(msTimeout);
            await Assert.ThrowsAsync <TaskCanceledException>(() => connection.ConnectAsync(cts.Token));

            var msDelay = (1000D * (Stopwatch.GetTimestamp() - timestamp)) / Stopwatch.Frequency;

            Context.WriteLine($"ConnectAsync returned after {msDelay:F3}ms");
            Assert.True(msDelay >= msTimeout && msDelay < (msTimeout * 1.5D));
            Assert.False(connection.IsConnected);
        }
Esempio n. 8
0
        public CurrentMotion(CameraConnection camera)
        {
            if (idCountDate != DateTime.Today)
            {
                idCount     = 0;
                idCountDate = DateTime.Today;
            }
            idCount++;

            this.MotionID = idCount.ToString().PadLeft(4, '0');

            this.camera  = camera;
            this.entries = new List <CurrentMotionEntry>();

            camera.Log.Info("Motion started, ID {0}", MotionID);
        }
Esempio n. 9
0
        public CameraConnection EditCameraSettings(CamViewerController controller, CameraConnection cameraSettings)
        {
            var form = controller.CreateView <IAddCameraForm>();
            CameraConnection connection = null;

            form.Connection = cameraSettings;
            if (form.Process())
            {
                connection = form.Connection;
                controller.Model.Settings.Connections.Remove(cameraSettings);
                controller.Model.Settings.Connections.Add(connection);
                controller.SaveSettings();
            }

            return(connection);
        }
Esempio n. 10
0
        public void ConnectToCamera(CamViewerController controller, CameraConnection connection)
        {
            controller.DisconnectFromCamera();

            controller.Log.Info("Connecting to {0}", connection.Title);
            controller.Model.MJPEGStream = new MJPEGStream
            {
                Source   = connection.Uri,
                Login    = connection.User,
                Password = connection.Password,
            };
            controller.Model.MJPEGStream.NewFrame +=
                controller.Model.OnNewFrame;
            controller.Model.MJPEGStream.Start();

            controller.Tool.ApplyChange(ViewChanges.SelectCamera, connection);
        }
Esempio n. 11
0
        public MotionHandler(CameraConnection camera)
        {
            this.camera = camera;

            if (camera.Settings.Properties.EnableMotionDetection)
            {
                // create the motion sensor and processing
                detector  = new SimpleBackgroundModelingDetector();
                processor = new BlobCountingObjectsProcessing(20, 20); // minimum size of objects to find

                // create the motion detector
                motionDetector             = new MotionDetector(detector, processor);
                motionDetector.MotionZones = camera.Settings.MotionZones;

                // bind events
                this.camera.NewFrameEvent += Camera_NewFrameEvent;
            }
        }
Esempio n. 12
0
        public async Task TestInquiriesAsync()
        {
            var cts = new CancellationTokenSource(14000);

            using var connection = new CameraConnection(IPAddress.Parse("192.168.1.201"), 1259,
                                                        logger: GetLogger <CameraConnection>());

            await connection.ConnectAsync(cts.Token);

            Assert.True(connection.IsConnected);
            Assert.NotEqual(CameraStatus.Unknown, connection.CurrentStatus);
            Output.WriteLine(connection.CurrentStatus.ToString());

            var zoom = await connection.SendAsync(InquiryCommands.Zoom, cts.Token)
                       .ConfigureAwait(false);

            Context.WriteLine($"Zoom result: {zoom.Result * 100:f2}%");
            Assert.True(connection.IsConnected);
        }
Esempio n. 13
0
 private void DeleteCameraFromUi(CameraConnection camera)
 {
     _camerasListBox.Items.Remove(camera);
 }
Esempio n. 14
0
 public void DeleteCamera(CameraConnection connection)
 {
     new DeleteCameraCmd().DeleteCamera(this, connection);
 }
Esempio n. 15
0
 public void ConnectToCamera(CameraConnection connection)
 {
     new ConnectToCameraCmd().ConnectToCamera(this, connection);
 }
Esempio n. 16
0
 private void AddCameraToUi(CameraConnection camera)
 {
     _camerasListBox.Items.Add(camera);
 }
Esempio n. 17
0
        public void DeleteCamera(CamViewerController controller, CameraConnection connection)
        {
            controller.Model.Settings.Connections.Remove(connection);

            controller.SaveSettings();
        }
Esempio n. 18
0
 public CameraConnection  EditCameraSettings(CameraConnection connection)
 {
     return(new EditCameraSettingsCmd().EditCameraSettings(this, connection));
 }