Example #1
0
        /// <summary>
        /// Creates a new instance of <see cref="UnconstrainedFrameRateGifRecorder"/>.
        /// </summary>
        /// <param name="Encoder">The <see cref="GifWriter"/> to write into.</param>
        /// <param name="ImageProvider">The <see cref="IImageProvider"/> providing the individual frames.</param>
        /// <exception cref="ArgumentNullException"><paramref name="Encoder"/> or <paramref name="ImageProvider"/> is null.</exception>
        public UnconstrainedFrameRateGifRecorder(GifWriter Encoder, IImageProvider ImageProvider)
        {
            if (Encoder == null)
            {
                throw new ArgumentNullException(nameof(Encoder));
            }

            if (ImageProvider == null)
            {
                throw new ArgumentNullException(nameof(ImageProvider));
            }

            // Init Fields
            _imageProvider = ImageProvider;
            _videoEncoder  = Encoder;

            // GifWriter.Init not needed.

            // RecordThread Init
            _recordThread = new Thread(Record)
            {
                Name         = "Captura.Record",
                IsBackground = true
            };


            // Not Actually Started, Waits for _continueCapturing to be Set
            _recordThread?.Start();
        }
Example #2
0
        /// <summary>
        /// Creates a new instance of <see cref="VFRGifRecorder"/>.
        /// </summary>
        /// <param name="Encoder">The <see cref="GifWriter"/> to write into.</param>
        /// <param name="ImageProvider">The <see cref="IImageProvider"/> providing the individual frames.</param>
        /// <exception cref="ArgumentNullException"><paramref name="Encoder"/> or <paramref name="ImageProvider"/> is null.</exception>
        public VFRGifRecorder(GifWriter Encoder, IImageProvider ImageProvider)
        {
            // Init Fields
            _imageProvider = ImageProvider ?? throw new ArgumentNullException(nameof(ImageProvider));
            _videoEncoder  = Encoder ?? throw new ArgumentNullException(nameof(Encoder));

            // Not Actually Started, Waits for _continueCapturing to be Set
            _recordTask = Task.Factory.StartNew(Record);
        }
Example #3
0
        /// <summary>
        /// Override this method with the code to stop recording.
        /// </summary>
        protected override void OnStop()
        {
            // Resume if Paused
            _continueCapturing?.Set();

            // Video
            if (_recordThread != null)
            {
                if (_stopCapturing != null && !_stopCapturing.SafeWaitHandle.IsClosed)
                {
                    _stopCapturing.Set();
                }

                if (!_recordThread.Join(500))
                {
                    _recordThread.Abort();
                }

                _recordThread = null;
            }

            if (_imageProvider != null)
            {
                _imageProvider.Dispose();
                _imageProvider = null;
            }

            // WaitHandles
            if (_stopCapturing != null && !_stopCapturing.SafeWaitHandle.IsClosed)
            {
                _stopCapturing.Dispose();
                _stopCapturing = null;
            }

            if (_continueCapturing != null && !_continueCapturing.SafeWaitHandle.IsClosed)
            {
                _continueCapturing.Dispose();
                _continueCapturing = null;
            }

            // Writers
            if (_videoEncoder == null)
            {
                return;
            }

            _videoEncoder.Dispose();
            _videoEncoder = null;
        }