public void TestVideoStreamsPacket_Encode() { VideoStreamsPacket vp = newVideoStreamsPacket(); byte[] buffer = VideoStreamsPacket.Encode(vp); VideoStreamsPacket decodeVp = VideoStreamsPacket.Decode(buffer); Assert.AreEqual(ti.BeginTime, decodeVp.TimePeriod.BeginTime); Assert.AreEqual(ti.EndTime, decodeVp.TimePeriod.EndTime); Assert.AreEqual(sps.Count, vp.VideoStreams.Length); for (int i = 0; i < sps.Count; i++) { Assert.AreEqual(sps[i].Time, vp.VideoStreams[i].Time); Assert.AreEqual(sps[i].Type, vp.VideoStreams[i].Type); Assert.AreEqual(sps[i].Buffer.Length, vp.VideoStreams[i].Buffer.Length); } }
private void Client_ReceiveCompleted(object sender, ReceiveEventArgs args) { try { if (args.ByteLength > 0) { onBytesLengthReceived(args.ByteLength); using (MemoryStream ms = new MemoryStream(args.ReceivedBytes)) { int code = PacketBase.ReadInt(ms); switch ((ParamCode)code) { case ParamCode.TimePeriods: onVideoStoragePacket(VideoTimePeriodsPacket.Decode(ms)); break; case ParamCode.VideoPacket: onVideoPacket(VideoStreamsPacket.Decode(ms)); break; case ParamCode.VideoBaseInfo: onVideoBasePacket(VideoBasePacket.Decode(ms)); break; case ParamCode.DownloadInfosAll: onDownloadInfosAll(DownloadInfoExpandPacket.DecodeArray(ms)); break; case ParamCode.DownloadInfosAdd: onDownloadInfosAdd(DownloadInfoExpandPacket.Decode(ms)); break; case ParamCode.DownloadInfoPart: onDownloadInfoPart(DownloadInfoPartConverter.Decode(ms)); break; } } } } catch (Exception ex) { onException(ex); } }
private void onReceived(object sender, ReceiveEventArgs args) { if (args.ByteLength > 0) { using (MemoryStream ms = new MemoryStream(args.ReceivedBytes)) { int code = PacketBase.ReadInt(ms); //Console.WriteLine("{0} - {1}", (ParamCode)code, args.ByteLength); switch ((ParamCode)code) { case ParamCode.TimePeriods: //接收所有有效视频分布 onTimePeriodsAll(VideoTimePeriodsPacket.Decode(ms).TimePeriods); break; case ParamCode.VideoBaseInfo: //设置视频基本信息 onVideoBase(VideoBasePacket.Decode(ms)); break; case ParamCode.DownloadProgress: //接收推送的下载进度。 onTimePeriodsDownloaded(VideoTimePeriodsPacket.Decode(ms).TimePeriods); break; case ParamCode.VideoPacket: //接收视频包数据流 onVideoStreams(VideoStreamsPacket.Decode(ms)); break; case ParamCode.LocalDownloadPath: onDownloadPathReceived(PacketBase.ReadString(ms)); break; case ParamCode.Message: onVideoMessageFeedback(MessagePacket.Decode(ms)); break; } } } }