예제 #1
0
        public static (ICollection <PlayPeerInfo>, DateTime, int, long) GetRecordingInfo(string _idxFilePath)
        {
            int                 duration = 0;
            int                 nPeers   = 0;
            DateTime            date     = DateTime.MinValue;
            List <PlayPeerInfo> peers    = new List <PlayPeerInfo>();

            using (FileStream idxFile = new FileStream(_idxFilePath, FileMode.Open, FileAccess.Read))
                using (BinaryReader idxBinaryReader = new BinaryReader(idxFile))
                {
                    byte[] auxBuff = new byte[1024];

                    // Read DateTime, Secs Interval and Peers info
                    if (idxBinaryReader.Read(auxBuff, 0, 16) == 16)
                    {
                        date = HelperTools.fromMillis(BitConverter.ToInt64(auxBuff, 0));
                        int secsIdxInterval = BitConverter.ToInt32(auxBuff, 8);
                        nPeers = BitConverter.ToInt32(auxBuff, 12);

                        // Read peers
                        for (int i = 0; i < nPeers; i++)
                        {
                            string ID   = HelperTools.Bytes2StringWithLength(idxFile);
                            string IP   = HelperTools.Bytes2StringWithLength(idxFile);
                            int    Port = idxBinaryReader.ReadInt32();

                            peers.Add(new PlayPeerInfo
                            {
                                ID   = ID,
                                IP   = IP,
                                Port = Port
                            });
                        }

                        // Guess duration
                        FileInfo fInfo = new FileInfo(_idxFilePath);
                        duration = ((int)((fInfo.Length - idxBinaryReader.BaseStream.Position) / HelperTools.idxIndexSize)) * secsIdxInterval;
                    }
                }

            string   rawFile = Path.Combine(Path.GetDirectoryName(_idxFilePath), Path.GetFileNameWithoutExtension(_idxFilePath)) + ".raw";
            FileInfo fRaw    = new FileInfo(rawFile);

            return(peers, date, duration, fRaw.Length);
        }
예제 #2
0
        public ICollection <PlayPeerInfo> LoadFile(string _filePath, out DateTime _startTime, out int _lastTime)
        {
            Stop();

            _lastTime = 0;

            filePath    = _filePath;
            idxFilePath = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)) + ".idx";

            // Init times
            lastTime   = 0;
            _startTime = DateTime.MinValue;
            timeIndexes.Clear();
            int nPeers = 0;

            udpSendersOriginal.Clear();
            udpSenders.Clear();
            _dataRate.Clear();


            using (FileStream idxFile = new FileStream(idxFilePath, FileMode.Open, FileAccess.Read))
                using (BinaryReader idxBinaryReader = new BinaryReader(idxFile))
                {
                    int    time = 0; long position = 0;
                    byte[] auxBuff = bytePool.Rent(4096);

                    // Read DateTime, Secs Interval and Peers info
                    if (idxBinaryReader.Read(auxBuff, 0, 16) == 16)
                    {
                        RecDateTime     = _startTime = HelperTools.fromMillis(BitConverter.ToInt64(auxBuff, 0));
                        secsIdxInterval = BitConverter.ToInt32(auxBuff, 8);
                        nPeers          = BitConverter.ToInt32(auxBuff, 12);

                        // Read peers
                        for (int i = 0; i < nPeers; i++)
                        {
                            string ID   = HelperTools.Bytes2StringWithLength(idxFile);
                            string IP   = HelperTools.Bytes2StringWithLength(idxFile);
                            int    Port = idxBinaryReader.ReadInt32();

                            udpSenders.Add(HelperTools.GetDeterministicHashCode(ID),
                                           new PlayPeerInfo {
                                ID   = ID,
                                IP   = IP,
                                Port = Port
                            });

                            udpSendersOriginal.Add(HelperTools.GetDeterministicHashCode(ID),
                                                   new PlayPeerInfo
                            {
                                ID   = ID,
                                IP   = IP,
                                Port = Port
                            });

                            _dataRate[ID] = 0f;
                        }

                        // Get All times to cache
                        while (idxBinaryReader.Read(auxBuff, 0, HelperTools.idxIndexSize) == HelperTools.idxIndexSize)
                        {
                            time     = BitConverter.ToInt32(auxBuff, 0);
                            position = BitConverter.ToInt64(auxBuff, 4);

                            try
                            {
                                timeIndexes.Add(time, position);
                            }
                            catch (Exception e)
                            {
                                logger?.LogError(e, "Error reading idx file. TimeIndexes");
                            }
                        }
                        _lastTime = lastTime = time;
                    }
                    bytePool.Return(auxBuff);
                }

            return(udpSenders.Values);
        }