tbf/TBF/BenchControl/Network/Camera/CLP1611/RtpFrame.cs

66 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TBF.BenchControl.Network.Camera
{
public class RtpFrame
{
public enum STATE
{
Empty, /// Initial state after being constructed
OK, /// The frame is not empty, but it's not complete yet. It's without any error
Error, /// An error occured
Complete, /// The frame is complete, consequent AddPacket() calls will be ignored
}
public readonly int PayloadType;
public IList<RtpPacket> Packets;
public STATE State { get { return state; } }
STATE state;
public RtpFrame(int payloadType)
{
PayloadType = payloadType;
Packets = new List<RtpPacket>();
state = STATE.Empty;
}
public STATE AddPacket(RtpPacket packet)
{
if (state == STATE.Error || packet.PayloadType != PayloadType)
{
return (state = STATE.Error); /// Already in error or wrong payload type
}
else if (state == STATE.Complete)
{
return STATE.Complete; /// Already complete
}
else if (state != STATE.Empty && packet.SequenceNumber != Packets.Last<RtpPacket>().SequenceNumber + 1)
{
return (state = STATE.Error); /// Packet out of order
}
/// Going to add a new packet previous ones
Packets.Add(packet);
if (packet.Mark)
{
return (state = STATE.Complete); /// Complete now
}
else
{
return (state = STATE.OK); /// OK, not complete yet
}
}
public void Clear()
{
Packets.Clear();
state = STATE.Empty;
}
}
}