Esempio n. 1
0
        /// <summary>
        ///   Releases resources and prepares
        ///   the application for closing.
        /// </summary>
        ///
        public void Close()
        {
            // Save last selected audio devices
            Settings.Default.LastAudioDevices.Clear();
            foreach (AudioCaptureDeviceViewModel dev in AudioCaptureDevices)
            {
                if (dev.Checked)
                {
                    Settings.Default.LastAudioDevices.Add(dev.DeviceInfo.Guid.ToString());
                }
            }

            if (videoWriter != null && videoWriter.IsOpen)
            {
                videoWriter.Close();
            }

            if (videoPlayer != null && videoPlayer.IsRunning)
            {
                videoPlayer.SignalToStop();
                videoPlayer.WaitForStop();
            }

            if (audioMixer != null && audioMixer.IsRunning)
            {
                audioMixer.SignalToStop();
                audioMixer.WaitForStop();
            }
        }
Esempio n. 2
0
        private void CloseVideoSource()
        {
            if (!bOpsStopped)
            {
                videoPlayer.SignalToStop();

                if (videoPlayer.IsRunning)
                {
                    videoPlayer.WaitForStop();
                    Thread.Sleep(150);
                    videoPlayer.Stop();
                }

                if (motionDetector != null)
                {
                    motionDetector.Reset();
                }

                bOpsStopped = true;

                this.lblInfotext.Text.ToUpper();
                this.lblInfotext.Text = "You can safely exit the App now.";
                this.lblInfotext.Text.ToLower();
            }
        }
Esempio n. 3
0
 public void StopVideoResource()
 {
     if (_videoSourcePlayer.IsRunning)
     {
         _videoSourcePlayer.SignalToStop();
         _videoSourcePlayer.WaitForStop();
     }
 }
Esempio n. 4
0
 // Close video source if it is running
 private void CloseCurrentVideoSource()
 {
     if (videoSourcePlayer.VideoSource != null)
     {
         videoSourcePlayer.SignalToStop();
         videoSourcePlayer.WaitForStop();
         videoSourcePlayer.VideoSource = null;
     }
 }
Esempio n. 5
0
 public static VideoSourcePlayer play(this VideoSourcePlayer videoPlayer, string aviFile)
 {
     videoPlayer.invokeOnThread(
         () => {
         var videoSource = new FileVideoSource(aviFile);
         videoPlayer.SignalToStop( );
         videoPlayer.WaitForStop( );
         videoPlayer.VideoSource = videoSource;
         videoPlayer.Start( );
     });
     return(videoPlayer);
 }
Esempio n. 6
0
        public void Disconnect()
        {
            StopRecordingVideo();

            _Timer.Stop();

            _VideoSourcePlayer.SignalToStop();
            _VideoSourcePlayer.WaitForStop();
            _VideoSourcePlayer.VideoSource = null;

            _VideoCaptureDevice = null;
        }
Esempio n. 7
0
 // Stop cameras
 public override void StopScanner()
 {
     timer.Stop();
     isScanning = false;
     if (videoSourcePlayerDepth != null)
     {
         videoSourcePlayerDepth.SignalToStop();
         videoSourcePlayerDepth.WaitForStop();
     }
     if (videoSourcePlayerColor != null)
     {
         videoSourcePlayerColor.SignalToStop();
         videoSourcePlayerColor.WaitForStop();
     }
 }
Esempio n. 8
0
        /// <summary>
        /// 关闭摄像头
        /// </summary>
        public void Disconnect()
        {
            if (videoSourcePlayer?.VideoSource != null)
            {
                // stop video device
                videoSourcePlayer.SignalToStop();
                videoSourcePlayer.WaitForStop();
                videoSourcePlayer.VideoSource = null;
            }

            if (videoDevice.ProvideSnapshots)
            {
                videoDevice.SnapshotFrame -= VideoDevice_SnapshotFrame;
            }
        }
        private void CloseVideoSource()
        {
            videoPlayer.SignalToStop();

            if (videoPlayer.IsRunning)
            {
                videoPlayer.WaitForStop();
                Thread.Sleep(150);
                videoPlayer.Stop();

                this.txtBoxInfo.Text = "You can exit Splash now.";
            }

            //if (motionDetector != null)
            //    motionDetector.Reset();
        }
Esempio n. 10
0
 /// <summary>
 /// 关闭摄像头
 /// </summary>
 private void closeCamera()
 {
     videPlayer.SignalToStop();
     videPlayer.WaitForStop();
     tip = "摄像头已经关闭...";
 }
