Beispiel #1
0
 private void StopSource(CS.VideoSources.Core.IVideoSource processedSource)
 {
     this._logger.InfoFormat("Stopping source {0} with connection string {1}", (object)processedSource.GetType(), (object)processedSource.ConnectionString);
     processedSource.SignalToStop();
     processedSource.WaitToStop();
     processedSource.VideoSourceError -= new CS.VideoSources.Core.VideoSourceErrorEventHandler(this.HandleVideoSourceError);
     this._logger.InfoFormat("Source {0} with connection string {1} stopped successfully", (object)processedSource.GetType(), (object)processedSource.ConnectionString);
 }
Beispiel #2
0
 private void HandleVideoSourceError(object sender, Exception exception, string additionalErrorMessage)
 {
     CS.VideoSources.Core.IVideoSource videoSource = (CS.VideoSources.Core.IVideoSource)sender;
     this._logger.ErrorFormat("Error in videosource. Sender: {0}. Error: {1}, stack: {2}", sender, (object)exception, (object)exception.StackTrace);
     try
     {
         if (!videoSource.IsRunning)
         {
             return;
         }
         this._logger.InfoFormat("Try to restart source {0}", (object)videoSource.ConnectionString);
         videoSource.Start();
     }
     catch (Exception ex)
     {
         this._logger.Error((object)"Error restarting source", ex);
     }
 }
Beispiel #3
0
        public void TryAddOrUpdateVideoSource(BcDevices device)
        {
            this.TryToRemoveVideoSource(device.Id);
            string connectionString = VideoServer.GetDeviceConnectionString(device);
            IReadOnlyDictionary <string, string> deviceOptions = VideoServer.GetDeviceOptions(device);

            CS.VideoSources.Core.IVideoSource videoSource = VideoServer.CreateVideoSource(device.Type, connectionString, device.Login, device.Password, deviceOptions);
            if (videoSource != null)
            {
                this.VideoSources.Add(device.Id, videoSource);
                videoSource.VideoSourceError += new CS.VideoSources.Core.VideoSourceErrorEventHandler(this.HandleVideoSourceError);
            }
            if (videoSource != null)
            {
                return;
            }
            this._logger.WarnFormat("Unable to create Video source of type {0} and id {1}", (object)device.Type, (object)device.Id);
        }
Beispiel #4
0
 private void AddOrUpdateVideoSources(IEnumerable <BcDevices> checkDevs)
 {
     foreach (BcDevices device in checkDevs)
     {
         bool   flag             = false;
         string connectionString = VideoServer.GetDeviceConnectionString(device);
         foreach (KeyValuePair <Guid, CS.VideoSources.Core.IVideoSource> keyValuePair in (IEnumerable <KeyValuePair <Guid, CS.VideoSources.Core.IVideoSource> >) this.VideoSources)
         {
             CS.VideoSources.Core.IVideoSource videoSource = keyValuePair.Value;
             if (!(keyValuePair.Key != device.Id))
             {
                 if (!string.Equals(videoSource.ConnectionString, connectionString, StringComparison.InvariantCultureIgnoreCase))
                 {
                     this.TryAddOrUpdateVideoSource(device);
                 }
                 flag = true;
                 break;
             }
         }
         if (!flag)
         {
             this.TryAddOrUpdateVideoSource(device);
         }
         CS.VideoSources.Core.IVideoSource processedSource = this.VideoSources[device.Id];
         if (device.IsActive && !processedSource.IsRunning)
         {
             try
             {
                 this._logger.InfoFormat("Starting source {0} with connection string {1}", (object)processedSource.GetType(), (object)processedSource.ConnectionString);
                 processedSource.Start();
             }
             catch (Exception ex)
             {
                 this._logger.Error((object)"Error starting source", ex);
                 this.TryToRemoveVideoSource(device.Id);
             }
         }
         else if (!device.IsActive && processedSource.IsRunning)
         {
             this.StopSource(processedSource);
         }
     }
 }
