public void TestVideoBasePacketLong() { VideoBasePacket packet = new VideoBasePacket(new byte[30], new DateTime(2016, 1, 1), 1000000000000); byte[] buffer = VideoBasePacket.Encode(packet); var packet2 = VideoBasePacket.Decode(buffer); AssertAreEqual(packet, packet2); }
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; } } } }