Пример #1
0
        public void Insert(Peer.StatePacket statePacket)
        {
            Packet packet = new Packet()
            {
                StatePacket           = statePacket,
                BufferFramesRemaining = buffer.Count > 0 ? buffer[0].BufferFramesRemaining + 1 : delayFrames
            };

            // Iterate through the buffer to determine where the new packet should be placed.
            for (int i = 0; i < buffer.Count + 1; i++)
            {
                // If the packet has arrived in order with respect to all elements in the buffer, its
                // remote frame should be larger than all other elements in the buffer, and it will
                // be inserted at the front of the buffer.
                if (i == buffer.Count || packet.StatePacket.Frame > buffer[i].StatePacket.Frame)
                {
                    buffer.Insert(i, packet);
                    break;
                }
                // If the packet arrived out of order with respect to the next packet in the buffer,
                // swap arrival frames with the next packet. This allows the buffer to more accurately represent
                // the cadence that the packets were sent.
                else
                {
                    int tempArrivalFrame = packet.BufferFramesRemaining;
                    packet.BufferFramesRemaining    = buffer[i].BufferFramesRemaining;
                    buffer[i].BufferFramesRemaining = tempArrivalFrame;
                }
            }

            NetDebug.Log($"<color=yellow><b>Inserting</b></color> packet with remote frame <b>{packet.StatePacket.Frame}</b> into jitter buffer. " +
                         $"<i>(Buffer is now size {buffer.Count}.)</i>", LogType.JitterBuffer);
        }
Пример #2
0
 public void InsertDelayedReader(float latency, Peer.StatePacket packet)
 {
     delayedPackets.Add(new System.Tuple <float, Peer.StatePacket>(Time.time + latency, packet));
 }