Example #1
0
        public override IVideoSource CreateVideoSource(IVideoSourceConfig config, IntPtr hWnd)
        {
            try
            {
                IVideoDevice device = GetVideoDevice(config.IP, config.Port, config.UserName, config.Password, false);
                if (device != null)
                {
                    IVideoSource vs = device.GetPlayer(config.Name);
                    if (vs == null)
                    {
                        vs = device.InitRealPlayer(config, hWnd);
                    }
                    return(vs);
                }
                return(null);
            }
            catch (Exception e)
            {
                IConfig pc = config.GetValue("LinkConfig") as IConfig;
                if (pc != null)
                {
                    pc.SetValue("ThrowException", e);
                }

                return(null);
            }
        }
Example #2
0
 public void OpenDevice(IVideoDevice videoDevice)
 {
     //unsubscriber?.Dispose();
     //unsubscriber = videoDevice.Subscribe(this);
     //MsPlayer.StopDecData();
     //MsPlayer.StartInputDecData(0, videoDevice.DeviceBitmapInfoHeader);
 }
Example #3
0
 public CVideoSource(IVideoSourceConfig config, IVideoDevice device, IVideoSourceFactory factory)
     : base()
 {
     mConfig  = config;
     mDevice  = device;
     mFactory = factory;
 }
Example #4
0
 public void SetVideoDevice(IVideoDevice device)
 {
     this._videoDevice = device;
     if (this._width > 0 && this._height > 0)
     {
         this._videoDevice.SetResolution(this, this._width, this._height);
     }
 }
 public bool SetVideoDevice(IVideoDevice videoDevice)
 {
     if (_useVideoDevice == videoDevice)
     {
         return(true);
     }
     _useVideoDevice = videoDevice;
     return(_videoEncoder.SetVideoSource(_useVideoDevice));
 }
Example #6
0
        public CRecordFile(IVideoDevice device)
            : base()
        {
            mVideoDevice = device;

            mTimer.Enabled  = false;
            mTimer.Interval = 1000;
            mTimer.Tick    += new EventHandler(OnTimerTick);
        }
Example #7
0
        public override IVideoSource CreateVideoSource(IVideoSourceConfig config, IntPtr hWnd)
        {
            IVideoDevice device = GetVideoDevice(config.IP, config.Port, config.UserName, config.Password, false);

            if (device != null)
            {
                return(device.InitBackPlayer(config, hWnd));
            }
            return(null);
        }
Example #8
0
 public void OpenDevice(IVideoDevice videoDevice)
 {
     if (_currentVideoDevice != null)
     {
         _currentVideoDevice.PushingData -= _videoDevice_PushData;
     }
     _currentVideoDevice              = videoDevice;
     _currentVideoDevice.PushingData += _videoDevice_PushData;
     PowerMsPlayer.StopDecData();
     PowerMsPlayer.StartInputDecData(0, videoDevice.DeviceBitmapInfoHeader);
 }
Example #9
0
        public void ShouldGetLocalVideoDeviceByDeviceId()
        {
            IVideoDeviceManager videoDeviceManager = Resolve <IVideoDeviceManager>();

            IVideoDevice videoDevice = videoDeviceManager.GetVideoDeviceById(0);

            Assert.IsNotNull(videoDevice);

            Assert.IsTrue(videoDevice.ID == 0);

            videoDeviceManager.Dispose();
        }
Example #10
0
 public bool SetVideoSource(IVideoDevice videoDevice)
 {
     if (!IsStartEncoder)
     {
         CurrentUseVideoDevice = videoDevice;
         return(true);
     }
     StopVideoEncoder();
     CurrentUseVideoDevice = videoDevice;
     StartVideoEncoder();
     return(true);
 }
