예제 #1
0
        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);
            }
        }
예제 #2
0
        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())));
        }
예제 #3
0
        public uint Read(byte [] data, uint pos)
        {
            Offset = MemoryMappedFileReader.ConvertToUintBE(data, pos);
            pos   += 4;
            Length = MemoryMappedFileReader.ConvertToUintBE(data, pos);
            pos   += 4;

            return(pos);
        }
예제 #4
0
        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();
            });
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
                }
            });
        }
예제 #9
0
        /// <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);
        }