Exemple #1
0
 public LiveCameraMonitor()
 {
     new Task(() =>
     {
         while (true)
         {
             Thread.Sleep(1500);
             IPCamera[] lives = null;
             lock (syncRoot)
             {
                 lives = new IPCamera[liveCameras.Count];
                 liveCameras.CopyTo(lives, 0);
             }
             foreach (var camera in lives)
             {
                 try
                 {
                     if (!camera.Player.IsPlaying)
                     {
                         camera.Player.Play(new FileInfo(camera.RecordPath));
                     }
                 }
                 catch (Exception) { }
             }
         }
     }, TaskCreationOptions.LongRunning).Start();
 }
Exemple #2
0
        public void Add(CameraAddress addr)
        {
            IPCamera camera = null;

            if (!TryGet(addr, out camera))
            {
                liveCameras.Add(new IPCamera(addr, monitor));
            }
        }
Exemple #3
0
 public void Watch(IPCamera camera)
 {
     if (!IsUnderWatching(camera))
     {
         lock (syncRoot)
         {
             liveCameras.Add(camera);
         }
     }
 }
Exemple #4
0
 public MediaPlayer(IPCamera camera, string fileName, long startPos, int duration)
 {
     InitializeComponent();
     this.camera = camera;
     this.fileName = fileName;
     this.startPos = startPos;
     this.duration = duration;
     this.Controls.Add(camera.Player);
     context = SynchronizationContext.Current;
 }
Exemple #5
0
 public MediaPlayer(IPCamera camera, string fileName, long startPos, int duration)
 {
     InitializeComponent();
     this.camera   = camera;
     this.fileName = fileName;
     this.startPos = startPos;
     this.duration = duration;
     this.Controls.Add(camera.Player);
     context = SynchronizationContext.Current;
 }
Exemple #6
0
 private bool IsUnderWatching(IPCamera camera)
 {
     foreach (var cam in liveCameras)
     {
         if (cam.Address == camera.Address)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #7
0
        public IList <IPCamera> ListCamerasToReplay(string machineAddr, DateTime checkInTime)
        {
            var directoriesToReplay = new List <string>();
            var camerasToReplay     = new List <IPCamera>();
            var directories         = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory + "video");

            foreach (var dir in directories)
            {
                var split = new DirectoryInfo(dir).Name.Split('.');
                if (split.Length == 2)
                {
                    if (split[1].Equals(machineAddr))
                    {
                        directoriesToReplay.Add(dir);
                    }
                }
            }
            foreach (var dir in directoriesToReplay)
            {
                var fileNamesToLong = Directory.GetFiles(dir)
                                      .Where(f => Path.GetExtension(f).Equals(".avi"))
                                      .Select(f => Convert.ToInt64(Path.GetFileNameWithoutExtension(f)))
                                      .OrderBy(d => d)
                                      .ToArray();
                var idx = Array.BinarySearch <long>(fileNamesToLong, TimeUtil.ToTimestamp(checkInTime));
                if (idx >= 0)
                {
                    var camera = new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx]));
                    camerasToReplay.Add(camera);
                    if (!camera.IsRecLongEnoughToPlay(checkInTime))
                    {
                        if (idx != fileNamesToLong.Length - 1)
                        {
                            camerasToReplay.Add(new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx + 1])));
                        }
                    }
                }
                else
                {
                    idx = ~idx;
                    if (idx != 0)
                    {
                        var camera = new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx - 1]));
                        camerasToReplay.Add(camera);
                        if (!camera.IsRecLongEnoughToPlay(checkInTime))
                        {
                            camerasToReplay.Add(new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx])));
                        }
                    }
                }
            }
            return(camerasToReplay);
        }
Exemple #8
0
 public bool TryGet(CameraAddress addr, out IPCamera camera)
 {
     camera = null;
     var exists = false;
     foreach (var cam in liveCameras)
     {
         if (cam.Address == addr)
         {
             camera = cam;
             exists = true;
             break;
         }
     }
     return exists;
 }
Exemple #9
0
        public bool TryGet(CameraAddress addr, out IPCamera camera)
        {
            camera = null;
            var exists = false;

            foreach (var cam in liveCameras)
            {
                if (cam.Address == addr)
                {
                    camera = cam;
                    exists = true;
                    break;
                }
            }
            return(exists);
        }
Exemple #10
0
 public IList<IPCamera> ListCamerasToReplay(string machineAddr, DateTime checkInTime)
 {
     var directoriesToReplay = new List<string>();
     var camerasToReplay = new List<IPCamera>();
     var directories = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory + "video");
     foreach(var dir in directories)
     {
         var split = new DirectoryInfo(dir).Name.Split('.');
         if (split.Length == 2)
         {
             if (split[1].Equals(machineAddr)) directoriesToReplay.Add(dir);
         }
     }
     foreach (var dir in directoriesToReplay)
     {
         var fileNamesToLong = Directory.GetFiles(dir)
             .Where(f => Path.GetExtension(f).Equals(".avi"))
             .Select(f => Convert.ToInt64(Path.GetFileNameWithoutExtension(f)))
             .OrderBy(d => d)
             .ToArray();
         var idx = Array.BinarySearch<long>(fileNamesToLong, TimeUtil.ToTimestamp(checkInTime));
         if (idx >= 0)
         {
             var camera = new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx]));
             camerasToReplay.Add(camera);
             if (!camera.IsRecLongEnoughToPlay(checkInTime))
             {
                 if (idx != fileNamesToLong.Length - 1) camerasToReplay.Add(new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx + 1])));
             }
         }
         else
         {
             idx = ~idx;
             if (idx != 0)
             {
                 var camera = new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx - 1]));
                 camerasToReplay.Add(camera);
                 if (!camera.IsRecLongEnoughToPlay(checkInTime))
                 {
                     camerasToReplay.Add(new IPCamera(string.Format(@"{0}\{1}.avi", dir, fileNamesToLong[idx])));
                 }
             }
         }
     }
     return camerasToReplay;
 }
Exemple #11
0
 private bool IsUnderWatching(IPCamera camera)
 {
     foreach (var cam in liveCameras) if (cam.Address == camera.Address) return true;
     return false;
 }
Exemple #12
0
 public void Watch(IPCamera camera)
 {
     if (!IsUnderWatching(camera))
     {
         lock (syncRoot)
         {
             liveCameras.Add(camera);
         }
     }
 }
Exemple #13
0
 public LiveCameraMonitor()
 {
     new Task(() =>
     {
         while (true)
         {
             Thread.Sleep(1500);
             IPCamera[] lives = null;
             lock (syncRoot)
             {
                 lives = new IPCamera[liveCameras.Count];
                 liveCameras.CopyTo(lives, 0);
             }
             foreach (var camera in lives)
             {
                 try
                 {
                     if (!camera.Player.IsPlaying) camera.Player.Play(new FileInfo(camera.RecordPath));
                 }
                 catch (Exception) { }
             }
         }
     }, TaskCreationOptions.LongRunning).Start();
 }