/// <summary> /// If we are having a different source of (grayscale) frames provide the frame and pose information, rather than setting up the camera in ARUWPVideo, /// the external class will call this function. /// </summary> unsafe public void OnFrameArrivedExternal(Matrix4x4 cameraPoseMatrix, byte[] grayscaleFrameBytes) { ARUWPUtils.VideoTick(); latestLocatableCameraToWorld = cameraPoseMatrix; grayscaleFrameBytes.CopyTo(frameData, 0); controller.ProcessFrameSync(frameData, latestLocatableCameraToWorld); signalTrackingUpdated = true; }
/// <summary> /// The callback that is triggered when new video preview frame arrives. In this function, /// video frame is saved for Unity UI if videoPreview is enabled, tracking task is triggered /// in this function call, and video FPS is recorded. [internal use] /// </summary> /// <param name="sender">MediaFrameReader object</param> /// <param name="args">arguments not used here</param> unsafe private void OnFrameArrived(MediaFrameReader sender, MediaFrameArrivedEventArgs args) { ARUWPUtils.VideoTick(); using (var frame = sender.TryAcquireLatestFrame()) { if (frame != null) { float[] cameraToWorldMatrixAsFloat = null; if (HL == 1) { if (HL1TryGetCameraToWorldMatrix(frame, out cameraToWorldMatrixAsFloat) == false) { Debug.Log(TAG + ": HL1TryGetCameraToWorldMatrix failed"); return; } } else if (HL == 2) { if (HL2TryGetCameraToWorldMatrix(frame, out cameraToWorldMatrixAsFloat) == false) { Debug.Log(TAG + ": HL2TryGetCameraToWorldMatrix failed"); return; } } latestLocatableCameraToWorld = ConvertFloatArrayToMatrix4x4(cameraToWorldMatrixAsFloat); var originalSoftwareBitmap = frame.VideoMediaFrame.SoftwareBitmap; using (var input = originalSoftwareBitmap.LockBuffer(BitmapBufferAccessMode.Read)) using (var inputReference = input.CreateReference()) { byte *inputBytes; uint inputCapacity; ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputBytes, out inputCapacity); Marshal.Copy((IntPtr)inputBytes, frameData, 0, frameData.Length); } // Process the frame in this thread (still different from Unity thread) controller.ProcessFrameSync(frameData, latestLocatableCameraToWorld); originalSoftwareBitmap?.Dispose(); signalTrackingUpdated = true; } } }
/// <summary> /// The callback that is triggered when new video preview frame arrives. In this function, /// video frame is saved for Unity UI if videoPreview is enabled, tracking task is triggered /// in this function call, and video FPS is recorded. [internal use] /// </summary> /// <param name="sender">MediaFrameReader object</param> /// <param name="args">arguments not used here</param> unsafe private void OnFrameArrived(MediaFrameReader sender, MediaFrameArrivedEventArgs args) { ARUWPUtils.VideoTick(); using (var frame = sender.TryAcquireLatestFrame()) { if (frame != null) { float[] cameraToWorldMatrixAsFloat; if (TryGetCameraToWorldMatrix(frame, out cameraToWorldMatrixAsFloat) == false) { return; } latestLocatableCameraToWorld = ConvertFloatArrayToMatrix4x4(cameraToWorldMatrixAsFloat); var originalSoftwareBitmap = frame.VideoMediaFrame.SoftwareBitmap; using (var input = originalSoftwareBitmap.LockBuffer(BitmapBufferAccessMode.Read)) using (var inputReference = input.CreateReference()) { byte *inputBytes; uint inputCapacity; ((IMemoryBufferByteAccess)inputReference).GetBuffer(out inputBytes, out inputCapacity); Marshal.Copy((IntPtr)inputBytes, frameData, 0, frameData.Length); } // Process the frame in this thread (still different from Unity thread) controller.ProcessFrameSync(frameData, latestLocatableCameraToWorld); if (_requestingSavePicture) { Debug.Log("Saving picture..."); var softwareBitmap = SoftwareBitmap.Convert(originalSoftwareBitmap, BitmapPixelFormat.Rgba8, BitmapAlphaMode.Ignore); SaveRequestedPicture(softwareBitmap); _requestingSavePicture = false; } originalSoftwareBitmap?.Dispose(); signalTrackingUpdated = true; } } }