/// <summary> /// Initializes a new instance of the <see cref="ReplayInfraredFrame"/> class /// from a <c>BinaryReader</c>. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> /// <exception cref="System.IO.IOException">The recording appears to be corrupt.</exception> internal static ReplayInfraredFrame FromReader(BinaryReader reader) { var frame = new ReplayInfraredFrame(); frame.FrameType = FrameTypes.Infrared; frame.RelativeTime = TimeSpan.FromMilliseconds(reader.ReadDouble()); frame.FrameSize = reader.ReadInt64(); long frameStartPos = reader.BaseStream.Position; 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 infraredReplay_FrameArrived(ReplayInfraredFrame frame) { if (InfraredFrameArrived != null) { InfraredFrameArrived(this, new ReplayFrameArrivedEventArgs <ReplayInfraredFrame> { Frame = frame }); } }
/// <summary> /// Adds a frame to the Frames list. /// </summary> /// <param name="reader">The reader.</param> public void AddFrame(BinaryReader reader) { var frame = ReplayInfraredFrame.FromReader(reader); if (frame != null) { this.Frames.Add(frame); } }
/// <summary> /// Records a <c>ReplayInfraredFrame</c>. /// </summary> /// <param name="frame">The frame.</param> public async Task RecordAsync(ReplayInfraredFrame 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.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>ReplayInfraredFrame</c>. /// </summary> /// <param name="frame">The frame.</param> public async Task RecordAsync(ReplayInfraredFrame 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.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> /// Update the Bitmap from the supplied <c>ReplayInfraredFrame</c>. /// </summary> public async void Update(ReplayInfraredFrame frame) { if (frame != null) { await frame.GetFrameDataAsync().ContinueWith(async (frameData) => { await UpdateAsync(frameData.Result); }); } }
/// <summary> /// Initializes a new instance of the <see cref="ReplayInfraredFrame"/> class /// from a <c>BinaryReader</c>. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> /// <exception cref="System.IO.IOException">The recording appears to be corrupt.</exception> internal static ReplayInfraredFrame FromReader(BinaryReader reader) { var frame = new ReplayInfraredFrame(); frame.FrameType = FrameTypes.Infrared; frame.RelativeTime = TimeSpan.FromMilliseconds(reader.ReadDouble()); frame.FrameSize = reader.ReadInt64(); long frameStartPos = reader.BaseStream.Position; 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 infraredReplay_FrameArrived(ReplayInfraredFrame frame) { if (InfraredFrameArrived != null) InfraredFrameArrived(this, new ReplayFrameArrivedEventArgs<ReplayInfraredFrame> { Frame = frame }); }