Exemple #1
0
        private Image RequestImages(ImageData imageData)
        {
            if (!_isRunning)
            {
                return(Image.Invalid);
            }

            LEAP_IMAGE_FRAME_DESCRIPTION imageSpecifier = new LEAP_IMAGE_FRAME_DESCRIPTION();

            imageSpecifier.frame_id   = imageData.frame_id;
            imageSpecifier.type       = imageData.type;
            imageSpecifier.pBuffer    = imageData.getPinnedHandle();
            imageSpecifier.buffer_len = (ulong)imageData.pixelBuffer.LongLength;
            LEAP_IMAGE_FRAME_REQUEST_TOKEN token;
            eLeapRS result = eLeapRS.eLeapRS_UnknownError;

            result = LeapC.RequestImages(_leapConnection, ref imageSpecifier, out token);

            if (result == eLeapRS.eLeapRS_Success)
            {
                imageData.isComplete = false;
                imageData.index      = token.requestID;
                Image futureImage = new Image(imageData);
                _pendingImageRequestList.Add(new ImageFuture(futureImage, imageData, LeapC.GetNow(), token));
                return(futureImage);
            }
            else
            {
                imageData.unPinHandle();
                reportAbnormalResults("LeapC Image Request call was ", result);
                return(Image.Invalid);
            }
        }
 private eLeapRS _lastResult; //Used to avoid repeating the same log message, ie. for events like time out
 private void reportAbnormalResults(string context, eLeapRS result) {
   if (result != eLeapRS.eLeapRS_Success &&
      result != _lastResult) {
     string msg = context + " " + result;
     if (LeapLogEvent != null) {
       LeapLogEvent.DispatchOnContext(this, EventContext,
         new LogEventArgs(MessageSeverity.MESSAGE_CRITICAL,
             LeapC.GetNow(),
             msg));
     }
   }
   _lastResult = result;
 }
        public int purgeOld(IntPtr connection)
        {
            Int64 now        = LeapC.GetNow();
            int   purgeCount = 0;

            lock (_locker){
                for (int i = _pending.Count - 1; i >= 0; i--)
                {
                    ImageFuture ir = _pending[i];
                    if ((now - ir.Timestamp) > pendingTimeLimit)
                    {
                        _pending.RemoveAt(i);
                        LeapC.CancelImageFrameRequest(connection, ir.Token);
                        purgeCount++;
                    }
                }
            }
            return(purgeCount);
        }
Exemple #4
0
 /**
  * Returns a timestamp value as close as possible to the current time.
  * Values are in microseconds, as with all the other timestamp values.
  *
  * @since 2.2.7
  *
  */
 public long Now()
 {
     return(LeapC.GetNow());
 }
Exemple #5
0
        private void handleFailedImageRequest(ref LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT failed_image_evt)
        {
            ImageReference pendingImage = null;

            lock (lockPendingImageList)
            {
                _pendingImageRequests.TryGetValue(failed_image_evt.token.requestID, out pendingImage);
            }

            if (pendingImage != null)
            {
                pendingImage.imageData.CheckIn();
                lock (_pendingImageRequests)
                {
                    _pendingImageRequests.Remove(failed_image_evt.token.requestID);
                }

                ImageRequestFailedEventArgs errorEventArgs = new ImageRequestFailedEventArgs(failed_image_evt.description.frame_id, pendingImage.imageObject.Type);
                switch (failed_image_evt.error)
                {
                case eLeapImageRequestError.eLeapImageRequestError_InsufficientBuffer:
                    errorEventArgs.message = "The buffer specified for the request was too small.";
                    errorEventArgs.reason  = Image.RequestFailureReason.Insufficient_Buffer;
                    if (failed_image_evt.description.type == eLeapImageType.eLeapImageType_Default && _standardImageBufferSize < failed_image_evt.required_buffer_len)
                    {
                        _standardImageBufferSize = failed_image_evt.required_buffer_len;
                    }
                    else if (failed_image_evt.description.type == eLeapImageType.eLeapImageType_Raw && _standardRawBufferSize < failed_image_evt.required_buffer_len)
                    {
                        _standardRawBufferSize = failed_image_evt.required_buffer_len;
                    }
                    break;

                case eLeapImageRequestError.eLeapImageRequestError_Unavailable:
                    errorEventArgs.message = "The image was request too late and is no longer available.";
                    errorEventArgs.reason  = Image.RequestFailureReason.Image_Unavailable;
                    break;

                case eLeapImageRequestError.eLeapImageRequestError_ImagesDisabled:
                    errorEventArgs.message = "Images are disabled by the current configuration settings.";
                    errorEventArgs.reason  = Image.RequestFailureReason.Images_Disabled;
                    break;

                default:
                    errorEventArgs.message = "The image request failed for an undetermined reason.";
                    errorEventArgs.reason  = Image.RequestFailureReason.Unknown_Error;
                    break;
                }
                errorEventArgs.requiredBufferSize = (long)failed_image_evt.required_buffer_len;

                this.LeapImageRequestFailed.Dispatch <ImageRequestFailedEventArgs>(this, errorEventArgs);
            }
            //Purge old requests
            List <UInt32>  keys = new List <UInt32>(_pendingImageRequests.Keys);
            ImageReference request;
            long           now = LeapC.GetNow();

            for (int k = 0; k < keys.Count; k++)
            {
                request = _pendingImageRequests[keys[k]];
                if ((now - request.Timestamp) > 90000)
                {
                    lock (_pendingImageRequests)
                    {
                        _pendingImageRequests.Remove(keys[k]);
                    }
                    request.imageData.CheckIn();
                }
            }
        }