コード例 #1
0
        public static new VideoBaseInfomParam Decode(Stream ms)
        {
            IVideoInfo  vi = VideoInfo.Decode(ms);
            ITimePeriod ti = TimePeriodPacket.Decode(ms);

            return(new VideoBaseInfomParam(vi, ti));
        }
コード例 #2
0
        /// <summary>
        /// 排序并合并连续时间段
        /// </summary>
        /// <param name="tis">时间段列表</param>
        /// <returns>合并结果</returns>
        public static TimePeriodPacket[] Combine(TimePeriodPacket[] tis)
        {
            List <TimePeriodPacket> tiList = new List <TimePeriodPacket>();

            if (tis != null && tis.Length > 0)
            {
                tis = GetValidArray(tis);
                tis = tis.OrderBy(_ => _.BeginTime).ToArray();
                TimePeriodPacket tiCombin = new TimePeriodPacket(tis[0].BeginTime, tis[0].EndTime);
                for (int i = 1; i < tis.Length; i++)
                {
                    if (tiCombin.EndTime < tis[i].BeginTime)
                    {
                        tryAddTimePeriod(tiList, tiCombin);
                        tiCombin = tis[i];
                    }
                    else
                    {
                        tiCombin = new TimePeriodPacket(tiCombin.BeginTime, tis[i].EndTime);
                    }
                }
                tryAddTimePeriod(tiList, tiCombin);
            }
            return(tiList.ToArray());
        }
コード例 #3
0
        public static new VideoTimePeriodsPacket Decode(Stream ms)
        {
            VideoInfo videoInfo = VideoInfo.Decode(ms);

            TimePeriodPacket[] packets = TimePeriodPacket.DecodeArray(ms);
            return(new VideoTimePeriodsPacket(videoInfo, packets));
        }
コード例 #4
0
 public static byte[] Encode(IVideoBaseInfom param)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, VideoInfo.Encode(param));
         PacketBase.WriteBytes(ms, TimePeriodPacket.Encode(param));
         return(ms.ToArray());
     }
 }
コード例 #5
0
 public static byte[] Encode(VideoTimePeriodsPacket packet)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, VideoInfo.Encode(packet));
         PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray(packet.TimePeriods));
         return(ms.ToArray());
     }
 }
コード例 #6
0
ファイル: FileManager.cs プロジェクト: windygu/SeecoolCCTV2
        private static List <TimePeriodPacket> readTimePeriodArray(Stream fs)
        {
            List <TimePeriodPacket> shortIndexesDatas = new List <TimePeriodPacket>();

            while (fs.Position < fs.Length)
            {
                byte[] buffer = readStream(fs);
                var    data   = TimePeriodPacket.Decode(buffer);
                shortIndexesDatas.Add(data);
            }
            return(shortIndexesDatas);
        }
コード例 #7
0
        public static LocalVideosInfoPacket Decode(Stream ms)
        {
            ITimePeriod tp     = TimePeriodPacket.Decode(ms);
            int         length = PacketBase.ReadInt(ms);

            VideoTimePeriodsPacket[] vis = new VideoTimePeriodsPacket[length];
            for (int i = 0; i < length; i++)
            {
                vis[i] = VideoTimePeriodsPacket.Decode(ms);
            }
            return(new LocalVideosInfoPacket(tp, vis));
        }
コード例 #8
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));
        }
コード例 #9
0
        public static TimePeriodPacket Intersection(TimePeriodPacket ti1, TimePeriodPacket ti2)
        {
            DateTime b  = ti1.BeginTime > ti2.BeginTime ? ti1.BeginTime : ti2.BeginTime;
            DateTime e  = ti1.EndTime < ti2.EndTime ? ti1.EndTime : ti2.EndTime;
            var      ti = new TimePeriodPacket(b, e);

            if (isValid(ti))
            {
                return(ti);
            }
            return(null);
        }
コード例 #10
0
        /// <summary>时间段序列中去除某时间段 </summary>
        public static TimePeriodPacket[] Subtracts(TimePeriodPacket[] tisAll, TimePeriodPacket ti)
        {
            List <TimePeriodPacket> tiList = new List <TimePeriodPacket>();

            if (tisAll != null && tisAll.Length > 0)
            {
                for (int i = 0; i < tisAll.Length; i++)
                {
                    tiList.AddRange(Subtract(tisAll[i], ti));
                }
            }
            return(tiList.ToArray());
        }