Esempio n. 11
0
    // capture webcam
    static void CaptureWebCam(string devicename, int delay, int resid, int number, int wait, string format, string filename)
    {
        // format
        ImageFormat imageformat;

        if (format.ToLower() == "jpg")
        {
            imageformat = ImageFormat.Jpeg;
        }
        else if (format.ToLower() == "png")
        {
            imageformat = ImageFormat.Png;
        }
        else if (format.ToLower() == "bmp")
        {
            imageformat = ImageFormat.Bmp;
        }
        else
        {
            throw new ApplicationException("wrong format");
        }

        // get video devices
        FilterInfoCollection videoInputDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

        if (videoInputDevices.Count == 0)
        {
            throw new ApplicationException("no cameras");
        }

        // list all devices
        int i = 0;

        foreach (FilterInfo device in videoInputDevices)
        {
            Print("{0,3}: {1}\n", i, device.Name);
            ++i;
        }

        // get deviceid
        int deviceid = 0; // default

        if (devicename != null)
        {
            if (IsNumber(devicename))
            {
                deviceid = ToNumber(devicename);
            }
            else
            {
                bool found = false;
                foreach (FilterInfo device in videoInputDevices)
                {
                    if (device.Name.ToLower().Contains(devicename.ToLower()))
                    {
                        found = true; break;
                    }
                    ++deviceid;
                }
                if (!found)
                {
                    throw new ApplicationException("wrong devicename");
                }
            }
        }
        if (deviceid < 0 || deviceid >= videoInputDevices.Count)
        {
            throw new ApplicationException("wrong deviceid");
        }

        // init capture device
        VideoCaptureDevice videoCaptureDevice = new VideoCaptureDevice(videoInputDevices[deviceid].MonikerString);

        if (videoCaptureDevice.VideoCapabilities.Length == 0)
        {
            throw new ApplicationException("no camera resolutions");
        }

        // list all resolutions
        Print("Camera {0} resolutions\n", deviceid);
        i = 0;
        foreach (VideoCapabilities capabilty in videoCaptureDevice.VideoCapabilities)
        {
            Print("{0,3}: {1} x {2}\n", i, capabilty.FrameSize.Width, capabilty.FrameSize.Height);
            ++i;
        }

        // get max resolutionid
        if (resid == Int32.MinValue)
        {
            i = 0;
            Size max = new Size(0, 0);
            foreach (VideoCapabilities capabilty in videoCaptureDevice.VideoCapabilities)
            {
                if (capabilty.FrameSize.Width > max.Width || (capabilty.FrameSize.Width == max.Width && capabilty.FrameSize.Height > max.Height))
                {
                    resid = i; // default
                    max   = capabilty.FrameSize;
                }
                ++i;
            }
        }
        if (resid < 0 || resid >= videoCaptureDevice.VideoCapabilities.Length)
        {
            throw new ApplicationException("wrong resolutionid");
        }
        videoCaptureDevice.VideoResolution = videoCaptureDevice.VideoCapabilities[resid];

        // init player
        VideoSourcePlayer videoSourcePlayer = new VideoSourcePlayer();

        videoSourcePlayer.VideoSource = videoCaptureDevice;
        videoSourcePlayer.Start();

        // waiting for first capture
        Print("waiting [{0} -d{1} -r{2} -n{3} -w{4} -f{5}] ", deviceid, delay, resid, number, wait, format);
        bool captured = false;

        for (i = 0; i < 25; ++i)
        {
            Print(".");
            Thread.Sleep(delay * 1000); // increase delay if image is black
            if (videoCaptureDevice.IsRunning &&
                videoSourcePlayer.IsRunning &&
                videoSourcePlayer.GetCurrentVideoFrame() != null)
            {
                captured = true;
                break;
            }
        }
        if (!captured)
        {
            Print("\n  capture failed, increase delay");
        }
        Print("\n");

        // captures images
        for (i = 0; i < number; ++i)
        {
            Bitmap bitmap = videoSourcePlayer.GetCurrentVideoFrame();
            if (bitmap == null)
            {
                Print("  capture failed\n");
            }
            else
            {
                string filenamefull;
                if (filename == null)
                {
                    filenamefull = "capcam" + deviceid + "-" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "." + format.ToLower(); // default
                }
                else
                {
                    string pathname  = Path.GetDirectoryName(filename);
                    string basename  = Path.GetFileNameWithoutExtension(filename);
                    string extension = Path.GetExtension(filename);
                    if (basename == "")
                    {
                        basename = "capcam";
                    }
                    if (extension == "")
                    {
                        extension = format.ToLower();
                    }
                    if (extension[0] == '.')
                    {
                        extension = extension.Substring(1);
                    }
                    if (number > 1)
                    {
                        basename += DateTime.Now.ToString("yyyyMMdd-HHmmss");
                    }
                    filenamefull = Path.Combine(pathname, basename) + "." + extension;
                }
                bitmap.Save(filenamefull, imageformat);
                Print("  {0}\n", filenamefull);
            }
            Thread.Sleep(wait * 1000);
        }

        // cleanup
        videoSourcePlayer.SignalToStop();
        videoSourcePlayer.WaitForStop();
        videoSourcePlayer.VideoSource = null;
        videoCaptureDevice.SignalToStop();
        videoCaptureDevice.WaitForStop();
    }
Esempio n. 12
0
 public MainWindowViewModel()
 {
     VPlayer            = new VideoSourcePlayer();
     StartButtonCommand = new RelayCommand(x => OpenVideoSource(MjpegSource));
     StopButtonCommand  = new RelayCommand(x => VPlayer.WaitForStop());
 }
Esempio n. 13
0
 /// <summary>
 /// 关闭摄像头
 /// </summary>
 private void closeCamera()
 {
     videPlayer.SignalToStop();
     videPlayer.WaitForStop();
 }
Esempio n. 14
0
 //关闭摄像头
 private static void StopCamera()
 {
     vid.SignalToStop();
     vid.WaitForStop();
 }