예제 #1
0
        private void httpStopButton_Click(object sender, EventArgs e)
        {
            httpStreamer?.Close();
            httpScreenSource?.Close();

            //statisticForm.Close();
        }
예제 #2
0
 private void CloseVideoSource()
 {
     if (_videoSource != null)
     {
         _videoSource.DetachAllMatrices();
         _videoSource.MatrixUpdated -= OnMatrixUpdated;
         _videoSource.Close();
     }
 }
예제 #3
0
        public void Close(bool force = false)
        {
            logger.Debug("HttpScreenStreamer::Close() " + force + " " + State);
            //if (State == MediaState.Closed)
            //{
            //    return;
            //}

            if (state == MediaState.Started || state == MediaState.Starting)
            {
                Stop();
            }

            if (!force)
            {
                if (streamerTask != null)
                {
                    if (streamerTask.Status == TaskStatus.Running)
                    {
                        int  tryCount   = 10;
                        bool waitResult = false;
                        do
                        {
                            waitResult = streamerTask.Wait(1000);
                            if (!waitResult)
                            {
                                logger.Warn("HttpScreenStreamer::Close() " + waitResult);
                                state = MediaState.Stopping;
                            }
                        } while (!waitResult && tryCount-- > 0);

                        if (tryCount == 0)
                        {//FATAL:
                        }
                    }
                }
            }

            if (httpStreamer != null)
            {
                httpStreamer.StreamerStopped -= HttpStreamer_StreamerStopped;
                httpStreamer.Close(force);
            }


            if (httpScreenSource != null)
            {
                httpScreenSource.CaptureStopped -= HttpScreenSource_CaptureStopped;
                httpScreenSource.Close(force);
            }

            state = MediaState.Closed;
        }
        private void SetupVideoSource(VideoStreamSettings settings)
        {
            logger.Debug("SetupVideoSource(...)");

            try
            {
                var captureDescr = settings.CaptureDescription;
                captureDescr.Resolution = videoSettings.EncodingParams.Resolution;

                if (captureDescr.CaptureMode == CaptureMode.CaptDevice)
                {
                    videoSource = new VideoCaptureSource();
                    videoSource.Setup(captureDescr);
                }
                else if (captureDescr.CaptureMode == CaptureMode.Screen)
                {
                    videoSource = new ScreenSource();
                    videoSource.Setup(captureDescr);
                }

                videoSource.CaptureStarted += VideoSource_CaptureStarted;
                videoSource.CaptureStopped += VideoSource_CaptureStopped;
            }
            catch (Exception ex)
            {
                logger.Error(ex);

                if (videoSource != null)
                {
                    videoSource.CaptureStarted -= VideoSource_CaptureStarted;
                    videoSource.CaptureStopped -= VideoSource_CaptureStopped;

                    videoSource.Close();
                    videoSource = null;
                }

                throw;
            }
        }
예제 #5
0
 public void Close()
 {
     if (videoSource != null)
     {
         _videoSource.Close();
         videoSource = null;
     }
     // dispose old frame
     if (lastFrame != null)
     {
         lastFrame.Dispose();
         lastFrame = null;
     }
 }
예제 #6
0
 public bool CleanupPlayer(string name)
 {
     lock (mVSTable.SyncRoot)
     {
         IVideoSource vs = mVSTable[name] as IVideoSource;
         if (vs != null)
         {
             mVSTable.Remove(name);
             vs.Close();
             vs.Dispose();
             return(true);
         }
     }
     return(false);
 }
예제 #7
0
 public bool CleanupVideoSource(String name)
 {
     lock (mVideoSourstTable.SyncRoot)
     {
         IVideoSource vs = (IVideoSource)mVideoSourstTable[name];
         if (vs != null)
         {
             mVideoSourstTable.Remove(name);
             vs.Close();
             vs.Dispose();
             return(true);
         }
     }
     return(false);
 }
예제 #8
0
        public bool Close(string name)
        {
            lock (mVideoSources.SyncRoot)
            {
                IVideoSource vs = mVideoSources[name] as IVideoSource;
                if (vs != null)
                {
                    if (vs.Close())
                    {
                        mVideoSources.Remove(name);
                        vs.Factory.FreeVideoSource(vs);

                        vs.Dispose();

                        return(true);
                    }
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
예제 #9
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;
                }
            }
        }