// %BANNER_BEGIN% // --------------------------------------------------------------------- // %COPYRIGHT_BEGIN% // Copyright (c) 2022-2023 Magic Leap, Inc. All Rights Reserved. // Use of this file is governed by the Magic Leap 2 Software License Agreement, located here: https://www.magicleap.com/software-license-agreement-ml2 // Terms and conditions applicable to third-party materials accompanying this distribution may also be found in the top-level NOTICE file appearing herein. // %COPYRIGHT_END% // --------------------------------------------------------------------- // %BANNER_END% using UnityEngine; using System.IO; using System.IO.Compression; namespace MagicLeap.Spectator { public class MLSpectatorRequest { public ulong id { get; private set; } public Vector3 position { get; private set; } public Quaternion rotation { get; private set; } public Matrix4x4 projectionMatrix { get; private set; } public int msaaLevel { get; private set; } public bool HasDepth { get; private set; } = false; public byte[] DecompressedData { get { lock (dataLock) { return decompressedData; } } } public int Ticks { get; private set; } = 0; private object dataLock = new object(); private byte[] compressedData = null; private byte[] decompressedData = null; public MLSpectatorRequest(int numDepthPixels) { compressedData = new byte[numDepthPixels]; decompressedData = new byte[numDepthPixels]; } public void Load(byte[] payload) { using (MemoryStream stream = new MemoryStream(payload)) { id = StreamHelper.ReadUInt64(stream); position = StreamHelper.ReadVector3(stream); rotation = StreamHelper.ReadQuaternion(stream); projectionMatrix = StreamHelper.ReadMatrix4x4(stream); msaaLevel = StreamHelper.ReadInt32(stream); int compressedLength = StreamHelper.ReadInt32(stream); HasDepth = compressedLength > 0; if (HasDepth) { StreamHelper.ReadBytes(stream, compressedLength, compressedData); using var srcStream = new MemoryStream(compressedData); using var decompressor = new DeflateStream(srcStream, CompressionMode.Decompress); decompressor.Read(decompressedData); } if (stream.Position == stream.Length) return; Ticks = StreamHelper.ReadInt32(stream); } } } }