Example #11
0
            public DeviceWrapper(IDevice dev)
            {
                this.dev = dev;
                Hash     = dev.UID.GetMD5Hash();

                vdev = dev as IVideoDevice;
                if (vdev != null)
                {
                    vdev.OnFrame += frame =>
                    {
                        frame.Freeze();
                        LastFrame = frame;
                    };
                    dev.OnError += error => LastError = error;
                }
                mdev  = dev as IDeviceWithModes;
                sdev  = dev as IDeviceWithSliderModes;
                ptdev = dev as IDeviceWithPanTilt;
            }
Example #12
0
        public virtual IVideoDevice GetVideoDevice(string ip, int port, string username, string password, object extparam)
        {
            string key = BuildKey(ip, port, username);

            lock (mVideoDevices.SyncRoot)
            {
                IVideoDevice device = (IVideoDevice)mVideoDevices[key];
                if (device == null)
                {
                    device = CreateVideoDevice(extparam);
                    if (device != null)
                    {
                        mVideoDevices.Add(key, device);
                    }
                }

                if (device != null && !device.IsLogin)
                {
                    try
                    {
                        if (!device.Login(ip, port, username, password))
                        {
                            mVideoDevices.Remove(key);
                            device.Dispose();
                            device = null;
                        }
                    }
                    catch (Exception e)
                    {
                        mVideoDevices.Remove(key);
                        device.Dispose();
                        device = null;
                        throw e;
                    }
                }

                return(device);
            }
        }
Example #13
0
 public void AddVideo(IVideoDevice device)
 {
     VideoController.attach(device);
 }
