/// <summary> /// 64B + 4B flag /// </summary> protected Matrix4x4?ReadTransformation(ReadBuffer reader) { var hasValue = reader.ReadInt32() == 1; // 4 * 4 * sizeof(float) int readOffset; reader.ReserveForReading(64, out readOffset); if (!hasValue) { return(null); } unsafe { var buffer = reader.GetBuffer(); fixed(byte *bufferPtr = buffer) { Matrix4x4 result; byte * resultMatrixPtr = (byte *)&result; DataManipulation.Copy(bufferPtr + readOffset, resultMatrixPtr, 64); return(result); } } }
public override bool ReadData(ReadBuffer reader) { // TODO; validate status var operationStatus = (OperationStatus)reader.ReadInt32(); var systemTime = reader.ReadInt64(); var dataLenght = reader.ReadInt32(); var bodyData = new byte[dataLenght]; int readOffset; reader.ReserveForReading(dataLenght, out readOffset); unsafe { var buffer = reader.GetBuffer(); fixed(byte *bodyDataPtr = bodyData) fixed(byte *bufferPtr = buffer) { DataManipulation.Copy(bufferPtr + readOffset, bodyDataPtr, (uint)dataLenght); } } BodyFrame = BodyFrame.Parse(bodyData, TimeSpan.FromTicks(systemTime)); return(true); }
protected void StartReceivingData() { _receiveBuffer = new ReadBuffer(ushort.MaxValue); var receiveArgs = new SocketAsyncEventArgs(); receiveArgs.SetBuffer(_receiveBuffer.GetBuffer(), _receiveBuffer.WriteOffset, ushort.MaxValue); receiveArgs.Completed += SocketOperationCompleted; Task.Run(() => ReceiveData(receiveArgs)); }
public override bool ReadData(ReadBuffer reader) { if (Bitmap == null) { // header + CI + transformation mx var status = (OperationStatus)reader.ReadInt32(); var pixelFormat = (BitmapPixelFormat)reader.ReadInt32(); var width = reader.ReadInt32(); var height = reader.ReadInt32(); var bitmapSize = reader.ReadInt32(); Bitmap = new SoftwareBitmap(pixelFormat, width, height, BitmapAlphaMode.Ignore); CameraIntrinsics = ReadCameraIntrinsics(reader); DepthToColorTransform = ReadTransformation(reader); return(false); } var operationStatus = (OperationStatus)reader.ReadInt32(); // check? var offset = reader.ReadInt32(); var dataLength = reader.ReadInt32(); int readOffset; reader.ReserveForReading(dataLength, out readOffset); uint bufferCapacity; using (var buffer = Bitmap.LockBuffer(BitmapBufferAccessMode.Write)) using (var bufferRef = buffer.CreateReference()) { unsafe { byte *targetPtr; ((IMemoryBufferByteAccess)bufferRef).GetBuffer(out targetPtr, out bufferCapacity); targetPtr += _offset; var readBuffer = reader.GetBuffer(); fixed(byte *readBufferPtr = readBuffer) { DataManipulation.Copy(readBufferPtr + readOffset, targetPtr, (uint)dataLength); _offset += dataLength; } } } return(_offset == bufferCapacity); }
public override bool ReadData(ReadBuffer reader) { if (Data == null) { // header var status = (OperationStatus)reader.ReadInt32(); var dataSize = reader.ReadInt32(); Data = new byte[dataSize]; return(false); } var operationStatus = (OperationStatus)reader.ReadInt32(); // check? var offset = reader.ReadInt32(); var dataLength = reader.ReadInt32(); int readOffset; reader.ReserveForReading(dataLength, out readOffset); unsafe { var data = Data; var readBuffer = reader.GetBuffer(); fixed(byte *readBufferPtr = readBuffer) fixed(byte *targetDataPtr = data) { DataManipulation.Copy(readBufferPtr + readOffset, targetDataPtr + _offset, (uint)dataLength); _offset += dataLength; } } return(_offset == Data.Length); }