public override void SendUserData(OutgoingPackage package) { // 更新发送序号 var seq = (ushort)this.Context.SeqNoManager.GetAndUpdateSendSeq(); // 计算用户数据在发送队列中的排队时延。 package.QueuingDelay = (UInt32)((DateTime.Now - package.CreationTime).TotalMilliseconds / 10); // 计算发送方时间戳 var currentTime = TripleTimestamp.CurrentTimestamp; var senderTimeStamp = currentTime; if (currentTime > (package.ExtraDelay + package.QueuingDelay)) { senderTimeStamp = currentTime - package.ExtraDelay - package.QueuingDelay; } var dtFrame = new SaiTtsFrameAppData(seq, senderTimeStamp, this.TTS.RemoteLastSendTimestamp, this.TTS.LocalLastRecvTimeStamp, package.UserData); this.Context.NextLayer.SendUserData(dtFrame.GetBytes()); }
public static SaiFrame Parse(byte[] bytes) { SaiFrame theFrame = null; var theFrameType = (SaiFrameType)bytes[0]; if (theFrameType == SaiFrameType.TTS_OffsetStart) { theFrame = new SaiTtsFrameOffsetStart(); } else if (theFrameType == SaiFrameType.TTS_OffsetAnswer1) { theFrame = new SaiTtsFrameOffsetAnswer1(); } else if (theFrameType == SaiFrameType.TTS_OffsetAnswer2) { theFrame = new SaiTtsFrameOffsetAnswer2(); } else if (theFrameType == SaiFrameType.TTS_OffsetEstimate) { theFrame = new SaiTtsFrameEstimate(); } else if (theFrameType == SaiFrameType.TTS_OffsetEnd) { theFrame = new SaiTtsFrameOffsetEnd(); } else if (theFrameType == SaiFrameType.TTS_AppData) { theFrame = new SaiTtsFrameAppData(); } else if (theFrameType == SaiFrameType.EC_Start) { theFrame = new SaiEcFrameStart(); } else if (theFrameType == SaiFrameType.EC_AppData) { theFrame = new SaiEcFrameApplication(); } else if (theFrameType == SaiFrameType.EC_AppDataAskForAck) { theFrame = new SaiEcFrameAskForAck(); } else if (theFrameType == SaiFrameType.EC_AppDataAcknowlegment) { theFrame = new SaiEcFrameAcknowlegment(); } else { throw new InvalidOperationException(string.Format("无法解析指定的Sai帧,不可识别的类型{0}。", theFrameType)); } theFrame.ParseBytes(bytes); return(theFrame); }
protected override void HandleTtsAppFrame(SaiTtsFrameAppData frame) { if (frame.UserData != null) { // 消息时延 var timeDelay = this.DefenseStrategy.CalcTimeDelay(frame); // 通知网络数据事件 this.Context.Observer.OnSaiUserDataArrival(this.Context.RsspEP.RemoteID, frame.UserData, timeDelay, MessageDelayDefenseTech.TTS); } }
private void SendResponseFrame() { var seq = (ushort)_ttsFrameTransport.NextSendSeq(); // var reqFrame = new SaiTtsFrameAppData(seq, TripleTimestamp.CurrentTimestamp, _observer.RemoteLastSendTimestamp, _observer.LocalLastRecvTimeStamp, null); _ttsFrameTransport.SendSaiFrame(reqFrame); }
public void Test1() { var frameInital = new SaiTtsFrameAppData(); frameInital.SequenceNo = 100; frameInital.SenderTimestamp = 1000; frameInital.SenderLastRecvTimestamp = 900; frameInital.ReceiverLastSendTimestamp = 800; frameInital.UserData = new byte[] { 1, 2, 3 }; var bytes = frameInital.GetBytes(); var actual = SaiFrame.Parse(bytes) as SaiTtsFrameAppData; Assert.AreEqual(frameInital.FrameType, actual.FrameType); Assert.AreEqual(frameInital.SequenceNo, actual.SequenceNo); Assert.AreEqual(frameInital.SenderTimestamp, actual.SenderTimestamp); Assert.AreEqual(frameInital.SenderLastRecvTimestamp, actual.SenderLastRecvTimestamp); Assert.AreEqual(frameInital.ReceiverLastSendTimestamp, actual.ReceiverLastSendTimestamp); Assert.AreEqual(frameInital.UserData[0], actual.UserData[0]); Assert.AreEqual(frameInital.UserData[1], actual.UserData[1]); Assert.AreEqual(frameInital.UserData[2], actual.UserData[2]); }
public void Test2() { var frameInital = new SaiTtsFrameAppData(); Assert.AreEqual(frameInital.UserDataLength, 0); }
protected virtual void HandleTtsAppFrame(SaiTtsFrameAppData frame) { LogUtility.Error(string.Format("{0}: {1}.{2} not implement!", this.Context.RsspEP.ID, this.GetType().Name, new StackFrame(0).GetMethod().Name.Split('.').Last())); }