forked from kthompson/RtpLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RtcpPacket.cs
99 lines (75 loc) · 2.34 KB
/
RtcpPacket.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
namespace RtpLib
{
public abstract class RtcpPacket : ICloneable
{
#region Constructors
public RtcpPacket()
: this(null)
{
}
public RtcpPacket(RtcpHeader header)
{
if (header == null)
header = new RtcpHeader();
this.Header = header;
}
public static RtcpPacket FromUdpBuffer(UdpBuffer buffer)
{
using (var stream = new MemoryStream(buffer.Data, 0, buffer.Size))
{
return FromStream(stream);
}
}
public static RtcpPacket FromStream(Stream stream)
{
var header = new RtcpHeader();
header.Parse(stream);
RtcpPacket packet = Rtcp.CreatePacketType(header.PacketType);
packet.Header = header;
packet.ParseData(stream);
// Verify the header has the right version
if (packet.Header.Version != 2)
throw new InvalidDataException();
return packet;
}
#endregion
#region Public Methods
protected virtual void Parse(Stream stream)
{
this.Header.Parse(stream);
this.ParseData(stream);
}
public abstract void ParseData(Stream stream);
public virtual void ToStream(Stream stream)
{
// Override whatever the header packet type is with the correct packet type
this.Header.PacketType = this.PacketType;
this.Header.ByteCount = this.GetByteCount();
this.Header.ToStream(stream);
this.ToStreamInternal(stream);
}
protected abstract int GetByteCount();
protected abstract void ToStreamInternal(Stream stream);
#endregion
#region Properties
public RtcpHeader Header
{
get;
protected set;
}
public abstract Rtcp.PacketType PacketType
{
get;
}
#endregion
#region ICloneable Implementation
public abstract object Clone();
#endregion
}
}