public void SendColorFrame(MessageComposer.Payload p) { if (!ColorLock.Wait(0)) // if no lock, bail immediately { return; } try { // avoid duplicate frame if (Interlocked.Exchange(ref LatestColorTicks, p.FrameId) != p.FrameId) { var latest_depth = Interlocked.Read(ref LatestDepthTicks); // may be stale! var is_first = ClosestColorFrame == null; var is_closer = is_first || Math.Abs(latest_depth - p.FrameId) < Math.Abs(latest_depth - ClosestColorFrame.Value.FrameId); // update only if no previous Color frame, or if new frame is closer in time to latest depth if (is_closer) { ClosestColorFrame = p; } } } finally { ColorLock.Release(); } }
public void SendDepthFrame(MessageComposer.Payload p) { if (!DepthLock.Wait(0)) // if no lock, bail immediately { return; } try { // avoid duplicate frame if (Interlocked.Exchange(ref LatestDepthTicks, p.FrameId) != p.FrameId) { // update depth frame as frequently as possible LatestDepthFrame = p; } } finally { DepthLock.Release(); } }