Beispiel #5
0
        private static CS.VideoSources.Core.IVideoSource CreateVideoSource(string type, string connectionString, string login, string password, IReadOnlyDictionary <string, string> options)
        {
            CS.VideoSources.Core.IVideoSource videoSource = (CS.VideoSources.Core.IVideoSource)null;
            switch (type)
            {
            case "Basler Aviator Series":
                videoSource = (CS.VideoSources.Core.IVideoSource) new BaslerVideoSource();
                break;

            case "Axis":
            case "Vocord":
            case "Basler":
            case "Arecont":
            case "Panasonic":
            case "HTTP MJPEG":
                videoSource = (CS.VideoSources.Core.IVideoSource) new AForgeVideoSource((Func <AForge.Video.IVideoSource>)(() => (AForge.Video.IVideoSource) new MJPEGStream()
                {
                    Login    = login,
                    Password = password
                }));
                break;

            case "Image":
                videoSource = (CS.VideoSources.Core.IVideoSource) new ImageSource();
                break;

            case "File":
                videoSource = (CS.VideoSources.Core.IVideoSource) new VideoFileSource();
                break;

            case "Web":
                videoSource = (CS.VideoSources.Core.IVideoSource) new AForgeVideoSource((Func <AForge.Video.IVideoSource>)(() => (AForge.Video.IVideoSource) new VideoCaptureDevice()));
                break;
            }
            if (videoSource != null)
            {
                videoSource.ConnectionString = connectionString;
                videoSource.Options          = options;
            }
            return(videoSource);
        }
Beispiel #6
0
 public CommonContracts.VideoFrame GetLastFrameFromDevice(Guid devId, bool deleteFrame)
 {
     try
     {
         this._performanceLogger.Info((object)string.Format("Request DevId = {0}", (object)devId));
         if (!this.VideoSources.ContainsKey(devId))
         {
             return((CommonContracts.VideoFrame)null);
         }
         CS.VideoSources.Core.IVideoSource videoSource = this.VideoSources[devId];
         if (!videoSource.IsRunning)
         {
             return((CommonContracts.VideoFrame)null);
         }
         using (CS.VideoSources.Core.VideoFrame currentFrame = videoSource.GetCurrentFrame(deleteFrame))
         {
             if (currentFrame == null)
             {
                 return((CommonContracts.VideoFrame)null);
             }
             this._performanceLogger.Info((object)string.Format("Response DevId = {0} FrameId = {1}", (object)devId, (object)currentFrame.Index));
             byte[] frameBytes = VideoServer.GetFrameBytes(currentFrame);
             return(new CommonContracts.VideoFrame()
             {
                 Frame = frameBytes,
                 FrameIndex = currentFrame.Index,
                 Date = DateTimeOffset.Now
             });
         }
     }
     catch (Exception ex)
     {
         this._logger.Error((object)ex);
     }
     return((CommonContracts.VideoFrame)null);
 }
Beispiel #7
0
        public void StopServer()
        {
            this._logger.Info((object)"Stopping server");
            List <Task> list = new List <Task>();

            foreach (CS.VideoSources.Core.IVideoSource videoSource in (IEnumerable <CS.VideoSources.Core.IVideoSource>) this.VideoSources.Values)
            {
                CS.VideoSources.Core.IVideoSource source = videoSource;
                list.Add(Task.Factory.StartNew((Action)(() => this.StopAndDisposeSource(source))));
            }
            list.Add(Task.Factory.StartNew((Action)(() =>
            {
                this._logger.Info((object)"Stopping devices check thread");
                this._signalToStop = true;
                if (this._checkDevicesThread != null && this._checkDevicesThread.IsAlive && !this._checkDevicesThread.Join(4500))
                {
                    this._checkDevicesThread.Abort();
                }
                this._logger.Info((object)"Devices check thread stopped successfully");
            })));
            Task.WaitAll(list.ToArray());
            this.VideoSources.Clear();
            this._logger.Info((object)"Server stopped");
        }
Beispiel #8
0
 private void StopAndDisposeSource(CS.VideoSources.Core.IVideoSource source)
 {
     this.StopSource(source);
     source.Dispose();
 }