コード例 #11
0
 public static byte[] Encode(LocalVideosInfoPacket packet)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, TimePeriodPacket.Encode(packet.TimePeriod));
         PacketBase.WriteBytes(ms, packet.ValidTimePeriods.Length);
         for (int i = 0; i < packet.ValidTimePeriods.Length; i++)
         {
             PacketBase.WriteBytes(ms, VideoTimePeriodsPacket.Encode(packet.ValidTimePeriods[i]));
         }
         return(ms.ToArray());
     }
 }
コード例 #12
0
        public static DownloadExpandPart Decode(MemoryStream ms)
        {
            Guid         guid = PacketBase.ReadGuid(ms);
            DownloadCode code = (DownloadCode)PacketBase.ReadInt(ms);
            Object       obj  = null;

            switch (code)
            {
            case DownloadCode.DownloadInfo:
                obj = DownloadInfoParam.Decode(ms);
                break;

            case DownloadCode.Name:
            case DownloadCode.Quality:
            case DownloadCode.ErrorInfo:
                obj = PacketBase.ReadString(ms);
                break;

            case DownloadCode.Size:
            case DownloadCode.Speed:
                obj = PacketBase.ReadLong(ms);
                break;

            case DownloadCode.IsLocalDownload:
                obj = PacketBase.ReadBool(ms);
                break;

            case DownloadCode.TimePeriodsAll:
            case DownloadCode.TimePeriodsCompleted:
                obj = TimePeriodPacket.DecodeArray(ms);
                break;

            case DownloadCode.Status:
                obj = (DownloadStatus)PacketBase.ReadInt(ms);
                break;

            case DownloadCode.UpdatedLastestTime:
                obj = PacketBase.ReadTime(ms);
                break;

            case DownloadCode.GoTop:
                obj = null;
                break;
            }
            return(new DownloadExpandPart(guid, code, obj));
        }
コード例 #13
0
        /// <summary>
        /// 获取所有某时间段的有效时间段列表
        /// </summary>
        /// <param name="tis">所有时间段列表</param>
        /// <param name="validTi">有效时间列表</param>
        /// <returns></returns>
        public static TimePeriodPacket[] GetIntersections(TimePeriodPacket[] tis, TimePeriodPacket validTi)
        {
            List <TimePeriodPacket> tiList = new List <TimePeriodPacket>();

            if (tis != null)
            {
                for (int i = 0; i < tis.Length; i++)
                {
                    var ti = Intersection(tis[i], validTi);
                    if (ti != null)
                    {
                        tiList.Add(ti);
                    }
                }
            }
            return(tiList.ToArray());
        }
コード例 #14
0
        static byte[] getBytes(Guid guid, DownloadCode code, object obj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                PacketBase.WriteBytes(ms, guid);
                PacketBase.WriteBytes(ms, (int)code);
                switch (code)
                {
                case DownloadCode.DownloadInfo:
                    PacketBase.WriteBytes(ms, DownloadInfoParam.Encode((DownloadInfoParam)obj));
                    break;

                case DownloadCode.Name:
                case DownloadCode.Quality:
                case DownloadCode.ErrorInfo:
                    PacketBase.WriteBytes(ms, (string)obj);
                    break;

                case DownloadCode.Size:
                case DownloadCode.Speed:
                    PacketBase.WriteBytes(ms, (long)obj);
                    break;

                case DownloadCode.IsLocalDownload:
                    PacketBase.WriteBytes(ms, (bool)obj);
                    break;

                case DownloadCode.TimePeriodsAll:
                case DownloadCode.TimePeriodsCompleted:
                    PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray((TimePeriodPacket[])obj));
                    break;

                case DownloadCode.Status:
                    PacketBase.WriteBytes(ms, (int)(DownloadStatus)obj);
                    break;

                case DownloadCode.UpdatedLastestTime:
                    PacketBase.WriteBytes(ms, (DateTime)obj);
                    break;

                case DownloadCode.GoTop:
                    break;
                }
                return(ms.ToArray());
            }
        }
