private void runVideoInfosTimePeriods(VideoDataInfoParam infosParam) { Parallel.ForEach(infosParam.VideoInfos, videoInfo => { readVideoTimePeriodsPacket(infosParam, infosParam, videoInfo); }); }
private void updateVideoInfosTimePeriods(VideoDataInfoParam infosParam) {//TODO:获取视频列表在指定时间段内的视频分布信息 Logger.Default.Trace("获取 {0} - {1} 时间内 {2} 路视频资源分布。", infosParam.BeginTime, infosParam.EndTime, infosParam.VideoInfos.Length); new Thread(() => runVideoInfosTimePeriods(infosParam)) { IsBackground = true }.Start(); }
public void TestVideoDataInfoParam() { VideoInfo[] vis = new VideoInfo[] { new VideoInfo("videoId1", 2), new VideoInfo("videoId2", 1) }; DateTime begin = new DateTime(2016, 5, 5, 13, 40, 1, 1); DateTime end = new DateTime(2016, 5, 5, 13, 45, 0); VideoDataInfoParam param = new VideoDataInfoParam("127.0.0.1", 10001, vis, begin, end); byte[] buffer = VideoDataInfoParam.Encode(param); VideoDataInfoParam param2 = VideoDataInfoParam.Decode(buffer); AssertAreEqual(param, param2); }
private void AssertAreEqual(VideoDataInfoParam p1, VideoDataInfoParam p2) { Assert.AreEqual(p1.SourceIp, p2.SourceIp); Assert.AreEqual(p1.SourcePort, p2.SourcePort); Assert.AreEqual(p1.BeginTime, p2.BeginTime); Assert.AreEqual(p1.EndTime, p2.EndTime); Assert.AreEqual(p1.VideoInfos.Length, p2.VideoInfos.Length); for (int i = 0; i < p1.VideoInfos.Length; i++) { Assert.AreEqual(p1.VideoInfos[i].VideoId, p2.VideoInfos[i].VideoId); Assert.AreEqual(p1.VideoInfos[i].StreamId, p2.VideoInfos[i].StreamId); } }
public void GetVideoDataInfoAsync(VideoInfo[] vis, DateTime begin, DateTime end) { if (!SourceValid) { throw new ErrorMessageException("尚未设置数据源地址。"); } if (_src.SrcType == SourceType.Local) { if (_localVideos != null && _localVideos.ValidTimePeriods != null) { //启动线程模拟异步事件。 new Thread(() => { foreach (VideoInfo vi in vis) { VideoTimePeriodsPacket rst = _localVideos.ValidTimePeriods.FirstOrDefault(vtpp => vtpp.VideoId == vi.VideoId); if (rst != null) { OnVideoDataInfoReceived(rst); } } }) { IsBackground = true }.Start(); } } else { EnsureStart(); if (_src.Storage != null) { VideoDataInfoParam param = new VideoDataInfoParam(_src.Storage.Ip, _src.Storage.Port, vis, begin, end); Client.Send((int)ParamCode.VideoInfosTimePeriods, VideoDataInfoParam.Encode(param)); } else { throw new ErrorMessageException("未配置集中存储相关信息。"); } } }
private void onReceiveCompleted(object sender, ReceiveEventArgs args) { try { if (args.ByteLength > 0) { using (MemoryStream ms = new MemoryStream(args.ReceivedBytes)) { ParamCode code = (ParamCode)PacketBase.ReadInt(ms); byte[] buffer = null; switch (code) { case ParamCode.VideoInfosTimePeriods: updateVideoInfosTimePeriods(VideoDataInfoParam.Decode(ms)); break; case ParamCode.DownloadBegin: beginDownload(DownloadInfoParam.Decode(ms)); break; case ParamCode.DownloadToLocal: downloadToLocal(PacketBase.ReadString(ms)); break; case ParamCode.VideoPacket: getVideoStreamsPacket(VideoDataParam.Decode(ms)); break; case ParamCode.ProbeTime: setProbeTime(PacketBase.ReadTime(ms)); break; case ParamCode.DownloadInfosAll: feedbackDownloadInfosToClient(); break; case ParamCode.DownloadControl: var controlCode = (DownloadControlCode)PacketBase.ReadInt(ms); onDownloadControl(controlCode, ms); break; case ParamCode.LocalDownloadPath: onLocalDownloadPath(PacketBase.ReadString(ms)); break; case ParamCode.LocalDownloadBegin: onLocalDownloadStart(LocalDownloadInfoPacket.Decode(ms)); break; } if (buffer != null) { send((ParamCode)code, buffer); } } } } catch (IOException ex) { sendMessage(MessageType.Warn, ex.Message, null); } catch (Exception ex) { sendMessage(MessageType.Error, ex.Message, null); Console.WriteLine(ex.ToString()); } }