Exemplo n.º 1
0
 private void writeToVideoStream(DateTime time, DataType type, byte[] buffer)
 {
     if (type != DataType.StopSign)
     {
         StreamPacket data  = new StreamPacket(time, type, buffer);
         byte[]       block = StreamPacket.Encode(data);
         writeBuffer(_fsStream, block);
     }
 }
Exemplo n.º 2
0
 private static StreamPacket readStreamPacket(Stream fs)
 {
     try
     {
         byte[] buffer = readStream(fs);
         return(StreamPacket.Decode(buffer));
     }
     catch { }
     return(null);
 }
Exemplo n.º 3
0
 public static byte[] Encode(StreamPacket data)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, data.Time);
         PacketBase.WriteBytes(ms, (int)data.Type);
         PacketBase.WriteBytes(ms, data.Buffer.Length);
         PacketBase.WriteBytes(ms, data.Buffer);
         return(ms.ToArray());
     }
 }
Exemplo n.º 4
0
        public static VideoStreamsPacket Decode(MemoryStream ms)
        {
            TimePeriodPacket ti = TimePeriodPacket.Decode(ms);
            int length          = PacketBase.ReadInt(ms);

            StreamPacket[] spList = new StreamPacket[length];
            for (int i = 0; i < length; i++)
            {
                spList[i] = StreamPacket.Decode(ms);
            }
            return(new VideoStreamsPacket(ti, spList));
        }
Exemplo n.º 5
0
 public static byte[] Encode(VideoStreamsPacket packet)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, TimePeriodPacket.Encode(packet.TimePeriod));
         PacketBase.WriteBytes(ms, packet.VideoStreams.Length);
         for (int i = 0; i < packet.VideoStreams.Length; i++)
         {
             PacketBase.WriteBytes(ms, StreamPacket.Encode(packet.VideoStreams[i]));
         }
         return(ms.ToArray());
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// 获取某文件夹下某段时间内首个视频头文件
        /// </summary>
        /// <param name="folder">文件夹路径</param>
        /// <param name="beginTime">起始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>视频头</returns>
        public static StreamPacket GetVideoHeader(string folder, DateTime beginTime, DateTime endTime)
        {
            StreamPacket header = null;

            string[] files = GetIndexesFiles(folder);
            if (files.Length > 0)
            {
                TimePeriodPacket   validTi = new TimePeriodPacket(beginTime, endTime);
                TimePeriodPacket[] tis     = FolderManager.GetTimePeriods(folder);
                if (TimePeriodManager.GetIntersections(tis, validTi).Length != 0)
                {
                    foreach (var file in files)
                    {
                        header = FileManager.GetVideoHeader(GlobalProcess.GetRecFileName(file));
                        if (header != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(header);
        }
Exemplo n.º 7
0
        public void Set(DateTime time, DataType type, byte[] buffer)
        {
            lock (_lockObj)
            {
                _curStream = new StreamPacket(time, type, buffer);
                switch (type)
                {
                case DataType.SysHead:
                    _header = buffer;
                    closeFile();
                    break;

                case DataType.StopSign:
                    closeFile();
                    break;

                case DataType.StreamDataKey:
                case DataType.StreamData:
                    writeToFile();
                    break;
                }
            }
        }
Exemplo n.º 8
0
 public void Set(StreamPacket packet)
 {
     Set(packet.Time, packet.Type, packet.Buffer);
 }
Exemplo n.º 9
0
 public RecorderBase(string path)
 {
     _filePath  = path;
     _curStream = new StreamPacket(DateTime.MinValue, DataType.StopSign, new byte[0]);
 }