public static List <ViofoGpsPoint> ReadMP4FileGpsInfo(string fileName) { using (MemoryMappedFileReader reader = new MemoryMappedFileReader(fileName)) { List <Box> boxes = new List <Box>(1024); while (reader.Position < reader.Length) { Box x = new Box(reader); if (x.Size > reader.Length) { return(null); //corrupt file } if (x.Kind == "moov") { uint off = 0; while (off < x.Size - 8) { Box g = new Box(x.Data, off); if (g.Kind == "gps ") { return(ParseGpsCatalog(g, reader)); //gps catalog - position and size list } off += g.Size; } } } return(null); } }
public ISourceBlock <Pipeline.Telemetry.V0.IGameTelemetry> CreateTelemetrySource() { var mmReader = new MemoryMappedFileReader <Contrib.Data.Shared>(Contrib.Constant.SharedMemoryName); var telemetry = new Telemetry(); return(PollingSource.Create <Pipeline.Telemetry.V0.IGameTelemetry>(_config.PollingInterval, () => telemetry.Transform(mmReader.Read()))); }
public uint Read(byte [] data, uint pos) { Offset = MemoryMappedFileReader.ConvertToUintBE(data, pos); pos += 4; Length = MemoryMappedFileReader.ConvertToUintBE(data, pos); pos += 4; return(pos); }
public void ThrowsExceptionOnReadWhenPathDoesntExist() { using var reader = new MemoryMappedFileReader <TestStruct>(FileName); Assert.Throws <FileNotFoundException>(() => reader.Read()); WithMMFile(FileName, new TestStruct(), (_, _) => { // Verify that file is opened when available reader.Read(); }); }
public Box(byte[] buffer, uint start) { Size = MemoryMappedFileReader.ConvertToUintBE(buffer, start); Kind = Encoding.ASCII.GetString(buffer, (int)start + 4, 4); if (Size > buffer.Length - start) { return; //bad offset or size } Data = new byte[Size - 8]; Array.Copy(buffer, start + 8, Data, 0, Size - 8); }
public Box(MemoryMappedFileReader reader) { const uint maxSize = 1024 * 1024 * 1024; Size = reader.ReadUintBE(); Kind = reader.ReadString(4); if (Size > reader.Length || Size > maxSize) { return; //bad offset or size } Data = reader.ReadBuffer((int)Size - 8); }
public LocationsList(Box gpsCatalog) { uint off = 0; Version = MemoryMappedFileReader.ConvertToUintBE(gpsCatalog.Data, off); off += 4; EncodedDate = MemoryMappedFileReader.ConvertToUintBE(gpsCatalog.Data, off); off += 4; while (off < gpsCatalog.Data.Length) { Location l = new Location(); off = l.Read(gpsCatalog.Data, off); locations.Add(l); } }
public void CanReadAMemoryMappedStruct() { var expectedStruct = new TestStruct() { Field = SequentialByteArray(FieldSize) }; WithMMFile(FileName, expectedStruct, (path, writtenData) => { using (var reader = new MemoryMappedFileReader <TestStruct>(path)) { Assert.Equal(writtenData.Field, reader.Read().Field); // Verify that the same data can be read more than once Assert.Equal(writtenData.Field, reader.Read().Field); } }); }
/// <summary> /// This will parse list of location-size pairs /// And parse each specific location /// </summary> /// <param name="g"></param> /// <param name="file"></param> /// <returns>list of gps points</returns> private static List <ViofoGpsPoint> ParseGpsCatalog(Box g, MemoryMappedFileReader reader) { LocationsList list = new LocationsList(g); List <ViofoGpsPoint> gpsPoints = new List <ViofoGpsPoint>(); foreach (Location loc in list.locations) { if (loc.Offset == 0 || loc.Length == 0) { continue; } reader.Position = loc.Offset; ViofoGpsPoint i = ViofoGpsPoint.Parse(reader, loc.Length); if (i == null) { continue; } gpsPoints.Add(i); } return(gpsPoints); }