private void ColorReader_FrameArrived(object sender, ColorFrameArrivedEventArgs e) { var colorPacket = new ColorFramePacket(e.Bitmap, e.CameraIntrinsics, _sensor.GetCoordinateMapper().ColorToDepth); SendFrameData(colorPacket); }
protected override void ProcessReceivedData(ReadBuffer receiveBuffer) { var opCode = (OperationCode)receiveBuffer.ReadInt32(); // TODO: validate operation type when processing //var operationType = (OperationStatus)_dataReader.ReadInt32(); switch (opCode) { // process responses case OperationCode.OpenReader: { // find first unprocessed request var openResponse = new OpenReader(); openResponse.ReadCommand(receiveBuffer); HandleCommandResponse(openResponse); break; } case OperationCode.CloseReader: { var closeResponse = new CloseReader(); closeResponse.ReadCommand(receiveBuffer); HandleCommandResponse(closeResponse); break; } case OperationCode.BodyFrameTransfer: { FramePacket activeReceive; if (_activeFrameReceives.TryGetValue(ReaderType.Body, out activeReceive)) { // todo: verify that operation status is not push init } else { activeReceive = new BodyFramePacket(); _activeFrameReceives[ReaderType.Body] = activeReceive; } var finishedReading = activeReceive.ReadData(receiveBuffer); if (finishedReading) { _activeFrameReceives.Remove(ReaderType.Body); var subs = BodyFrameArrived; if (subs != null) { Task.Run(() => subs(this, (BodyFramePacket)activeReceive)); } } break; } case OperationCode.DepthFrameTransfer: { FramePacket activeReceive; if (_activeFrameReceives.TryGetValue(ReaderType.Depth, out activeReceive)) { // todo: verify that operation status is not push init } else { activeReceive = new DepthFramePacket(); _activeFrameReceives[ReaderType.Depth] = activeReceive; } var finishedReading = activeReceive.ReadData(receiveBuffer); if (finishedReading) { _activeFrameReceives.Remove(ReaderType.Depth); var subs = DepthFrameArrived; if (subs != null) { Task.Run(() => subs(this, (DepthFramePacket)activeReceive)); } } break; } case OperationCode.BodyIndexFrameTransfer: { FramePacket activeReceive; if (_activeFrameReceives.TryGetValue(ReaderType.BodyIndex, out activeReceive)) { // todo: verify that operation status is not push init } else { activeReceive = new BodyIndexFramePacket(); _activeFrameReceives[ReaderType.BodyIndex] = activeReceive; } var finishedReading = activeReceive.ReadData(receiveBuffer); if (finishedReading) { _activeFrameReceives.Remove(ReaderType.BodyIndex); var subs = BodyIndexFrameArrived; if (subs != null) { Task.Run(() => subs(this, (BodyIndexFramePacket)activeReceive)); } } break; } case OperationCode.ColorFrameTransfer: { FramePacket activeReceive; if (_activeFrameReceives.TryGetValue(ReaderType.Color, out activeReceive)) { // todo: verify that operation status is not push init } else { activeReceive = new ColorFramePacket(); _activeFrameReceives[ReaderType.Color] = activeReceive; } var finishedReading = activeReceive.ReadData(receiveBuffer); if (finishedReading) { _activeFrameReceives.Remove(ReaderType.Color); var subs = ColorFrameArrived; if (subs != null) { Task.Run(() => subs(this, (ColorFramePacket)activeReceive)); } } break; } case OperationCode.UserFrameTransfer: { FramePacket activeReceive; if (_activeFrameReceives.TryGetValue(ReaderType.UserDefined, out activeReceive)) { // todo: verify that operation status is not push init } else { activeReceive = new CustomFramePacket(); _activeFrameReceives[ReaderType.UserDefined] = activeReceive; } var finishedReading = activeReceive.ReadData(receiveBuffer); if (finishedReading) { _activeFrameReceives.Remove(ReaderType.UserDefined); OnCustomDataReceived((CustomFramePacket)activeReceive); } break; } } }