Exemplo n.º 1
0
        /// <summary>Gets the next available body frame.</summary>
        /// <param name="bodyFrame">
        /// If successful this contains object with body data (don't forget to free this object by calling <see cref="BodyFrame.Dispose"/>),
        /// otherwise - <see langword="null"/>.
        /// </param>
        /// <param name="timeout">
        /// Specifies the time the function should block waiting for the body frame.
        /// Default value is <see cref="Timeout.NoWait"/>, which means checking of the status without blocking.
        /// Passing <see cref="Timeout.Infinite"/> will block indefinitely until the body frame becomes available.
        /// </param>
        /// <returns>
        /// <see langword="true"/> - if a body frame is returned,
        /// <see langword="false"/> - if a body frame is not available before the timeout elapses.
        /// </returns>
        /// <exception cref="ObjectDisposedException">Object was disposed before this call or has been disposed during this call.</exception>
        /// <exception cref="BodyTrackingException">Cannot get body frame for some unknown reason. See logs for details.</exception>
        /// <seealso cref="PopResult"/>
        public bool TryPopResult([NotNullWhen(returnValue: true)] out BodyFrame?bodyFrame, Timeout timeout = default)
        {
            if (isDisposed)
            {
                throw new ObjectDisposedException(nameof(Tracker));
            }

            var res = NativeApi.TrackerPopResult(handle.ValueNotDisposed, out var bodyFrameHandle, timeout);

            if (res == NativeCallResults.WaitResult.Timeout)
            {
                bodyFrame = null;
                return(false);
            }
            if (res == NativeCallResults.WaitResult.Failed)
            {
                // to throw ObjectDisposedException() if failure is a result of disposing
                if (isDisposed)
                {
                    throw new ObjectDisposedException(nameof(Tracker));
                }
                handle.CheckNotDisposed();

                throw new BodyTrackingException("Cannot extract tracking result from body tracking pipeline. See logs for details.");
            }

            Interlocked.Decrement(ref queueSize);
            QueueSizeDecreased?.Invoke(this, EventArgs.Empty);

            bodyFrame = BodyFrame.Create(bodyFrameHandle);
            return(bodyFrame != null);
        }
Exemplo n.º 2
0
        public bool TryPopResult(out BodyFrame bodyFrame, Timeout timeout = default(Timeout))
        {
            var res = NativeApi.TrackerPopResult(handle.ValueNotDisposed, out var bodyFrameHandle, timeout);
            if (res == NativeCallResults.WaitResult.Timeout)
            {
                bodyFrame = null;
                return false;
            }
            if (res == NativeCallResults.WaitResult.Failed)
            {
                handle.CheckNotDisposed();      // to throw ObjectDisposedException() if failure is a result of disposing
                throw new BodyTrackingException("Cannot extract tracking result from body tracking pipeline");
            }

            Interlocked.Decrement(ref queueSize);
            QueueSizeDecreased?.Invoke(this, EventArgs.Empty);

            bodyFrame = BodyFrame.Create(bodyFrameHandle);
            return bodyFrame != null;
        }