コード例 #1
0
 public void Add(ImageFuture pendingImage)
 {
     lock (_locker)
     {
         _pending.Add(pendingImage);
     }
 }
コード例 #2
0
        private void handleImageCompletion(ref LEAP_IMAGE_COMPLETE_EVENT imageMsg)
        {
            LEAP_IMAGE_PROPERTIES props;

            StructMarshal <LEAP_IMAGE_PROPERTIES> .PtrToStruct(imageMsg.properties, out props);

            ImageFuture pendingImage = _pendingImageRequestList.FindAndRemove(imageMsg.token);

            if (pendingImage == null)
            {
                return;
            }

            //Update distortion data, if changed
            if ((_currentDistortionData.Version != imageMsg.matrix_version) || !_currentDistortionData.IsValid)
            {
                _currentDistortionData         = new DistortionData();
                _currentDistortionData.Version = imageMsg.matrix_version;
                _currentDistortionData.Width   = LeapC.DistortionSize; //fixed value for now
                _currentDistortionData.Height  = LeapC.DistortionSize; //fixed value for now
                if (_currentDistortionData.Data == null || _currentDistortionData.Data.Length != (2 * _currentDistortionData.Width * _currentDistortionData.Height * 2))
                {
                    _currentDistortionData.Data = new float[(int)(2 * _currentDistortionData.Width * _currentDistortionData.Height * 2)]; //2 float values per map point
                }
                LEAP_DISTORTION_MATRIX matrix;
                StructMarshal <LEAP_DISTORTION_MATRIX> .PtrToStruct(imageMsg.distortionMatrix, out matrix);

                Array.Copy(matrix.matrix_data, _currentDistortionData.Data, matrix.matrix_data.Length);

                if (LeapDistortionChange != null)
                {
                    LeapDistortionChange.DispatchOnContext <DistortionEventArgs>(this, EventContext, new DistortionEventArgs(_currentDistortionData));
                }
            }

            pendingImage.imageData.CompleteImageData(props.type,
                                                     props.format,
                                                     props.bpp,
                                                     props.width,
                                                     props.height,
                                                     imageMsg.info.timestamp,
                                                     imageMsg.info.frame_id,
                                                     props.x_offset,
                                                     props.y_offset,
                                                     props.x_scale,
                                                     props.y_scale,
                                                     _currentDistortionData,
                                                     LeapC.DistortionSize,
                                                     imageMsg.matrix_version);

            Image completedImage = pendingImage.imageObject;

            if (LeapImageReady != null)
            {
                LeapImageReady.DispatchOnContext <ImageEventArgs>(this, EventContext, new ImageEventArgs(completedImage));
            }
        }
コード例 #3
0
        private void handleFailedImageRequest(ref LEAP_IMAGE_FRAME_REQUEST_ERROR_EVENT failed_image_evt)
        {
            if (_leapConnection == IntPtr.Zero)
            {
                return;
            }

            ImageFuture pendingImage = _pendingImageRequestList.FindAndRemove(failed_image_evt.token);

            if (pendingImage != null)
            {
                pendingImage.imageData.CheckIn();

                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);
            }
            _pendingImageRequestList.purgeOld(_leapConnection);
        }
コード例 #4
0
 public ImageFuture FindAndRemove(LEAP_IMAGE_FRAME_REQUEST_TOKEN token)
 {
     lock (_locker){
         for (int i = 0; i < _pending.Count; i++)
         {
             ImageFuture ir = _pending[i];
             if (ir.Token.requestID == token.requestID)
             {
                 _pending.RemoveAt(i);
                 return(ir);
             }
         }
     }
     return(null);
 }
コード例 #5
0
        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);
        }
コード例 #6
0
 public void Add(ImageFuture pendingImage)
 {
   lock(_locker){
     _pending.Add(pendingImage);
   }
 }