Exemplo n.º 1
0
        private static async Task VideoWorkerDoWork(
            CameraVideoSettings settings,
            Action <byte[]> onDataCallback,
            Action onExitCallback)
        {
            try
            {
                await ProcessRunner.RunProcessAsync(
                    settings.CommandName,
                    settings.CreateProcessArguments(),
                    (data, proc) => onDataCallback?.Invoke(data),
                    null,
                    true,
                    _videoTokenSource.Token);

                onExitCallback?.Invoke();
            }
            catch
            {
                // swallow
            }
            finally
            {
                Instance.CloseVideoStream();
                OperationDone.Set();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens the video stream with a timeout of 0 (running indefinitely) at 1080p resolution, variable bitrate and 25 FPS.
        /// No preview is shown
        /// </summary>
        /// <param name="onDataCallback">The on data callback.</param>
        /// <param name="onExitCallback">The on exit callback.</param>
        public void OpenVideoStream(Action <byte[]> onDataCallback, Action onExitCallback = null)
        {
            var settings = new CameraVideoSettings
            {
                CaptureTimeoutMilliseconds = 0,
                CaptureDisplayPreview      = false,
                CaptureWidth  = 1920,
                CaptureHeight = 1080
            };

            OpenVideoStream(settings, onDataCallback, onExitCallback);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Opens the video stream with the supplied settings. Capture Timeout Milliseconds has to be 0 or greater
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="onDataCallback">The on data callback.</param>
        /// <param name="onExitCallback">The on exit callback.</param>
        /// <exception cref="InvalidOperationException">Cannot use camera module because it is currently busy.</exception>
        /// <exception cref="ArgumentException">CaptureTimeoutMilliseconds</exception>
        public void OpenVideoStream(CameraVideoSettings settings, Action <byte[]> onDataCallback, Action onExitCallback)
        {
            if (Instance.IsBusy)
            {
                throw new InvalidOperationException("Cannot use camera module because it is currently busy.");
            }

            if (settings.CaptureTimeoutMilliseconds < 0)
            {
                throw new ArgumentException($"{nameof(settings.CaptureTimeoutMilliseconds)} needs to be greater than or equal to 0");
            }

            try
            {
                OperationDone.Reset();
                _videoStreamTask = Task.Factory.StartNew(() => VideoWorkerDoWork(settings, onDataCallback, onExitCallback), _videoTokenSource.Token);
            }
            catch
            {
                OperationDone.Set();
                throw;
            }
        }