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(); }
public void Add(CameraAddress addr) { IPCamera camera = null; if (!TryGet(addr, out camera)) { liveCameras.Add(new IPCamera(addr, monitor)); } }
public void Watch(IPCamera camera) { if (!IsUnderWatching(camera)) { lock (syncRoot) { liveCameras.Add(camera); } } }
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; }
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; }
private bool IsUnderWatching(IPCamera camera) { foreach (var cam in liveCameras) { if (cam.Address == camera.Address) { return(true); } } return(false); }
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); }
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; }
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); }
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; }
private bool IsUnderWatching(IPCamera camera) { foreach (var cam in liveCameras) if (cam.Address == camera.Address) return true; return false; }
public void Watch(IPCamera camera) { if (!IsUnderWatching(camera)) { lock (syncRoot) { liveCameras.Add(camera); } } }
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(); }