Example #14
0
        private void Window_SourceInitialized(object sender, EventArgs e)
        {
            Handle = new WindowInteropHelper(this).Handle;

            btnChangeMode.ContextMenu.Closed += (_, __) =>
            {
                isBlockingClose = false;
            };

            dev.OnError += msg =>
            {
                Video.Dispatcher.Invoke(DispatcherPriority.Input, (ThreadStart)(() =>
                {
                    alerting = true;
                    txtAlert.Text = "Error: " + msg;
                    gAlert.Visibility = Visibility.Visible;
                }));
            };

            var authdev = dev as IDeviceWithAuthentication;

            if (authdev != null)
            {
                authdev.OnCredentialsRequired += user =>
                {
                    DavuxLib2.Controls.CredentialsDialog cd = new DavuxLib2.Controls.CredentialsDialog(dev.Name);
                    cd.Caption  = "Connect to " + dev.Name;
                    cd.Message  = dev.Name + " requires a password.";
                    cd.Name     = user;
                    cd.Password = "";
                    Dispatcher.Invoke(DispatcherPriority.Input, (ThreadStart)(() =>
                    {
                        if (IsEnabled && cd.Show((System.Windows.Forms.IWin32Window) new Win(Handle)) == System.Windows.Forms.DialogResult.Cancel)
                        {
                            IsEnabled = false;
                            Close();
                        }
                    }));
                    return(new KeyValuePair <string, string>(cd.Name, cd.Password));
                };
            }

            // Note: make sure to call this before IVideo.OnStart
            mdev = dev as IDeviceWithModes;
            if (mdev != null)
            {
                PopulateModes();
                btnChangeMode.Visibility = Visibility.Visible;
            }

            ptzdev = dev as IDeviceWithPanTilt;

            if (ptzdev != null && ptzdev.PTSupported)
            {
                PTZ.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                PTZ.Visibility = System.Windows.Visibility.Hidden;
            }

            var smdev = dev as IDeviceWithSliderModes;

            if (smdev != null)
            {
                var sliders = smdev.GetSliderModes();

                foreach (var slider in sliders)
                {
                    var sp = new DockPanel();
                    sp.LastChildFill = true;

                    TextBlock tb = new TextBlock();
                    tb.Padding = new Thickness(4);
                    tb.Text    = slider.Key.Text;
                    DockPanel.SetDock(tb, Dock.Left);
                    sp.Children.Add(tb);

                    Slider sl = new Slider();
                    sl.Tag             = slider.Key;
                    sl.Value           = slider.Value;
                    sl.PreviewMouseUp += (send, _) =>
                    {
                        var s = (send as Slider).Tag as ISlider;
                        (dev as IDeviceWithSliderModes).SetSliderMode(s, (int)(send as Slider).Value);
                    };
                    (dev as IDeviceWithSliderModes).SliderValueChanged += (isli, value) =>
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart)(() =>
                        {
                            foreach (var ch in sp.Children)
                            {
                                // also TextBlock controls
                                var sdr = ch as Slider;
                                if (sdr != null)
                                {
                                    var isdr = sdr.Tag as ISlider;
                                    if (isdr == isli)
                                    {
                                        sdr.Value = value;
                                    }
                                }
                            }
                        }));
                    };
                    sl.Maximum = slider.Key.Max;
                    sl.Minimum = slider.Key.Min;
                    sp.Children.Add(sl);

                    DockPanel p = new DockPanel();
                    p.LastChildFill = true;
                    DockPanel.SetDock(p, Dock.Bottom);
                    p.Children.Add(sp);
                    quality.Children.Insert(0, p);
                }
            }


            vdev = dev as IVideoDevice;
            if (vdev != null)
            {
                vdev.OnFrame += frame =>
                {
                    frame.Freeze();
                    Video.Dispatcher.Invoke(DispatcherPriority.Input, (ThreadStart)(() =>
                    {
                        try
                        {
                            Video.Source = frame;
                            watchdog = 0;
                            pgrLag.Value = 0;

                            frame_count++;
                            if (tick_count == 0)
                            {
                                tick_count = Environment.TickCount;
                            }
                            if (Environment.TickCount - tick_count > 1000)
                            {
                                // calculate fps
                                //Trace.WriteLine(dev.Name + " " + Math.Round((double)frame_count/(double)10,3) + "fps");
                                FPS.Text = frame_count + " fps";
                                alerting = false;
                                gAlert.Visibility = System.Windows.Visibility.Collapsed;

                                tick_count = Environment.TickCount;
                                frame_count = 0;
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine("frame err " + ex);
                        }
                    }));
                };
                new Thread(() =>
                           vdev.StartVideo()).Start();

                StartWatchDog();

                System.Timers.Timer t = new System.Timers.Timer(100);
                t.Elapsed += (sx, ex) =>
                {
                    if (!lockedBar)
                    {
                        lockedBar = true;
                        Video.Dispatcher.Invoke(DispatcherPriority.Input, (ThreadStart)(() =>
                        {
                            try
                            {
                                if (pgrLag.Value + 1 < pgrLag.Maximum)
                                {
                                    pgrLag.Value += 1;
                                }
                            }
                            catch (Exception ex2)
                            {
                                Trace.WriteLine("pgerr " + ex2);
                            }
                            lockedBar = false;
                        }));
                    }
                };
                t.Start();
            }

            var decd = dev as IDeviceWithConfigurationDialog;

            if (decd != null)
            {
                btnConfigure.Visibility = Visibility.Visible;
                btnConfigure.Tag        = decd;
            }

            /*
             *
             *  qdec = decoder as IQualityControllable;
             *  if (qdec != null)
             *  {
             *      quality.Visibility = Visibility.Visible;
             *      qualitySlider.Value = (double)qdec.Quality;
             *      scaleSlider.Value = (double)qdec.Scale;
             *  }
             */
            Title = dev.Name;
            setButtonText();
        }
 public void attach(IVideoDevice device)
 {
     this.Device = device;
 }
Example #16
0
 public VideoDeviceInfo(IVideoDevice videoDevice)
 {
     OwnerVideoDevice = videoDevice;
 }
Example #17
0
 public CHKDVRVideoSource(IVideoSourceConfig config, IVideoDevice device, IVideoSourceFactory factory)
     : base(config, device, factory)
 {
     mPlayDataCallback = new PLAY_DATA_CALLBACK(DoPlayDataCallback);
 }