コード例 #15
0
        public static DownloadInfoExpandPacket Decode(MemoryStream ms)
        {
            Guid          guid            = PacketBase.ReadGuid(ms);
            IDownloadInfo di              = DownloadInfoParam.Decode(ms);
            string        name            = PacketBase.ReadString(ms);
            string        quality         = PacketBase.ReadString(ms);
            long          size            = PacketBase.ReadLong(ms);
            bool          isLocalDownload = PacketBase.ReadBool(ms);

            TimePeriodPacket[] tps       = TimePeriodPacket.DecodeArray(ms);
            TimePeriodPacket[] tpsc      = TimePeriodPacket.DecodeArray(ms);
            DownloadStatus     status    = (DownloadStatus)PacketBase.ReadInt(ms);
            string             errorInfo = PacketBase.ReadString(ms);
            DateTime           time      = PacketBase.ReadTime(ms);
            long speed = PacketBase.ReadLong(ms);

            return(new DownloadInfoExpandPacket(guid, di, name, quality, size, isLocalDownload, tps, tpsc, status, errorInfo, time, speed));
        }
コード例 #16
0
 public static byte[] Encode(IDownloadInfoExpand packet)
 {
     using (MemoryStream ms = new MemoryStream())
     {
         PacketBase.WriteBytes(ms, packet.GuidCode);
         PacketBase.WriteBytes(ms, DownloadInfoParam.Encode(packet.DownloadInfo));
         PacketBase.WriteBytes(ms, packet.Name);
         PacketBase.WriteBytes(ms, packet.Quality);
         PacketBase.WriteBytes(ms, packet.Size);
         PacketBase.WriteBytes(ms, packet.IsLocalDownload);
         PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray(packet.TimePeriodsAll));
         PacketBase.WriteBytes(ms, TimePeriodPacket.EncodeArray(packet.TimePeriodsCompleted));
         PacketBase.WriteBytes(ms, (int)packet.DownloadStatus);
         PacketBase.WriteBytes(ms, packet.ErrorInfo);
         PacketBase.WriteBytes(ms, packet.UpdatedLastestTime);
         PacketBase.WriteBytes(ms, packet.Speed);
         return(ms.ToArray());
     }
 }
コード例 #17
0
        public static TimePeriodPacket[] Subtract(TimePeriodPacket ti1, TimePeriodPacket ti2)
        {
            List <TimePeriodPacket> tis = new List <TimePeriodPacket>();

            if (ti1.BeginTime >= ti2.EndTime || ti1.EndTime <= ti2.BeginTime)
            {
                tis.Add(ti1);
            }
            else if (ti1.BeginTime < ti2.BeginTime || ti1.EndTime > ti2.EndTime)
            {
                if (ti1.BeginTime < ti2.BeginTime)
                {
                    tis.Add(new TimePeriodPacket(ti1.BeginTime, ti2.BeginTime));
                }
                if (ti1.EndTime > ti2.EndTime)
                {
                    tis.Add(new TimePeriodPacket(ti2.EndTime, ti1.EndTime));
                }
            }
            return(tis.ToArray());
        }
コード例 #18
0
        public static DateTime GetProbeTime(TimePeriodPacket[] times, DateTime begin)
        {
            DateTime probe = DateTime.MaxValue;

            if (times == null || times.Length == 0)
            {
                return(probe);
            }
            if (begin >= times.Last().EndTime)
            {
                return(probe);
            }
            TimePeriodPacket packet = times.FirstOrDefault(_ => _.IsInRange(begin));

            if (packet != null)
            {
                return(begin);
            }
            packet = times.FirstOrDefault(_ => _.BeginTime >= begin);
            return(packet.BeginTime);
        }
コード例 #19
0
ファイル: FolderManager.cs プロジェクト: windygu/SeecoolCCTV2
        /// <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);
        }
コード例 #20
0
 public VideoStreamsPacket(TimePeriodPacket timePeriod, StreamPacket[] streamDatas)
 {
     TimePeriod   = timePeriod;
     VideoStreams = streamDatas;
 }
コード例 #21
0
 protected abstract void updateShortIndexes(TimePeriodPacket newTi);
コード例 #22
0
 private static bool isValid(TimePeriodPacket ti)
 {
     return(ti != null && ti.EndTime > ti.BeginTime);
 }
コード例 #23
0
 private static void tryAddTimePeriod(List <TimePeriodPacket> tiList, TimePeriodPacket tiCombin)
 {
     //if(isValid(tiCombin))
     tiList.Add(tiCombin);
 }
コード例 #24
0
 public static bool IsValid(TimePeriodPacket ti, DateTime time)
 {
     return(ti.BeginTime <= time && ti.EndTime > time);
 }