private void depthReplay_FrameArrived(ReplayDepthFrame frame) { if (DepthFrameArrived != null) { DepthFrameArrived(this, new ReplayFrameArrivedEventArgs <ReplayDepthFrame> { Frame = frame }); } }
/// <summary> /// Adds a frame to the Frames list. /// </summary> /// <param name="reader">The reader.</param> public void AddFrame(BinaryReader reader) { var frame = ReplayDepthFrame.FromReader(reader); if (frame != null) { this.Frames.Add(frame); } }
/// <summary> /// Records a <c>ReplayDepthFrame</c>. /// </summary> /// <param name="frame">The frame.</param> public async Task RecordAsync(ReplayDepthFrame frame) { await Task.Run(() => { try { // Header _writer.Write((int)frame.FrameType); _writer.Write(frame.RelativeTime.TotalMilliseconds); // Data using (var dataStream = new MemoryStream()) { using (var dataWriter = new BinaryWriter(dataStream)) { dataWriter.Write(frame.DepthMinReliableDistance); dataWriter.Write(frame.DepthMaxReliableDistance); dataWriter.Write(frame.Width); dataWriter.Write(frame.Height); dataWriter.Write(frame.BytesPerPixel); if (_staticBytes == null) { _staticBytes = new byte[frame.FrameData.Length * 2]; } System.Buffer.BlockCopy(frame.FrameData, 0, _staticBytes, 0, _staticBytes.Length); dataWriter.Write(_staticBytes); // Reset frame data stream dataWriter.Flush(); dataStream.Position = 0; // Write FrameSize _writer.Write(dataStream.Length); // Write actual frame data dataStream.CopyTo(_writer.BaseStream); // Write end of frame marker _writer.Write(ReplayFrame.EndOfFrameMarker); } } } catch (Exception ex) { // TODO: Change to log the error System.Diagnostics.Debug.WriteLine(ex); } }); }
/// <summary> /// Records a <c>ReplayDepthFrame</c>. /// </summary> /// <param name="frame">The frame.</param> public async Task RecordAsync(ReplayDepthFrame frame) { await Task.Run(() => { try { // Header _writer.Write((int)frame.FrameType); _writer.Write(frame.RelativeTime.TotalMilliseconds); // Data using (var dataStream = new MemoryStream()) { using (var dataWriter = new BinaryWriter(dataStream)) { dataWriter.Write(frame.DepthMinReliableDistance); dataWriter.Write(frame.DepthMaxReliableDistance); dataWriter.Write(frame.Width); dataWriter.Write(frame.Height); dataWriter.Write(frame.BytesPerPixel); if (_staticBytes == null) _staticBytes = new byte[frame.FrameData.Length * 2]; System.Buffer.BlockCopy(frame.FrameData, 0, _staticBytes, 0, _staticBytes.Length); dataWriter.Write(_staticBytes); // Reset frame data stream dataWriter.Flush(); dataStream.Position = 0; // Write FrameSize _writer.Write(dataStream.Length); // Write actual frame data dataStream.CopyTo(_writer.BaseStream); // Write end of frame marker _writer.Write(ReplayFrame.EndOfFrameMarker); } } } catch (Exception ex) { // TODO: Change to log the error System.Diagnostics.Debug.WriteLine(ex); } }); }
/// <summary> /// Initializes a new instance of the <see cref="ReplayDepthFrame"/> class /// by reading from the specified <c>BinaryReader</c>. /// </summary> /// <param name="reader">The reader.</param> /// <returns>The <c>ReplayDepthFrame</c></returns> /// <exception cref="System.IO.IOException">The recording appears to be corrupt.</exception> internal static ReplayDepthFrame FromReader(BinaryReader reader) { var frame = new ReplayDepthFrame(); frame.FrameType = FrameTypes.Depth; frame.RelativeTime = TimeSpan.FromMilliseconds(reader.ReadDouble()); frame.FrameSize = reader.ReadInt64(); long frameStartPos = reader.BaseStream.Position; frame.DepthMinReliableDistance = reader.ReadUInt32(); frame.DepthMaxReliableDistance = reader.ReadUInt32(); frame.Width = reader.ReadInt32(); frame.Height = reader.ReadInt32(); frame.BytesPerPixel = reader.ReadUInt32(); frame.Stream = reader.BaseStream; frame.StreamPosition = frame.Stream.Position; frame.Stream.Position += frame.Width * frame.Height * frame.BytesPerPixel; // Do Frame Integrity Check if (reader.ReadString() != ReplayFrame.EndOfFrameMarker) { System.Diagnostics.Debug.WriteLine("BAD FRAME...RESETTING"); reader.BaseStream.Position = frameStartPos + frame.FrameSize; if (reader.ReadString() != ReplayFrame.EndOfFrameMarker) { throw new IOException("The recording appears to be corrupt."); } return(null); } return(frame); }
/// <summary> /// Update the Bitmap from the supplied <c>ReplayDepthFrame</c>. /// </summary> public async void Update(ReplayDepthFrame frame) { if (frame != null) { await frame.GetFrameDataAsync().ContinueWith(async (frameData) => { await UpdateAsync(frameData.Result, (ushort)frame.DepthMinReliableDistance, (ushort)frame.DepthMaxReliableDistance); }); } }
/// <summary> /// Initializes a new instance of the <see cref="ReplayDepthFrame"/> class /// by reading from the specified <c>BinaryReader</c>. /// </summary> /// <param name="reader">The reader.</param> /// <returns>The <c>ReplayDepthFrame</c></returns> /// <exception cref="System.IO.IOException">The recording appears to be corrupt.</exception> internal static ReplayDepthFrame FromReader(BinaryReader reader) { var frame = new ReplayDepthFrame(); frame.FrameType = FrameTypes.Depth; frame.RelativeTime = TimeSpan.FromMilliseconds(reader.ReadDouble()); frame.FrameSize = reader.ReadInt64(); long frameStartPos = reader.BaseStream.Position; frame.DepthMinReliableDistance = reader.ReadUInt32(); frame.DepthMaxReliableDistance = reader.ReadUInt32(); frame.Width = reader.ReadInt32(); frame.Height = reader.ReadInt32(); frame.BytesPerPixel = reader.ReadUInt32(); frame.Stream = reader.BaseStream; frame.StreamPosition = frame.Stream.Position; frame.Stream.Position += frame.Width * frame.Height * frame.BytesPerPixel; // Do Frame Integrity Check if (reader.ReadString() != ReplayFrame.EndOfFrameMarker) { System.Diagnostics.Debug.WriteLine("BAD FRAME...RESETTING"); reader.BaseStream.Position = frameStartPos + frame.FrameSize; if (reader.ReadString() != ReplayFrame.EndOfFrameMarker) { throw new IOException("The recording appears to be corrupt."); } return null; } return frame; }
private void depthReplay_FrameArrived(ReplayDepthFrame frame) { if (DepthFrameArrived != null) DepthFrameArrived(this, new ReplayFrameArrivedEventArgs<ReplayDepthFrame> { Frame = frame }); }