Exemplo n.º 1
0
        /// <summary>
        /// Stops a capture.
        /// </summary>
        /// <exception cref="InvalidOperationException">The control is not capturing a video stream.</exception>
        /// <exception cref="DirectShowException">Failed to stop a video capture graph.</exception>
        public void StopCapture()
        {
            if (!_isCapturing)
            {
                throw new InvalidOperationException();
            }

            Utilities.Stop();
            _isCapturing = false;

            Utilities.ResetCaptureGraph();
            _currentCamera = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stops a capture.
        /// </summary>
        /// <exception cref="InvalidOperationException">The control is not capturing a video stream.</exception>
        /// <exception cref="DirectShowException">Failed to stop a video capture graph.</exception>
        public void StopCapture()
        {
            if (!IsCapturing)
            {
                throw new InvalidOperationException();
            }

            Proxy.Stop();
            IsCapturing = false;

            Proxy.ResetCaptureGraph();
            _currentCamera = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Starts a capture.
        /// </summary>
        /// <param name="camera">The camera to capture from.</param>
        /// <exception cref="ArgumentNullException">A null reference is passed as an argument.</exception>
        /// <exception cref="Win32Exception">Failed to load the DirectShow utilities dll.</exception>
        /// <exception cref="DirectShowException">Failed to run a video capture graph.</exception>
        public void StartCapture(WebCameraId camera)
        {
            if (camera == null)
            {
                throw new ArgumentNullException();
            }

            if (!_captureGraphInitialized)
            {
                InitializeCaptureGraph();

                _captureGraphInitialized = true;
            }

            if (_isCapturing)
            {
                if (_currentCamera == camera)
                {
                    return;
                }

                StopCapture();
            }

            if (_currentCamera != null)
            {
                Utilities.ResetCaptureGraph();
                _currentCamera = null;
            }

            Utilities.AddCaptureFilter(camera.DevicePath);
            _currentCamera = camera;

            try
            {
                Utilities.Start();
                _isCapturing = true;
            }
            catch (DirectShowException)
            {
                Utilities.ResetCaptureGraph();
                _currentCamera = null;
                throw;
            }
        }