public void GetToPreviousWindow()
        {
            _videoSource?.Stop();
            var scanner = new ScanView();

            scanner.Show();
            CloseAction();
        }
예제 #2
0
 // Signal video source to stop
 public void Stop()
 {
     if (CW.IsClone)
     {
         return;
     }
     VideoSource?.Stop();
     _motionRecentlyDetected = false;
 }
예제 #3
0
        public override void PromptDeviceSelector()
        {
            DelegatesPool dp = DelegatesPool.Instance();

            if (dp.DeactivateKeyboardHandler != null)
            {
                dp.DeactivateKeyboardHandler();
            }

            bool reconnected = false;

            // Ask the user which device he wants to use or which size/framerate.
            formDevicePicker fdp = new formDevicePicker(ListDevices(), m_CurrentVideoDevice, DisplayDevicePropertyPage);

            if (fdp.ShowDialog() == DialogResult.OK)
            {
                DeviceDescriptor dev = fdp.SelectedDevice;

                if (dev == null || dev.Empty)
                {
                    log.DebugFormat("Selected device is null or empty.");
                    if (m_CurrentVideoDevice != null)
                    {
                        // From something to empty.
                        Disconnect();
                    }
                }
                else if (dev.Network)
                {
                    if (m_CurrentVideoDevice == null || !m_CurrentVideoDevice.Network)
                    {
                        // From empty or non-network to network.
                        log.DebugFormat("Selected network camera - connect with default parameters");
                        reconnected = ConnectToDevice(dev);
                    }
                    else
                    {
                        // From network to network.
                        log.DebugFormat("Network camera - parameters changed - connect with new parameters");
                        // Parameters were set on the dialog. We don't care if the parameters were actually changed.
                        DeviceDescriptor netDevice = new DeviceDescriptor(ScreenManagerLang.Capture_NetworkCamera, fdp.SelectedUrl, fdp.SelectedFormat);
                        reconnected = ConnectToDevice(netDevice);
                    }
                }
                else
                {
                    if (m_CurrentVideoDevice == null || m_CurrentVideoDevice.Network || dev.Identification != m_CurrentVideoDevice.Identification)
                    {
                        // From network or different capture device to capture device.
                        log.DebugFormat("Selected capture device");
                        reconnected = ConnectToDevice(dev);
                    }
                    else
                    {
                        // From same capture device - caps changed.
                        DeviceCapability cap = fdp.SelectedCapability;
                        if (cap != null && !cap.Equals(m_CurrentVideoDevice.SelectedCapability))
                        {
                            log.DebugFormat("Capture device, capability changed.");

                            m_CurrentVideoDevice.SelectedCapability = cap;
                            m_PrefsManager.UpdateSelectedCapability(m_CurrentVideoDevice.Identification, cap);

                            if (m_bIsGrabbing)
                            {
                                m_VideoSource.Stop();
                            }

                            ((VideoCaptureDevice)m_VideoSource).DesiredFrameSize = cap.FrameSize;
                            ((VideoCaptureDevice)m_VideoSource).DesiredFrameRate = cap.Framerate;

                            m_FrameSize      = cap.FrameSize;
                            m_FramesInterval = 1000 / (double)cap.Framerate;

                            log.Debug(String.Format("New capability: {0}", cap.ToString()));

                            m_bSizeChanged = true;

                            if (m_bIsGrabbing)
                            {
                                m_VideoSource.Start();
                            }
                        }
                    }
                }

                if (reconnected)
                {
                    m_Container.Connected();
                }
            }

            fdp.Dispose();

            if (dp.ActivateKeyboardHandler != null)
            {
                dp.ActivateKeyboardHandler();
            }
        }
예제 #4
0
 /// <summary>
 /// Stop video source.
 /// </summary>
 ///
 /// <remarks><para>Stops nested video source by calling its <see cref="IVideoSource.Stop"/> method.
 /// See documentation of the particular video source for additional details.</para></remarks>
 ///
 public void Stop()
 {
     nestedVideoSource.Stop();
     Free();
 }
예제 #5
0
        private void previewButton_Click(object sender, EventArgs e)
        {
            logger.Debug("previewButton_Click(...)");

            if (VideoSettings == null)
            {
                return;
            }

            try
            {
                var captureDevice = this.VideoSettings.CaptureDevice;

                if (videoSource == null)
                {
                    if (captureDevice.CaptureMode == CaptureMode.UvcDevice)
                    {
                        videoSource = new VideoCaptureSource();
                        videoSource.Setup(captureDevice);
                    }
                    else if (captureDevice.CaptureMode == CaptureMode.Screen)
                    {
                        videoSource = new ScreenSource();
                        videoSource.Setup(captureDevice);
                    }
                    else if (captureDevice.CaptureMode == CaptureMode.AppWindow)
                    {
                        videoSource = new ScreenSource();
                        videoSource.Setup(captureDevice);
                    }

                    videoSource.CaptureStarted += VideoSource_CaptureStarted;
                    videoSource.CaptureStopped += VideoSource_CaptureStopped;

                    videoSource.BufferUpdated += VideoSource_BufferUpdated;
                }


                if (videoSource.State == CaptureState.Capturing)
                {
                    videoSource.Stop();
                }
                else
                {
                    videoSource.Start();
                }

                this.Cursor  = Cursors.WaitCursor;
                this.Enabled = false;
            }
            catch (Exception ex)
            {
                this.Cursor  = Cursors.Default;
                this.Enabled = true;

                MessageBox.Show(ex.Message);

                if (videoSource != null)
                {
                    videoSource.BufferUpdated  -= VideoSource_BufferUpdated;
                    videoSource.CaptureStarted -= VideoSource_CaptureStarted;
                    videoSource.CaptureStopped -= VideoSource_CaptureStopped;
                    videoSource.Close(true);
                    videoSource = null;
                }
            }
        }
예제 #6
0
 // Stop work
 public void Stop()
 {
     videoSource.Stop();
 }
예제 #7
0
        public void Start()
        {
            logger.Debug("HttpScreenStreamer::Start()");

            if (!(state == MediaState.Initialized || state == MediaState.Stopped))
            {
                throw new InvalidOperationException("Invalid state " + State);
            }

            state        = MediaState.Starting;
            streamerTask = Task.Run(() =>
            {
                try
                {
                    httpScreenSource.Start();
                    httpStreamer.Start();

                    state = MediaState.Started;
                    OnStreamerStarted();

                    while (State == MediaState.Started)
                    {
                        if (httpScreenSource.ErrorCode != 0 || httpStreamer.ErrorCode != 0)
                        {//В одном из потоков ошибка - останавливаем стрим
                            logger.Warn("HttpScreenStreamer: Error occurred " + httpScreenSource.ErrorCode + ", " + httpStreamer.ErrorCode);

                            httpScreenSource.Stop();
                            httpStreamer.Stop();

                            errorCode = 100500;
                            break;
                        }

                        syncEvent.WaitOne(500);
                    }


                    while (State == MediaState.Stopping)
                    {// ждем остановки потоков
                        if (httpScreenSource.State == CaptureState.Stopped && httpStreamer.State == MediaState.Stopped)
                        {
                            logger.Debug("HttpScreenStreamer: All thread stopped...");
                            break;
                        }
                        else
                        {//...
                        }

                        syncEvent.WaitOne(500);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                }

                object obj = null;
                if (ErrorCode != 0)
                {
                    obj = ErrorCode;
                }

                state = MediaState.Stopped;
                OnStreamerStopped(obj);
            });
        }
예제 #8
0
 public void GetToPreviousWindow()
 {
     _videoSource.Stop();
     CloseAction();
 }